'Java Spring Boot: How to access local WSDL instead of a Public WSDL URL?

I have been using a public WSDL URL to make a call to our customer. Now the customer decided to hide the public WSDL URL and I have been asked to use a local WSDL that I need to deploy on my own server.

I'm using Java Spring Boot and here's my previous code to call the public WSDL URL:

    try { 
            SaajSoapMessageFactory messageFactory= new SaajSoapMessageFactory(MessageFactory.newInstance());
            messageFactory.afterPropertiesSet();
            WebServiceTemplate webServiceTemplate = new WebServiceTemplate( messageFactory);
            Jaxb2Marshaller marshaller = new Jaxb2Marshaller(); 
            marshaller.setContextPath(appConfig.SOAP_PKG);  
            marshaller.afterPropertiesSet(); 
            webServiceTemplate.setMarshaller(marshaller);
            webServiceTemplate.setUnmarshaller(marshaller);
            webServiceTemplate.afterPropertiesSet();  
            WebServiceMessageSender messageSender = this.webServiceMessageSender();  
            webServiceTemplate.setMessageSender(messageSender);  
            try { 
                response = webServiceTemplate.marshalSendAndReceive(soapURL, request, new WebServiceMessageCallback() {
                     
                    @Override
                    public void doWithMessage(WebServiceMessage message) {
                        try {
                            SoapHeader soapHeader = ((SoapMessage) message).getSoapHeader();
                            Map mapRequest = new HashMap(); 
                            mapRequest.put("loginuser", soapUsername);
                            mapRequest.put("loginpass", soapPassword); 
 
                            StrSubstitutor substitutor = new StrSubstitutor(mapRequest, "%(", ")");
                            String finalXMLRequest = substitutor.replace(appConfig.SOAP_HEADER); 
                            StringSource headerSource = new StringSource(finalXMLRequest);  
                            Transformer transformer = TransformerFactory.newInstance().newTransformer();
                            transformer.transform(headerSource, soapHeader.getResult());   
                            
                            
                        } catch (Exception e) {
                            logger.error("Error while invoking session service :", e.getMessage() );  
                        }
                    }
                });
            }catch (SoapFaultClientException e){
                logger.error("Error while invoking session service : " + e.getMessage()); 
            }

....

How am I supposed now to replace "soapURL" which is the public WSDL URL used in marshalSendAndReceive with the local wsdl?



Solution 1:[1]

I used wsd2ljava to generate the sources in eclipse as shown below.

             <plugin>
                <groupId>org.apache.cxf</groupId>
                <artifactId>cxf-codegen-plugin</artifactId>
                <version>3.1.12</version>
                <executions>
                    <execution>
                        <id>generate-sources</id>
                        <phase>generate-sources</phase>
                        <configuration>
                            <sourceRoot>${project.build.directory}/generated/cxf</sourceRoot>
                            <wsdlOptions>
                                <wsdlOption>
                                    <wsdl>${basedir}/src/main/resources/wsdl/XXX.wsdl</wsdl>
                                    <wsdlLocation>classpath:wsdl/XXX.wsdl</wsdlLocation>
                                </wsdlOption>
                            </wsdlOptions>
                            <fork>always</fork>
                        </configuration>
                        <goals>
                            <goal>wsdl2java</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>

Java classes have been created. What is the next step after generating all the classes? Shall I create a CXF client configuration?

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Guan