Spring WS 无效内容类型

标签 spring types

我有一个 Spring WS 客户端。我通过 wsimport 生成了 WSDL stub 。

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

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?

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

我尝试通过 Soap UI 模拟 Web 服务。我能够发送和接收正确的响应。

编辑:

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

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

然后我得到了这个异常:

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

最佳答案

问题已解决。

事实证明我没有发送任何 SOAP 内容。 SOAP header 设置正确。但 SOAP 主体是空的。为了解决该问题,我必须附加我所请求的内容。

之前:

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 实现。

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

我环顾四周,在 Spring 论坛中看到了类似的问题,内容类型无效,地址为 WS Client using JAXB for marshalling 。最后一位发帖者建议使用 CommonsHttpMessageSender,就像他在 Web Service Client with Spring-WS 提供的示例一样。 (这是一件好事)。使用 CommonsHttpMessageSender,它能够打印出我的整个 SOAP 信封:

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

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

关于Spring WS 无效内容类型,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4350269/

相关文章:

c# - 'keyword' 和 'aliased type' 有什么区别?

c++ - 通过基类指针获取子类类型

objective-c - CLI 和 GUI 之间的 NSInteger 区别?

java - 当键改变时如何访问 Thymeleaf Spring 方言中的 map ?

Spring::如果一个新线程会被 Spring 在事务中强制执行

Spring MVC : how to get case-insensitive ordering from Pageable

java - setter 在 Spring 框架中如何工作?

java - Gradle-无法确定合适的驱动程序类别

types - 如何找到一个类型的父类型和子类型?

haskell - 函数不仅有类型 : They ARE Types. 和种类。和排序。帮助重振精神