312.5. 多部分消息


从 Camel 2.8.1 开始提供

ServiceInterfaceStrategy 支持多部分 SOAP 信息。ServiceInterfaceStrategy 必须使用服务接口定义进行初始化,该定义根据 JAX-WS 2.2 进行注解,并满足 Document Barestyle 的要求。目标方法需要满足以下条件,遵循 JAX-WS 规格:1) 它最多有一个 inin/out 非标头的参数,2) 如果它有一个非 void 的返回类型,它必须没有 in/outout 非标题的参数,3) 如果它有一个返回类型 void,它需要最多有一个 in/outout 非标头的参数。

ServiceInterfaceStrategy 应该使用布尔值参数进行初始化,该参数指示映射策略是否应用到请求参数或响应参数。

ServiceInterfaceStrategy strat =  new ServiceInterfaceStrategy(com.example.customerservice.multipart.MultiPartCustomerService.class, true);
SoapJaxbDataFormat soapDataFormat = new SoapJaxbDataFormat("com.example.customerservice.multipart", strat);
Copy to Clipboard Toggle word wrap

312.5.1. 多部分请求

多部分请求的有效负载参数使用包括目标操作签名的 BeanInvocation 对象进行 initiazlied。在调用 marshal () 处理器时,camel-soap DataFormat 将 BeanInvocation 中的内容映射到 SOAP 标头和正文中的字段。

BeanInvocation beanInvocation = new BeanInvocation();

// Identify the target method
beanInvocation.setMethod(MultiPartCustomerService.class.getMethod("getCustomersByName",
    GetCustomersByName.class, com.example.customerservice.multipart.Product.class));

// Populate the method arguments
GetCustomersByName getCustomersByName = new GetCustomersByName();
getCustomersByName.setName("Dr. Multipart");

Product product = new Product();
product.setName("Multiuse Product");
product.setDescription("Useful for lots of things.");

Object[] args = new Object[] {getCustomersByName, product};

// Add the arguments to the bean invocation
beanInvocation.setArgs(args);

// Set the bean invocation object as the message body
exchange.getIn().setBody(beanInvocation);
Copy to Clipboard Toggle word wrap

312.5.2. 多部分响应

多部分的 soap 响应可能包括 soap 正文中的一个元素,并在 soap 标头中包含一个或多个元素。camel-soap DataFormat 将 unmarshall 在 soap 正文(如果存在)中的元素,并将其放在交换中消息的正文中。标头元素 不会 放入其 JAXB 映射的对象类型中。相反,这些元素被放入 camel out 消息标头 org.apache.camel.dataformat.soap.UNMARSHALLED_HEADER_LIST 中。元素将显示为元素实例值或 JAXBElement 值,具体取决于 ignoreJAXBElement 属性的设置。此属性继承自 camel-jaxb。

通过将 ignoreUnmarshalledHeaders 值设置为 true,您也可以让 camel-soap DataFormate 忽略标头内容。

312.5.3. holder 对象映射

JAX-WS 指定对 In/OutOut 参数使用类型参数 javax.xml.ws.Holder 对象。构建 BeanInvocation 时,可以使用 Holder 对象,或者直接使用参数类型实例。根据 Holder 的类的 JAXB 映射,camel-soap DataFormat marshals Holder 值。在 unmarshalled 响应中,没有为 'Holder 对象提供映射。

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。 了解我们当前的更新.

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

Theme

© 2025 Red Hat