Skip to content
Snippets Groups Projects
Commit 1f8375b9 authored by Jesper Fyhr Knudsen's avatar Jesper Fyhr Knudsen
Browse files

Add Request endpoint parsing

parent 74951720
Branches
No related tags found
No related merge requests found
...@@ -2,9 +2,8 @@ ...@@ -2,9 +2,8 @@
<project version="4"> <project version="4">
<component name="ChangeListManager"> <component name="ChangeListManager">
<list default="true" id="057f0053-f4e8-40ac-9d01-6a2f351d655a" name="Default" comment=""> <list default="true" id="057f0053-f4e8-40ac-9d01-6a2f351d655a" name="Default" comment="">
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/core/Request.java" />
<change type="NEW" beforePath="" afterPath="$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/core/Response.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/core/Request.java" afterPath="$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/core/Request.java" />
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/http/SimpleServer.java" afterPath="$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/http/SimpleServer.java" /> <change type="MODIFICATION" beforePath="$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/http/SimpleServer.java" afterPath="$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/http/SimpleServer.java" />
</list> </list>
<ignored path="parent-project.iws" /> <ignored path="parent-project.iws" />
...@@ -84,22 +83,8 @@ ...@@ -84,22 +83,8 @@
<file leaf-file-name="SimpleServer.java" pinned="false" current-in-tab="true"> <file leaf-file-name="SimpleServer.java" pinned="false" current-in-tab="true">
<entry file="file://$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/http/SimpleServer.java"> <entry file="file://$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/http/SimpleServer.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-263"> <state relative-caret-position="212">
<caret line="63" column="7" selection-start-line="63" selection-start-column="7" selection-end-line="63" selection-end-column="7" /> <caret line="69" column="0" selection-start-line="69" selection-start-column="0" selection-end-line="69" selection-end-column="0" />
<folding>
<element signature="imports" expanded="true" />
<element signature="e#1076#1077#0" expanded="true" />
<element signature="e#1110#1111#0" expanded="true" />
</folding>
</state>
</provider>
</entry>
</file>
<file leaf-file-name="Request.java" pinned="false" current-in-tab="false">
<entry file="file://$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/core/Request.java">
<provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="170">
<caret line="10" column="57" selection-start-line="10" selection-start-column="57" selection-end-line="10" selection-end-column="57" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
</folding> </folding>
...@@ -114,8 +99,6 @@ ...@@ -114,8 +99,6 @@
<caret line="10" column="23" selection-start-line="10" selection-start-column="23" selection-end-line="10" selection-end-column="23" /> <caret line="10" column="23" selection-start-line="10" selection-start-column="23" selection-end-line="10" selection-end-column="23" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#309#310#0" expanded="true" />
<element signature="e#360#361#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
...@@ -850,9 +833,9 @@ ...@@ -850,9 +833,9 @@
</PATH> </PATH>
</subPane> </subPane>
</pane> </pane>
<pane id="Scope" />
<pane id="PackagesPane" /> <pane id="PackagesPane" />
<pane id="Scratches" /> <pane id="Scratches" />
<pane id="Scope" />
</panes> </panes>
</component> </component>
<component name="PropertiesComponent"> <component name="PropertiesComponent">
...@@ -1491,44 +1474,45 @@ ...@@ -1491,44 +1474,45 @@
<workItem from="1466680301868" duration="4041000" /> <workItem from="1466680301868" duration="4041000" />
<workItem from="1466691045796" duration="601000" /> <workItem from="1466691045796" duration="601000" />
<workItem from="1466764339577" duration="7277000" /> <workItem from="1466764339577" duration="7277000" />
<workItem from="1467023521811" duration="6520000" /> <workItem from="1467023521811" duration="7535000" />
<workItem from="1467103515684" duration="3986000" />
</task> </task>
<servers /> <servers />
</component> </component>
<component name="TestHistory"> <component name="TestHistory">
<history-entry file="SimpleServerTest_nothing - 2016.06.27 at 16h 14m 55s.xml"> <history-entry file="SimpleServerTest_nothing - 2016.06.28 at 11h 38m 14s.xml">
<configuration name="SimpleServerTest.nothing" configurationId="JUnit" /> <configuration name="SimpleServerTest.nothing" configurationId="JUnit" />
</history-entry> </history-entry>
<history-entry file="SimpleServerTest_nothing - 2016.06.27 at 16h 15m 59s.xml"> <history-entry file="SimpleServerTest_nothing - 2016.06.28 at 11h 39m 04s.xml">
<configuration name="SimpleServerTest.nothing" configurationId="JUnit" /> <configuration name="SimpleServerTest.nothing" configurationId="JUnit" />
</history-entry> </history-entry>
<history-entry file="SimpleServerTest_nothing - 2016.06.27 at 16h 25m 08s.xml"> <history-entry file="SimpleServerTest_nothing - 2016.06.28 at 11h 40m 31s.xml">
<configuration name="SimpleServerTest.nothing" configurationId="JUnit" /> <configuration name="SimpleServerTest.nothing" configurationId="JUnit" />
</history-entry> </history-entry>
<history-entry file="SimpleServerTest_nothing - 2016.06.27 at 16h 28m 56s.xml"> <history-entry file="SimpleServerTest_nothing - 2016.06.28 at 11h 41m 36s.xml">
<configuration name="SimpleServerTest.nothing" configurationId="JUnit" /> <configuration name="SimpleServerTest.nothing" configurationId="JUnit" />
</history-entry> </history-entry>
<history-entry file="SimpleServerTest_nothing - 2016.06.27 at 16h 35m 22s.xml"> <history-entry file="SimpleServerTest_nothing - 2016.06.28 at 11h 42m 16s.xml">
<configuration name="SimpleServerTest.nothing" configurationId="JUnit" /> <configuration name="SimpleServerTest.nothing" configurationId="JUnit" />
</history-entry> </history-entry>
<history-entry file="SimpleServerTest_nothing - 2016.06.27 at 16h 36m 22s.xml"> <history-entry file="SimpleServerTest_nothing - 2016.06.28 at 11h 44m 11s.xml">
<configuration name="SimpleServerTest.nothing" configurationId="JUnit" /> <configuration name="SimpleServerTest.nothing" configurationId="JUnit" />
</history-entry> </history-entry>
<history-entry file="SimpleServerTest_nothing - 2016.06.27 at 16h 37m 07s.xml"> <history-entry file="SimpleServerTest_nothing - 2016.06.28 at 11h 44m 23s.xml">
<configuration name="SimpleServerTest.nothing" configurationId="JUnit" /> <configuration name="SimpleServerTest.nothing" configurationId="JUnit" />
</history-entry> </history-entry>
<history-entry file="SimpleServerTest_nothing - 2016.06.27 at 16h 37m 36s.xml"> <history-entry file="SimpleServerTest_nothing - 2016.06.28 at 11h 45m 14s.xml">
<configuration name="SimpleServerTest.nothing" configurationId="JUnit" /> <configuration name="SimpleServerTest.nothing" configurationId="JUnit" />
</history-entry> </history-entry>
<history-entry file="SimpleServerTest_nothing - 2016.06.27 at 16h 41m 18s.xml"> <history-entry file="SimpleServerTest_nothing - 2016.06.28 at 11h 50m 48s.xml">
<configuration name="SimpleServerTest.nothing" configurationId="JUnit" /> <configuration name="SimpleServerTest.nothing" configurationId="JUnit" />
</history-entry> </history-entry>
<history-entry file="SimpleServerTest_nothing - 2016.06.27 at 16h 42m 04s.xml"> <history-entry file="SimpleServerTest_nothing - 2016.06.28 at 11h 51m 54s.xml">
<configuration name="SimpleServerTest.nothing" configurationId="JUnit" /> <configuration name="SimpleServerTest.nothing" configurationId="JUnit" />
</history-entry> </history-entry>
</component> </component>
<component name="TimeTrackingManager"> <component name="TimeTrackingManager">
<option name="totallyTimeSpent" value="23105000" /> <option name="totallyTimeSpent" value="28106000" />
</component> </component>
<component name="ToolWindowManager"> <component name="ToolWindowManager">
<frame x="-8" y="-8" width="1936" height="1056" extended-state="6" /> <frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
...@@ -1542,12 +1526,13 @@ ...@@ -1542,12 +1526,13 @@
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="11" side_tool="true" content_ui="tabs" /> <window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="11" side_tool="true" content_ui="tabs" />
<window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.096875" sideWeight="0.4973404" order="4" side_tool="false" content_ui="tabs" /> <window_info id="Maven Projects" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.096875" sideWeight="0.4973404" order="4" side_tool="false" content_ui="tabs" />
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" /> <window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="9" side_tool="false" content_ui="tabs" />
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.2410148" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> <window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24312897" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" /> <window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="10" side_tool="false" content_ui="tabs" />
<window_info id="Capture Tool" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" /> <window_info id="Capture Tool" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
<window_info id="Designer" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" /> <window_info id="Designer" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.1734375" sideWeight="0.4974055" order="0" side_tool="false" content_ui="combo" /> <window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.1734375" sideWeight="0.4974055" order="0" side_tool="false" content_ui="combo" />
<window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" /> <window_info id="Database" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.23150106" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" /> <window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" /> <window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
<window_info id="UI Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" /> <window_info id="UI Designer" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
...@@ -1560,7 +1545,6 @@ ...@@ -1560,7 +1545,6 @@
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="3" side_tool="false" content_ui="combo" /> <window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="3" side_tool="false" content_ui="combo" />
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" /> <window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
<window_info id="Coverage" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.108072914" sideWeight="0.50265956" order="0" side_tool="true" content_ui="tabs" /> <window_info id="Coverage" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.108072914" sideWeight="0.50265956" order="0" side_tool="true" content_ui="tabs" />
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.23206107" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
</layout> </layout>
</component> </component>
<component name="Vcs.Log.UiProperties"> <component name="Vcs.Log.UiProperties">
...@@ -1893,17 +1877,6 @@ ...@@ -1893,17 +1877,6 @@
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="17"> <state relative-caret-position="17">
<caret line="32" column="0" selection-start-line="32" selection-start-column="0" selection-end-line="32" selection-end-column="0" /> <caret line="32" column="0" selection-start-line="32" selection-start-column="0" selection-end-line="32" selection-end-column="0" />
<folding>
<element signature="n#!!doc" expanded="false" />
<element signature="e#1352#1353#0" expanded="false" />
<element signature="e#1386#1387#0" expanded="false" />
<element signature="e#2055#2056#0" expanded="false" />
<element signature="e#2101#2102#0" expanded="false" />
<element signature="e#2784#2785#0" expanded="false" />
<element signature="e#2829#2830#0" expanded="false" />
<element signature="e#3023#3024#0" expanded="false" />
<element signature="e#3048#3049#0" expanded="false" />
</folding>
</state> </state>
</provider> </provider>
</entry> </entry>
...@@ -1947,26 +1920,23 @@ ...@@ -1947,26 +1920,23 @@
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="102"> <state relative-caret-position="102">
<caret line="14" column="21" selection-start-line="14" selection-start-column="17" selection-end-line="14" selection-end-column="21" /> <caret line="14" column="21" selection-start-line="14" selection-start-column="17" selection-end-line="14" selection-end-column="21" />
<folding />
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/core/Response.java"> <entry file="file://$PROJECT_DIR$/octopus-commons/src/test/java/com/chaos/octopus/commons/core/http/test/SimpleServerTest.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="170"> <state relative-caret-position="204">
<caret line="10" column="23" selection-start-line="10" selection-start-column="23" selection-end-line="10" selection-end-column="23" /> <caret line="12" column="0" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#309#310#0" expanded="true" />
<element signature="e#360#361#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/octopus-commons/src/test/java/com/chaos/octopus/commons/core/http/test/SimpleServerTest.java"> <entry file="file://$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/core/Response.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="204"> <state relative-caret-position="170">
<caret line="12" column="0" selection-start-line="12" selection-start-column="0" selection-end-line="12" selection-end-column="0" /> <caret line="10" column="23" selection-start-line="10" selection-start-column="23" selection-end-line="10" selection-end-column="23" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
</folding> </folding>
...@@ -1975,22 +1945,21 @@ ...@@ -1975,22 +1945,21 @@
</entry> </entry>
<entry file="file://$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/core/Request.java"> <entry file="file://$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/core/Request.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="170"> <state relative-caret-position="187">
<caret line="10" column="57" selection-start-line="10" selection-start-column="57" selection-end-line="10" selection-end-column="57" /> <caret line="12" column="9" selection-start-line="12" selection-start-column="9" selection-end-line="12" selection-end-column="9" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="e#277#278#0" expanded="true" />
<element signature="e#311#312#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
</entry> </entry>
<entry file="file://$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/http/SimpleServer.java"> <entry file="file://$PROJECT_DIR$/octopus-commons/src/main/java/com/chaos/octopus/commons/http/SimpleServer.java">
<provider selected="true" editor-type-id="text-editor"> <provider selected="true" editor-type-id="text-editor">
<state relative-caret-position="-263"> <state relative-caret-position="212">
<caret line="63" column="7" selection-start-line="63" selection-start-column="7" selection-end-line="63" selection-end-column="7" /> <caret line="69" column="0" selection-start-line="69" selection-start-column="0" selection-end-line="69" selection-end-column="0" />
<folding> <folding>
<element signature="imports" expanded="true" /> <element signature="imports" expanded="true" />
<element signature="e#1076#1077#0" expanded="true" />
<element signature="e#1110#1111#0" expanded="true" />
</folding> </folding>
</state> </state>
</provider> </provider>
......
...@@ -7,6 +7,10 @@ import java.util.Map; ...@@ -7,6 +7,10 @@ import java.util.Map;
* Created by Jesper on 27-06-2016. * Created by Jesper on 27-06-2016.
*/ */
public class Request { public class Request {
public String method; public String endpoint;
public Map<String, String> queryString = new HashMap<>(); public Map<String, String> queryString = new HashMap<>();
public Request(String endpoint){
this.endpoint = endpoint;
}
} }
...@@ -8,6 +8,10 @@ import java.io.UnsupportedEncodingException; ...@@ -8,6 +8,10 @@ import java.io.UnsupportedEncodingException;
import java.net.*; import java.net.*;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.Queue;
import java.util.concurrent.ConcurrentLinkedQueue;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
/** /**
* Created by Jesper on 23-06-2016. * Created by Jesper on 23-06-2016.
...@@ -35,7 +39,8 @@ public class SimpleServer implements Runnable{ ...@@ -35,7 +39,8 @@ public class SimpleServer implements Runnable{
@Override @Override
public void run() { public void run() {
while (_isRunning) { while (_isRunning) {
try(Socket socket = _serverSocket.accept()){ try{
Socket socket = _serverSocket.accept();
new HttpRequestHandler(socket).invoke(); new HttpRequestHandler(socket).invoke();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
...@@ -53,17 +58,18 @@ public class SimpleServer implements Runnable{ ...@@ -53,17 +58,18 @@ public class SimpleServer implements Runnable{
public void invoke() throws IOException { public void invoke() throws IOException {
while(socket.getInputStream().available() == 0); while(socket.getInputStream().available() == 0);
Request requestString = parseRequest(); Request request = parseRequest();
Response res = new Response(); Response res = new Response();
Response.Result result = res.new Result(); Response.Result result = res.new Result();
res.Results.add(result); res.Results.add(result);
for (String val : requestString.queryString.values()) { for (String val : request.queryString.values()) {
result.Keys.add(val); result.Keys.add(val);
} }
SendResponse(res); SendResponse(res);
socket.close();
} }
private Request parseRequest() throws IOException { private Request parseRequest() throws IOException {
...@@ -76,18 +82,26 @@ public class SimpleServer implements Runnable{ ...@@ -76,18 +82,26 @@ public class SimpleServer implements Runnable{
requestString += new String(buffer); requestString += new String(buffer);
} }
Request request = new Request(); int startOfEndpoint = requestString.indexOf(" ");
request.method = "GET"; int endOfEndpoint = requestString.indexOf("?") != -1 ?
requestString.indexOf("?"):
requestString.lastIndexOf("HTTP/");
String endpoint = requestString.substring(startOfEndpoint, endOfEndpoint).trim();
Request request = new Request(endpoint);
request.queryString = parseQueryString(requestString); request.queryString = parseQueryString(requestString);
return request; return request;
} }
private Map<String, String> parseQueryString(String requestString) throws UnsupportedEncodingException { private Map<String, String> parseQueryString(String requestString) throws UnsupportedEncodingException {
String query = requestString.substring(6, requestString.indexOf("HTTP"));
query = URLDecoder.decode(query.trim(), "UTF-8");
Map<String, String> parameters = new HashMap<>(); Map<String, String> parameters = new HashMap<>();
int startOfQueryString = requestString.indexOf("?");
if(startOfQueryString == -1) return parameters;
String query = requestString.substring(startOfQueryString +1, requestString.indexOf("HTTP"));
query = URLDecoder.decode(query.trim(), "UTF-8");
if("".equals(query)) return parameters; if("".equals(query)) return parameters;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment