@Override
    protected Soap createMessage(byte[] rawXml, SOAPMessage soap, String charset) throws Exception {
      if (soap.getSOAPHeader() != null) {
        SoapHeader header = unmarshalHeader(SoapHeader.class, soap.getSOAPHeader());
        if (header.getCentralService() != null) {
          if (header.getService() != null) {
            throw new CodedException(
                X_MALFORMED_SOAP,
                "Message header must contain either service id" + " or central service id");
          }

          ServiceId serviceId = GlobalConf.getServiceId(header.getCentralService());
          header.setService(serviceId);

          SOAPEnvelope envelope = soap.getSOAPPart().getEnvelope();
          envelope.removeChild(soap.getSOAPHeader());

          Node soapBody = envelope.removeChild(soap.getSOAPBody());
          envelope.removeContents(); // removes newlines etc.

          Marshaller marshaller =
              JaxbUtils.createMarshaller(SoapHeader.class, new SoapNamespacePrefixMapper());
          marshaller.marshal(header, envelope);

          envelope.appendChild(soapBody);

          byte[] newRawXml = SoapUtils.getBytes(soap);
          return super.createMessage(newRawXml, soap, charset);
        }
      }
      return super.createMessage(rawXml, soap, charset);
    }
Ejemplo n.º 2
0
 public void writeTo(SOAPMessage saaj) throws SOAPException {
   try {
     bridge.marshal(jaxbObject, saaj.getSOAPHeader());
   } catch (JAXBException e) {
     throw new SOAPException(e);
   }
 }
Ejemplo n.º 3
0
  /** Adds an "Access" element to the SOAP header */
  public boolean handleRequest(MessageContext msgct) {
    if (msgct instanceof SOAPMessageContext) {
      SOAPMessageContext smsgct = (SOAPMessageContext) msgct;
      try {
        SOAPMessage msg = smsgct.getMessage();
        SOAPEnvelope envelope = msg.getSOAPPart().getEnvelope();
        SOAPHeader header = msg.getSOAPHeader();

        if (header == null) header = envelope.addHeader(); // add an header if non exists

        SOAPHeaderElement accessElement =
            header.addHeaderElement(
                envelope.createName(
                    "Access", "ns0", "http://www.ipd.uni-karlsruhe.de/jplag/types"));
        SOAPElement usernameelem = accessElement.addChildElement("username");
        usernameelem.addTextNode(username);
        SOAPElement passwordelem = accessElement.addChildElement("password");
        passwordelem.addTextNode(password);
        SOAPElement compatelem = accessElement.addChildElement("compatLevel");
        compatelem.addTextNode(compatibilityLevel + "");
      } catch (SOAPException x) {
        System.out.println("Unable to create access SOAP header!");
        x.printStackTrace();
      }
    }
    return true;
  }
 private SOAPHeader getSOAPHeader(SOAPMessage doc) {
   SOAPHeader header;
   try {
     header = doc.getSOAPHeader();
   } catch (SOAPException e) {
     throw new RuntimeException(e);
   }
   return header;
 }
Ejemplo n.º 5
0
 public void writeTo(SOAPMessage saaj) throws SOAPException {
   SOAPHeader header = saaj.getSOAPHeader();
   SOAPHeaderElement she = header.addHeaderElement(new QName(getNamespaceURI(), getLocalPart()));
   she.addChildElement(actionLocalName);
   she.addTextNode(action);
   if (soapAction != null) {
     she.addChildElement(soapActionLocalName);
     she.addTextNode(soapAction);
   }
 }
Ejemplo n.º 6
0
  /*
   * ???
   *
   * @param response
   * @param responseBean
   * @throws DOMException
   * @throws SOAPException
   */
  private void extractHeaderDataSOAP(SOAPMessage response, HttpResponseBean responseBean)
      throws SOAPException {
    // extract MimeHeaders
    MimeHeaders mime = response.getMimeHeaders();
    Iterator<MimeHeader> iter = mime.getAllHeaders();

    while (iter.hasNext()) {
      MimeHeader mimeH = iter.next();
      responseBean.addEntryToResponseHeaders(mimeH.getName(), mimeH.getValue());
    }

    // extract SOAPHeaders from the envelope and a them to the mimeHeaders
    if (response.getSOAPHeader() != null) {
      javax.xml.soap.SOAPHeader header = response.getSOAPHeader();

      NodeList nodes = header.getChildNodes();

      for (int x = 0; x < nodes.getLength(); x++) {
        // if the header entry contains child nodes - write them with the node names
        if (nodes.item(x).hasChildNodes()) {
          NodeList childnodes = nodes.item(x).getChildNodes();
          StringBuilder buff = new StringBuilder();
          for (int y = 0; y < childnodes.getLength(); y++) {
            if (!"".equals(buff.toString())) {
              buff.append(" ");
            }
            buff.append(childnodes.item(y).getLocalName()).append(":");
            buff.append(childnodes.item(y).getTextContent());
          }
          responseBean.addEntryToResponseHeaders(nodes.item(x).getLocalName(), buff.toString());
        } else {
          responseBean.addEntryToResponseHeaders(
              nodes.item(x).getLocalName(), nodes.item(x).getTextContent());
        }
      }
    }
  }
Ejemplo n.º 7
0
  @Validated
  @Test
  public void testAppendChild() throws Exception {
    MessageFactory fact = MessageFactory.newInstance();
    SOAPMessage message = fact.createMessage();
    SOAPHeader soapHeader = message.getSOAPHeader();

    assertEquals(0, soapHeader.getChildNodes().getLength());
    assertFalse(soapHeader.getChildElements().hasNext());

    Document doc = soapHeader.getOwnerDocument();
    String namespace = "http://example.com";
    String localName = "GetLastTradePrice";
    Element getLastTradePrice = doc.createElementNS(namespace, localName);
    Element symbol = doc.createElement("symbol");
    symbol.setAttribute("foo", "bar");
    getLastTradePrice.appendChild(symbol);
    org.w3c.dom.Text def = doc.createTextNode("DEF");
    symbol.appendChild(def);

    soapHeader.appendChild(getLastTradePrice);

    assertEquals(1, soapHeader.getChildNodes().getLength());
    Iterator iter = soapHeader.getChildElements();
    assertTrue(iter.hasNext());
    Object obj = iter.next();
    // must be SOAPHeaderElement
    assertTrue(obj instanceof SOAPHeaderElement);
    SOAPElement soapElement = (SOAPElement) obj;
    assertEquals(namespace, soapElement.getNamespaceURI());
    assertEquals(localName, soapElement.getLocalName());

    iter = soapElement.getChildElements();
    assertTrue(iter.hasNext());
    obj = iter.next();
    assertTrue(obj instanceof SOAPElement);
    soapElement = (SOAPElement) obj;
    assertEquals(null, soapElement.getNamespaceURI());
    assertEquals("symbol", soapElement.getLocalName());
    assertFalse(iter.hasNext());

    iter = soapElement.getChildElements();
    assertTrue(iter.hasNext());
    obj = iter.next();
    assertTrue(obj instanceof Text);
    Text text = (Text) obj;
    assertEquals("DEF", text.getData());
    assertFalse(iter.hasNext());
  }
 @Override
 public void mapTo(Context context, SOAPBindingData target) throws Exception {
   SOAPMessage soapMessage = target.getSOAPMessage();
   MimeHeaders mimeHeaders = soapMessage.getMimeHeaders();
   SOAPHeader soapHeader = soapMessage.getSOAPHeader();
   for (Property property : context.getProperties(Scope.IN)) {
     Object value = property.getValue();
     if (value != null) {
       String name = property.getName();
       QName qname = XMLHelper.createQName(name);
       boolean qualifiedForSoapHeader = Strings.trimToNull(qname.getNamespaceURI()) != null;
       if (qualifiedForSoapHeader && matches(qname)) {
         if (value instanceof Node) {
           Node domNode = soapHeader.getOwnerDocument().importNode((Node) value, true);
           soapHeader.appendChild(domNode);
         } else if (value instanceof Configuration) {
           Element configElement = new ElementPuller().pull(new StringReader(value.toString()));
           Node configNode = soapHeader.getOwnerDocument().importNode(configElement, true);
           soapHeader.appendChild(configNode);
         } else {
           String v = value.toString();
           if (SOAPHeadersType.XML.equals(getSOAPHeadersType())) {
             try {
               Element xmlElement = new ElementPuller().pull(new StringReader(v));
               Node xmlNode = soapHeader.getOwnerDocument().importNode(xmlElement, true);
               soapHeader.appendChild(xmlNode);
             } catch (Throwable t) {
               soapHeader.addChildElement(qname).setValue(v);
             }
           } else {
             soapHeader.addChildElement(qname).setValue(v);
           }
         }
       } else {
         if (matches(name)) {
           mimeHeaders.addHeader(name, String.valueOf(value));
         }
       }
     }
   }
 }
Ejemplo n.º 9
0
  private SOAPMessage actionToSoap(RpcInvokeAction action) throws Exception {
    useFirstElementPrefix = true;

    SOAPMessage message = messageFactory.createMessage();
    actionData =
        WsRpcActionUtil.getWsRpcActionData(((SimpleRpcInvokeAction) action).getProperties());

    SOAPEnvelope env = message.getSOAPPart().getEnvelope();
    env.addNamespaceDeclaration(ACTION_PREFIX, actionData.getMethodInputNameSpace());

    setFields(action.getFields(), env.getBody());

    if (actionData.getSoapAction().length() > 0) {
      message.getMimeHeaders().addHeader("SOAPAction", actionData.getSoapAction());
    }

    // Base auth headers from http://www.whitemesa.com/soapauth.html#S322
    /*
     * all auth standarts: http://www.soapui.org/testing-dojo/best-practices/authentication.html
     */
    if (props.getPassword() != null
        && props.getUserName() != null
        && !props.getUserName().trim().equals("")) {
      SOAPHeaderElement auth =
          message
              .getSOAPHeader()
              .addHeaderElement(
                  new QName("http://soap-authentication.org/basic/2001/10/", "BasicAuth", "h"));
      auth.setMustUnderstand(true);
      auth.addChildElement("Name").setValue(props.getUserName());
      auth.addChildElement("Password").setValue(props.getPassword());
    }

    logMessage("Request message:", message);

    return message;
  }
Ejemplo n.º 10
0
  @Override
  protected MessageContext createProtocolMessageContext(SoapMessage message) {
    SOAPMessageContextImpl sm = new SOAPMessageContextImpl(message);

    Exchange exch = message.getExchange();
    setupBindingOperationInfo(exch, sm);
    SOAPMessage msg = sm.getMessage();
    try {
      List<SOAPElement> params = new ArrayList<SOAPElement>();
      message.put(MessageContext.REFERENCE_PARAMETERS, params);
      SOAPHeader head = msg.getSOAPHeader();
      if (head != null) {
        Iterator<Node> it = CastUtils.cast(head.getChildElements());
        while (it != null && it.hasNext()) {
          Node nd = it.next();
          if (nd instanceof SOAPElement) {
            SOAPElement el = (SOAPElement) nd;
            if (el.hasAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")
                && ("1".equals(el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter"))
                    || Boolean.parseBoolean(
                        el.getAttributeNS(Names.WSA_NAMESPACE_NAME, "IsReferenceParameter")))) {
              params.add(el);
            }
          }
        }
      }
      if (msg.getSOAPPart().getEnvelope().getBody() != null
          && msg.getSOAPPart().getEnvelope().getBody().hasFault()) {
        return null;
      }
    } catch (SOAPException e) {
      throw new Fault(e);
    }

    return sm;
  }
Ejemplo n.º 11
0
  /**
   * Find Base64 encoded certificate used to sign given message. No default constructor: Once
   * content has been created, remains unchanged for life of the instance.
   *
   * @param msg (received) SOAP message to parse
   * @exception JAXRException if any problem at all occurs, wrapping problems decoding content (from
   *     Base64) and any caught CertificateException or SOAPException
   */
  public ReceivedCertificate(SOAPMessage msg) throws JAXRException {
    // @wss:Id attribute value for <BinarySecurityToken/> element of interest
    final String tokenId = CanonicalConstants.CANONICAL_URI_SENDER_CERT;

    try {
      final Name binSecTokenName =
          SOAPFactory.newInstance().createName("BinarySecurityToken", "wsse", securityNS);

      SOAPHeader hdr = msg.getSOAPHeader();
      Iterator hdrElemIter = hdr.examineAllHeaderElements();
      while (hdrElemIter.hasNext()) {
        Object hdrElemObj = hdrElemIter.next();
        if (hdrElemObj instanceof SOAPHeaderElement) {
          // found a SOAP header element of some type
          SOAPHeaderElement hdrElem = (SOAPHeaderElement) hdrElemObj;
          if ((hdrElem.getLocalName().equals("Security"))
              && (hdrElem.getNamespaceURI().equals(securityNS))) {

            // found a <wss:Security/> element
            //                        Name binSecTokenName = SOAPFactory.newInstance().
            //			    createName("BinarySecurityToken", "wsse", securityNS);
            Iterator secTokensIter = hdrElem.getChildElements(binSecTokenName);
            while (secTokensIter.hasNext()) {
              Object binSecTokenObj = secTokensIter.next();
              if (binSecTokenObj instanceof Element) {
                // found a <BinarySecurityToken/> element
                Element binSecTokenElem = (Element) binSecTokenObj;
                String _tokenId = binSecTokenElem.getAttributeNS(securityUtilityNS, "Id");
                if (_tokenId.equals(tokenId)) {
                  // found propery identified element
                  if (null == cert) {
                    // found first cert content
                    InputStream is = null;
                    String encodedData = binSecTokenElem.getFirstChild().getNodeValue();
                    try {
                      try {
                        is = new ByteArrayInputStream(encodedData.getBytes("UTF-8"));
                        is = MimeUtility.decode(is, "base64");
                      } catch (Exception e) {
                        throw new JAXRException(
                            CommonResourceBundle.getInstance()
                                .getString("message.UnableToDecodeData"),
                            e);
                      }

                      CertificateFactory cf = CertificateFactory.getInstance("X.509");
                      cert = (X509Certificate) cf.generateCertificate(is);
                    } finally {
                      if (is != null) {
                        try {
                          is.close();
                        } catch (Exception e) {
                        }
                      }
                    }
                  } else {
                    // found second cert content
                    foundMultiple = true;
                    break;
                  }
                }
              }
            }
          }
        }
      }
    } catch (SOAPException e) {
      throw new JAXRException(
          CommonResourceBundle.getInstance().getString("message.CouldNotGetCertificate"), e);
    } catch (CertificateException e) {
      throw new JAXRException(
          CommonResourceBundle.getInstance().getString("message.CouldNotGetCertificate"), e);
    }
  }
Ejemplo n.º 12
0
 public void writeTo(SOAPMessage saaj) throws SOAPException {
   SOAPHeader header = saaj.getSOAPHeader();
   if (header == null) header = saaj.getSOAPPart().getEnvelope().addHeader();
   Node clone = header.getOwnerDocument().importNode(node, true);
   header.appendChild(clone);
 }
Ejemplo n.º 13
0
  public boolean handleMessage(SOAPMessageContext context) {
    boolean isSuccess = true;
    SOAPMessage message = null;
    boolean isRequest = false;
    String msgType = Constant.MESSAGE_TYPE_REQUEST;
    String requestID = null;
    String requestTimeStamp = null;
    String responseTimeStamp = null;
    String nameSpace = null;
    String webServiceName = null;
    try {
      if (context != null) {
        // get soap message from context
        message = context.getMessage();
        if (message != null) {
          isRequest =
              ((Boolean) context.get(MessageContext.MESSAGE_OUTBOUND_PROPERTY)).booleanValue();
          if (isRequest) {
            // assign a unique request id
            requestID = UUID.randomUUID().toString();
            context.put(Constant.WS_REQUEST_ID, requestID);
            // get the request time stamp
            requestTimeStamp = Utility.getTimeStamp(Constant.WS_TIMESTAMP_FORMAT);
            // find the name space and service name
            QName wsdlService = null;
            if (context.get(SOAPMessageContext.WSDL_SERVICE) != null) {
              wsdlService = (QName) context.get(SOAPMessageContext.WSDL_SERVICE);
              nameSpace = wsdlService.getNamespaceURI();
              webServiceName = wsdlService.getLocalPart();
              context.put(Constant.WS_NAME, webServiceName);
            }
            // dump the request
            dump(message, msgType, requestTimeStamp, webServiceName, requestID);
            // add the authentication header
            QName userNameElement = new QName(nameSpace, Constant.SOAP_USERNAME);
            QName passwordElement = new QName(nameSpace, Constant.SOAP_PASSWORD);
            SOAPHeader header = message.getSOAPHeader();
            SOAPPart soapPart = message.getSOAPPart();
            SOAPEnvelope soapEnvelope = soapPart.getEnvelope();
            header = soapEnvelope.addHeader();
            SOAPElement userNameSOAPElement = header.addChildElement(userNameElement);
            userNameSOAPElement.addTextNode(Utility.getWSProperty(Constant.USERNAME_KEY));
            SOAPElement passwordSOAPElement = header.addChildElement(passwordElement);
            passwordSOAPElement.addTextNode(
                Utility.convertHexToString(Utility.getWSProperty(Constant.PASSWORD_KEY)));
          } else {
            msgType = Constant.MESSAGE_TYPE_RESPONSE;
            requestID = (String) context.get(Constant.WS_REQUEST_ID);
            webServiceName = (String) context.get(Constant.WS_NAME);
            responseTimeStamp = Utility.getTimeStamp(Constant.WS_TIMESTAMP_FORMAT);
            if (message.getSOAPHeader() != null) {
              message.getSOAPHeader().detachNode();
            }
            dump(message, msgType, responseTimeStamp, webServiceName, requestID);
          }
        }
      }
    } catch (Exception e) {

    }
    return isSuccess;
  }
Ejemplo n.º 14
0
  public SOAPMessage buildPullMessage(
      URI uri, String enumerationContext, String resourceUri, int maxElements, int timeout)
      throws SOAPException {
    MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage soapMessage = messageFactory.createMessage();

    SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
    env.removeNamespaceDeclaration(env.getPrefix());
    env.setPrefix("s");
    env.addNamespaceDeclaration("a", NS_WS_ADDRESSING);
    env.addNamespaceDeclaration("w", NS_WS_MANAGEMENT);
    env.addNamespaceDeclaration("n", NS_WS_ENUMERATION);
    env.addNamespaceDeclaration("ev", NS_WS_EVENTING);

    QName mustUnderstand = new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "mustUnderstand", "s");

    SOAPHeader soapHeader = soapMessage.getSOAPHeader();
    soapHeader.setPrefix("s");

    SOAPHeaderElement toHeader =
        soapHeader.addHeaderElement(new QName(NS_WS_ADDRESSING, "To", "a"));
    toHeader.setValue(uri.toString());

    SOAPHeaderElement resourceURI =
        soapHeader.addHeaderElement(new QName(NS_WS_MANAGEMENT, "ResourceURI", "w"));
    resourceURI.addAttribute(mustUnderstand, "true");
    resourceURI.setValue(resourceUri);

    SOAPHeaderElement replyTo =
        soapHeader.addHeaderElement(new QName(NS_WS_ADDRESSING, "ReplyTo", "a"));

    SOAPElement addressElement =
        replyTo.addChildElement(new QName(NS_WS_ADDRESSING, "Address", "a"));
    addressElement.addAttribute(mustUnderstand, "true");
    addressElement.addTextNode("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous");

    SOAPElement actionElement =
        soapHeader.addChildElement(new QName(NS_WS_ADDRESSING, "Action", "a"));
    actionElement.addAttribute(mustUnderstand, "true");
    actionElement.addTextNode(ENUMERATION_PULL);

    // MaxEnvelopeSize
    SOAPElement maxEnvelopeSize =
        soapHeader.addChildElement(new QName(NS_WS_MANAGEMENT, "MaxEnvelopeSize", "w"));
    maxEnvelopeSize.addAttribute(mustUnderstand, "true");
    maxEnvelopeSize.addTextNode("51200");

    // Message ID
    SOAPElement messageId =
        soapHeader.addChildElement(new QName(NS_WS_ADDRESSING, "MessageID", "a"));
    messageId.addTextNode("uuid:" + UUID.randomUUID().toString());

    // Locale
    // SOAPElement locale = soapHeader.addChildElement(new
    // QName(NS_WS_MANAGEMENT, "Locale", "w"));
    // locale.addAttribute(mustUnderstand, "false");
    // locale.addAttribute(new QName("xml", "lang"), "en-US");

    SOAPElement operationTimeout =
        soapHeader.addChildElement(new QName(NS_WS_MANAGEMENT, "OperationTimeout", "w"));
    operationTimeout.addTextNode(String.format("PT%d.000S", timeout));

    SOAPBody soapBody = soapMessage.getSOAPBody();
    soapBody.setPrefix("s");

    SOAPElement pullElement = soapBody.addBodyElement(new QName(NS_WS_ENUMERATION, "Pull", "n"));

    SOAPElement enumerationContextElement =
        pullElement.addChildElement(new QName(NS_WS_ENUMERATION, "EnumerationContext", "n"));
    enumerationContextElement.setTextContent(enumerationContext);

    // SOAPElement maxTime = pullElement.addChildElement(new
    // QName(NS_WS_ENUMERATION, "MaxTime", "n"));
    // maxTime.setTextContent("PS60S");

    SOAPElement maxElement =
        pullElement.addChildElement(new QName(NS_WS_ENUMERATION, "MaxElements", "n"));
    maxElement.setTextContent(String.valueOf(maxElements));

    // SOAPElement maxCharacters = pullElement.addChildElement(new
    // QName(NS_WS_ENUMERATION, "MaxCharacters", "n"));
    // enumerationContextElement.setTextContent("250000");

    return soapMessage;
  }
Ejemplo n.º 15
0
  public SOAPMessage buildWQLQuery(
      URI uri, String namespace, String query, int maxElements, int timeout) throws SOAPException {
    MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage soapMessage = messageFactory.createMessage();

    SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
    env.removeNamespaceDeclaration(env.getPrefix());
    env.setPrefix("s");
    env.addNamespaceDeclaration("a", NS_WS_ADDRESSING);
    env.addNamespaceDeclaration("w", NS_WS_MANAGEMENT);
    env.addNamespaceDeclaration("en", NS_WS_ENUMERATION);

    QName mustUnderstand = new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "mustUnderstand", "s");

    SOAPHeader soapHeader = soapMessage.getSOAPHeader();
    soapHeader.setPrefix("s");

    SOAPHeaderElement toHeader =
        soapHeader.addHeaderElement(new QName(NS_WS_ADDRESSING, "To", "a"));
    toHeader.setValue(uri.toString());

    SOAPHeaderElement resourceURI =
        soapHeader.addHeaderElement(new QName(NS_WS_MANAGEMENT, "ResourceURI", "w"));
    resourceURI.addAttribute(mustUnderstand, "true");
    resourceURI.setValue(WSMAN_WMI_PREFIX + "/" + namespace + "/*");

    SOAPHeaderElement replyTo =
        soapHeader.addHeaderElement(new QName(NS_WS_ADDRESSING, "ReplyTo", "a"));

    SOAPElement addressElement =
        replyTo.addChildElement(new QName(NS_WS_ADDRESSING, "Address", "a"));
    addressElement.addAttribute(mustUnderstand, "true");
    addressElement.addTextNode("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous");

    SOAPElement actionElement =
        soapHeader.addChildElement(new QName(NS_WS_ADDRESSING, "Action", "a"));
    actionElement.addTextNode(ENUMERATION_ENUMERATE);

    // MaxEnvelopeSize
    SOAPElement maxEnvelopeSize =
        soapHeader.addChildElement(new QName(NS_WS_MANAGEMENT, "MaxEnvelopeSize", "w"));
    maxEnvelopeSize.addAttribute(mustUnderstand, "true");
    maxEnvelopeSize.addTextNode("51200");

    // Message ID
    SOAPElement messageId =
        soapHeader.addChildElement(new QName(NS_WS_ADDRESSING, "MessageID", "a"));
    messageId.addTextNode("uuid:" + UUID.randomUUID().toString());

    // Locale
    // SOAPElement locale = soapHeader.addChildElement(new
    // QName(NS_WS_MANAGEMENT, "Locale", "w"));
    // locale.addAttribute(mustUnderstand, "false");
    // locale.addAttribute(new QName("xml", "lang"), "en-US");

    SOAPElement operationTimeout =
        soapHeader.addChildElement(new QName(NS_WS_MANAGEMENT, "OperationTimeout", "w"));
    operationTimeout.addTextNode(String.format("PT%d.000S", timeout));

    SOAPBody soapBody = soapMessage.getSOAPBody();
    soapBody.setPrefix("s");

    SOAPElement enumerateElement =
        soapBody.addBodyElement(new QName(NS_WS_ENUMERATION, "Enumerate", "en"));

    // Return in the same response
    enumerateElement.addChildElement(new QName(NS_WS_MANAGEMENT, "OptimizeEnumeration", "w"));
    SOAPElement maxElement =
        enumerateElement.addChildElement(new QName(NS_WS_MANAGEMENT, "MaxElements", "w"));
    maxElement.addTextNode(String.valueOf(maxElements));
    SOAPElement filterElement =
        enumerateElement.addChildElement(new QName(NS_WS_MANAGEMENT, "Filter", "w"));
    filterElement.setAttribute("Dialect", DIALECT_WQL);
    filterElement.addTextNode(query);

    return soapMessage;
  }
Ejemplo n.º 16
0
  public SOAPMessage buildEventSubscription(
      URI uri, String subscriptionQuery, int maxElements, int timeout) throws SOAPException {
    // EVENT_LOG_NOTIFICATION_QUERY = """
    // SELECT * FROM __InstanceCreationEvent
    // WHERE TargetInstance ISA 'Win32_NTLogEvent'
    // AND TargetInstance.EventType <= %d
    // """
    MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage soapMessage = messageFactory.createMessage();

    SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
    env.removeNamespaceDeclaration(env.getPrefix());
    env.setPrefix("s");
    env.addNamespaceDeclaration("a", NS_WS_ADDRESSING);
    env.addNamespaceDeclaration("w", NS_WS_MANAGEMENT);
    env.addNamespaceDeclaration("en", NS_WS_ENUMERATION);
    env.addNamespaceDeclaration("ev", NS_WS_EVENTING);

    QName mustUnderstand = new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "mustUnderstand", "s");

    SOAPHeader soapHeader = soapMessage.getSOAPHeader();
    soapHeader.setPrefix("s");

    SOAPHeaderElement toHeader =
        soapHeader.addHeaderElement(new QName(NS_WS_ADDRESSING, "To", "a"));
    toHeader.setValue(uri.toString());

    SOAPHeaderElement resourceURI =
        soapHeader.addHeaderElement(new QName(NS_WS_MANAGEMENT, "ResourceURI", "w"));
    resourceURI.addAttribute(mustUnderstand, "true");
    resourceURI.setValue(WSMAN_EVENTLOG_PREFIX);

    SOAPHeaderElement replyTo =
        soapHeader.addHeaderElement(new QName(NS_WS_ADDRESSING, "ReplyTo", "a"));

    SOAPElement addressElement =
        replyTo.addChildElement(new QName(NS_WS_ADDRESSING, "Address", "a"));
    addressElement.addAttribute(mustUnderstand, "true");
    addressElement.addTextNode("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous");

    SOAPElement actionElement =
        soapHeader.addChildElement(new QName(NS_WS_ADDRESSING, "Action", "a"));
    actionElement.addTextNode(EVENTING_SUBSCRIBE);

    // MaxEnvelopeSize
    SOAPElement maxEnvelopeSize =
        soapHeader.addChildElement(new QName(NS_WS_MANAGEMENT, "MaxEnvelopeSize", "w"));
    maxEnvelopeSize.addAttribute(mustUnderstand, "true");
    maxEnvelopeSize.addTextNode("51200");

    // Message ID
    SOAPElement messageId =
        soapHeader.addChildElement(new QName(NS_WS_ADDRESSING, "MessageID", "a"));
    messageId.addTextNode("uuid:" + UUID.randomUUID().toString());

    // Locale
    // SOAPElement locale = soapHeader.addChildElement(new
    // QName(NS_WS_MANAGEMENT, "Locale", "w"));
    // locale.addAttribute(mustUnderstand, "false");
    // locale.addAttribute(new QName("xml", "lang"), "en-US");

    SOAPElement operationTimeout =
        soapHeader.addChildElement(new QName(NS_WS_MANAGEMENT, "OperationTimeout", "w"));
    operationTimeout.addTextNode(String.format("PT%d.000S", timeout));

    SOAPBody soapBody = soapMessage.getSOAPBody();
    soapBody.setPrefix("s");

    SOAPElement enumerateElement =
        soapBody.addBodyElement(new QName(NS_WS_EVENTING, "Subscribe", "ev"));

    SOAPElement deliveryElement =
        enumerateElement.addChildElement(new QName(NS_WS_EVENTING, "Delivery", "ev"));
    deliveryElement.setAttribute("Mode", "http://schemas.dmtf.org/wbem/wsman/1/wsman/Pull");

    SOAPElement expiresElement =
        enumerateElement.addChildElement(new QName(NS_WS_EVENTING, "Expires", "ev"));
    // EXPIRE in 60 seconds - don't do this normally!
    expiresElement.addTextNode(String.format("PT%dS", new Date().getTime() + 500)); // "PT60S");

    // <ev:Expires>[xs:dateTime | xs:duration]</ev:Expires>
    SOAPElement filterElement =
        enumerateElement.addChildElement(new QName(NS_WS_MANAGEMENT, "Filter", "w"));
    filterElement.setAttribute("Dialect", DIALECT_EVENTQUERY);

    // Need to convert the XML snippet specified in the subscriptionQuery
    try {
      filterElement.addChildElement(new Util().xmlToSOAPElement(subscriptionQuery));
    } catch (ParserConfigurationException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (SAXException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    } catch (IOException e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }

    // Tell them to send bookmarks so we can catch up later if we get
    // disconnected
    enumerateElement.addChildElement(new QName(NS_WS_MANAGEMENT, "SendBookmarks", "w"));

    return soapMessage;
  }
Ejemplo n.º 17
0
  public SOAPMessage buildUnsubscribeMessage(
      URI uri, String enumerationContext, String subscriptionId, int maxElements, int timeout)
      throws SOAPException {
    MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage soapMessage = messageFactory.createMessage();

    SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
    env.removeNamespaceDeclaration(env.getPrefix());
    env.setPrefix("s");
    env.addNamespaceDeclaration("a", NS_WS_ADDRESSING);
    env.addNamespaceDeclaration("w", NS_WS_MANAGEMENT);
    env.addNamespaceDeclaration("en", NS_WS_ENUMERATION);
    env.addNamespaceDeclaration("ev", NS_WS_EVENTING);

    QName mustUnderstand = new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "mustUnderstand", "s");

    SOAPHeader soapHeader = soapMessage.getSOAPHeader();
    soapHeader.setPrefix("s");

    SOAPHeaderElement toHeader =
        soapHeader.addHeaderElement(new QName(NS_WS_ADDRESSING, "To", "a"));
    toHeader.setValue(uri.toString());

    SOAPHeaderElement resourceURI =
        soapHeader.addHeaderElement(new QName(NS_WS_MANAGEMENT, "ResourceURI", "w"));
    resourceURI.addAttribute(mustUnderstand, "true");
    resourceURI.setValue(WSMAN_EVENTLOG_PREFIX);

    SOAPHeaderElement replyTo =
        soapHeader.addHeaderElement(new QName(NS_WS_ADDRESSING, "ReplyTo", "a"));

    SOAPElement addressElement =
        replyTo.addChildElement(new QName(NS_WS_ADDRESSING, "Address", "a"));
    addressElement.addAttribute(mustUnderstand, "true");
    addressElement.addTextNode("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous");

    SOAPElement actionElement =
        soapHeader.addChildElement(new QName(NS_WS_ADDRESSING, "Action", "a"));
    actionElement.addTextNode(EVENTING_UNSUBSCRIBE);

    // MaxEnvelopeSize
    SOAPElement maxEnvelopeSize =
        soapHeader.addChildElement(new QName(NS_WS_MANAGEMENT, "MaxEnvelopeSize", "w"));
    maxEnvelopeSize.addAttribute(mustUnderstand, "true");
    maxEnvelopeSize.addTextNode("51200");

    // Message ID
    SOAPElement messageId =
        soapHeader.addChildElement(new QName(NS_WS_ADDRESSING, "MessageID", "a"));
    messageId.addTextNode("uuid:" + UUID.randomUUID().toString());

    SOAPElement operationTimeout =
        soapHeader.addChildElement(new QName(NS_WS_MANAGEMENT, "OperationTimeout", "w"));
    operationTimeout.addTextNode(String.format("PT%d.000S", timeout));

    SOAPElement hsubId = soapHeader.addChildElement(new QName(NS_WS_EVENTING, "Identifier", "ev"));
    hsubId.addTextNode(subscriptionId);

    SOAPBody soapBody = soapMessage.getSOAPBody();
    soapBody.setPrefix("s");

    soapBody.addChildElement(new QName(NS_WS_EVENTING, "Unsubscribe", "ev"));

    return soapMessage;
  }
Ejemplo n.º 18
0
  public SOAPMessage buildGetMessage(
      URI uri,
      String namespace,
      String className,
      Map<String, String> selectors,
      int maxElements,
      int timeout)
      throws TransformerException, SOAPException, IOException {
    MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
    SOAPMessage soapMessage = messageFactory.createMessage();

    SOAPEnvelope env = soapMessage.getSOAPPart().getEnvelope();
    env.removeNamespaceDeclaration(env.getPrefix());
    env.setPrefix("s");
    env.addNamespaceDeclaration("a", NS_WS_ADDRESSING);
    env.addNamespaceDeclaration("w", NS_WS_MANAGEMENT);

    QName mustUnderstand = new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "mustUnderstand", "s");

    SOAPHeader soapHeader = soapMessage.getSOAPHeader();
    soapHeader.setPrefix("s");

    SOAPHeaderElement toHeader =
        soapHeader.addHeaderElement(new QName(NS_WS_ADDRESSING, "To", "a"));
    toHeader.setValue(uri.toString());

    SOAPHeaderElement resourceURI =
        soapHeader.addHeaderElement(new QName(NS_WS_MANAGEMENT, "ResourceURI", "w"));
    resourceURI.addAttribute(mustUnderstand, "true");
    resourceURI.setValue(wmiClassUri("root/cimv2", className));

    SOAPHeaderElement replyTo =
        soapHeader.addHeaderElement(new QName(NS_WS_ADDRESSING, "ReplyTo", "a"));

    SOAPElement addressElement =
        replyTo.addChildElement(new QName(NS_WS_ADDRESSING, "Address", "a"));
    addressElement.addAttribute(mustUnderstand, "true");
    addressElement.addTextNode("http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous");

    SOAPElement actionElement =
        soapHeader.addChildElement(new QName(NS_WS_ADDRESSING, "Action", "a"));
    actionElement.addTextNode(TRANSFER_GET);

    // MaxEnvelopeSize
    // SOAPElement maxEnvelopeSize = soapHeader.addChildElement(new
    // QName(NS_WS_MANAGEMENT, "MaxEnvelopeSize", "w"));
    // maxEnvelopeSize.addAttribute(mustUnderstand, "true");
    // maxEnvelopeSize.addTextNode("153600");

    // Message ID
    SOAPElement messageId =
        soapHeader.addChildElement(new QName(NS_WS_ADDRESSING, "MessageID", "a"));
    messageId.addTextNode("uuid:" + UUID.randomUUID().toString());

    // Locale
    // SOAPElement locale = soapHeader.addChildElement(new
    // QName(NS_WS_MANAGEMENT, "Locale", "w"));
    // locale.addAttribute(mustUnderstand, "false");
    // locale.addAttribute(new QName("xml", "lang"), "en-US");

    SOAPElement selectorSet =
        soapHeader.addChildElement(new QName(NS_WS_MANAGEMENT, "SelectorSet", "w"));
    for (String key : selectors.keySet()) {
      SOAPElement selector =
          selectorSet.addChildElement(new QName(NS_WS_MANAGEMENT, "Selector", "w"));
      selector.setAttribute("Name", key);
      selector.addTextNode(selectors.get(key));
    }

    // <w:OperationTimeout>PT60.000S</w:OperationTimeout>
    SOAPElement operationTimeout =
        soapHeader.addChildElement(new QName(NS_WS_MANAGEMENT, "OperationTimeout", "w"));
    operationTimeout.addTextNode(String.format("PT%d.000S", timeout));

    // SOAPElement fragmentTransfer = soapHeader.addChildElement(new
    // QName(NS_WS_MANAGEMENT, "FragmentTransfer", "w"));
    // fragmentTransfer.addAttribute(mustUnderstand, "true");
    // fragmentTransfer.addTextNode("FreeSpace");

    SOAPBody soapBody = soapMessage.getSOAPBody();
    soapBody.setPrefix("s");

    return soapMessage;
  }
Ejemplo n.º 19
0
  @Validated
  @Test
  public void testHeaders() {
    try {
      // Create message factory and SOAP factory
      MessageFactory messageFactory = MessageFactory.newInstance();
      SOAPFactory soapFactory = SOAPFactory.newInstance();

      // Create a message
      SOAPMessage message = messageFactory.createMessage();

      // Get the SOAP header from the message and
      //  add headers to it
      SOAPHeader header = message.getSOAPHeader();

      String nameSpace = "ns";
      String nameSpaceURI = "http://gizmos.com/NSURI";

      Name order = soapFactory.createName("orderDesk", nameSpace, nameSpaceURI);
      SOAPHeaderElement orderHeader = header.addHeaderElement(order);
      orderHeader.setActor("http://gizmos.com/orders");

      Name shipping = soapFactory.createName("shippingDesk", nameSpace, nameSpaceURI);
      SOAPHeaderElement shippingHeader = header.addHeaderElement(shipping);
      shippingHeader.setActor("http://gizmos.com/shipping");

      Name confirmation = soapFactory.createName("confirmationDesk", nameSpace, nameSpaceURI);
      SOAPHeaderElement confirmationHeader = header.addHeaderElement(confirmation);
      confirmationHeader.setActor("http://gizmos.com/confirmations");

      Name billing = soapFactory.createName("billingDesk", nameSpace, nameSpaceURI);
      SOAPHeaderElement billingHeader = header.addHeaderElement(billing);
      billingHeader.setActor("http://gizmos.com/billing");

      // Add header with mustUnderstand attribute
      Name tName = soapFactory.createName("Transaction", "t", "http://gizmos.com/orders");

      SOAPHeaderElement transaction = header.addHeaderElement(tName);
      transaction.setMustUnderstand(true);
      transaction.addTextNode("5");

      // Get the SOAP body from the message but leave
      // it empty
      SOAPBody body = message.getSOAPBody();

      message.saveChanges();

      // Display the message that would be sent
      // System.out.println("\n----- Request Message ----\n");
      // message.writeTo(System.out);

      // Look at the headers
      Iterator allHeaders = header.examineAllHeaderElements();

      while (allHeaders.hasNext()) {
        SOAPHeaderElement headerElement = (SOAPHeaderElement) allHeaders.next();
        Name headerName = headerElement.getElementName();
        // System.out.println("\nHeader name is " +
        //                   headerName.getQualifiedName());
        // System.out.println("Actor is " + headerElement.getActor());
        // System.out.println("mustUnderstand is " +
        //                   headerElement.getMustUnderstand());
      }
    } catch (Exception e) {
      fail("Enexpected Exception " + e);
    }
  }
  /**
   * Create an STS client, create dispatch Invoke dispatch, return response
   *
   * @param args
   * @return
   * @throws SOAPException
   * @throws IOException
   * @throws SAXException
   * @throws ParserConfigurationException
   */
  public static String Go(
      String CSR,
      String SAN,
      String TemplateName,
      String CertFormat,
      String MEXuRI,
      String ValidUnit,
      String ValidValue,
      String OU1,
      String OU2,
      String OU3,
      String OU4,
      String OU5,
      String dnEmail)
      throws SOAPException, IOException, ParserConfigurationException, SAXException {

    MetadataClient mexClient = new MetadataClient();

    // the MEX URI is the service URL +/MEX
    Metadata metadata = mexClient.retrieveMetadata(MEXuRI + "/MEX");
    metadata.getOtherAttributes();

    QName serviceInfo = null;
    QName portName = null;
    String Address = null;
    // String namespace = null;

    List<PortInfo> ports = mexClient.getServiceInformation(metadata);
    for (PortInfo port : ports) {

      serviceInfo = port.getServiceName();
      portName = port.getPortName();
      Address = port.getAddress();
      // namespace = port.getPortNamespaceURI();

    }

    // an instance of SecurityTokenService
    Service STSS = Service.create(new URL(MEXuRI), serviceInfo);

    // a dispatch of SOAPMessage
    Dispatch<SOAPMessage> dispatch =
        STSS.createDispatch(portName, SOAPMessage.class, Service.Mode.MESSAGE);

    // Message factor instance of SOAP 1.2 protcol
    MessageFactory factory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);

    // Create SOAPMessage Request
    SOAPMessage request = factory.createMessage();

    // Request Header
    SOAPHeader header = request.getSOAPHeader();

    // Soap Factory
    SOAPFactory factory1 = SOAPFactory.newInstance();

    // Enable WS-Addressing and Add the "To:" endpoint
    SOAPElement To = factory1.createElement("To", "", "http://www.w3.org/2005/08/addressing");
    To.addTextNode(Address);

    // add the Microsoft MS-STEP Action Element:
    SOAPElement ActionElem =
        factory1.createElement("Action", "", "http://www.w3.org/2005/08/addressing");
    ActionElem.addTextNode("http://schemas.microsoft.com/windows/pki/2009/01/enrollment/RST/wstep");

    // Add a unique message ID "UUID"
    SOAPElement MessageID =
        factory1.createElement("MessageID", "", "http://www.w3.org/2005/08/addressing");
    MessageID.addTextNode("uuid:" + UUID.randomUUID());

    // add all the required SOAP header items:
    header.addChildElement(To);
    header.addChildElement(ActionElem);
    header.addChildElement(MessageID);

    // create a "Request Body" to hold request elements:
    SOAPBody body = request.getSOAPBody();

    // Compose the soap:Body payload "RequestSecurityToken" as the body type
    QName payloadName =
        new QName("http://docs.oasis-open.org/ws-sx/ws-trust/200512", "RequestSecurityToken", "");
    SOAPBodyElement payload = body.addBodyElement(payloadName);

    // Add the WS-Trust TokenType and RequestType elements:
    payload
        .addChildElement("TokenType")
        .addTextNode(
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-x509-token-profile-1.0#X509v3");
    payload
        .addChildElement("RequestType")
        .addTextNode("http://docs.oasis-open.org/ws-sx/ws-trust/200512/Issue");

    // add the BinarySecurityToken type
    SOAPElement BinarySecurityToken =
        factory1.createElement(
            "BinarySecurityToken",
            "",
            "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd");

    // set BinarySecurityToken type as PKCS10 also known as a CSR..
    BinarySecurityToken.setAttribute(
        "ValueType", "http://schemas.microsoft.com/windows/pki/2009/01/enrollment#PKCS10");

    // Set the EncodingType to base64binary"
    BinarySecurityToken.setAttribute(
        "EncodingType",
        "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd#base64binary");

    // add the WSS wssSecurity namespace:
    BinarySecurityToken.addNamespaceDeclaration(
        "a", "http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd");

    // The CSR is Base64 encoded PKCS10 CSR without the "Begin" and "End" tags
    // add the CSR as a "TextNode"
    BinarySecurityToken.addTextNode(CSR);

    // add the BinarySecurityToken element to Soap pay load
    payload.addChildElement(BinarySecurityToken);

    // Create "AdditionalContext" Element for additional context items such as policy file name,
    // etc..
    QName AdditionalContextName =
        new QName("http://schemas.xmlsoap.org/ws/2006/12/authorization", "AdditionalContext", "");
    SOAPBodyElement AdditionalContext = body.addBodyElement(AdditionalContextName);

    // Create a ContextItem to specify the CertificateTemplate name, get
    // element from "TemplateName" argument
    SOAPElement ContextItem1 = AdditionalContext.addChildElement("ContextItem");
    ContextItem1.setAttribute("Name", "CertificateTemplate");
    SOAPElement Value = AdditionalContext.addChildElement("Value");
    Value.setTextContent(TemplateName);
    ContextItem1.addChildElement(Value);

    // Create a ContextItem to specify the value of "Other" context item
    // element from "TemplateName" argument
    SOAPElement ContextItem2 = AdditionalContext.addChildElement("ContextItem");
    ContextItem2.setAttribute("Name", "OU1");
    SOAPElement Value2 = AdditionalContext.addChildElement("Value");
    Value2.setTextContent(OU1);
    ContextItem2.addChildElement(Value2);

    // Create a ContextItem to specify the rmd (remote server) name
    SOAPElement ContextItem3 = AdditionalContext.addChildElement("ContextItem");
    ContextItem3.setAttribute("Name", "rmd");
    SOAPElement Value3 = AdditionalContext.addChildElement("Value");
    // Get application server FQDNS hostname
    InetAddress addr = InetAddress.getLocalHost();
    Value3.setTextContent(addr.getCanonicalHostName());
    ContextItem3.addChildElement(Value3);

    // Request specific validity period:

    // to enable client side to set validity period you must enable:
    // certutil -setreg Policy\EditFlags + EDITF_ATTRIBUTEENDDATE
    // on the CA!
    // Create a ContextItem to specify the rmd (remote server) name
    SOAPElement ContextItem4 = AdditionalContext.addChildElement("ContextItem");
    ContextItem4.setAttribute("Name", "ValidityPeriod");
    SOAPElement Value4 = AdditionalContext.addChildElement("Value");
    // Units can be "Seconds", "Minutes", "Hours", "Days", "Weeks", "Months", "Years"
    Value4.setTextContent(ValidUnit);
    ContextItem4.addChildElement(Value4);

    // Create a ContextItem to specify the rmd (remote server) name
    SOAPElement ContextItem5 = AdditionalContext.addChildElement("ContextItem");
    ContextItem5.setAttribute("Name", "ValidityPeriodUnits");
    SOAPElement Value5 = AdditionalContext.addChildElement("Value");
    Value5.setTextContent(ValidValue);
    ContextItem5.addChildElement(Value5);

    // Create a ContextItem to specify the value of "Other" context item
    // element from "TemplateName" argument
    SOAPElement ContextItem7 = AdditionalContext.addChildElement("ContextItem");
    ContextItem7.setAttribute("Name", "OU2");
    SOAPElement Value7 = AdditionalContext.addChildElement("Value");
    Value7.setTextContent(OU2);
    ContextItem7.addChildElement(Value7);

    // Create a ContextItem to specify the value of "Other" context item
    // element from "TemplateName" argument
    SOAPElement ContextItem8 = AdditionalContext.addChildElement("ContextItem");
    ContextItem8.setAttribute("Name", "OU3");
    SOAPElement Value8 = AdditionalContext.addChildElement("Value");
    Value8.setTextContent(OU3);
    ContextItem8.addChildElement(Value8);

    // Create a ContextItem to specify the value of "Other" context item
    // element from "TemplateName" argument
    SOAPElement ContextItem9 = AdditionalContext.addChildElement("ContextItem");
    ContextItem9.setAttribute("Name", "OU4");
    SOAPElement Value9 = AdditionalContext.addChildElement("Value");
    Value9.setTextContent(OU4);
    ContextItem9.addChildElement(Value9);

    // Create a ContextItem to specify the value of "Other" context item
    // element from "TemplateName" argument
    SOAPElement ContextItem10 = AdditionalContext.addChildElement("ContextItem");
    ContextItem10.setAttribute("Name", "OU5");
    SOAPElement Value10 = AdditionalContext.addChildElement("Value");
    Value10.setTextContent(OU5);
    ContextItem10.addChildElement(Value10);

    // KeyUsage=0xa0
    // SOAPElement ContextItem15 = AdditionalContext.addChildElement("ContextItem");
    // ContextItem15.setAttribute("Name", "CertificateUsage");
    // SOAPElement Value15 = AdditionalContext.addChildElement("Value");
    // Value15.setTextContent("1.3.6.1.5.5.7.3.1,1.3.6.1.5.5.7.3.2");
    // ContextItem15.addChildElement(Value15);

    // TODO:
    // let's try this an see what it does:
    // CertificateUsage

    // alternatively we can specify a specific end date:
    // ExpirationDate = L"Tue, 21 Nov 2000 01:06:53 GMT"

    // add the ContextItem child to the soap payload:
    AdditionalContext.addChildElement(ContextItem1);

    // TODO: document this, rename the context items
    AdditionalContext.addChildElement(ContextItem2);
    AdditionalContext.addChildElement(ContextItem3);
    // AdditionalContext.addChildElement(ContextItem4);
    // AdditionalContext.addChildElement(ContextItem5);
    AdditionalContext.addChildElement(ContextItem7);
    AdditionalContext.addChildElement(ContextItem8);
    AdditionalContext.addChildElement(ContextItem9);
    AdditionalContext.addChildElement(ContextItem10);
    // AdditionalContext.addChildElement(ContextItem15);

    // Create a ContextItem to specify the value of "Other" context item
    // element from "TemplateName" argument
    if (dnEmail != null) {
      SOAPElement ContextItem11 = AdditionalContext.addChildElement("ContextItem");
      ContextItem11.setAttribute("Name", "dnEmail");
      SOAPElement Value11 = AdditionalContext.addChildElement("Value");
      Value11.setTextContent(dnEmail);
      ContextItem11.addChildElement(Value11);
      AdditionalContext.addChildElement(ContextItem11);
    }

    // if SAN extention is specified add the ContextItem
    if (SAN != null) {
      // Create a ContextItem to specify the rmd (remote server) name
      SOAPElement ContextItem6 = AdditionalContext.addChildElement("ContextItem");
      ContextItem6.setAttribute("Name", "SAN");
      SOAPElement Value6 = AdditionalContext.addChildElement("Value");
      Value6.setTextContent(SAN);
      ContextItem6.addChildElement(Value6);
      AdditionalContext.addChildElement(ContextItem6);
    }

    payload.addChildElement(AdditionalContext);

    // place holder for RequestSecurityToken response soap message
    SOAPMessage reply = null;

    // Invoke the end point operation synchronously
    try {
      // and read response
      reply = dispatch.invoke(request);
    } catch (WebServiceException wse) {
      wse.printStackTrace();
    }

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    reply.writeTo(baos);

    // to view the reply via STD-Out:
    // System.out.println(baos);
    StringBuffer ressponseSB = new StringBuffer();
    String resonseS = baos.toString();

    ressponseSB.append(resonseS);
    StringBuilder sBuilder = RequestTokenResponseParser.ParseResponse(ressponseSB, CertFormat);

    String Certs = sBuilder.toString();

    return Certs;
  }