@Override
 public void handleMessage(SoapMessage message) throws Fault {
   final Header callHeader = message.getHeader(RequestCallbackFeature.CALL_ID_HEADER_NAME);
   if (callHeader == null) {
     return;
   }
   handleAddressing(message);
   final Header callbackHeader = message.getHeader(RequestCallbackFeature.CALLBACK_ID_HEADER_NAME);
   if (callbackHeader == null) {
     return;
   }
   final BindingOperationInfo boi = message.getExchange().getBindingOperationInfo();
   if (boi == null) {
     return;
   }
   final String action = SoapActionInInterceptor.getSoapAction(message);
   if (StringUtils.isEmpty(action)) {
     return;
   }
   final SoapOperationInfo soi = boi.getExtensor(SoapOperationInfo.class);
   if (soi == null) {
     return;
   }
   if (StringUtils.isEmpty(soi.getAction())) {
     soi.setAction(action);
   }
 }
示例#2
0
  /**
   * Validate incoming MAPs
   *
   * @param maps the incoming MAPs
   * @param message the current message
   * @return true if incoming MAPs are valid
   * @pre inbound message, not requestor
   */
  private boolean validateIncomingMAPs(AddressingProperties maps, Message message) {
    boolean valid = true;

    if (maps != null) {
      // WSAB spec, section 4.2 validation (SOAPAction must match action
      String sa = SoapActionInInterceptor.getSoapAction(message);
      String s1 = this.getActionUri(message, false);

      if (maps.getAction() == null || maps.getAction().getValue() == null) {
        String reason = BUNDLE.getString("MISSING_ACTION_MESSAGE");

        ContextUtils.storeMAPFaultName(Names.HEADER_REQUIRED_NAME, message);
        ContextUtils.storeMAPFaultReason(reason, message);
        valid = false;
      }

      if (!StringUtils.isEmpty(sa)
          && valid
          && !MessageUtils.isTrue(message.get(MAPAggregator.ACTION_VERIFIED))) {
        if (sa.startsWith("\"")) {
          sa = sa.substring(1, sa.lastIndexOf('"'));
        }
        String action = maps.getAction() == null ? "" : maps.getAction().getValue();
        if (!StringUtils.isEmpty(sa) && !sa.equals(action)) {
          // don't match, must send fault back....
          String reason = BUNDLE.getString("INVALID_ADDRESSING_PROPERTY_MESSAGE");

          ContextUtils.storeMAPFaultName(Names.ACTION_MISMATCH_NAME, message);
          ContextUtils.storeMAPFaultReason(reason, message);
          valid = false;
        } else if (!StringUtils.isEmpty(s1)
            && !action.equals(s1)
            && !action.equals(s1 + "Request")
            && !s1.equals(action + "Request")) {
          // if java first, it's likely to have "Request", if wsdl first,
          // it will depend if the wsdl:input has a name or not. Thus, we'll
          // check both plain and with the "Request" trailer

          // doesn't match what's in the wsdl/annotations
          String reason =
              BundleUtils.getFormattedString(BUNDLE, "ACTION_NOT_SUPPORTED_MSG", action);

          ContextUtils.storeMAPFaultName(Names.ACTION_NOT_SUPPORTED_NAME, message);
          ContextUtils.storeMAPFaultReason(reason, message);
          valid = false;
        }
      }

      AttributedURIType messageID = maps.getMessageID();

      if (!message.getExchange().isOneWay()
          && (messageID == null || messageID.getValue() == null)
          && valid) {
        String reason = BUNDLE.getString("MISSING_ACTION_MESSAGE");

        ContextUtils.storeMAPFaultName(Names.HEADER_REQUIRED_NAME, message);
        ContextUtils.storeMAPFaultReason(reason, message);

        valid = false;
      }

      // Always cache message IDs, even when the message is not valid for some
      // other reason.
      if (!allowDuplicates
          && messageID != null
          && messageID.getValue() != null
          && !messageIdCache.checkUniquenessAndCacheId(messageID.getValue())) {

        LOG.log(Level.WARNING, "DUPLICATE_MESSAGE_ID_MSG", messageID.getValue());

        // Only throw the fault if something else has not already marked the
        // message as invalid.
        if (valid) {
          String reason = BUNDLE.getString("DUPLICATE_MESSAGE_ID_MSG");
          String l7dReason = MessageFormat.format(reason, messageID.getValue());
          ContextUtils.storeMAPFaultName(Names.DUPLICATE_MESSAGE_ID_NAME, message);
          ContextUtils.storeMAPFaultReason(l7dReason, message);
        }

        valid = false;
      }
    } else if (usingAddressingAdvisory) {
      String reason = BUNDLE.getString("MISSING_ACTION_MESSAGE");

      ContextUtils.storeMAPFaultName(Names.HEADER_REQUIRED_NAME, message);
      ContextUtils.storeMAPFaultReason(reason, message);
      valid = false;
    }

    if (Names.INVALID_CARDINALITY_NAME.equals(ContextUtils.retrieveMAPFaultName(message))) {
      valid = false;
    }

    return valid;
  }