Package org.serviceconnector.scmp

Examples of org.serviceconnector.scmp.SCMPMessage


      // XAB procedure for casc subscriptions
      Set<String> subscriptionIds = cascSubscription.getCscSubscriptionIds().keySet();

      int oti = AppContext.getBasicConfiguration().getSrvAbortOTIMillis();
      // set up abort message
      SCMPMessage abortMessage = new SCMPMessage();
      abortMessage.setHeader(SCMPHeaderAttributeKey.SC_ERROR_CODE, SCMPError.SESSION_ABORT.getErrorCode());
      abortMessage.setHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT,
          SCMPError.SESSION_ABORT.getErrorText("Cascaded subscription abort received."));
      abortMessage.setServiceName(cascSubscription.getService().getName());
      abortMessage.setHeader(SCMPHeaderAttributeKey.OPERATION_TIMEOUT, oti);

      StatefulServer server = (StatefulServer) cascSubscription.getServer();

      for (String id : subscriptionIds) {
        abortMessage.setSessionId(id);
        server.abortSessionAndWaitMech(oti, abortMessage, "Cascaded subscription abort in csc abort command", true);
      }
      cascSubscription.getCscSubscriptionIds().clear();
    }
  }
View Full Code Here


  }

  /** {@inheritDoc} */
  @Override
  public void validate(IRequest request) throws Exception {
    SCMPMessage message = request.getMessage();
    try {
      // msgSequenceNr mandatory
      String msgSequenceNr = message.getMessageSequenceNr();
      ValidatorUtility.validateLong(1, msgSequenceNr, SCMPError.HV_WRONG_MESSAGE_SEQUENCE_NR);
      // serviceName mandatory
      String serviceName = message.getServiceName();
      ValidatorUtility.validateStringLengthTrim(1, serviceName, Constants.MAX_LENGTH_SERVICENAME,
          SCMPError.HV_WRONG_SERVICE_NAME);
      // operation timeout mandatory
      String otiValue = message.getHeader(SCMPHeaderAttributeKey.OPERATION_TIMEOUT);
      ValidatorUtility.validateInt(Constants.MIN_OTI_VALUE_CSC, otiValue, Constants.MAX_OTI_VALUE,
          SCMPError.HV_WRONG_OPERATION_TIMEOUT);
      // cascadedSubscriptionId mandatory
      String cascadedSubscriptionId = message.getHeader(SCMPHeaderAttributeKey.CASCADED_SUBSCRIPTION_ID);
      ValidatorUtility.validateStringLengthTrim(1, cascadedSubscriptionId, Constants.MAX_STRING_LENGTH_256,
          SCMPError.HV_WRONG_SESSION_ID);
      // subscriptionId mandatory
      String subscriptionId = message.getSessionId();
      ValidatorUtility.validateStringLengthTrim(1, subscriptionId, Constants.MAX_STRING_LENGTH_256,
          SCMPError.HV_WRONG_SESSION_ID);
    } catch (HasFaultResponseException ex) {
      // needs to set message type at this point
      ex.setMessageType(getKey());
View Full Code Here

        LOGGER.debug("SCFileService uploadFile done");
      } catch (Exception e) {
        throw new SCServiceException("Upload file 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("Upload file 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
      // always delete file session
View Full Code Here

        downloadFileCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      } catch (Exception e) {
        throw new SCServiceException("Download file 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("Download file failed.");
        ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
        ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
        throw ex;
      }
      // 4. post process, reply to client
      if (reply.isComposite()) {
        ((SCMPCompositeReceiver) reply).writeBodyAsStream(outStream);
        return;
      }
      outStream.write((byte[]) reply.getBody());
    } catch (IOException e) {
      throw new SCServiceException("Writing to OutputStream failed. ", e);
    } finally {
      // always delete file session
      this.deleteFileSession(operationTimeoutSeconds);
View Full Code Here

      fileListCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
    } catch (Exception e) {
      throw new SCServiceException("List files 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("List files failed.");
      ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
      ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
      throw ex;
    }
    // 4. post process, reply to client
    byte[] body = (byte[]) reply.getBody();
    if (body == null) {
      return new ArrayList<String>();
    }
    String fileNameList = new String((byte[]) reply.getBody());
    String[] fileNames = fileNameList.split(Constants.FILE_LIST_DELIMITER);
    return Arrays.asList(fileNames);
  }
View Full Code Here

      createSessionCall.invoke(callback, operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
    } catch (Exception e) {
      throw new SCServiceException("Create file session on SC 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("Create file session on SC failed.");
      ex.setSCErrorCode(reply.getHeaderInt(SCMPHeaderAttributeKey.SC_ERROR_CODE));
      ex.setSCErrorText(reply.getHeader(SCMPHeaderAttributeKey.SC_ERROR_TEXT));
      throw ex;
    }
    // 4. post process, reply to client
    this.sessionId = reply.getSessionId();
  }
View Full Code Here

        // only logging the failure no further action
        LOGGER.warn("deleting file session on SC failed sid=" + sessionId + " " + e.toString());
        return;
      }
      // 3. receiving reply and error handling
      SCMPMessage reply = callback.getMessageSync(operationTimeoutSeconds * Constants.SEC_TO_MILLISEC_FACTOR);
      if (reply.isFault()) {
        // only logging the failure no further action
        LOGGER.warn("deleting file session on SC failed sid=" + sessionId);
      }
    } finally {
      // 4. post process, reply to client
View Full Code Here

  @Override
  public void receive(SCMPMessage reply) {
    // free server from subscription
    IStatefulServer server = this.subscription.getServer();
    server.removeSession(subscription);
    SCMPMessage reqMessage = request.getMessage();
    String serviceName = reqMessage.getServiceName();
    // forward server reply to client
    reply.setIsReply(true);
    reply.setServiceName(serviceName);
    reply.setMessageType(SCMPMsgType.CLN_UNSUBSCRIBE);
    this.response.setSCMP(reply);
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public void receive(Exception ex) {
    SCMPMessage reqMessage = request.getMessage();
    String sid = reqMessage.getSessionId();
    String serviceName = reqMessage.getServiceName();
    LOGGER.warn("receive exception sid=" + sid + " service=" + " " + ex.toString());
    // free server from subscription
    IStatefulServer server = this.subscription.getServer();
    server.removeSession(subscription);
    SCMPMessage fault = null;
    if (ex instanceof IdleTimeoutException) {
      // operation timeout handling
      fault = new SCMPMessageFault(SCMPError.OPERATION_TIMEOUT, "Operation timeout expired on SC cln unsubscribe sid=" + sid);
    } else if (ex instanceof IOException) {
      fault = new SCMPMessageFault(SCMPError.CONNECTION_EXCEPTION, "broken connection on SC cln unsubscribe sid=" + sid);
    } else if (ex instanceof InvalidMaskLengthException) {
      fault = new SCMPMessageFault(SCMPError.HV_WRONG_MASK, ex.getMessage() + "sid=" + sid);
    } else {
      fault = new SCMPMessageFault(SCMPError.SC_ERROR, "executing cln unsubscribe failed sid=" + sid);
    }
    // forward server reply to client
    fault.setIsReply(true);
    fault.setServiceName(serviceName);
    fault.setMessageType(SCMPMsgType.CLN_UNSUBSCRIBE);
    this.response.setSCMP(fault);
    this.responderCallback.responseCallback(request, response);
    // delete subscription failed abort!
    server.abortSession(subscription, "unsubscribe failed, exception received in callback");
  }
View Full Code Here

  }

  /** {@inheritDoc} */
  @Override
  public void run(IRequest request, IResponse response, IResponderCallback responderCallback) throws Exception {
    SCMPMessage reqMessage = request.getMessage();
    String serviceName = reqMessage.getServiceName();

    // check service is present
    Service abstractService = this.getService(serviceName);
    String subscriptionId = reqMessage.getSessionId();
    Subscription subscription = this.getSubscriptionById(subscriptionId);

    // enhance ipAddressList
    String ipAddressList = reqMessage.getHeader(SCMPHeaderAttributeKey.IP_ADDRESS_LIST);
    ipAddressList = ipAddressList + Constants.SLASH + request.getRemoteSocketAddress().getAddress().getHostAddress();
    reqMessage.setHeader(SCMPHeaderAttributeKey.IP_ADDRESS_LIST, ipAddressList);
    reqMessage.setHeader(SCMPHeaderAttributeKey.ACTUAL_MASK, subscription.getMask().getValue());

    int oti = reqMessage.getHeaderInt(SCMPHeaderAttributeKey.OPERATION_TIMEOUT);

    switch (abstractService.getType()) {
    case CASCADED_PUBLISH_SERVICE:
      CascadedPublishService cascadedPublishService = (CascadedPublishService) abstractService;
      // publish service is cascaded
      CascadedSC cascadedSC = cascadedPublishService.getCascadedSC();
      ClnChangeSubscriptionCommandCallback callback = new ClnChangeSubscriptionCommandCallback(request, response,
          responderCallback, subscription);
      cascadedSC.cascadedSCChangeSubscription(cascadedPublishService.getCascClient(), reqMessage, callback, oti);
      return;
    default:
      // code for other types of services is below
      break;
    }

    ClnChangeSubscriptionCommandCallback callback = null;
    StatefulServer server = (StatefulServer) subscription.getServer();
    int otiOnSCMillis = (int) (oti * basicConf.getOperationTimeoutMultiplier());
    int tries = (otiOnSCMillis / Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS);
    // Following loop implements the wait mechanism in case of a busy connection pool
    int i = 0;

    do {
      // reset ipList&msgType, might have been modified in below change subscription try
      reqMessage.setHeader(SCMPHeaderAttributeKey.IP_ADDRESS_LIST, ipAddressList);
      reqMessage.setMessageType(this.getKey());
      callback = new ClnChangeSubscriptionCommandCallback(request, response, responderCallback, subscription);
      try {
        server.changeSubscription(reqMessage, callback, otiOnSCMillis
            - (i * Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS));
        // no exception has been thrown - get out of wait loop
        break;
      } catch (ConnectionPoolBusyException ex) {
        LOGGER.debug("ConnectionPoolBusyException caught in wait mec of change subscription, tries left=" + tries);
        if (i >= (tries - 1)) {
          // only one loop outstanding - don't continue throw current exception
          LOGGER.debug(SCMPError.NO_FREE_CONNECTION.getErrorText("service=" + reqMessage.getServiceName()));
          SCMPCommandException scmpCommandException = new SCMPCommandException(SCMPError.NO_FREE_CONNECTION, "service="
              + reqMessage.getServiceName());
          scmpCommandException.setMessageType(this.getKey());
          throw scmpCommandException;
        }
      } // sleep for a while and then try again
      Thread.sleep(Constants.WAIT_FOR_FREE_CONNECTION_INTERVAL_MILLIS);
View Full Code Here

TOP

Related Classes of org.serviceconnector.scmp.SCMPMessage

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.