You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tuscany.apache.org by fm...@apache.org on 2010/08/27 11:42:42 UTC
svn commit: r990078 - in
/tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime: ./
src/main/java/org/apache/tuscany/sca/binding/comet/runtime/
src/test/java/org/apache/tuscany/sca/test/
Author: fmoga
Date: Fri Aug 27 09:42:41 2010
New Revision: 990078
URL: http://svn.apache.org/viewvc?rev=990078&view=rev
Log:
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.
Modified:
tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/pom.xml
tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java
tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java
tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/CometTestCase.java
Modified: tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/pom.xml
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/pom.xml?rev=990078&r1=990077&r2=990078&view=diff
==============================================================================
--- tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/pom.xml (original)
+++ tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/pom.xml Fri Aug 27 09:42:41 2010
@@ -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>
Modified: tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java?rev=990078&r1=990077&r2=990078&view=diff
==============================================================================
--- tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java (original)
+++ tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/CometServiceBindingProvider.java Fri Aug 27 09:42:41 2010
@@ -59,12 +59,13 @@ public class CometServiceBindingProvider
*/
@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
*/
@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
Modified: tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java?rev=990078&r1=990077&r2=990078&view=diff
==============================================================================
--- tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java (original)
+++ tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java Fri Aug 27 09:42:41 2010
@@ -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);
}
}
Modified: tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/CometTestCase.java
URL: http://svn.apache.org/viewvc/tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/CometTestCase.java?rev=990078&r1=990077&r2=990078&view=diff
==============================================================================
--- tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/CometTestCase.java (original)
+++ tuscany/sca-java-2.x/contrib/modules/binding-comet-runtime/src/test/java/org/apache/tuscany/sca/test/CometTestCase.java Fri Aug 27 09:42:41 2010
@@ -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 TestC
* 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));