gpt4 book ai didi

java - 使用 httpClient 创建 HttpComponentsMessageSender

转载 作者:行者123 更新时间:2023-12-01 17:47:24 32 4
gpt4 key购买 nike

我无法使用 kerberos 授权 SOAP 服务器。这是我的配置代码

  @Bean
def webServiceTemplate(): WebServiceTemplate = {
val webServiceTemplate = new WebServiceTemplate()
webServiceTemplate.setMarshaller(marshaller.marshaller)
webServiceTemplate.setUnmarshaller(marshaller.marshaller)
webServiceTemplate.setDefaultUri(Parameters.getDefaultURI)
webServiceTemplate.setMessageSender(httpComponentsMessageSender())
webServiceTemplate
}

@Bean
def httpComponentsMessageSender(): HttpComponentsMessageSender = {
val sender = new HttpComponentsMessageSender()
if(Parameters.isProduction){
sender.setHttpClient(getHttpClient())
} else sender.setCredentials(usernamePasswordCredentials())
sender
}

@Bean
def usernamePasswordCredentials(): NTCredentials = {
new NTCredentials(
"usr",
"pass",
"",
"MY_COMPANY"
)
}

@Bean
def getHttpClient() = {
val builder = HttpClientBuilder.create
val authSchemeRegistry = RegistryBuilder.create[AuthSchemeProvider]
.register(AuthSchemes.SPNEGO, new SPNegoSchemeFactory(true)).build
builder.setDefaultAuthSchemeRegistry(authSchemeRegistry)
builder.setDefaultCredentialsProvider(getCredProvider())
builder.addInterceptorFirst(new RemoveSoapHeadersInterceptor())
builder.build
}

我的 HttpClient 可以向其他基于 Kerberos 的服务(例如 oozie)发出请求。然而,当使用 SOAP 服务器时,我得到

Caused by: org.springframework.ws.client.WebServiceTransportException: Unauthorized [401]
at org.springframework.ws.client.core.WebServiceTemplate.handleError(WebServiceTemplate.java:699)
at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:609)
at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:390)
at org.springframework.ws.client.core.WebServiceTemplate.marshalSendAndReceive(WebServiceTemplate.java:378)

我使用krb5module并发出如下请求

reply = Subject.doAs(subject, new PrivilegedExceptionAction[CreateReply]() {
@throws[Exception]
override def run: CreateReply = getWebServiceTemplate
.marshalSendAndReceive("http://my-soap-service", request)
.asInstanceOf[CreateReply]

如何授权 SOAP 服务?我做错了什么?

最佳答案

事实证明我使用了错误的路径( http://my-soap-service )。我改成有效的,可以授权了。

结论:HttpClient 属性可以帮助为 SAOP 设置 HttpComponentsMessageSender。

关于java - 使用 httpClient 创建 HttpComponentsMessageSender,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60844986/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com