diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpBindServlet.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpBindServlet.java index e6f4625..d720e3a 100644 --- a/src/java/org/jivesoftware/multiplexer/net/http/HttpBindServlet.java +++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpBindServlet.java @@ -8,6 +8,15 @@ */ package org.jivesoftware.multiplexer.net.http; +import org.xmlpull.v1.XmlPullParserFactory; +import org.xmlpull.v1.XmlPullParserException; +import org.jivesoftware.multiplexer.net.MXParser; +import org.jivesoftware.util.Log; +import org.dom4j.io.XMPPPacketReader; +import org.dom4j.Document; +import org.dom4j.DocumentException; +import org.dom4j.Element; + import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -20,15 +29,70 @@ public class HttpBindServlet extends HttpServlet { private HttpSessionManager sessionManager; + private static XmlPullParserFactory factory; + + static { + try { + factory = XmlPullParserFactory.newInstance(MXParser.class.getName(), null); + } + catch (XmlPullParserException e) { + Log.error("Error creating a parser factory", e); + } + } + public HttpBindServlet(HttpSessionManager sessionManager) { this.sessionManager = sessionManager; } @Override - protected void service(HttpServletRequest httpServletRequest, - HttpServletResponse httpServletResponse) - throws ServletException, IOException + protected void doPost(HttpServletRequest request, HttpServletResponse response) + throws ServletException, IOException { + Document document; + try { + document = createDocument(request); + } + catch (Exception e) { + Log.warn("Error parsing user request. [" + request.getRemoteAddr() + "]"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, + "Unable to parse request content: " + e.getMessage()); + return; + } + + Element node = document.getRootElement(); + if(node == null || !"body".equals(node.getName())) { + Log.warn("Body missing from request content. [" + request.getRemoteAddr() + "]"); + response.sendError(HttpServletResponse.SC_BAD_REQUEST, + "Body missing from request content."); + return; + } + + String sid = node.attributeValue("sid"); + // We have a new session + if(sid == null) { + createNewSession(request, response, node); + } + else { + + } + } + + private void createNewSession(HttpServletRequest request, HttpServletResponse response, + Element rootNode) { - super.service(httpServletRequest, httpServletResponse); + } + + private Document createDocument(HttpServletRequest request) throws + DocumentException, IOException, XmlPullParserException + { + Document document = (Document) request.getAttribute("xml-document"); + if (document == null) { + // Reader is associated with a new XMPPPacketReader + XMPPPacketReader reader = new XMPPPacketReader(); + reader.setXPPFactory(factory); + + document = reader.read(request.getInputStream()); + request.setAttribute("xml-document", document); + } + return document; } } diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpConnection.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpConnection.java new file mode 100644 index 0000000..4ce2827 --- /dev/null +++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpConnection.java @@ -0,0 +1,79 @@ +/** + * $RCSfile: $ + * $Revision: $ + * $Date: $ + * + * Copyright (C) 2006 Jive Software. All rights reserved. + * This software is the proprietary information of Jive Software. Use is subject to license terms. + */ +package org.jivesoftware.multiplexer.net.http; + +import org.jivesoftware.multiplexer.Connection; +import org.dom4j.Element; + +import java.net.InetAddress; +import java.net.UnknownHostException; + +/** + * + */ +public class HttpConnection implements Connection { + private int majorVersion = 1; + private int minorVersion = 0; + + public boolean validate() { + return false; + } + + public InetAddress getInetAddress() throws UnknownHostException { + return null; + } + + public void close() { + } + + public void systemShutdown() { + } + + public boolean isClosed() { + return false; + } + + public boolean isSecure() { + return false; + } + + public void deliver(Element doc) { + } + + public void deliverRawText(String text) { + } + + public boolean isFlashClient() { + return false; + } + + public int getMajorXMPPVersion() { + return majorVersion; + } + + public int getMinorXMPPVersion() { + return minorVersion; + } + + public String getLanguage() { + return null; + } + + public boolean isCompressed() { + return false; + } + + public CompressionPolicy getCompressionPolicy() { + return null; + } + + public TLSPolicy getTlsPolicy() { + return null; + } +} diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpSession.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpSession.java new file mode 100644 index 0000000..da625ff --- /dev/null +++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpSession.java @@ -0,0 +1,33 @@ +/** + * $RCSfile: $ + * $Revision: $ + * $Date: $ + * + * Copyright (C) 2006 Jive Software. All rights reserved. + * This software is the proprietary information of Jive Software. Use is subject to license terms. + */ +package org.jivesoftware.multiplexer.net.http; + +import org.jivesoftware.multiplexer.Session; +import org.jivesoftware.multiplexer.Connection; + +/** + * + */ +public class HttpSession extends Session { + /** + * Creates a session with an underlying connection and permission protection. + * + * @param connection The connection we are proxying + */ + public HttpSession(String serverName, Connection connection, String streamID) { + super(serverName, connection, streamID); + } + + public String getAvailableStreamFeatures() { + return null; + } + + public void close() { + } +}