Calling SOAP service returns a 500 error when using marshalSendAndReceive

Viewed 46

I am using Spring Boot and Java 11.

I am trying to write a SOP client to invoke the following web service. The service provider has provided a tool to test the it, and from here you can see it is working as expected.

enter image description here

Results - returns a 200:

enter image description here

enter image description here

I use the provided WSDL to generate the stubs successfully, and then write the following Java Client using the generated ObjectFactory:

String PROCON_SOAP_ACCESS_URL = "http://********/ProCONWS/WebService_PCSOrderEntry.asmx";

public CalculateMD5Response calculateMD5(final String userName) {
    String msg = null;
    String parameters = null;
    try {
        // request
        ObjectFactory objectFactory = new ObjectFactory();
        CalculateMD5 request = objectFactory.createCalculateMD5();
        request.setUser("pcscord");
        request.setTimestamp(DateUtil.dateToString(new Date(), "yyyyMMdd HHmmss"));
        request.setSecretWord("********");
        parameters = URLEncoder.encode("user="+request.getUser()+"&timestamp="+request.getTimestamp()+"&Secret_word="+request.getSecretWord(), "UTF-8");

        PROCON_SOAP_ACCESS_URL = PROCON_SOAP_ACCESS_URL + "/calculate_MD5";//?"+parameters;

        // call the SOAP service
        logger.info("About to call Procon SOAP Service: " + PROCON_SOAP_ACCESS_URL + ".");
        JAXBElement<String> jaxbElementPayload = objectFactory.createString(parameters);
        Object response = getWebServiceTemplate().marshalSendAndReceive(PROCON_SOAP_ACCESS_URL, jaxbElementPayload);
        logger.info("Called Procon SOAP service. Response: " + response);
    } catch (Exception e) {
        msg = "FAILURE: There was an error calling the Procon SOAP service. Exception: "+e.getMessage()+". URL: "+PROCON_SOAP_ACCESS_URL+" and PARAMETERS: "+parameters+".";
        logger.error(msg);
    }
    return null;
}

This however returns a 500 error:

Internal Server Error [500]

As far as I understand, the getWebServiceTemplate().marshalSendAndReceive should perform a SOAP POST request with the given URL and payload.

Am I using the generated stubs incorrectly? Is the URLEncoder.encode incorrectly formatting the payload? Any feedback appreciated.

1 Answers

Check names of elements. It's possible add @XmlRootElement("<ElementName>").

Related