Spring WS 无效的内容类型 [英] Spring WS Invalid Content Type

查看:31
本文介绍了Spring WS 无效的内容类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 Spring WS 客户端.我通过 wsimport 生成了 WSDL 存根.

I have a Spring WS client. I generated the WSDL stubs via wsimport.

当我尝试发送请求时,我收到无效的内容类型异常:

When I try to send a request, I get a Invalid Content-type exception:

严重:SAAJ0537:无效的内容类型.可能是错误消息而不是 SOAP 消息线程main" org.springframework.ws.soap.SoapMessageCreationException 中的异常:无法从 InputStream 创建消息:无效的内容类型:文本/html.这是错误消息而不是 SOAP 响应吗?嵌套异常是 com.sun.xml.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html.这是错误消息而不是 SOAP 响应吗?

SEVERE: SAAJ0537: Invalid Content-Type. Could be an error message instead of a SOAP message Exception in thread "main" org.springframework.ws.soap.SoapMessageCreationException: Could not create message from InputStream: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?; nested exception is com.sun.xml.messaging.saaj.SOAPExceptionImpl: Invalid Content-Type:text/html. Is this an error message instead of a SOAP response?

这是否表明我发送的消息具有无效的内容类型或我收到的响应具有无效的内容类型?如果是在客户端,如何设置内容类型?

Is this an indication that the message I sent has an invalid content-type or the response I receive has an invalid content-type? If it's on the client side, how do I set up the content-type?

我尝试通过 Soap UI 模拟 Web 服务.我能够发送和接收正确的回复.

I tried mocking the web service via Soap UI. I'm able to send and receive correct response.

在我的日志中,显示请求已发送:

On my log, it's shown that the request is sent:

DEBUG [org.springframework.ws.client.MessageTracing.sent] - 发送请求

DEBUG [org.springframework.ws.client.MessageTracing.sent] - Sent request

然后我得到那个例外:

线程main"org.springframework.ws.soap.SoapMessageCreationException 中的异常:

Exception in thread "main" org.springframework.ws.soap.SoapMessageCreationException:

推荐答案

问题已解决.

事实证明我没有发送任何 SOAP 内容.SOAP 标头设置正确.但是 SOAP 主体是空的.为了解决这个问题,我必须附上我请求的内容.

It turns out I was NOT sending any SOAP content. The SOAP header is set correctly. But the SOAP body is empty. To resolve the issue I had to attach the content that I'm requesting.

之前:

GetDeletedRequest request = new GetDeletedRequest();
JAXBElement res = (JAXBElement) webServiceTemplate.marshalSendAndReceive(request, new WebServiceMessageCallback() {...}

之后:

GetDeletedRequest request = new GetDeletedRequest();
request.setGetDeletedFilter(deleteFilter); // This is the content that I'm missing!
JAXBElement res = (JAXBElement) webServiceTemplate.marshalSendAndReceive(request, new WebServiceMessageCallback() {...}

我忽略了这个错误,因为我专注于将 AXIS 1.x 客户端实现移植到 Spring WS 实现.

This mistake was overlooked by me because I was focus on porting an AXIS 1.x client implementation to a Spring WS implementation.

有些人,包括 Arjen Poustma,建议使用 tcpmon 来嗅探发送的内容.我没有设法正确配置和运行它(这是另一个不相关的问题).但这给了我一个想法,首先检查我的应用程序发送的内容.

Some people, including Arjen Poustma, suggested to use tcpmon to sniff what's being sent. I didn't manage to configure and run it correctly (that's another unrelated issue). But this gave me an idea to inspect first what's being sent by my application.

我环顾四周,在 Spring 论坛中看到了关于 的无效内容类型的类似问题WS 客户端使用 JAXB 进行编组.最后一张海报建议使用 CommonsHttpMessageSender,就像他在 带有 Spring-WS 的 Web 服务客户端(这是一个不错的选择).使用 CommonsHttpMessageSender,它能够打印出我的整个 SOAP 信封:

I looked around and saw a similar problem in the Spring Forums about the invalid content type at WS Client using JAXB for marshalling. The last poster suggested to use the CommonsHttpMessageSender, just like the example he provided at Web Service Client with Spring-WS (which is a good one). With the CommonsHttpMessageSender it was able to print out my whole SOAP envelope:

<property name="messageSender">
     <bean class="org.springframework.ws.transport.http.CommonsHttpMessageSender" />
</property>

我在这里记录我的经历,因为我知道有一天会有另一个像我一样的人遇到同样的问题.

I'm documenting here my experiences because I know one day there will be another guy like me who will be having this same problem.

这篇关于Spring WS 无效的内容类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆