http://git-wip-us.apache.org/repos/asf/ode/blob/4b87e5b1/bpel-test/src/test/java/org/apache/ode/test/RestExtensionActivitiesTest.java
----------------------------------------------------------------------
diff --git
a/bpel-test/src/test/java/org/apache/ode/test/RestExtensionActivitiesTest.java
b/bpel-test/src/test/java/org/apache/ode/test/RestExtensionActivitiesTest.java
index e300260..b1562de 100644
---
a/bpel-test/src/test/java/org/apache/ode/test/RestExtensionActivitiesTest.java
+++
b/bpel-test/src/test/java/org/apache/ode/test/RestExtensionActivitiesTest.java
@@ -1,20 +1,16 @@
/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
+ * Licensed to the Apache Software Foundation (ASF) under one or more
contributor license
+ * agreements. See the NOTICE file distributed with this work for additional
information regarding
+ * copyright ownership. The ASF licenses this file to you under the Apache
License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
License. You may obtain a
+ * copy of the License at
*
- * http://www.apache.org/licenses/LICENSE-2.0
+ * http://www.apache.org/licenses/LICENSE-2.0
*
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
+ * Unless required by applicable law or agreed to in writing, software
distributed under the License
+ * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
KIND, either express
+ * or implied. See the License for the specific language governing permissions
and limitations under
+ * the License.
*/
package org.apache.ode.test;
@@ -47,223 +43,231 @@ import com.sun.net.httpserver.HttpServer;
*/
public class RestExtensionActivitiesTest extends BPELTestAbstract {
- private HttpServer httpServer;
-
- private int port = 8085;
-
- @Override
- public void setUp() throws Exception {
- super.setUp();
-
- // Register the extension bundle at the ODE server
- _server.registerExtensionBundle(new
Bpel4RestLightExtensionBundle());
-
- // Start a test HTTP server for executing the REST extension
activities
- httpServer = HttpServer.create(new InetSocketAddress(port), 0);
-
- // Create handler to reply HTTP calls
- httpServer.createContext("/test", new HttpHandler() {
- public void handle(HttpExchange exchange) throws
IOException {
- handleHttpRequest(exchange);
- }
- });
-
- httpServer.start();
- }
-
- /**
- * Tests the "GET" REST extension activity.
- *
- * @throws Throwable
- */
- @Test
- public void testGetExtAct() throws Throwable {
- go("/bpel/2.0/TestRestGetExtAct");
- }
-
- /**
- * Tests the "POST" REST extension activity.
- *
- * @throws Throwable
- */
- @Test
- public void testPostExtAct() throws Throwable {
- go("/bpel/2.0/TestRestPostExtAct");
- }
-
- /**
- * Tests the "POST" REST extension activity with a static wrapped
request
- * message.
- *
- * @throws Throwable
- */
- @Test
- public void testPostExtActWithWrappedRequest() throws Throwable {
- go("/bpel/2.0/TestRestPostExtAct2");
- }
-
- /**
- * Tests the "PUT" REST extension activity.
- *
- * @throws Throwable
- */
- @Test
- public void testPutExtAct() throws Throwable {
- go("/bpel/2.0/TestRestPutExtAct");
- }
-
- /**
- * Tests the "DELETE" REST extension activity.
- *
- * @throws Throwable
- */
- @Test
- public void testDeleteExtAct() throws Throwable {
- go("/bpel/2.0/TestRestDeleteExtAct");
- }
-
- /**
- * Tests the HTTP status code variable of a REST extension activity.
- *
- * @throws Throwable
- */
- @Test
- public void testRestExtActStatusCode() throws Throwable {
- go("/bpel/2.0/TestRestExtActStatusCode");
- }
-
- /**
- * Tests a BPEL REST extension activity with complex type variables.
- *
- * @throws Throwable
- */
- @Test
- public void testRestExtActComplexTypeVar() throws Throwable {
- go("/bpel/2.0/TestRestExtActComplexTypeVar");
- }
-
- /**
- * Tests the "POST" REST extension activity with an invalid URL value
message.
- *
- * @throws Throwable
- */
- @Test
- public void testPostExtActWithWrongURL() throws Throwable {
- deploy("/bpel/2.0/TestPostExtActWithWrongURL");
-
- Invocation inv = addInvoke("REST-POST#1", new
QName("http://ode/bpel/unit-test.wsdl", "HelloService"), "hello",
-
"<message><TestPart>Hello</TestPart></message>", null);
- inv.expectedFinalStatus = MessageExchange.Status.FAULT;
- inv.expectedInvokeException = FaultException.class;
-
- go();
- }
-
- private void handleHttpRequest(HttpExchange exchange) throws
IOException {
- String method = exchange.getRequestMethod();
-
- if (method.toUpperCase().equals("GET")) {
- String response = "<service:getResponse
xmlns:service=\"http://www.example.org/restApi\">\n"
- + "
<service:result>GET response data</service:result>\n"
- + "
</service:getResponse>";
-
- byte[] bResponse = response.getBytes();
-
- exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK,
bResponse.length);
- exchange.getResponseBody().write(bResponse);
- exchange.close();
- } else if (method.toUpperCase().equals("POST")) {
- String request =
IOUtils.toString(exchange.getRequestBody());
-
- String requestValue = "";
- try {
- Node reqNode = DOMUtils.stringToDOM(request);
-
- NodeList list = reqNode.getChildNodes();
- int i = 0;
- while (i < list.getLength()) {
- Node node = list.item(i);
- if (node.getNodeType() ==
Node.ELEMENT_NODE && ((Element) node).getLocalName().equals("value")) {
- requestValue =
node.getTextContent();
- }
- i++;
- }
-
- String response = "<service:postResponse
xmlns:service=\"http://www.example.org/restApi\">\n"
- + "
<service:result>" + requestValue + " Result</service:result>\n"
- + "
</service:postResponse>";
-
- byte[] bResponse = response.getBytes();
-
-
exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, bResponse.length);
- exchange.getResponseBody().write(bResponse);
- } catch (SAXException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
-
-
exchange.sendResponseHeaders(HttpURLConnection.HTTP_INTERNAL_ERROR, 0);
- }
-
- exchange.close();
- } else if (method.toUpperCase().equals("PUT")) {
- String request =
IOUtils.toString(exchange.getRequestBody());
-
- String requestValue = "";
- try {
- Node reqNode = DOMUtils.stringToDOM(request);
-
- NodeList list = reqNode.getChildNodes();
- int i = 0;
- while (i < list.getLength()) {
- Node node = list.item(i);
- if (node.getNodeType() ==
Node.ELEMENT_NODE && ((Element) node).getLocalName().equals("value")) {
- requestValue =
node.getTextContent();
- }
- i++;
- }
-
- String response = "<service:putResponse
xmlns:service=\"http://www.example.org/restApi\">\n"
- + "
<service:result>" + requestValue + " Result</service:result>\n"
- + "
</service:putResponse>";
-
- byte[] bResponse = response.getBytes();
-
-
exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, bResponse.length);
- exchange.getResponseBody().write(bResponse);
- } catch (SAXException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
-
-
exchange.sendResponseHeaders(HttpURLConnection.HTTP_INTERNAL_ERROR, 0);
- }
-
- exchange.close();
- } else if (method.toUpperCase().equals("DELETE")) {
- if
(exchange.getRequestURI().getPath().endsWith("/test")) {
- String response = "<service:deleteResponse
xmlns:service=\"http://www.example.org/restApi\">\n"
- + "
<service:result>DELETE Method Test</service:result>\n"
- + "
</service:deleteResponse>";
-
- byte[] bResponse = response.getBytes();
-
-
exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK, bResponse.length);
- exchange.getResponseBody().write(bResponse);
- exchange.close();
- } else {
-
exchange.sendResponseHeaders(HttpURLConnection.HTTP_NOT_FOUND, 0);
- exchange.close();
- }
- } else {
-
exchange.sendResponseHeaders(HttpURLConnection.HTTP_NOT_FOUND, 0);
- exchange.close();
- }
- }
-
- @Override
- public void tearDown() throws Exception {
- super.tearDown();
-
- // Stop the server
- httpServer.stop(0);
- }
+ private HttpServer httpServer;
+
+ private int port = 8085;
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+
+ // Register the extension bundle at the ODE server
+ _server.registerExtensionBundle(new Bpel4RestLightExtensionBundle());
+
+ // Start a test HTTP server for executing the REST extension activities
+ httpServer = HttpServer.create(new InetSocketAddress(port), 0);
+
+ // Create handler to reply HTTP calls
+ httpServer.createContext("/test", new HttpHandler() {
+ public void handle(HttpExchange exchange) throws IOException {
+ handleHttpRequest(exchange);
+ }
+ });
+
+ httpServer.start();
+ }
+
+ /**
+ * Tests the "GET" REST extension activity.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testGetExtAct() throws Throwable {
+ go("/bpel/2.0/TestRestGetExtAct");
+ }
+
+ /**
+ * Tests the "POST" REST extension activity.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testPostExtAct() throws Throwable {
+ go("/bpel/2.0/TestRestPostExtAct");
+ }
+
+ /**
+ * Tests the "POST" REST extension activity with a static wrapped request
message.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testPostExtActWithWrappedRequest() throws Throwable {
+ go("/bpel/2.0/TestRestPostExtAct2");
+ }
+
+ /**
+ * Tests the "PUT" REST extension activity.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testPutExtAct() throws Throwable {
+ go("/bpel/2.0/TestRestPutExtAct");
+ }
+
+ /**
+ * Tests the "DELETE" REST extension activity.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testDeleteExtAct() throws Throwable {
+ go("/bpel/2.0/TestRestDeleteExtAct");
+ }
+
+ /**
+ * Tests the HTTP status code variable of a REST extension activity.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testRestExtActStatusCode() throws Throwable {
+ go("/bpel/2.0/TestRestExtActStatusCode");
+ }
+
+ /**
+ * Tests a BPEL REST extension activity with complex type variables.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testRestExtActComplexTypeVar() throws Throwable {
+ go("/bpel/2.0/TestRestExtActComplexTypeVar");
+ }
+
+ /**
+ * Tests the "POST" REST extension activity with an invalid URL value
message.
+ *
+ * @throws Throwable
+ */
+ @Test
+ public void testPostExtActWithWrongURL() throws Throwable {
+ deploy("/bpel/2.0/TestPostExtActWithWrongURL");
+
+ Invocation inv = addInvoke("REST-POST#1",
+ new QName("http://ode/bpel/unit-test.wsdl", "HelloService"),
"hello",
+ "<message><TestPart>Hello</TestPart></message>", null);
+ inv.expectedFinalStatus = MessageExchange.Status.FAULT;
+ inv.expectedInvokeException = FaultException.class;
+
+ go();
+ }
+
+ private void handleHttpRequest(HttpExchange exchange) throws IOException {
+ String method = exchange.getRequestMethod();
+
+ if (method.toUpperCase().equals("GET")) {
+ String response =
+ "<service:getResponse
xmlns:service=\"http://www.example.org/restApi\">\n"
+ + " <service:result>GET
response data</service:result>\n"
+ + " </service:getResponse>";
+
+ byte[] bResponse = response.getBytes();
+
+ exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK,
bResponse.length);
+ exchange.getResponseBody().write(bResponse);
+ exchange.close();
+ } else if (method.toUpperCase().equals("POST")) {
+ String request = IOUtils.toString(exchange.getRequestBody());
+
+ String requestValue = "";
+ try {
+ Node reqNode = DOMUtils.stringToDOM(request);
+
+ NodeList list = reqNode.getChildNodes();
+ int i = 0;
+ while (i < list.getLength()) {
+ Node node = list.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE
+ && ((Element)
node).getLocalName().equals("value")) {
+ requestValue = node.getTextContent();
+ }
+ i++;
+ }
+
+ String response =
+ "<service:postResponse
xmlns:service=\"http://www.example.org/restApi\">\n"
+ + " <service:result>" +
requestValue
+ + " Result</service:result>\n"
+ + "
</service:postResponse>";
+
+ byte[] bResponse = response.getBytes();
+
+ exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK,
bResponse.length);
+ exchange.getResponseBody().write(bResponse);
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+
+
exchange.sendResponseHeaders(HttpURLConnection.HTTP_INTERNAL_ERROR, 0);
+ }
+
+ exchange.close();
+ } else if (method.toUpperCase().equals("PUT")) {
+ String request = IOUtils.toString(exchange.getRequestBody());
+
+ String requestValue = "";
+ try {
+ Node reqNode = DOMUtils.stringToDOM(request);
+
+ NodeList list = reqNode.getChildNodes();
+ int i = 0;
+ while (i < list.getLength()) {
+ Node node = list.item(i);
+ if (node.getNodeType() == Node.ELEMENT_NODE
+ && ((Element)
node).getLocalName().equals("value")) {
+ requestValue = node.getTextContent();
+ }
+ i++;
+ }
+
+ String response =
+ "<service:putResponse
xmlns:service=\"http://www.example.org/restApi\">\n"
+ + " <service:result>" +
requestValue
+ + " Result</service:result>\n"
+ + " </service:putResponse>";
+
+ byte[] bResponse = response.getBytes();
+
+ exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK,
bResponse.length);
+ exchange.getResponseBody().write(bResponse);
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+
+
exchange.sendResponseHeaders(HttpURLConnection.HTTP_INTERNAL_ERROR, 0);
+ }
+
+ exchange.close();
+ } else if (method.toUpperCase().equals("DELETE")) {
+ if (exchange.getRequestURI().getPath().endsWith("/test")) {
+ String response =
+ "<service:deleteResponse
xmlns:service=\"http://www.example.org/restApi\">\n"
+ + "
<service:result>DELETE Method Test</service:result>\n"
+ + "
</service:deleteResponse>";
+
+ byte[] bResponse = response.getBytes();
+
+ exchange.sendResponseHeaders(HttpURLConnection.HTTP_OK,
bResponse.length);
+ exchange.getResponseBody().write(bResponse);
+ exchange.close();
+ } else {
+ exchange.sendResponseHeaders(HttpURLConnection.HTTP_NOT_FOUND,
0);
+ exchange.close();
+ }
+ } else {
+ exchange.sendResponseHeaders(HttpURLConnection.HTTP_NOT_FOUND, 0);
+ exchange.close();
+ }
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+
+ // Stop the server
+ httpServer.stop(0);
+ }
}