0

I am pretty new to SOAP and i am struggling to create a SOAP POST request to a server . I have the following sample request:-

POST /sso/ArtifactResolver/metaAlias/assert-idp
HTTP/1.1
Host:xxx
Content-Type: text/xml
Content-Length: 
SOAPAction:http://....

and here is my SOAP Envevelop

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Body>
<samlp:ArtifactResolve
xmlns:samlp="xxxxxxxxxxxxxx"
xmlns="xxxxxxxxxxx"
ID="_6c3a4f8b9c2d"
25 March 2014 Page 30
(APPROVED – Version 1.1)
Version="2.0"
IssueInstant="2012-05-21T00:39:45Z">
<Issuer>https://www.xxxxxxxxxxxxxx</Issuer>
<Artifact>
AAQAABWFTOPhANZhf21nl9DmXsAkiSM0ocx7GdxUfXFttmS954 BP6Vb01I0=
</Artifact>
</samlp:ArtifactResolve>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Below is my java code i am trying to use:-

    MessageFactory factory = MessageFactory.newInstance();
    SOAPMessage soapMsg = factory.createMessage();
    SOAPPart part = soapMsg.getSOAPPart();
    SOAPEnvelope envelope = part.getEnvelope();
    SOAPHeader header = envelope.getHeader();
    SOAPBody body = envelope.getBody();


    SOAPBodyElement element = body.addBodyElement(envelope.createName("ArtifactResolve", "sampl", "xxxxxxxxxxxx"));
    element.addChildElement("Issuer").addTextNode("xxxxxxxxxxx");
    element.addChildElement("Artifact").addTextNode("xxxxxxxxxxxx");
    element.setAttribute("xmlns", "xxxxxxxxxxxxx");
    element.setAttribute("ID", "xxxxxxxxx");
    element.setAttribute("Version", "2.0");
    element.setAttribute("IssueInstant", "xxxxxxxxxx"); 

 PostMethod post = new PostMethod("PUT Server Url");
            // Request content will be retrieved directly from the input stream

            post.setRequestEntity(entity);
            // consult documentation for your web service
            post.setRequestHeader("SOAPAction", "**what to put here????**");
            // Get HTTP client
            HttpClient httpclient = new HttpClient();

            try {
                int result = httpclient.executeMethod(post);
                System.out.println(post.getResponseBodyAsString());
            } finally {
                // Release current connection to the connection pool once you are done
                post.releaseConnection();
            }

Now in the above code where to specify the Server url? Second is how to pass complete soap XML to post request? How to pass the top POST data which is given? What to give for soap action.?

Sorry for this guys buy i am completely new to this so no idea. I tried looking for this over the internet but no help.

Please help me out over here

Thanks ...

Vishesh
  • 3,599
  • 4
  • 22
  • 36
  • URL endpoint goes in `new PostMethod("xxx")` as suggested in your sample. The request is built with `SOAPBodyElement element = body... `. SOAP action is described in your WSDL into the binding. I suggest you to check this SO post http://stackoverflow.com/questions/19291283/soap-request-to-webservice-with-java – Anthony Corrado Nov 04 '15 at 22:05
  • thanks for replying Anthony Corrado but i dont have a web service url – Vishesh Nov 04 '15 at 22:06

2 Answers2

1

URL endpoint goes in new PostMethod("xxx") as suggested in your sample.

The request is built with SOAPBodyElement element = body....

SOAP action is described in your WSDL into the binding.

I suggest you to check this SO post SOAP request to WebService with java

Community
  • 1
  • 1
  • One doubt i have in the example you gave ... // Send SOAP Message to SOAP Server String url = "http://ws.cdyne.com/emailverify/Emailvernotestemail.asmx"; SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(), url); What is this url ??????? Second while creating the SOAP Message String serverURI = "http://ws.cdyne.com/"; // SOAP Envelope SOAPEnvelope envelope = soapPart.getEnvelope(); envelope.addNamespaceDeclaration("example", serverURI); what is this URI??? – Vishesh Nov 04 '15 at 22:19
0

Please refer this URL - http://svn.apache.org/repos/asf/httpcomponents/oac.hc3x/trunk/src/examples/PostSOAP.java

This is a very concrete example and I tested it fully working.

Now in the above code where to specify the Server url? - You can pass it as a command line argument, or hardcode in the client code.

Second is how to pass complete soap XML to post request? - The example is accepting the XML from a file that is passed as the third argument. Alternately you can hardcode the XML within the client code.

What to give for soap action.? Please check the WSDL file for the SOAPAction. It will be listed against each method. Please note that in the URL you are not putting any method name, you are putting just the service URL. So if there are many methods, how to distinguish them? By this SOAPAction. If there is any method like "multiply", then SOAPAction will be "urn:multiply".

Hope this helps.

Nirmalya
  • 398
  • 5
  • 19