Commit 3162db31 authored by 9731301's avatar 9731301

add some changes

parent e891b2da
...@@ -8,11 +8,16 @@ ...@@ -8,11 +8,16 @@
<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$/src/com/insomnia/parser/Insomnia.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/Insomnia.java" afterDir="false" /> <change beforePath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/parser/RequestData.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/Insomnia/com/insomnia/parser/RequestData.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/com/insomnia/GUI/Insomnia.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/Insomnia.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/LeftPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/GUI/LeftPanel.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/parser/Parser.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/Parser.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/RequestData.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/com/insomnia/parser/RequestData.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/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" />
...@@ -153,7 +158,8 @@ ...@@ -153,7 +158,8 @@
<workItem from="1591205535989" duration="8740000" /> <workItem from="1591205535989" duration="8740000" />
<workItem from="1591376356200" duration="7395000" /> <workItem from="1591376356200" duration="7395000" />
<workItem from="1591474740815" duration="314000" /> <workItem from="1591474740815" duration="314000" />
<workItem from="1591548369519" duration="737000" /> <workItem from="1591548369519" duration="6526000" />
<workItem from="1591614811869" duration="23168000" />
</task> </task>
<servers /> <servers />
</component> </component>
...@@ -168,10 +174,10 @@ ...@@ -168,10 +174,10 @@
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="518" y="216" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1536.824@0.0.1536.824" timestamp="1591133961860" /> <state x="518" y="216" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1536.824@0.0.1536.824" timestamp="1591133961860" />
<state x="472" y="159" key="#com.intellij.ide.util.MemberChooser" timestamp="1591034675582"> <state x="472" y="159" key="#com.intellij.ide.util.MemberChooser" timestamp="1591640326733">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="472" y="159" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1591034675582" /> <state x="472" y="159" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1591640326733" />
<state x="499" y="197" key="#com.intellij.ide.util.TreeClassChooserDialog" timestamp="1590961999762"> <state x="499" y="197" key="#com.intellij.ide.util.TreeClassChooserDialog" timestamp="1590961999762">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
...@@ -180,38 +186,38 @@ ...@@ -180,38 +186,38 @@
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="499" y="160" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1536.824@0.0.1536.824" timestamp="1590603376669" /> <state x="499" y="160" key="#com.intellij.refactoring.safeDelete.UnsafeUsagesDialog/0.0.1536.824@0.0.1536.824" timestamp="1590603376669" />
<state x="369" y="145" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1" timestamp="1589304315504"> <state x="369" y="145" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1" timestamp="1591643836542">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="369" y="145" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1/0.0.1536.824@0.0.1536.824" timestamp="1589304315504" /> <state x="369" y="145" key="ANALYSIS_DLG_com.intellij.analysis.BaseAnalysisAction$1/0.0.1536.824@0.0.1536.824" timestamp="1591643836542" />
<state x="402" y="167" key="FileChooserDialogImpl" timestamp="1590494460700"> <state x="402" y="167" key="FileChooserDialogImpl" timestamp="1591643834959">
<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="1591643834959" />
<state width="1493" height="154" key="GridCell.Tab.0.bottom" timestamp="1591216845298"> <state width="1493" height="154" key="GridCell.Tab.0.bottom" timestamp="1591643837235">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="154" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1591216845298" /> <state width="1493" height="154" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1591643837235" />
<state width="1493" height="154" key="GridCell.Tab.0.center" timestamp="1591216845298"> <state width="1493" height="154" key="GridCell.Tab.0.center" timestamp="1591643837234">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="154" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1591216845298" /> <state width="1493" height="154" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1591643837234" />
<state width="1493" height="154" key="GridCell.Tab.0.left" timestamp="1591216845298"> <state width="1493" height="154" key="GridCell.Tab.0.left" timestamp="1591643837233">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="154" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1591216845298" /> <state width="1493" height="154" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1591643837233" />
<state width="1493" height="154" key="GridCell.Tab.0.right" timestamp="1591216845298"> <state width="1493" height="154" key="GridCell.Tab.0.right" timestamp="1591643837235">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state width="1493" height="154" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1591216845298" /> <state width="1493" height="154" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1591643837235" />
<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>
<state x="249" y="0" key="SettingsEditor/0.0.1536.824@0.0.1536.824" timestamp="1590962002174" /> <state x="249" y="0" key="SettingsEditor/0.0.1536.824@0.0.1536.824" timestamp="1590962002174" />
<state x="425" y="237" key="com.intellij.ide.util.TipDialog" timestamp="1591548525191"> <state x="425" y="237" key="com.intellij.ide.util.TipDialog" timestamp="1591614884627">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
<state x="425" y="237" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1591548525191" /> <state x="425" y="237" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1591614884627" />
<state x="499" y="179" key="extract.method.dialog" timestamp="1590145349556"> <state x="499" y="179" key="extract.method.dialog" timestamp="1590145349556">
<screen x="0" y="0" width="1536" height="824" /> <screen x="0" y="0" width="1536" height="824" />
</state> </state>
......
package com.insomnia.GUI; package com.insomnia.GUI;
import java.awt.*; import java.awt.*;
import java.io.IOException; import java.io.IOException;
......
...@@ -7,36 +7,25 @@ package com.insomnia.GUI; ...@@ -7,36 +7,25 @@ package com.insomnia.GUI;
import com.insomnia.parser.RequestData; import com.insomnia.parser.RequestData;
import com.insomnia.parser.ResponseData; 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.*;
import java.io.IOException; import java.io.IOException;
import static com.sun.glass.ui.Cursor.setVisible; import static com.sun.glass.ui.Cursor.setVisible;
import static java.awt.Frame.*; import static java.awt.Frame.*;
public class InsomniaGUI { public class InsomniaGUI {
JFrame frame ; private JFrame frame ;
RespondPanel response; private RespondPanel response;
RequestPanel request; private RequestPanel request;
ResponseData data_req = null; private ResponseData data_req = null;
public void load(ResponseData d){
data_req = d;
response.load(d);
}
public boolean hasRequest(){
return data_req!=null;
}
public void loadRequest (RequestData r){
request.load(r);
}
/**
* create a insomnia gui
* @throws IOException
*/
public InsomniaGUI() throws IOException { public InsomniaGUI() throws IOException {
frame = new JFrame(); frame = new JFrame();
frame.setTitle("Insomnia"); frame.setTitle("Insomnia");
...@@ -286,4 +275,75 @@ public class InsomniaGUI { ...@@ -286,4 +275,75 @@ public class InsomniaGUI {
} }
} }
/**
* this method is for loading data for sending data and get the response
* @param d
*/
public void load(ResponseData d){
data_req = d;
response.load(d);
}
/**
* this method checks that is there any request here or not
*/
public boolean hasRequest(){
return data_req!=null;
}
/**
* @param r is the request data
*/
public void loadRequest (RequestData r){
request.load(r);
}
/**
* @return the frame of app
*/
public JFrame getFrame() {
return frame;
}
/**
*set the frame of app
*/
public void setFrame(JFrame frame) {
this.frame = frame;
}
/**
* get the response panel
* @return the response panel
*/
public RespondPanel getResponse() {
return response;
}
/**
* set the response panel
*/
public void setResponse(RespondPanel response) {
this.response = response;
}
/**
*
* @return the request panel
*/
public RequestPanel getRequest() {
return request;
}
/**
*set the request panel
*/
public void setRequest(RequestPanel request) {
this.request = request;
}
public ResponseData getData_req() {
return data_req;
}
} }
...@@ -40,7 +40,7 @@ public class LeftPanel extends JPanel { ...@@ -40,7 +40,7 @@ public class LeftPanel extends JPanel {
public void mouseClicked(MouseEvent e) { public void mouseClicked(MouseEvent e) {
if (!main_class.hasRequest()){ if (!main_class.hasRequest()){
JOptionPane.showMessageDialog(main_class.frame,"You need to send a request first.","Error",JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(main_class.getFrame(),"You need to send a request first.","Error",JOptionPane.ERROR_MESSAGE);
return; return;
} }
JFrame newRequestFrame = new JFrame("request name"); JFrame newRequestFrame = new JFrame("request name");
...@@ -66,7 +66,7 @@ public class LeftPanel extends JPanel { ...@@ -66,7 +66,7 @@ public class LeftPanel extends JPanel {
newRequestFrame.setVisible(false); newRequestFrame.setVisible(false);
//Save Request //Save Request
ResponseData data = main_class.data_req; ResponseData data = main_class.getData_req();
data.getRequestData().setName(name); data.getRequestData().setName(name);
new Saver().saveRequestAndResponse(data); new Saver().saveRequestAndResponse(data);
//Add Request to list //Add Request to list
...@@ -74,7 +74,6 @@ public class LeftPanel extends JPanel { ...@@ -74,7 +74,6 @@ public class LeftPanel extends JPanel {
newRequest.addMouseListener(new MouseRequestClick(name)); newRequest.addMouseListener(new MouseRequestClick(name));
requestList.add(newRequest); requestList.add(newRequest);
requestList.validate(); requestList.validate();
//ToDo:add action listener to button requests
} }
}); });
} }
...@@ -98,10 +97,18 @@ public class LeftPanel extends JPanel { ...@@ -98,10 +97,18 @@ public class LeftPanel extends JPanel {
this.setBackground(Color.LIGHT_GRAY); this.setBackground(Color.LIGHT_GRAY);
} }
/**
*
* @return the addRequest button
*/
public JButton getAddRequest() { public JButton getAddRequest() {
return addRequest; return addRequest;
} }
/**
*
* @return the menu
*/
public JMenu getMenu() { public JMenu getMenu() {
return menu; return menu;
} }
...@@ -118,6 +125,7 @@ public class LeftPanel extends JPanel { ...@@ -118,6 +125,7 @@ public class LeftPanel extends JPanel {
return up_left; return up_left;
} }
private class MouseRequestClick extends MouseAdapter { private class MouseRequestClick extends MouseAdapter {
String name; String name;
MouseRequestClick(String name){ MouseRequestClick(String name){
......
/**
* represents a panel for requests
*/
package com.insomnia.GUI; package com.insomnia.GUI;
import com.insomnia.parser.*; import com.insomnia.parser.*;
import javax.imageio.ImageIO; import javax.imageio.ImageIO;
import javax.swing.*; import javax.swing.*;
import javax.swing.border.Border; import javax.swing.border.Border;
import javax.swing.text.Utilities;
import java.awt.*; import java.awt.*;
import java.awt.event.*; import java.awt.event.*;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.DataInput;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
...@@ -95,6 +95,9 @@ public class RequestPanel extends JPanel { ...@@ -95,6 +95,9 @@ public class RequestPanel extends JPanel {
return tabbedPaneCenterRequest; return tabbedPaneCenterRequest;
} }
/**
*this method is for adding headers
*/
private void addHeader(String... args){ private void addHeader(String... args){
try { try {
Border border = BorderFactory.createLineBorder(Color.BLACK, 3); Border border = BorderFactory.createLineBorder(Color.BLACK, 3);
...@@ -150,14 +153,30 @@ public class RequestPanel extends JPanel { ...@@ -150,14 +153,30 @@ public class RequestPanel extends JPanel {
} }
} }
/**
*
* @param c is component
* @return the component is the last one or not
*/
boolean isLastComponent(Component c){ boolean isLastComponent(Component c){
return isLastComponent(c,mainCenterHeader); return isLastComponent(c,mainCenterHeader);
} }
/**
*
* @param c is component
* @param p is a panel
* @return the component is the last one or not
*/
boolean isLastComponent(Component c,JPanel p){ boolean isLastComponent(Component c,JPanel p){
return p.getComponent(p.getComponentCount()-1)==c; return p.getComponent(p.getComponentCount()-1)==c;
} }
/**
*
* @return the headers
*/
public HashMap<String,String> getHeaders(){ public HashMap<String,String> getHeaders(){
HashMap<String,String> headers = new HashMap<>(); HashMap<String,String> headers = new HashMap<>();
for(Component c : mainCenterHeader.getComponents()){ for(Component c : mainCenterHeader.getComponents()){
...@@ -241,6 +260,10 @@ public class RequestPanel extends JPanel { ...@@ -241,6 +260,10 @@ public class RequestPanel extends JPanel {
int selectedItem = -2; int selectedItem = -2;
MouseAdapter body_insert = null; MouseAdapter body_insert = null;
/**
*create the body layout
*/
void initBody(String... args){ void initBody(String... args){
if (args.length==0 && selectedItem == Json_FormData.getSelectedIndex()) return; if (args.length==0 && selectedItem == Json_FormData.getSelectedIndex()) return;
selectedItem = Json_FormData.getSelectedIndex(); selectedItem = Json_FormData.getSelectedIndex();
...@@ -325,6 +348,9 @@ public class RequestPanel extends JPanel { ...@@ -325,6 +348,9 @@ public class RequestPanel extends JPanel {
} }
/**
*add component to the body
*/
private void addBody(String... args){ private void addBody(String... args){
Border border = BorderFactory.createLineBorder(Color.BLACK,3); Border border = BorderFactory.createLineBorder(Color.BLACK,3);
BufferedImage master = null; BufferedImage master = null;
...@@ -494,7 +520,10 @@ public class RequestPanel extends JPanel { ...@@ -494,7 +520,10 @@ public class RequestPanel extends JPanel {
} }
/**
*
* @return body panel
*/
public JPanel getBody() { public JPanel getBody() {
return body; return body;
} }
......
/**
* represents a panel for responds that contains response data and components and action listeners
* @zahra_fatehi
* @version 0.0
*/
package com.insomnia.GUI; package com.insomnia.GUI;
import com.insomnia.parser.ResponseData; 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.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
public class RespondPanel extends JPanel { public class RespondPanel extends JPanel {
private Border border = BorderFactory.createLineBorder(Color.BLACK,3); private Border border = BorderFactory.createLineBorder(Color.BLACK,3);
......
/**
* Parser represents a class to get data from console as sting and find and set requestData fields
* @zahra_fatehi
* @version 0.0
*/
package com.insomnia.parser; package com.insomnia.parser;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
public class Parser { public class Parser {
/**
*
* @param args are the fields data
* @return an arrayList of args
*/
public 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 = "";
...@@ -98,7 +107,11 @@ public class Parser { ...@@ -98,7 +107,11 @@ public class Parser {
return requestData; return requestData;
} }
/**
* this method is to find the kind of method we wanna use
* @param v is the name of method that maybe is with lower case or trim
* @return the expected method
*/
public static String findMethod(String v){ public static String findMethod(String v){
switch (v.toUpperCase().trim()){ switch (v.toUpperCase().trim()){
case "GET": case "GET":
...@@ -106,12 +119,16 @@ public class Parser { ...@@ -106,12 +119,16 @@ public class Parser {
case "DELETE": case "DELETE":
case "PUT": case "PUT":
return v.toUpperCase().trim(); return v.toUpperCase().trim();
default: default:
return "GET"; return "GET";
} }
} }
/**
*this method is to find the value
* @param v is the value which has \ at the beginning and at the end
* @return the expected value
*/
static String findParamValue(String v){ static String findParamValue(String v){
if (v.startsWith("\"") && v.endsWith("\"")){ if (v.startsWith("\"") && v.endsWith("\"")){
return v.substring(1,v.length()-1); return v.substring(1,v.length()-1);
...@@ -119,6 +136,11 @@ public class Parser { ...@@ -119,6 +136,11 @@ public class Parser {
return v; return v;
} }
/**
* this method is for finding args
* @param v is the ard with -
* @return the arg
*/
static String findArg (String v){ static String findArg (String v){
if (v.startsWith("--")){ if (v.startsWith("--")){
return v.substring(2); return v.substring(2);
......
/**
* this class represents a class which contains a method to load data from RequestData class and set the ResponseData class fields
*/
package com.insomnia.parser; package com.insomnia.parser;
import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.HttpsURLConnection;
import java.io.*; import java.io.*;
...@@ -10,7 +13,11 @@ import java.nio.file.Paths; ...@@ -10,7 +13,11 @@ import java.nio.file.Paths;
import java.util.HashMap; import java.util.HashMap;
public class RequestLoader { public class RequestLoader {
/**
* a method to load request data and get response data
* @param data is the information we get from request
*
*/
public static ResponseData run (RequestData data){ public static ResponseData run (RequestData data){
String boundary = "*****" + System.currentTimeMillis() + "*****"; String boundary = "*****" + System.currentTimeMillis() + "*****";
ResponseData responseData = new ResponseData(data); ResponseData responseData = new ResponseData(data);
......
/** /**
* ResponseData represents a class that contains responses data and has some methods to keep these information * ResponseData represents a class that contains responses data and has some methods to keep these information
* @zahra_fatehi
* @version 0.0
*/ */
package com.insomnia.parser; package com.insomnia.parser;
...@@ -19,20 +21,35 @@ public class ResponseData implements Serializable { ...@@ -19,20 +21,35 @@ public class ResponseData implements Serializable {
private String errorMessage = ""; private String errorMessage = "";
private long size; private long size;
/**
* create a response data with request data
* @param data is the request data
*/
public ResponseData (RequestData data){ public ResponseData (RequestData data){
this.requestData = data; this.requestData = data;
startTime = System.currentTimeMillis(); startTime = System.currentTimeMillis();
} }
/**
* @return the time of finishing finalTime
*/
public ResponseData finish(){ public ResponseData finish(){
finalTime = System.currentTimeMillis(); finalTime = System.currentTimeMillis();
return this; return this;
} }
/**
* set size of requestData
* @param size
*/
public void setSize(long size) { public void setSize(long size) {
this.size = size; this.size = size;
} }
/**
*
* @return the size of request data
*/
public long getSize() { public long getSize() {
return size; return size;
} }
...@@ -77,10 +94,18 @@ public class ResponseData implements Serializable { ...@@ -77,10 +94,18 @@ public class ResponseData implements Serializable {
return finalTime; return finalTime;
} }
/**
*
* @return the time of start processing data
*/
public long getStartTime() { public long getStartTime() {
return startTime; return startTime;
} }
/**
*
* @return true of processing is successful or not
*/
public boolean isSuccessful() { public boolean isSuccessful() {
return successful; return successful;
} }
...@@ -108,6 +133,10 @@ public class ResponseData implements Serializable { ...@@ -108,6 +133,10 @@ public class ResponseData implements Serializable {
this.errorMessage = errorMessage; this.errorMessage = errorMessage;
} }
/**
*
* @param status is the status of response data
*/
public void setStatus(int status) { public void setStatus(int status) {
this.status = status; this.status = status;
} }
......
/**
* represents a class that contains some methods to save requests
* @zahra_fatehi
* @version 0.0
*/
package com.insomnia.parser; package com.insomnia.parser;
import java.io.*; import java.io.*;
import java.nio.charset.Charset; import java.nio.charset.Charset;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Paths; import java.nio.file.Paths;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
public class Saver { public class Saver {
private static final String appName = "Insomnia"; private static final String appName = "Insomnia";
//get address of app /**
* get the direction app(insomnia)
* @return the the direction of he app as string
*/
public static String getDirApp(){ public static String getDirApp(){
return System.getProperty("user.dir"); return System.getProperty("user.dir");
} }
/**
* get the outputs of requests direction
* @return the address of where we save requests
*/
public static String getOutputDir(){ public static String getOutputDir(){
File f = new File(getDirApp(),"Outputs"); File f = new File(getDirApp(),"Outputs");
f.mkdir(); f.mkdir();
return f.toString(); return f.toString();
} }
/**
*
* @return
*/
public static String getRequestsDir(){ public static String getRequestsDir(){
File f = new File(getDirApp(),"Requests"); File f = new File(getDirApp(),"Requests");
f.mkdir(); f.mkdir();
...@@ -58,6 +72,10 @@ public class Saver { ...@@ -58,6 +72,10 @@ public class Saver {
} }
} }
/**
* this method saves the requests and their responses
* @param data is the request data
*/
public void saveRequestAndResponse (ResponseData data) { public void saveRequestAndResponse (ResponseData data) {
String fileName = data.getRequestData().getName()+".insomnia"; String fileName = data.getRequestData().getName()+".insomnia";
...@@ -77,6 +95,11 @@ public class Saver { ...@@ -77,6 +95,11 @@ public class Saver {
} }
} }
/**
* this method is for read responses from a file
* @param fileName is the name of the file where requests and responses will be save there
* @return the response data
*/
public ResponseData readRequestAndResponse (String fileName){ public ResponseData readRequestAndResponse (String fileName){
try { try {
FileInputStream file = new FileInputStream(new File(getRequestsDir(),fileName+".insomnia")); FileInputStream file = new FileInputStream(new File(getRequestsDir(),fileName+".insomnia"));
...@@ -93,6 +116,11 @@ public class Saver { ...@@ -93,6 +116,11 @@ public class Saver {
return null; return null;
} }
/**
* this method is for saving responses in a file
* @param data is the response data
* @param stream
*/
public static void saveResponse(ResponseData data, InputStream stream) { public static void saveResponse(ResponseData data, InputStream stream) {
if (!data.getRequestData().getOutput().equals("-null")){ if (!data.getRequestData().getOutput().equals("-null")){
String fileName; String fileName;
...@@ -121,6 +149,10 @@ public class Saver { ...@@ -121,6 +149,10 @@ public class Saver {
} }
} }
/**
* this method is for getting files
* @return the files of requests
*/
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