示例#1
0
  @Override
  protected InvocationResponse doProcessing(MessageContext mc, EntityProxy<UserMessage> um)
      throws DatabaseException {

    log.debug("Check for payloads to include");
    Collection<IPayload> payloads = um.entity.getPayloads();

    if (Utils.isNullOrEmpty(payloads)) {
      // No payloads in this user message, so nothing to do
      log.debug("Usser message has no payloads");
    } else {
      // Add each payload to the message as described by the containment attribute
      log.debug("User message contains " + payloads.size() + " payload(s)");
      // If a MIME Content-Id is generated it should be saved to database as well
      boolean cidGenerated = false;
      for (IPayload pl : payloads) {
        // First ensure that the payload is assigned a MIME Content-Id when it added as an
        // attachment
        if (pl.getContainment() == ATTACHMENT && Utils.isNullOrEmpty(pl.getPayloadURI())) {
          // No MIME Content-Id assigned on submission, assign now
          String cid = MessageIdGenerator.createContentId(um.entity.getMessageId());
          log.debug(
              "Generated a new Content-id ["
                  + cid
                  + "] for payload ["
                  + pl.getContentLocation()
                  + "]");
          ((Payload) pl).setPayloadURI(cid);
          cidGenerated = true;
        }
        // Add the content of the payload to the SOAP message
        try {
          addContent(pl, mc);
        } catch (Exception e) {
          log.error(
              "Adding the payload content to message failed. Error details: " + e.getMessage());
          // If adding the payload fails, the message is in an incomplete state and should not
          // be sent. Therefor cancel further processing
          return InvocationResponse.ABORT;
        }
      }
      if (cidGenerated) {
        MessageUnitDAO.updateMessageUnitInfo(um);
        log.debug("Generated MIME Content-Id(s) saved to database");
      }
      log.debug("Payloads successfully added to message");
    }
    return InvocationResponse.CONTINUE;
  }
示例#2
0
  @Override
  protected InvocationResponse doProcessing(MessageContext mc, EntityProxy<UserMessage> umProxy)
      throws AxisFault {
    // Only when user message was successfully delivered to business application the Receipt should
    // be created
    Boolean delivered = (Boolean) mc.getProperty(MessageContextProperties.DELIVERED_USER_MSG);

    if (delivered != null && delivered) {
      // Extract the entity object from the proxy
      UserMessage um = umProxy.entity;
      log.debug("User message was succesfully delivered, check if Receipt is needed");

      IPMode pmode = HolodeckB2BCoreInterface.getPModeSet().get(um.getPModeId());
      if (pmode == null) {
        // The P-Mode configurations has changed and does not include this P-Mode anymore, assume no
        // receipt
        // is needed
        log.error(
            "P-Mode "
                + um.getPModeId()
                + " not found in current P-Mode set!"
                + "Unable to determine if receipt is needed for message [msgId="
                + um.getMessageId()
                + "]");
        return InvocationResponse.CONTINUE;
      }

      // Currently we only support one-way MEPs so the leg is always the first one
      ILeg leg = pmode.getLegs().iterator().next();
      IReceiptConfiguration rcptConfig = leg.getReceiptConfiguration();

      if (rcptConfig == null) {
        log.debug("No receipts requested for this message exchange");
        return InvocationResponse.CONTINUE;
      }

      log.debug("Receipt requested for this message exchange, create new Receipt signal");
      Receipt rcptData = new Receipt();
      // Copy some meta-data to receipt
      rcptData.setRefToMessageId(um.getMessageId());
      rcptData.setPMode(um.getPModeId());

      log.debug("Determine type of Receipt that should be sent");
      // Check if message was signed, done by checking if Signature info was available in default
      // WS-Sec header
      Map<String, IAuthenticationInfo> authInfo =
          (Map<String, IAuthenticationInfo>)
              mc.getProperty(SecurityConstants.MC_AUTHENTICATION_INFO);
      if (authInfo != null && authInfo.containsKey(SecurityConstants.SIGNATURE)) {
        log.debug("Received message was signed, created NRR receipt");
        rcptData.setContent(createNRRContent(mc));
      } else {
        log.debug("Received message not signed, create reception awareness receipt");
        rcptData.setContent(createRARContent(mc, um));
      }

      // Check reply patten to see if receipt should be sent as response
      boolean asResponse = rcptConfig.getPattern() == ReplyPattern.RESPONSE;

      log.debug("Store the receipt signal in database");
      try {
        // @todo: Use same pattern for creating the receipt as other message unit (let MsgDAO factor
        // object)
        EntityProxy<Receipt> receipt =
            MessageUnitDAO.storeOutgoingReceiptMessageUnit(rcptData, asResponse);
        if (asResponse) {
          log.debug("Store the receipt in the MessageContext");
          mc.setProperty(MessageContextProperties.RESPONSE_RECEIPT, receipt);
          mc.setProperty(MessageContextProperties.RESPONSE_REQUIRED, true);
        } else {
          if (rcptConfig.getTo() != null && !rcptConfig.getTo().isEmpty()) {
            log.debug(
                "The Receipt should be sent separately, change its processing state to READY_TO_PUSH");
            MessageUnitDAO.setReadyToPush(receipt);
          } else {
            log.debug("Receipt will be piggybacked on next PullRequest");
          }
        }
        log.debug("Receipt for message [msgId=" + um.getMessageId() + "] created successfully");
        // Trigger event to signal that the event was created
        HolodeckB2BCoreInterface.getEventProcessor()
            .raiseEvent(
                new ReceiptCreatedEvent(
                    um,
                    receipt.entity,
                    um.getCurrentProcessingState().getName().equals(ProcessingStates.DUPLICATE)),
                mc);
      } catch (DatabaseException ex) {
        // Storing the new Receipt signal failed! This is a severe problem, but it does not
        // need to stop processing because the user message is already delivered. The receipt
        // can be regenerated when a retry is received.
        log.error(
            "Creating the Receipt signal in repsonse to user message [msgId="
                + um.getMessageId()
                + "] failed! Details: "
                + ex.getMessage());
      }
    } else {
      // The user message is not delivered to the business application, so do not create a receipt
      log.debug("User message is not delivered successfully, so no Receipt possible");
    }

    return InvocationResponse.CONTINUE;
  }