java - 为什么使用基本身份验证通过 WebServiceGatewaySupport 发送两个 SOAP 请求
问题描述
我正在为具有基本身份验证的 SOAP Web 服务编写客户端,并且我使用了 Spring WebServiceGatewaySupport。一切正常,我确实得到了预期的回复。
以下是相应的类。
配置类
@ConfigurationProperties(prefix = "ws.api")
@Data
public class ApiConfiguration {
@NonNull
private String endPointAddress;
@NonNull
private String userName;
@NonNull
private String password;
}
@Configuration
@AllArgsConstructor
public class ApiBeanConfiguration {
private final ApiConfiguration config;
@Bean
public Jaxb2Marshaller marshaller() {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("com.model");
return marshaller;
}
@Bean
public ClientTransport soapConnector(Jaxb2Marshaller marshaller) {
ClientTransportImpl client = new ClientTransportImpl(config);
client.setDefaultUri(config.getEndPointAddress());
client.setMarshaller(marshaller);
client.setUnmarshaller(marshaller);
client.setMessageSender(httpComponentsMessageSender());
return client;
}
@Bean
public HttpComponentsMessageSender httpComponentsMessageSender() {
HttpComponentsMessageSender httpComponentsMessageSender = new HttpComponentsMessageSender();
httpComponentsMessageSender.setCredentials(usernamePasswordCredentials());
return httpComponentsMessageSender;
}
@Bean
public UsernamePasswordCredentials usernamePasswordCredentials() {
return new UsernamePasswordCredentials(config.getUserName(), config.getPassword());
}
}
调用客户端类
@AllArgsConstructor
public class ClientTransportImpl extends WebServiceGatewaySupport implements ClientTransport {
private final ApiConfiguration config;
@SuppressWarnings("unchecked")
@Override
public SemanticResponse exchangeWithEndpoint(@NonNull Request request) {
JAXBElement<GetQuoteRequest> requestElement =
new JAXBElement<Request>( new QName(config.getSoapAction()
,config.getSoapMethod()),
Request.class,
request);
JAXBElement<GetQuoteResponse> response = (JAXBElement<Response>)
getWebServiceTemplate()
.marshalSendAndReceive(requestElement);
return response;
}
}
pom中的依赖
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
</parent>
...
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web-services</artifactId>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
</dependency>
然而,在使用 http 代理工具检查实际请求时,我发现这是从客户端发送的两个 post 请求,而不是一个。第一个是没有身份验证标头的请求,然后作为响应,它返回了 401,然后有一个带有基本身份验证的 soap 请求,一切正常。
127.0.0.1:63399: POST https://cloud.com/ws/connectors.soap:SubmitService
<< 401 [ISS.0088.9164] Access to WSDescriptor connectors.soap:SubmitService denied. 375b
127.0.0.1:63399: clientdisconnect
127.0.0.1:63477: clientconnect
127.0.0.1:63477: POST https://cloud.com/ws/connectors.soap:SubmitService
<< 200 OK 306b
我很想知道发送两个请求的原因以及我是否缺少一些配置。
解决方案
推荐阅读
- php - 无法更改 PHPPowerpoint 幻灯片的宽度和高度
- react-native - 如何在本机反应中调用函数?
- php - 在php中使用break(新行)回显变量
- c++ - 如何使用构造函数中的初始化程序设置具有相同值的二维数组?
- r - 使用 rlm 计算稳健回归的 r 平方是否合适
- snowflake-cloud-data-platform - PIVOT 无法识别用引号括起来的列
- react-native - 如何像 Way of Life App 一样在 React Native 上水平滚动日历。您可以通过链接查看视频
- python - “-e”是什么意思。在aws cdk的requirements.txt中?
- angular - 如何将 MatPaginator 初始化为 @ViewChild 成员变量?
- java - 从 Kubernetes 上的 Java pod 到 Mongo 数据库实例的连接失败并出现 MongoSocketReadException