Package org.serviceconnector.api

Examples of org.serviceconnector.api.SCMessage


      String serviceName = "session-1";
      service = sc.newSessionService(serviceName); // name of the service to use
      service.setEchoIntervalSeconds(10); // can be set before create session
      service.setEchoTimeoutSeconds(2); // can be set before create session

      SCMessage msg = new SCMessage();
      msg.setSessionInfo("session-info"); // optional
      msg.setData("certificate or what so ever"); // optional
      SCMessageCallback cbk = new DemoSessionClientCallback(service); // callback on service!!
      SCMessage reply = service.createSession(10, msg, cbk); // create a session within 10 seconds
      Object body = reply.getData();

      String sid = service.getSessionId();

      SCMessage requestMsg = new SCMessage();
      SCMessage responseMsg = new SCMessage();

      for (int i = 0; i < 5; i++) {
        requestMsg.setData("body nr : " + i);
        responseMsg = service.execute(requestMsg); // regular synchronous call
        LOGGER.info("Message sent sync=" + requestMsg.getData());
        LOGGER.info("Message received sync=" + responseMsg.getData());
        Thread.sleep(2000);
      }
      for (int i = 0; i < 5; i++) {
        requestMsg.setData("body nr : " + i);
        service.send(requestMsg); // regular asynchronous call
        LOGGER.info("Message sent async=" + requestMsg.getData());
        Thread.sleep(2000);
      }

      requestMsg.setData("cache message body");
      requestMsg.setCacheId("700");
      responseMsg = service.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent to put in cache=" + requestMsg.getData());
      LOGGER.info("Message received=" + responseMsg.getData());

      responseMsg = service.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent with cacheId=" + requestMsg.getData());
      LOGGER.info("Message received from cache=" + responseMsg.getData());
    } catch (Exception e) {
      LOGGER.error("run", e);
    } finally {
      try {
        SCMessage msg = new SCMessage();
        msg.setSessionInfo("kill server");
        service.deleteSession(5, msg);
        sc.detach(2); // detaches from SC, stops communication
      } catch (Exception e) {
        LOGGER.error("cleanup", e);
      }
View Full Code Here


      this.service.setRequestComplete();
      this.messageCallback.receive(e);
      return;
    }
    // 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(reply.getSessionId());
    replyToClient.setMessageInfo(reply.getHeader(SCMPHeaderAttributeKey.MSG_INFO));
    replyToClient.setAppErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.APP_ERROR_CODE));
    replyToClient.setAppErrorText(reply.getHeader(SCMPHeaderAttributeKey.APP_ERROR_TEXT));
    // inform service request is completed
    this.service.setRequestComplete();
    this.messageCallback.receive(replyToClient);
  }
View Full Code Here

      String serviceName = "session-1";
      sessionSrv = sc.newSessionService(serviceName); // name of the service to use
      sessionSrv.setEchoIntervalSeconds(10); // can be set before create session
      sessionSrv.setEchoTimeoutSeconds(2); // can be set before create session

      SCMessage msg = new SCMessage();
      msg.setSessionInfo("session-info"); // optional
      msg.setData("certificate or what so ever"); // optional
      SCMessageCallback cbk = new DemoSessionClientCallback(sessionSrv); // callback on service!!
      SCMessage reply = sessionSrv.createSession(10, msg, cbk); // create a session within 10 seconds
      Object body = reply.getData();   
     
      String sid = sessionSrv.getSessionId();

      SCMessage requestMsg = new SCMessage();
      SCMessage responseMsg = new SCMessage();

      requestMsg.setData("cache message body");
      requestMsg.setCacheId("700");
      responseMsg = sessionSrv.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent to put in cache=" + requestMsg.getData());
      LOGGER.info("Message received=" + responseMsg.getData());

      responseMsg = sessionSrv.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent with cacheId=" + requestMsg.getData());
      LOGGER.info("Message received from cache=" + responseMsg.getData());     
     
      SCPublishService publishService = sc.newPublishService("cacheGuardian1"); // name of the service to use

      DemoPublishClientCallback pubCbk = new DemoPublishClientCallback(publishService); // callback on service!!
      // set up subscribe message
      SCSubscribeMessage subMsg = new SCSubscribeMessage();
      String mask = "0000121ABCDEFGHIJKLMNO-----------X-----------";
      subMsg.setSessionInfo("subscription-info"); // optional
      subMsg.setData("certificate or what so ever"); // optional
      subMsg.setMask(mask); // mandatory
      subMsg.setNoDataIntervalSeconds(100); // mandatory
      SCSubscribeMessage subReply = publishService.subscribe(subMsg, pubCbk); // regular subscribe
     
      responseMsg = sessionSrv.execute(requestMsg); // regular synchronous call
      LOGGER.info("Message sent with cacheId=" + requestMsg.getData());
      LOGGER.info("Message received from cache=" + responseMsg.getData());   
     
     
    } catch (Exception e) {
      LOGGER.error("run", e);
    } finally {
      try {
        SCMessage msg = new SCMessage();
        msg.setSessionInfo("kill server");
        sessionSrv.deleteSession(5, msg);
        sc.detach(2); // detaches from SC, stops communication
      } catch (Exception e) {
        LOGGER.error("cleanup", e);
      }
View Full Code Here

      String serviceName = "session-1";
      service = sc.newSessionService(serviceName); // regular, no other params possible
      service.setEchoIntervalSeconds(10); // can be set before create session
      service.setEchoTimeoutSeconds(2); // can be set before create session

      SCMessage msg = new SCMessage();
      msg.setSessionInfo("session-info"); // optional
      msg.setData("certificate or what so ever"); // optional
      SCMessageCallback cbk = new DemoSessionClientCallback(service); // callback on service!!
      service.createSession(10, msg, cbk); // alternative with operation timeout and message
      // service.createSession(msg); // alternative with message

      String sid = service.getSessionId();

      SCMessage requestMsg = new SCMessage();
      requestMsg.setCacheId("CBCD_SECURITY_MARKET");
      SCMessage responseMsg = new SCMessage();

      for (int i = 0; i < 10; i++) {
        requestMsg.setData("body nr : " + i);
        LOGGER.info("Message sent=" + requestMsg.getData());

        // service.send(cbk, requestMsg); // regular asynchronous call
        // service.send(cbk, requestMsg, 10); // alternative with operation timeout
        // service.receive(cbk); // wait for response
        // cbk.receive(); // wait for response ?
        // responseMsg = cbk.getMessage(); // response message

        // synchronous call encapsulates asynchronous call!
        responseMsg = service.execute(requestMsg); // regular synchronous call
        // responseMsg = service.execute(requestMsg, 10); // alternative with operation timeout

        LOGGER.info("Message received=" + responseMsg.getData());
        Thread.sleep(1000);
      }
      requestMsg.setData("kill server");
      // service.send(cbk, requestMsg);
View Full Code Here

      // connects to SC, checks connection to SC
      sc.attach();

      SCSessionService sessionServiceA = sc.newSessionService("session-1");
      // creates a session
      SCMessage scMessage = new SCMessage();
      scMessage.setSessionInfo("sessionInfo");
      sessionServiceA.setEchoTimeoutSeconds(300);
      SCMessageCallback cbk = new ExampleCallback(sessionServiceA);
      sessionServiceA.createSession(60, scMessage, cbk);

      SCMessage requestMsg = new SCMessage();
      requestMsg.setData("Hello World");
      requestMsg.setCompressed(false);

      sessionServiceA.send(requestMsg);

      // wait until message received
      waitForMessage(10);
View Full Code Here

      // connects to SC, checks connection to SC
      sc.attach();

      SCSessionService sessionServiceA = sc.newSessionService("session-1");
      // creates a session
      SCMessage scMessage = new SCMessage();
      scMessage.setSessionInfo("sessionInfo");
      sessionServiceA.setEchoTimeoutSeconds(300);
      SCMessageCallback cbk = new ExampleCallback(sessionServiceA);
      sessionServiceA.createSession(60, scMessage, cbk);

      SCMessage requestMsg = new SCMessage();
      // set up large buffer
      byte[] buffer = new byte[9000000];
      for (int i = 0; i < buffer.length; i++) {
        buffer[i] = (byte) i;
      }
      requestMsg.setData(buffer);
      requestMsg.setPartSize(65536); // 64KB
      requestMsg.setCompressed(false);
      System.out.println(buffer.length);
      SCMessage responseMsg = sessionServiceA.execute(requestMsg);
      System.out.println(responseMsg.getData().toString());
      // deletes the session
      sessionServiceA.deleteSession();
    } catch (Exception e) {
      e.printStackTrace();
    } finally {
View Full Code Here

      // connects to SC, checks connection to SC
      sc.attach();

      SCSessionService sessionServiceA = sc.newSessionService("session-1");
      // creates a session
      SCMessage scMessage = new SCMessage();
      scMessage.setSessionInfo("sessionInfo");
      sessionServiceA.setEchoTimeoutSeconds(300);
      SCMessageCallback cbk = new ExampleCallback(sessionServiceA);
      sessionServiceA.createSession(60, scMessage, cbk);

      SCMessage requestMsg = new SCMessage();
      requestMsg.setData("Hello World");
      requestMsg.setCompressed(false);
      SCMessage responseMsg = sessionServiceA.execute(requestMsg);

      System.out.println(responseMsg.getData().toString());
      // deletes the session
      sessionServiceA.deleteSession();

    } catch (Exception e) {
      e.printStackTrace();
View Full Code Here

   *            the operation timeout millis
   * @return the sCMP message
   */
  protected final SCMPMessage baseCreateSession(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.setSessionId(reqMessage.getSessionId());
    scMessage.setSessionInfo(reqMessage.getHeader(SCMPHeaderAttributeKey.SESSION_INFO));
    scMessage.setServiceName(reqMessage.getServiceName());

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

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

    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()) {
        // session 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());
      }
    }
    reply.setSessionId(reqMessage.getSessionId());
    reply.setServiceName(serviceName);
    reply.setMessageType(reqMessage.getMessageType());
View Full Code Here

   */
  protected final SCMPMessage baseDeleteSession(SCMPMessage reqMessage, int operationTimeoutMillis) {
    // remove session from composite registry
    SCBaseServlet.compositeRegistry.removeSession(reqMessage.getSessionId());
    // 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.setSessionId(reqMessage.getSessionId());
    scMessage.setServiceName(reqMessage.getServiceName());
    scMessage.setSessionInfo(reqMessage.getHeader(SCMPHeaderAttributeKey.SESSION_INFO));
    // call servlet service implementation
    ((ISCSessionServerCallback) this).deleteSession(scMessage, operationTimeoutMillis);
    // set up reply
    SCMPMessage reply = new SCMPMessage();
    reply.setServiceName(serviceName);
View Full Code Here

   *            the operation timeout millis
   * @return the sCMP message
   */
  protected final SCMPMessage baseAbortSession(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.setSessionId(reqMessage.getSessionId());
    scMessage.setServiceName(reqMessage.getServiceName());
    // call servlet service implementation
    ((ISCSessionServerCallback) this).abortSession(scMessage, operationTimeoutMillis);
    // set up reply
    SCMPMessage reply = new SCMPMessage();
    reply.setServiceName(serviceName);
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.