Spring 集成解组
我正在尝试使用 UnmarshallingTransformer 在 Spring 集成中将 java 对象解组为 xml,但收到错误消息,表明未创建有效负载。 这是我的代码:
@Bean
public Marshaller jaxbMarshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setClassesToBeBound(TargetedClass.class);
return jaxb2Marshaller;
}
@Bean
public IntegrationFlow posting() {
try {
return IntegrationFlows.from(Http.inboundGateway("/foo")
.requestMapping(m -> m.methods(HttpMethod.POST)
).errorChannel("error.input")
)
.transform(Transformers.objectToString())
.enrichHeaders(h -> h.headerExpression())
.transform(httpcallFunc())
.transform(new UnmarshallingTransformer((Unmarshaller) jaxbMarshaller()))
.get();
} catch (Exception e) {
System.out.println(e.getMessage());
}
return null;
}
我收到此错误。
org.springframework.messaging.MessagingException: failed to create Source for payload type [com.org.model.ClassName]
org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 : "<Map><timestamp>2022-03-18T11:24:26.568+00:00</timestamp><status>500</status><error>Internal Server Error</error><path>/foo</path></Map>"
当我尝试使用 UnmarshallingTransformer 时会发生这种情况。
I am trying to unmarshal java objects to xml in Spring integration using UnmarshallingTransformer but I am getting an error that the payload is not created.
This is my code :
@Bean
public Marshaller jaxbMarshaller() {
Jaxb2Marshaller jaxb2Marshaller = new Jaxb2Marshaller();
jaxb2Marshaller.setClassesToBeBound(TargetedClass.class);
return jaxb2Marshaller;
}
@Bean
public IntegrationFlow posting() {
try {
return IntegrationFlows.from(Http.inboundGateway("/foo")
.requestMapping(m -> m.methods(HttpMethod.POST)
).errorChannel("error.input")
)
.transform(Transformers.objectToString())
.enrichHeaders(h -> h.headerExpression())
.transform(httpcallFunc())
.transform(new UnmarshallingTransformer((Unmarshaller) jaxbMarshaller()))
.get();
} catch (Exception e) {
System.out.println(e.getMessage());
}
return null;
}
I am getting this error back.
org.springframework.messaging.MessagingException: failed to create Source for payload type [com.org.model.ClassName]
org.springframework.web.client.HttpServerErrorException$InternalServerError: 500 : "<Map><timestamp>2022-03-18T11:24:26.568+00:00</timestamp><status>500</status><error>Internal Server Error</error><path>/foo</path></Map>"
This occurs when I am trying to use the UnmarshallingTransformer.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
UnmarshallingTransformer
默认情况下使用DomSourceFactory
。它的逻辑是这样的:由于默认选项和您的自定义类型
com.org.model.ClassName
,没有任何条件适用,因此它无法执行最后一个else
。DomSourceFactory
的逻辑如下:这也不满足您的
com.org.model.ClassName
。因此,您会在日志中看到异常等等。我不确定您的期望是什么,但是您从
httpcallFunc()
生成的类型与UnmarshallingTransformer
不兼容。The
UnmarshallingTransformer
uses aDomSourceFactory
by default. And its logic is like this:Since no one condition applies because of the default options and your custom type
com.org.model.ClassName
, it fails to the lastelse
. TheDomSourceFactory
has a logic like this:Which also does not satisfy your
com.org.model.ClassName
. Therefore an exception you see in your logs and so.I'm not sure what is your expectations, but the type you produce from your
httpcallFunc()
is not what would be compatible with theUnmarshallingTransformer
.