Package org.serviceconnector.api

Examples of org.serviceconnector.api.SCServiceException


   *             publish message is not set<br />
   */
  public void publish(int operationTimeoutSeconds, SCPublishMessage publishMessage) throws SCServiceException,
      SCMPValidatorException {
    if (this.registered == false) {
      throw new SCServiceException("Server is not registered for a service.");
    }
    if (publishMessage == null) {
      throw new SCMPValidatorException("Publish message is missing.");
    }
    synchronized (this.scServer) {
      this.requester.getSCMPMsgSequenceNr().incrementAndGetMsgSequenceNr();
      // get lock on scServer - only one server is allowed to communicate over the initial connection
      SCMPPublishCall publishCall = new SCMPPublishCall(this.requester, serviceName);
      publishCall.setRequestBody(publishMessage.getData());
      publishCall.setMask(publishMessage.getMask());
      publishCall.setPartSize(publishMessage.getPartSize());
      publishCall.setMessageInfo(publishMessage.getMessageInfo());
      SCServerCallback callback = new SCServerCallback(true);
      try {
        publishCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      } catch (Exception e) {
        throw new SCServiceException("Publish failed. ", e);
      }
      SCMPMessage message = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      if (message.isFault()) {
        SCServiceException ex = new SCServiceException("Publish failed.");
        ex.setSCErrorCode(message.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
        ex.setSCErrorText(message.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
        throw ex;
      }
    }
  }
View Full Code Here


      return;
    }
    if (reply.isFault()) {
      this.service.sessionActive = false;
      // operation failed
      SCServiceException ex = new SCServiceException("SCPublishService operation failed sid=" + this.service.sessionId);
      ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
      ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
      super.receive(ex);
      return;
    }
    // 4. post process, reply to client
    boolean noData = reply.getHeaderFlag(SCMPHeaderAttributeKey.NO_DATA);
View Full Code Here

      return;
    }
    if (reply.isFault()) {
      this.service.sessionActive = false;
      // operation failed
      SCServiceException ex = new SCServiceException("SCGuardian operation failed sid=" + this.service.sessionId);
      ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
      ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
      super.receive(ex);
      return;
    }
    // 4. post process, reply to client
    boolean noData = reply.getHeaderFlag(SCMPHeaderAttributeKey.NO_DATA);
View Full Code Here

   *             publish message is not set<br />
   */
  public void publish(int operationTimeoutSeconds, SCPublishMessage publishMessage) throws SCServiceException,
      SCMPValidatorException {
    if (this.registered == false) {
      throw new SCServiceException("Server is not registered for a service.");
    }
    if (publishMessage == null) {
      throw new SCMPValidatorException("Publish message is missing.");
    }
    synchronized (this.scServer) {
      this.requester.getSCMPMsgSequenceNr().incrementAndGetMsgSequenceNr();
      // get lock on scServer - only one server is allowed to communicate over the initial connection
      SCMPPublishCall publishCall = new SCMPPublishCall(this.requester, serviceName);
      publishCall.setRequestBody(publishMessage.getData());
      publishCall.setMask(publishMessage.getMask());
      publishCall.setPartSize(publishMessage.getPartSize());
      publishCall.setMessageInfo(publishMessage.getMessageInfo());
      publishCall.setCacheMethod(publishMessage.getCachingMethod().getValue());
      publishCall.setCacheId(publishMessage.getCacheId());
      SCServerCallback callback = new SCServerCallback(true);
      try {
        publishCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      } catch (Exception e) {
        throw new SCServiceException("Publish failed. ", e);
      }
      SCMPMessage message = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      if (message.isFault()) {
        SCServiceException ex = new SCServiceException("Publish failed.");
        ex.setSCErrorCode(message.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
        ex.setSCErrorText(message.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
        throw ex;
      }
    }
  }
View Full Code Here

   */
  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
View Full Code Here

   */
  public synchronized SCMessage execute(int operationTimeoutSeconds, SCMessage scMessage) throws SCServiceException,
      SCMPValidatorException {
    // 1. checking preconditions and initialize
    if (this.sessionActive == false) {
      throw new SCServiceException("Execute not possible, no active session.");
    }
    if (this.pendingRequest) {
      // pending Request - reply still outstanding
      throw new SCServiceException("Execute not possible, there is a pending request - two pending request are not allowed.");
    }
    if (scMessage == null) {
      throw new SCMPValidatorException("Message (scMessage) must be set.");
    }
    this.requester.getSCMPMsgSequenceNr().incrementAndGetMsgSequenceNr();
    // 2. initialize call & invoke
    SCMPClnExecuteCall clnExecuteCall = new SCMPClnExecuteCall(this.requester, this.serviceName, this.sessionId);
    clnExecuteCall.setMessageInfo(scMessage.getMessageInfo());
    clnExecuteCall.setCacheId(scMessage.getCacheId());
    clnExecuteCall.setCompressed(scMessage.isCompressed());
    clnExecuteCall.setPartSize(scMessage.getPartSize());
    clnExecuteCall.setRequestBody(scMessage.getData());
    SCServiceCallback callback = new SCServiceCallback(true);
    try {
      PerformanceLogger.beginThreadBound();
      clnExecuteCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
    } catch (Exception e) {
      PerformanceLogger.endThreadBound(this.sessionId);
      throw new SCServiceException("Execute request failed. ", e);
    }
    // 3. receiving reply and error handling
    SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
    PerformanceLogger.endThreadBound(this.sessionId);
    if (reply.isFault()) {
      SCServiceException scEx = new SCServiceException("Execute failed.");
      scEx.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
      scEx.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
      throw scEx;
    }

    // 4. post process, reply to client
    SCMessage replyToClient = null;
View Full Code Here

      clnExecutePollCall.setAppendixNr(readApp);
      SCServiceCallback cbk = new SCServiceCallback(true);
      try {
        clnExecutePollCall.invoke(cbk, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      } catch (Exception e) {
        throw new SCServiceException("Execute poll request failed. ", e);
      }
      // 3. receiving reply and error handling
      SCMPMessage reply = cbk.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      if (reply.isFault()) {
        SCServiceException scEx = new SCServiceException("Execute poll failed.");
        scEx.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
        scEx.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
        throw scEx;
      }

      SCAppendMessage appendix = new SCAppendMessage();
      appendix.setData(reply.getBody());
View Full Code Here

   */
  public synchronized void send(int operationtTimeoutSeconds, SCMessage scMessage) throws SCServiceException,
      SCMPValidatorException {
    // 1. checking preconditions and initialize
    if (this.sessionActive == false) {
      throw new SCServiceException("Send not possible, no active session.");
    }
    if (this.pendingRequest) {
      // already executed before - reply still outstanding
      throw new SCServiceException("Send not possible, there is a pending request - two pending request are not allowed.");
    }
    if (scMessage == null) {
      throw new SCMPValidatorException("Message (scMessage) must be set.");
    }
    this.requester.getSCMPMsgSequenceNr().incrementAndGetMsgSequenceNr();
    // important to set pendingRequest true in case of asynchronous communication
    this.pendingRequest = true;
    // 2. initialize call & invoke
    SCMPClnExecuteCall clnExecuteCall = new SCMPClnExecuteCall(this.requester, this.serviceName, this.sessionId);
    clnExecuteCall.setMessageInfo(scMessage.getMessageInfo());
    clnExecuteCall.setCacheId(scMessage.getCacheId());
    clnExecuteCall.setCompressed(scMessage.isCompressed());
    clnExecuteCall.setPartSize(scMessage.getPartSize());
    clnExecuteCall.setRequestBody(scMessage.getData());
    SCServiceCallback scmpCallback = new SCServiceCallback(this, this.messageCallback);
    try {
      clnExecuteCall.invoke(scmpCallback, operationtTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
    } catch (Exception e) {
      this.pendingRequest = false;
      throw new SCServiceException("Send request failed. ", e);
    }
  }
View Full Code Here

      clnEchoCall.invoke(callback, this.echoTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
    } catch (Exception e) {
      PerformanceLogger.endThreadBound(this.sessionId);
      // inactivate the session
      this.sessionActive = false;
      SCServiceException ex = new SCServiceException("Refreshing session by echo failed, service=" + this.serviceName
          + " sid=" + this.sessionId + ".");
      ex.setSCErrorCode(SCMPError.BROKEN_SESSION.getErrorCode());
      ex.setSCErrorText(SCMPError.BROKEN_SESSION.getErrorText("Can not send echo message for service=" + this.serviceName
          + " sid=" + this.sessionId + "."));
      this.messageCallback.receive(ex);
      return;
    }
    // 3. receiving reply and error handling
    SCMPMessage reply = callback.getMessageSync(this.echoTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
    PerformanceLogger.endThreadBound(this.sessionId);
    if (reply.isFault()) {
      // inactivate the session
      this.sessionActive = false;
      SCServiceException ex = new SCServiceException("Refreshing session by echo failed, service=" + this.serviceName
          + " sid=" + this.sessionId + ".");
      ex.setSCErrorCode(SCMPError.BROKEN_SESSION.getErrorCode());
      ex.setSCErrorText(SCMPError.BROKEN_SESSION.getErrorText("Can not send echo message for service=" + this.serviceName
          + " sid=" + this.sessionId + "."));
      this.messageCallback.receive(ex);
      return;
    }
    // 4. post process, reply to client
View Full Code Here

      // delete session not possible - no session on this service just ignore
      return;
    }
    if (this.pendingRequest) {
      // pending request - reply still outstanding
      throw new SCServiceException(
          "Delete session not possible, there is a pending request - two pending request are not allowed.");
    }
    // cancel session timeout even if its running already
    this.cancelSessionTimeout(true);
    this.requester.getSCMPMsgSequenceNr().incrementAndGetMsgSequenceNr();
    try {
      // 2. initialize call & invoke
      SCServiceCallback callback = new SCServiceCallback(true);
      SCMPClnDeleteSessionCall deleteSessionCall = new SCMPClnDeleteSessionCall(this.requester, this.serviceName,
          this.sessionId);
      if (scMessage != null) {
        // message might be null for deleteSession operation
        deleteSessionCall.setSessionInfo(scMessage.getSessionInfo());
      }
      try {
        deleteSessionCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      } catch (Exception e) {
        throw new SCServiceException("Delete session failed ", e);
      }
      // 3. receiving reply and error handling
      SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      if (reply.isFault()) {
        SCServiceException ex = new SCServiceException("Delete session failed.");
        ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
        ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
        throw ex;
      }
    } finally {
      // 4. post process, reply to client
      this.sessionId = null;
View Full Code Here

TOP

Related Classes of org.serviceconnector.api.SCServiceException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.