diff --git a/src/java/org/jivesoftware/multiplexer/ClientSession.java b/src/java/org/jivesoftware/multiplexer/ClientSession.java
index a7354b8..1408659 100644
--- a/src/java/org/jivesoftware/multiplexer/ClientSession.java
+++ b/src/java/org/jivesoftware/multiplexer/ClientSession.java
@@ -18,6 +18,9 @@
import org.xmlpull.v1.XmlPullParser;
import org.xmlpull.v1.XmlPullParserException;
+import java.net.InetAddress;
+import java.net.UnknownHostException;
+
/**
* Session that represents a client to server connection.
*
@@ -121,7 +124,13 @@
// Register that the new session is associated with the specified stream ID
Session.addSession(streamID, session);
// Send to the server that a new client session has been created
- serverSurrogate.clientSessionCreated(streamID);
+ InetAddress address = null;
+ try {
+ address = connection.getInetAddress();
+ } catch (UnknownHostException e) {
+ // Do nothing
+ }
+ serverSurrogate.clientSessionCreated(streamID, address);
// Build the start packet response
StringBuilder sb = new StringBuilder(200);
diff --git a/src/java/org/jivesoftware/multiplexer/ConnectionWorkerThread.java b/src/java/org/jivesoftware/multiplexer/ConnectionWorkerThread.java
index db3aa30..6fc0d2f 100644
--- a/src/java/org/jivesoftware/multiplexer/ConnectionWorkerThread.java
+++ b/src/java/org/jivesoftware/multiplexer/ConnectionWorkerThread.java
@@ -27,6 +27,7 @@
import javax.net.ssl.SSLHandshakeException;
import java.io.InputStreamReader;
+import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.security.MessageDigest;
@@ -384,14 +385,16 @@
* Sends a notification to the main server that a new client session has been created.
*
* @param streamID the stream ID assigned by the connection manager to the new session.
+ * @param address the remote address of the client.
*/
- public void clientSessionCreated(String streamID) {
+ public void clientSessionCreated(String streamID, InetAddress address) {
StringBuilder sb = new StringBuilder(100);
sb.append("");
+ sb.append("'>");
// Forward the notification to the server
connection.deliver(sb.toString());
}
diff --git a/src/java/org/jivesoftware/multiplexer/ServerPacketHandler.java b/src/java/org/jivesoftware/multiplexer/ServerPacketHandler.java
index b015b05..527927b 100644
--- a/src/java/org/jivesoftware/multiplexer/ServerPacketHandler.java
+++ b/src/java/org/jivesoftware/multiplexer/ServerPacketHandler.java
@@ -89,8 +89,32 @@
if (Log.isDebugEnabled()) {
Log.debug("IQ stanza of type RESULT was discarded: " + stanza.asXML());
}
+ } else if ("error".equals(type)) {
+ // Close session if child element is CREATE
+ Element wrapper = stanza.element("session");
+ if (wrapper != null) {
+ String streamID = wrapper.attributeValue("id");
+ // Check if the server is informing us that we need to close a session
+ if (wrapper.element("create") != null) {
+ // Get the session that matches the requested stream ID
+ Session session = Session.getSession(streamID);
+ if (session != null) {
+ session.close();
+ }
+ } else {
+ if (Log.isDebugEnabled()) {
+ Log.debug("IQ stanza of type ERRROR was discarded: " + stanza.asXML());
+ }
+ }
+ } else {
+ if (Log.isDebugEnabled()) {
+ Log.debug("IQ stanza of type ERRROR was discarded: " + stanza.asXML());
+ }
+ }
} else {
- Log.warn("IQ stanza with invalid type was discarded: " + stanza.asXML());
+ if (Log.isDebugEnabled()) {
+ Log.debug("IQ stanza with invalid type was discarded: " + stanza.asXML());
+ }
}
} else if ("error".equals(tag) && "stream".equals(stanza.getNamespacePrefix())) {
if (stanza.element("system-shutdown") != null) {
diff --git a/src/java/org/jivesoftware/multiplexer/ServerSurrogate.java b/src/java/org/jivesoftware/multiplexer/ServerSurrogate.java
index 45df35d..7716cd2 100644
--- a/src/java/org/jivesoftware/multiplexer/ServerSurrogate.java
+++ b/src/java/org/jivesoftware/multiplexer/ServerSurrogate.java
@@ -19,6 +19,7 @@
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
+import java.net.InetAddress;
import java.util.Map;
import java.util.concurrent.*;
import java.util.concurrent.atomic.AtomicInteger;
@@ -145,9 +146,10 @@
* a notification to the main server.
*
* @param streamID the stream ID assigned by the connection manager to the new session.
+ * @param address the remote address of the connection.
*/
- public void clientSessionCreated(final String streamID) {
- threadPool.execute(new NewSessionTask(streamID));
+ public void clientSessionCreated(final String streamID, final InetAddress address) {
+ threadPool.execute(new NewSessionTask(streamID, address));
}
/**
diff --git a/src/java/org/jivesoftware/multiplexer/net/NIOConnection.java b/src/java/org/jivesoftware/multiplexer/net/NIOConnection.java
index fb516c6..47dbc6c 100644
--- a/src/java/org/jivesoftware/multiplexer/net/NIOConnection.java
+++ b/src/java/org/jivesoftware/multiplexer/net/NIOConnection.java
@@ -197,7 +197,7 @@
if (session == null) {
return !ioSession.isConnected();
}
- return session.getStatus() == Session.STATUS_CLOSED;
+ return session.getStatus() == Session.STATUS_CLOSED && !ioSession.isConnected();
}
public boolean isSecure() {
diff --git a/src/java/org/jivesoftware/multiplexer/net/http/HttpSessionManager.java b/src/java/org/jivesoftware/multiplexer/net/http/HttpSessionManager.java
index 7020416..c85a4e0 100644
--- a/src/java/org/jivesoftware/multiplexer/net/http/HttpSessionManager.java
+++ b/src/java/org/jivesoftware/multiplexer/net/http/HttpSessionManager.java
@@ -14,20 +14,20 @@
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
+import org.jivesoftware.multiplexer.ConnectionManager;
+import org.jivesoftware.multiplexer.ServerSurrogate;
+import org.jivesoftware.multiplexer.Session;
+import org.jivesoftware.multiplexer.StreamIDFactory;
import org.jivesoftware.util.JiveConstants;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.Log;
import org.jivesoftware.util.TaskEngine;
-import org.jivesoftware.multiplexer.StreamIDFactory;
-import org.jivesoftware.multiplexer.ServerSurrogate;
-import org.jivesoftware.multiplexer.ConnectionManager;
-import org.jivesoftware.multiplexer.Session;
import java.net.InetAddress;
import java.util.List;
import java.util.Map;
import java.util.TimerTask;
-import java.util.concurrent.*;
+import java.util.concurrent.ConcurrentHashMap;
/**
* Manages sessions for all users connecting to Openfire using the HTTP binding protocal,
@@ -240,7 +240,7 @@
Session.addSession(streamID, session);
session.addSessionCloseListener(sessionListener);
// Send to the server that a new client session has been created
- serverSurrogate.clientSessionCreated(streamID);
+ serverSurrogate.clientSessionCreated(streamID, address);
return session;
}
diff --git a/src/java/org/jivesoftware/multiplexer/task/NewSessionTask.java b/src/java/org/jivesoftware/multiplexer/task/NewSessionTask.java
index ea87e20..87ef45a 100644
--- a/src/java/org/jivesoftware/multiplexer/task/NewSessionTask.java
+++ b/src/java/org/jivesoftware/multiplexer/task/NewSessionTask.java
@@ -11,8 +11,10 @@
package org.jivesoftware.multiplexer.task;
-import org.jivesoftware.multiplexer.ConnectionWorkerThread;
import org.jivesoftware.multiplexer.ClientSession;
+import org.jivesoftware.multiplexer.ConnectionWorkerThread;
+
+import java.net.InetAddress;
/**
* Task that notifies the server that a new client session has been created. This task
@@ -22,13 +24,16 @@
*/
public class NewSessionTask extends ClientTask {
- public NewSessionTask(String streamID) {
+ private InetAddress address;
+
+ public NewSessionTask(String streamID, InetAddress address) {
super(streamID);
+ this.address = address;
}
public void run() {
ConnectionWorkerThread workerThread = (ConnectionWorkerThread) Thread.currentThread();
- workerThread.clientSessionCreated(streamID);
+ workerThread.clientSessionCreated(streamID, address);
}
public void serverNotAvailable() {