Commit c3a90235 authored by 9731301's avatar 9731301

add ResponseDataClass

parent 23f3b1b4
...@@ -7,43 +7,10 @@ ...@@ -7,43 +7,10 @@
</component> </component>
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="f2dd20fb-7e97-49ef-9dfe-5631626d7912" name="Default Changelist" comment=""> <list default="true" id="f2dd20fb-7e97-49ef-9dfe-5631626d7912" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/.idea/artifacts/Insomnia_jar.xml" afterDir="false" /> <change afterPath="$PROJECT_DIR$/src/com/insomnia/parser/ResponseData.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/META-INF/MANIFEST.MF" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/Run.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/InsomniaGUI.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/LeftPanel.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/RequestPanel.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/RespondPanel.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/VerticalFlowLayout.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/insomnia/parser/Parser.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/insomnia/parser/RequestData.java" afterDir="false" />
<change afterPath="$PROJECT_DIR$/src/com/insomnia/parser/Saver.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" /> <change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/Insomnia.class" beforeDir="false" /> <change beforePath="$PROJECT_DIR$/src/com/insomnia/parser/Parser.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/Parser.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/InsomniaGUI$1.class" beforeDir="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/InsomniaGUI$2.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/InsomniaGUI$3.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/InsomniaGUI$4.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/InsomniaGUI$5.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/InsomniaGUI$6.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/InsomniaGUI$exitApp$1.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/InsomniaGUI$exitApp$2.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/InsomniaGUI$exitApp.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/InsomniaGUI.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/LeftPanel$1.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/LeftPanel.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/RequestPanel$1.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/RequestPanel$TextFieldHandler.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/RequestPanel.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/RespondPanel$1.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/RespondPanel.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/Insomnia/VerticalFlowLayout.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/Insomnia.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/InsomniaGUI.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/LeftPanel.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/RequestPanel.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/RespondPanel.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/VerticalFlowLayout.java" beforeDir="false" />
</list> </list>
<option name="SHOW_DIALOG" value="false" /> <option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" /> <option name="HIGHLIGHT_CONFLICTS" value="true" />
...@@ -145,7 +112,7 @@ ...@@ -145,7 +112,7 @@
<workItem from="1590491155616" duration="8322000" /> <workItem from="1590491155616" duration="8322000" />
<workItem from="1590502223611" duration="8513000" /> <workItem from="1590502223611" duration="8513000" />
<workItem from="1590582948373" duration="9875000" /> <workItem from="1590582948373" duration="9875000" />
<workItem from="1590600904796" duration="3653000" /> <workItem from="1590600904796" duration="12014000" />
</task> </task>
<servers /> <servers />
</component> </component>
...@@ -176,22 +143,22 @@ ...@@ -176,22 +143,22 @@
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="402" y="167" key="FileChooserDialogImpl/0.0.1536.824@0.0.1536.824" timestamp="1590494460700" /> <state x="402" y="167" key="FileChooserDialogImpl/0.0.1536.824@0.0.1536.824" timestamp="1590494460700" />
<state width="906" height="2" key="GridCell.Tab.0.bottom" timestamp="1590597048866"> <state width="1493" height="174" key="GridCell.Tab.0.bottom" timestamp="1590614025564">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="906" height="2" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1590597048866" /> <state width="1493" height="174" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1590614025564" />
<state width="906" height="2" key="GridCell.Tab.0.center" timestamp="1590597048866"> <state width="1493" height="174" key="GridCell.Tab.0.center" timestamp="1590614025564">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="906" height="2" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1590597048866" /> <state width="1493" height="174" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1590614025564" />
<state width="906" height="2" key="GridCell.Tab.0.left" timestamp="1590597048866"> <state width="1493" height="174" key="GridCell.Tab.0.left" timestamp="1590614025564">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="906" height="2" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1590597048866" /> <state width="1493" height="174" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1590614025564" />
<state width="906" height="2" key="GridCell.Tab.0.right" timestamp="1590597048866"> <state width="1493" height="174" key="GridCell.Tab.0.right" timestamp="1590614025564">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="906" height="2" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1590597048866" /> <state width="1493" height="174" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1590614025564" />
<state x="249" y="0" key="SettingsEditor" timestamp="1590496679192"> <state x="249" y="0" key="SettingsEditor" timestamp="1590496679192">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
......
...@@ -5,7 +5,7 @@ import java.util.HashMap; ...@@ -5,7 +5,7 @@ import java.util.HashMap;
public class Parser { public class Parser {
static ArrayList<String> fixArgs(String[] args){ public static ArrayList<String> fixArgs(String[] args){
ArrayList<String> args2 = new ArrayList<>(); ArrayList<String> args2 = new ArrayList<>();
String f = ""; String f = "";
for (String arg : args){ for (String arg : args){
......
/**
* ResponseData represents a class
*/
package com.insomnia.parser;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.List;
import java.util.Map;
public class ResponseData {
private RequestData requestData;
private long startTime,finalTime;
private boolean syntaxError = false;
private String syntaxErrorLog = "";
private boolean successful = false;
private int status = -1;
private InputStream inputStream = null;
private Map<String, List<String>> responseHeaders;
private String errorMessage = "";
public ResponseData (RequestData data){
this.requestData = data;
startTime = System.currentTimeMillis();
}
public ResponseData finish(){
finalTime = System.currentTimeMillis();
return this;
}
public int getStatus() {
return status;
}
public void setResponseHeaders(Map<String, List<String>> responseHeaders) {
this.responseHeaders = responseHeaders;
}
public void setSuccessful(boolean successful) {
this.successful = successful;
}
public String getErrorMessage() {
return errorMessage;
}
public String getSyntaxErrorLog() {
return syntaxErrorLog;
}
public RequestData getRequestData() {
return requestData;
}
public Map<String, List<String>> getResponseHeaders() {
return responseHeaders;
}
public boolean hasSyntaxError() {
return syntaxError;
}
public int getResponseStatus() {
return status;
}
public long getFinalTime() {
return finalTime;
}
public long getStartTime() {
return startTime;
}
public boolean isSuccessful() {
return successful;
}
String res = "";
public String getResponseString(){
return res;
}
String convertStreamToString(InputStream is,boolean close) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line);
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (close) {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return sb.toString();
}
public void setRequestData(RequestData requestData) {
this.requestData = requestData;
}
public void setFinalTime(long finalTime) {
this.finalTime = finalTime;
}
public boolean isSyntaxError() {
return syntaxError;
}
public void setSyntaxError(boolean syntaxError) {
this.syntaxError = syntaxError;
}
public void setSyntaxErrorLog(String syntaxErrorLog) {
this.syntaxErrorLog = syntaxErrorLog;
}
public InputStream getInputStream() {
return inputStream;
}
public void setInputStream(InputStream inputStream) {
this.inputStream = inputStream;
}
public void setErrorMessage(String errorMessage) {
this.errorMessage = errorMessage;
}
public void setStatus(int status) {
this.status = status;
}
}
...@@ -88,6 +88,30 @@ public class Saver { ...@@ -88,6 +88,30 @@ public class Saver {
return null; return null;
} }
public static void saveResponse (ResponseData data){
if (!data.getRequestData().getOutput().equals("-null")){
String fileName;
if (data.getRequestData().getOutput().equals("-t")){
fileName = "output_"+new SimpleDateFormat("dd_MM_yyyy").format(new Date());
}else{
fileName = data.getRequestData().getOutput();
}
File file = new File(getOutputDir(),fileName);
try{
FileOutputStream outputStream = new FileOutputStream(file);
int read;
byte[] bytes = new byte[1024];
while ((read = data.getInputStream().read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
}catch (IOException e) {
e.printStackTrace();
}
}
}
public static File[] getRequestFiles(){ public static File[] getRequestFiles(){
return new File(getRequestsDir()).listFiles(); return new File(getRequestsDir()).listFiles();
} }
......
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