Java Spring Boot:如何访问本地 WSDL 而不是公共 WSDL URL?

发布于 2025-01-17 01:19:02 字数 2534 浏览 0 评论 0原文

我一直在使用公共 WSDL URL 来呼叫我们的客户。现在,客户决定隐藏公共 WSDL URL,并且要求我使用需要部署在我自己的服务器上的本地 WSDL。

我正在使用 Java Spring Boot,这是我之前调用公共 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()); 
            }

....

我现在应该如何用本地 wsdl 替换“soapURL”(marshalSendAndReceive 中使用的公共 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

感性 2025-01-24 01:19:02

我使用 wsd2ljava 在 eclipse 中生成源代码,如下所示。

             <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 类已创建。生成所有类后下一步是什么?我应该创建 CXF 客户端配置吗?

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?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文