| | 22 | private String getHttpQueueName() { |
| | 23 | return this.httpObject.getDestinationQueue().getqName(); |
| | 24 | } |
| | 25 | |
| | 26 | private String getQueueName(String header) { |
| | 27 | // "POST /<<QueueNaam>> HTTP/1.1" |
| | 28 | return header.substring(6, header.indexOf(" HTTP/1.1")); |
| | 29 | } |
| | 30 | |
| | 31 | private void handleValidRequest() { |
| | 32 | int contentLength = 0; |
| | 33 | try { |
| | 34 | String inputLine = inputReader.readLine().trim(); |
| | 35 | while (inputLine != null) { |
| | 36 | if (inputLine.startsWith("Content-Length=")) { |
| | 37 | // Content length oplezen |
| | 38 | try { |
| | 39 | contentLength = Integer.parseInt(inputLine.substring(15)); |
| | 40 | } catch (Exception e) { |
| | 41 | outPutWriter.println("HTTP/1.1 500 Bad Request"); |
| | 42 | break; |
| | 43 | } |
| | 44 | } else { |
| | 45 | inputMessage = inputLine; |
| | 46 | break; |
| | 47 | } |
| | 48 | inputLine = inputReader.readLine().trim(); |
| | 49 | } |
| | 50 | |
| | 51 | } catch (Exception e) { |
| | 52 | outPutWriter.println("HTTP/1.1 500 Bad Request"); |
| | 53 | } |
| | 54 | } |
| | 55 | |
69 | private void handleValidRequest() { | | |
70 | int contentLength = 0; | | |
71 | this.inputMessage = new StringBuilder(); | | |
72 | try { | | |
73 | String inputLine = inputReader.readLine().trim(); | | |
74 | while (inputLine != null) { | | |
75 | if (inputLine.startsWith("Content-Length=")) { | | |
76 | // Content length oplezen | | |
77 | try { | | |
78 | contentLength = Integer.parseInt(inputLine.substring(15)); | | |
79 | } catch (Exception e) { | | |
80 | outPutWriter.println("HTTP/1.1 500 Bad Request"); | | |
81 | break; | | |
82 | } | | |
83 | } else { | | |
84 | // Lees input in stringbuilder | | |
85 | char[] tmp = new char[contentLength]; | | |
86 | int index = 0; | | |
87 | int read = 0; | | |
88 | while (index < contentLength | | |
89 | && (read = inputReader.read(tmp, index, contentLength - index)) >= 0) { | | |
90 | index += read; | | |
91 | } | | |
92 | | | |
93 | inputMessage.append("<message>"); | | |
94 | inputMessage.append(tmp); | | |
95 | break; | | |
96 | } | | |
97 | inputLine = inputReader.readLine().trim(); | | |
98 | } | | |
99 | | | |
100 | } catch (Exception e) { | | |
101 | outPutWriter.println("HTTP/1.1 500 Bad Request"); | | |
102 | } | | |
103 | } | | |
104 | | | |
105 | private String getHttpQueueName() { | | |
106 | return this.httpObject.getDestinationQueue().getqName(); | | |
107 | } | | |
108 | | | |
109 | private String getQueueName(String header) { | | |
110 | // "POST /<<QueueNaam>> HTTP/1.1" | | |
111 | return header.substring(6, header.indexOf(" HTTP/1.1")); | | |
112 | } | | |
113 | | | |
114 | private void writeToQueue() { | | |
115 | this.httpObject.getDestinationQueue().addToQueue(inputMessage.toString()); | | |
116 | } | | |
117 | | | |