diff options
Diffstat (limited to 'sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat')
3 files changed, 55 insertions, 14 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatInterceptor.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatInterceptor.java index e73ec961b3..fdcbc92c9c 100644 --- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/json/provider/JSONWireFormatInterceptor.java @@ -54,7 +54,9 @@ public class JSONWireFormatInterceptor implements Interceptor { public Message invoke(Message msg) { HTTPContext bindingContext = (HTTPContext) msg.getBindingContext(); - + if (bindingContext == null) { + return getNext().invoke(msg); + } // Decode using the charset in the request if it exists otherwise // use UTF-8 as this is what all browser implementations use. String charset = bindingContext.getHttpRequest().getCharacterEncoding(); 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 90efd3390d..c90f5c331c 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 @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.binding.rest.wireformat.json.provider; import java.util.List; import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.rest.provider.RESTServiceBindingProvider; import org.apache.tuscany.sca.binding.rest.wireformat.json.JSONWireFormat; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; @@ -30,6 +31,7 @@ import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Phase; import org.apache.tuscany.sca.provider.WireFormatProvider; @@ -46,27 +48,44 @@ public class JSONWireFormatServiceProvider implements WireFormatProvider { private InterfaceContract serviceContract; private Binding binding; + private boolean jaxrs; public JSONWireFormatServiceProvider(ExtensionPointRegistry extensionPoints, RuntimeEndpoint endpoint) { this.extensionPoints = extensionPoints; this.endpoint = endpoint; this.binding = endpoint.getBinding(); + this.jaxrs = isJAXRSResource(); + } + + private boolean isJAXRSResource() { + Interface interfaze = endpoint.getComponentServiceInterfaceContract().getInterface(); + if (interfaze instanceof JavaInterface) { + if (RESTServiceBindingProvider.isJAXRSResource(((JavaInterface)interfaze).getJavaClass())) { + return true; + } + } + return false; } public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract) { serviceContract = interfaceContract; - //set JSON databinding - setDataBinding(serviceContract.getInterface()); - - //make JSON databinding default - serviceContract.getInterface().resetDataBinding(JSONDataBinding.NAME); + if (!jaxrs) { + //set JSON databinding + setDataBinding(serviceContract.getInterface()); + + //make JSON databinding default + serviceContract.getInterface().resetDataBinding(JSONDataBinding.NAME); + } return serviceContract; } public Interceptor createInterceptor() { - if(binding.getRequestWireFormat() != null && binding.getRequestWireFormat() instanceof JSONWireFormat) { + if (jaxrs) { + return null; + } + if (binding.getRequestWireFormat() != null && binding.getRequestWireFormat() instanceof JSONWireFormat) { return new JSONWireFormatInterceptor(extensionPoints, endpoint); } return null; diff --git a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatServiceProvider.java b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatServiceProvider.java index 508b029b00..9e532d2df2 100644 --- a/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatServiceProvider.java +++ b/sca-java-2.x/trunk/modules/binding-rest-runtime/src/main/java/org/apache/tuscany/sca/binding/rest/wireformat/xml/provider/XMLWireFormatServiceProvider.java @@ -24,6 +24,7 @@ import java.util.List; import javax.xml.stream.XMLStreamReader; import org.apache.tuscany.sca.assembly.Binding; +import org.apache.tuscany.sca.binding.rest.provider.RESTServiceBindingProvider; import org.apache.tuscany.sca.binding.rest.wireformat.xml.XMLWireFormat; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.databinding.javabeans.SimpleJavaDataBinding; @@ -32,6 +33,7 @@ import org.apache.tuscany.sca.interfacedef.DataType; import org.apache.tuscany.sca.interfacedef.Interface; import org.apache.tuscany.sca.interfacedef.InterfaceContract; import org.apache.tuscany.sca.interfacedef.Operation; +import org.apache.tuscany.sca.interfacedef.java.JavaInterface; import org.apache.tuscany.sca.invocation.Interceptor; import org.apache.tuscany.sca.invocation.Phase; import org.apache.tuscany.sca.provider.WireFormatProvider; @@ -51,26 +53,44 @@ public class XMLWireFormatServiceProvider implements WireFormatProvider { private InterfaceContract serviceContract; private Binding binding; + private boolean jaxrs; + public XMLWireFormatServiceProvider(ExtensionPointRegistry extensionPoints, RuntimeEndpoint endpoint) { this.extensionPoints = extensionPoints; this.endpoint = endpoint; this.binding = endpoint.getBinding(); + this.jaxrs = isJAXRSResource(); + } + + private boolean isJAXRSResource() { + Interface interfaze = endpoint.getComponentServiceInterfaceContract().getInterface(); + if (interfaze instanceof JavaInterface) { + if (RESTServiceBindingProvider.isJAXRSResource(((JavaInterface)interfaze).getJavaClass())) { + return true; + } + } + return false; } public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract) { serviceContract = interfaceContract; - - //make XML databinding default - serviceContract.getInterface().resetDataBinding(DATABABINDING); - - //set XML databinding - setDataBinding(serviceContract.getInterface()); + if (!jaxrs) { + + //make XML databinding default + serviceContract.getInterface().resetDataBinding(DATABABINDING); + + //set XML databinding + setDataBinding(serviceContract.getInterface()); + } return serviceContract; } public Interceptor createInterceptor() { - if(binding.getRequestWireFormat() != null && binding.getRequestWireFormat() instanceof XMLWireFormat) { + if (jaxrs) { + return null; + } + if (binding.getRequestWireFormat() != null && binding.getRequestWireFormat() instanceof XMLWireFormat) { return new XMLWireFormatInterceptor(extensionPoints, endpoint); } return null; |