使用 Camel Spring-WS 和 JAXB 数据格式解组 MTOM 消息

发布于 2024-12-12 13:16:55 字数 2048 浏览 0 评论 0原文

1)有没有办法使用Camel Spring-WS组件解组MTOM消息?

2)我尝试使用Camel JAXB数据格式。它不起作用。 Datahandler 没有任何内容。 JAXB 数据格式支持 MTOM 吗?

<dataFormats>
    <jaxb id="jaxb" contextPath="com.mycompany.hr.jaxb"/>
</dataFormats>

<route>
    <from uri="spring-ws:rootqname:{http://mycompany.com/hr/schemas}HolidayRequest?endpointMapping=#endpointMapping" />
    <unmarshal ref="jaxb"/>
    <process ref="testProcessor" />
</route>

3)我认为JAXB数据格式中未启用MTOM。因此,我使用支持 MTOM 的 JAXB2Marshaller 创建了自定义数据格式。但仍然面临同样的问题。

import java.io.InputStream;
import java.io.OutputStream;

import javax.xml.transform.Source;

import org.apache.camel.Exchange;
import org.apache.camel.spi.DataFormat;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;

public class MtomDataFormat implements DataFormat {

    public void marshal(Exchange arg0, Object arg1, OutputStream arg2)
            throws Exception {
        // TODO Auto-generated method stub

    }

    public Object unmarshal(Exchange exchange, InputStream is) throws Exception {
        Source source = exchange.getContext().getTypeConverter().mandatoryConvertTo(Source.class, is);

        Jaxb2Marshaller mar = new Jaxb2Marshaller();
        mar.setContextPath("com.mycompany.hr.jaxb");
        mar.setMtomEnabled(true);
        return mar.unmarshal(source);
    }

}

弹簧配置

<bean id="endpointMapping"
    class="org.apache.camel.component.spring.ws.bean.CamelEndpointMapping">
</bean>

<bean id="testProcessor" class="TestProcessor" />

<bean id="mtomDataFormat" class="MtomDataFormat" />

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="spring-ws:rootqname:{http://mycompany.com/hr/schemas}HolidayRequest?endpointMapping=#endpointMapping" />
        <unmarshal ref="mtomDataFormat"/>
        <process ref="testProcessor" />
    </route>
</camelContext>

1) Is there a way to unmarshall MTOM message using Camel Spring-WS component?

2) I tried with Camel JAXB dataformat. It didn't work. Datahandler doesn't have any content. Does JAXB dataformat support MTOM?

<dataFormats>
    <jaxb id="jaxb" contextPath="com.mycompany.hr.jaxb"/>
</dataFormats>

<route>
    <from uri="spring-ws:rootqname:{http://mycompany.com/hr/schemas}HolidayRequest?endpointMapping=#endpointMapping" />
    <unmarshal ref="jaxb"/>
    <process ref="testProcessor" />
</route>

3) I thought MTOM is not enabled in JAXB dataformat. So I created a custom dataformat using MTOM enabled JAXB2Marshaller. But still facing the same issue.

import java.io.InputStream;
import java.io.OutputStream;

import javax.xml.transform.Source;

import org.apache.camel.Exchange;
import org.apache.camel.spi.DataFormat;
import org.springframework.oxm.jaxb.Jaxb2Marshaller;

public class MtomDataFormat implements DataFormat {

    public void marshal(Exchange arg0, Object arg1, OutputStream arg2)
            throws Exception {
        // TODO Auto-generated method stub

    }

    public Object unmarshal(Exchange exchange, InputStream is) throws Exception {
        Source source = exchange.getContext().getTypeConverter().mandatoryConvertTo(Source.class, is);

        Jaxb2Marshaller mar = new Jaxb2Marshaller();
        mar.setContextPath("com.mycompany.hr.jaxb");
        mar.setMtomEnabled(true);
        return mar.unmarshal(source);
    }

}

Spring configuration

<bean id="endpointMapping"
    class="org.apache.camel.component.spring.ws.bean.CamelEndpointMapping">
</bean>

<bean id="testProcessor" class="TestProcessor" />

<bean id="mtomDataFormat" class="MtomDataFormat" />

<camelContext xmlns="http://camel.apache.org/schema/spring">
    <route>
        <from uri="spring-ws:rootqname:{http://mycompany.com/hr/schemas}HolidayRequest?endpointMapping=#endpointMapping" />
        <unmarshal ref="mtomDataFormat"/>
        <process ref="testProcessor" />
    </route>
</camelContext>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文