312.5. 多部分消息


从 Camel 2.8.1 开始提供

ServiceInterfaceStrategy 支持多部分 SOAP 消息。ServiceInterfaceStrategy 必须初始化,它根据 JAX-WS 2.2 注解的服务接口定义,并满足 Document Bare 风格的要求。目标方法需要满足以下条件,遵循 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. 多部分请求

多部分请求的有效负载参数是 initiazlied 使用代表目标操作的签名的 BeanInvocation 对象。在调用 marshal () 处理器时,camel-soap DataFormat 将 BeanInvocation 中的内容映射到 SOAP 标头中的字段,并遵循 JAX-WS 映射。

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 正文中的元素(如果存在),并将它放到交换中 out 消息的正文。标头元素 不会 放入其 JAXB 映射的对象类型中。相反,这些元素被放入 camel out 消息标头 org.apache.camel.dataformat.soap.UNMARSHALLED_HEADER_LIST 中。元素将显示为元素实例值,或是 JAXBElement 值,具体取决于 ignoreJAXBElement 属性的设置。此属性从 camel-jaxb 继承。

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

312.5.3. 拥有者对象映射

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

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat