From 3ac2d800d840f03618fc364090d786effde84b1f Mon Sep 17 00:00:00 2001 From: lresende Date: Wed, 11 Nov 2009 23:13:16 +0000 Subject: Moving 1.x branches git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@835142 13f79535-47bb-0310-9956-ffa450edef68 --- .../http/provider/HTTPBindingListenerServlet.java | 432 --------------------- .../http/provider/HTTPBindingProviderFactory.java | 64 --- .../http/provider/HTTPGetListenerServlet.java | 94 ----- .../http/provider/HTTPServiceBindingProvider.java | 137 ------- .../http/provider/HTTPServiceListenerServlet.java | 86 ---- ...che.tuscany.sca.provider.BindingProviderFactory | 19 - .../sca/binding/http/HTTPBindingTestCase.java | 147 ------- .../tuscany/sca/binding/http/TestGetImpl.java | 38 -- .../tuscany/sca/binding/http/TestServiceImpl.java | 61 --- .../src/test/resources/content/test.html | 21 - .../src/test/resources/test.composite | 47 --- 11 files changed, 1146 deletions(-) delete mode 100644 branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java delete mode 100644 branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java delete mode 100644 branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPGetListenerServlet.java delete mode 100644 branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java delete mode 100644 branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceListenerServlet.java delete mode 100644 branches/sca-java-20080910/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory delete mode 100644 branches/sca-java-20080910/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingTestCase.java delete mode 100644 branches/sca-java-20080910/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestGetImpl.java delete mode 100644 branches/sca-java-20080910/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceImpl.java delete mode 100644 branches/sca-java-20080910/modules/binding-http-runtime/src/test/resources/content/test.html delete mode 100644 branches/sca-java-20080910/modules/binding-http-runtime/src/test/resources/test.composite (limited to 'branches/sca-java-20080910/modules/binding-http-runtime/src') diff --git a/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java b/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java deleted file mode 100644 index 582742bd3f..0000000000 --- a/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingListenerServlet.java +++ /dev/null @@ -1,432 +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.provider; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URLDecoder; -import java.text.ParseException; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.tuscany.sca.binding.http.CacheContext; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.invocation.MessageFactory; - -/** - * Servlet responsible for dispatching HTTP requests to the - * target component implementation. - * - * @version $Rev$ $Date$ - */ -public class HTTPBindingListenerServlet extends HttpServlet { - private static final long serialVersionUID = 2865466417329430610L; - - private MessageFactory messageFactory; - private Invoker getInvoker; - private Invoker conditionalGetInvoker; - private Invoker putInvoker; - private Invoker conditionalPutInvoker; - private Invoker postInvoker; - private Invoker conditionalPostInvoker; - private Invoker deleteInvoker; - private Invoker conditionalDeleteInvoker; - - /** - * Constructs a new HTTPServiceListenerServlet. - */ - public HTTPBindingListenerServlet(MessageFactory messageFactory) { - this.messageFactory = messageFactory; - } - - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - // Get the request path - String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); - if (path.length() ==0) { - // Redirect to a URL ending with / to make relative hrefs work - // relative to the served resource. - response.sendRedirect(request.getRequestURL().append('/').toString()); - return; - } - - // Invoke the get operation on the service implementation - Message requestMessage = messageFactory.createMessage(); - String id = path.substring(1); - - Message responseMessage = null; - CacheContext cacheContext = null; - try { - cacheContext = CacheContext.getCacheContextFromRequest(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); - } else { - 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; - } - - throw new ServletException((Throwable)responseMessage.getBody()); - } - - // Write the response from the service implementation to the response - // output stream - InputStream is = (InputStream)responseMessage.getBody(); - OutputStream os = response.getOutputStream(); - byte[] buffer = new byte[2048]; - for (;;) { - int n = is.read(buffer); - if (n <= 0) - break; - os.write(buffer, 0, n); - } - os.flush(); - os.close(); - } - - @Override - protected void doDelete(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - // Get the request path - String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); - if (path.length() ==0) { - // Redirect to a URL ending with / to make relative hrefs work - // relative to the served resource. - response.sendRedirect(request.getRequestURL().append('/').toString()); - return; - } - - // Invoke the get operation on the service implementation - Message requestMessage = messageFactory.createMessage(); - String id = path.substring(1); - - Message responseMessage = null; - CacheContext cacheContext = null; - try { - cacheContext = CacheContext.getCacheContextFromRequest(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); - } else { - 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; - } - - throw new ServletException((Throwable)responseMessage.getBody()); - } - - // Write the response from the service implementation to the response - // output stream - InputStream is = (InputStream)responseMessage.getBody(); - OutputStream os = response.getOutputStream(); - byte[] buffer = new byte[2048]; - for (;;) { - int n = is.read(buffer); - if (n <= 0) - break; - os.write(buffer, 0, n); - } - os.flush(); - os.close(); - } - - @Override - protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - // Get the request path - String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); - if (path.length() ==0) { - // Redirect to a URL ending with / to make relative hrefs work - // relative to the served resource. - response.sendRedirect(request.getRequestURL().append('/').toString()); - return; - } - - // Invoke the get operation on the service implementation - Message requestMessage = messageFactory.createMessage(); - String id = path.substring(1); - - Message responseMessage = null; - CacheContext cacheContext = null; - try { - cacheContext = CacheContext.getCacheContextFromRequest(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); - } else { - 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; - } - - throw new ServletException((Throwable)responseMessage.getBody()); - } - - // Write the response from the service implementation to the response - // output stream - InputStream is = (InputStream)responseMessage.getBody(); - OutputStream os = response.getOutputStream(); - byte[] buffer = new byte[2048]; - for (;;) { - int n = is.read(buffer); - if (n <= 0) - break; - os.write(buffer, 0, n); - } - os.flush(); - os.close(); - } - - @Override - protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - // Get the request path - String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); - if (path.length() ==0) { - // Redirect to a URL ending with / to make relative hrefs work - // relative to the served resource. - response.sendRedirect(request.getRequestURL().append('/').toString()); - return; - } - - // Invoke the get operation on the service implementation - Message requestMessage = messageFactory.createMessage(); - // String id = path.substring(1); - - Message responseMessage = null; - CacheContext cacheContext = null; - try { - cacheContext = CacheContext.getCacheContextFromRequest(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); - } else { - 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; - } - - throw new ServletException((Throwable)responseMessage.getBody()); - } - - // Put ETag and LastModified in response. - CacheContext cc = (CacheContext)responseMessage.getBody(); - response.setHeader( "ETag", cc.getETag() ); - response.setHeader( "LastModified", cc.getLastModified() ); - } - - /** - * @return the getInvoker - */ - public Invoker getGetInvoker() { - return getInvoker; - } - - /** - * @param getInvoker the getInvoker to set - */ - public void setGetInvoker(Invoker getInvoker) { - this.getInvoker = getInvoker; - } - - /** - * @return the conditionalGetInvoker - */ - public Invoker getConditionalGetInvoker() { - return conditionalGetInvoker; - } - - /** - * @param conditionalGetInvoker the conditionalGetInvoker to set - */ - public void setConditionalGetInvoker(Invoker conditionalGetInvoker) { - this.conditionalGetInvoker = conditionalGetInvoker; - } - - /** - * @return the putInvoker - */ - public Invoker getPutInvoker() { - return putInvoker; - } - - /** - * @param putInvoker the putInvoker to set - */ - public void setPutInvoker(Invoker putInvoker) { - this.putInvoker = putInvoker; - } - - /** - * @return the conditionalPutInvoker - */ - public Invoker getConditionalPutInvoker() { - return conditionalPutInvoker; - } - - /** - * @param conditionalPutInvoker the conditionalPutInvoker to set - */ - public void setConditionalPutInvoker(Invoker conditionalPutInvoker) { - this.conditionalPutInvoker = conditionalPutInvoker; - } - - /** - * @return the postInvoker - */ - public Invoker getPostInvoker() { - return postInvoker; - } - - /** - * @param postInvoker the postInvoker to set - */ - public void setPostInvoker(Invoker postInvoker) { - this.postInvoker = postInvoker; - } - - /** - * @return the conditionalPostInvoker - */ - public Invoker getConditionalPostInvoker() { - return conditionalPostInvoker; - } - - /** - * @param conditionalPostInvoker the conditionalPostInvoker to set - */ - public void setConditionalPostInvoker(Invoker conditionalPostInvoker) { - this.conditionalPostInvoker = conditionalPostInvoker; - } - - /** - * @return the deleteInvoker - */ - public Invoker getDeleteInvoker() { - return deleteInvoker; - } - - /** - * @param deleteInvoker the deleteInvoker to set - */ - public void setDeleteInvoker(Invoker deleteInvoker) { - this.deleteInvoker = deleteInvoker; - } - - /** - * @return the conditionalDeleteInvoker - */ - public Invoker getConditionalDeleteInvoker() { - return conditionalDeleteInvoker; - } - - /** - * @param conditionalDeleteInvoker the conditionalDeleteInvoker to set - */ - public void setConditionalDeleteInvoker(Invoker conditionalDeleteInvoker) { - this.conditionalDeleteInvoker = conditionalDeleteInvoker; - } - -} diff --git a/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java b/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java deleted file mode 100644 index fccd10f3cd..0000000000 --- a/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPBindingProviderFactory.java +++ /dev/null @@ -1,64 +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.provider; - -import org.apache.tuscany.sca.binding.http.HTTPBinding; -import org.apache.tuscany.sca.contribution.ModelFactoryExtensionPoint; -import org.apache.tuscany.sca.core.ExtensionPointRegistry; -import org.apache.tuscany.sca.host.http.ServletHost; -import org.apache.tuscany.sca.host.http.ServletHostExtensionPoint; -import org.apache.tuscany.sca.invocation.MessageFactory; -import org.apache.tuscany.sca.provider.BindingProviderFactory; -import org.apache.tuscany.sca.provider.ReferenceBindingProvider; -import org.apache.tuscany.sca.provider.ServiceBindingProvider; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentReference; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; - - -/** - * Factory for HTTP binding providers. - * - * @version $Rev$ $Date$ - */ -public class HTTPBindingProviderFactory implements BindingProviderFactory { - - private MessageFactory messageFactory; - private ServletHost servletHost; - - public HTTPBindingProviderFactory(ExtensionPointRegistry extensionPoints) { - ServletHostExtensionPoint servletHosts = extensionPoints.getExtensionPoint(ServletHostExtensionPoint.class); - this.servletHost = servletHosts.getServletHosts().get(0); - ModelFactoryExtensionPoint modelFactories = extensionPoints.getExtensionPoint(ModelFactoryExtensionPoint.class); - messageFactory = modelFactories.getFactory(MessageFactory.class); - } - - public ReferenceBindingProvider createReferenceBindingProvider(RuntimeComponent component, RuntimeComponentReference reference, HTTPBinding binding) { - return null; - } - - public ServiceBindingProvider createServiceBindingProvider(RuntimeComponent component, RuntimeComponentService service, HTTPBinding binding) { - return new HTTPServiceBindingProvider(component, service, binding, messageFactory, servletHost); - } - - public Class getModelType() { - return HTTPBinding.class; - } -} diff --git a/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPGetListenerServlet.java b/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPGetListenerServlet.java deleted file mode 100644 index e20d420d49..0000000000 --- a/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPGetListenerServlet.java +++ /dev/null @@ -1,94 +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.provider; - -import java.io.IOException; -import java.io.InputStream; -import java.io.OutputStream; -import java.net.URLDecoder; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.invocation.MessageFactory; - -/** - * Servlet responsible for dispatching HTTP GET requests to the - * target component implementation. - * - * @version $Rev$ $Date$ - */ -public class HTTPGetListenerServlet extends HttpServlet { - private static final long serialVersionUID = 2865466417329430610L; - - private MessageFactory messageFactory; - private Invoker getInvoker; - - /** - * Constructs a new HTTPServiceListenerServlet. - */ - public HTTPGetListenerServlet(Invoker getInvoker, MessageFactory messageFactory) { - this.getInvoker = getInvoker; - this.messageFactory = messageFactory; - } - - @Override - protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { - - // Get the request path - String path = URLDecoder.decode(request.getRequestURI().substring(request.getServletPath().length()), "UTF-8"); - if (path.length() ==0) { - - // Redirect to a URL ending with / to make relative hrefs work - // relative to the served resource. - response.sendRedirect(request.getRequestURL().append('/').toString()); - return; - } - - // Invoke the get operation on the service implementation - Message requestMessage = messageFactory.createMessage(); - String id = path.substring(1); - requestMessage.setBody(new Object[] {id}); - Message responseMessage = getInvoker.invoke(requestMessage); - if (responseMessage.isFault()) { - throw new ServletException((Throwable)responseMessage.getBody()); - } - - // Write the response from the service implementation to the response - // output stream - InputStream is = (InputStream)responseMessage.getBody(); - OutputStream os = response.getOutputStream(); - byte[] buffer = new byte[2048]; - for (;;) { - int n = is.read(buffer); - if (n <= 0) - break; - os.write(buffer, 0, n); - } - os.flush(); - os.close(); - - } - -} diff --git a/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java b/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java deleted file mode 100644 index 0a8f74edca..0000000000 --- a/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceBindingProvider.java +++ /dev/null @@ -1,137 +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.provider; - -import javax.servlet.Servlet; - -import org.apache.tuscany.sca.binding.http.HTTPBinding; -import org.apache.tuscany.sca.host.http.ServletHost; -import org.apache.tuscany.sca.interfacedef.InterfaceContract; -import org.apache.tuscany.sca.interfacedef.Operation; -import org.apache.tuscany.sca.invocation.InvocationChain; -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.MessageFactory; -import org.apache.tuscany.sca.provider.ServiceBindingProvider; -import org.apache.tuscany.sca.runtime.RuntimeComponent; -import org.apache.tuscany.sca.runtime.RuntimeComponentService; -import org.apache.tuscany.sca.runtime.RuntimeWire; - -/** - * Implementation of an HTTP binding provider. - * - * @version $Rev$ $Date$ - */ -public class HTTPServiceBindingProvider implements ServiceBindingProvider { - - private RuntimeComponentService service; - private HTTPBinding binding; - private MessageFactory messageFactory; - private ServletHost servletHost; - private String servletMapping; - private HTTPBindingListenerServlet bindingListenerServlet; - - public HTTPServiceBindingProvider(RuntimeComponent component, - RuntimeComponentService service, - HTTPBinding binding, - MessageFactory messageFactory, - ServletHost servletHost) { - this.service = service; - this.binding = binding; - this.messageFactory = messageFactory; - this.servletHost = servletHost; - } - - public void start() { - // Get the invokers for the supported operations - RuntimeComponentService componentService = (RuntimeComponentService) service; - RuntimeWire wire = componentService.getRuntimeWire(binding); - Servlet servlet = null; - bindingListenerServlet = new HTTPBindingListenerServlet( messageFactory ); - for (InvocationChain invocationChain : wire.getInvocationChains()) { - Operation operation = invocationChain.getTargetOperation(); - 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(serviceInvoker, messageFactory); - break; - } - } - if (servlet == null) { - throw new IllegalStateException("No get or service method found on the service"); - } - - // Create our HTTP service listener Servlet and register it with the - // Servlet host - servletMapping = binding.getURI(); - if (!servletMapping.endsWith("/")) { - servletMapping += "/"; - } - if (!servletMapping.endsWith("*")) { - servletMapping += "*"; - } - servletHost.addServletMapping(servletMapping, servlet); - } - - public void stop() { - // Unregister the Servlet from the Servlet host - servletHost.removeServletMapping(servletMapping); - } - - public InterfaceContract getBindingInterfaceContract() { - return null; - } - - public boolean supportsOneWayInvocation() { - return false; - } - -} diff --git a/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceListenerServlet.java b/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceListenerServlet.java deleted file mode 100644 index 3dee67b1ba..0000000000 --- a/branches/sca-java-20080910/modules/binding-http-runtime/src/main/java/org/apache/tuscany/sca/binding/http/provider/HTTPServiceListenerServlet.java +++ /dev/null @@ -1,86 +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.provider; - -import java.io.IOException; - -import javax.servlet.Servlet; -import javax.servlet.ServletConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletResponse; - -import org.apache.tuscany.sca.invocation.Invoker; -import org.apache.tuscany.sca.invocation.Message; -import org.apache.tuscany.sca.invocation.MessageFactory; - -/** - * Servlet responsible for dispatching HTTP service requests to the - * target component implementation. - * - * @version $Rev$ $Date$ - */ -public class HTTPServiceListenerServlet implements Servlet { - - private ServletConfig config; - private MessageFactory messageFactory; - private Invoker serviceInvoker; - - /** - * Constructs a new HTTPServiceListenerServlet. - */ - public HTTPServiceListenerServlet(Invoker serviceInvoker, MessageFactory messageFactory) { - System.out.println( "DOB: HTTPServiceListenerServlet.service cons"); - this.serviceInvoker = serviceInvoker; - this.messageFactory = messageFactory; - } - - public ServletConfig getServletConfig() { - return config; - } - - public String getServletInfo() { - return ""; - } - - public void init(ServletConfig config) throws ServletException { - this.config = config; - } - - public void destroy() { - } - - public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { - System.out.println( "DOB: HTTPServiceListenerServlet.service entry"); - - // Dispatch the service interaction to the service invoker - Message requestMessage = messageFactory.createMessage(); - requestMessage.setBody(new Object[]{request, response}); - Message responseMessage = serviceInvoker.invoke(requestMessage); - if (responseMessage.isFault()) { - // Turn a fault into an exception - //throw new ServletException((Throwable)responseMessage.getBody()); - Throwable e = (Throwable)responseMessage.getBody(); - ((HttpServletResponse)response).sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.toString()); - } - } - -} diff --git a/branches/sca-java-20080910/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory b/branches/sca-java-20080910/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory deleted file mode 100644 index 0fa8d44c08..0000000000 --- a/branches/sca-java-20080910/modules/binding-http-runtime/src/main/resources/META-INF/services/org.apache.tuscany.sca.provider.BindingProviderFactory +++ /dev/null @@ -1,19 +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. - -# Implementation class for the binding extension -org.apache.tuscany.sca.binding.http.provider.HTTPBindingProviderFactory;model=org.apache.tuscany.sca.binding.http.HTTPBinding diff --git a/branches/sca-java-20080910/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingTestCase.java b/branches/sca-java-20080910/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingTestCase.java deleted file mode 100644 index e5cad080a6..0000000000 --- a/branches/sca-java-20080910/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/HTTPBindingTestCase.java +++ /dev/null @@ -1,147 +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; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStreamReader; -import java.io.OutputStream; -import java.net.Socket; -import java.text.MessageFormat; - -import junit.framework.TestCase; - -import org.apache.tuscany.sca.host.embedded.SCADomain; - -/** - * HTTP binding unit tests. - * - * @version $Rev$ $Date$ - */ -public class HTTPBindingTestCase extends TestCase { - - private static final String REQUEST1_HEADER = - "GET /httpservice/test HTTP/1.0\n" + "Host: localhost\n" - + "Content-Type: text/xml\n" - + "Connection: close\n" - + "Content-Length: "; - private static final String REQUEST1_CONTENT = ""; - private static final String REQUEST1 = - REQUEST1_HEADER + REQUEST1_CONTENT.getBytes().length + "\n\n" + REQUEST1_CONTENT; - - private static final String REQUEST2_HEADER = - "GET /webcontent/test.html HTTP/1.0\n" + "Host: localhost\n" - + "Content-Type: text/xml\n" - + "Connection: close\n" - + "Content-Length: "; - private static final String REQUEST2_CONTENT = ""; - private static final String REQUEST2 = - REQUEST2_HEADER + REQUEST2_CONTENT.getBytes().length + "\n\n" + REQUEST2_CONTENT; - - private static final String REQUEST3_HEADER = - "GET /httpget/{0} HTTP/1.0\n" + "Host: localhost\n" - + "Content-Type: text/xml\n" - + "Connection: close\n" - + "Content-Length: "; - private static final String REQUEST3_CONTENT = ""; - private static final String REQUEST3 = - REQUEST3_HEADER + REQUEST3_CONTENT.getBytes().length + "\n\n" + REQUEST3_CONTENT; - - private static final int HTTP_PORT = 8085; - - private SCADomain scaDomain; - - @Override - protected void setUp() throws Exception { - scaDomain = SCADomain.newInstance("test.composite"); - } - - @Override - protected void tearDown() throws Exception { - scaDomain.close(); - } - - /** - * Test invoking a POJO service implementation using the HTTP binding. - * @throws Exception - */ - public void testServiceImplementation() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - os.write(REQUEST1.getBytes()); - os.flush(); - - String document = read(client); - assertTrue(document.indexOf("

hey") != -1); - } - - /** - * Test invoking a POJO get method implementation using the HTTP binding. - * @throws Exception - */ - public void testGetImplementation() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - int index = 0; - String request = MessageFormat.format( REQUEST3, index ); - os.write( request.getBytes()); - os.flush(); - - String document = read(client); - assertTrue(document.indexOf("

item=" + index) != -1); - } - - /** - * Test getting a static resource provided using the HTTP binding. - * @throws Exception - */ - public void testStaticResourceImplementation() throws Exception { - Socket client = new Socket("127.0.0.1", HTTP_PORT); - OutputStream os = client.getOutputStream(); - os.write(REQUEST2.getBytes()); - os.flush(); - - String document = read(client); - assertTrue(document.indexOf("

hello") != -1); - } - - /** - * Read response stream from the given socket. - * @param socket - * @return - * @throws IOException - */ - private static String read(Socket socket) throws IOException { - BufferedReader reader = null; - try { - reader = new BufferedReader(new InputStreamReader(socket.getInputStream())); - 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/branches/sca-java-20080910/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestGetImpl.java b/branches/sca-java-20080910/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestGetImpl.java deleted file mode 100644 index 0df279dedd..0000000000 --- a/branches/sca-java-20080910/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestGetImpl.java +++ /dev/null @@ -1,38 +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; - -import java.io.ByteArrayInputStream; -import java.io.InputStream; - -/** - * Test service implementation that implements a get method. - * - * @version $Rev$ $Date$ - */ -public class TestGetImpl { - - public InputStream get(String id) { - System.out.println( "DOB: TestGetImpl id=" + id ); - return new ByteArrayInputStream(("

item=" + id + "").getBytes()); - - } - -} diff --git a/branches/sca-java-20080910/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceImpl.java b/branches/sca-java-20080910/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceImpl.java deleted file mode 100644 index 11945c8cd1..0000000000 --- a/branches/sca-java-20080910/modules/binding-http-runtime/src/test/java/org/apache/tuscany/sca/binding/http/TestServiceImpl.java +++ /dev/null @@ -1,61 +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; - -import java.io.IOException; - -import javax.servlet.Servlet; -import javax.servlet.ServletConfig; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; - -import org.osoa.sca.annotations.Service; - -/** - * Test service implementation. - * - * @version $Rev$ $Date$ - */ - -@Service(Servlet.class) -public class TestServiceImpl implements Servlet { - - public void init(ServletConfig config) throws ServletException { - } - - public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { - //HttpServletResponse httpResponse = (HttpServletResponse)response; - response.getOutputStream().print("

hey"); - } - - public void destroy() { - } - - public ServletConfig getServletConfig() { - return null; - } - - public String getServletInfo() { - return null; - } - -} diff --git a/branches/sca-java-20080910/modules/binding-http-runtime/src/test/resources/content/test.html b/branches/sca-java-20080910/modules/binding-http-runtime/src/test/resources/content/test.html deleted file mode 100644 index f4b79d7f01..0000000000 --- a/branches/sca-java-20080910/modules/binding-http-runtime/src/test/resources/content/test.html +++ /dev/null @@ -1,21 +0,0 @@ - - -

hello - \ No newline at end of file diff --git a/branches/sca-java-20080910/modules/binding-http-runtime/src/test/resources/test.composite b/branches/sca-java-20080910/modules/binding-http-runtime/src/test/resources/test.composite deleted file mode 100644 index 62c4af4e22..0000000000 --- a/branches/sca-java-20080910/modules/binding-http-runtime/src/test/resources/test.composite +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3