summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/branches/2.0/modules/binding-http-runtime/src')
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultOperationSelectorProviderFactory.java64
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultServiceOperationSelectorInterceptor.java105
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCOperationSelectorProviderFactory.java64
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCServiceOperationSelectorInterceptor.java85
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java64
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingServiceServlet.java70
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java175
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatProviderFactory.java68
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatServiceInterceptor.java58
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatProviderFactory.java72
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatServiceInterceptor.java252
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatProviderFactory.java74
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatServiceInterceptor.java182
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory20
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory19
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory20
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuffTestCase.java129
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HelloworldTestCase.java93
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ResourceServiceTestCase.java79
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/BeanA.java60
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/ComplexStuff.java32
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/ComplexStuffImpl.java53
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/Helloworld.java26
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/HelloworldImpl.java28
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/ResourceService.java55
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/SomeException.java29
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/resources/complex.composite45
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/resources/helloworld.composite45
-rw-r--r--sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/resources/resource.composite33
29 files changed, 2099 insertions, 0 deletions
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultOperationSelectorProviderFactory.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultOperationSelectorProviderFactory.java
new file mode 100644
index 0000000000..f1a9767374
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultOperationSelectorProviderFactory.java
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+/**
+ *
+ * @version $Rev$ $Date$
+*/
+public class HTTPDefaultOperationSelectorProviderFactory implements OperationSelectorProviderFactory<HTTPDefaultOperationSelector>{
+
+ public HTTPDefaultOperationSelectorProviderFactory(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/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultServiceOperationSelectorInterceptor.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultServiceOperationSelectorInterceptor.java
new file mode 100644
index 0000000000..4950ea2563
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultServiceOperationSelectorInterceptor.java
@@ -0,0 +1,105 @@
+/*
+ * 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;
+
+/**
+ * HTTP Binding Default operation selector, which would map
+ * http method (GET, PUT, POST, DELETE) to operations matching
+ * those name. It also supports plain servlet using 'service'
+ * to provide the component functionality.
+ *
+ * @version $Rev$ $Date$
+ */
+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/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCOperationSelectorProviderFactory.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCOperationSelectorProviderFactory.java
new file mode 100644
index 0000000000..08766e33ea
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCOperationSelectorProviderFactory.java
@@ -0,0 +1,64 @@
+/*
+ * 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;
+
+/**
+ *
+ * @version $Rev$ $Date$
+*/
+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 HTTPRPCServiceOperationSelectorInterceptor(endpoint);
+ }
+
+ @Override
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_OPERATION_SELECTOR;
+ }};
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCServiceOperationSelectorInterceptor.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCServiceOperationSelectorInterceptor.java
new file mode 100644
index 0000000000..915399bb4e
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCServiceOperationSelectorInterceptor.java
@@ -0,0 +1,85 @@
+/*
+ * 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 HTTPRPCServiceOperationSelectorInterceptor implements Interceptor {
+
+ private Invoker next;
+ private List<Operation> operations;
+
+ public HTTPRPCServiceOperationSelectorInterceptor(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();
+ String path = request.getPathInfo();
+ if (path.startsWith("/")) {
+ path = path.substring(1);
+ }
+
+ for (Operation op : operations) {
+ if (op.getName().equals(path)) {
+ msg.setOperation(op);
+ return next.invoke(msg);
+ }
+ }
+
+ throw new ServiceRuntimeException("No matching operation: " + path);
+ }
+
+ @Override
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ @Override
+ public Invoker getNext() {
+ return next;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java
new file mode 100644
index 0000000000..118a2c3bc4
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java
@@ -0,0 +1,64 @@
+/*
+ * 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.provider;
+
+import org.apache.tuscany.sca.binding.http.HTTPBinding;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.core.FactoryExtensionPoint;
+import org.apache.tuscany.sca.host.http.ServletHost;
+import org.apache.tuscany.sca.host.http.ServletHostHelper;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.provider.BindingProviderFactory;
+import org.apache.tuscany.sca.provider.ReferenceBindingProvider;
+import org.apache.tuscany.sca.provider.ServiceBindingProvider;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+
+/**
+ * Factory for HTTP binding providers.
+ *
+ * @version $Rev$ $Date$
+ */
+public class HTTPBindingProviderFactory implements BindingProviderFactory<HTTPBinding> {
+ private ExtensionPointRegistry extensionPoints;
+ private MessageFactory messageFactory;
+ private ServletHost servletHost;
+
+ public HTTPBindingProviderFactory(ExtensionPointRegistry extensionPoints) {
+ this.extensionPoints = extensionPoints;
+ this.servletHost = ServletHostHelper.getServletHost(extensionPoints);
+ FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class);
+ messageFactory = modelFactories.getFactory(MessageFactory.class);
+ }
+
+ public ReferenceBindingProvider createReferenceBindingProvider(RuntimeEndpointReference endpointReference) {
+ // Binding HTTP is currently NOT supporting References
+ return null;
+ }
+
+ public ServiceBindingProvider createServiceBindingProvider(RuntimeEndpoint endpoint) {
+ return new HTTPServiceBindingProvider(endpoint, extensionPoints, messageFactory, servletHost);
+ }
+
+ public Class<HTTPBinding> getModelType() {
+ return HTTPBinding.class;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingServiceServlet.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingServiceServlet.java
new file mode 100644
index 0000000000..c345177146
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingServiceServlet.java
@@ -0,0 +1,70 @@
+/*
+ * 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.provider;
+
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.sca.common.http.HTTPContext;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * HTTP Binding service servlet, that listens to HTTP
+ * requests and dispatch to the invocation chain.
+ *
+ * The proper invocation chains and/or wireformat interceptors
+ * will properly handle selecting the right operation and
+ * handling data
+ *
+ * @version $Rev$ $Date$
+ */
+public class HTTPBindingServiceServlet extends HttpServlet {
+ private static final long serialVersionUID = 6496710199406616194L;
+
+ protected transient MessageFactory messageFactory;
+ protected transient RuntimeEndpoint wire;
+
+ public HTTPBindingServiceServlet(RuntimeEndpoint wire, MessageFactory messageFactory) {
+ this.wire = wire;
+ this.messageFactory = messageFactory;
+ }
+
+ @Override
+ protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
+ HTTPContext bindingContext = new HTTPContext();
+ bindingContext.setHttpRequest(request);
+ bindingContext.setHttpResponse(response);
+ Message msg = messageFactory.createMessage();
+ msg.setBindingContext(bindingContext);
+ 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/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java
new file mode 100644
index 0000000000..6d23bfd329
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java
@@ -0,0 +1,175 @@
+/*
+ * 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.provider;
+
+import javax.servlet.Servlet;
+
+import org.apache.tuscany.sca.binding.http.HTTPBinding;
+import org.apache.tuscany.sca.binding.http.operationselector.HTTPDefaultOperationSelector;
+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;
+import org.apache.tuscany.sca.invocation.InvocationChain;
+import org.apache.tuscany.sca.invocation.MessageFactory;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.EndpointProvider;
+import org.apache.tuscany.sca.provider.OperationSelectorProvider;
+import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory;
+import org.apache.tuscany.sca.provider.ProviderFactoryExtensionPoint;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.provider.WireFormatProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * Implementation of an HTTP binding provider.
+ *
+ * @version $Rev$ $Date$
+ */
+public class HTTPServiceBindingProvider implements EndpointProvider {
+ private ExtensionPointRegistry extensionPoints;
+
+ private RuntimeEndpoint endpoint;
+ private HTTPBinding binding;
+ private MessageFactory messageFactory;
+ private OperationSelectorProvider osProvider;
+ private WireFormatProvider wfProvider;
+ private ServletHost servletHost;
+ private String servletMapping;
+ private InterfaceContract interfaceContract;
+
+ public HTTPServiceBindingProvider(RuntimeEndpoint endpoint,
+ ExtensionPointRegistry extensionPoints,
+ MessageFactory messageFactory,
+ ServletHost servletHost) {
+
+ this.endpoint = endpoint;
+ this.binding = (HTTPBinding)endpoint.getBinding();
+
+ this.extensionPoints = extensionPoints;
+ this.messageFactory = messageFactory;
+ this.servletHost = servletHost;
+
+ if (binding.getOperationSelector() == null) {
+ binding.setOperationSelector(new HTTPDefaultOperationSelector());
+ }
+ if (binding.getRequestWireFormat() == null) {
+ binding.setRequestWireFormat(new HTTPDefaultWireFormat());
+ }
+ if (binding.getResponseWireFormat() == null) {
+ binding.setResponseWireFormat(new HTTPDefaultWireFormat());
+ }
+
+ ProviderFactoryExtensionPoint providerFactories = extensionPoints.getExtensionPoint(ProviderFactoryExtensionPoint.class);
+
+ if (binding.getOperationSelector() != null) {
+ // Configure the interceptors for operation selection
+ OperationSelectorProviderFactory osProviderFactory = (OperationSelectorProviderFactory) providerFactories.getProviderFactory(binding.getOperationSelector().getClass());
+ if (osProviderFactory != null) {
+ this.osProvider = osProviderFactory.createServiceOperationSelectorProvider(endpoint);
+ }
+ }
+
+ if (binding.getRequestWireFormat() != null && binding.getResponseWireFormat() != null) {
+ // Configure the interceptors for wire format
+ WireFormatProviderFactory wfProviderFactory = (WireFormatProviderFactory) providerFactories.getProviderFactory(binding.getRequestWireFormat().getClass());
+ if (wfProviderFactory != null) {
+ this.wfProvider = wfProviderFactory.createServiceWireFormatProvider(endpoint);
+ }
+ }
+
+ //clone the service contract to avoid databinding issues
+ try {
+ interfaceContract = (InterfaceContract)endpoint.getComponentServiceInterfaceContract().clone();
+
+ // configure data binding
+ if (this.wfProvider != null) {
+ wfProvider.configureWireFormatInterfaceContract(interfaceContract);
+ }
+ } catch(CloneNotSupportedException e) {
+ // shouldn't happen
+ }
+
+ servletMapping = binding.getURI();
+ if (!servletMapping.endsWith("/")) {
+ servletMapping += "/";
+ }
+ if (!servletMapping.endsWith("*")) {
+ servletMapping += "*";
+ }
+ }
+
+ public void start() {
+
+ /**
+ * 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.");
+ }
+
+ Servlet servlet = new HTTPBindingServiceServlet(endpoint, messageFactory);
+
+ // Create our HTTP service listener Servlet and register it with the
+ // Servlet host
+ servletMapping = binding.getURI();
+ if (!servletMapping.endsWith("/")) {
+ servletMapping += "/";
+ }
+ if (!servletMapping.endsWith("*")) {
+ servletMapping += "*";
+ }
+
+ String deployedURI = servletHost.addServletMapping(servletMapping, servlet);
+ endpoint.setDeployedURI(deployedURI);
+ }
+
+ public void stop() {
+ servletHost.removeServletMapping(servletMapping);
+ }
+
+ public InterfaceContract getBindingInterfaceContract() {
+ return interfaceContract;
+ }
+
+ public boolean supportsOneWayInvocation() {
+ return false;
+ }
+
+ /**
+ * Add specific http interceptor to invocation chain
+ */
+ public void configure() {
+ 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());
+ }
+
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatProviderFactory.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatProviderFactory.java
new file mode 100644
index 0000000000..4c605a62be
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatProviderFactory.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.HTTPDefaultWireFormat;
+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;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class HTTPDefaultWireFormatProviderFactory implements WireFormatProviderFactory<HTTPDefaultWireFormat> {
+
+ public HTTPDefaultWireFormatProviderFactory(ExtensionPointRegistry extensionPoints) {
+ }
+
+ @Override
+ public Class<HTTPDefaultWireFormat> getModelType() {
+ return HTTPDefaultWireFormat.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) {
+ return interfaceContract;
+ }
+ @Override
+ public Interceptor createInterceptor() {
+ return new HTTPDefaultWireFormatServiceInterceptor(endpoint);
+ }
+ @Override
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_WIREFORMAT;
+ }};
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatServiceInterceptor.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatServiceInterceptor.java
new file mode 100644
index 0000000000..0b6771e5bc
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatServiceInterceptor.java
@@ -0,0 +1,58 @@
+/*
+ * 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.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
+ * by passing the HTTP request and response down to the
+ * actual component implementation that is a servlet.
+ *
+ */
+public class HTTPDefaultWireFormatServiceInterceptor implements Interceptor {
+ private Invoker next;
+
+ public HTTPDefaultWireFormatServiceInterceptor(RuntimeEndpoint endpoint) {
+
+ }
+
+ @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/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatProviderFactory.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatProviderFactory.java
new file mode 100644
index 0000000000..004941fdf5
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatProviderFactory.java
@@ -0,0 +1,72 @@
+/*
+ * 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;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+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/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatServiceInterceptor.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatServiceInterceptor.java
new file mode 100644
index 0000000000..3323fd34fe
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatServiceInterceptor.java
@@ -0,0 +1,252 @@
+/*
+ * 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 java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.StringTokenizer;
+import java.util.TreeSet;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.sca.common.http.HTTPContext;
+import org.apache.tuscany.sca.interfacedef.DataType;
+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;
+
+/**
+ * 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 HTTPJSONWireFormatServiceInterceptor implements Interceptor {
+
+ private Invoker next;
+ private String jsonpCallbackName = "callback";
+
+ public HTTPJSONWireFormatServiceInterceptor(RuntimeEndpoint endpoint) {
+ }
+
+ @Override
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ @Override
+ public Invoker getNext() {
+ return next;
+ }
+
+ @Override
+ public Message invoke(Message msg) {
+ try {
+ return invokeResponse(getNext().invoke(invokeRequest(msg)));
+ } catch (IOException e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ private Message invokeRequest(Message msg) throws IOException {
+ HTTPContext context = msg.getBindingContext();
+ HttpServletRequest servletRequest = context.getHttpRequest();
+ if ("GET".equals(servletRequest.getMethod())) {
+ msg.setBody(getRequestFromQueryString(msg.getOperation(), servletRequest));
+ } else {
+ msg.setBody(getRequestFromPost(msg.getOperation(), servletRequest));
+ }
+ return msg;
+ }
+
+ /**
+ * The data binding seems to be expecting an Object array of json strings so if the
+ * post data is a json array convert that to an array of strings
+ * TODO: should this be being done by the data binding framework?
+ */
+ private Object[] getRequestFromPost(Operation operation, HttpServletRequest servletRequest) throws IOException {
+ List<Object> os = new ArrayList<Object>();
+ String data = read(servletRequest);
+ if (data.length() > 0) {
+ if (data.startsWith("[") && data.endsWith("]")) {
+ data = data.substring(1, data.length()-1);
+ StringTokenizer st = new StringTokenizer(data, ",");
+ while (st.hasMoreElements()) {
+ os.add(st.nextElement());
+ }
+ } else {
+ os.add(data);
+ }
+ }
+ return os.toArray();
+ }
+
+ private Message invokeResponse(Message msg) throws IOException {
+ HTTPContext context = msg.getBindingContext();
+ HttpServletRequest servletRequest = context.getHttpRequest();
+ HttpServletResponse servletResponse = context.getHttpResponse();
+
+ if (msg.isFault()) {
+ servletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, String.valueOf(msg.getBody()));
+ } else {
+ String response = getResponseAsString(servletRequest, servletResponse, msg.getBody());
+ servletResponse.getOutputStream().println(response);
+ }
+
+ return msg;
+ }
+
+ /**
+ * Turn the request into a string array of JSON structures. The data binding
+ * layer will then convert each of the individual parameters into the appropriate
+ * types for the implementation interface
+ *
+ * From ML thread: http://apache.markmail.org/message/ix3vvyomronellmi
+ * 1- if the binding configuration contains a mapping from query parameter name to operation parameter then use that.
+ * 2- if the service interface or impl uses jaxrs annotations to name the parameters then use that mapping
+ * 3- if the query parameters are name arg0, arg1 etc than use those names for the mapping,
+ * 4- otherwise use the order in the query string.
+ */
+ protected Object[] getRequestFromQueryString(Operation operation, ServletRequest servletRequest) {
+
+ List<DataType> types = operation.getInputType().getLogical();
+ int typesIndex = 0;
+
+ List<String> jsonRequestArray = new ArrayList<String>();
+
+ for (String name : getOrderedParameterNames(servletRequest)) {
+ String jsonRequest = "";
+ // quote string parameters so clients work in the usual javascript way
+ if (typesIndex < types.size() && String.class.equals(types.get(typesIndex++).getGenericType())) {
+ String x = servletRequest.getParameter(name);
+ if (x.startsWith("\"") || x.startsWith("'")) {
+ jsonRequest += x;
+ } else {
+ if (x.contains("\"")) {
+ jsonRequest += "'" + x + "'";
+ } else {
+ jsonRequest += "\"" + x + "\"";
+ }
+ }
+ } else {
+ jsonRequest += servletRequest.getParameter(name);
+ }
+ jsonRequestArray.add(jsonRequest);
+ }
+
+ return jsonRequestArray.toArray();
+ }
+
+ /**
+ * Get the request parameter names in the correct order.
+ * Either the query parameters are named arg0, arg1, arg2 etc or else use the order
+ * from the order in the query string. Eg, the url:
+ * http://localhost:8085/HelloWorldService/sayHello2?first=petra&last=arnold&callback=foo"
+ * should invoke:
+ * sayHello2("petra", "arnold")
+ * so the parameter names should be ordered: "first", "last"
+ */
+ protected List<String> getOrderedParameterNames(ServletRequest servletRequest) {
+ List<String> orderedNames = new ArrayList<String>();
+ Set<String> parameterNames = servletRequest.getParameterMap().keySet();
+ if (parameterNames.contains("arg0")) {
+ for (int i=0; i<parameterNames.size(); i++) {
+ String name = "arg" + i;
+ if (parameterNames.contains(name)) {
+ orderedNames.add(name);
+ } else {
+ break;
+ }
+ }
+ } else {
+ final String queryString = ((HttpServletRequest)servletRequest).getQueryString();
+ SortedSet<String> sortedNames = new TreeSet<String>(new Comparator<String>(){
+ public int compare(String o1, String o2) {
+ int i = queryString.indexOf(o1);
+ int j = queryString.indexOf(o2);
+ return i - j;
+ }});
+ for (String name : parameterNames) {
+ // ignore system and jsonpCallbackName parameters
+ if (!name.startsWith("_") && !name.equals(jsonpCallbackName)) {
+ sortedNames.add(name);
+ }
+ }
+ orderedNames.addAll(sortedNames);
+ }
+ return orderedNames;
+ }
+
+ /**
+ * The databinding layer will have converted the return type into a JSON string so simply
+ * add wrap it for return.
+ */
+ protected String getResponseAsString(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Object response) {
+ String jsonResponse = response == null ? "" : response.toString();
+
+ if ("GET".equals(servletRequest.getMethod())) {
+ // handle JSONP callback name padding
+ String callback = servletRequest.getParameter(jsonpCallbackName);
+ if (callback != null && callback.length() > 1) {
+ jsonResponse = callback + "(" + jsonResponse + ");";
+ }
+ }
+
+ return jsonResponse;
+ }
+
+ protected static String read(HttpServletRequest servletRequest) throws IOException {
+ InputStream is = servletRequest.getInputStream();
+ 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().trim();
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatProviderFactory.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatProviderFactory.java
new file mode 100644
index 0000000000..d09ddc0ea5
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatProviderFactory.java
@@ -0,0 +1,74 @@
+/*
+ * 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.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;
+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;
+
+/**
+ *
+ * @version $Rev$ $Date$
+ */
+public class HTTPXMLWireFormatProviderFactory implements WireFormatProviderFactory<HTTPXMLWireFormat> {
+
+ private DOMHelper domHelper;
+
+ public HTTPXMLWireFormatProviderFactory(ExtensionPointRegistry extensionPoints) {
+ this.domHelper = DOMHelper.getInstance(extensionPoints);
+ }
+
+ @Override
+ public Class<HTTPXMLWireFormat> getModelType() {
+ return HTTPXMLWireFormat.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) {
+ interfaceContract.getInterface().resetDataBinding(DOMDataBinding.NAME);
+ return interfaceContract;
+ }
+ @Override
+ public Interceptor createInterceptor() {
+ return new HTTPXMLWireFormatServiceInterceptor(endpoint, domHelper);
+ }
+ @Override
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_WIREFORMAT;
+ }};
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatServiceInterceptor.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatServiceInterceptor.java
new file mode 100644
index 0000000000..93935a9f41
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatServiceInterceptor.java
@@ -0,0 +1,182 @@
+/*
+ * 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 java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.ArrayList;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+
+import javax.servlet.ServletRequest;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.apache.tuscany.sca.common.http.HTTPContext;
+import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.interfacedef.util.FaultException;
+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;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.xml.sax.SAXException;
+
+/**
+ * Handles the xml wire format for the http binding
+ */
+public class HTTPXMLWireFormatServiceInterceptor implements Interceptor {
+
+ private Invoker next;
+ private DOMHelper domHelper;
+
+ public HTTPXMLWireFormatServiceInterceptor(RuntimeEndpoint endpoint, DOMHelper domHelper) {
+ this.domHelper = domHelper;
+ }
+
+ @Override
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ @Override
+ public Invoker getNext() {
+ return next;
+ }
+
+ @Override
+ public Message invoke(Message msg) {
+ try {
+ return invokeResponse(getNext().invoke(invokeRequest(msg)));
+ } catch (Exception e) {
+ throw new ServiceRuntimeException(e);
+ }
+ }
+
+ private Message invokeRequest(Message msg) throws IOException, SAXException {
+ HTTPContext context = msg.getBindingContext();
+ HttpServletRequest servletRequest = context.getHttpRequest();
+ if ("GET".equals(servletRequest.getMethod())) {
+ msg.setBody(getRequestFromQueryString(msg.getOperation(), servletRequest));
+ } else {
+ msg.setBody(new Object[]{domHelper.load(read(servletRequest))});
+ }
+ return msg;
+ }
+
+ private Message invokeResponse(Message msg) throws IOException {
+ HTTPContext context = msg.getBindingContext();
+ HttpServletResponse servletResponse = context.getHttpResponse();
+
+ servletResponse.setContentType("text/xml");
+
+ Object o = msg.getBody();
+ if (msg.isFault()) {
+ String xml = domHelper.saveAsString((Node)((FaultException)o).getFaultInfo());
+ servletResponse.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, xml);
+ } else {
+ String xml = "";
+ if (o instanceof Element) {
+ xml = domHelper.saveAsString((Node)o);
+ } else if ((o instanceof Object[]) && ((Object[])o)[0] instanceof Node) {
+ xml = domHelper.saveAsString((Node)((Object[])o)[0]);
+ } else if (o != null) {
+ throw new IllegalStateException("expecting Node payload: " + o);
+ }
+ servletResponse.getOutputStream().println(xml);
+ }
+
+ return msg;
+ }
+
+ /**
+ * Turn the query request into XML.
+ */
+ protected Object[] getRequestFromQueryString(Operation operation, ServletRequest servletRequest) throws IOException, SAXException {
+ List<Object> xmlRequestArray = new ArrayList<Object>();
+ for (String name : getOrderedParameterNames(servletRequest)) {
+ xmlRequestArray.add(domHelper.load("<" + name + ">" + servletRequest.getParameter(name) + "</" + name + ">"));
+ }
+ return xmlRequestArray.toArray();
+ }
+
+ /**
+ * Get the request parameter names in the correct order.
+ * Either the query parameters are named arg0, arg1, arg2 etc or else use the order
+ * from the order in the query string. Eg, the url:
+ * http://localhost:8085/HelloWorldService/sayHello2?first=petra&last=arnold&callback=foo"
+ * should invoke:
+ * sayHello2("petra", "arnold")
+ * so the parameter names should be ordered: "first", "last"
+ */
+ protected List<String> getOrderedParameterNames(ServletRequest servletRequest) {
+ List<String> orderedNames = new ArrayList<String>();
+ Set<String> parameterNames = servletRequest.getParameterMap().keySet();
+ if (parameterNames.contains("arg0")) {
+ for (int i=0; i<parameterNames.size(); i++) {
+ String name = "arg" + i;
+ if (parameterNames.contains(name)) {
+ orderedNames.add(name);
+ } else {
+ break;
+ }
+ }
+ } else {
+ final String queryString = ((HttpServletRequest)servletRequest).getQueryString();
+ SortedSet<String> sortedNames = new TreeSet<String>(new Comparator<String>(){
+ public int compare(String o1, String o2) {
+ int i = queryString.indexOf(o1);
+ int j = queryString.indexOf(o2);
+ return i - j;
+ }});
+ for (String name : parameterNames) {
+ sortedNames.add(name);
+ }
+ orderedNames.addAll(sortedNames);
+ }
+ return orderedNames;
+ }
+
+ protected static String read(HttpServletRequest servletRequest) throws IOException {
+ InputStream is = servletRequest.getInputStream();
+ 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/branches/2.0/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory
new file mode 100644
index 0000000000..48678871eb
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory
@@ -0,0 +1,20 @@
+# 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 binding extension
+org.apache.tuscany.sca.binding.http.provider.HTTPBindingProviderFactory;model=org.apache.tuscany.sca.binding.http.HTTPBinding,ranking=100
+
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory
new file mode 100644
index 0000000000..88560749de
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory
@@ -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.
+
+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/branches/2.0/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory
new file mode 100644
index 0000000000..796407d122
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory
@@ -0,0 +1,20 @@
+# 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.
+
+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/branches/2.0/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuffTestCase.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuffTestCase.java
new file mode 100644
index 0000000000..704a24554b
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuffTestCase.java
@@ -0,0 +1,129 @@
+/*
+ * 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 ComplexStuffTestCase {
+
+ private static Node node;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ node = NodeFactory.newInstance().createNode("complex.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/ComplexComponent/ComplexStuff/multiParams?x=1&s=petra&b=true");
+ InputStream is = url.openStream();
+ Assert.assertEquals("\"1petratrue\"", read(is));
+ }
+
+ @Test
+ public void testNoArgs() throws Exception {
+ URL url = new URL("http://localhost:8080/ComplexComponent/ComplexStuff/noArgs");
+ InputStream is = url.openStream();
+ Assert.assertEquals("\"noArgs\"", read(is));
+ }
+
+ @Test
+ public void testEchoBean() throws Exception {
+ URL url = new URL("http://localhost:8080/ComplexComponent/ComplexStuff/echoBeanA?x={\"s\":\"petra\",\"b\":true,\"y\":42,\"x\":1}");
+ InputStream is = url.openStream();
+ String result = read(is);
+ Assert.assertTrue(result.startsWith("{"));
+ Assert.assertTrue(result.contains("\"s\":\"petra\""));
+ Assert.assertTrue(result.contains("\"b\":true"));
+ Assert.assertTrue(result.contains("\"y\":42"));
+ Assert.assertTrue(result.contains("\"x\":1"));
+ // Assert.assertEquals("{\"s\":\"petra\",\"b\":true,\"y\":42,\"x\":1}", read(is));
+ }
+
+ @Test
+ public void testVoidReturn() throws Exception {
+ URL url = new URL("http://localhost:8080/ComplexComponent/ComplexStuff/voidReturn");
+ InputStream is = url.openStream();
+ Assert.assertEquals("", read(is));
+ }
+
+ @Test
+ public void testCheckedException() throws Exception {
+ URL url = new URL("http://localhost:8080/ComplexComponent/ComplexStuff/checkedException");
+ try {
+ InputStream is = url.openStream();
+ Assert.fail();
+ } catch (IOException e) {
+ // expected
+ // TODO: what should happen with checked exceptions?
+ }
+ }
+
+ @Test
+ public void testRuntimeException() throws Exception {
+ URL url = new URL("http://localhost:8080/ComplexComponent/ComplexStuff/runtimeException");
+ try {
+ InputStream is = url.openStream();
+ Assert.fail();
+ } catch (IOException e) {
+ Assert.assertTrue(e.getMessage().contains("HTTP response code: 500"));
+ }
+ }
+
+ 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/branches/2.0/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HelloworldTestCase.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HelloworldTestCase.java
new file mode 100644
index 0000000000..89598b91c7
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HelloworldTestCase.java
@@ -0,0 +1,93 @@
+/*
+ * 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 HelloworldTestCase {
+
+ private static Node node;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ node = NodeFactory.newInstance().createNode("helloworld.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/HelloworldComponent/Helloworld/sayHello?name=Petra");
+ InputStream is = url.openStream();
+ Assert.assertEquals("\"Hello Petra\"", read(is));
+ }
+
+ @Test
+ public void testGetArg0() throws Exception {
+ URL url = new URL("http://localhost:8080/HelloworldComponent/Helloworld/sayHello?arg0=Petra");
+ InputStream is = url.openStream();
+ Assert.assertEquals("\"Hello Petra\"", read(is));
+ }
+
+ @Test
+ public void testXml() throws Exception {
+ URL url = new URL("http://localhost:8080/HelloworldXmlComponent/Helloworld/sayHello?arg0=Petra");
+ InputStream is = url.openStream();
+ Assert.assertTrue(read(is).endsWith(">Hello Petra</return>"));
+ }
+
+ 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/branches/2.0/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ResourceServiceTestCase.java b/sca-java-2.x/branches/2.0/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/branches/2.0/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/branches/2.0/modules/binding-http-runtime/src/test/java/services/BeanA.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/BeanA.java
new file mode 100644
index 0000000000..73bd908db8
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/BeanA.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 services;
+
+public class BeanA {
+
+ protected Boolean b;
+ protected String s;
+ protected int x;
+ protected Integer y;
+
+ public Boolean getB() {
+ return b;
+ }
+
+ public void setB(Boolean b) {
+ this.b = b;
+ }
+
+ public String getS() {
+ return s;
+ }
+
+ public void setS(String s) {
+ this.s = s;
+ }
+
+ public int getX() {
+ return x;
+ }
+
+ public void setX(int x) {
+ this.x = x;
+ }
+
+ public Integer getY() {
+ return y;
+ }
+
+ public void setY(Integer y) {
+ this.y = y;
+ }
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/ComplexStuff.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/ComplexStuff.java
new file mode 100644
index 0000000000..5c3ef631d7
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/ComplexStuff.java
@@ -0,0 +1,32 @@
+/*
+ * 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 org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
+public interface ComplexStuff {
+ BeanA echoBeanA(BeanA bean);
+ String multiParams(int x, String s, Boolean b);
+ String noArgs();
+ void voidReturn();
+ String checkedException() throws SomeException;
+ String runtimeException();
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/ComplexStuffImpl.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/ComplexStuffImpl.java
new file mode 100644
index 0000000000..f41ca498c1
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/ComplexStuffImpl.java
@@ -0,0 +1,53 @@
+/*
+ * 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;
+
+public class ComplexStuffImpl implements ComplexStuff {
+
+ @Override
+ public BeanA echoBeanA(BeanA bean) {
+ return bean;
+ }
+
+ @Override
+ public String multiParams(int x, String s, Boolean b) {
+ return x + s + b;
+ }
+
+ @Override
+ public String noArgs() {
+ return "noArgs";
+ }
+
+ @Override
+ public void voidReturn() {
+ }
+
+ @Override
+ public String checkedException() throws SomeException {
+ throw new SomeException("some msg");
+ }
+
+ @Override
+ public String runtimeException() {
+ throw new RuntimeException("bang");
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/Helloworld.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/Helloworld.java
new file mode 100644
index 0000000000..4ecda47d71
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/Helloworld.java
@@ -0,0 +1,26 @@
+/*
+ * 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 org.oasisopen.sca.annotation.Remotable;
+
+@Remotable
+public interface Helloworld {
+ String sayHello(String name);
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/HelloworldImpl.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/HelloworldImpl.java
new file mode 100644
index 0000000000..f0a24a6d9a
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/HelloworldImpl.java
@@ -0,0 +1,28 @@
+/*
+ * 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;
+
+public class HelloworldImpl implements Helloworld {
+
+ @Override
+ public String sayHello(String name) {
+ return "Hello " + name;
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/ResourceService.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/ResourceService.java
new file mode 100644
index 0000000000..612a61247d
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/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/branches/2.0/modules/binding-http-runtime/src/test/java/services/SomeException.java b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/SomeException.java
new file mode 100644
index 0000000000..f65c22dc05
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/java/services/SomeException.java
@@ -0,0 +1,29 @@
+/*
+ * 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;
+
+public class SomeException extends Exception {
+ private static final long serialVersionUID = 1L;
+
+ public SomeException(String msg) {
+ super(msg);
+ }
+
+}
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/resources/complex.composite b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/resources/complex.composite
new file mode 100644
index 0000000000..9aa3e26c6c
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/resources/complex.composite
@@ -0,0 +1,45 @@
+<?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="ComplexStuff">
+
+ <component name="ComplexComponent">
+ <implementation.java class="services.ComplexStuffImpl"/>
+ <service name="ComplexStuff">
+ <tuscany:binding.http>
+ <tuscany:wireFormat.json />
+ <tuscany:operationSelector.rpc />
+ </tuscany:binding.http>
+ </service>
+ </component>
+
+ <component name="ComplexXmlComponent">
+ <implementation.java class="services.ComplexStuffImpl"/>
+ <service name="ComplexStuff">
+ <tuscany:binding.http>
+ <tuscany:wireFormat.xml />
+ <tuscany:operationSelector.rpc />
+ </tuscany:binding.http>
+ </service>
+ </component>
+
+</composite>
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/resources/helloworld.composite b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/resources/helloworld.composite
new file mode 100644
index 0000000000..8b8b2877cd
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/resources/helloworld.composite
@@ -0,0 +1,45 @@
+<?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="helloworld">
+
+ <component name="HelloworldComponent">
+ <implementation.java class="services.HelloworldImpl"/>
+ <service name="Helloworld">
+ <tuscany:binding.http>
+ <tuscany:wireFormat.json />
+ <tuscany:operationSelector.rpc />
+ </tuscany:binding.http>
+ </service>
+ </component>
+
+ <component name="HelloworldXmlComponent">
+ <implementation.java class="services.HelloworldImpl"/>
+ <service name="Helloworld">
+ <tuscany:binding.http>
+ <tuscany:wireFormat.xml />
+ <tuscany:operationSelector.rpc />
+ </tuscany:binding.http>
+ </service>
+ </component>
+
+</composite>
diff --git a/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/resources/resource.composite b/sca-java-2.x/branches/2.0/modules/binding-http-runtime/src/test/resources/resource.composite
new file mode 100644
index 0000000000..27b229e483
--- /dev/null
+++ b/sca-java-2.x/branches/2.0/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