Author: lresende
Date: Tue Apr 27 21:43:08 2010
New Revision: 938687
URL: http://svn.apache.org/viewvc?rev=938687&view=rev
Log:
Operation selector implementation that uses JAX-RS annotations to map http
requests to properly annotated REST interfaces
Added:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
(with props)
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorProviderFctory.java
- copied, changed from r938686,
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorReferenceProvider.java
- copied, changed from r938686,
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorServiceProvider.java
- copied, changed from r938686,
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory
Removed:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/JSONWireFormatTestCase.java
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Catalog.java
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF?rev=938687&r1=938686&r2=938687&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/META-INF/MANIFEST.MF
Tue Apr 27 21:43:08 2010
@@ -12,6 +12,7 @@ Import-Package: javax.servlet,
javax.servlet.http,
org.apache.tuscany.sca.assembly;version="2.0.0",
org.apache.tuscany.sca.binding.rest;version="2.0.0",
+ org.apache.tuscany.sca.binding.rest.operationselector.jaxrs,
org.apache.tuscany.sca.binding.rest.wireformat.json,
org.apache.tuscany.sca.common.http;version="2.0.0",
org.apache.tuscany.sca.core;version="2.0.0",
Modified: tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml?rev=938687&r1=938686&r2=938687&view=diff
==============================================================================
--- tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml (original)
+++ tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/pom.xml Tue Apr 27
21:43:08 2010
@@ -37,6 +37,12 @@
</dependency>
<dependency>
+ <groupId>javax.ws.rs</groupId>
+ <artifactId>jsr311-api</artifactId>
+ <version>1.0</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-data-api</artifactId>
<version>2.0-SNAPSHOT</version>
@@ -65,7 +71,7 @@
<artifactId>tuscany-databinding-json</artifactId>
<version>2.0-SNAPSHOT</version>
</dependency>
-
+
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-host-http</artifactId>
@@ -92,7 +98,14 @@
<version>2.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
-
+
+ <dependency>
+ <groupId>org.apache.tuscany.sca</groupId>
+ <artifactId>tuscany-interface-java-jaxrs</artifactId>
+ <version>2.0-SNAPSHOT</version>
+ <scope>test</scope>
+ </dependency>
+
<dependency>
<groupId>org.apache.tuscany.sca</groupId>
<artifactId>tuscany-implementation-java-runtime</artifactId>
@@ -113,7 +126,6 @@
<version>4.8.1</version>
<scope>test</scope>
</dependency>
-
</dependencies>
<build>
Added:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java?rev=938687&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
(added)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
Tue Apr 27 21:43:08 2010
@@ -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;
+ }
+}
Propchange:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorInterceptor.java
------------------------------------------------------------------------------
svn:keywords = Rev Date
Copied:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorProviderFctory.java
(from r938686,
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java)
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorProviderFctory.java?p2=tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorProviderFctory.java&p1=tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java&r1=938686&r2=938687&rev=938687&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorProviderFctory.java
Tue Apr 27 21:43:08 2010
@@ -17,32 +17,36 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.rest.wireformat.json.provider;
+package org.apache.tuscany.sca.binding.rest.operationselector.jaxrs.provider;
-import org.apache.tuscany.sca.binding.rest.wireformat.json.JSONWireFormat;
+import
org.apache.tuscany.sca.binding.rest.operationselector.jaxrs.JAXRSOperationSelector;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.provider.WireFormatProvider;
-import org.apache.tuscany.sca.provider.WireFormatProviderFactory;
+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;
-
-public class JSONWireFormatProviderFctory implements
WireFormatProviderFactory<JSONWireFormat>{
+/**
+ * JAXRS operation selector Provider Factory.
+ *
+ * @version $Rev$ $Date$
+*/
+public class JAXRSOperationSelectorProviderFctory implements
OperationSelectorProviderFactory<JAXRSOperationSelector>{
private ExtensionPointRegistry extensionPoints;
- public JSONWireFormatProviderFctory(ExtensionPointRegistry
extensionPoints) {
+ public JAXRSOperationSelectorProviderFctory(ExtensionPointRegistry
extensionPoints) {
this.extensionPoints = extensionPoints;
}
- public WireFormatProvider
createReferenceWireFormatProvider(RuntimeEndpointReference endpointReference) {
- return new JSONWireFormatReferenceProvider(extensionPoints,
endpointReference);
+ public OperationSelectorProvider
createReferenceOperationSelectorProvider(RuntimeEndpointReference
endpointReference) {
+ return new JAXRSOperationSelectorReferenceProvider(extensionPoints,
endpointReference);
}
- public WireFormatProvider createServiceWireFormatProvider(RuntimeEndpoint
endpoint) {
- return new JSONWireFormatServiceProvider(extensionPoints, endpoint);
+ public OperationSelectorProvider
createServiceOperationSelectorProvider(RuntimeEndpoint endpoint) {
+ return new JAXRSOperationSelectorServiceProvider(extensionPoints,
endpoint);
}
- public Class<JSONWireFormat> getModelType() {
- return JSONWireFormat.class;
+ public Class<JAXRSOperationSelector> getModelType() {
+ return JAXRSOperationSelector.class;
}
}
Copied:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorReferenceProvider.java
(from r938686,
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java)
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorReferenceProvider.java?p2=tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorReferenceProvider.java&p1=tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java&r1=938686&r2=938687&rev=938687&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorReferenceProvider.java
Tue Apr 27 21:43:08 2010
@@ -17,33 +17,34 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.rest.wireformat.json.provider;
+package org.apache.tuscany.sca.binding.rest.operationselector.jaxrs.provider;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
-import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.invocation.Interceptor;
import org.apache.tuscany.sca.invocation.Phase;
-import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.provider.OperationSelectorProvider;
import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
-public class JSONWireFormatReferenceProvider implements WireFormatProvider {
+/**
+ * JAXRS operation selector Reference Provider.
+ *
+ * @version $Rev$ $Date$
+*/
+public class JAXRSOperationSelectorReferenceProvider implements
OperationSelectorProvider {
private ExtensionPointRegistry extensionPoints;
private RuntimeEndpointReference endpointReference;
- public JSONWireFormatReferenceProvider(ExtensionPointRegistry
extensionPoints,RuntimeEndpointReference endpointReference ) {
+ public JAXRSOperationSelectorReferenceProvider(ExtensionPointRegistry
extensionPoints, RuntimeEndpointReference endpointReference ) {
this.extensionPoints = extensionPoints;
this.endpointReference = endpointReference;
}
- public InterfaceContract
configureWireFormatInterfaceContract(InterfaceContract interfaceContract) {
- return null;
- }
-
+
public Interceptor createInterceptor() {
return null;
}
public String getPhase() {
- return Phase.REFERENCE_BINDING_WIREFORMAT;
+ return Phase.SERVICE_BINDING_OPERATION_SELECTOR;
}
}
Copied:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorServiceProvider.java
(from r938686,
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java)
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorServiceProvider.java?p2=tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorServiceProvider.java&p1=tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java&r1=938686&r2=938687&rev=938687&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/operationselector/jaxrs/provider/JAXRSOperationSelectorServiceProvider.java
Tue Apr 27 21:43:08 2010
@@ -17,33 +17,41 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.rest.wireformat.json.provider;
+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.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.invocation.Interceptor;
import org.apache.tuscany.sca.invocation.Phase;
-import org.apache.tuscany.sca.provider.WireFormatProvider;
-import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+import org.apache.tuscany.sca.provider.OperationSelectorProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
-public class JSONWireFormatReferenceProvider implements WireFormatProvider {
+/**
+ * JAXRS operation selector Service Provider.
+ *
+ * @version $Rev$ $Date$
+*/
+public class JAXRSOperationSelectorServiceProvider implements
OperationSelectorProvider {
private ExtensionPointRegistry extensionPoints;
- private RuntimeEndpointReference endpointReference;
-
- public JSONWireFormatReferenceProvider(ExtensionPointRegistry
extensionPoints,RuntimeEndpointReference endpointReference ) {
+ private RuntimeEndpoint endpoint;
+
+ private Binding binding;
+
+ public JAXRSOperationSelectorServiceProvider(ExtensionPointRegistry
extensionPoints, RuntimeEndpoint endpoint) {
this.extensionPoints = extensionPoints;
- this.endpointReference = endpointReference;
- }
- public InterfaceContract
configureWireFormatInterfaceContract(InterfaceContract interfaceContract) {
- return null;
+ 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.REFERENCE_BINDING_WIREFORMAT;
+ return Phase.SERVICE_BINDING_OPERATION_SELECTOR;
}
-
}
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java?rev=938687&r1=938686&r2=938687&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTBindingListenerServlet.java
Tue Apr 27 21:43:08 2010
@@ -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.HttpServletRes
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
*/
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
/**
* 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
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java?rev=938687&r1=938686&r2=938687&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceBindingProvider.java
Tue Apr 27 21:43:08 2010
@@ -105,7 +105,7 @@ public class RESTServiceBindingProvider
// 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
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
}
public InterfaceContract getBindingInterfaceContract() {
- return service.getInterfaceContract();
+ return serviceContract;
}
public boolean supportsOneWayInvocation() {
@@ -195,13 +196,13 @@ public class RESTServiceBindingProvider
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());
+ }
}
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java?rev=938687&r1=938686&r2=938687&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/provider/RESTServiceListenerServlet.java
Tue Apr 27 21:43:08 2010
@@ -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
*
* @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
}
- 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()) {
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java?rev=938687&r1=938686&r2=938687&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatProviderFctory.java
Tue Apr 27 21:43:08 2010
@@ -26,7 +26,11 @@ import org.apache.tuscany.sca.provider.W
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;
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java?rev=938687&r1=938686&r2=938687&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatReferenceProvider.java
Tue Apr 27 21:43:08 2010
@@ -26,6 +26,11 @@ import org.apache.tuscany.sca.invocation
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;
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java?rev=938687&r1=938686&r2=938687&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatServiceProvider.java
Tue Apr 27 21:43:08 2010
@@ -35,6 +35,11 @@ import org.apache.tuscany.sca.invocation
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 JSONWireFormatServiceProvid
this.extensionPoints = extensionPoints;
this.endpoint = endpoint;
this.binding = endpoint.getBinding();
-
}
public InterfaceContract
configureWireFormatInterfaceContract(InterfaceContract interfaceContract) {
Added:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory?rev=938687&view=auto
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory
(added)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory
Tue Apr 27 21:43:08 2010
@@ -0,0 +1,19 @@
+# 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.
+
+# Implementation class for the wire format provider factory
+org.apache.tuscany.sca.binding.rest.operationselector.jaxrs.provider.JAXRSOperationSelectorProviderFctory;model=org.apache.tuscany.sca.binding.rest.operationselector.jaxrs.JAXRSOperationSelector
\ No newline at end of file
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java?rev=938687&r1=938686&r2=938687&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/org/apache/tuscany/sca/binding/rest/wireformat/json/CatalogServiceTestCase.java
Tue Apr 27 21:43:08 2010
@@ -34,7 +34,6 @@ import org.junit.Test;
import services.Catalog;
import services.Item;
-...@ignore
public class CatalogServiceTestCase {
private static Node node;
private static Catalog catalogService;
@@ -63,10 +62,10 @@ public class CatalogServiceTestCase {
@Test
public void testPing() throws Exception {
new Socket("127.0.0.1", 8085);
- System.in.read();
+ //System.in.read();
}
- @Test
+ @Ignore
public void testNewsService() throws Exception {
Item[] items = catalogService.get();
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Catalog.java
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Catalog.java?rev=938687&r1=938686&r2=938687&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Catalog.java
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/java/services/Catalog.java
Tue Apr 27 21:43:08 2010
@@ -19,9 +19,13 @@
package services;
+import javax.ws.rs.GET;
+
import org.oasisopen.sca.annotation.Remotable;
@Remotable
public interface Catalog {
+
+ @GET
Item[] get();
}
Modified:
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite
URL:
http://svn.apache.org/viewvc/tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite?rev=938687&r1=938686&r2=938687&view=diff
==============================================================================
---
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite
(original)
+++
tuscany/sca-java-2.x/trunk/modules/binding-rest-runtime/src/test/resources/store.composite
Tue Apr 27 21:43:08 2010
@@ -28,6 +28,7 @@
<service name="Catalog">
<tuscany:binding.rest
uri="http://localhost:8085/Catalog">
<tuscany:wireFormat.json />
+ <tuscany:operationSelector.jaxrs />
</tuscany:binding.rest>
</service>
<reference name="currencyConverter"
target="CurrencyConverter"/>