I am trying to develop an applet that uses Jabber & Smack as its message transport. Unfortunately, the Jabber server must reside on a different server, and the applet (when used in demo mode) really wants to remain unsigned.
Is there an existing Java (server-side) forwarder/proxy that would take care of this?
Not having found one, and looking over the code in XMPPConnection and SSLXMPPConnection, it appears that currently the code expects to always open a socket to a destination with the same host name as the user’'s ID. Whereas a proxy/forwarder would want these as different.
The following code change would facilitate this by allowing creation of a factory class that could derive anonimous extentions to XMPPConnection that would allow for easy overrides with custom Socket creation logic.
Basicly changing the core constructor of XMPPConnection to:
public XMPPConnection(String host, int port) throws XMPPException {
this.host = host;
this.port = port;
this.socket = createSocket(host, port);
init();
}
And isolating the socket creation logic in:
public Socket createSocket(String host, int port) throws XMPPException {
Socket s;
try {
s = new Socket(host, port);
}
catch (UnknownHostException uhe) {
throw new XMPPException(
"Could not connect to " + host + “:” + port + “.”,
new XMPPError(504),
uhe);
}
catch (IOException ioe) {
throw new XMPPException(
"XMPPError connecting to " + host + “:” + port + “.”,
new XMPPError(502),
ioe);
}
return s;
}
The factored out createSocket() would allow code such as:
new XMPPConnection(“host”, sockNum)
{ public Socket createSocket(String host, int port) throws XMPPException
{ return … create_my_custom_proxy_socket(host, port);
}
};
As best I can tell, this should let me create a custom proxy socket, and do any initialization in a maner transparent to the rest of Smack.
Have I missed something in the Smack library? Is this covered in some other way?
Harrison