summaryrefslogtreecommitdiffstats
path: root/sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java
diff options
context:
space:
mode:
Diffstat (limited to 'sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java')
-rw-r--r--sca-java-2.x/contrib/modules/binding-comet-runtime/src/main/java/org/apache/tuscany/sca/binding/comet/runtime/ServletFactory.java213
1 files changed, 107 insertions, 106 deletions
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 1002446b65..588702f880 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
@@ -29,112 +29,113 @@ import org.atmosphere.cpr.AtmosphereServlet;
/**
* This class is used to create two servlets: one exposing all the comet
- * services, the other one exposing the javascript toolkit.
- *
- * Exposing all comet services through a single servlet is needed as the
- * browsers are undergone by the two http connection limit so all comet services
- * should send their responses via the same http connection to the same client.
- *
- * Dispatching to the corresponding endpoint and operation is done internally
- * using Jersey RESTful Web Services integration with the AtmosphereServlet.
- *
- * The Javascript toolkit servlet is unique as it is not tied to any of the
- * services - it offers a global API.
+ * services, the other one exposing the javascript toolkit. Exposing all comet
+ * services through a single servlet is needed as the browsers are undergone by
+ * the two http connection limit so all comet services should send their
+ * responses via the same http connection to the same client. Dispatching to the
+ * corresponding endpoint and operation is done internally using Jersey RESTful
+ * Web Services integration with the AtmosphereServlet. The Javascript toolkit
+ * servlet is unique as it is not tied to any of the services - it offers a
+ * global API.
*/
-public class ServletFactory {
-
- /**
- * Init-param key for the AtmosphereServlet defining where to look for
- * Jersey classes.
- */
- private static final String PACKAGE_KEY = "com.sun.jersey.config.property.packages";
-
- /**
- * Package of the class handling dispatching to endpoints.
- */
- private static final String PACKAGE_VALUE = "org.apache.tuscany.sca.binding.comet.runtime.handler";
-
- /**
- * Package of the class handling Javascript toolkit retrieval.
- */
- private static final String JS_PACKAGE_VALUE = "org.apache.tuscany.sca.binding.comet.runtime.javascript";
-
- /**
- * Property in the ServletContext where endpoints are added incrementally as
- * the Tuscany runtime calls the CometServiceBindingProvider for each comet
- * service.
- */
- public static final String ENDPOINTS_KEY = "org.apache.tuscany.sca.binding.comet.endpoints";
-
- /**
- * Property in the ServletContext where operations are added incrementally
- * as the CometServiceBindingProvider is calling the registerServlet method
- * for each comet service method.
- */
- public static final String OPERATIONS_KEY = "org.apache.tuscany.sca.binding.comet.operations";
-
- /**
- * Path where services will be exposed.
- */
- public static final String PATH = "/tuscany-comet/*";
-
- /**
- * Path where Javascript toolkit will be exposed.
- */
- public static final String JS_PATH = "/org.apache.tuscany.sca.cometComponentContext.js/*";
-
- /**
- * The servlet that is exposing the comet services.
- */
- private static AtmosphereServlet cometServlet = null;
-
- /**
- * The servlet that is exposing the Javascript toolkit.
- */
- private static AtmosphereServlet javascriptServlet = null;
-
- /**
- * 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.
- *
- * @param servletHost
- * the underlying servlet host
- * @param endpoint
- * the endpoint
- * @param operation
- * the operation
- */
- public static synchronized void registerServlet(ServletHost servletHost,
- RuntimeEndpoint endpoint, Operation operation) {
- if (cometServlet == null) {
- cometServlet = new AtmosphereServlet();
- cometServlet.addInitParameter(PACKAGE_KEY, PACKAGE_VALUE);
- servletHost.addServletMapping(PATH, cometServlet);
- // store operations and corresponding endpoint in the ServletContext
- // so that they can be retrieved from inside the web service methods
- Map<String, RuntimeEndpoint> endpoints = new HashMap<String, RuntimeEndpoint>();
- cometServlet.getServletContext().setAttribute(ENDPOINTS_KEY,
- endpoints);
- Map<String, Operation> operations = new HashMap<String, Operation>();
- cometServlet.getServletContext().setAttribute(OPERATIONS_KEY,
- operations);
- }
- // add current operation to ServletContext
- String url = "/" + endpoint.getService().getName() + "/"
- + operation.getName();
- Map<String, RuntimeEndpoint> endpoints = (Map<String, RuntimeEndpoint>) cometServlet
- .getServletContext().getAttribute(ENDPOINTS_KEY);
- endpoints.put(url, endpoint);
- Map<String, Operation> operations = (Map<String, Operation>) cometServlet
- .getServletContext().getAttribute(OPERATIONS_KEY);
- operations.put(url, operation);
-
- if (javascriptServlet == null) {
- javascriptServlet = new AtmosphereServlet();
- javascriptServlet.addInitParameter(PACKAGE_KEY, JS_PACKAGE_VALUE);
- servletHost.addServletMapping(JS_PATH, javascriptServlet);
- }
- }
+public final class ServletFactory {
+
+ /**
+ * Init-param key for the AtmosphereServlet defining where to look for
+ * Jersey classes.
+ */
+ private static final String PACKAGE_KEY = "com.sun.jersey.config.property.packages";
+
+ /**
+ * Package of the class handling dispatching to endpoints.
+ */
+ private static final String PACKAGE_VALUE = "org.apache.tuscany.sca.binding.comet.runtime.handler";
+
+ /**
+ * Package of the class handling Javascript toolkit retrieval.
+ */
+ private static final String JS_PACKAGE_VALUE = "org.apache.tuscany.sca.binding.comet.runtime.javascript";
+
+ /**
+ * Property in the ServletContext where endpoints are added incrementally as
+ * the Tuscany runtime calls the CometServiceBindingProvider for each comet
+ * service.
+ */
+ public static final String ENDPOINTS_KEY = "org.apache.tuscany.sca.binding.comet.endpoints";
+
+ /**
+ * Property in the ServletContext where operations are added incrementally
+ * as the CometServiceBindingProvider is calling the registerServlet method
+ * for each comet service method.
+ */
+ public static final String OPERATIONS_KEY = "org.apache.tuscany.sca.binding.comet.operations";
+
+ /**
+ * Path where services will be exposed.
+ */
+ public static final String PATH = "/tuscany-comet/*";
+
+ /**
+ * Path where Javascript toolkit will be exposed.
+ */
+ public static final String JS_PATH = "/org.apache.tuscany.sca.cometComponentContext.js/*";
+
+ /**
+ * The servlet that is exposing the comet services.
+ */
+ private static AtmosphereServlet cometServlet = null;
+
+ /**
+ * The servlet that is exposing the Javascript toolkit.
+ */
+ private static AtmosphereServlet javascriptServlet = null;
+
+ /**
+ * Private constructor for the singleton class.
+ */
+ private 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.
+ *
+ * @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) {
+ if (ServletFactory.cometServlet == null) {
+ ServletFactory.cometServlet = new AtmosphereServlet();
+ ServletFactory.cometServlet.addInitParameter(ServletFactory.PACKAGE_KEY, ServletFactory.PACKAGE_VALUE);
+ servletHost.addServletMapping(ServletFactory.PATH, ServletFactory.cometServlet);
+ // store operations and corresponding endpoint in the ServletContext
+ // so that they can be retrieved from inside the web service methods
+ final Map<String, RuntimeEndpoint> endpoints = new HashMap<String, RuntimeEndpoint>();
+ ServletFactory.cometServlet.getServletContext().setAttribute(ServletFactory.ENDPOINTS_KEY, endpoints);
+ final Map<String, Operation> operations = new HashMap<String, Operation>();
+ ServletFactory.cometServlet.getServletContext().setAttribute(ServletFactory.OPERATIONS_KEY, operations);
+ }
+ // add current operation to ServletContext
+ final String url = "/" + endpoint.getService().getName() + "/" + operation.getName();
+ final Map<String, RuntimeEndpoint> endpoints =
+ (Map<String, RuntimeEndpoint>)ServletFactory.cometServlet.getServletContext()
+ .getAttribute(ServletFactory.ENDPOINTS_KEY);
+ endpoints.put(url, endpoint);
+ final Map<String, Operation> operations =
+ (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);
+ }
+ }
}