简体   繁体   中英

Calling SOAP service returns a 500 error when using marshalSendAndReceive

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.

在此处输入图像描述

Results - returns a 200:

在此处输入图像描述

在此处输入图像描述

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM