ConnectQosServer conQos = new ConnectQosServer(glob, receiver.getQos());
if (conQos.getSecurityQos() == null)
throw new XmlBlasterException(glob, ErrorCode.USER_SECURITY_AUTHENTICATION_ILLEGALARGUMENT, ME, "connect() without securityQos");
conQos.getSecurityQos().setClientIp (socket.getInetAddress().getHostAddress());
conQos.setAddressServer(getAddressServer());
Object callbackSocketDriver = new CallbackSocketDriver(conQos.getSessionName().getLoginName(), this);
conQos.getAddressServer().setCallbackDriver(callbackSocketDriver);
conQos.getData().getCurrentCallbackAddress().setCallbackDriver(callbackSocketDriver);
ConnectReturnQosServer retQos = getAuthenticateCore().connect(conQos);
this.secretSessionId = retQos.getSecretSessionId();
receiver.setSecretSessionId(retQos.getSecretSessionId()); // executeResponse needs it
executeResponse(receiver, retQos.toXml(), SocketUrl.SOCKET_TCP);
}
else if (MethodName.DISCONNECT == receiver.getMethodName()) {
executeResponse(receiver, Constants.RET_OK, SocketUrl.SOCKET_TCP); // ACK the disconnect to the client and then proceed to the server core
// Note: the disconnect will call over the CbInfo our shutdown as well
// setting sessionId = null prevents that our shutdown calls disconnect() again.
getAuthenticateCore().disconnect(getAddressServer(), receiver.getSecretSessionId(), receiver.getQos());
shutdown();
}
else {
if (log.isLoggable(Level.FINE)) log.fine("Received tunneled message, forwarding now to xmlBlaster core: " + receiver.getMethodNameStr());
boolean processed = receiveReply(receiver, SocketUrl.SOCKET_TCP); // Parse the message and invoke actions in same thread
if (!processed)
log.warning("Received message is not processed: " + receiver.toLiteral());
}
}
else if (this.acceptRemoteLoginAsTunnel
&& receiver.isResponse()
&& MethodName.UPDATE.equals(receiver.getMethodName())
&& MethodName.UPDATE_ONEWAY.equals(receiver.getMethodName()) // ONEWAY have no response, just do be complete
) {
log.severe("UPDATE RESPONSE IS NOT YET IMPLEMENTED");
boolean processed = receiveReply(receiver, SocketUrl.SOCKET_TCP); // Parse the message and invoke actions in same thread
if (!processed)
log.warning("Received message is not processed: " + receiver.toLiteral());
}
else {
// Normal client operation
if (receiver.isInvoke() && multiThreaded) {
// Parse the message and invoke callback to client code in a separate thread
// to avoid dead lock when client does a e.g. publish() during this update()
WorkerThread t = new WorkerThread(glob, this, receiver);
// -dispatch/callback/plugin/socket/invokerThreadPrio 5
t.setPriority(this.callbackAddress.getEnv("invokerThreadPrio", Thread.NORM_PRIORITY).getValue());
t.start();
}
else {
boolean processed = receiveReply(receiver, SocketUrl.SOCKET_TCP); // Parse the message and invoke actions in same thread
if (!processed)
log.warning("Received message is not processed: " + receiver.toLiteral());
}
if (MethodName.DISCONNECT == receiver.getMethodName() && receiver.isResponse()) {
if (log.isLoggable(Level.FINE)) log.fine("Terminating socket callback thread because of disconnect response");
threadRunning = false;
}
}
}
catch(XmlBlasterException e) {
log.warning(e.toString());
}
catch(Throwable e) {
if (e instanceof NullPointerException)
e.printStackTrace();
if (threadRunning == true) {
if (e.toString().indexOf("javax.net.ssl") != -1) {
log.warning("Closing connection to server, please try debugging SSL with 'java -Djavax.net.debug=all ...': " + e.toString());
}
else if (e instanceof IOException) {
log.warning("Closing connection to server: " + e.toString());
}
else {
log.severe("Closing connection to server: " + e.toString());
}
try {
// calls our shutdownSocket() which does this.threadRunning = false
sockCon.shutdown();
}
catch (XmlBlasterException ex) {
log.severe("run() could not shutdown correctly. " + ex.getMessage());
}
// Exceptions ends nowhere but terminates the thread
// Notify client library XmlBlasterAccess.java to go to polling
try {
I_CallbackExtended cb = this.cbClient;
if (cb != null) {
cb.lostConnection(XmlBlasterException.convert(this.glob, ME, "Lost socket connection", e));
}
}
catch(Throwable xx) {
xx.printStackTrace();
}
if (this.acceptRemoteLoginAsTunnel) {
try {
AddressServer addr = this.addressServer;
if (addr != null) {
CallbackSocketDriver cbd = (CallbackSocketDriver)addr.getCallbackDriver();
if (cbd != null) {
cbd.shutdown(); // notify about lost connection
}
}
}
catch(Throwable xx) {
xx.printStackTrace();