root/Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/http/HTTPConnection.java
| 355 | 356 | ||
|---|---|---|---|
1 | package hanze.ga.wt3.http; | 1 | package hanze.ga.wt3.http; |
2 | 2 | ||
3 | import hanze.ga.wt3.channels.ESBQueue; | ||
4 | |||
5 | import java.io.BufferedReader; | 3 | import java.io.BufferedReader; |
6 | import java.io.IOException; | 4 | import java.io.IOException; |
7 | import java.io.InputStreamReader; | 5 | import java.io.InputStreamReader; |
... | ... | ||
39 | try { | 37 | try { |
40 | String inputLine = inputReader.readLine().trim(); | 38 | String inputLine = inputReader.readLine().trim(); |
41 | while (inputLine != null) { | 39 | while (inputLine != null) { |
42 | |||
43 | if (inputLine.startsWith("POST /")) { | 40 | if (inputLine.startsWith("POST /")) { |
44 | if (this.getHttpQueueName().equals(this.getQueueName(inputLine))) { | 41 | if (this.getHttpQueueName().equals(this.getQueueName(inputLine))) { |
45 | this.handleValidRequest(); | 42 | this.handleValidRequest(); |
... | ... | ||
63 | // System.out.println(); | 60 | // System.out.println(); |
64 | 61 | ||
65 | } catch (Exception e) { | 62 | } catch (Exception e) { |
66 | e.printStackTrace(); | 63 | // do nothing |
64 | System.err.println("Fout in connectie"); | ||
67 | } | 65 | } |
68 | 66 | ||
69 | } | 67 | } |
... | ... | ||
82 | outPutWriter.println("HTTP/1.1 500 Bad Request"); | 80 | outPutWriter.println("HTTP/1.1 500 Bad Request"); |
83 | break; | 81 | break; |
84 | } | 82 | } |
85 | } else if (contentLength > 0) { | 83 | } else { |
86 | // Lees input in stringbuilder | 84 | // Lees input in stringbuilder |
87 | char[] tmp = new char[contentLength]; | 85 | char[] tmp = new char[contentLength]; |
88 | int index = 0; | 86 | int index = 0; |
... | ... | ||
92 | index += read; | 90 | index += read; |
93 | } | 91 | } |
94 | 92 | ||
93 | inputMessage.append("<message>"); | ||
95 | inputMessage.append(tmp); | 94 | inputMessage.append(tmp); |
96 | break; | 95 | break; |
97 | } | 96 | } |
98 | inputLine = inputReader.readLine(); | 97 | inputLine = inputReader.readLine().trim(); |
99 | } | 98 | } |
100 | 99 | ||
101 | } catch (Exception e) { | 100 | } catch (Exception e) { |
102 | e.printStackTrace(); | 101 | outPutWriter.println("HTTP/1.1 500 Bad Request"); |
103 | } | 102 | } |
104 | } | 103 | } |
105 | 104 | ||
... | ... | ||
113 | } | 112 | } |
114 | 113 | ||
115 | private void writeToQueue() { | 114 | private void writeToQueue() { |
116 | ESBQueue q = this.httpObject.getDestinationQueue(); | 115 | this.httpObject.getDestinationQueue().addToQueue(inputMessage.toString()); |
117 | q.addToQueue(q.getFreeId(), inputMessage.toString()); | ||
118 | } | 116 | } |
119 | 117 | ||
120 | @Override | 118 | @Override |
121 | public void run() { | 119 | public void run() { |
120 | // Open connection | ||
122 | this.initListen(); | 121 | this.initListen(); |
122 | |||
123 | // Input lezen | ||
123 | this.listenAndHandle(); | 124 | this.listenAndHandle(); |
125 | |||
126 | // Schrijf input naar Queue | ||
124 | this.writeToQueue(); | 127 | this.writeToQueue(); |
125 | } | 128 | } |
126 | 129 |
Download diff