MsgInfo[] msgInfoArr = MsgInfo.parse(glob, progressListener, iStream, getMsgInfoParserClassName(), this.pluginInfo);
if (msgInfoArr.length < 1) {
log.warning(toString() + ": Got unexpected empty data from SOCKET, closing connection now");
break;
}
final MsgInfo receiver = msgInfoArr[0];
//if (MethodName.CONNECT.equals(receiver.getMethodName()))
// log.info("Test: Got connectQos");
if (log.isLoggable(Level.FINEST)) log.finest("Receiving message >" + receiver.toLiteral() + "<\n" + receiver.dump());
if (this.acceptRemoteLoginAsTunnel
&& receiver.isInvoke()
&& !MethodName.UPDATE.equals(receiver.getMethodName())
&& !MethodName.UPDATE_ONEWAY.equals(receiver.getMethodName())
&& !MethodName.EXCEPTION.equals(receiver.getMethodName())
&& !MethodName.PING.equals(receiver.getMethodName())) {
//getSocketExecutor().getXmlBlasterCore().
if (MethodName.CONNECT == receiver.getMethodName()) {
// TODO: crypt.importMessage(receiver.getQos()); see also ClientDispatchConnection.java:440
Socket socket = this.sock;
if (socket == null) return; // Is possible when EOF arrived inbetween
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;
}
}
}