Package org.serviceconnector.api

Examples of org.serviceconnector.api.SCMessage


   *            the operation timeout millis
   * @return the sCMP message
   */
  protected final SCMPMessage baseExecute(SCMPMessage reqMessage, int operationTimeoutMillis) {
    // create scMessage
    SCMessage scMessage = new SCMessage();
    scMessage.setData(reqMessage.getBody());
    scMessage.setDataLength(reqMessage.getBodyLength());
    scMessage.setCompressed(reqMessage.getHeaderFlag(SCMPHeaderAttributeKey.COMPRESSION));
    scMessage.setMessageInfo(reqMessage.getHeader(SCMPHeaderAttributeKey.MSG_INFO));
    scMessage.setCacheId(reqMessage.getCacheId());
    scMessage.setCachePartNr(reqMessage.getHeader(SCMPHeaderAttributeKey.CACHE_PARTN_NUMBER));
    scMessage.setServiceName(reqMessage.getServiceName());
    scMessage.setSessionId(reqMessage.getSessionId());
    // call servlet service implementation
    SCMessage scReply = ((ISCSessionServerCallback) this).execute(scMessage, operationTimeoutMillis);

    // set up reply
    SCMPMessage reply = new SCMPMessage();
    reply.setIsReply(true);
    reply.setServiceName(serviceName);
    reply.setSessionId(reqMessage.getSessionId());
    long msgSequenceNr = this.requester.getSCMPMsgSequenceNr().incrementAndGetMsgSequenceNr();
    reply.setHeader(SCMPHeaderAttributeKey.MESSAGE_SEQUENCE_NR, msgSequenceNr);
    reply.setMessageType(reqMessage.getMessageType());
    if (scReply != null) {
      reply.setBody(scReply.getData());
      if (scReply.getCacheExpirationDateTime() != null) {
        reply.setHeader(SCMPHeaderAttributeKey.CACHE_EXPIRATION_DATETIME,
            DateTimeUtility.getDateTimeAsString(scReply.getCacheExpirationDateTime()));
      }
      reply.setCacheId(scReply.getCacheId());
      if (scReply.getMessageInfo() != null) {
        reply.setHeader(SCMPHeaderAttributeKey.MSG_INFO, scReply.getMessageInfo());
      }
      if (scReply.isCompressed()) {
        reply.setHeaderFlag(SCMPHeaderAttributeKey.COMPRESSION);
      }
      if (scReply.getAppErrorCode() != Constants.EMPTY_APP_ERROR_CODE) {
        reply.setHeader(SCMPHeaderAttributeKey.APP_ERROR_CODE, scReply.getAppErrorCode());
      }
      if (scReply.getAppErrorText() != null) {
        reply.setHeader(SCMPHeaderAttributeKey.APP_ERROR_TEXT, scReply.getAppErrorText());
      }
      reply.setPartSize(scReply.getPartSize());
    }
    return reply;
  }
View Full Code Here


    }
    this.sessionId = reply.getSessionId();
    this.sessionActive = true;
    // 4. post process, reply to client
    this.triggerSessionTimeout();
    SCMessage replyToClient = new SCMessage();
    replyToClient.setData(reply.getBody());
    replyToClient.setDataLength(reply.getBodyLength());
    replyToClient.setCompressed(reply.getHeaderFlag(SCMPHeaderAttributeKey.COMPRESSION));
    replyToClient.setSessionId(this.sessionId);
    replyToClient.setSessionInfo(reply.getHeader(SCMPHeaderAttributeKey.SESSION_INFO));
    replyToClient.setAppErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.APP_ERROR_CODE));
    replyToClient.setAppErrorText(reply.getHeader(SCMPHeaderAttributeKey.APP_ERROR_TEXT));
    return replyToClient;
  }
View Full Code Here

      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 = new SCMessage();
    replyToClient.setData(reply.getBody());
    replyToClient.setDataLength(reply.getBodyLength());
    replyToClient.setCompressed(reply.getHeaderFlag(SCMPHeaderAttributeKey.COMPRESSION));
    replyToClient.setSessionId(this.sessionId);
    replyToClient.setCacheId(reply.getCacheId());
    replyToClient.setCachePartNr(reply.getHeader(SCMPHeaderAttributeKey.CACHE_PARTN_NUMBER));
    replyToClient.setMessageInfo(reply.getHeader(SCMPHeaderAttributeKey.MSG_INFO));
    replyToClient.setAppErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.APP_ERROR_CODE));
    replyToClient.setAppErrorText(reply.getHeader(SCMPHeaderAttributeKey.APP_ERROR_TEXT));
    return replyToClient;
  }
View Full Code Here

    scMessage.setSessionId(reqMessage.getSessionId());
    scMessage.setMask(reqMessage.getHeader(SCMPHeaderAttributeKey.MASK));
    scMessage.setServiceName(reqMessage.getServiceName());

    // call servlet service implementation
    SCMessage scReply = ((ISCPublishServerCallback) this).subscribe(scMessage, operationTimeoutMillis);

    // set up reply
    SCMPMessage reply = new SCMPMessage();
    long msgSequenceNr = this.requester.getSCMPMsgSequenceNr().incrementAndGetMsgSequenceNr();
    reply.setHeader(SCMPHeaderAttributeKey.MESSAGE_SEQUENCE_NR, msgSequenceNr);
    reply.setServiceName(serviceName);
    reply.setMessageType(reqMessage.getMessageType());
    reply.setSessionId(reqMessage.getSessionId());

    if (scReply != null) {
      reply.setBody(scReply.getData());
      if (scReply.isCompressed()) {
        reply.setHeaderFlag(SCMPHeaderAttributeKey.COMPRESSION);
      }
      if (scReply.getAppErrorCode() != Constants.EMPTY_APP_ERROR_CODE) {
        reply.setHeader(SCMPHeaderAttributeKey.APP_ERROR_CODE, scReply.getAppErrorCode());
      }
      if (scReply.getAppErrorText() != null) {
        reply.setHeader(SCMPHeaderAttributeKey.APP_ERROR_TEXT, scReply.getAppErrorText());
      }
      if (scReply.isReject()) {
        // subscription rejected
        reply.setHeaderFlag(SCMPHeaderAttributeKey.REJECT_SESSION);
      } else {
        // add session to composite registry
        SCBaseServlet.compositeRegistry.addSession(reqMessage.getSessionId());
      }
      if (scReply.getSessionInfo() != null) {
        reply.setHeader(SCMPHeaderAttributeKey.SESSION_INFO, scReply.getSessionInfo());
      }
    }
    return reply;
  }
View Full Code Here

    scMessage.setMask(reqMessage.getHeader(SCMPHeaderAttributeKey.MASK));
    scMessage.setServiceName(reqMessage.getServiceName());
    scMessage.setActualMask(reqMessage.getHeader(SCMPHeaderAttributeKey.ACTUAL_MASK));

    // call servlet service implementation
    SCMessage scReply = ((ISCPublishServerCallback) this).changeSubscription(scMessage, operationTimeoutMillis);

    // set up reply
    SCMPMessage reply = new SCMPMessage();
    long msgSequenceNr = this.requester.getSCMPMsgSequenceNr().incrementAndGetMsgSequenceNr();
    reply.setHeader(SCMPHeaderAttributeKey.MESSAGE_SEQUENCE_NR, msgSequenceNr);
    reply.setServiceName(serviceName);
    reply.setMessageType(reqMessage.getMessageType());

    if (scReply != null) {
      reply.setBody(scReply.getData());
      if (scReply.isCompressed()) {
        reply.setHeaderFlag(SCMPHeaderAttributeKey.COMPRESSION);
      }
      if (scReply.getAppErrorCode() != Constants.EMPTY_APP_ERROR_CODE) {
        reply.setHeader(SCMPHeaderAttributeKey.APP_ERROR_CODE, scReply.getAppErrorCode());
      }
      if (scReply.getAppErrorText() != null) {
        reply.setHeader(SCMPHeaderAttributeKey.APP_ERROR_TEXT, scReply.getAppErrorText());
      }
      if (scReply.isReject()) {
        reply.setHeaderFlag(SCMPHeaderAttributeKey.REJECT_SESSION);
      }
      if (scReply.getSessionInfo() != null) {
        reply.setHeader(SCMPHeaderAttributeKey.SESSION_INFO, scReply.getSessionInfo());
      }
    }
    return reply;
  }
View Full Code Here

   * Description: send 1 uncompressed 1MB message<br>
   * Expectation: passes
   */
  @Test
  public void t103_sendLargeUncompressed() throws Exception {
    SCMessage request = new SCMessage(new byte[TestConstants.dataLength1MB]);
    request.setDataLength(TestConstants.dataLength1MB);
    request.setCompressed(false);
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(new SCMessage(), msgCallback1);
    request.setMessageInfo(TestConstants.echoCmd);
    sessionService1.send(request);
    msgCallback1.waitForMessage(20);
    response = msgCallback1.getResponse();
    Assert.assertEquals("message body is not the same length", request.getDataLength(), response.getDataLength());
    Assert.assertEquals("message info is not the same", request.getMessageInfo(), response.getMessageInfo());
    Assert.assertEquals("sessionId is not the same", sessionService1.getSessionId(), response.getSessionId());
    Assert.assertEquals("service name is not the same", request.getServiceName(), response.getServiceName());
    Assert.assertEquals("session info is not the same", request.getSessionInfo(), response.getSessionInfo());
    Assert.assertEquals("compression is not the same", request.isCompressed(), response.isCompressed());
    sessionService1.deleteSession();
  }
View Full Code Here

   * Description: send 1 compressed 1MB message<br>
   * Expectation: passes
   */
  @Test
  public void t104_sendLargeCompressed() throws Exception {
    SCMessage request = new SCMessage(new byte[TestConstants.dataLength1MB]);
    request.setDataLength(TestConstants.dataLength1MB);
    request.setCompressed(true);
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(new SCMessage(), msgCallback1);
    request.setMessageInfo(TestConstants.echoCmd);
    sessionService1.send(request);
    msgCallback1.waitForMessage(20);
    response = msgCallback1.getResponse();
    Assert.assertEquals("message body is not the same length", request.getDataLength(), response.getDataLength());
    Assert.assertEquals("message info is not the same", request.getMessageInfo(), response.getMessageInfo());
    Assert.assertEquals("sessionId is not the same", sessionService1.getSessionId(), response.getSessionId());
    Assert.assertEquals("service name is not the same", request.getServiceName(), response.getServiceName());
    Assert.assertEquals("session info is not the same", request.getSessionInfo(), response.getSessionInfo());
    Assert.assertEquals("compression is not the same", request.isCompressed(), response.isCompressed());
    sessionService1.deleteSession();
  }
View Full Code Here

   * Description: send message before create session<br>
   * Expectation: throws SCServiceException
   */
  @Test(expected = SCServiceException.class)
  public void t120_sendBeforeCreateSession() throws Exception {
    SCMessage request = new SCMessage(TestConstants.pangram);
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    sessionService1.send(request);
  }
View Full Code Here

   * Description: exchange messages on service which has been disabled<br>
   * Expectation: passes
   */
  @Test
  public void t110_disabledService() throws Exception {
    SCMessage request = new SCMessage(TestConstants.pangram);
    request.setDataLength(TestConstants.pangram.length());
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    msgCallback1 = new MsgCallback(sessionService1);
    response = sessionService1.createSession(request, msgCallback1);

    // disable service
    SCMgmtClient clientMgmt = new SCMgmtClient(TestConstants.HOST, TestConstants.PORT_SC0_TCP);
    clientMgmt.attach();
    clientMgmt.disableService(TestConstants.sesServiceName1);
    clientMgmt.detach();

    // send
    request.setMessageInfo(TestConstants.echoCmd);
    sessionService1.send(request);
    msgCallback1.waitForMessage(10);
    response = msgCallback1.getResponse();
    Assert.assertEquals("message body is not the same length", request.getDataLength(), response.getDataLength());
    Assert.assertEquals("messageInfo is not the same", request.getMessageInfo(), response.getMessageInfo());
    Assert.assertEquals("compression is not the same", request.isCompressed(), response.isCompressed());
    sessionService1.deleteSession();
  }
View Full Code Here

   * Description: send message after session rejection<br>
   * Expectation: throws SCserviceException
   */
  @Test(expected = SCServiceException.class)
  public void t140_rejectSession() throws Exception {
    SCMessage request = new SCMessage(TestConstants.pangram);
    SCMessage response = null;
    sessionService1 = client.newSessionService(TestConstants.sesServiceName1);
    request.setSessionInfo(TestConstants.rejectCmd);
    msgCallback1 = new MsgCallback(sessionService1);
    try {
      response = sessionService1.createSession(request, msgCallback1);
View Full Code Here

TOP

Related Classes of org.serviceconnector.api.SCMessage

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.