示例#1
0
  /**
   * Invoke a handler. If a fault occurs it will be handled via the <code>handleFault</code> method.
   *
   * @param context The message context.
   */
  public void invoke(MessageContext context) throws Exception {
    UMOEvent event = (UMOEvent) context.getProperty(MuleProperties.MULE_EVENT_PROPERTY);

    if (event == null && context.getClient() != null) {
      event = (UMOEvent) context.getClient().getProperty(MuleProperties.MULE_EVENT_PROPERTY);
    }

    if (event != null) {
      MuleSoapHeaders muleHeaders = new MuleSoapHeaders(event);
      Element header = context.getOutMessage().getHeader();

      if (header == null) {
        header =
            new Element(
                "Header",
                context.getOutMessage().getSoapVersion().getPrefix(),
                context.getOutMessage().getSoapVersion().getNamespace());
      }

      // we can also add some extra properties like
      // Enconding Property, Session Property

      Element muleHeader = null;
      Namespace ns =
          Namespace.getNamespace(MuleSoapHeaders.MULE_NAMESPACE, MuleSoapHeaders.MULE_10_ACTOR);
      if (muleHeaders.getCorrelationId() != null || muleHeaders.getReplyTo() != null) {
        muleHeader = new Element(MuleSoapHeaders.MULE_HEADER, ns);
      } else {
        return;
      }

      Element e = null;
      if (muleHeaders.getCorrelationId() != null) {

        e = new Element(MuleProperties.MULE_CORRELATION_ID_PROPERTY, ns);
        e.setText(muleHeaders.getCorrelationId());
        muleHeader.addContent(e);

        e = new Element(MuleProperties.MULE_CORRELATION_GROUP_SIZE_PROPERTY, ns);
        e.setText(muleHeaders.getCorrelationGroup());
        muleHeader.addContent(e);

        e = new Element(MuleProperties.MULE_CORRELATION_SEQUENCE_PROPERTY, ns);
        e.setText(muleHeaders.getCorrelationSequence());
        muleHeader.addContent(e);
      }
      if (muleHeaders.getReplyTo() != null) {

        e = new Element(MuleProperties.MULE_REPLY_TO_PROPERTY, ns);
        e.setText(muleHeaders.getReplyTo());
        muleHeader.addContent(e);
      }
      header.addContent(muleHeader);

      context.getOutMessage().setHeader(header);
    }
  }
示例#2
0
  public void invoke(MessageContext context) throws Exception {

    // 为SOAP Header构造验证信息
    Element el = new Element("header");
    context.getOutMessage().setHeader(el);
    Element auth = new Element("AuthenticationToken");
    Element username_el = new Element("Username");
    username_el.addContent(username);
    Element password_el = new Element("Password");
    password_el.addContent(password);
    auth.addContent(username_el);
    auth.addContent(password_el);
    el.addContent(auth);
  }