Java SOAP Message createSOAPRequestForPartnerCategories( String userId)

Here you can find the source of createSOAPRequestForPartnerCategories( String userId)

Description

create SOAP Request For Partner Categories

License

LGPL

Declaration

private static SOAPMessage createSOAPRequestForPartnerCategories(
            String userId) throws Exception 

Method Source Code

//package com.java2s;
//License from project: LGPL 

import java.io.ByteArrayOutputStream;

import javax.xml.soap.MessageFactory;
import javax.xml.soap.MimeHeaders;
import javax.xml.soap.SOAPBody;

import javax.xml.soap.SOAPElement;
import javax.xml.soap.SOAPEnvelope;

import javax.xml.soap.SOAPMessage;
import javax.xml.soap.SOAPPart;

public class Main {
    private static SOAPMessage createSOAPRequestForPartnerCategories(
            String userId) throws Exception {
        MessageFactory messageFactory = MessageFactory.newInstance();
        SOAPMessage soapMessage = messageFactory.createMessage();
        SOAPPart soapPart = soapMessage.getSOAPPart();

        String serverURI = "http://service.entitlement.siemens.com";

        // SOAP Envelope
        SOAPEnvelope envelope = soapPart.getEnvelope();
        envelope.addNamespaceDeclaration("ser", serverURI);
        envelope.addNamespaceDeclaration("xsi",
                "http://www.w3.org/2001/XMLSchema-instance");

        // SOAP Body
        //<ser:getCompanyByUserId soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/">
        //<request xsi:type="urn:CompanyByUserIdRequest" xmlns:urn="urn:model.service.entitlement.siemens.com">
        SOAPBody soapBody = envelope.getBody();
        SOAPElement soapBodyElem = soapBody.addChildElement(
                "getCompanyByUserId", "ser");
        soapBodyElem/* w  w w.j av a2  s . c o m*/
                .setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding");

        SOAPElement soapBodyElem0 = soapBodyElem.addChildElement("request");
        soapBodyElem0
                .setAttribute("xsi:type", "urn:CompanyByUserIdRequest");
        soapBodyElem0.setAttribute("xmlns:urn",
                "urn:model.service.entitlement.siemens.com");

        SOAPElement soapBodyElem1 = soapBodyElem0
                .addChildElement("applicationId");

        soapBodyElem1.addTextNode("bolayer");
        soapBodyElem1
                .setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding");
        SOAPElement soapBodyElem2 = soapBodyElem0.addChildElement("userId");
        soapBodyElem2.addTextNode(userId);
        soapBodyElem2
                .setEncodingStyle("http://schemas.xmlsoap.org/soap/encoding");

        MimeHeaders headers = soapMessage.getMimeHeaders();
        headers.addHeader("SOAPAction", serverURI
                + "CompanyByUserIdRequest");
        ByteArrayOutputStream os = new ByteArrayOutputStream();
        //soapMessage.writeTo(os);

        soapMessage.saveChanges();

        return soapMessage;
    }
}

Related

  1. createAttachmentPart(String cid, DataHandler dh, SOAPMessage message)
  2. createDoc(SOAPMessage soapMsg)
  3. createException(String code, String message)
  4. createFault(String message)
  5. createSOAPFault(SOAPFault fault, Throwable cause)
  6. ensureNamespaceDeclared(SOAPElement elem, String namespaceURI, String prefix)
  7. ensureNamespaceDeclared(SOAPElement element, String prefix, String nsURI)
  8. extractXMLPayloadFromSOAPMessage(SOAPMessage messageSOAP)
  9. getAttachmentContentType(SOAPMessage message)