root/Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/http/HTTPGetConnection.java
| 365 | 366 | ||
|---|---|---|---|
16 | private Socket socket; | 16 | private Socket socket; |
17 | private PrintWriter outPutWriter; | 17 | private PrintWriter outPutWriter; |
18 | private BufferedReader inputReader; | 18 | private BufferedReader inputReader; |
19 | private String inputMessage; | ||
20 | private HTTPQ2AppChannel httpObject; | 19 | private HTTPQ2AppChannel httpObject; |
21 | 20 | ||
22 | public HTTPGetConnection(Socket accept, HTTPQ2AppChannel httpq2AppChannel) { | 21 | public HTTPGetConnection(Socket accept, HTTPQ2AppChannel httpq2AppChannel) { |
... | ... | ||
32 | 31 | ||
33 | private String getQueueName(String header) { | 32 | private String getQueueName(String header) { |
34 | // "GET /<<QueueNaam>> HTTP/1.1" | 33 | // "GET /<<QueueNaam>> HTTP/1.1" |
34 | if (header.indexOf("?") > 0) { // Has ID | ||
35 | return header.substring(5, header.indexOf("?ID=")); | ||
36 | } | ||
37 | // "GET /<<QueueNaam>> HTTP/1.1" | ||
35 | return header.substring(5, header.indexOf(" HTTP/1.1")); | 38 | return header.substring(5, header.indexOf(" HTTP/1.1")); |
36 | } | 39 | } |
37 | 40 | ||
38 | private void reply(String queryType) { | 41 | private void reply(String queryType) { |
39 | if (queryType.indexOf("?ID") > 0) { // Specifiek ID | 42 | if (queryType.indexOf("?ID=") > 0) { // Specifiek ID |
40 | this.replyId(this.getId(queryType)); | 43 | this.replyId(this.getId(queryType)); |
41 | } else { // Overzicht | 44 | } else { // Overzicht |
42 | this.replyList(); | 45 | this.replyList(); |
... | ... | ||
63 | 66 | ||
64 | // Luister naar input van gebruiker | 67 | // Luister naar input van gebruiker |
65 | try { | 68 | try { |
66 | String inputLine = inputReader.readLine().trim(); | 69 | String inputLine = inputReader.readLine(); |
67 | while (inputLine != null) { | 70 | while (inputLine != null) { |
68 | if (inputLine.startsWith("GET /")) { | 71 | if (inputLine.startsWith("GET /")) { |
69 | String queryType = this.getHttpQueueName(); | 72 | String queryType = this.getHttpQueueName(); |
70 | if (queryType.equals(this.getQueueName(inputLine))) { | 73 | String qName = this.getQueueName(inputLine); |
71 | this.reply(queryType); | 74 | if (queryType.equals(qName)) { |
75 | this.reply(inputLine); | ||
72 | break; | 76 | break; |
73 | } else { | 77 | } else { |
74 | System.err.println("Queue niet gevonden"); | 78 | System.err.println("Queue " + qName + " niet gevonden"); |
75 | outPutWriter.println("HTTP/1.1 404 Not Found"); | 79 | outPutWriter.println("HTTP/1.1 404 Not Found"); |
76 | break; | 80 | break; |
77 | } | 81 | } |
... | ... | ||
85 | outPutWriter.close(); | 89 | outPutWriter.close(); |
86 | inputReader.close(); | 90 | inputReader.close(); |
87 | 91 | ||
88 | // Print op scherm | ||
89 | // System.out.println(); | ||
90 | |||
91 | } catch (Exception e) { | 92 | } catch (Exception e) { |
92 | // do nothing | 93 | // do nothing |
93 | System.err.println("Fout in connectie"); | 94 | System.err.println("Fout in connectie"); |
... | ... | ||
134 | LinkedList<String> queued = this.httpObject.getSourceQueue().peekEntireQueue(); | 135 | LinkedList<String> queued = this.httpObject.getSourceQueue().peekEntireQueue(); |
135 | if (queued.size() > 0) { | 136 | if (queued.size() > 0) { |
136 | for (String inQueue : queued) { | 137 | for (String inQueue : queued) { |
137 | if (queryId == this.findId(inQueue)) { | 138 | if (queryId.equals(this.findId(inQueue))) { |
138 | outPutWriter.write("HTTP/1.1 200 OK\n"); | 139 | outPutWriter.write("HTTP/1.1 200 OK\n"); |
139 | outPutWriter.write("Content-Length=" + inQueue.length() + "\n"); | 140 | outPutWriter.write("Content-Length=" + inQueue.length() + "\n"); |
140 | outPutWriter.write(inQueue); | 141 | outPutWriter.write(inQueue); |
142 | |||
143 | // Verwijder | ||
144 | this.httpObject.getSourceQueue().deleteFromQueue(inQueue); | ||
145 | |||
141 | return; | 146 | return; |
142 | } | 147 | } |
143 | } | 148 | } |
Download diff