Commit 85cf4166 authored by Alex Wenckus's avatar Alex Wenckus Committed by alex

Fixed initial stream establishment response

git-svn-id: http://svn.igniterealtime.org/svn/repos/wildfire/branches@5831 b35dd754-fafc-0310-a699-88a17e54d16e
parent 3d120237
...@@ -238,6 +238,7 @@ public class HttpServerManager { ...@@ -238,6 +238,7 @@ public class HttpServerManager {
} }
httpBindServer = null; httpBindServer = null;
} }
//noinspection ConstantConditions
if(adminServer != null && adminServer != httpBindServer) { if(adminServer != null && adminServer != httpBindServer) {
try { try {
adminServer.stop(); adminServer.stop();
......
...@@ -147,7 +147,6 @@ public class HttpBindServlet extends HttpServlet { ...@@ -147,7 +147,6 @@ public class HttpBindServlet extends HttpServlet {
return; return;
} }
try { try {
HttpConnection connection = new HttpConnection(rid, request.isSecure()); HttpConnection connection = new HttpConnection(rid, request.isSecure());
connection.setSession(sessionManager.createSession(rootNode, connection)); connection.setSession(sessionManager.createSession(rootNode, connection));
...@@ -158,6 +157,9 @@ public class HttpBindServlet extends HttpServlet { ...@@ -158,6 +157,9 @@ public class HttpBindServlet extends HttpServlet {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
"Server Not initialized"); "Server Not initialized");
} }
catch (HttpBindException e) {
response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
} }
......
...@@ -18,6 +18,10 @@ import org.jivesoftware.wildfire.net.VirtualConnection; ...@@ -18,6 +18,10 @@ import org.jivesoftware.wildfire.net.VirtualConnection;
import org.jivesoftware.wildfire.auth.UnauthorizedException; import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.xmpp.packet.Packet; import org.xmpp.packet.Packet;
import org.xmpp.packet.Message; import org.xmpp.packet.Message;
import org.dom4j.Element;
import org.dom4j.DocumentHelper;
import org.dom4j.QName;
import org.dom4j.Namespace;
import java.util.*; import java.util.*;
import java.net.InetAddress; import java.net.InetAddress;
...@@ -102,6 +106,46 @@ public class HttpSession extends ClientSession { ...@@ -102,6 +106,46 @@ public class HttpSession extends ClientSession {
lastPoll = time; lastPoll = time;
} }
public Collection<Element> getAvailableStreamFeaturesElements() {
List<Element> elements = new ArrayList<Element>();
// Include Stream Compression Mechanism
if (conn.getCompressionPolicy() != Connection.CompressionPolicy.disabled &&
!conn.isCompressed()) {
Element compression = DocumentHelper.createElement(new QName("compression",
new Namespace("", "http://jabber.org/features/compress")));
Element method = compression.addElement("method");
method.setText("zlib");
elements.add(compression);
}
if (getAuthToken() == null) {
// Advertise that the server supports Non-SASL Authentication
Element auth = DocumentHelper.createElement(new QName("auth",
new Namespace("", "http://jabber.org/features/iq-auth")));
elements.add(auth);
// Advertise that the server supports In-Band Registration
if (XMPPServer.getInstance().getIQRegisterHandler().isInbandRegEnabled()) {
Element register = DocumentHelper.createElement(new QName("register",
new Namespace("", "http://jabber.org/features/iq-register")));
elements.add(register);
}
}
else {
// If the session has been authenticated then offer resource binding
// and session establishment
Element bind = DocumentHelper.createElement(new QName("bind",
new Namespace("", "urn:ietf:params:xml:ns:xmpp-bind")));
elements.add(bind);
Element session = DocumentHelper.createElement(new QName("session",
new Namespace("", "urn:ietf:params:xml:ns:xmpp-session")));
elements.add(session);
}
return elements;
}
public String getAvailableStreamFeatures() { public String getAvailableStreamFeatures() {
StringBuilder sb = new StringBuilder(200); StringBuilder sb = new StringBuilder(200);
......
...@@ -11,12 +11,13 @@ ...@@ -11,12 +11,13 @@
package org.jivesoftware.wildfire.http; package org.jivesoftware.wildfire.http;
import org.jivesoftware.util.JiveGlobals; import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.wildfire.SessionManager; import org.jivesoftware.wildfire.SessionManager;
import org.jivesoftware.wildfire.StreamID; import org.jivesoftware.wildfire.StreamID;
import org.jivesoftware.wildfire.multiplex.MultiplexerPacketRouter; import org.jivesoftware.wildfire.multiplex.MultiplexerPacketRouter;
import org.jivesoftware.wildfire.multiplex.UnknownStanzaException; import org.jivesoftware.wildfire.multiplex.UnknownStanzaException;
import org.jivesoftware.wildfire.auth.UnauthorizedException; import org.jivesoftware.wildfire.auth.UnauthorizedException;
import org.dom4j.Element; import org.dom4j.*;
import java.util.*; import java.util.*;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
...@@ -75,7 +76,7 @@ public class HttpSessionManager { ...@@ -75,7 +76,7 @@ public class HttpSessionManager {
} }
public HttpSession createSession(Element rootNode, HttpConnection connection) public HttpSession createSession(Element rootNode, HttpConnection connection)
throws UnauthorizedException throws UnauthorizedException, HttpBindException
{ {
// TODO Check if IP address is allowed to connect to the server // TODO Check if IP address is allowed to connect to the server
...@@ -102,6 +103,10 @@ public class HttpSessionManager { ...@@ -102,6 +103,10 @@ public class HttpSessionManager {
catch (HttpConnectionClosedException e) { catch (HttpConnectionClosedException e) {
/* This won't happen here. */ /* This won't happen here. */
} }
catch (DocumentException e) {
Log.error("Error creating document", e);
throw new HttpBindException("Internal server error", true, 500);
}
timer.reset(session); timer.reset(session);
return session; return session;
...@@ -145,25 +150,24 @@ public class HttpSessionManager { ...@@ -145,25 +150,24 @@ public class HttpSessionManager {
} }
} }
private String createSessionCreationResponse(HttpSession session) { private String createSessionCreationResponse(HttpSession session) throws DocumentException {
StringBuilder builder = new StringBuilder(); Element response = DocumentHelper.createElement("body");
builder.append("<body") response.addNamespace("", "http://jabber.org/protocol/httpbind");
.append(" xmlns='http://jabber.org/protocol/httpbind'").append(" authID='") response.addNamespace("stream", "http://etherx.jabber.org/streams");
.append(session.getStreamID()).append("'") response.addAttribute("authid", session.getStreamID().getID());
.append(" sid='").append(session.getStreamID()).append("'") response.addAttribute("sid", session.getStreamID().getID());
.append(" secure='true" + "'").append(" requests='") response.addAttribute("secure", Boolean.TRUE.toString());
.append(String.valueOf(maxRequests)).append("'") response.addAttribute("requests", String.valueOf(maxRequests));
.append(" inactivity='").append(String.valueOf(session.getInactivityTimeout())) response.addAttribute("inactivity", String.valueOf(session.getInactivityTimeout()));
.append("'") response.addAttribute("polling", String.valueOf(pollingInterval));
.append(" polling='").append(String.valueOf(pollingInterval)).append("'") response.addAttribute("wait", String.valueOf(session.getWait()));
.append(" wait='").append(String.valueOf(session.getWait())).append("'")
.append(">"); Element features = response.addElement("stream:features");
builder.append("<stream:features>"); for(Element feature : session.getAvailableStreamFeaturesElements()) {
builder.append(session.getAvailableStreamFeatures()); features.add(feature);
builder.append("</stream:features>"); }
builder.append("</body>");
return response.asXML();
return builder.toString();
} }
public HttpConnection forwardRequest(long rid, HttpSession session, boolean isSecure, public HttpConnection forwardRequest(long rid, HttpSession session, boolean isSecure,
......
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