root/Weektaken2/Weektaak3/ESB/src/hanze/ga/wt3/http/HTTPGetConnection.java
| 366 | 368 | ||
|---|---|---|---|
23 | this.httpObject = httpq2AppChannel; | 23 | this.httpObject = httpq2AppChannel; |
24 | } | 24 | } |
25 | 25 | ||
26 | private String findId(String inQueue) { | ||
27 | File tmpFile = new File("C:/queuetemp.tmp"); | ||
28 | try { | ||
29 | FileWriter fw = new FileWriter("C:/queuetemp.tmp"); | ||
30 | fw.write(inQueue); | ||
31 | fw.close(); | ||
32 | } catch (Exception e) { | ||
33 | // Doe niets | ||
34 | } | ||
35 | Xml xmlParser = new Xml("C:/queuetemp.tmp", "message"); | ||
36 | String reqId = xmlParser.child("id").content(); | ||
37 | tmpFile.delete(); | ||
38 | return reqId; | ||
39 | } | ||
40 | |||
41 | private String getHttpQueueName() { | ||
42 | return this.httpObject.getSourceQueue().getqName(); | ||
43 | } | ||
44 | |||
26 | private String getId(String queryType) { | 45 | private String getId(String queryType) { |
27 | int start = queryType.indexOf("?ID=") + 4; | 46 | int start = queryType.indexOf("?ID=") + 4; |
28 | queryType = queryType.replace(" HTTP/1.1", ""); | 47 | queryType = queryType.replace(" HTTP/1.1", ""); |
... | ... | ||
38 | return header.substring(5, header.indexOf(" HTTP/1.1")); | 57 | return header.substring(5, header.indexOf(" HTTP/1.1")); |
39 | } | 58 | } |
40 | 59 | ||
41 | private void reply(String queryType) { | ||
42 | if (queryType.indexOf("?ID=") > 0) { // Specifiek ID | ||
43 | this.replyId(this.getId(queryType)); | ||
44 | } else { // Overzicht | ||
45 | this.replyList(); | ||
46 | } | ||
47 | } | ||
48 | |||
49 | private String getHttpQueueName() { | ||
50 | return this.httpObject.getSourceQueue().getqName(); | ||
51 | } | ||
52 | |||
53 | private void initListen() { | 60 | private void initListen() { |
54 | System.out.println("[HTTPQ2AppChannel] Connection received from " | 61 | System.out.println("[HTTPQ2AppChannel] Connection received from " |
55 | + socket.getInetAddress().getHostName()); | 62 | + socket.getInetAddress().getHostName()); |
... | ... | ||
97 | 104 | ||
98 | } | 105 | } |
99 | 106 | ||
100 | private void replyList() { | 107 | private void reply(String queryType) { |
101 | LinkedList<String> queued = this.httpObject.getSourceQueue().peekEntireQueue(); | 108 | if (queryType.indexOf("?ID=") > 0) { // Specifiek ID |
102 | if (queued.size() > 0) { | 109 | this.replyId(this.getId(queryType)); |
103 | LinkedList<String> idOutput = new LinkedList<String>(); | 110 | } else { // Overzicht |
104 | int contentLength = 0; | 111 | this.replyList(); |
105 | for (String inQueue : queued) { | ||
106 | String inputId = "ID=" + this.findId(inQueue) + "\n"; | ||
107 | idOutput.add(inputId); | ||
108 | contentLength += inputId.length(); | ||
109 | } | ||
110 | outPutWriter.write("HTTP/1.1 200 OK\n"); | ||
111 | outPutWriter.write("Content-Length=" + contentLength + "\n"); | ||
112 | for (String id : idOutput) { | ||
113 | System.out.println(id); | ||
114 | outPutWriter.write(id.trim()); | ||
115 | } | ||
116 | } | 112 | } |
117 | } | 113 | } |
118 | 114 | ||
119 | private String findId(String inQueue) { | ||
120 | File tmpFile = new File("C:/queuetemp.tmp"); | ||
121 | try { | ||
122 | FileWriter fw = new FileWriter("C:/queuetemp.tmp"); | ||
123 | fw.write(inQueue); | ||
124 | fw.close(); | ||
125 | } catch (Exception e) { | ||
126 | // Doe niets | ||
127 | } | ||
128 | Xml xmlParser = new Xml("C:/queuetemp.tmp", "message"); | ||
129 | String reqId = xmlParser.child("id").content(); | ||
130 | tmpFile.delete(); | ||
131 | return reqId; | ||
132 | } | ||
133 | |||
134 | private void replyId(String queryId) { | 115 | private void replyId(String queryId) { |
135 | LinkedList<String> queued = this.httpObject.getSourceQueue().peekEntireQueue(); | 116 | LinkedList<String> queued = this.httpObject.getSourceQueue().peekEntireQueue(); |
136 | if (queued.size() > 0) { | 117 | if (queued.size() > 0) { |
... | ... | ||
150 | outPutWriter.write("HTTP/1.1 404 Not Found"); | 131 | outPutWriter.write("HTTP/1.1 404 Not Found"); |
151 | } | 132 | } |
152 | 133 | ||
134 | private void replyList() { | ||
135 | LinkedList<String> queued = this.httpObject.getSourceQueue().peekEntireQueue(); | ||
136 | if (queued.size() > 0) { | ||
137 | LinkedList<String> idOutput = new LinkedList<String>(); | ||
138 | int contentLength = 0; | ||
139 | for (String inQueue : queued) { | ||
140 | String inputId = "ID=" + this.findId(inQueue) + "\n"; | ||
141 | idOutput.add(inputId); | ||
142 | contentLength += inputId.length(); | ||
143 | } | ||
144 | outPutWriter.write("HTTP/1.1 200 OK\n"); | ||
145 | outPutWriter.write("Content-Length=" + contentLength + "\n"); | ||
146 | for (String id : idOutput) { | ||
147 | System.out.println(id); | ||
148 | outPutWriter.write(id.trim()); | ||
149 | } | ||
150 | } | ||
151 | } | ||
152 | |||
153 | @Override | 153 | @Override |
154 | public void run() { | 154 | public void run() { |
155 | // Open connection | 155 | // Open connection |
Download diff