Search code examples
javasoapapache-axis

How to invoke apache axis soap services?


I need to create a client for some legacy soap services. I use java and preferably I would create a project with with proper rest endpoints that proxy request/response to this archaic sopa service. I have a wsdl url but it has use="encoded" which means I guess it uses rpc style and it has not been supported by any framework for a long time. I believe I need to use apache axis 1 to call this service. Most posts Ive seen are from ~2012 and even back then those old posts said rpc soap services are extremely deprecated. I dont have any option to update the remote wsdl and I need to call these services. I think anyone at my company who ever knew what it does or how it works is long gone. I was able to generate some code off the wsdl after a lot of trial and error and I have these classes now:

enter image description here

I have no idea how to invoke these classes and documentation online is all dead ends. Please save me. I assume I would need to use one of these classes and enter a url, then I need to invoke one of the rpc functions and pass some payload. Was expecting to have some stongly typed DTO classes generated but I can pass a string of XML I guess if I have to.

Any help or links to working code samples would be hugely appreciated!


Solution

  • You should try something like this :

    import org.springframework.web.bind.annotation.GetMapping;
    import org.springframework.web.bind.annotation.RequestParam;
    import org.springframework.web.bind.annotation.RestController;
    
    @RestController
    public class SoapProxyController {
    
        @GetMapping("/soap-endpoint")
        public String proxyRequest(@RequestParam String param1, @RequestParam String param2) {
            try {
                EntitiesWebServiceBrokerLocator locator = new EntitiesWebServiceBrokerLocator();
                EntitiesWebServiceBrokerPortSoapBindingStub stub = (EntitiesWebServiceBrokerPortSoapBindingStub) locator.getYourServicePort();
                // Set the endpoint URL if necessary
                stub._setProperty(EntitiesWebServiceBrokerPortSoapBindingStub.ENDPOINT_ADDRESS_PROPERTY, "url-to-be-fille");
    
                // Call the SOAP method
                String response = stub.yourSoapMethod(param1, param2);
                return response;
            } catch (Exception e) {
                e.printStackTrace();
                return "Error: " + e.getMessage();
            }