diff options
author | fmoga <fmoga@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-27 09:42:41 +0000 |
---|---|---|
committer | fmoga <fmoga@13f79535-47bb-0310-9956-ffa450edef68> | 2010-08-27 09:42:41 +0000 |
commit | aab1938b933443e8ea6a778a3540c5300b139b60 (patch) | |
tree | de3b106cca017cf1643246ae388bc15c67e5ba82 /sca-java-2.x/contrib/modules | |
parent | 0dfe5b9d3fe50c80f135e01226dc999ccd1a21d1 (diff) |
Changed Jetty port to 8085 to avoid conflict on testing.
Fixed servlet mapping removal and refactored ServletFactory code.
Added temporary fix for javaee 6 related unit test error by adding servlet-api:3.0-alpha-1 instead of javaee-web-api:6.0.
git-svn-id: http://svn.us.apache.org/repos/asf/tuscany@990078 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'sca-java-2.x/contrib/modules')
4 files changed, 42 insertions, 26 deletions
diff --git a/sca-java-2.x/contrib/modules/binding-comet-runtime/pom.xml b/sca-java-2.x/contrib/modules/binding-comet-runtime/pom.xml index b08887072a..1939a4240b 100644 --- a/sca-java-2.x/contrib/modules/binding-comet-runtime/pom.xml +++ b/sca-java-2.x/contrib/modules/binding-comet-runtime/pom.xml @@ -82,10 +82,10 @@ <version>1.4</version> </dependency> <dependency> - <groupId>javax</groupId> - <artifactId>javaee-web-api</artifactId> - <version>6.0</version> - <scope>provided</scope> + <groupId>javax.servlet</groupId> + <artifactId>servlet-api</artifactId> + <version>3.0-alpha-1</version> + <scope>provided</scope> </dependency> </dependencies> @@ -106,6 +106,10 @@ <url>http://download.java.net/maven/2/</url> <layout>default</layout> </repository> + <repository> + <id>glassfish-repository</id> + <url>http://download.java.net/maven/glassfish</url> + </repository> </repositories> </project> diff --git a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java index 9c65acaa54..31c0b5b4d8 100644 --- a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java +++ b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java @@ -59,12 +59,13 @@ public class CometServiceBindingProvider implements ServiceBindingProvider { */ @Override public void start() { + ServletFactory.registerServlet(this.servletHost); final ComponentService service = this.endpoint.getService(); final Interface serviceInterface = service.getInterfaceContract().getInterface(); JavascriptGenerator.generateServiceProxy(service); for (final Operation operation : serviceInterface.getOperations()) { JavascriptGenerator.generateMethodProxy(service, operation); - ServletFactory.registerServlet(this.servletHost, this.endpoint, operation); + ServletFactory.addOperation(this.endpoint, operation); } } @@ -73,12 +74,7 @@ public class CometServiceBindingProvider implements ServiceBindingProvider { */ @Override public void stop() { - final ComponentService service = this.endpoint.getService(); - final Interface serviceInterface = service.getInterfaceContract().getInterface(); - for (final Operation op : serviceInterface.getOperations()) { - final String path = service.getName() + "/" + op.getName(); - this.servletHost.removeServletMapping(path); - } + ServletFactory.unregisterServlet(this.servletHost); } @Override diff --git a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java index 588702f880..c1244b3183 100644 --- a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java +++ b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java @@ -97,17 +97,12 @@ public final class ServletFactory { } /** - * Method called by CometServiceBindingProvider for each endpoint operation - * in order to create the two servlets and keep track of all the endpoints - * and their operations. + * Method called by CometServiceBindingProvider for each endpoint in order + * to create the two singleton servlets. * * @param servletHost the underlying servlet host - * @param endpoint the endpoint - * @param operation the operation */ - public static synchronized void registerServlet(final ServletHost servletHost, - final RuntimeEndpoint endpoint, - final Operation operation) { + public static synchronized void registerServlet(final ServletHost servletHost) { if (ServletFactory.cometServlet == null) { ServletFactory.cometServlet = new AtmosphereServlet(); ServletFactory.cometServlet.addInitParameter(ServletFactory.PACKAGE_KEY, ServletFactory.PACKAGE_VALUE); @@ -119,7 +114,22 @@ public final class ServletFactory { final Map<String, Operation> operations = new HashMap<String, Operation>(); ServletFactory.cometServlet.getServletContext().setAttribute(ServletFactory.OPERATIONS_KEY, operations); } - // add current operation to ServletContext + if (ServletFactory.javascriptServlet == null) { + ServletFactory.javascriptServlet = new AtmosphereServlet(); + ServletFactory.javascriptServlet.addInitParameter(ServletFactory.PACKAGE_KEY, + ServletFactory.JS_PACKAGE_VALUE); + servletHost.addServletMapping(ServletFactory.JS_PATH, ServletFactory.javascriptServlet); + } + } + + /** + * Method called by CometServiceBindingProvider for each endpoint operation + * in order to store all the operations the servlet will serve. + * + * @param endpoint the endpoint + * @param operation the operation + */ + public static synchronized void addOperation(final RuntimeEndpoint endpoint, final Operation operation) { final String url = "/" + endpoint.getService().getName() + "/" + operation.getName(); final Map<String, RuntimeEndpoint> endpoints = (Map<String, RuntimeEndpoint>)ServletFactory.cometServlet.getServletContext() @@ -129,13 +139,17 @@ public final class ServletFactory { (Map<String, Operation>)ServletFactory.cometServlet.getServletContext() .getAttribute(ServletFactory.OPERATIONS_KEY); operations.put(url, operation); + } - if (ServletFactory.javascriptServlet == null) { - ServletFactory.javascriptServlet = new AtmosphereServlet(); - ServletFactory.javascriptServlet.addInitParameter(ServletFactory.PACKAGE_KEY, - ServletFactory.JS_PACKAGE_VALUE); - servletHost.addServletMapping(ServletFactory.JS_PATH, ServletFactory.javascriptServlet); - } + /** + * Method called by CometServiceBindingProvider for each endpoint operation + * in order to remove the two servlets. + * + * @param servletHost the underlying servlet host + */ + public static synchronized void unregisterServlet(final ServletHost servletHost) { + servletHost.removeServletMapping(ServletFactory.PATH); + servletHost.removeServletMapping(ServletFactory.JS_PATH); } } diff --git a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/CometTestCase.java b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/CometTestCase.java index e485fd2ca6..56c6b9f4f1 100644 --- a/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/CometTestCase.java +++ b/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/CometTestCase.java @@ -22,6 +22,7 @@ package org.apache.tuscany.sca.test; import junit.framework.Assert; import junit.framework.TestCase; +import org.apache.tuscany.sca.http.jetty.JettyServer; import org.apache.tuscany.sca.node.Contribution; import org.apache.tuscany.sca.node.ContributionLocationHelper; import org.apache.tuscany.sca.node.Node; @@ -37,6 +38,7 @@ public class CometTestCase extends TestCase { * comet binding. */ public void testComet() { + JettyServer.portDefault = 8085; try { final String location = ContributionLocationHelper.getContributionLocation("test.composite"); final Node node = NodeFactory.newInstance().createNode("test.composite", new Contribution("c1", location)); |