@@ -96,6 +96,46 @@ public void testPostExtAct() throws Throwable {
96
96
public void testPostExtActWithWrappedRequest () throws Throwable {
97
97
go ("/bpel/2.0/TestRestPostExtAct2" );
98
98
}
99
+
100
+ /**
101
+ * Tests the "POST" REST extension activity without a request message specified.
102
+ *
103
+ * @throws Throwable
104
+ */
105
+ @ Test
106
+ public void testPostExtActWithoutRequest () throws Throwable {
107
+ go ("/bpel/2.0/TestRestPostExtActNoRequest" );
108
+ }
109
+
110
+ /**
111
+ * Tests the "POST" REST extension activity with undeclared request variable specified.
112
+ *
113
+ * @throws Throwable
114
+ */
115
+ @ Test
116
+ public void testPostExtActWithUndeclaredRequestVariable () throws Throwable {
117
+ go ("/bpel/2.0/TestRestPostExtActUndeclaredRequestVariable" );
118
+ }
119
+
120
+ /**
121
+ * Tests the "POST" REST extension activity with non-initialized request variable specified.
122
+ *
123
+ * @throws Throwable
124
+ */
125
+ @ Test
126
+ public void testPostExtActWithNonInitializedRequestVariable () throws Throwable {
127
+ go ("/bpel/2.0/TestRestPostExtActNonInitializedRequestVariable" );
128
+ }
129
+
130
+ /**
131
+ * Tests the "POST" REST extension activity with an empty request variable specified (variableName="").
132
+ *
133
+ * @throws Throwable
134
+ */
135
+ @ Test
136
+ public void testPostExtActWithEmptyRequestVariable () throws Throwable {
137
+ go ("/bpel/2.0/TestRestPostExtActEmptyRequestVariable" );
138
+ }
99
139
100
140
/**
101
141
* Tests the "PUT" REST extension activity.
@@ -106,6 +146,16 @@ public void testPostExtActWithWrappedRequest() throws Throwable {
106
146
public void testPutExtAct () throws Throwable {
107
147
go ("/bpel/2.0/TestRestPutExtAct" );
108
148
}
149
+
150
+ /**
151
+ * Tests the "PUT" REST extension activity without a request message specified..
152
+ *
153
+ * @throws Throwable
154
+ */
155
+ @ Test
156
+ public void testPutExtActWithoutRequest () throws Throwable {
157
+ go ("/bpel/2.0/TestRestPutExtActNoRequest" );
158
+ }
109
159
110
160
/**
111
161
* Tests the "DELETE" REST extension activity.
@@ -172,42 +222,56 @@ private void handleHttpRequest(HttpExchange exchange) throws IOException {
172
222
} else if (method .toUpperCase ().equals ("POST" )) {
173
223
String request = IOUtils .toString (exchange .getRequestBody ());
174
224
175
- String requestValue = "" ;
176
- try {
177
- Node reqNode = DOMUtils .stringToDOM (request );
178
-
179
- NodeList list = reqNode .getChildNodes ();
180
- int i = 0 ;
181
- while (i < list .getLength ()) {
182
- Node node = list .item (i );
183
- if (node .getNodeType () == Node .ELEMENT_NODE
184
- && ((Element ) node ).getLocalName ().equals ("value" )) {
185
- requestValue = node .getTextContent ();
225
+ if (request != null && !request .isEmpty ()) {
226
+ String requestValue = "" ;
227
+ try {
228
+ Node reqNode = DOMUtils .stringToDOM (request );
229
+
230
+ NodeList list = reqNode .getChildNodes ();
231
+ int i = 0 ;
232
+ while (i < list .getLength ()) {
233
+ Node node = list .item (i );
234
+ if (node .getNodeType () == Node .ELEMENT_NODE
235
+ && ((Element ) node ).getLocalName ().equals ("value" )) {
236
+ requestValue = node .getTextContent ();
237
+ }
238
+ i ++;
186
239
}
187
- i ++;
188
- }
189
240
190
- String response =
241
+ String response =
242
+ "<service:postResponse xmlns:service=\" http://www.example.org/restApi\" >\n "
243
+ + " <service:result>" + requestValue
244
+ + " Result</service:result>\n "
245
+ + " </service:postResponse>" ;
246
+
247
+ byte [] bResponse = response .getBytes ();
248
+
249
+ exchange .sendResponseHeaders (HttpURLConnection .HTTP_OK , bResponse .length );
250
+ exchange .getResponseBody ().write (bResponse );
251
+ } catch (SAXException e ) {
252
+ // TODO Auto-generated catch block
253
+ e .printStackTrace ();
254
+
255
+ exchange .sendResponseHeaders (HttpURLConnection .HTTP_INTERNAL_ERROR , 0 );
256
+ }
257
+ } else {
258
+ String response =
191
259
"<service:postResponse xmlns:service=\" http://www.example.org/restApi\" >\n "
192
- + " <service:result>" + requestValue
260
+ + " <service:result>" + "No request specified"
193
261
+ " Result</service:result>\n "
194
262
+ " </service:postResponse>" ;
195
263
196
264
byte [] bResponse = response .getBytes ();
197
265
198
266
exchange .sendResponseHeaders (HttpURLConnection .HTTP_OK , bResponse .length );
199
267
exchange .getResponseBody ().write (bResponse );
200
- } catch (SAXException e ) {
201
- // TODO Auto-generated catch block
202
- e .printStackTrace ();
203
-
204
- exchange .sendResponseHeaders (HttpURLConnection .HTTP_INTERNAL_ERROR , 0 );
205
268
}
206
269
207
270
exchange .close ();
208
271
} else if (method .toUpperCase ().equals ("PUT" )) {
209
272
String request = IOUtils .toString (exchange .getRequestBody ());
210
273
274
+ if (request != null && !request .isEmpty ()) {
211
275
String requestValue = "" ;
212
276
try {
213
277
Node reqNode = DOMUtils .stringToDOM (request );
@@ -239,6 +303,18 @@ private void handleHttpRequest(HttpExchange exchange) throws IOException {
239
303
240
304
exchange .sendResponseHeaders (HttpURLConnection .HTTP_INTERNAL_ERROR , 0 );
241
305
}
306
+ } else {
307
+ String response =
308
+ "<service:putResponse xmlns:service=\" http://www.example.org/restApi\" >\n "
309
+ + " <service:result>" + "No request specified"
310
+ + " Result</service:result>\n "
311
+ + " </service:putResponse>" ;
312
+
313
+ byte [] bResponse = response .getBytes ();
314
+
315
+ exchange .sendResponseHeaders (HttpURLConnection .HTTP_OK , bResponse .length );
316
+ exchange .getResponseBody ().write (bResponse );
317
+ }
242
318
243
319
exchange .close ();
244
320
} else if (method .toUpperCase ().equals ("DELETE" )) {
0 commit comments