- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我对 Spring 框架非常陌生,我在使用 Spring 创建一个简单的 SOAP 客户端时遇到了一些问题。
像一个优秀的新手一样,我使用 Spring 教程来制作我的 SOAP 客户端。你可以在这里找到它-> https://spring.io/guides/gs/consuming-web-service/
使用示例中给出的 Web 服务进行的测试是可以的。我已更改代码以使其与我的 Web 服务一起使用,所以这是文件:
SetCodePinConfigurartion.java
package hello;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;
@Configuration
public class SetPinCodeConfiguration {
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
// this package must match the package in the <generatePackage> specified in
// pom.xml
marshaller.setContextPath("hello.wsdl");
return marshaller;
}
@Bean
public SetPinCodeClient SetPinCodeClient(Jaxb2Marshaller marshaller) {
SetPinCodeClient client = new SetPinCodeClient();
client.setDefaultUri("http://xxx.xxx.xx.x/PlayerServices/PlayerIntelligence/PlayerManagementService");
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
return client;
}
}
package hello;
import javax.xml.bind.JAXBElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.client.core.SoapActionCallback;
import hello.wsdl.SetPinCode;
import hello.wsdl.SetPinCodeResponse;
public class SetPinCodeClient extends WebServiceGatewaySupport{
private static final Logger log = LoggerFactory.getLogger(SetPinCodeClient.class);
public SetPinCodeResponse SetPinCode(JAXBElement<String> pinCode, JAXBElement<String> cardNumber, JAXBElement<Integer> casinoCreationId) {
SetPinCode request = new SetPinCode();
request.setPinCode(pinCode);
request.setCardNumber(cardNumber);
request.setCasinoCreationId(casinoCreationId);
log.info("Requesting save in database for card " + cardNumber + "with pin code" + pinCode + "from casino n°" + casinoCreationId);
SetPinCodeResponse response = (SetPinCodeResponse) getWebServiceTemplate()
.marshalSendAndReceive("http://xxx.xxx.xx.x/PlayerServices/PlayerIntelligence/PlayerManagementService",
request,
new SoapActionCallback("http://xxx.xxx.xx.x/PlayerServices/PlayerIntelligence/PlayerManagementService/SetPinCode"));
return response;
}
}
package hello;
import javax.xml.bind.JAXBElement;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import hello.wsdl.ObjectFactory;
import hello.wsdl.SetPinCodeResponse;
@SpringBootApplication
public class Application {
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
@Bean
CommandLineRunner lookup(SetPinCodeClient setPinCodeClient) {
return args -> {
JAXBElement<String> pinCode = new ObjectFactory().createSetPinCodeCardNumber("2004");
JAXBElement<String> cardNumber = new ObjectFactory().createSetPinCodeCardNumber("B09B036");
JAXBElement<Integer> casinoCreationId = new ObjectFactory().createSetPinCodeCasinoCreationId(185);
SetPinCodeResponse response = setPinCodeClient.SetPinCode(pinCode, cardNumber, casinoCreationId);
System.err.println(response.toString());
};
}
}
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:793) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:774) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at hello.Application.main(Application.java:18) [classes/:na]
Caused by: org.springframework.ws.client.WebServiceTransportException: Cannot process the message because the content type 'text/xml; charset=utf-8' was not the expected type 'application/soap+xml; charset=utf-8'. [415]
at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:699) ~[spring-ws-core-3.0.0.RELEASE.jar:na]
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:609) ~[spring-ws-core-3.0.0.RELEASE.jar:na]
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555) ~[spring-ws-core-3.0.0.RELEASE.jar:na]
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390) ~[spring-ws-core-3.0.0.RELEASE.jar:na]
at hello.SetPinCodeClient.SetPinCode(SetPinCodeClient.java:33) ~[classes/:na]
at hello.Application.lambda$0(Application.java:28) [classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:790) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
... 5 common frames omitted
public SetPinCodeResponse SetPinCode(JAXBElement<String> pinCode, JAXBElement<String> cardNumber, JAXBElement<Integer> casinoCreationId) {
SetPinCode request = new SetPinCode();
request.setPinCode(pinCode);
request.setCardNumber(cardNumber);
request.setCasinoCreationId(casinoCreationId);
log.info("Requesting save in database for card " + cardNumber + "with pin code" + pinCode + "from casino n°" + casinoCreationId);
SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory();
messageFactory.setSoapVersion(SoapVersion.SOAP_12);
WebServiceTemplate wsTemplate = getWebServiceTemplate();
wsTemplate.setMessageFactory(messageFactory);
SetPinCodeResponse response = (SetPinCodeResponse) wsTemplate
.marshalSendAndReceive("http://192.168.67.63:8095/PlayerServices/PlayerIntelligence/PlayerManagementService",
request,
new SoapActionCallback("http://192.168.67.63:8095/PlayerServices/PlayerIntelligence/PlayerManagementService/SetPinCode"));
return response;
}
java.lang.IllegalStateException: Failed to execute CommandLineRunner
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:793) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.callRunners(SpringApplication.java:774) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:335) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1246) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1234) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
at hello.Application.main(Application.java:18) [classes/:na]
Caused by: java.lang.NullPointerException: null
at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:174) ~[spring-ws-core-3.0.0.RELEASE.jar:na]
at org.springframework.ws.soap.saaj.SaajSoapMessageFactory.createWebServiceMessage(SaajSoapMessageFactory.java:60) ~[spring-ws-core-3.0.0.RELEASE.jar:na]
at org.springframework.ws.context.DefaultMessageContext.<init>(DefaultMessageContext.java:42) ~[spring-ws-core-3.0.0.RELEASE.jar:na]
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:553) ~[spring-ws-core-3.0.0.RELEASE.jar:na]
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390) ~[spring-ws-core-3.0.0.RELEASE.jar:na]
at hello.SetPinCodeClient.SetPinCode(SetPinCodeClient.java:36) ~[classes/:na]
at hello.Application.lambda$0(Application.java:28) [classes/:na]
at org.springframework.boot.SpringApplication.callRunner(SpringApplication.java:790) [spring-boot-2.0.0.RELEASE.jar:2.0.0.RELEASE]
... 5 common frames omitted
最佳答案
所以我终于找到了一种使用 SOAP 1.2 协议(protocol)进行调用的方法。
这是的完整代码SetPinCodeClient.java
package hello;
import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import javax.xml.soap.MessageFactory;
import javax.xml.soap.SOAPConstants;
import javax.xml.soap.SOAPException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ws.WebServiceMessage;
import org.springframework.ws.client.core.WebServiceTemplate;
import org.springframework.ws.client.core.support.WebServiceGatewaySupport;
import org.springframework.ws.soap.SoapHeader;
import org.springframework.ws.soap.SoapHeaderElement;
import org.springframework.ws.soap.client.core.SoapActionCallback;
import org.springframework.ws.soap.saaj.SaajSoapMessage;
import org.springframework.ws.soap.saaj.SaajSoapMessageFactory;
import hello.wsdl.SetPinCode;
import hello.wsdl.SetPinCodeResponse;
public class SetPinCodeClient extends WebServiceGatewaySupport{
private static final Logger log = LoggerFactory.getLogger(SetPinCodeClient.class);
public SetPinCodeResponse SetPinCode(JAXBElement<String> pinCode, JAXBElement<String> cardNumber, JAXBElement<Integer> casinoCreationId) throws SOAPException {
String action ="http://tempuri.org/Player_x0020_Management_x0020_Service/SetPinCode";
String uri = "http://xxx.xxx.xx.x/PlayerServices/PlayerIntelligence/PlayerManagementService";
SetPinCode request = new SetPinCode();
request.setPinCode(pinCode);
request.setCardNumber(cardNumber);
request.setCasinoCreationId(casinoCreationId);
log.info("Requesting save in database for card " + cardNumber + "with pin code" + pinCode + "from casino n°" + casinoCreationId);
MessageFactory msgFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL);
SaajSoapMessageFactory saajSoapMessageFactory = new SaajSoapMessageFactory(msgFactory);
WebServiceTemplate wsTemplate = getWebServiceTemplate();
wsTemplate.setMessageFactory(saajSoapMessageFactory);
SoapActionCallback requestCallback = new SoapActionCallback(action) {
public void doWithMessage(WebServiceMessage message) {
SaajSoapMessage soapMessage = (SaajSoapMessage) message;
SoapHeader soapHeader = soapMessage.getSoapHeader();
QName wsaToQName = new QName("http://www.w3.org/2005/08/addressing", "To", "wsa");
SoapHeaderElement wsaTo = soapHeader.addHeaderElement(wsaToQName);
wsaTo.setText(uri);
QName wsaActionQName = new QName("http://www.w3.org/2005/08/addressing", "Action", "wsa");
SoapHeaderElement wsaAction = soapHeader.addHeaderElement(wsaActionQName);
wsaAction.setText(action);
}
};
SetPinCodeResponse response = (SetPinCodeResponse) wsTemplate.marshalSendAndReceive(uri, request, requestCallback);
return response;
}
}
关于java - 在 Spring 中使用带有 WebServiceGatewaySupport 的 SOAP 1.2,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49236349/
我正在使用 SOA 客户端 Firefox 插件向某些 ONVIF 摄像机发送 SOAP 请求。您将在下面看到“GetServices”请求。它对于一台相机工作正常,但对于另一台(AXIS 相机)我收
我正在使用 SOA 客户端 Firefox 插件向某些 ONVIF 摄像机发送 SOAP 请求。您将在下面看到“GetServices”请求。它对于一台相机工作正常,但对于另一台(AXIS 相机)我收
有谁知道 Fiddler 是否可以显示 ASMX Web 服务的原始 SOAP 消息?我正在使用 Fiddler2 和 Storm 测试一个简单的 Web 服务,结果各不相同(Fiddler 显示纯
使用 SOAP 协议(protocol)时,是否可以使用 SOAP 取消挂起的远程函数调用? 我看到三种不同的情况: A) 向需要很长时间才能完成的服务发出请求。例如,当复制包含大量文件的目录时,可以
人们还在写吗SOAP services还是已经通过了它的技术architectural shelf life ?人们是否回归二进制格式? 最佳答案 SOAP 的替代方案不是二进制格式。 我认为您看到了
SOAP 协议(protocol)工作的默认端口号是多少? 最佳答案 没有“SOAP 协议(protocol)”之类的东西。 SOAP 是一种 XML 模式。 但是,它通常通过 HTTP(端口 80)
之间有什么区别 和 以及如何在它们之间切换? 如何将响应从 具有定义的命名空间 "http://schemas.xmlsoap.org/soap/envelope/" ,它的特殊含义是底层 XML
我正在从 Mule 进行 SOAP 调用。我正在使用 default-exception-strategy 来捕获异常。发生异常时,如何发送我自己的故障代码和故障字符串而不是通用的 soap 故障消息
我正在编写一个 powershell 脚本,它将每 10 分钟 ping 一次soap web 服务,以使其保持活跃状态,从而提高性能。我们已经在 IIS 中尝试了多种技术,应用程序池空闲超时和只
如有任何帮助,我们将不胜感激;我已经研究了几天了。 下面是我目前得到的代码;不幸的是,当我运行它时出现 HTTP 415 错误; 无法处理消息,因为内容类型为“text/xml; charset=UT
我们需要使用其他团队开发的网络服务。使用 JAX-WS用于生成网络服务。我们正在使用 wsimport 生成客户端 stub 。 问题是我需要将以下信息作为 header 与 SOAP 正文一起传递:
我的意思是,真正的互操作:从 Java 到 .NET,从 PHP 到 Java,等等。 我之所以这样问,是因为我们的权力希望我们使用 SOAP Web 服务实现面向公众的 API,并且我试图强调支持
我写了一个拦截器进行测试。但是我在Interceptor中获得的Soap消息正文始终为null。 我的Cxf是Apache-CXF-2.4.0 bean.xml是这样的:
我正在尝试查询货币的 netsuite api。以下soap请求在SOAP UI客户端中对我有用。但是我很难尝试使用 ruby 的 savon gem 0.9.7 版进行相同的工作。
我创建了一个示例 Mule 流,首先根据 http://www.mulesoft.org/documentation/display/current/Consuming+Web+Services+wi
我正在尝试使用此 SOAP 服务:http://testws.truckstop.com:8080/v13/Posting/LoadPosting.svc?singleWsdl使用 node-soap
我有几个 SoapUI 测试步骤,其中响应返回空(即“-> 空/空响应”),这正是我所期望的。 如何断言对测试步骤请求的响应为空? 到目前为止,我已经尝试了以下但没有运气: 审查可用的断言,无需定制
我正在尝试构建一个手动 HTTP 请求,以便从我认为是相当简单的 SOAP Web 服务调用中返回响应。但是,我无法正确构建请求,并且没有得到我期望的响应。 适用wsdl声明: wsdl 目标命名空间
我正在尝试使用 Insomnia 调用 SOAP 电话 - 特别是试图让帖子成功。我将 URL 定义为端点,并将正文类型作为带有 SOAP 内容(信封、标题、正文)的 XML。我在标题中定义了用户 I
我正在学习 SOAP 实现,并且对于 SOAP 1.2 信封的适当 namespace URI 感到有些困惑。 w3c specification for SOAP指的是“http://www.w3.
我是一名优秀的程序员,十分优秀!