Commit 80f032e6 authored by 9731301's avatar 9731301

add mains to packages

parent 2e18f338
......@@ -7,8 +7,14 @@
</component>
<component name="ChangeListManager">
<list default="true" id="f2dd20fb-7e97-49ef-9dfe-5631626d7912" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/Insomnia.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/insomnia/parser/Insomnia.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/parser/Saver.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/Saver.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/Run.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/parser/Parser.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/parser/Parser.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/parser/Saver.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/parser/Saver.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Run.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/parser/RequestLoader.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/RequestLoader.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -62,7 +68,33 @@
<property name="project.structure.proportion" value="0.15" />
<property name="project.structure.side.proportion" value="0.2" />
</component>
<component name="RunManager" selected="Application.Insomnia">
<component name="RunManager" selected="Application.Insomnia (2)">
<configuration name="Insomnia (1)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.insomnia.GUI.Insomnia" />
<module name="Insomnia" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.insomnia.GUI.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Insomnia (2)" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="com.insomnia.parser.Insomnia" />
<module name="Insomnia" />
<extension name="coverage">
<pattern>
<option name="PATTERN" value="com.insomnia.parser.*" />
<option name="ENABLED" value="true" />
</pattern>
</extension>
<method v="2">
<option name="Make" enabled="true" />
</method>
</configuration>
<configuration name="Insomnia" type="Application" factoryName="Application" temporary="true" nameIsGenerated="true">
<option name="MAIN_CLASS_NAME" value="Insomnia" />
<module name="Insomnia" />
......@@ -79,6 +111,8 @@
</configuration>
<recent_temporary>
<list>
<item itemvalue="Application.Insomnia (2)" />
<item itemvalue="Application.Insomnia (1)" />
<item itemvalue="Application.Insomnia" />
<item itemvalue="Application.Run" />
</list>
......@@ -113,6 +147,8 @@
<workItem from="1590600904796" duration="12014000" />
<workItem from="1590623093663" duration="5335000" />
<workItem from="1590682418201" duration="308000" />
<workItem from="1590757579057" duration="2543000" />
<workItem from="1590934179600" duration="245000" />
</task>
<servers />
</component>
......@@ -143,22 +179,22 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="402" y="167" key="FileChooserDialogImpl/0.0.1536.824@0.0.1536.824" timestamp="1590494460700" />
<state width="1493" height="174" key="GridCell.Tab.0.bottom" timestamp="1590614025564">
<state width="1493" height="174" key="GridCell.Tab.0.bottom" timestamp="1590934462040">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="174" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1590614025564" />
<state width="1493" height="174" key="GridCell.Tab.0.center" timestamp="1590614025564">
<state width="1493" height="174" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1590934462040" />
<state width="1493" height="174" key="GridCell.Tab.0.center" timestamp="1590934462040">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="174" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1590614025564" />
<state width="1493" height="174" key="GridCell.Tab.0.left" timestamp="1590614025564">
<state width="1493" height="174" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1590934462040" />
<state width="1493" height="174" key="GridCell.Tab.0.left" timestamp="1590934462040">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="174" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1590614025564" />
<state width="1493" height="174" key="GridCell.Tab.0.right" timestamp="1590614025564">
<state width="1493" height="174" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1590934462040" />
<state width="1493" height="174" key="GridCell.Tab.0.right" timestamp="1590934462040">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="174" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1590614025564" />
<state width="1493" height="174" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1590934462040" />
<state x="249" y="0" key="SettingsEditor" timestamp="1590496679192">
<screen x="0" y="0" width="1536" height="824" />
</state>
......@@ -175,10 +211,10 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="209" y="33" key="new project wizard/0.0.1536.824@0.0.1536.824" timestamp="1590495277464" />
<state x="163" y="189" key="run.anything.popup" timestamp="1589217529286">
<state x="163" y="189" key="run.anything.popup" timestamp="1590759062213">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="163" y="189" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1589217529286" />
<state x="163" y="189" key="run.anything.popup/0.0.1536.824@0.0.1536.824" timestamp="1590759062213" />
<state x="46" y="145" width="672" height="678" key="search.everywhere.popup" timestamp="1589292677842">
<screen x="0" y="0" width="1536" height="824" />
</state>
......
import java.io.*;
import java.net.*;
import java.util.HashMap;
public class Run {
public static void bufferOutFormData(HashMap<String, String> body, String boundary, BufferedOutputStream bufferedOutputStream) throws IOException {
for (String key : body.keySet()) {
bufferedOutputStream.write(("--" + boundary + "\r\n").getBytes());
if (key.contains("file")) {
bufferedOutputStream.write(("Content-Disposition: form-data; filename=\"" + (new File(body.get(key))).getName() + "\"\r\nContent-Type: Auto\r\n\r\n").getBytes());
try {
BufferedInputStream tempBufferedInputStream = new BufferedInputStream(new FileInputStream(new File(body.get(key))));
byte[] filesBytes = tempBufferedInputStream.readAllBytes();
bufferedOutputStream.write(filesBytes);
bufferedOutputStream.write("\r\n".getBytes());
} catch (IOException e) {
e.printStackTrace();
}
} else {
bufferedOutputStream.write(("Content-Disposition: form-data; name=\"" + key + "\"\r\n\r\n").getBytes());
bufferedOutputStream.write((body.get(key) + "\r\n").getBytes());
}
}
bufferedOutputStream.write(("--" + boundary + "--\r\n").getBytes());
bufferedOutputStream.flush();
bufferedOutputStream.close();
}
public static void uploadBinary() {
try {
URL url = new URL("http://apapi.haditabatabaei.ir/tests/post/binary");
File haditabatabaei = new File("haditabatabaei.txt");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "application/octet-stream");
BufferedOutputStream bufferedOutputStream = new BufferedOutputStream(connection.getOutputStream());
BufferedInputStream fileInputStream = new BufferedInputStream(new FileInputStream(haditabatabaei));
bufferedOutputStream.write(fileInputStream.readAllBytes());
bufferedOutputStream.flush();
bufferedOutputStream.close();
BufferedInputStream bufferedInputStream = new BufferedInputStream(connection.getInputStream());
System.out.println(new String(bufferedInputStream.readAllBytes()));
System.out.println(connection.getResponseCode());
System.out.println(connection.getHeaderFields());
} catch (IOException e) {
e.printStackTrace();
}
}
public static void formData() {
HashMap<String, String> fooBody = new HashMap<>();
fooBody.put("name", "hadi");
fooBody.put("lastName", "tabatabaei");
fooBody.put("file", "pic2.png");
fooBody.put("file2", "result.png");
try {
URL url = new URL("http://apapi.haditabatabaei.ir/tests/post/formdata");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
String boundary = System.currentTimeMillis() + "";
connection.setRequestMethod("POST");
connection.setDoOutput(true);
connection.setRequestProperty("Content-Type", "multipart/form-data; boundary=" + boundary);
BufferedOutputStream request = new BufferedOutputStream(connection.getOutputStream());
bufferOutFormData(fooBody, boundary, request);
BufferedInputStream bufferedInputStream = new BufferedInputStream(connection.getInputStream());
System.out.println(new String(bufferedInputStream.readAllBytes()));
System.out.println(connection.getResponseCode());
System.out.println(connection.getHeaderFields());
} catch (Exception e) {
}
}
public static void main(String[] args) {
uploadBinary();
formData();
}
}
\ No newline at end of file
package com.insomnia.GUI;
import java.awt.*;
import java.io.IOException;
public class Insomnia {
public static void main(String [] args) throws IOException {
InsomniaGUI insomniaGUI = new InsomniaGUI();
Frame frame = new Frame();
}
}
package com.insomnia.parser;
public class Insomnia {
public static void main(String [] args) {
ResponseData data = RequestLoader.run(Parser.parse(args));
if (data.hasSyntaxError()){
System.out.println("Syntax Error : "+data.getSyntaxErrorLog());
}else{
System.out.println("Connection time : "+((data.getFinalTime()-data.getStartTime())/1000)+"s");
System.out.println("Response Status : "+ data.getResponseStatus());
if (data.isSuccessful()){
System.out.println("Response : "+data.getResponseString());
if (data.getRequestData().isShowResponseHeaders()&& data.getResponseHeaders()!=null){
System.out.println("******* Response Headers *******");
for (String key : data.getResponseHeaders().keySet()){
System.out.println(key+" : "+data.getResponseHeaders().get(key).toString());
}
}
}else {
System.out.println("Error : "+data.getErrorMessage());
}
}
}
}
......@@ -15,9 +15,6 @@ import java.util.HashMap;
public class RequestLoader {
private static String twoHyphens = "--";
private static String crlf = "\r\n";
public static ResponseData run (RequestData data){
String boundary = "*****" + System.currentTimeMillis() + "*****";
ResponseData responseData = new ResponseData(data);
......@@ -87,6 +84,8 @@ public class RequestLoader {
if (con.getDoOutput()){
if (!data.getUploadPath().isEmpty()){
DataOutputStream request = new DataOutputStream(con.getOutputStream());
String twoHyphens = "--";
String crlf = "\r\n";
if (!data.getBody().isEmpty()) {
HashMap<String, String> fields = new HashMap<>();
if (!data.getBody().contains(";")) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment