Exception thrown when using Java Generic SOAPClient (SAAJ)?
===

I’m trying to use the following SOAPClient for Java (details which I’ve obtained from the following tutorial http://users.skynet.be/pascalbotte/rcx-ws-doc/saajpost.htm).

However, it seems to be throwing an exception.

Here is my code:

    javax.xml.soap.SOAPMessage msg;
    MessageFactory mf = MessageFactory.newInstance();
    msg = mf.createMessage();
    SOAPPart part = msg.getSOAPPart();
    StreamSource source = new StreamSource(new File("samples/input1.xml”));
    part.setContent(source);
    msg.saveChanges();
    
    String endpoint = "http://ws1.parasoft.com/glue/calculator";
    
    SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
    SOAPConnection conn = scf.createConnection();
    javax.xml.soap.SOAPMessage response = conn.call(msg, endpoint);
    TransformerFactory tff = TransformerFactory.newInstance();
    Transformer tf = tff.newTransformer();
    Source sc = response.getSOAPPart().getContent();
    ByteArrayOutputStream ostream = new ByteArrayOutputStream(); 
    StreamResult result = new StreamResult(ostream);
    tf.transform(sc, result);
    conn.close();
    
    System.out.println(new String(ostream.toByteArray(), "UTF-8”));

In this example, we assume `samples/input1.xml` holds the following:

    <s11:Envelope xmlns:s11="http://schemas.xmlsoap.org/soap/envelope/">
       <s11:Body>
          <ns1:add xmlns:ns1="http://www.parasoft.com/wsdl/calculator/">
             <ns1:x>248</ns1:x>
             <ns1:y>365</ns1:y>
          </ns1:add>
       </s11:Body>
    </s11:Envelope>

The sample web-service that I’m trying to use can be found here:
http://www.service-repository.com/client/operations

When running the above Java-code (using the SOAPClient library), the following exception is thrown:

    Jul 19, 2012 3:50:11 AM com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection post
    SEVERE: SAAJ0008: Bad Response; cannot find /calculator
    Exception in thread "main" com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (404cannot find /calculator
    	at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:148)
    	at corebus.test.deprecated.TestMain.main(TestMain.java:1870)
    Caused by: com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (404cannot find /calculator
    	at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:258)
    	at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:144)
    	... 1 more
    
    CAUSE:
    
    com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Bad response: (404cannot find /calculator
    	at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.post(HttpSOAPConnection.java:258)
    	at com.sun.xml.internal.messaging.saaj.client.p2p.HttpSOAPConnection.call(HttpSOAPConnection.java:144)

Using this web-site, it seems the services is up and running, and working well.

I have even verified the service-endpoint is active, by conducted a simple cURL request, which surprisingly produces the correct output.

    curl -H "Content-Type: text/xml; charset=utf-8" -H "SOAPAction:http://www.parasoft.com/wsdl/calculator/" -d@soap-request.xml http://ws1.parasoft.com/glue/calculator

The output produced is:

    <soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xmlns:xsd='http://www.w3.org/2001/XMLSchema' xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/‘>
        <soap:Body>
            <n:addResponse xmlns:n='http://www.parasoft.com/wsdl/calculator/‘>
                <n:Result xsi:type='xsd:float'>613.0</n:Result>
            </n:addResponse>
        </soap:Body>
    </soap:Envelope>

So, my question is: Firstly, what is wrong with the Java-code? And how could it be fixed? Or also, is there any other better/more-reliable Generic SOAPClient Library that would be recommended? 