diff options
author | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2011-11-11 00:53:16 +0000 |
---|---|---|
committer | lresende <lresende@13f79535-47bb-0310-9956-ffa450edef68> | 2011-11-11 00:53:16 +0000 |
commit | cd07713f408a9edc820fb70a7dead012ee1ff899 (patch) | |
tree | baea598f776a47141d9afc49f453200ba1f947f2 /sca-java-2.x/trunk | |
parent | c607b0cf671eda11eff333748e4ce3a75ce941d1 (diff) |
Refactoring binding http model to bring back support for servlet based resources, and making rpc style it's own operationSelector
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@1200669 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/trunk')
41 files changed, 965 insertions, 458 deletions
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/binding-http-runtime/META-INF/MANIFEST.MF index 0cadabbf76..9f9fc76ee3 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/META-INF/MANIFEST.MF @@ -12,6 +12,8 @@ Import-Package: javax.servlet, javax.servlet.http, org.apache.tuscany.sca.assembly;version="2.0.0", org.apache.tuscany.sca.binding.http;version="2.0.0", + org.apache.tuscany.sca.binding.http.operationselector, + org.apache.tuscany.sca.binding.http.wireformat, org.apache.tuscany.sca.common.http;version="2.0.0", org.apache.tuscany.sca.core;version="2.0.0", org.apache.tuscany.sca.host.http;version="2.0.0", diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultOperationSelectorProviderFactory.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultOperationSelectorProviderFactory.java index bf6ad75cd3..f027424ff0 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultOperationSelectorProviderFactory.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultOperationSelectorProviderFactory.java @@ -17,9 +17,9 @@ * under the License.
*/
-package org.apache.tuscany.sca.binding.http.format;
+package org.apache.tuscany.sca.binding.http.operationselector.provider;
-import org.apache.tuscany.sca.binding.http.HTTPDefaultOperationSelector;
+import org.apache.tuscany.sca.binding.http.operationselector.HTTPDefaultOperationSelector;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.invocation.Interceptor;
import org.apache.tuscany.sca.invocation.Phase;
@@ -35,7 +35,7 @@ public class HTTPDefaultOperationSelectorProviderFactory implements OperationSel @Override
public Class<HTTPDefaultOperationSelector> getModelType() {
- return null;
+ return HTTPDefaultOperationSelector.class;
}
@Override
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultServiceOperationSelectorInterceptor.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultServiceOperationSelectorInterceptor.java new file mode 100644 index 0000000000..e9cb0fd1da --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPDefaultServiceOperationSelectorInterceptor.java @@ -0,0 +1,108 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.http.operationselector.provider;
+
+import java.util.List;
+
+import javax.servlet.http.HttpServletRequest;
+
+import org.apache.tuscany.sca.common.http.HTTPContext;
+import org.apache.tuscany.sca.interfacedef.Interface;
+import org.apache.tuscany.sca.interfacedef.Operation;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.oasisopen.sca.ServiceRuntimeException;
+
+/**
+ * Sets the operation based on the request path.
+ *
+ * From a url: http://localhost:8080/HelloworldComponent/Helloworld/sayHello?name=Petra
+ * where the component is HelloworldComponent and the service is Helloworld
+ * the path will be "/sayHello" so the operation is "sayHello".
+ *
+ * TODO: we could also do something similar to how the JMS binding supports
+ * a single "onMessage" method to get all requests, so perhaps this could
+ * also support impls with method: service(HttpServletRequest, HttpServletResponse)
+ */
+public class HTTPDefaultServiceOperationSelectorInterceptor implements Interceptor {
+
+ private Invoker next;
+ private List<Operation> operations;
+
+ public HTTPDefaultServiceOperationSelectorInterceptor(RuntimeEndpoint endpoint) {
+ Interface serviceInterface = endpoint.getService().getInterfaceContract().getInterface();
+ this.operations = serviceInterface.getOperations();
+ }
+
+ @Override
+ public Message invoke(Message msg) {
+ HTTPContext context = msg.getBindingContext();
+ HttpServletRequest request = context.getHttpRequest();
+
+ Operation operation = findOperation(request.getMethod());
+ if(operation == null) {
+ operation = findOperation("service");
+ }
+
+ if(operation == null) {
+ throw new ServiceRuntimeException("No matching operation for " + request.getMethod());
+ }
+ msg.setOperation(operation);
+ return next.invoke(msg);
+ }
+
+ @Override
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ @Override
+ public Invoker getNext() {
+ return next;
+ }
+
+
+
+ /**
+ * Find the operation from the component service contract
+ * @param componentService
+ * @param method
+ * @return
+ */
+ private Operation findOperation(String method) {
+ if (method.contains(".")) {
+ method = method.substring(method.lastIndexOf(".") + 1);
+ }
+
+ Operation result = null;
+ for (Operation o : operations) {
+ if (o.isDynamic())
+ return o;
+ if (o.getName().equalsIgnoreCase(method)) {
+ result = o;
+ break;
+ }
+ }
+
+ return result;
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCOperationSelectorProviderFactory.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCOperationSelectorProviderFactory.java new file mode 100644 index 0000000000..bc34a86af5 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCOperationSelectorProviderFactory.java @@ -0,0 +1,60 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.http.operationselector.provider;
+
+import org.apache.tuscany.sca.binding.http.operationselector.HTTPDefaultOperationSelector;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.OperationSelectorProvider;
+import org.apache.tuscany.sca.provider.OperationSelectorProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+public class HTTPRPCOperationSelectorProviderFactory implements OperationSelectorProviderFactory<HTTPDefaultOperationSelector>{
+
+ public HTTPRPCOperationSelectorProviderFactory(ExtensionPointRegistry extensionPoints) {
+ }
+
+ @Override
+ public Class<HTTPDefaultOperationSelector> getModelType() {
+ return HTTPDefaultOperationSelector.class;
+ }
+
+ @Override
+ public OperationSelectorProvider createReferenceOperationSelectorProvider(RuntimeEndpointReference endpointReference) {
+ return null;
+ }
+
+ @Override
+ public OperationSelectorProvider createServiceOperationSelectorProvider(final RuntimeEndpoint endpoint) {
+ return new OperationSelectorProvider(){
+ @Override
+ public Interceptor createInterceptor() {
+ return new HTTPDefaultServiceOperationSelectorInterceptor(endpoint);
+ }
+
+ @Override
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_OPERATION_SELECTOR;
+ }};
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultServiceOperationSelectorInterceptor.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCServiceOperationSelectorInterceptor.java index d45401bd7f..915399bb4e 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultServiceOperationSelectorInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/provider/HTTPRPCServiceOperationSelectorInterceptor.java @@ -17,7 +17,7 @@ * under the License.
*/
-package org.apache.tuscany.sca.binding.http.format;
+package org.apache.tuscany.sca.binding.http.operationselector.provider;
import java.util.List;
@@ -43,12 +43,12 @@ import org.oasisopen.sca.ServiceRuntimeException; * a single "onMessage" method to get all requests, so perhaps this could
* also support impls with method: service(HttpServletRequest, HttpServletResponse)
*/
-public class HTTPDefaultServiceOperationSelectorInterceptor implements Interceptor {
+public class HTTPRPCServiceOperationSelectorInterceptor implements Interceptor {
private Invoker next;
private List<Operation> operations;
- public HTTPDefaultServiceOperationSelectorInterceptor(RuntimeEndpoint endpoint) {
+ public HTTPRPCServiceOperationSelectorInterceptor(RuntimeEndpoint endpoint) {
Interface serviceInterface = endpoint.getService().getInterfaceContract().getInterface();
this.operations = serviceInterface.getOperations();
}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java index e2a3a5cf39..4835a54906 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java @@ -45,7 +45,7 @@ import org.apache.tuscany.sca.invocation.MessageFactory; */ public class HTTPBindingListenerServlet extends HttpServlet { private static final long serialVersionUID = 2865466417329430610L; - + transient private Binding binding; private MessageFactory messageFactory; @@ -57,7 +57,7 @@ public class HTTPBindingListenerServlet extends HttpServlet { private Invoker conditionalPostInvoker; private Invoker deleteInvoker; private Invoker conditionalDeleteInvoker; - + /** * Constructs a new HTTPServiceListenerServlet. */ @@ -66,12 +66,12 @@ public class HTTPBindingListenerServlet extends HttpServlet { this.messageFactory = messageFactory; } - + @Override protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { super.service(request, response); } - + @Override protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Get the request path @@ -88,43 +88,43 @@ public class HTTPBindingListenerServlet extends HttpServlet { Message requestMessage = messageFactory.createMessage(); String id = path.substring(1); - + Message responseMessage = null; HTTPCacheContext cacheContext = null; try { - cacheContext = HTTPCacheContext.createCacheContextFromRequest(request); + cacheContext = HTTPCacheContext.createCacheContextFromRequest(request); } catch (ParseException e) { } // Route message based on availability of cache info and cache methods if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalGetInvoker != null )) { - requestMessage.setBody(new Object[] {id, cacheContext}); - responseMessage = conditionalGetInvoker.invoke(requestMessage); + requestMessage.setBody(new Object[] {id, cacheContext}); + responseMessage = conditionalGetInvoker.invoke(requestMessage); } else { - requestMessage.setBody(new Object[] {id}); - responseMessage = getInvoker.invoke(requestMessage); + requestMessage.setBody(new Object[] {id}); + responseMessage = getInvoker.invoke(requestMessage); } if (responseMessage.isFault()) { - Object body = responseMessage.getBody(); - - int index = -1; - if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { - if ( index > -1 ) - response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); - else - response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); - return; - } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { - if ( index > -1 ) - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); - else - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); - return; + Object body = responseMessage.getBody(); + + int index = -1; + if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); + return; + } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); + return; } - + throw new ServletException((Throwable)responseMessage.getBody()); } - + if(response.getContentType() == null || response.getContentType().length() == 0){ // Calculate content-type based on extension String contentType = HTTPContentTypeMapper.getContentType(id); @@ -132,7 +132,7 @@ public class HTTPBindingListenerServlet extends HttpServlet { response.setContentType(contentType); } } - + // Write the response from the service implementation to the response // output stream InputStream is = (InputStream)responseMessage.getBody(); @@ -162,43 +162,43 @@ public class HTTPBindingListenerServlet extends HttpServlet { // Invoke the get operation on the service implementation Message requestMessage = messageFactory.createMessage(); String id = path.substring(1); - + Message responseMessage = null; HTTPCacheContext cacheContext = null; try { - cacheContext = HTTPCacheContext.createCacheContextFromRequest(request); + cacheContext = HTTPCacheContext.createCacheContextFromRequest(request); } catch (ParseException e) { } - + // Route message based on availability of cache info and cache methods if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalDeleteInvoker != null )) { - requestMessage.setBody(new Object[] {id, cacheContext}); - responseMessage = conditionalDeleteInvoker.invoke(requestMessage); + requestMessage.setBody(new Object[] {id, cacheContext}); + responseMessage = conditionalDeleteInvoker.invoke(requestMessage); } else { - requestMessage.setBody(new Object[] {id}); - responseMessage = deleteInvoker.invoke(requestMessage); + requestMessage.setBody(new Object[] {id}); + responseMessage = deleteInvoker.invoke(requestMessage); } if (responseMessage.isFault()) { - Object body = responseMessage.getBody(); - - int index = -1; - if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { - if ( index > -1 ) - response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); - else - response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); - return; - } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { - if ( index > -1 ) - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); - else - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); - return; + Object body = responseMessage.getBody(); + + int index = -1; + if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); + return; + } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); + return; } - + throw new ServletException((Throwable)responseMessage.getBody()); } - + // Write the response from the service implementation to the response // output stream InputStream is = (InputStream)responseMessage.getBody(); @@ -228,43 +228,43 @@ public class HTTPBindingListenerServlet extends HttpServlet { // Invoke the get operation on the service implementation Message requestMessage = messageFactory.createMessage(); String id = path.substring(1); - + Message responseMessage = null; HTTPCacheContext cacheContext = null; try { - cacheContext = HTTPCacheContext.createCacheContextFromRequest(request); + cacheContext = HTTPCacheContext.createCacheContextFromRequest(request); } catch (ParseException e) { } - + // Route message based on availability of cache info and cache methods if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalPutInvoker != null )) { - requestMessage.setBody(new Object[] {id, cacheContext}); - responseMessage = conditionalPutInvoker.invoke(requestMessage); + requestMessage.setBody(new Object[] {id, cacheContext}); + responseMessage = conditionalPutInvoker.invoke(requestMessage); } else { - requestMessage.setBody(new Object[] {id}); - responseMessage = putInvoker.invoke(requestMessage); + requestMessage.setBody(new Object[] {id}); + responseMessage = putInvoker.invoke(requestMessage); } if (responseMessage.isFault()) { - Object body = responseMessage.getBody(); - - int index = -1; - if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { - if ( index > -1 ) - response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); - else - response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); - return; - } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { - if ( index > -1 ) - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); - else - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); - return; + Object body = responseMessage.getBody(); + + int index = -1; + if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); + return; + } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); + return; } - + throw new ServletException((Throwable)responseMessage.getBody()); } - + // Write the response from the service implementation to the response // output stream InputStream is = (InputStream)responseMessage.getBody(); @@ -294,58 +294,58 @@ public class HTTPBindingListenerServlet extends HttpServlet { // Invoke the get operation on the service implementation Message requestMessage = messageFactory.createMessage(); // String id = path.substring(1); - + Message responseMessage = null; HTTPCacheContext cacheContext = null; try { - cacheContext = HTTPCacheContext.createCacheContextFromRequest(request); + cacheContext = HTTPCacheContext.createCacheContextFromRequest(request); } catch (ParseException e) { } - + // Route message based on availability of cache info and cache methods if (( cacheContext != null ) && (cacheContext.isEnabled()) && (conditionalPostInvoker != null )) { - requestMessage.setBody(new Object[] {cacheContext}); - responseMessage = conditionalPostInvoker.invoke(requestMessage); + requestMessage.setBody(new Object[] {cacheContext}); + responseMessage = conditionalPostInvoker.invoke(requestMessage); } else { - requestMessage.setBody(new Object[] {}); - responseMessage = postInvoker.invoke(requestMessage); + requestMessage.setBody(new Object[] {}); + responseMessage = postInvoker.invoke(requestMessage); } if (responseMessage.isFault()) { - Object body = responseMessage.getBody(); - - int index = -1; - if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { - if ( index > -1 ) - response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); - else - response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); - return; - } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { - if ( index > -1 ) - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); - else - response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); - return; + Object body = responseMessage.getBody(); + + int index = -1; + if ( -1 < (index = body.getClass().getName().indexOf( "NotModifiedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_NOT_MODIFIED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_NOT_MODIFIED ); + return; + } else if ( -1 < (index = body.getClass().getName().indexOf( "PreconditionFailedException")) ) { + if ( index > -1 ) + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED, body.toString().substring( index )); + else + response.sendError( HttpServletResponse.SC_PRECONDITION_FAILED ); + return; } - + throw new ServletException((Throwable)responseMessage.getBody()); } // Test if the ETag and LastModified are returned as a cache context. - Object body = responseMessage.getBody(); - if ( body.getClass() == HTTPCacheContext.class ) { - // Transfer to header if so. - HTTPCacheContext cc = (HTTPCacheContext)responseMessage.getBody(); - if (( cc != null ) && ( cc.isEnabled() )) { - String eTag = cc.getETag(); - if ( eTag != null ) - response.setHeader( "ETag", cc.getETag() ); - String lastModified = cc.getLastModified(); - if ( lastModified != null) - response.setHeader( "LastModified", cc.getLastModified() ); - } - } + Object body = responseMessage.getBody(); + if ( body.getClass() == HTTPCacheContext.class ) { + // Transfer to header if so. + HTTPCacheContext cc = (HTTPCacheContext)responseMessage.getBody(); + if (( cc != null ) && ( cc.isEnabled() )) { + String eTag = cc.getETag(); + if ( eTag != null ) + response.setHeader( "ETag", cc.getETag() ); + String lastModified = cc.getLastModified(); + if ( lastModified != null) + response.setHeader( "LastModified", cc.getLastModified() ); + } + } } /** diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingServiceServlet.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingServiceServlet.java index 4d1f655577..13872f87bc 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingServiceServlet.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingServiceServlet.java @@ -32,8 +32,8 @@ import org.apache.tuscany.sca.invocation.MessageFactory; import org.apache.tuscany.sca.runtime.RuntimeEndpoint; public class HTTPBindingServiceServlet extends HttpServlet { - private static final long serialVersionUID = 1L; - + private static final long serialVersionUID = 6496710199406616194L; + protected transient MessageFactory messageFactory; protected transient RuntimeEndpoint wire; @@ -49,6 +49,12 @@ public class HTTPBindingServiceServlet extends HttpServlet { bindingContext.setHttpResponse(response); Message msg = messageFactory.createMessage(); msg.setBindingContext(bindingContext); - wire.invoke(msg); + Message responseMessage = wire.invoke(msg); + // return response to client + if (responseMessage.isFault()) { + // Turn a fault into an exception + Throwable e = (Throwable)responseMessage.getBody(); + response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); + } } } diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java index 3a3436d101..f06dad2a9b 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java @@ -22,8 +22,9 @@ package org.apache.tuscany.sca.binding.http.provider; import javax.servlet.Servlet; import org.apache.tuscany.sca.binding.http.HTTPBinding; -import org.apache.tuscany.sca.binding.http.HTTPDefaultOperationSelector; -import org.apache.tuscany.sca.binding.http.HTTPDefaultWireFormat; +import org.apache.tuscany.sca.binding.http.operationselector.HTTPDefaultOperationSelector; +import org.apache.tuscany.sca.binding.http.operationselector.HTTPRPCOperationSelector; +import org.apache.tuscany.sca.binding.http.wireformat.HTTPDefaultWireFormat; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.host.http.ServletHost; import org.apache.tuscany.sca.interfacedef.InterfaceContract; @@ -56,7 +57,6 @@ public class HTTPServiceBindingProvider implements EndpointProvider { private ServletHost servletHost; private String servletMapping; private InterfaceContract interfaceContract; - private boolean widget; private HTTPBindingListenerServlet bindingListenerServlet; @@ -67,19 +67,18 @@ public class HTTPServiceBindingProvider implements EndpointProvider { this.endpoint = endpoint; this.binding = (HTTPBinding)endpoint.getBinding(); - this.widget = "Widget".equals(binding.getName()); this.extensionPoints = extensionPoints; this.messageFactory = messageFactory; this.servletHost = servletHost; - if (binding.getOperationSelector() == null && !widget) { + if (binding.getOperationSelector() == null) { binding.setOperationSelector(new HTTPDefaultOperationSelector()); } - if (binding.getRequestWireFormat() == null && !widget) { + if (binding.getRequestWireFormat() == null) { binding.setRequestWireFormat(new HTTPDefaultWireFormat()); } - if (binding.getResponseWireFormat() == null && !widget) { + if (binding.getResponseWireFormat() == null) { binding.setResponseWireFormat(new HTTPDefaultWireFormat()); } @@ -123,63 +122,40 @@ public class HTTPServiceBindingProvider implements EndpointProvider { } public void start() { - if (widget) { - start1x(); - } else { - String deployedURI = servletHost.addServletMapping(servletMapping, new HTTPBindingServiceServlet(endpoint, messageFactory)); - endpoint.setDeployedURI(deployedURI); + + /** + * Consider three scenarios here : + * - Default servlet using service level operation + * - Default servlet using GET, PUT, POST, DELETE operations mapped to interface names with same name + * - RPC over HTTP like : http://localhost:8080/HelloworldComponent/Helloworld/sayHello?name=Petra + */ + if (binding.getOperationSelector() == null || binding.getRequestWireFormat() == null || binding.getResponseWireFormat() == null) { + throw new IllegalStateException("Binding operation selector and/or wire formats not properly setup."); } - } - - public void start1x() { - // Get the invokers for the supported operations + + InvocationChain bindingChain = endpoint.getBindingInvocationChain(); + Servlet servlet = null; - bindingListenerServlet = new HTTPBindingListenerServlet(binding, messageFactory ); + Invoker bindingInvoker = bindingChain.getHeadInvoker(); + bindingListenerServlet = new HTTPBindingListenerServlet(binding, messageFactory); for (InvocationChain invocationChain : endpoint.getInvocationChains()) { + Operation operation = invocationChain.getTargetOperation(); + Invoker serviceInvoker = invocationChain.getHeadInvoker(); String operationName = operation.getName(); - if (operationName.equals("get")) { - Invoker getInvoker = invocationChain.getHeadInvoker(); - bindingListenerServlet.setGetInvoker(getInvoker); - servlet = bindingListenerServlet; - } else if (operationName.equals("conditionalGet")) { - Invoker conditionalGetInvoker = invocationChain.getHeadInvoker(); - bindingListenerServlet.setConditionalGetInvoker(conditionalGetInvoker); - servlet = bindingListenerServlet; - } else if (operationName.equals("delete")) { - Invoker deleteInvoker = invocationChain.getHeadInvoker(); - bindingListenerServlet.setDeleteInvoker(deleteInvoker); - servlet = bindingListenerServlet; - } else if (operationName.equals("conditionalDelete")) { - Invoker conditionalDeleteInvoker = invocationChain.getHeadInvoker(); - bindingListenerServlet.setConditionalDeleteInvoker(conditionalDeleteInvoker); - servlet = bindingListenerServlet; - } else if (operationName.equals("put")) { - Invoker putInvoker = invocationChain.getHeadInvoker(); - bindingListenerServlet.setPutInvoker(putInvoker); - servlet = bindingListenerServlet; - } else if (operationName.equals("conditionalPut")) { - Invoker conditionalPutInvoker = invocationChain.getHeadInvoker(); - bindingListenerServlet.setConditionalPutInvoker(conditionalPutInvoker); - servlet = bindingListenerServlet; - } else if (operationName.equals("post")) { - Invoker postInvoker = invocationChain.getHeadInvoker(); - bindingListenerServlet.setPostInvoker(postInvoker); - servlet = bindingListenerServlet; - } else if (operationName.equals("conditionalPost")) { - Invoker conditionalPostInvoker = invocationChain.getHeadInvoker(); - bindingListenerServlet.setConditionalPostInvoker(conditionalPostInvoker); - servlet = bindingListenerServlet; - } else if (operationName.equals("service")) { - Invoker serviceInvoker = invocationChain.getHeadInvoker(); -// servlet = new HTTPServiceListenerServlet(binding, serviceInvoker, messageFactory); + + /* + if (operationName.equals("service")) { + servlet = new HTTPBindingListenerServlet(binding, messageFactory); break; - } - } - if (servlet == null) { - throw new IllegalStateException("No get or service method found on the service"); + } else { + */ + servlet = new HTTPBindingServiceServlet(endpoint, messageFactory); + /* + } + */ } - + // Create our HTTP service listener Servlet and register it with the // Servlet host servletMapping = binding.getURI(); @@ -210,9 +186,6 @@ public class HTTPServiceBindingProvider implements EndpointProvider { * Add specific http interceptor to invocation chain */ public void configure() { - - if (widget) return; - InvocationChain bindingChain = endpoint.getBindingInvocationChain(); if(osProvider != null) { diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatProviderFactory.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatProviderFactory.java index 45e74d8ec8..f3be0c27bf 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatProviderFactory.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatProviderFactory.java @@ -17,9 +17,9 @@ * under the License.
*/
-package org.apache.tuscany.sca.binding.http.format;
+package org.apache.tuscany.sca.binding.http.wireformat.provider;
-import org.apache.tuscany.sca.binding.http.HTTPDefaultWireFormat;
+import org.apache.tuscany.sca.binding.http.wireformat.HTTPDefaultWireFormat;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.interfacedef.InterfaceContract;
import org.apache.tuscany.sca.invocation.Interceptor;
@@ -36,7 +36,7 @@ public class HTTPDefaultWireFormatProviderFactory implements WireFormatProviderF @Override
public Class<HTTPDefaultWireFormat> getModelType() {
- return null;
+ return HTTPDefaultWireFormat.class;
}
@Override
@@ -49,10 +49,6 @@ public class HTTPDefaultWireFormatProviderFactory implements WireFormatProviderF return new WireFormatProvider() {
@Override
public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract) {
- // TODO: Ideally this wants to set the databinding on a per request basis from the
- // http content type and accept headers and so support things like json or xml etc,
- // for now to get started just use json
- interfaceContract.getInterface().resetDataBinding("JSON");
return interfaceContract;
}
@Override
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatServiceInterceptor.java new file mode 100644 index 0000000000..d1c2c61242 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPDefaultWireFormatServiceInterceptor.java @@ -0,0 +1,71 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.http.wireformat.provider;
+
+import org.apache.tuscany.sca.binding.http.HTTPBinding;
+import org.apache.tuscany.sca.common.http.HTTPContext;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Invoker;
+import org.apache.tuscany.sca.invocation.Message;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+
+/**
+ * Handles the default wire format for the http binding
+ *
+ * 1- determine the request and response format (xml, json, etc) from the
+ * binding config or content type header and accept headers
+ * - TODO: need a way to configure the databinding framework based on that format
+ * 2- get the request contents from the HttpServletRequest
+ * - for a post its just the request body
+ * - for a get need to convert the query string into a body based on the format (xml, json, etc)
+ * 3- send the request on down the wire
+ * 4- set the response contents in the HttpServletResponse
+ * (the databinding should already have put it in the correct format)
+ *
+ */
+public class HTTPDefaultWireFormatServiceInterceptor implements Interceptor {
+
+ private RuntimeEndpoint endpoint;
+ private HTTPBinding binding;
+ private Invoker next;
+
+ public HTTPDefaultWireFormatServiceInterceptor(RuntimeEndpoint endpoint) {
+ this.endpoint = endpoint;
+ this.binding = (HTTPBinding) endpoint.getBinding();
+ }
+
+ @Override
+ public void setNext(Invoker next) {
+ this.next = next;
+ }
+
+ @Override
+ public Invoker getNext() {
+ return next;
+ }
+
+ @Override
+ public Message invoke(Message msg) {
+ HTTPContext context = msg.getBindingContext();
+
+ msg.setBody(new Object[] {context.getHttpRequest(), context.getHttpResponse()});
+ return getNext().invoke(msg);
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatProviderFactory.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatProviderFactory.java new file mode 100644 index 0000000000..c9ef568402 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatProviderFactory.java @@ -0,0 +1,68 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tuscany.sca.binding.http.wireformat.provider;
+
+import org.apache.tuscany.sca.binding.http.wireformat.HTTPJSONWireFormat;
+import org.apache.tuscany.sca.core.ExtensionPointRegistry;
+import org.apache.tuscany.sca.interfacedef.InterfaceContract;
+import org.apache.tuscany.sca.invocation.Interceptor;
+import org.apache.tuscany.sca.invocation.Phase;
+import org.apache.tuscany.sca.provider.WireFormatProvider;
+import org.apache.tuscany.sca.provider.WireFormatProviderFactory;
+import org.apache.tuscany.sca.runtime.RuntimeEndpoint;
+import org.apache.tuscany.sca.runtime.RuntimeEndpointReference;
+
+public class HTTPJSONWireFormatProviderFactory implements WireFormatProviderFactory<HTTPJSONWireFormat> {
+
+ public HTTPJSONWireFormatProviderFactory(ExtensionPointRegistry extensionPoints) {
+ }
+
+ @Override
+ public Class<HTTPJSONWireFormat> getModelType() {
+ return HTTPJSONWireFormat.class;
+ }
+
+ @Override
+ public WireFormatProvider createReferenceWireFormatProvider(RuntimeEndpointReference endpointReference) {
+ return null;
+ }
+
+ @Override
+ public WireFormatProvider createServiceWireFormatProvider(final RuntimeEndpoint endpoint) {
+ return new WireFormatProvider() {
+ @Override
+ public InterfaceContract configureWireFormatInterfaceContract(InterfaceContract interfaceContract) {
+ // TODO: Ideally this wants to set the databinding on a per request basis from the
+ // http content type and accept headers and so support things like json or xml etc,
+ // for now to get started just use json
+ interfaceContract.getInterface().resetDataBinding("JSON");
+ return interfaceContract;
+ }
+ @Override
+ public Interceptor createInterceptor() {
+ return new HTTPJSONWireFormatServiceInterceptor(endpoint);
+ }
+ @Override
+ public String getPhase() {
+ return Phase.SERVICE_BINDING_WIREFORMAT;
+ }};
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatServiceInterceptor.java index e2ac99bfb8..3323fd34fe 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPDefaultWireFormatServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPJSONWireFormatServiceInterceptor.java @@ -17,7 +17,7 @@ * under the License.
*/
-package org.apache.tuscany.sca.binding.http.format;
+package org.apache.tuscany.sca.binding.http.wireformat.provider;
import java.io.BufferedReader;
import java.io.IOException;
@@ -58,12 +58,12 @@ import org.oasisopen.sca.ServiceRuntimeException; * (the databinding should already have put it in the correct format)
*
*/
-public class HTTPDefaultWireFormatServiceInterceptor implements Interceptor {
+public class HTTPJSONWireFormatServiceInterceptor implements Interceptor {
private Invoker next;
private String jsonpCallbackName = "callback";
- public HTTPDefaultWireFormatServiceInterceptor(RuntimeEndpoint endpoint) {
+ public HTTPJSONWireFormatServiceInterceptor(RuntimeEndpoint endpoint) {
}
@Override
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPXMLWireFormatProviderFactory.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatProviderFactory.java index cb60101bb7..3a670bd299 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPXMLWireFormatProviderFactory.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatProviderFactory.java @@ -17,9 +17,9 @@ * under the License.
*/
-package org.apache.tuscany.sca.binding.http.format;
+package org.apache.tuscany.sca.binding.http.wireformat.provider;
-import org.apache.tuscany.sca.binding.http.HTTPXMLWireFormat;
+import org.apache.tuscany.sca.binding.http.wireformat.HTTPXMLWireFormat;
import org.apache.tuscany.sca.common.xml.dom.DOMHelper;
import org.apache.tuscany.sca.core.ExtensionPointRegistry;
import org.apache.tuscany.sca.databinding.xml.DOMDataBinding;
@@ -41,7 +41,7 @@ public class HTTPXMLWireFormatProviderFactory implements WireFormatProviderFacto @Override
public Class<HTTPXMLWireFormat> getModelType() {
- return null;
+ return HTTPXMLWireFormat.class;
}
@Override
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPXMLWireFormatServiceInterceptor.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatServiceInterceptor.java index bfc22ec78f..93935a9f41 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/format/HTTPXMLWireFormatServiceInterceptor.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/provider/HTTPXMLWireFormatServiceInterceptor.java @@ -17,7 +17,7 @@ * under the License.
*/
-package org.apache.tuscany.sca.binding.http.format;
+package org.apache.tuscany.sca.binding.http.wireformat.provider;
import java.io.BufferedReader;
import java.io.IOException;
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory index 8d9b98604c..88560749de 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.OperationSelectorProviderFactory @@ -15,4 +15,5 @@ # specific language governing permissions and limitations
# under the License.
-org.apache.tuscany.sca.binding.http.format.HTTPDefaultOperationSelectorProviderFactory;model=org.apache.tuscany.sca.binding.http.HTTPDefaultOperationSelector
+org.apache.tuscany.sca.binding.http.operationselector.provider.HTTPDefaultOperationSelectorProviderFactory;model=org.apache.tuscany.sca.binding.http.operationselector.HTTPDefaultOperationSelector
+org.apache.tuscany.sca.binding.http.operationselector.provider.HTTPRPCOperationSelectorProviderFactory;model=org.apache.tuscany.sca.binding.http.operationselector.HTTPRPCOperationSelector
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory index 88cd59bb13..796407d122 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.WireFormatProviderFactory @@ -15,5 +15,6 @@ # specific language governing permissions and limitations
# under the License.
-org.apache.tuscany.sca.binding.http.format.HTTPDefaultWireFormatProviderFactory;model=org.apache.tuscany.sca.binding.http.HTTPDefaultWireFormat
-org.apache.tuscany.sca.binding.http.format.HTTPXMLWireFormatProviderFactory;model=org.apache.tuscany.sca.binding.http.HTTPXMLWireFormat
+org.apache.tuscany.sca.binding.http.wireformat.provider.HTTPDefaultWireFormatProviderFactory;model=org.apache.tuscany.sca.binding.http.wireformat.HTTPDefaultWireFormat
+org.apache.tuscany.sca.binding.http.wireformat.provider.HTTPJSONWireFormatProviderFactory;model=org.apache.tuscany.sca.binding.http.wireformat.HTTPJSONWireFormat
+org.apache.tuscany.sca.binding.http.wireformat.provider.HTTPXMLWireFormatProviderFactory;model=org.apache.tuscany.sca.binding.http.wireformat.HTTPXMLWireFormat
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ResourceServiceTestCase.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ResourceServiceTestCase.java new file mode 100644 index 0000000000..edbb111198 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ResourceServiceTestCase.java @@ -0,0 +1,79 @@ +/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.tuscany.sca.binding.http;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.net.URL;
+
+import junit.framework.Assert;
+
+import org.apache.tuscany.sca.node.Node;
+import org.apache.tuscany.sca.node.NodeFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+/**
+ * HTTP binding unit tests for Helloworld service.
+ */
+public class ResourceServiceTestCase {
+
+ private static Node node;
+
+ @BeforeClass
+ public static void setUp() throws Exception {
+ node = NodeFactory.newInstance().createNode("resource.composite", new String[] {"target/test-classes"});
+ node.start();
+ }
+
+ @AfterClass
+ public static void tearDown() throws Exception {
+ if (node != null) {
+ node.stop();
+ }
+ }
+
+ @Test
+ public void testGet() throws Exception {
+ URL url = new URL("http://localhost:8080/resource");
+ InputStream is = url.openStream();
+ Assert.assertTrue(read(is).startsWith("Resource"));
+ }
+
+ private static String read(InputStream is) throws IOException {
+ BufferedReader reader = null;
+ try {
+ reader = new BufferedReader(new InputStreamReader(is));
+ StringBuffer sb = new StringBuffer();
+ String str;
+ while ((str = reader.readLine()) != null) {
+ sb.append(str);
+ }
+ return sb.toString();
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ }
+ }
+
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/BeanA.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/BeanA.java index 2c33895f67..73bd908db8 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/BeanA.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/BeanA.java @@ -17,7 +17,7 @@ * under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
public class BeanA {
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuff.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuff.java index cf0d457317..5c3ef631d7 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuff.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuff.java @@ -17,7 +17,7 @@ * under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
import org.oasisopen.sca.annotation.Remotable;
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuffImpl.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuffImpl.java index 9395024e5b..f41ca498c1 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/ComplexStuffImpl.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ComplexStuffImpl.java @@ -17,7 +17,7 @@ * under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
public class ComplexStuffImpl implements ComplexStuff {
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/Helloworld.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/Helloworld.java index 17a0b28fdb..4ecda47d71 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/Helloworld.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/Helloworld.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
import org.oasisopen.sca.annotation.Remotable;
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HelloworldImpl.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/HelloworldImpl.java index e245f607f1..f0a24a6d9a 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HelloworldImpl.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/HelloworldImpl.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
public class HelloworldImpl implements Helloworld {
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ResourceService.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ResourceService.java new file mode 100644 index 0000000000..612a61247d --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/ResourceService.java @@ -0,0 +1,55 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package services; + +import java.io.IOException; + +import javax.servlet.Servlet; +import javax.servlet.ServletConfig; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; + +import org.oasisopen.sca.annotation.Service; + +@Service(Servlet.class) +public class ResourceService extends HttpServlet implements Servlet { + private static final long serialVersionUID = 8240260033930060726L; + + public void init(ServletConfig config) throws ServletException { + } + + public void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + response.addHeader("Content-Type","text/plain"); + response.getOutputStream().print("Resource request sucessfuly handled : " + request.getRequestURI() +'\n'); + } + + public void destroy() { + } + + public ServletConfig getServletConfig() { + return null; + } + + public String getServletInfo() { + return null; + } +} diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/SomeException.java b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/SomeException.java index f4ffd19c9c..f65c22dc05 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/SomeException.java +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/java/services/SomeException.java @@ -17,7 +17,7 @@ * under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package services;
public class SomeException extends Exception {
private static final long serialVersionUID = 1L;
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite index 7f4cc64fe2..9aa3e26c6c 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/complex.composite @@ -23,17 +23,21 @@ name="ComplexStuff">
<component name="ComplexComponent">
- <implementation.java class="org.apache.tuscany.sca.binding.http.ComplexStuffImpl"/>
+ <implementation.java class="services.ComplexStuffImpl"/>
<service name="ComplexStuff">
- <tuscany:binding.http />
+ <tuscany:binding.http>
+ <tuscany:wireFormat.json />
+ <tuscany:operationSelector.rpc />
+ </tuscany:binding.http>
</service>
</component>
<component name="ComplexXmlComponent">
- <implementation.java class="org.apache.tuscany.sca.binding.http.ComplexStuffImpl"/>
+ <implementation.java class="services.ComplexStuffImpl"/>
<service name="ComplexStuff">
<tuscany:binding.http>
- <tuscany:wireFormat.httpXml />
+ <tuscany:wireFormat.xml />
+ <tuscany:operationSelector.rpc />
</tuscany:binding.http>
</service>
</component>
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite index 7497cfcbac..8b8b2877cd 100644 --- a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/helloworld.composite @@ -23,17 +23,21 @@ name="helloworld">
<component name="HelloworldComponent">
- <implementation.java class="org.apache.tuscany.sca.binding.http.HelloworldImpl"/>
+ <implementation.java class="services.HelloworldImpl"/>
<service name="Helloworld">
- <tuscany:binding.http />
+ <tuscany:binding.http>
+ <tuscany:wireFormat.json />
+ <tuscany:operationSelector.rpc />
+ </tuscany:binding.http>
</service>
</component>
<component name="HelloworldXmlComponent">
- <implementation.java class="org.apache.tuscany.sca.binding.http.HelloworldImpl"/>
+ <implementation.java class="services.HelloworldImpl"/>
<service name="Helloworld">
<tuscany:binding.http>
- <tuscany:wireFormat.httpXml />
+ <tuscany:wireFormat.xml />
+ <tuscany:operationSelector.rpc />
</tuscany:binding.http>
</service>
</component>
diff --git a/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/resource.composite b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/resource.composite new file mode 100644 index 0000000000..27b229e483 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-http-runtime/src/test/resources/resource.composite @@ -0,0 +1,33 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. +--> +<composite xmlns="http://docs.oasis-open.org/ns/opencsa/sca/200912" + targetNamespace="http://sample/test" + xmlns:tuscany="http://tuscany.apache.org/xmlns/sca/1.1" + name="ResourceService"> + + + <component name="ResourceComponent"> + <implementation.java class="services.ResourceService" /> + <service name="Servlet"> + <tuscany:binding.http uri="/resource" /> + </service> + </component> + +</composite>
\ No newline at end of file diff --git a/sca-java-2.x/trunk/modules/binding-http/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/binding-http/META-INF/MANIFEST.MF index 861da02411..0ef3ea9d98 100644 --- a/sca-java-2.x/trunk/modules/binding-http/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/binding-http/META-INF/MANIFEST.MF @@ -1,6 +1,7 @@ Manifest-Version: 1.0
Export-Package: org.apache.tuscany.sca.binding.http;version="2.0.0";uses:="org.apache.tuscany.sca.assembly,javax.xml.namespace,javax.servlet.http",
- org.apache.tuscany.sca.binding.http.impl;version="2.0.0"
+ org.apache.tuscany.sca.binding.http.operationselector,
+ org.apache.tuscany.sca.binding.http.wireformat
Bundle-Name: Apache Tuscany SCA HTTP Binding Model
Bundle-Vendor: The Apache Software Foundation
Bundle-Version: 2.0.0
diff --git a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPDefaultOperationSelector.java b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/HTTPDefaultOperationSelector.java index a77774356f..2ce5e4a399 100644 --- a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPDefaultOperationSelector.java +++ b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/HTTPDefaultOperationSelector.java @@ -16,18 +16,24 @@ * specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package org.apache.tuscany.sca.binding.http.operationselector;
import javax.xml.namespace.QName;
import org.apache.tuscany.sca.assembly.OperationSelector;
import org.apache.tuscany.sca.assembly.xml.Constants;
+
+/**
+ * HTTP binding default operation selector.
+ *
+ * @version $Rev$ $Date$
+*/
public class HTTPDefaultOperationSelector implements OperationSelector {
- public static final QName OPERATION_SELECTOR_HTTP_DEFAULT_QNAME = new QName(Constants.SCA11_NS, "operationSelector.httpDefault");
+ public static final QName HTTP_OPERATION_SELECTOR_DEFAULT_QNAME = new QName(Constants.SCA11_NS, "operationSelector.default");
public QName getSchemaName() {
- return OPERATION_SELECTOR_HTTP_DEFAULT_QNAME;
+ return HTTP_OPERATION_SELECTOR_DEFAULT_QNAME;
}
public boolean isUnresolved() {
diff --git a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/HTTPRPCOperationSelector.java b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/HTTPRPCOperationSelector.java new file mode 100644 index 0000000000..e5df37f5eb --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/operationselector/HTTPRPCOperationSelector.java @@ -0,0 +1,44 @@ +/*
+ * 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;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.OperationSelector;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+
+/**
+ * HTTP binding RPC style operation selector.
+ *
+ * @version $Rev$ $Date$
+*/
+public class HTTPRPCOperationSelector implements OperationSelector {
+ public static final QName HTTP_OPERATION_SELECTOR_RPC_QNAME = new QName(Constants.SCA11_NS, "operationSelector.rpc");
+
+ public QName getSchemaName() {
+ return HTTP_OPERATION_SELECTOR_RPC_QNAME;
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPDefaultWireFormat.java b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/HTTPDefaultWireFormat.java index e3ff891a32..ba2816a4cc 100644 --- a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPDefaultWireFormat.java +++ b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/HTTPDefaultWireFormat.java @@ -16,7 +16,7 @@ * specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package org.apache.tuscany.sca.binding.http.wireformat;
import javax.xml.namespace.QName;
@@ -24,16 +24,15 @@ import org.apache.tuscany.sca.assembly.WireFormat; import org.apache.tuscany.sca.assembly.xml.Constants;
/**
- * Implementation for policies that could be injected as parameter
- * into the axis2config.
+ * Default wire format for http binding
*
- * @version $Rev: 813442 $ $Date: 2009-09-10 14:56:17 +0100 (Thu, 10 Sep 2009) $
+ * @version $Rev$ $Date$
*/
public class HTTPDefaultWireFormat implements WireFormat {
- public static final QName WIRE_FORMAT_HTTP_DEFAULT_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "wireFormat.httpDefault");
+ public static final QName HTTP_WIRE_FORMAT_DEFAULT_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "wireFormat.default");
public QName getSchemaName() {
- return WIRE_FORMAT_HTTP_DEFAULT_QNAME;
+ return HTTP_WIRE_FORMAT_DEFAULT_QNAME;
}
public boolean isUnresolved() {
diff --git a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/HTTPJSONWireFormat.java b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/HTTPJSONWireFormat.java new file mode 100644 index 0000000000..739446785d --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/HTTPJSONWireFormat.java @@ -0,0 +1,44 @@ +/*
+ * 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;
+
+import javax.xml.namespace.QName;
+
+import org.apache.tuscany.sca.assembly.WireFormat;
+import org.apache.tuscany.sca.assembly.xml.Constants;
+
+/**
+ * JSON wire format for http binding
+ *
+ * @version $Rev$ $Date$
+ */
+public class HTTPJSONWireFormat implements WireFormat {
+ public static final QName HTTP_WIRE_FORMAT_JSON_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "wireFormat.json");
+
+ public QName getSchemaName() {
+ return HTTP_WIRE_FORMAT_JSON_QNAME;
+ }
+
+ public boolean isUnresolved() {
+ return false;
+ }
+
+ public void setUnresolved(boolean unresolved) {
+ }
+}
diff --git a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPXMLWireFormat.java b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/HTTPXMLWireFormat.java index a616c15ee6..58c5c9f84f 100644 --- a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/HTTPXMLWireFormat.java +++ b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/wireformat/HTTPXMLWireFormat.java @@ -16,13 +16,19 @@ * specific language governing permissions and limitations
* under the License.
*/
-package org.apache.tuscany.sca.binding.http;
+package org.apache.tuscany.sca.binding.http.wireformat;
import javax.xml.namespace.QName;
import org.apache.tuscany.sca.assembly.WireFormat;
import org.apache.tuscany.sca.assembly.xml.Constants;
+
+/**
+ * XML Wire format for HTTP binding
+ *
+ * @version $Rev$ $Date$
+*/
public class HTTPXMLWireFormat implements WireFormat {
public static final QName WIRE_FORMAT_HTTP_XML_QNAME = new QName(Constants.SCA11_TUSCANY_NS, "wireFormat.httpXml");
diff --git a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessor.java b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessor.java index bdec50bde0..fc57ada6f2 100644 --- a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessor.java +++ b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessor.java @@ -27,6 +27,7 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import javax.xml.stream.XMLStreamWriter; +import org.apache.tuscany.sca.assembly.Base; import org.apache.tuscany.sca.assembly.OperationSelector; import org.apache.tuscany.sca.assembly.WireFormat; import org.apache.tuscany.sca.binding.http.HTTPBinding; @@ -42,22 +43,27 @@ import org.apache.tuscany.sca.contribution.resolver.ModelResolver; import org.apache.tuscany.sca.core.ExtensionPointRegistry; import org.apache.tuscany.sca.core.FactoryExtensionPoint; + +/** + * HTTP binding artifact processor that handles the read/write of HTTP specific XML elements. + * + * @version $Rev$ $Date$ +*/ public class HTTPBindingProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<HTTPBinding> { + private static final QName RESPONSE_QNAME = new QName(Base.SCA11_TUSCANY_NS, "response"); + private static final String NAME = "name"; private static final String URI = "uri"; private HTTPBindingFactory httpBindingFactory; private StAXArtifactProcessor<Object> extensionProcessor; - private StAXAttributeProcessor<Object> extensionAttributeProcessor; - - public HTTPBindingProcessor(ExtensionPointRegistry extensionPoints, - StAXArtifactProcessor extensionProcessor, - StAXAttributeProcessor extensionAttributeProcessor) { + public HTTPBindingProcessor(ExtensionPointRegistry extensionPoints, + StAXArtifactProcessor<Object> extensionProcessor, + StAXAttributeProcessor<Object> extensionAttributeProcessor) { FactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(FactoryExtensionPoint.class); this.httpBindingFactory = modelFactories.getFactory(HTTPBindingFactory.class); this.extensionProcessor = (StAXArtifactProcessor<Object>)extensionProcessor; - this.extensionAttributeProcessor = extensionAttributeProcessor; } public QName getArtifactType() { @@ -68,10 +74,21 @@ public class HTTPBindingProcessor extends BaseStAXArtifactProcessor implements S return HTTPBinding.class; } - public HTTPBinding read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException { + public HTTPBinding read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException,XMLStreamException { HTTPBinding httpBinding = httpBindingFactory.createHTTPBinding(); - while(reader.hasNext()) { + /** + * <tuscany:binding.http uri="http://localhost:8085/Customer"> + * <tuscany:wireFormat.json /> + * <tuscany:operationSelector.default /> + * <tuscany:response> + * <tuscany:wireFormat.xml /> + * </tuscany:response> + * </tuscany:binding.http> + * + */ + + while (reader.hasNext()) { QName elementName = null; int event = reader.getEventType(); switch (event) { @@ -80,7 +97,7 @@ public class HTTPBindingProcessor extends BaseStAXArtifactProcessor implements S if (HTTPBinding.TYPE.equals(elementName)) { String name = getString(reader, NAME); - if(name != null) { + if (name != null) { httpBinding.setName(name); } @@ -88,13 +105,38 @@ public class HTTPBindingProcessor extends BaseStAXArtifactProcessor implements S if (uri != null) { httpBinding.setURI(uri); } + } else if (RESPONSE_QNAME.equals(elementName)) { + + // skip response + reader.next(); + // and position to the next start_element event + while (reader.hasNext()) { + int sub_event = reader.getEventType(); + switch (sub_event) { + case START_ELEMENT: + elementName = reader.getName(); + break; + default: + reader.next(); + } + break; + } + + // dispatch to read wire format for the response + Object extension = extensionProcessor.read(reader, context); + if (extension != null) { + if (extension instanceof WireFormat) { + httpBinding.setResponseWireFormat((WireFormat)extension); + } + } + break; } else { // Read an extension element Object extension = extensionProcessor.read(reader, context); if (extension != null) { if (extension instanceof WireFormat) { httpBinding.setRequestWireFormat((WireFormat)extension); - } else if(extension instanceof OperationSelector) { + } else if (extension instanceof OperationSelector) { httpBinding.setOperationSelector((OperationSelector)extension); } } @@ -114,8 +156,9 @@ public class HTTPBindingProcessor extends BaseStAXArtifactProcessor implements S return httpBinding; } - public void write(HTTPBinding httpBinding, XMLStreamWriter writer, ProcessorContext context) throws ContributionWriteException, XMLStreamException { - //writer.writeStartElement(Constants.SCA10_NS, BINDING_HTTP); + public void write(HTTPBinding httpBinding, XMLStreamWriter writer, ProcessorContext context) + throws ContributionWriteException, XMLStreamException { + // writer.writeStartElement(Constants.SCA10_NS, BINDING_HTTP); writeStart(writer, HTTPBinding.TYPE.getNamespaceURI(), HTTPBinding.TYPE.getLocalPart()); @@ -129,13 +172,29 @@ public class HTTPBindingProcessor extends BaseStAXArtifactProcessor implements S writer.writeAttribute(URI, httpBinding.getURI()); } + // Write operation selectors + if (httpBinding.getOperationSelector() != null) { + extensionProcessor.write(httpBinding.getOperationSelector(), writer, context); + } + + // Write wire formats + if (httpBinding.getRequestWireFormat() != null) { + extensionProcessor.write(httpBinding.getRequestWireFormat(), writer, context); + } + + if (httpBinding.getResponseWireFormat() != null && httpBinding.getRequestWireFormat() != httpBinding + .getResponseWireFormat()) { + writeStart(writer, RESPONSE_QNAME.getNamespaceURI(), RESPONSE_QNAME.getLocalPart()); + extensionProcessor.write(httpBinding.getResponseWireFormat(), writer, context); + writeEnd(writer); + } + writeEnd(writer); - //writer.writeEndElement(); + // writer.writeEndElement(); } - public void resolve(HTTPBinding model, ModelResolver resolver, ProcessorContext context) throws ContributionResolveException { - // Should not need to do anything here for now... + // Should not need to do anything here for now... } diff --git a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPDefaultOperationSelectorProcessor.java b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPDefaultOperationSelectorProcessor.java deleted file mode 100644 index 1e15965cb9..0000000000 --- a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPDefaultOperationSelectorProcessor.java +++ /dev/null @@ -1,70 +0,0 @@ -/*
- * 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.xml;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.tuscany.sca.assembly.xml.Constants;
-import org.apache.tuscany.sca.binding.http.HTTPDefaultOperationSelector;
-import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
-import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
-import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
-import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-
-public class HTTPDefaultOperationSelectorProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<HTTPDefaultOperationSelector> {
-
- public HTTPDefaultOperationSelectorProcessor(FactoryExtensionPoint modelFactories) {
- }
-
- public QName getArtifactType() {
- return HTTPDefaultOperationSelector.OPERATION_SELECTOR_HTTP_DEFAULT_QNAME;
- }
-
- public HTTPDefaultOperationSelector read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
- HTTPDefaultOperationSelector wireFormat = new HTTPDefaultOperationSelector();
-
- return wireFormat;
- }
-
- public void write(HTTPDefaultOperationSelector wireFormat, XMLStreamWriter writer, ProcessorContext context)
- throws ContributionWriteException, XMLStreamException {
- writer.writeStartElement("tuscany",
- getArtifactType().getLocalPart(),
- getArtifactType().getNamespaceURI());
- writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS);
-
- writer.writeEndElement();
- }
-
- public Class<HTTPDefaultOperationSelector> getModelType() {
- return HTTPDefaultOperationSelector.class;
- }
-
- public void resolve(HTTPDefaultOperationSelector arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException {
-
- }
-
-}
diff --git a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPDefaultWireFormatProcessor.java b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPDefaultWireFormatProcessor.java deleted file mode 100644 index b5b1827d21..0000000000 --- a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPDefaultWireFormatProcessor.java +++ /dev/null @@ -1,71 +0,0 @@ -/*
- * 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.xml;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.tuscany.sca.assembly.xml.Constants;
-import org.apache.tuscany.sca.binding.http.HTTPDefaultWireFormat;
-import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
-import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
-import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
-import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-
-public class HTTPDefaultWireFormatProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<HTTPDefaultWireFormat> {
-
- public HTTPDefaultWireFormatProcessor(FactoryExtensionPoint modelFactories) {
- }
-
- public QName getArtifactType() {
- return HTTPDefaultWireFormat.WIRE_FORMAT_HTTP_DEFAULT_QNAME;
- }
-
-
- public HTTPDefaultWireFormat read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
- HTTPDefaultWireFormat wireFormat = new HTTPDefaultWireFormat();
-
- return wireFormat;
- }
-
- public void write(HTTPDefaultWireFormat wireFormat, XMLStreamWriter writer, ProcessorContext context)
- throws ContributionWriteException, XMLStreamException {
- writer.writeStartElement("tuscany",
- getArtifactType().getLocalPart(),
- getArtifactType().getNamespaceURI());
- writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS);
-
- writer.writeEndElement();
- }
-
- public Class<HTTPDefaultWireFormat> getModelType() {
- return HTTPDefaultWireFormat.class;
- }
-
- public void resolve(HTTPDefaultWireFormat arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException {
-
- }
-
-}
diff --git a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPXMLWireFormatProcessor.java b/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPXMLWireFormatProcessor.java deleted file mode 100644 index 86292cf724..0000000000 --- a/sca-java-2.x/trunk/modules/binding-http/src/main/java/org/apache/tuscany/sca/binding/http/xml/HTTPXMLWireFormatProcessor.java +++ /dev/null @@ -1,71 +0,0 @@ -/*
- * 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.xml;
-
-import javax.xml.namespace.QName;
-import javax.xml.stream.XMLStreamException;
-import javax.xml.stream.XMLStreamReader;
-import javax.xml.stream.XMLStreamWriter;
-
-import org.apache.tuscany.sca.assembly.xml.Constants;
-import org.apache.tuscany.sca.binding.http.HTTPXMLWireFormat;
-import org.apache.tuscany.sca.contribution.processor.BaseStAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.processor.ContributionReadException;
-import org.apache.tuscany.sca.contribution.processor.ContributionResolveException;
-import org.apache.tuscany.sca.contribution.processor.ContributionWriteException;
-import org.apache.tuscany.sca.contribution.processor.ProcessorContext;
-import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor;
-import org.apache.tuscany.sca.contribution.resolver.ModelResolver;
-import org.apache.tuscany.sca.core.FactoryExtensionPoint;
-
-public class HTTPXMLWireFormatProcessor extends BaseStAXArtifactProcessor implements StAXArtifactProcessor<HTTPXMLWireFormat> {
-
- public HTTPXMLWireFormatProcessor(FactoryExtensionPoint modelFactories) {
- }
-
- public QName getArtifactType() {
- return HTTPXMLWireFormat.WIRE_FORMAT_HTTP_XML_QNAME;
- }
-
-
- public HTTPXMLWireFormat read(XMLStreamReader reader, ProcessorContext context) throws ContributionReadException, XMLStreamException {
- HTTPXMLWireFormat wireFormat = new HTTPXMLWireFormat();
-
- return wireFormat;
- }
-
- public void write(HTTPXMLWireFormat wireFormat, XMLStreamWriter writer, ProcessorContext context)
- throws ContributionWriteException, XMLStreamException {
- writer.writeStartElement("tuscany",
- getArtifactType().getLocalPart(),
- getArtifactType().getNamespaceURI());
- writer.writeNamespace("tuscany", Constants.SCA11_TUSCANY_NS);
-
- writer.writeEndElement();
- }
-
- public Class<HTTPXMLWireFormat> getModelType() {
- return HTTPXMLWireFormat.class;
- }
-
- public void resolve(HTTPXMLWireFormat arg0, ModelResolver arg1, ProcessorContext context) throws ContributionResolveException {
-
- }
-
-}
diff --git a/sca-java-2.x/trunk/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor b/sca-java-2.x/trunk/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor index 9a26611bee..d35ee610f0 100644 --- a/sca-java-2.x/trunk/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor +++ b/sca-java-2.x/trunk/modules/binding-http/src/main/resources/META-INF/services/org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor @@ -17,6 +17,10 @@ # Implementation class for the artifact processor extension org.apache.tuscany.sca.binding.http.xml.HTTPBindingProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#binding.http,model=org.apache.tuscany.sca.binding.http.HTTPBinding,factory=org.apache.tuscany.sca.binding.http.HTTPBindingFactory
-org.apache.tuscany.sca.binding.http.xml.HTTPDefaultWireFormatProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.httpDefault,model=org.apache.tuscany.sca.binding.http.HTTPDefaultWireFormat -org.apache.tuscany.sca.binding.http.xml.HTTPXMLWireFormatProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.httpXml,model=org.apache.tuscany.sca.binding.http.HTTPXMLWireFormat -org.apache.tuscany.sca.binding.http.xml.HTTPDefaultOperationSelectorProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#operationSelector.httpDefault,model=org.apache.tuscany.sca.binding.http.HTTPDefaultOperationSelector + +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.default,model=org.apache.tuscany.sca.binding.http.wireformat.HTTPDefaultWireFormat +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.json,model=org.apache.tuscany.sca.binding.http.wireformat.HTTPJSONWireFormat +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#wireFormat.xml,model=org.apache.tuscany.sca.binding.http.wireformat.HTTPXMLWireFormat + +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#operationSelector.default,model=org.apache.tuscany.sca.binding.http.operationselector.HTTPDefaultOperationSelector +org.apache.tuscany.sca.assembly.xml.DefaultBeanModelProcessor;qname=http://tuscany.apache.org/xmlns/sca/1.1#operationSelector.rpc,model=org.apache.tuscany.sca.binding.http.operationselector.HTTPRPCOperationSelector diff --git a/sca-java-2.x/trunk/modules/binding-http/src/test/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessorTestCase.java b/sca-java-2.x/trunk/modules/binding-http/src/test/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessorTestCase.java new file mode 100644 index 0000000000..055bdb8588 --- /dev/null +++ b/sca-java-2.x/trunk/modules/binding-http/src/test/java/org/apache/tuscany/sca/binding/http/xml/HTTPBindingProcessorTestCase.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.xml; + +import java.io.StringReader; + +import javax.xml.stream.XMLInputFactory; +import javax.xml.stream.XMLStreamReader; + +import org.apache.tuscany.sca.assembly.Composite; +import org.apache.tuscany.sca.binding.http.HTTPBinding; +import org.apache.tuscany.sca.contribution.processor.DefaultStAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.contribution.processor.ExtensibleStAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.ProcessorContext; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessor; +import org.apache.tuscany.sca.contribution.processor.StAXArtifactProcessorExtensionPoint; +import org.apache.tuscany.sca.core.DefaultExtensionPointRegistry; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.Test; + + +/** + * @version $Rev$ $Date$ + */ +public class HTTPBindingProcessorTestCase { + + private static final String COMPOSITE = + "<?xml version=\"1.0\" encoding=\"ASCII\"?>" + + "<composite xmlns=\"http://docs.oasis-open.org/ns/opencsa/sca/200912\" xmlns:tuscany=\"http://tuscany.apache.org/xmlns/sca/1.1\" targetNamespace=\"http://binding-http\" name=\"binding-http\">" + + " <component name=\"CustomerService\">" + + " <implementation.java class=\"services.customer.CustomerServiceImpl\"/>" + + " <service name=\"CustomerService\">" + + " <tuscany:binding.http uri=\"http://localhost:8085/Customer\">" + + " <tuscany:wireFormat.json />" + + " <tuscany:operationSelector.default />" + + " <tuscany:response>" + + " <tuscany:wireFormat.xml />" + + " </tuscany:response>" + + " </tuscany:binding.http>" + + " </service>" + + " </component>" + + "</composite>"; + + private static XMLInputFactory inputFactory; + private static StAXArtifactProcessor<Object> staxProcessor; + private static ProcessorContext context; + + @BeforeClass + public static void setUp() throws Exception { + DefaultExtensionPointRegistry extensionPoints = new DefaultExtensionPointRegistry(); + context = new ProcessorContext(extensionPoints); + inputFactory = XMLInputFactory.newInstance(); + + StAXArtifactProcessorExtensionPoint staxProcessors = new DefaultStAXArtifactProcessorExtensionPoint(extensionPoints); + staxProcessor = new ExtensibleStAXArtifactProcessor(staxProcessors, inputFactory, null); + } + + /** + * Test parsing valid composite definition. Valid composite populated with correct values expected. + * @throws Exception + */ + @Test + public void testLoadValidComposite() throws Exception { + XMLStreamReader reader = inputFactory.createXMLStreamReader(new StringReader(COMPOSITE)); + + Composite composite = (Composite)staxProcessor.read(reader, context); + HTTPBinding binding = (HTTPBinding) composite.getComponents().get(0).getServices().get(0).getBindings().get(0); + + Assert.assertNotNull(binding); + Assert.assertNotNull(binding.getOperationSelector()); + Assert.assertNotNull(binding.getRequestWireFormat()); + Assert.assertNotNull(binding.getResponseWireFormat()); + + } +} diff --git a/sca-java-2.x/trunk/modules/binding-jsonp/META-INF/MANIFEST.MF b/sca-java-2.x/trunk/modules/binding-jsonp/META-INF/MANIFEST.MF index 4fdd920cb9..7d9503de88 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonp/META-INF/MANIFEST.MF +++ b/sca-java-2.x/trunk/modules/binding-jsonp/META-INF/MANIFEST.MF @@ -13,6 +13,8 @@ Import-Package: javax.xml.namespace, org.apache.tuscany.sca.assembly.xml;version="2.0.0",
org.apache.tuscany.sca.binding.http;version="2.0.0",
org.apache.tuscany.sca.binding.http.impl;version="2.0.0",
+ org.apache.tuscany.sca.binding.http.operationselector,
+ org.apache.tuscany.sca.binding.http.wireformat,
org.apache.tuscany.sca.binding.jsonp;version="2.0.0"
Bundle-SymbolicName: org.apache.tuscany.sca.binding.jsonp
Bundle-DocURL: http://www.apache.org/
diff --git a/sca-java-2.x/trunk/modules/binding-jsonp/src/main/java/org/apache/tuscany/sca/binding/jsonp/JSONPBinding.java b/sca-java-2.x/trunk/modules/binding-jsonp/src/main/java/org/apache/tuscany/sca/binding/jsonp/JSONPBinding.java index 7ef6fcf91d..195e2d71fc 100644 --- a/sca-java-2.x/trunk/modules/binding-jsonp/src/main/java/org/apache/tuscany/sca/binding/jsonp/JSONPBinding.java +++ b/sca-java-2.x/trunk/modules/binding-jsonp/src/main/java/org/apache/tuscany/sca/binding/jsonp/JSONPBinding.java @@ -21,9 +21,9 @@ package org.apache.tuscany.sca.binding.jsonp; import javax.xml.namespace.QName; -import org.apache.tuscany.sca.binding.http.HTTPDefaultOperationSelector; -import org.apache.tuscany.sca.binding.http.HTTPDefaultWireFormat; import org.apache.tuscany.sca.binding.http.impl.HTTPBindingImpl; +import org.apache.tuscany.sca.binding.http.operationselector.HTTPRPCOperationSelector; +import org.apache.tuscany.sca.binding.http.wireformat.HTTPJSONWireFormat; /** * JSONP Binding model @@ -36,9 +36,9 @@ public class JSONPBinding extends HTTPBindingImpl { super(); // configure the HTTP binding for JSONP (which for the moment is the default wireFormat) - setOperationSelector(new HTTPDefaultOperationSelector()); - setRequestWireFormat(new HTTPDefaultWireFormat()); - setResponseWireFormat(new HTTPDefaultWireFormat()); + setOperationSelector(new HTTPRPCOperationSelector()); + setRequestWireFormat(new HTTPJSONWireFormat()); + setResponseWireFormat(new HTTPJSONWireFormat()); } @Override |