【问题标题】:Spring Integration WS Outbound Gateway POC - XMLMarshalExceptionSpring 集成 WS 出站网关 POC - XMLMarshalException
【发布时间】:2017-03-28 15:22:10
【问题描述】:

我正在使用以下用例开发关于 Spring Integration 的 POC。

  • 从远程 JMS 队列订阅输入消息 (A)
  • 将输入消息 (A) 转换为 (B)
  • 使用 (B) 调用远程 Web 服务并接收响应

我的 spring-int 配置 xml 有以下


<int-ws:outbound-gateway id="marshallingGateway" request-channel="mdmIntInputChannel" reply-channel="mdmIntOutputChannel" 
        uri="ws-endpoint" marshaller="marshaller" unmarshaller="marshaller"/>

<oxm:jaxb2-marshaller id="marshaller" contextPath="com.veeaar.ws.types.jaxb"/> 

在我的 spring 集成项目工作区中拥有我所有的 jaxb 生成的源代码。

在 STS 3.8.3 中执行此操作时,抛出以下错误。

不确定我的代码有什么问题。非常感谢任何解决此问题的帮助。谢谢。

Caused by: org.springframework.oxm.MarshallingFailureException: JAXB marshalling exception; nested exception is javax.xml.bind.MarshalException
 - with linked exception:
[Exception [EclipseLink-25007] (Eclipse Persistence Services - 2.6.1.v20150916-55dc7c3): org.eclipse.persistence.exceptions.XMLMarshalException
Exception Description: A descriptor for class java.lang.String was not found in the project.  For JAXB, if the JAXBContext was bootstrapped using TypeMappingInfo[] you must call a marshal method that accepts TypeMappingInfo as an input parameter.]
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.convertJaxbException(Jaxb2Marshaller.java:908)
    at org.springframework.oxm.jaxb.Jaxb2Marshaller.marshal(Jaxb2Marshaller.java:684)
    at org.springframework.ws.support.MarshallingUtils.marshal(MarshallingUtils.java:81)
    at org.springframework.integration.ws.MarshallingWebServiceOutboundGateway$MarshallingRequestMessageCallback.doWithMessageInternal(MarshallingWebServiceOutboundGateway.java:129)
    at org.springframework.integration.ws.AbstractWebServiceOutboundGateway$RequestMessageCallback.doWithMessage(AbstractWebServiceOutboundGateway.java:233)
    at org.springframework.ws.client.core.WebServiceTemplate.doSendAndReceive(WebServiceTemplate.java:590)
    at org.springframework.ws.client.core.WebServiceTemplate.sendAndReceive(WebServiceTemplate.java:555)
    at org.springframework.integration.ws.MarshallingWebServiceOutboundGateway.doHandle(MarshallingWebServiceOutboundGateway.java:87)
    at org.springframework.integration.ws.AbstractWebServiceOutboundGateway.handleRequestMessage(AbstractWebServiceOutboundGateway.java:188)
    at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:109)
    at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
    ... 36 more

我在这里进一步解释我的 POC,以进一步了解为什么在调用远程 Web 服务之前需要进行 JAXB 转换。

我在 Spring Integ 中进行的 XSL 转换将“Event”的输入消息转换为“fetchCodeByName”消息,如下所示。

<tns:fetchCodeByName xmlns:tns="http://www.veeaar.com/remote/wsdl/2010-1" xmlns:ns1="http://www.veeaar.com/remote/xml/2010-1" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
<ns1:Code>
    <Name>xxx</Name>
</ns1:Code>
</tns:fetchCodeByName>

在 WSDL 中,fetchCodeByName 映射到 ns1 命名空间的 CodesType。已从“代码”模式 XSD 生成 JAXB 类。

在调用远程 Web 服务之前,如果我创建一个服务激活器并尝试将转换输出解组到 JAXB 对象,我们会收到错误报告,因为解组任务期望“代码”作为根元素而不是“fetchCodeByName”。

如何解决这个问题?

在 Spring Integration 中有什么方法,我们可以在没有编组和解组输入消息的情况下调用远程 Web 服务吗?我们不能直接将 XSLT 输出直接指向 int-ws:outbound-gateway 吗?

【问题讨论】:

  • 欢迎来到 StackOverflow!请考虑阅读以下内容:stackoverflow.com/help/how-to-ask。如果没有正确的格式,您的问题是不可读的。太难了,抱歉。
  • 感谢@ArtemBilan 的投入。已格式化问题并希望它现在可读。
  • 好。我现在明白了。所以,问题是:那个异常不是说你的mdmIntInputChannelpayload 是一个字符串而不是一些JaxB 映射的POJO 吗?
  • 感谢@ArtemBilan 指出。我仍然不清楚如何进行。我更新了我的原始帖子,提供了更多关于尝试将 Web 服务输入转换为 JAXB 映射 XML 消息后出现的错误的信息。

标签: xml spring web-services jaxb spring-integration


【解决方案1】:

为什么需要在 WS Outbound Gateway 之前解组?你看,然后你再编组它!只需使用simple WS Outbound Gateway 变体(不带marshaller)并按原样在其input 通道中发送XSLT 转换器结果。

【讨论】:

  • 感谢@ArtemBilan 的投入。在我删除编组器任务后它起作用了。能够将 XSLT 转换器结果直接发送到 WS 出站网关并接收来自远程 Web 服务的响应。
  • 太棒了!所以,这是下一步:stackoverflow.com/help/someone-answers
  • 当我们处理各种适配器时,您能告诉我在 Spring Integration 中哪些用例需要编组器和解组器任务吗?谢谢。
  • 当您基于 JaxB 注释构建 POJO 时,它表示为该 WS 网关的 payload。以及您期望 POJO 作为网关的结果。由于您手动构建 XML(甚至通过 XSLT),因此无需担心 POJO 层。
猜你喜欢
  • 1970-01-01
  • 2014-06-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-12
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多