Commit fa3710c7 authored by 9731301's avatar 9731301

show respond in respondPanel

parent d4a0e680
...@@ -8,10 +8,15 @@ ...@@ -8,10 +8,15 @@
<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 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/com/insomnia/parser/ResponseData.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/parser/ResponseData.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/com/insomnia/GUI/InsomniaGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/InsomniaGUI.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/com/insomnia/GUI/InsomniaGUI.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/InsomniaGUI.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/GUI/RequestPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/RequestPanel.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/com/insomnia/GUI/RequestPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/RequestPanel.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/GUI/RespondPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/RespondPanel.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/com/insomnia/GUI/RespondPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/RespondPanel.java" afterDir="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$/src/com/insomnia/parser/RequestLoader.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/RequestLoader.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/src/com/insomnia/parser/RequestLoader.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/RequestLoader.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/parser/ResponseData.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/ResponseData.java" 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" />
</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" />
...@@ -146,7 +151,7 @@ ...@@ -146,7 +151,7 @@
<workItem from="1590682418201" duration="308000" /> <workItem from="1590682418201" duration="308000" />
<workItem from="1590757579057" duration="2543000" /> <workItem from="1590757579057" duration="2543000" />
<workItem from="1590934179600" duration="31544000" /> <workItem from="1590934179600" duration="31544000" />
<workItem from="1591024948574" duration="14918000" /> <workItem from="1591024948574" duration="21598000" />
</task> </task>
<servers /> <servers />
</component> </component>
...@@ -177,22 +182,22 @@ ...@@ -177,22 +182,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="1493" height="105" key="GridCell.Tab.0.bottom" timestamp="1591040084950"> <state width="1493" height="105" key="GridCell.Tab.0.bottom" timestamp="1591046612712">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="105" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1591040084950" /> <state width="1493" height="105" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1591046612712" />
<state width="1493" height="105" key="GridCell.Tab.0.center" timestamp="1591040084950"> <state width="1493" height="105" key="GridCell.Tab.0.center" timestamp="1591046612712">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="105" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1591040084950" /> <state width="1493" height="105" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1591046612712" />
<state width="1493" height="105" key="GridCell.Tab.0.left" timestamp="1591040084950"> <state width="1493" height="105" key="GridCell.Tab.0.left" timestamp="1591046612712">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="105" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1591040084950" /> <state width="1493" height="105" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1591046612712" />
<state width="1493" height="105" key="GridCell.Tab.0.right" timestamp="1591040084950"> <state width="1493" height="105" key="GridCell.Tab.0.right" timestamp="1591046612712">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="105" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1591040084950" /> <state width="1493" height="105" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1591046612712" />
<state x="249" y="0" key="SettingsEditor" timestamp="1590962002174"> <state x="249" y="0" key="SettingsEditor" timestamp="1590962002174">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
......
...@@ -5,6 +5,8 @@ package com.insomnia.GUI; ...@@ -5,6 +5,8 @@ package com.insomnia.GUI;
* @version 0.0 * @version 0.0
*/ */
import com.insomnia.parser.ResponseData;
import javax.swing.*; import javax.swing.*;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
...@@ -16,6 +18,13 @@ import static java.awt.Frame.*; ...@@ -16,6 +18,13 @@ import static java.awt.Frame.*;
public class InsomniaGUI { public class InsomniaGUI {
JFrame frame ; JFrame frame ;
RespondPanel response;
ResponseData data_req = null;
public void load(ResponseData d){
data_req = d;
response.load(d);
}
public InsomniaGUI() throws IOException { public InsomniaGUI() throws IOException {
frame = new JFrame(); frame = new JFrame();
...@@ -25,9 +34,9 @@ public class InsomniaGUI { ...@@ -25,9 +34,9 @@ public class InsomniaGUI {
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setVisible(true); frame.setVisible(true);
RequestPanel request = new RequestPanel(); RequestPanel request = new RequestPanel(this);
request.createRequestPanel(); request.createRequestPanel();
RespondPanel response = new RespondPanel(); response = new RespondPanel();
response.createRespondPanel(); response.createRespondPanel();
JPanel panelRight = new JPanel(new GridLayout(1 ,2 )); JPanel panelRight = new JPanel(new GridLayout(1 ,2 ));
panelRight.add(request); panelRight.add(request);
...@@ -55,7 +64,6 @@ public class InsomniaGUI { ...@@ -55,7 +64,6 @@ public class InsomniaGUI {
response.getCookie().setBackground(Color.WHITE); response.getCookie().setBackground(Color.WHITE);
response.getCopyToClipBoard().setBackground(Color.WHITE); response.getCopyToClipBoard().setBackground(Color.WHITE);
response.getHeader_MainPanel().setBackground(Color.WHITE); response.getHeader_MainPanel().setBackground(Color.WHITE);
response.getHeaderField2().setBackground(Color.WHITE);
response.getMainCenterHeader_respond().setBackground(Color.WHITE); response.getMainCenterHeader_respond().setBackground(Color.WHITE);
response.getMassageBody().setBackground(Color.WHITE); response.getMassageBody().setBackground(Color.WHITE);
response.getScrollPane_Header_Respond().setBackground(Color.WHITE); response.getScrollPane_Header_Respond().setBackground(Color.WHITE);
...@@ -85,7 +93,6 @@ public class InsomniaGUI { ...@@ -85,7 +93,6 @@ public class InsomniaGUI {
response.getCookie().setBackground(Color.DARK_GRAY); response.getCookie().setBackground(Color.DARK_GRAY);
response.getCopyToClipBoard().setBackground(Color.DARK_GRAY); response.getCopyToClipBoard().setBackground(Color.DARK_GRAY);
response.getHeader_MainPanel().setBackground(Color.DARK_GRAY); response.getHeader_MainPanel().setBackground(Color.DARK_GRAY);
response.getHeaderField2().setBackground(Color.DARK_GRAY);
response.getMainCenterHeader_respond().setBackground(Color.DARK_GRAY); response.getMainCenterHeader_respond().setBackground(Color.DARK_GRAY);
response.getMassageBody().setBackground(Color.DARK_GRAY); response.getMassageBody().setBackground(Color.DARK_GRAY);
response.getScrollPane_Header_Respond().setBackground(Color.DARK_GRAY); response.getScrollPane_Header_Respond().setBackground(Color.DARK_GRAY);
......
package com.insomnia.GUI; package com.insomnia.GUI;
import com.insomnia.parser.RequestData; import com.insomnia.parser.*;
import com.insomnia.parser.RequestLoader;
import com.insomnia.parser.ResponseData;
import com.insomnia.parser.Saver;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
...@@ -46,6 +44,12 @@ public class RequestPanel extends JPanel { ...@@ -46,6 +44,12 @@ public class RequestPanel extends JPanel {
private JButton sendButton = new JButton("send"); private JButton sendButton = new JButton("send");
private JPanel centerUp = new JPanel(new BorderLayout()); private JPanel centerUp = new JPanel(new BorderLayout());
private InsomniaGUI main_class;
public RequestPanel(InsomniaGUI m){
main_class = m;
}
public JTabbedPane tabbedPaneCenterRequest() throws IOException { public JTabbedPane tabbedPaneCenterRequest() throws IOException {
Border border = BorderFactory.createLineBorder(Color.BLACK,3); Border border = BorderFactory.createLineBorder(Color.BLACK,3);
BufferedImage master; BufferedImage master;
...@@ -323,8 +327,8 @@ public class RequestPanel extends JPanel { ...@@ -323,8 +327,8 @@ public class RequestPanel extends JPanel {
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
RequestData requestData = new RequestData(); RequestData requestData = new RequestData();
requestData.setUrl(URLTextField.getText()); requestData.setUrl(URLTextField.getText());
super.mouseClicked(e); requestData.setMethod(Parser.findMethod((String)centerMenu.getSelectedItem()));
Saver saver = new Saver();
//set if it is Json or not //set if it is Json or not
if(Json_FormData.getSelectedItem().equals("JSON")) { if(Json_FormData.getSelectedItem().equals("JSON")) {
requestData.setJson(true); requestData.setJson(true);
...@@ -345,26 +349,7 @@ public class RequestPanel extends JPanel { ...@@ -345,26 +349,7 @@ public class RequestPanel extends JPanel {
requestData.setSaveRequest(false); requestData.setSaveRequest(false);
ResponseData data = RequestLoader.run(requestData); ResponseData data = RequestLoader.run(requestData);
main_class.load(data);
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());
}
}
} }
}); });
......
package com.insomnia.GUI; package com.insomnia.GUI;
import com.insomnia.parser.ResponseData;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
import java.awt.*; import java.awt.*;
...@@ -16,14 +18,13 @@ public class RespondPanel extends JPanel { ...@@ -16,14 +18,13 @@ public class RespondPanel extends JPanel {
return row.getSize(); return row.getSize();
} }
}; };
private JPanel mainCenterHeader_respond = new JPanel(vfLayout); private JPanel mainCenterHeader_respond = new JPanel(vfLayout) ;
private JScrollPane scrollPane_Header_Respond = new JScrollPane(mainCenterHeader_respond); private JScrollPane scrollPane_Header_Respond = new JScrollPane(mainCenterHeader_respond);
private JPanel header_MainPanel = new JPanel(new BorderLayout()); private JPanel header_MainPanel = new JPanel(new BorderLayout());
private JButton copyToClipBoard = new JButton("copy to clip board"); private JButton copyToClipBoard = new JButton("copy to clip board");
private JPanel cookie = new JPanel(); private JPanel cookie = new JPanel();
private JPanel timeline = new JPanel(new BorderLayout()); private JPanel timeline = new JPanel(new BorderLayout());
private JTabbedPane tabbedPaneCenterResponse = new JTabbedPane(); private JTabbedPane tabbedPaneCenterResponse = new JTabbedPane();
private JTextField headerField2 = new JTextField("header");
public JTabbedPane tabbedPaneCenterResponse() { public JTabbedPane tabbedPaneCenterResponse() {
massageBody.setLineWrap(true); massageBody.setLineWrap(true);
...@@ -31,6 +32,7 @@ public class RespondPanel extends JPanel { ...@@ -31,6 +32,7 @@ public class RespondPanel extends JPanel {
row.add(massageBody); row.add(massageBody);
row.setBackground(Color.GRAY); row.setBackground(Color.GRAY);
scrollPane_Header_Respond.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS); scrollPane_Header_Respond.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_ALWAYS);
scrollPane_Header_Respond.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
mainCenterHeader_respond.setBackground(Color.GRAY); mainCenterHeader_respond.setBackground(Color.GRAY);
header_MainPanel.setBackground(Color.GRAY); header_MainPanel.setBackground(Color.GRAY);
header_MainPanel.add(scrollPane_Header_Respond, BorderLayout.CENTER); header_MainPanel.add(scrollPane_Header_Respond, BorderLayout.CENTER);
...@@ -43,67 +45,19 @@ public class RespondPanel extends JPanel { ...@@ -43,67 +45,19 @@ public class RespondPanel extends JPanel {
tabbedPaneCenterResponse.add("Cookie", cookie); tabbedPaneCenterResponse.add("Cookie", cookie);
tabbedPaneCenterResponse.add("Timeline", timeline); tabbedPaneCenterResponse.add("Timeline", timeline);
headerField2.setEditable(false);
headerField2.addMouseListener(new MouseListener() {
@Override
public void mouseClicked(MouseEvent e) {
System.out.println(")))))))))))");
// if (!headerField2.getText().equals("") ) {
JTextField newHeaderField = new JTextField("header");
newHeaderField.setEditable(false);
newHeaderField.setBorder(border);
JTextField newValueField = new JTextField("value");
newValueField.setEditable(false);
newValueField.setBorder(border);
JPanel new_center_header = new JPanel(new GridLayout(1, 2));
new_center_header.add(newHeaderField);
new_center_header.add(newValueField);
JPanel newHeader = new JPanel(new BorderLayout());
newHeader.add(new_center_header, BorderLayout.CENTER);
mainCenterHeader_respond.add(newHeader);
// }
}
@Override
public void mousePressed(MouseEvent e) {
}
@Override
public void mouseReleased(MouseEvent e) {
}
@Override
public void mouseEntered(MouseEvent e) {
}
@Override
public void mouseExited(MouseEvent e) {
}
});
headerField2.setBorder(border);
JTextField valueField2 = new JTextField("value");
valueField2.setEditable(false);
valueField2.setBorder(border);
JPanel center_header2 = new JPanel(new GridLayout(1, 2));
center_header2.add(headerField2);
center_header2.add(valueField2);
JPanel header2 = new JPanel(new BorderLayout());
header2.add(center_header2, BorderLayout.CENTER);
mainCenterHeader_respond.add(header2);
return tabbedPaneCenterResponse; return tabbedPaneCenterResponse;
} }
public JPanel up_response() {
JPanel up_response = new JPanel(); JPanel up_response = new JPanel();
public JPanel up_response() {
JLabel label1 = new JLabel("ok"); JLabel label1 = new JLabel("ok");
label1.setBorder(border); label1.setBorder(border);
JLabel label2 = new JLabel("s"); JLabel label2 = new JLabel("s");
label2.setBorder(border); label2.setBorder(border);
JLabel label3 = new JLabel("KB"); JLabel label3 = new JLabel("KB");
label3.setBorder(border); label3.setBorder(border);
up_response.add(label1); up_response.add(label1);
up_response.add(label2); up_response.add(label2);
up_response.add(label3); up_response.add(label3);
...@@ -154,11 +108,55 @@ public class RespondPanel extends JPanel { ...@@ -154,11 +108,55 @@ public class RespondPanel extends JPanel {
} }
public JTextField getHeaderField2() {
return headerField2;
}
public JPanel getRow() { public JPanel getRow() {
return row; return row;
} }
public void load(ResponseData data){
if (data.getResponseHeaders()!=null &&data.getResponseHeaders().size()>0){
for (String k : data.getResponseHeaders().keySet()){
JTextField newHeaderField = new JTextField(k);
newHeaderField.setEditable(false);
newHeaderField.setBorder(border);
JTextField newValueField = new JTextField(data.getResponseHeaders().get(k).toString());
newValueField.setEditable(false);
newValueField.setBorder(border);
JPanel new_center_header = new JPanel(new GridLayout(1, 2));
new_center_header.add(newHeaderField);
new_center_header.add(newValueField);
JPanel newHeader = new JPanel(new BorderLayout()) {
@Override
public Dimension getPreferredSize(){
return new Dimension(header_MainPanel.getSize().width,28);
}
};
newHeader.add(new_center_header, BorderLayout.CENTER);
mainCenterHeader_respond.add(newHeader);
}
}
if (data.isSuccessful()) {
massageBody.setText(data.getResponseString());
}else{
massageBody.setText("Error : "+(data.hasSyntaxError()?data.getSyntaxErrorLog():data.getErrorMessage()));
}
JLabel label1 = (JLabel) up_response.getComponent(0);
JLabel label2 = (JLabel) up_response.getComponent(1);
JLabel label3 = (JLabel) up_response.getComponent(2);
label2.setText(((data.getFinalTime()-data.getStartTime())/1000)+"s");
if (data.hasSyntaxError()){
label1.setText("Syntax Error");
}else {
String isOk = data.isSuccessful() ? "OK" : "Error";
label1.setText(data.getResponseStatus()+" "+isOk);
}
if (data.getSize()>1024){
label3.setText((Math.round(data.getSize()/1024*100.0)/100.0)+" KB");
}else {
label3.setText(data.getSize() + " Bytes");
}
}
} }
...@@ -99,7 +99,7 @@ public class Parser { ...@@ -99,7 +99,7 @@ public class Parser {
} }
static String findMethod(String v){ public static String findMethod(String v){
switch (v.toUpperCase().trim()){ switch (v.toUpperCase().trim()){
case "GET": case "GET":
case "POST": case "POST":
......
package com.insomnia.parser; package com.insomnia.parser;
import java.io.BufferedInputStream; import java.io.*;
import java.io.BufferedReader;
import java.io.DataOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.HttpURLConnection; import java.net.HttpURLConnection;
import java.net.MalformedURLException; import java.net.MalformedURLException;
import java.net.URL; import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.HashMap; import java.util.HashMap;
public class RequestLoader { public class RequestLoader {
...@@ -44,7 +39,7 @@ public class RequestLoader { ...@@ -44,7 +39,7 @@ public class RequestLoader {
try { try {
String mUrl = data.getUrl(); String mUrl = data.getUrl();
if (data.getUrl().equals(RequestData.GET)) { if (data.getMethod().equals(RequestData.GET)) {
if (mUrl.contains("?")) { if (mUrl.contains("?")) {
mUrl = mUrl + "&" + data.getBody(); mUrl = mUrl + "&" + data.getBody();
}else{ }else{
...@@ -158,9 +153,27 @@ public class RequestLoader { ...@@ -158,9 +153,27 @@ public class RequestLoader {
responseData.setSuccessful(true); responseData.setSuccessful(true);
//Save files //Save files
Saver.saveResponse(responseData); if (responseData.getRequestData().getOutput().equals("-null")){
File f = new File(System.getProperty("java.io.tmpdir"),"insomnia");
try{
FileOutputStream outputStream = new FileOutputStream(f);
int read;
byte[] bytes = new byte[1024];
while ((read = responseStream.read(bytes)) != -1) {
outputStream.write(bytes, 0, read);
}
}catch (IOException e) {
e.printStackTrace();
}
responseData.setSize(f.length());
responseData.res = new String(Files.readAllBytes(Paths.get(f.getAbsolutePath())), Charset.forName("utf-8"));
f.delete();
}else {
Saver.saveResponse(responseData);
}
if (data.isSaveRequest()) Saver.saveRequest(data); if (data.isSaveRequest()) Saver.saveRequest(data);
responseData.res = responseData.convertStreamToString(responseStream,true);
con.disconnect(); con.disconnect();
} else { } else {
......
...@@ -21,6 +21,7 @@ public class ResponseData { ...@@ -21,6 +21,7 @@ public class ResponseData {
private InputStream inputStream = null; private InputStream inputStream = null;
private Map<String, List<String>> responseHeaders; private Map<String, List<String>> responseHeaders;
private String errorMessage = ""; private String errorMessage = "";
private long size;
public ResponseData (RequestData data){ public ResponseData (RequestData data){
this.requestData = data; this.requestData = data;
...@@ -32,6 +33,14 @@ public class ResponseData { ...@@ -32,6 +33,14 @@ public class ResponseData {
return this; return this;
} }
public void setSize(long size) {
this.size = size;
}
public long getSize() {
return size;
}
public int getStatus() { public int getStatus() {
return status; return status;
} }
......
...@@ -6,6 +6,9 @@ import java.io.FileOutputStream; ...@@ -6,6 +6,9 @@ import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
import java.io.ObjectInputStream; import java.io.ObjectInputStream;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.nio.charset.Charset;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
...@@ -95,7 +98,7 @@ public class Saver { ...@@ -95,7 +98,7 @@ public class Saver {
return null; return null;
} }
public static void saveResponse(ResponseData data){ public static void saveResponse(ResponseData data) {
if (!data.getRequestData().getOutput().equals("-null")){ if (!data.getRequestData().getOutput().equals("-null")){
String fileName; String fileName;
if (data.getRequestData().getOutput().equals("-t")){ if (data.getRequestData().getOutput().equals("-t")){
...@@ -113,9 +116,13 @@ public class Saver { ...@@ -113,9 +116,13 @@ public class Saver {
while ((read = data.getInputStream().read(bytes)) != -1) { while ((read = data.getInputStream().read(bytes)) != -1) {
outputStream.write(bytes, 0, read); outputStream.write(bytes, 0, read);
} }
data.setSize(file.length());
data.res = new String(Files.readAllBytes(Paths.get(file.getAbsolutePath())), Charset.forName("utf-8"));
}catch (IOException e) { }catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
} }
......
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