*/
public synchronized SCMessage createSession(int operationTimeoutSeconds, SCMessage scMessage, SCMessageCallback messageCallback)
throws SCServiceException, SCMPValidatorException {
// 1. checking preconditions and initialize
if (this.sessionActive) {
throw new SCServiceException("Session already created - delete session first.");
}
if (messageCallback == null) {
throw new SCMPValidatorException("Message callback must be set.");
}
if (scMessage == null) {
throw new SCMPValidatorException("Message (scMessage) must be set.");
}
// reset pendingRequest - necessary if service instances reused
this.pendingRequest = false;
this.messageCallback = messageCallback;
this.requester.getSCMPMsgSequenceNr().reset();
// 2. initialize call & invoke
SCMPClnCreateSessionCall createSessionCall = new SCMPClnCreateSessionCall(this.requester, this.serviceName);
createSessionCall.setRequestBody(scMessage.getData());
createSessionCall.setCompressed(scMessage.isCompressed());
createSessionCall.setSessionInfo(scMessage.getSessionInfo());
createSessionCall.setEchoIntervalSeconds(this.echoIntervalSeconds);
SCServiceCallback callback = new SCServiceCallback(true);
try {
createSessionCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
} catch (Exception e) {
throw new SCServiceException("Create session failed. ", e);
}
// 3. receiving reply and error handling
SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
if (reply.isFault() || reply.getHeaderFlag(SCMPHeaderAttributeKey.REJECT_SESSION)) {
SCServiceException ex = new SCServiceException("Create session failed.");
ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
ex.setAppErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.APP_ERROR_CODE));
ex.setAppErrorText(reply.getHeader(SCMPHeaderAttributeKey.APP_ERROR_TEXT));
throw ex;
}
this.sessionId = reply.getSessionId();
this.sessionActive = true;
// 4. post process, reply to client