summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/trunk/modules/binding-http-runtime/src
diff options
context:
space:
mode:
authorlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2011-11-11 00:53:16 +0000
committerlresende <lresende@13f79535-47bb-0310-9956-ffa450edef68>2011-11-11 00:53:16 +0000
commitcd07713f408a9edc820fb70a7dead012ee1ff899 (patch)
treebaea598f776a47141d9afc49f453200ba1f947f2 /sca-java-2.x/trunk/modules/binding-http-runtime/src
parentc607b0cf671eda11eff333748e4ce3a75ce941d1 (diff)
Refactoring binding http model to bring back support for servlet based resources, and making rpc style it's own operationSelector
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1200669 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to '')
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultOperationSelectorProviderFactory.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultOperationSelectorProviderFactory.java)6
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultServiceOperationSelectorInterceptor.java108
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCOperationSelectorProviderFactory.java60
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCServiceOperationSelectorInterceptor.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultServiceOperationSelectorInterceptor.java)6
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java224
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingServiceServlet.java12
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java93
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatProviderFactory.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatProviderFactory.java)10
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatServiceInterceptor.java71
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatProviderFactory.java68
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatServiceInterceptor.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatServiceInterceptor.java)6
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatProviderFactory.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPXMLWireFormatProviderFactory.java)6
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatServiceInterceptor.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPXMLWireFormatServiceInterceptor.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory3
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory5
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ResourceServiceTestCase.java79
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/BeanA.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/BeanA.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuff.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuff.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuffImpl.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuffImpl.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/Helloworld.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/Helloworld.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/HelloworldImpl.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HelloworldImpl.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ResourceService.java55
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/SomeException.java (renamed from sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/SomeException.java)2
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite12
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite12
-rw-r--r--sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/resource.composite33
26 files changed, 671 insertions, 212 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultOperationSelectorProviderFactory.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultOperationSelectorProviderFactory.java
index bf6ad75cd3..f027424ff0 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultOperationSelectorProviderFactory.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultOperationSelectorProviderFactory.java
@@ -17,9 +17,9 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http.format;
+package org.apache.tuscany.sca.binding.http.operationselector.provider;
-import org.apache.tuscany.sca.binding.http.HTTPDefaultOperationSelector;
+import org.apache.tuscany.sca.binding.http.operationselector.HTTPDefaultOperationSelector;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.invocation.Interceptor;
import org.apache.tuscany.sca.invocation.Phase;
@@ -35,7 +35,7 @@ public class HTTPDefaultOperationSelectorProviderFactory implements OperationSel
@Override
public Class<HTTPDefaultOperationSelector> getModelType() {
- return null;
+ return HTTPDefaultOperationSelector.class;
}
@Override
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultServiceOperationSelectorInterceptor.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultServiceOperationSelectorInterceptor.java
new file mode 100644
index 0000000000..e9cb0fd1da
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultServiceOperationSelectorInterceptor.java
@@ -0,0 +1,108 @@
+/*
+ * 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.http.operationselector.provider;
+
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.tuscany.sca.common.http.HTTPContext;
+import org.apache.tuscany.sca.interfacedef.Interface;
+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.RuntimeEndpoint;
+import org.oasisopen.sca.ServiceRuntimeException;
+
+/**
+ * Sets the operation based on the request path.
+ *
+ * From a url: http://localhost:8080/HelloworldComponent/Helloworld/sayHello?name=Petra
+ * where the component is HelloworldComponent and the service is Helloworld
+ * the path will be "/sayHello" so the operation is "sayHello".
+ *
+ * TODO: we could also do something similar to how the JMS binding supports
+ * a single "onMessage" method to get all requests, so perhaps this could
+ * also support impls with method: service(HttpServletRequest, HttpServletResponse)
+ */
+public class HTTPDefaultServiceOperationSelectorInterceptor implements Interceptor {
+
+ private Invoker next;
+ private List<Operation> operations;
+
+ public HTTPDefaultServiceOperationSelectorInterceptor(RuntimeEndpoint endpoint) {
+ Interface serviceInterface = endpoint.getService().getInterfaceContract().getInterface();
+ this.operations = serviceInterface.getOperations();
+ }
+
+ @Override
+ public Message invoke(Message msg) {
+ HTTPContext context = msg.getBindingContext();
+ HttpServletRequest request = context.getHttpRequest();
+
+ Operation operation = findOperation(request.getMethod());
+ if(operation == null) {
+ operation = findOperation("service");
+ }
+
+ if(operation == null) {
+ throw new ServiceRuntimeException("No matching operation for " + request.getMethod());
+ }
+ msg.setOperation(operation);
+ return next.invoke(msg);
+ }
+
+ @Override
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ @Override
+ public Invoker getNext() {
+ return next;
+ }
+
+
+
+ /**
+ * Find the operation from the component service contract
+ * @param componentService
+ * @param method
+ * @return
+ */
+ private Operation findOperation(String method) {
+ if (method.contains(".")) {
+ method = method.substring(method.lastIndexOf(".") + 1);
+ }
+
+ Operation result = null;
+ for (Operation o : operations) {
+ if (o.isDynamic())
+ return o;
+ if (o.getName().equalsIgnoreCase(method)) {
+ result = o;
+ break;
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCOperationSelectorProviderFactory.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCOperationSelectorProviderFactory.java
new file mode 100644
index 0000000000..bc34a86af5
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCOperationSelectorProviderFactory.java
@@ -0,0 +1,60 @@
+/*
+ * 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.http.operationselector.provider;
+
+import org.apache.tuscany.sca.binding.http.operationselector.HTTPDefaultOperationSelector;
+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.provider.OperationSelectorProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+public class HTTPRPCOperationSelectorProviderFactory implements OperationSelectorProviderFactory<HTTPDefaultOperationSelector>{
+
+ public HTTPRPCOperationSelectorProviderFactory(ExtensionPointRegistry extensionPoints) {
+ }
+
+ @Override
+ public Class<HTTPDefaultOperationSelector> getModelType() {
+ return HTTPDefaultOperationSelector.class;
+ }
+
+ @Override
+ public OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeEndpointReference endpointReference) {
+ return null;
+ }
+
+ @Override
+ public OperationSelectorProvider createServiceOperationSelectorProvider(final RuntimeEndpoint endpoint) {
+ return new OperationSelectorProvider(){
+ @Override
+ public Interceptor createInterceptor() {
+ return new HTTPDefaultServiceOperationSelectorInterceptor(endpoint);
+ }
+
+ @Override
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_OPERATION_SELECTOR;
+ }};
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultServiceOperationSelectorInterceptor.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCServiceOperationSelectorInterceptor.java
index d45401bd7f..915399bb4e 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultServiceOperationSelectorInterceptor.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCServiceOperationSelectorInterceptor.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http.format;
+package org.apache.tuscany.sca.binding.http.operationselector.provider;
import java.util.List;
@@ -43,12 +43,12 @@ import org.oasisopen.sca.ServiceRuntimeException;
* a single "onMessage" method to get all requests, so perhaps this could
* also support impls with method: service(HttpServletRequest, HttpServletResponse)
*/
-public class HTTPDefaultServiceOperationSelectorInterceptor implements Interceptor {
+public class HTTPRPCServiceOperationSelectorInterceptor implements Interceptor {
private Invoker next;
private List<Operation> operations;
- public HTTPDefaultServiceOperationSelectorInterceptor(RuntimeEndpoint endpoint) {
+ public HTTPRPCServiceOperationSelectorInterceptor(RuntimeEndpoint endpoint) {
Interface serviceInterface = endpoint.getService().getInterfaceContract().getInterface();
this.operations = serviceInterface.getOperations();
}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java
index e2a3a5cf39..4835a54906 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java
@@ -45,7 +45,7 @@ import org.apache.tuscany.sca.invocation.MessageFactory;
*/
public class HTTPBindingListenerServlet extends HttpServlet {
private static final long serialVersionUID = 2865466417329430610L;
-
+
transient private Binding binding;
private MessageFactory messageFactory;
@@ -57,7 +57,7 @@ public class HTTPBindingListenerServlet extends HttpServlet {
private Invoker conditionalPostInvoker;
private Invoker deleteInvoker;
private Invoker conditionalDeleteInvoker;
-
+
/**
* Constructs a new HTTPServiceListenerServlet.
*/
@@ -66,12 +66,12 @@ public class HTTPBindingListenerServlet extends HttpServlet {
this.messageFactory = messageFactory;
}
-
+
@Override
protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
super.service(request, response);
}
-
+
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Get the request path
@@ -88,43 +88,43 @@ public class HTTPBindingListenerServlet extends HttpServlet {
Message requestMessage = messageFactory.createMessage();
String id = path.substring(1);
-
+
Message responseMessage = null;
HTTPCacheContext cacheContext = null;
try {
- cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
+ cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
} catch (ParseException e) {
}
// Route message based on availability of cache info and cache methods
if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalGetInvoker != null )) {
- requestMessage.setBody(new Object[] {id, cacheContext});
- responseMessage = conditionalGetInvoker.invoke(requestMessage);
+ requestMessage.setBody(new Object[] {id, cacheContext});
+ responseMessage = conditionalGetInvoker.invoke(requestMessage);
} else {
- requestMessage.setBody(new Object[] {id});
- responseMessage = getInvoker.invoke(requestMessage);
+ requestMessage.setBody(new Object[] {id});
+ responseMessage = getInvoker.invoke(requestMessage);
}
if (responseMessage.isFault()) {
- Object body = responseMessage.getBody();
-
- int index = -1;
- if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) {
- if ( index > -1 )
- response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index ));
- else
- response.sendError( HttpServletResponse.SC_NOT_MODIFIED );
- return;
- } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) {
- if ( index > -1 )
- response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index ));
- else
- response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED );
- return;
+ Object body = responseMessage.getBody();
+
+ int index = -1;
+ if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) {
+ if ( index > -1 )
+ response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index ));
+ else
+ response.sendError( HttpServletResponse.SC_NOT_MODIFIED );
+ return;
+ } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) {
+ if ( index > -1 )
+ response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index ));
+ else
+ response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED );
+ return;
}
-
+
throw new ServletException((Throwable)responseMessage.getBody());
}
-
+
if(response.getContentType() == null || response.getContentType().length() == 0){
// Calculate content-type based on extension
String contentType = HTTPContentTypeMapper.getContentType(id);
@@ -132,7 +132,7 @@ public class HTTPBindingListenerServlet extends HttpServlet {
response.setContentType(contentType);
}
}
-
+
// Write the response from the service implementation to the response
// output stream
InputStream is = (InputStream)responseMessage.getBody();
@@ -162,43 +162,43 @@ public class HTTPBindingListenerServlet extends HttpServlet {
// Invoke the get operation on the service implementation
Message requestMessage = messageFactory.createMessage();
String id = path.substring(1);
-
+
Message responseMessage = null;
HTTPCacheContext cacheContext = null;
try {
- cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
+ cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
} catch (ParseException e) {
}
-
+
// Route message based on availability of cache info and cache methods
if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalDeleteInvoker != null )) {
- requestMessage.setBody(new Object[] {id, cacheContext});
- responseMessage = conditionalDeleteInvoker.invoke(requestMessage);
+ requestMessage.setBody(new Object[] {id, cacheContext});
+ responseMessage = conditionalDeleteInvoker.invoke(requestMessage);
} else {
- requestMessage.setBody(new Object[] {id});
- responseMessage = deleteInvoker.invoke(requestMessage);
+ requestMessage.setBody(new Object[] {id});
+ responseMessage = deleteInvoker.invoke(requestMessage);
}
if (responseMessage.isFault()) {
- Object body = responseMessage.getBody();
-
- int index = -1;
- if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) {
- if ( index > -1 )
- response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index ));
- else
- response.sendError( HttpServletResponse.SC_NOT_MODIFIED );
- return;
- } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) {
- if ( index > -1 )
- response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index ));
- else
- response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED );
- return;
+ Object body = responseMessage.getBody();
+
+ int index = -1;
+ if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) {
+ if ( index > -1 )
+ response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index ));
+ else
+ response.sendError( HttpServletResponse.SC_NOT_MODIFIED );
+ return;
+ } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) {
+ if ( index > -1 )
+ response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index ));
+ else
+ response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED );
+ return;
}
-
+
throw new ServletException((Throwable)responseMessage.getBody());
}
-
+
// Write the response from the service implementation to the response
// output stream
InputStream is = (InputStream)responseMessage.getBody();
@@ -228,43 +228,43 @@ public class HTTPBindingListenerServlet extends HttpServlet {
// Invoke the get operation on the service implementation
Message requestMessage = messageFactory.createMessage();
String id = path.substring(1);
-
+
Message responseMessage = null;
HTTPCacheContext cacheContext = null;
try {
- cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
+ cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
} catch (ParseException e) {
}
-
+
// Route message based on availability of cache info and cache methods
if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalPutInvoker != null )) {
- requestMessage.setBody(new Object[] {id, cacheContext});
- responseMessage = conditionalPutInvoker.invoke(requestMessage);
+ requestMessage.setBody(new Object[] {id, cacheContext});
+ responseMessage = conditionalPutInvoker.invoke(requestMessage);
} else {
- requestMessage.setBody(new Object[] {id});
- responseMessage = putInvoker.invoke(requestMessage);
+ requestMessage.setBody(new Object[] {id});
+ responseMessage = putInvoker.invoke(requestMessage);
}
if (responseMessage.isFault()) {
- Object body = responseMessage.getBody();
-
- int index = -1;
- if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) {
- if ( index > -1 )
- response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index ));
- else
- response.sendError( HttpServletResponse.SC_NOT_MODIFIED );
- return;
- } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) {
- if ( index > -1 )
- response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index ));
- else
- response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED );
- return;
+ Object body = responseMessage.getBody();
+
+ int index = -1;
+ if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) {
+ if ( index > -1 )
+ response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index ));
+ else
+ response.sendError( HttpServletResponse.SC_NOT_MODIFIED );
+ return;
+ } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) {
+ if ( index > -1 )
+ response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index ));
+ else
+ response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED );
+ return;
}
-
+
throw new ServletException((Throwable)responseMessage.getBody());
}
-
+
// Write the response from the service implementation to the response
// output stream
InputStream is = (InputStream)responseMessage.getBody();
@@ -294,58 +294,58 @@ public class HTTPBindingListenerServlet extends HttpServlet {
// Invoke the get operation on the service implementation
Message requestMessage = messageFactory.createMessage();
// String id = path.substring(1);
-
+
Message responseMessage = null;
HTTPCacheContext cacheContext = null;
try {
- cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
+ cacheContext = HTTPCacheContext.createCacheContextFromRequest(request);
} catch (ParseException e) {
}
-
+
// Route message based on availability of cache info and cache methods
if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalPostInvoker != null )) {
- requestMessage.setBody(new Object[] {cacheContext});
- responseMessage = conditionalPostInvoker.invoke(requestMessage);
+ requestMessage.setBody(new Object[] {cacheContext});
+ responseMessage = conditionalPostInvoker.invoke(requestMessage);
} else {
- requestMessage.setBody(new Object[] {});
- responseMessage = postInvoker.invoke(requestMessage);
+ requestMessage.setBody(new Object[] {});
+ responseMessage = postInvoker.invoke(requestMessage);
}
if (responseMessage.isFault()) {
- Object body = responseMessage.getBody();
-
- int index = -1;
- if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) {
- if ( index > -1 )
- response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index ));
- else
- response.sendError( HttpServletResponse.SC_NOT_MODIFIED );
- return;
- } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) {
- if ( index > -1 )
- response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index ));
- else
- response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED );
- return;
+ Object body = responseMessage.getBody();
+
+ int index = -1;
+ if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) {
+ if ( index > -1 )
+ response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index ));
+ else
+ response.sendError( HttpServletResponse.SC_NOT_MODIFIED );
+ return;
+ } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) {
+ if ( index > -1 )
+ response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index ));
+ else
+ response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED );
+ return;
}
-
+
throw new ServletException((Throwable)responseMessage.getBody());
}
// Test if the ETag and LastModified are returned as a cache context.
- Object body = responseMessage.getBody();
- if ( body.getClass() == HTTPCacheContext.class ) {
- // Transfer to header if so.
- HTTPCacheContext cc = (HTTPCacheContext)responseMessage.getBody();
- if (( cc != null ) && ( cc.isEnabled() )) {
- String eTag = cc.getETag();
- if ( eTag != null )
- response.setHeader( "ETag", cc.getETag() );
- String lastModified = cc.getLastModified();
- if ( lastModified != null)
- response.setHeader( "LastModified", cc.getLastModified() );
- }
- }
+ Object body = responseMessage.getBody();
+ if ( body.getClass() == HTTPCacheContext.class ) {
+ // Transfer to header if so.
+ HTTPCacheContext cc = (HTTPCacheContext)responseMessage.getBody();
+ if (( cc != null ) && ( cc.isEnabled() )) {
+ String eTag = cc.getETag();
+ if ( eTag != null )
+ response.setHeader( "ETag", cc.getETag() );
+ String lastModified = cc.getLastModified();
+ if ( lastModified != null)
+ response.setHeader( "LastModified", cc.getLastModified() );
+ }
+ }
}
/**
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingServiceServlet.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingServiceServlet.java
index 4d1f655577..13872f87bc 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingServiceServlet.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingServiceServlet.java
@@ -32,8 +32,8 @@ import org.apache.tuscany.sca.invocation.MessageFactory;
import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
public class HTTPBindingServiceServlet extends HttpServlet {
- private static final long serialVersionUID = 1L;
-
+ private static final long serialVersionUID = 6496710199406616194L;
+
protected transient MessageFactory messageFactory;
protected transient RuntimeEndpoint wire;
@@ -49,6 +49,12 @@ public class HTTPBindingServiceServlet extends HttpServlet {
bindingContext.setHttpResponse(response);
Message msg = messageFactory.createMessage();
msg.setBindingContext(bindingContext);
- wire.invoke(msg);
+ Message responseMessage = wire.invoke(msg);
+ // return response to client
+ if (responseMessage.isFault()) {
+ // Turn a fault into an exception
+ Throwable e = (Throwable)responseMessage.getBody();
+ response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString());
+ }
}
}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java
index 3a3436d101..f06dad2a9b 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java
@@ -22,8 +22,9 @@ package org.apache.tuscany.sca.binding.http.provider;
import javax.servlet.Servlet;
import org.apache.tuscany.sca.binding.http.HTTPBinding;
-import org.apache.tuscany.sca.binding.http.HTTPDefaultOperationSelector;
-import org.apache.tuscany.sca.binding.http.HTTPDefaultWireFormat;
+import org.apache.tuscany.sca.binding.http.operationselector.HTTPDefaultOperationSelector;
+import org.apache.tuscany.sca.binding.http.operationselector.HTTPRPCOperationSelector;
+import org.apache.tuscany.sca.binding.http.wireformat.HTTPDefaultWireFormat;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.host.http.ServletHost;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
@@ -56,7 +57,6 @@ public class HTTPServiceBindingProvider implements EndpointProvider {
private ServletHost servletHost;
private String servletMapping;
private InterfaceContract interfaceContract;
- private boolean widget;
private HTTPBindingListenerServlet bindingListenerServlet;
@@ -67,19 +67,18 @@ public class HTTPServiceBindingProvider implements EndpointProvider {
this.endpoint = endpoint;
this.binding = (HTTPBinding)endpoint.getBinding();
- this.widget = "Widget".equals(binding.getName());
this.extensionPoints = extensionPoints;
this.messageFactory = messageFactory;
this.servletHost = servletHost;
- if (binding.getOperationSelector() == null && !widget) {
+ if (binding.getOperationSelector() == null) {
binding.setOperationSelector(new HTTPDefaultOperationSelector());
}
- if (binding.getRequestWireFormat() == null && !widget) {
+ if (binding.getRequestWireFormat() == null) {
binding.setRequestWireFormat(new HTTPDefaultWireFormat());
}
- if (binding.getResponseWireFormat() == null && !widget) {
+ if (binding.getResponseWireFormat() == null) {
binding.setResponseWireFormat(new HTTPDefaultWireFormat());
}
@@ -123,63 +122,40 @@ public class HTTPServiceBindingProvider implements EndpointProvider {
}
public void start() {
- if (widget) {
- start1x();
- } else {
- String deployedURI = servletHost.addServletMapping(servletMapping, new HTTPBindingServiceServlet(endpoint, messageFactory));
- endpoint.setDeployedURI(deployedURI);
+
+ /**
+ * Consider three scenarios here :
+ * - Default servlet using service level operation
+ * - Default servlet using GET, PUT, POST, DELETE operations mapped to interface names with same name
+ * - RPC over HTTP like : http://localhost:8080/HelloworldComponent/Helloworld/sayHello?name=Petra
+ */
+ if (binding.getOperationSelector() == null || binding.getRequestWireFormat() == null || binding.getResponseWireFormat() == null) {
+ throw new IllegalStateException("Binding operation selector and/or wire formats not properly setup.");
}
- }
-
- public void start1x() {
- // Get the invokers for the supported operations
+
+ InvocationChain bindingChain = endpoint.getBindingInvocationChain();
+
Servlet servlet = null;
- bindingListenerServlet = new HTTPBindingListenerServlet(binding, messageFactory );
+ Invoker bindingInvoker = bindingChain.getHeadInvoker();
+ bindingListenerServlet = new HTTPBindingListenerServlet(binding, messageFactory);
for (InvocationChain invocationChain : endpoint.getInvocationChains()) {
+
Operation operation = invocationChain.getTargetOperation();
+ Invoker serviceInvoker = invocationChain.getHeadInvoker();
String operationName = operation.getName();
- if (operationName.equals("get")) {
- Invoker getInvoker = invocationChain.getHeadInvoker();
- bindingListenerServlet.setGetInvoker(getInvoker);
- servlet = bindingListenerServlet;
- } else if (operationName.equals("conditionalGet")) {
- Invoker conditionalGetInvoker = invocationChain.getHeadInvoker();
- bindingListenerServlet.setConditionalGetInvoker(conditionalGetInvoker);
- servlet = bindingListenerServlet;
- } else if (operationName.equals("delete")) {
- Invoker deleteInvoker = invocationChain.getHeadInvoker();
- bindingListenerServlet.setDeleteInvoker(deleteInvoker);
- servlet = bindingListenerServlet;
- } else if (operationName.equals("conditionalDelete")) {
- Invoker conditionalDeleteInvoker = invocationChain.getHeadInvoker();
- bindingListenerServlet.setConditionalDeleteInvoker(conditionalDeleteInvoker);
- servlet = bindingListenerServlet;
- } else if (operationName.equals("put")) {
- Invoker putInvoker = invocationChain.getHeadInvoker();
- bindingListenerServlet.setPutInvoker(putInvoker);
- servlet = bindingListenerServlet;
- } else if (operationName.equals("conditionalPut")) {
- Invoker conditionalPutInvoker = invocationChain.getHeadInvoker();
- bindingListenerServlet.setConditionalPutInvoker(conditionalPutInvoker);
- servlet = bindingListenerServlet;
- } else if (operationName.equals("post")) {
- Invoker postInvoker = invocationChain.getHeadInvoker();
- bindingListenerServlet.setPostInvoker(postInvoker);
- servlet = bindingListenerServlet;
- } else if (operationName.equals("conditionalPost")) {
- Invoker conditionalPostInvoker = invocationChain.getHeadInvoker();
- bindingListenerServlet.setConditionalPostInvoker(conditionalPostInvoker);
- servlet = bindingListenerServlet;
- } else if (operationName.equals("service")) {
- Invoker serviceInvoker = invocationChain.getHeadInvoker();
-// servlet = new HTTPServiceListenerServlet(binding, serviceInvoker, messageFactory);
+
+ /*
+ if (operationName.equals("service")) {
+ servlet = new HTTPBindingListenerServlet(binding, messageFactory);
break;
- }
- }
- if (servlet == null) {
- throw new IllegalStateException("No get or service method found on the service");
+ } else {
+ */
+ servlet = new HTTPBindingServiceServlet(endpoint, messageFactory);
+ /*
+ }
+ */
}
-
+
// Create our HTTP service listener Servlet and register it with the
// Servlet host
servletMapping = binding.getURI();
@@ -210,9 +186,6 @@ public class HTTPServiceBindingProvider implements EndpointProvider {
* Add specific http interceptor to invocation chain
*/
public void configure() {
-
- if (widget) return;
-
InvocationChain bindingChain = endpoint.getBindingInvocationChain();
if(osProvider != null) {
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatProviderFactory.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatProviderFactory.java
index 45e74d8ec8..f3be0c27bf 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatProviderFactory.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatProviderFactory.java
@@ -17,9 +17,9 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http.format;
+package org.apache.tuscany.sca.binding.http.wireformat.provider;
-import org.apache.tuscany.sca.binding.http.HTTPDefaultWireFormat;
+import org.apache.tuscany.sca.binding.http.wireformat.HTTPDefaultWireFormat;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.invocation.Interceptor;
@@ -36,7 +36,7 @@ public class HTTPDefaultWireFormatProviderFactory implements WireFormatProviderF
@Override
public Class<HTTPDefaultWireFormat> getModelType() {
- return null;
+ return HTTPDefaultWireFormat.class;
}
@Override
@@ -49,10 +49,6 @@ public class HTTPDefaultWireFormatProviderFactory implements WireFormatProviderF
return new WireFormatProvider() {
@Override
public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract) {
- // TODO: Ideally this wants to set the databinding on a per request basis from the
- // http content type and accept headers and so support things like json or xml etc,
- // for now to get started just use json
- interfaceContract.getInterface().resetDataBinding("JSON");
return interfaceContract;
}
@Override
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatServiceInterceptor.java
new file mode 100644
index 0000000000..d1c2c61242
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatServiceInterceptor.java
@@ -0,0 +1,71 @@
+/*
+ * 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.http.wireformat.provider;
+
+import org.apache.tuscany.sca.binding.http.HTTPBinding;
+import org.apache.tuscany.sca.common.http.HTTPContext;
+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.RuntimeEndpoint;
+
+/**
+ * Handles the default wire format for the http binding
+ *
+ * 1- determine the request and response format (xml, json, etc) from the
+ * binding config or content type header and accept headers
+ * - TODO: need a way to configure the databinding framework based on that format
+ * 2- get the request contents from the HttpServletRequest
+ * - for a post its just the request body
+ * - for a get need to convert the query string into a body based on the format (xml, json, etc)
+ * 3- send the request on down the wire
+ * 4- set the response contents in the HttpServletResponse
+ * (the databinding should already have put it in the correct format)
+ *
+ */
+public class HTTPDefaultWireFormatServiceInterceptor implements Interceptor {
+
+ private RuntimeEndpoint endpoint;
+ private HTTPBinding binding;
+ private Invoker next;
+
+ public HTTPDefaultWireFormatServiceInterceptor(RuntimeEndpoint endpoint) {
+ this.endpoint = endpoint;
+ this.binding = (HTTPBinding) endpoint.getBinding();
+ }
+
+ @Override
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ @Override
+ public Invoker getNext() {
+ return next;
+ }
+
+ @Override
+ public Message invoke(Message msg) {
+ HTTPContext context = msg.getBindingContext();
+
+ msg.setBody(new Object[] {context.getHttpRequest(), context.getHttpResponse()});
+ return getNext().invoke(msg);
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatProviderFactory.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatProviderFactory.java
new file mode 100644
index 0000000000..c9ef568402
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatProviderFactory.java
@@ -0,0 +1,68 @@
+/*
+ * 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.http.wireformat.provider;
+
+import org.apache.tuscany.sca.binding.http.wireformat.HTTPJSONWireFormat;
+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.WireFormatProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+public class HTTPJSONWireFormatProviderFactory implements WireFormatProviderFactory<HTTPJSONWireFormat> {
+
+ public HTTPJSONWireFormatProviderFactory(ExtensionPointRegistry extensionPoints) {
+ }
+
+ @Override
+ public Class<HTTPJSONWireFormat> getModelType() {
+ return HTTPJSONWireFormat.class;
+ }
+
+ @Override
+ public WireFormatProvider createReferenceWireFormatProvider(RuntimeEndpointReference endpointReference) {
+ return null;
+ }
+
+ @Override
+ public WireFormatProvider createServiceWireFormatProvider(final RuntimeEndpoint endpoint) {
+ return new WireFormatProvider() {
+ @Override
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract) {
+ // TODO: Ideally this wants to set the databinding on a per request basis from the
+ // http content type and accept headers and so support things like json or xml etc,
+ // for now to get started just use json
+ interfaceContract.getInterface().resetDataBinding("JSON");
+ return interfaceContract;
+ }
+ @Override
+ public Interceptor createInterceptor() {
+ return new HTTPJSONWireFormatServiceInterceptor(endpoint);
+ }
+ @Override
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_WIREFORMAT;
+ }};
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatServiceInterceptor.java
index e2ac99bfb8..3323fd34fe 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatServiceInterceptor.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatServiceInterceptor.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http.format;
+package org.apache.tuscany.sca.binding.http.wireformat.provider;
import java.io.BufferedReader;
import java.io.IOException;
@@ -58,12 +58,12 @@ import org.oasisopen.sca.ServiceRuntimeException;
* (the databinding should already have put it in the correct format)
*
*/
-public class HTTPDefaultWireFormatServiceInterceptor implements Interceptor {
+public class HTTPJSONWireFormatServiceInterceptor implements Interceptor {
private Invoker next;
private String jsonpCallbackName = "callback";
- public HTTPDefaultWireFormatServiceInterceptor(RuntimeEndpoint endpoint) {
+ public HTTPJSONWireFormatServiceInterceptor(RuntimeEndpoint endpoint) {
}
@Override
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPXMLWireFormatProviderFactory.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatProviderFactory.java
index cb60101bb7..3a670bd299 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPXMLWireFormatProviderFactory.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatProviderFactory.java
@@ -17,9 +17,9 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http.format;
+package org.apache.tuscany.sca.binding.http.wireformat.provider;
-import org.apache.tuscany.sca.binding.http.HTTPXMLWireFormat;
+import org.apache.tuscany.sca.binding.http.wireformat.HTTPXMLWireFormat;
import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
@@ -41,7 +41,7 @@ public class HTTPXMLWireFormatProviderFactory implements WireFormatProviderFacto
@Override
public Class<HTTPXMLWireFormat> getModelType() {
- return null;
+ return HTTPXMLWireFormat.class;
}
@Override
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPXMLWireFormatServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatServiceInterceptor.java
index bfc22ec78f..93935a9f41 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPXMLWireFormatServiceInterceptor.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatServiceInterceptor.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http.format;
+package org.apache.tuscany.sca.binding.http.wireformat.provider;
import java.io.BufferedReader;
import java.io.IOException;
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory
index 8d9b98604c..88560749de 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory
@@ -15,4 +15,5 @@
# specific language governing permissions and limitations
# under the License.
-org.apache.tuscany.sca.binding.http.format.HTTPDefaultOperationSelectorProviderFactory;model=org.apache.tuscany.sca.binding.http.HTTPDefaultOperationSelector
+org.apache.tuscany.sca.binding.http.operationselector.provider.HTTPDefaultOperationSelectorProviderFactory;model=org.apache.tuscany.sca.binding.http.operationselector.HTTPDefaultOperationSelector
+org.apache.tuscany.sca.binding.http.operationselector.provider.HTTPRPCOperationSelectorProviderFactory;model=org.apache.tuscany.sca.binding.http.operationselector.HTTPRPCOperationSelector
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory
index 88cd59bb13..796407d122 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory
@@ -15,5 +15,6 @@
# specific language governing permissions and limitations
# under the License.
-org.apache.tuscany.sca.binding.http.format.HTTPDefaultWireFormatProviderFactory;model=org.apache.tuscany.sca.binding.http.HTTPDefaultWireFormat
-org.apache.tuscany.sca.binding.http.format.HTTPXMLWireFormatProviderFactory;model=org.apache.tuscany.sca.binding.http.HTTPXMLWireFormat
+org.apache.tuscany.sca.binding.http.wireformat.provider.HTTPDefaultWireFormatProviderFactory;model=org.apache.tuscany.sca.binding.http.wireformat.HTTPDefaultWireFormat
+org.apache.tuscany.sca.binding.http.wireformat.provider.HTTPJSONWireFormatProviderFactory;model=org.apache.tuscany.sca.binding.http.wireformat.HTTPJSONWireFormat
+org.apache.tuscany.sca.binding.http.wireformat.provider.HTTPXMLWireFormatProviderFactory;model=org.apache.tuscany.sca.binding.http.wireformat.HTTPXMLWireFormat
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ResourceServiceTestCase.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ResourceServiceTestCase.java
new file mode 100644
index 0000000000..edbb111198
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ResourceServiceTestCase.java
@@ -0,0 +1,79 @@
+/*
+ * 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.http;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * HTTP binding unit tests for Helloworld service.
+ */
+public class ResourceServiceTestCase {
+
+ private static Node node;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ node = NodeFactory.newInstance().createNode("resource.composite", new String[] {"target/test-classes"});
+ node.start();
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ if (node != null) {
+ node.stop();
+ }
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ URL url = new URL("http://localhost:8080/resource");
+ InputStream is = url.openStream();
+ Assert.assertTrue(read(is).startsWith("Resource"));
+ }
+
+ private static String read(InputStream is) throws IOException {
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(is));
+ StringBuffer sb = new StringBuffer();
+ String str;
+ while ((str = reader.readLine()) != null) {
+ sb.append(str);
+ }
+ return sb.toString();
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/BeanA.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/BeanA.java
index 2c33895f67..73bd908db8 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/BeanA.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/BeanA.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
public class BeanA {
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuff.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuff.java
index cf0d457317..5c3ef631d7 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuff.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuff.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
import org.oasisopen.sca.annotation.Remotable;
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuffImpl.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuffImpl.java
index 9395024e5b..f41ca498c1 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuffImpl.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuffImpl.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
public class ComplexStuffImpl implements ComplexStuff {
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/Helloworld.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/Helloworld.java
index 17a0b28fdb..4ecda47d71 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/Helloworld.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/Helloworld.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
import org.oasisopen.sca.annotation.Remotable;
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HelloworldImpl.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/HelloworldImpl.java
index e245f607f1..f0a24a6d9a 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HelloworldImpl.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/HelloworldImpl.java
@@ -16,7 +16,7 @@
* specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
public class HelloworldImpl implements Helloworld {
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ResourceService.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ResourceService.java
new file mode 100644
index 0000000000..612a61247d
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ResourceService.java
@@ -0,0 +1,55 @@
+/*
+ * 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 services;
+
+import java.io.IOException;
+
+import javax.servlet.Servlet;
+import javax.servlet.ServletConfig;
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.oasisopen.sca.annotation.Service;
+
+@Service(Servlet.class)
+public class ResourceService extends HttpServlet implements Servlet {
+ private static final long serialVersionUID = 8240260033930060726L;
+
+ public void init(ServletConfig config) throws ServletException {
+ }
+
+ public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ response.addHeader("Content-Type","text/plain");
+ response.getOutputStream().print("Resource request sucessfuly handled : " + request.getRequestURI() +'\n');
+ }
+
+ public void destroy() {
+ }
+
+ public ServletConfig getServletConfig() {
+ return null;
+ }
+
+ public String getServletInfo() {
+ return null;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/SomeException.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/SomeException.java
index f4ffd19c9c..f65c22dc05 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/SomeException.java
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/SomeException.java
@@ -17,7 +17,7 @@
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
public class SomeException extends Exception {
private static final long serialVersionUID = 1L;
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite
index 7f4cc64fe2..9aa3e26c6c 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite
@@ -23,17 +23,21 @@
name="ComplexStuff">
<component name="ComplexComponent">
- <implementation.java class="org.apache.tuscany.sca.binding.http.ComplexStuffImpl"/>
+ <implementation.java class="services.ComplexStuffImpl"/>
<service name="ComplexStuff">
- <tuscany:binding.http />
+ <tuscany:binding.http>
+ <tuscany:wireFormat.json />
+ <tuscany:operationSelector.rpc />
+ </tuscany:binding.http>
</service>
</component>
<component name="ComplexXmlComponent">
- <implementation.java class="org.apache.tuscany.sca.binding.http.ComplexStuffImpl"/>
+ <implementation.java class="services.ComplexStuffImpl"/>
<service name="ComplexStuff">
<tuscany:binding.http>
- <tuscany:wireFormat.httpXml />
+ <tuscany:wireFormat.xml />
+ <tuscany:operationSelector.rpc />
</tuscany:binding.http>
</service>
</component>
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite
index 7497cfcbac..8b8b2877cd 100644
--- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite
@@ -23,17 +23,21 @@
name="helloworld">
<component name="HelloworldComponent">
- <implementation.java class="org.apache.tuscany.sca.binding.http.HelloworldImpl"/>
+ <implementation.java class="services.HelloworldImpl"/>
<service name="Helloworld">
- <tuscany:binding.http />
+ <tuscany:binding.http>
+ <tuscany:wireFormat.json />
+ <tuscany:operationSelector.rpc />
+ </tuscany:binding.http>
</service>
</component>
<component name="HelloworldXmlComponent">
- <implementation.java class="org.apache.tuscany.sca.binding.http.HelloworldImpl"/>
+ <implementation.java class="services.HelloworldImpl"/>
<service name="Helloworld">
<tuscany:binding.http>
- <tuscany:wireFormat.httpXml />
+ <tuscany:wireFormat.xml />
+ <tuscany:operationSelector.rpc />
</tuscany:binding.http>
</service>
</component>
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/resource.composite b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/resource.composite
new file mode 100644
index 0000000000..27b229e483
--- /dev/null
+++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/resource.composite
@@ -0,0 +1,33 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ * 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.
+-->
+<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912"
+ targetNamespace="http://sample/test"
+ xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1"
+ name="ResourceService">
+
+
+ <component name="ResourceComponent">
+ <implementation.java class="services.ResourceService" />
+ <service name="Servlet">
+ <tuscany:binding.http uri="/resource" />
+ </service>
+ </component>
+
+</composite> \ No newline at end of file