Commit a3a2bfb5 authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Decoupled http-binding service from file system. No longer dependent on the...

Decoupled http-binding service from file system. No longer dependent on the web.xml in the spank directory. JM-1074

git-svn-id: http://svn.igniterealtime.org/svn/repos/openfire/branches@8388 b35dd754-fafc-0310-a699-88a17e54d16e
parent bdd5f54e
...@@ -14,8 +14,10 @@ package org.jivesoftware.openfire.http; ...@@ -14,8 +14,10 @@ package org.jivesoftware.openfire.http;
import org.mortbay.jetty.Server; import org.mortbay.jetty.Server;
import org.mortbay.jetty.Connector; import org.mortbay.jetty.Connector;
import org.mortbay.jetty.Handler; import org.mortbay.jetty.Handler;
import org.mortbay.jetty.servlet.ServletHandler;
import org.mortbay.jetty.handler.ContextHandlerCollection; import org.mortbay.jetty.handler.ContextHandlerCollection;
import org.mortbay.jetty.handler.DefaultHandler; import org.mortbay.jetty.handler.DefaultHandler;
import org.mortbay.jetty.handler.ContextHandler;
import org.mortbay.jetty.webapp.WebAppContext; import org.mortbay.jetty.webapp.WebAppContext;
import org.mortbay.jetty.security.SslSocketConnector; import org.mortbay.jetty.security.SslSocketConnector;
import org.mortbay.jetty.nio.SelectChannelConnector; import org.mortbay.jetty.nio.SelectChannelConnector;
...@@ -58,7 +60,7 @@ public final class HttpBindManager { ...@@ -58,7 +60,7 @@ public final class HttpBindManager {
private CertificateListener certificateListener; private CertificateListener certificateListener;
private HttpSessionManager httpSessionManager; private HttpSessionManager httpSessionManager;
private ContextHandlerCollection contexts; private ContextHandlerCollection contexts;
public static HttpBindManager getInstance() { public static HttpBindManager getInstance() {
...@@ -132,7 +134,8 @@ public final class HttpBindManager { ...@@ -132,7 +134,8 @@ public final class HttpBindManager {
if (securePort > 0 && CertificateManager.isRSACertificate(SSLConfig.getKeyStore(), "*")) { if (securePort > 0 && CertificateManager.isRSACertificate(SSLConfig.getKeyStore(), "*")) {
if (!CertificateManager.isRSACertificate(SSLConfig.getKeyStore(), if (!CertificateManager.isRSACertificate(SSLConfig.getKeyStore(),
XMPPServer.getInstance().getServerInfo().getName())) { XMPPServer.getInstance().getServerInfo().getName())) {
Log.warn("HTTP binding: Using RSA certificates but they are not valid for the hosted domain"); Log.warn("HTTP binding: Using RSA certificates but they are not valid for " +
"the hosted domain");
} }
SslSocketConnector sslConnector = new JiveSslConnector(); SslSocketConnector sslConnector = new JiveSslConnector();
...@@ -222,8 +225,7 @@ public final class HttpBindManager { ...@@ -222,8 +225,7 @@ public final class HttpBindManager {
} }
private synchronized void changeHttpBindPorts(int unsecurePort, int securePort) private synchronized void changeHttpBindPorts(int unsecurePort, int securePort)
throws Exception throws Exception {
{
if (unsecurePort < 0 && securePort < 0) { if (unsecurePort < 0 && securePort < 0) {
throw new IllegalArgumentException("At least one port must be greater than zero."); throw new IllegalArgumentException("At least one port must be greater than zero.");
} }
...@@ -264,15 +266,33 @@ public final class HttpBindManager { ...@@ -264,15 +266,33 @@ public final class HttpBindManager {
if (httpsConnector != null) { if (httpsConnector != null) {
httpBindServer.addConnector(httpsConnector); httpBindServer.addConnector(httpsConnector);
} }
createWebAppContext();
httpBindServer.setHandlers(new Handler[] { contexts, new DefaultHandler() }); createBoshHandler(contexts, "/http-bind");
loadStaticDirectory(contexts);
httpBindServer.setHandlers(new Handler[]{contexts, new DefaultHandler()});
} }
private WebAppContext createWebAppContext() { private void createBoshHandler(ContextHandlerCollection contexts, String boshPath) {
WebAppContext context = new WebAppContext(contexts, JiveGlobals.getHomeDirectory() + ServletHandler handler = new ServletHandler();
File.separator + "resources" + File.separator + "spank", "/"); handler.addServletWithMapping(HttpBindServlet.class, "/");
context.setWelcomeFiles(new String[]{"index.html"});
return context; ContextHandler boshContextHandler = new ContextHandler(contexts, boshPath);
boshContextHandler.setHandler(handler);
}
private void loadStaticDirectory(ContextHandlerCollection contexts) {
File spankDirectory = new File(JiveGlobals.getHomeDirectory() + File.separator
+ "resources" + File.separator + "spank");
if (spankDirectory.exists()) {
if (spankDirectory.canRead()) {
WebAppContext context = new WebAppContext(contexts, spankDirectory.getPath(), "/");
context.setWelcomeFiles(new String[]{"index.html"});
}
else {
Log.warn("Openfire cannot read the directory: " + spankDirectory);
}
}
} }
public ContextHandlerCollection getContexts() { public ContextHandlerCollection getContexts() {
...@@ -348,7 +368,7 @@ public final class HttpBindManager { ...@@ -348,7 +368,7 @@ public final class HttpBindManager {
} }
private synchronized void restartServer() { private synchronized void restartServer() {
if(httpBindServer != null) { if (httpBindServer != null) {
try { try {
httpBindServer.stop(); httpBindServer.stop();
} }
...@@ -428,7 +448,7 @@ public final class HttpBindManager { ...@@ -428,7 +448,7 @@ public final class HttpBindManager {
} }
public void certificateDeleted(KeyStore keyStore, String alias) { public void certificateDeleted(KeyStore keyStore, String alias) {
restartServer(); restartServer();
} }
public void certificateSigned(KeyStore keyStore, String alias, public void certificateSigned(KeyStore keyStore, String alias,
......
...@@ -4,36 +4,4 @@ ...@@ -4,36 +4,4 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<servlet>
<servlet-name>HttpBindServlet</servlet-name>
<servlet-class>org.jivesoftware.openfire.http.HttpBindServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>HttpBindServlet</servlet-name>
<url-pattern>/http-bind/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>JavaScriptServlet</servlet-name>
<servlet-class>org.jivesoftware.openfire.http.ResourceServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>JavaScriptServlet</servlet-name>
<url-pattern>/scripts/</url-pattern>
</servlet-mapping>
<servlet>
<servlet-name>FlashCrossDomain</servlet-name>
<servlet-class>org.jivesoftware.openfire.http.FlashCrossDomainServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>FlashCrossDomain</servlet-name>
<url-pattern>/crossdomain.xml</url-pattern>
</servlet-mapping>
</web-app> </web-app>
var Flash = {
installed: false,
callbacks: new Array(),
install: function(callbackName) {
dojo.event.connect(dojo.flash, "loaded", callbackName);
dojo.flash.setSwf({flash6: "/crossdomain_version6.swf",
flash8: "/crossdomain_version8.swf",
visible: false});
},
request: function() {
var self = this;
var _method, _url = null;
var _contentType = "application/x-www-form-urlencoded";
var _headers = new Array();
// responseXML
// status
this.open = function(method, url, async, user, password) {
_method = method;
_url = url;
}
this.send = function(body) {
function callback(response) {
self.responseText = response;
self.responseXML = XmlDocument.create();
self.responseXML.loadXML(response);
if (self.onload) {
self.onload(self);
}
}
dojo.flash.comm.XmlHttp(
_url, Flash.registerCallback(callback), _method, body, _contentType);
}
this.setRequestHeader = function(header, value) {
if (header.toLowerCase() == "Content-Type".toLowerCase()) {
_contentType = value;
return;
}
}
this.getRequestHeader = function() { alert("not supported"); }
this.getResponseHeader = function(a) { alert("not supported"); }
this.getAllResponseHeaders = function() { alert("not supported"); }
this.abort = function() { alert("not supported"); }
this.addEventListener = function(a, b, c) { alert("not supported"); }
this.dispatchEvent = function(e) { alert("not supported"); }
this.openRequest = function(a, b, c, d, e) { this.open(a, b, c, d, e); }
this.overrideMimeType = function(e) { alert("not supported"); }
this.removeEventListener = function(a, b, c) { alert("not supported"); }
},
registerCallback: function(callback) {
// todo: could be improved (look for the first available spot in the callbacks table,
// if necessary, expand it)
var length = this.callbacks.push(selfDeleteCallback);
var callbackID = length - 1;
return "Flash.callbacks[" + callbackID + "]";
function selfDeleteCallback(obj) {
delete Flash.callbacks[callbackID];
setTimeout(function() { callback(obj); }, 0);
return;
}
}
}
\ No newline at end of file
This diff is collapsed.
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment