summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-04-27 21:43:08 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2010-04-27 21:43:08 +0000
commitf67991dfc3c5a924e684b7071810dca7055d2fe6 (patch)
tree4d07fa3444e0dbbd7738bea4622d00928ce32181 /sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca
parent3f0c8d9c3553f5f49e79c35f0c269983db9adeb8 (diff)
Operation selector implementation that uses JAX-RS annotations to map http requests to properly annotated REST interfaces
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@938687 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca')
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java109
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorProviderFctory.java52
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorReferenceProvider.java50
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorServiceProvider.java57
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java63
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java15
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java18
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java6
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java5
-rw-r--r--sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java6
10 files changed, 364 insertions, 17 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
new file mode 100644
index 0000000000..199ba0a696
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
@@ -0,0 +1,109 @@
+/*
+ * 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
+ *
+ * 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.tuscany.sca.binding.rest.operationselector.jaxrs.provider;
+
+import java.util.List;
+
+import javax.ws.rs.DELETE;
+import javax.ws.rs.GET;
+import javax.ws.rs.POST;
+import javax.ws.rs.PUT;
+
+import org.apache.tuscany.sca.common.http.HTTPContext;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeComponentService;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * JAXRS operation selector Interceptor.
+ *
+ * @version $Rev$ $Date$
+*/
+public class JAXRSOperationSelectorInterceptor implements Interceptor {
+ private ExtensionPointRegistry extensionPoints;
+ private RuntimeEndpoint endpoint;
+
+ private RuntimeComponentService service;
+ private InterfaceContract interfaceContract;
+ private List<Operation> serviceOperations;
+
+ private Invoker next;
+
+ public JAXRSOperationSelectorInterceptor(ExtensionPointRegistry extensionPoints, RuntimeEndpoint endpoint) {
+ this.extensionPoints = extensionPoints;
+ this.endpoint = endpoint;
+
+ this.service = (RuntimeComponentService)endpoint.getService();
+ this.interfaceContract = service.getInterfaceContract();
+ this.serviceOperations = service.getInterfaceContract().getInterface().getOperations();
+ }
+
+ public Invoker getNext() {
+ return next;
+ }
+
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ public Message invoke(Message msg) {
+ HTTPContext bindingContext = (HTTPContext) msg.getBindingContext();
+
+ Operation operation = findOperation(bindingContext.getHttpRequest().getMethod());
+
+ msg.setOperation(operation);
+
+ return getNext().invoke(msg);
+ }
+
+ /**
+ * Find the operation from the component service contract
+ * @param componentService
+ * @param http_method
+ * @return
+ */
+ private Operation findOperation(String http_method) {
+ List<Operation> operations = null;
+
+ if(http_method.equalsIgnoreCase("get")) {
+ operations = (List<Operation>) interfaceContract.getInterface().getAttributes().get(GET.class);
+ }else if(http_method.equalsIgnoreCase("put")) {
+ operations = (List<Operation>) interfaceContract.getInterface().getAttributes().get(PUT.class);
+ }else if(http_method.equalsIgnoreCase("post")) {
+ operations = (List<Operation>) interfaceContract.getInterface().getAttributes().get(POST.class);
+ }else if(http_method.equalsIgnoreCase("delete")) {
+ operations = (List<Operation>) interfaceContract.getInterface().getAttributes().get(DELETE.class);
+ }
+
+ Operation result = null;
+ if(operations != null) {
+ if(! operations.isEmpty()) {
+ result = operations.get(0);
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorProviderFctory.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorProviderFctory.java
new file mode 100644
index 0000000000..12a90d8fbb
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorProviderFctory.java
@@ -0,0 +1,52 @@
+/*
+ * 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
+ *
+ * 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.tuscany.sca.binding.rest.operationselector.jaxrs.provider;
+
+import org.apache.tuscany.sca.binding.rest.operationselector.jaxrs.JAXRSOperationSelector;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.provider.OperationSelectorProvider;
+import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * JAXRS operation selector Provider Factory.
+ *
+ * @version $Rev$ $Date$
+*/
+public class JAXRSOperationSelectorProviderFctory implements OperationSelectorProviderFactory<JAXRSOperationSelector>{
+ private ExtensionPointRegistry extensionPoints;
+
+ public JAXRSOperationSelectorProviderFctory(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+ }
+ public OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeEndpointReference endpointReference) {
+ return new JAXRSOperationSelectorReferenceProvider(extensionPoints, endpointReference);
+ }
+
+ public OperationSelectorProvider createServiceOperationSelectorProvider(RuntimeEndpoint endpoint) {
+ return new JAXRSOperationSelectorServiceProvider(extensionPoints, endpoint);
+ }
+
+ public Class<JAXRSOperationSelector> getModelType() {
+ return JAXRSOperationSelector.class;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorReferenceProvider.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorReferenceProvider.java
new file mode 100644
index 0000000000..c560a13ae2
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorReferenceProvider.java
@@ -0,0 +1,50 @@
+/*
+ * 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
+ *
+ * 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.tuscany.sca.binding.rest.operationselector.jaxrs.provider;
+
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.OperationSelectorProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+/**
+ * JAXRS operation selector Reference Provider.
+ *
+ * @version $Rev$ $Date$
+*/
+public class JAXRSOperationSelectorReferenceProvider implements OperationSelectorProvider {
+ private ExtensionPointRegistry extensionPoints;
+ private RuntimeEndpointReference endpointReference;
+
+ public JAXRSOperationSelectorReferenceProvider(ExtensionPointRegistry extensionPoints, RuntimeEndpointReference endpointReference ) {
+ this.extensionPoints = extensionPoints;
+ this.endpointReference = endpointReference;
+ }
+
+ public Interceptor createInterceptor() {
+ return null;
+ }
+
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_OPERATION_SELECTOR;
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorServiceProvider.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorServiceProvider.java
new file mode 100644
index 0000000000..105c84ebda
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorServiceProvider.java
@@ -0,0 +1,57 @@
+/*
+ * 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
+ *
+ * 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.tuscany.sca.binding.rest.operationselector.jaxrs.provider;
+
+import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.binding.rest.operationselector.jaxrs.JAXRSOperationSelector;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.OperationSelectorProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * JAXRS operation selector Service Provider.
+ *
+ * @version $Rev$ $Date$
+*/
+public class JAXRSOperationSelectorServiceProvider implements OperationSelectorProvider {
+ private ExtensionPointRegistry extensionPoints;
+ private RuntimeEndpoint endpoint;
+
+ private Binding binding;
+
+ public JAXRSOperationSelectorServiceProvider(ExtensionPointRegistry extensionPoints, RuntimeEndpoint endpoint) {
+ this.extensionPoints = extensionPoints;
+ this.endpoint = endpoint;
+ this.binding = endpoint.getBinding();
+ }
+
+ public Interceptor createInterceptor() {
+ if(binding.getOperationSelector() != null && binding.getOperationSelector() instanceof JAXRSOperationSelector) {
+ return new JAXRSOperationSelectorInterceptor(extensionPoints, endpoint);
+ }
+ return null;
+ }
+
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_OPERATION_SELECTOR;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java
index 3b0b69bcd7..ab13d952e4 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java
@@ -19,8 +19,11 @@
package org.apache.tuscany.sca.binding.rest.provider;
+import java.io.BufferedReader;
+import java.io.CharArrayWriter;
import java.io.IOException;
import java.io.InputStream;
+import java.io.InputStreamReader;
import java.io.OutputStream;
import java.net.URLDecoder;
import java.text.ParseException;
@@ -33,6 +36,7 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.tuscany.sca.assembly.Binding;
import org.apache.tuscany.sca.binding.rest.RESTCacheContext;
import org.apache.tuscany.sca.common.http.HTTPContentTypeMapper;
+import org.apache.tuscany.sca.common.http.HTTPContext;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
import org.apache.tuscany.sca.invocation.MessageFactory;
@@ -45,10 +49,12 @@ import org.apache.tuscany.sca.invocation.MessageFactory;
*/
public class RESTBindingListenerServlet extends HttpServlet {
private static final long serialVersionUID = 2865466417329430610L;
-
+
+ transient private MessageFactory messageFactory;
+
transient private Binding binding;
+ transient private Invoker bindingInvoker;
- private MessageFactory messageFactory;
private Invoker getInvoker;
private Invoker conditionalGetInvoker;
private Invoker putInvoker;
@@ -61,15 +67,64 @@ public class RESTBindingListenerServlet extends HttpServlet {
/**
* Constructs a new RESTServiceListenerServlet.
*/
- public RESTBindingListenerServlet(Binding binding, MessageFactory messageFactory) {
+ public RESTBindingListenerServlet(Binding binding, Invoker bindingInvoker, MessageFactory messageFactory) {
this.binding = binding;
+ this.bindingInvoker = bindingInvoker;
this.messageFactory = messageFactory;
}
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
- super.service(request, response);
+ if( binding.getOperationSelector() != null && binding.getRequestWireFormat() != null) {
+ // Decode using the charset in the request if it exists otherwise
+ // use UTF-8 as this is what all browser implementations use.
+ String charset = request.getCharacterEncoding();
+ if (charset == null) {
+ charset = "UTF-8";
+ }
+
+ BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream(), charset));
+
+ // Read the request
+ CharArrayWriter data = new CharArrayWriter();
+ char[] buf = new char[4096];
+ int ret;
+ while ((ret = in.read(buf, 0, 4096)) != -1) {
+ data.write(buf, 0, ret);
+ }
+
+ HTTPContext bindingContext = new HTTPContext();
+ bindingContext.setHttpRequest(request);
+ bindingContext.setHttpResponse(response);
+
+ // Dispatch the service interaction to the service invoker
+ Message requestMessage = messageFactory.createMessage();
+ requestMessage.setBindingContext(bindingContext);
+ if(data.size() > 0) {
+ requestMessage.setBody(new Object[]{data});
+ }
+
+ Message responseMessage = bindingInvoker.invoke(requestMessage);
+
+ // return response to client
+ if (responseMessage.isFault()) {
+ // Turn a fault into an exception
+ //throw new ServletException((Throwable)responseMessage.getBody());
+ Throwable e = (Throwable)responseMessage.getBody();
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
+ } else {
+ byte[] bout;
+ bout = responseMessage.<Object>getBody().toString().getBytes("UTF-8");
+ response.getOutputStream().write(bout);
+ response.getOutputStream().flush();
+ response.getOutputStream().close();
+ }
+ } else {
+ super.service(request, response);
+ }
+
+
}
@Override
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java
index e70aed8680..a037e6e45c 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java
@@ -105,7 +105,7 @@ public class RESTServiceBindingProvider implements EndpointProvider {
// configure data binding
if (this.wfProvider != null) {
- wfProvider.configureWireFormatInterfaceContract(service.getInterfaceContract());
+ wfProvider.configureWireFormatInterfaceContract(serviceContract);
}
} catch(CloneNotSupportedException e) {
this.serviceContract = service.getInterfaceContract();
@@ -116,7 +116,8 @@ public class RESTServiceBindingProvider implements EndpointProvider {
public void start() {
// Get the invokers for the supported operations
Servlet servlet = null;
- bindingListenerServlet = new RESTBindingListenerServlet(binding, messageFactory );
+ Invoker bindingInvoker = endpoint.getBindingInvocationChain().getHeadInvoker();
+ bindingListenerServlet = new RESTBindingListenerServlet(binding, bindingInvoker, messageFactory );
for (InvocationChain invocationChain : endpoint.getInvocationChains()) {
Operation operation = invocationChain.getTargetOperation();
String operationName = operation.getName();
@@ -181,7 +182,7 @@ public class RESTServiceBindingProvider implements EndpointProvider {
}
public InterfaceContract getBindingInterfaceContract() {
- return service.getInterfaceContract();
+ return serviceContract;
}
public boolean supportsOneWayInvocation() {
@@ -195,13 +196,13 @@ public class RESTServiceBindingProvider implements EndpointProvider {
InvocationChain bindingChain = endpoint.getBindingInvocationChain();
- if(osProvider != null) {
- bindingChain.addInterceptor(Phase.SERVICE_BINDING_OPERATION_SELECTOR, osProvider.createInterceptor());
- }
-
if (wfProvider != null) {
bindingChain.addInterceptor(Phase.SERVICE_BINDING_WIREFORMAT, wfProvider.createInterceptor());
}
+
+ if(osProvider != null) {
+ bindingChain.addInterceptor(Phase.SERVICE_BINDING_OPERATION_SELECTOR, osProvider.createInterceptor());
+ }
}
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java
index 183a0e599b..0ee63b1668 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java
@@ -24,11 +24,12 @@ import java.io.IOException;
import javax.servlet.Servlet;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
-import javax.servlet.ServletRequest;
-import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.tuscany.sca.assembly.Binding;
+import org.apache.tuscany.sca.common.http.HTTPContext;
import org.apache.tuscany.sca.invocation.Invoker;
import org.apache.tuscany.sca.invocation.Message;
import org.apache.tuscany.sca.invocation.MessageFactory;
@@ -39,7 +40,10 @@ import org.apache.tuscany.sca.invocation.MessageFactory;
*
* @version $Rev$ $Date$
*/
-public class RESTServiceListenerServlet implements Servlet {
+public class RESTServiceListenerServlet extends HttpServlet implements Servlet {
+
+ private static final long serialVersionUID = -5543706958107836637L;
+
transient private Binding binding;
transient private ServletConfig config;
transient private MessageFactory messageFactory;
@@ -70,9 +74,15 @@ public class RESTServiceListenerServlet implements Servlet {
}
- public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException {
+ @Override
+ public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ HTTPContext bindingContext = new HTTPContext();
+ bindingContext.setHttpRequest(request);
+ bindingContext.setHttpResponse(response);
+
// Dispatch the service interaction to the service invoker
Message requestMessage = messageFactory.createMessage();
+ requestMessage.setBindingContext(bindingContext);
requestMessage.setBody(new Object[]{request, response});
Message responseMessage = serviceInvoker.invoke(requestMessage);
if (responseMessage.isFault()) {
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java
index 8abc979c02..0c417c0d94 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java
@@ -26,7 +26,11 @@ import org.apache.tuscany.sca.provider.WireFormatProviderFactory;
import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
-
+/**
+ * JSON wire format Provider Factory.
+ *
+ * @version $Rev$ $Date$
+*/
public class JSONWireFormatProviderFctory implements WireFormatProviderFactory<JSONWireFormat>{
private ExtensionPointRegistry extensionPoints;
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java
index e1dce660ca..830b02a3e8 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java
@@ -26,6 +26,11 @@ import org.apache.tuscany.sca.invocation.Phase;
import org.apache.tuscany.sca.provider.WireFormatProvider;
import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+/**
+ * JSON wire format Reference Provider.
+ *
+ * @version $Rev$ $Date$
+*/
public class JSONWireFormatReferenceProvider implements WireFormatProvider {
private ExtensionPointRegistry extensionPoints;
private RuntimeEndpointReference endpointReference;
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java
index b4d59bd5ad..90efd3390d 100644
--- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java
+++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java
@@ -35,6 +35,11 @@ import org.apache.tuscany.sca.invocation.Phase;
import org.apache.tuscany.sca.provider.WireFormatProvider;
import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+/**
+ * JSON wire format service provider.
+ *
+ * @version $Rev$ $Date$
+*/
public class JSONWireFormatServiceProvider implements WireFormatProvider {
private ExtensionPointRegistry extensionPoints;
private RuntimeEndpoint endpoint;
@@ -46,7 +51,6 @@ public class JSONWireFormatServiceProvider implements WireFormatProvider {
this.extensionPoints = extensionPoints;
this.endpoint = endpoint;
this.binding = endpoint.getBinding();
-
}
public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract) {