argeo.node.repo.type=h2
org.osgi.service.http.port=7070
#org.osgi.service.http.port.secure=7073
+#org.eclipse.equinox.http.jetty.websocket.enabled=true
# Logging
log4j.configuration=file:../../log4j.properties
/** Compatible with Jetty. */
public interface HttpConstants {
- public static final String HTTP_ENABLED = "http.enabled";
- public static final String HTTP_PORT = "http.port";
- public static final String HTTP_HOST = "http.host";
- public static final String HTTPS_ENABLED = "https.enabled";
- public static final String HTTPS_HOST = "https.host";
- public static final String HTTPS_PORT = "https.port";
- public static final String SSL_KEYSTORE = "ssl.keystore";
- public static final String SSL_PASSWORD = "ssl.password";
- public static final String SSL_KEYPASSWORD = "ssl.keypassword";
- public static final String SSL_NEEDCLIENTAUTH = "ssl.needclientauth";
- public static final String SSL_WANTCLIENTAUTH = "ssl.wantclientauth";
- public static final String SSL_PROTOCOL = "ssl.protocol";
- public static final String SSL_ALGORITHM = "ssl.algorithm";
- public static final String SSL_KEYSTORETYPE = "ssl.keystoretype";
- public static final String JETTY_PROPERTY_PREFIX = "org.eclipse.equinox.http.jetty.";
+ static final String HTTP_ENABLED = "http.enabled";
+ static final String HTTP_PORT = "http.port";
+ static final String HTTP_HOST = "http.host";
+ static final String HTTPS_ENABLED = "https.enabled";
+ static final String HTTPS_HOST = "https.host";
+ static final String HTTPS_PORT = "https.port";
+ static final String SSL_KEYSTORE = "ssl.keystore";
+ static final String SSL_PASSWORD = "ssl.password";
+ static final String SSL_KEYPASSWORD = "ssl.keypassword";
+ static final String SSL_NEEDCLIENTAUTH = "ssl.needclientauth";
+ static final String SSL_WANTCLIENTAUTH = "ssl.wantclientauth";
+ static final String SSL_PROTOCOL = "ssl.protocol";
+ static final String SSL_ALGORITHM = "ssl.algorithm";
+ static final String SSL_KEYSTORETYPE = "ssl.keystoretype";
+ static final String JETTY_PROPERTY_PREFIX = "org.eclipse.equinox.http.jetty.";
+ // Argeo specific
+ static final String WEB_SOCKET_ENABLED = "websocket.enabled";
}
Dictionary<String, Object> webServerConfig = InitUtils
.getHttpServerConfig(getProps(KernelConstants.JETTY_FACTORY_PID, NodeConstants.DEFAULT));
if (!webServerConfig.isEmpty()) {
- webServerConfig.put("customizer.class", "org.argeo.equinox.jetty.WebSocketJettyCustomizer");
+ // TODO chekc for other customizers
+ webServerConfig.put("customizer.class", "org.argeo.equinox.jetty.CmsJettyCustomizer");
putFactoryDeployConfig(KernelConstants.JETTY_FACTORY_PID, webServerConfig);
}
save();
/// TODO make it more generic
String httpHost = getFrameworkProp(HttpConstants.JETTY_PROPERTY_PREFIX + HttpConstants.HTTP_HOST);
String httpsHost = getFrameworkProp(HttpConstants.JETTY_PROPERTY_PREFIX + HttpConstants.HTTPS_HOST);
+ String webSocketEnabled = getFrameworkProp(
+ HttpConstants.JETTY_PROPERTY_PREFIX + HttpConstants.WEB_SOCKET_ENABLED);
final Hashtable<String, Object> props = new Hashtable<String, Object>();
// try {
if (httpsHost != null)
props.put(HttpConstants.HTTPS_HOST, httpHost);
+ if (webSocketEnabled != null)
+ if (webSocketEnabled.equals("true"))
+ props.put(HttpConstants.WEB_SOCKET_ENABLED, true);
+
props.put(NodeConstants.CN, NodeConstants.DEFAULT);
}
return props;
--- /dev/null
+package org.argeo.equinox.jetty;
+
+import java.util.Dictionary;
+
+import javax.servlet.ServletException;
+
+import org.eclipse.equinox.http.jetty.JettyCustomizer;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
+import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
+import org.osgi.framework.BundleContext;
+import org.osgi.framework.FrameworkUtil;
+
+/** Customises the Jetty HTTP server. */
+public class CmsJettyCustomizer extends JettyCustomizer {
+ private BundleContext bc = FrameworkUtil.getBundle(CmsJettyCustomizer.class).getBundleContext();
+
+ @Override
+ public Object customizeContext(Object context, Dictionary<String, ?> settings) {
+ // WebSocket
+ Object webSocketEnabled = settings.get("websocket.enabled");
+ if (webSocketEnabled != null && webSocketEnabled.toString().equals("true")) {
+ ServletContextHandler servletContextHandler = (ServletContextHandler) context;
+ new WebSocketInit(servletContextHandler).start();
+ }
+ return super.customizeContext(context, settings);
+
+ }
+
+ /** Configure websocket container asynchronously as it may take some time */
+ private class WebSocketInit extends Thread {
+ ServletContextHandler servletContextHandler;
+
+ public WebSocketInit(ServletContextHandler servletContextHandler) {
+ super("WebSocket Init");
+ this.servletContextHandler = servletContextHandler;
+ }
+
+ @Override
+ public void run() {
+ ServerContainer serverContainer;
+ try {
+ serverContainer = WebSocketServerContainerInitializer.configureContext(servletContextHandler);
+ } catch (ServletException e) {
+ throw new IllegalStateException("Cannot configure web sockets", e);
+ }
+ bc.registerService(javax.websocket.server.ServerContainer.class, serverContainer, null);
+ }
+
+ }
+}
+++ /dev/null
-package org.argeo.equinox.jetty;
-
-import java.util.Dictionary;
-
-import javax.servlet.ServletException;
-
-import org.eclipse.equinox.http.jetty.JettyCustomizer;
-import org.eclipse.jetty.servlet.ServletContextHandler;
-import org.eclipse.jetty.websocket.jsr356.server.ServerContainer;
-import org.eclipse.jetty.websocket.jsr356.server.deploy.WebSocketServerContainerInitializer;
-import org.osgi.framework.BundleContext;
-import org.osgi.framework.FrameworkUtil;
-
-public class WebSocketJettyCustomizer extends JettyCustomizer {
- private BundleContext bc = FrameworkUtil.getBundle(WebSocketJettyCustomizer.class).getBundleContext();
-
- @Override
- public Object customizeContext(Object context, Dictionary<String, ?> settings) {
- ServletContextHandler servletContextHandler = (ServletContextHandler) context;
- new WebSocketInit(servletContextHandler).start();
- return super.customizeContext(context, settings);
- }
-
- /** Configure websocket container asynchronously as it may take some time */
- private class WebSocketInit extends Thread {
- ServletContextHandler servletContextHandler;
-
- public WebSocketInit(ServletContextHandler servletContextHandler) {
- super("WebSocket Init");
- this.servletContextHandler = servletContextHandler;
- }
-
- @Override
- public void run() {
- ServerContainer serverContainer;
- try {
- serverContainer = WebSocketServerContainerInitializer.configureContext(servletContextHandler);
-// serverContainer.addSessionListener(new WebSocketSessionListener() {
-//
-// @Override
-// public void onSessionOpened(WebSocketSession session) {
-// UpgradeRequest upgradeRequest = session.getUpgradeRequest();
-// UpgradeResponse upgradeResponse = session.getUpgradeResponse();
-// List<String> acceptHeader = upgradeResponse.getHeaders("Sec-WebSocket-Accept");
-// if (acceptHeader.contains("no"))
-// try {
-// upgradeResponse.sendForbidden("FORBIDDEN");
-// return;
-// } catch (IOException e) {
-// // TODO Auto-generated catch block
-// e.printStackTrace();
-// }
-// List<HttpCookie> cookies = upgradeRequest.getCookies();
-//
-// System.out.println("Upgrade request cookies : " + cookies);
-// String httpSessionId = null;
-// if (cookies != null) {
-// for (HttpCookie cookie : cookies) {
-// if (cookie.getName().equals("JSESSIONID")) {
-// httpSessionId = cookie.getValue();
-// }
-// }
-// }
-//
-// if (httpSessionId == null) {
-// HttpSession httpSession = (HttpSession) upgradeRequest.getSession();
-// if (httpSession == null) {
-//// session.disconnect();
-//// return;
-// } else {
-// httpSessionId = httpSession.getId();
-// System.out.println("Upgrade request session ID : " + httpSession.getId());
-// }
-// }
-//
-// if (httpSessionId != null) {
-// int dotIdx = httpSessionId.lastIndexOf('.');
-// if (dotIdx > 0) {
-// httpSessionId = httpSessionId.substring(0, dotIdx);
-// }
-// }
-// }
-//
-// @Override
-// public void onSessionClosed(WebSocketSession session) {
-// }
-// });
- } catch (ServletException e) {
- throw new IllegalStateException("Cannot configure web sockets", e);
- }
- bc.registerService(javax.websocket.server.ServerContainer.class, serverContainer, null);
- }
-
- }
-}