이 콘텐츠는 선택한 언어로 제공되지 않습니다.

18.2. Provider Marshalers


Overview

Providers use an implementation of the org.apache.servicemix.jms.endpoints.JmsProviderMarshaler interface to convert normalized messages into JMS messages. The marshaler also converts the incoming reply from a JMS message into a normalized message. The JMS binding component comes with two provider marshaler implementations:
DefaultProviderMarshaler
The DefaultProviderMarshaler class provides the marshaler used by generic provider endpoints.
JmsSoapProviderMarshaler
The JmsSoapProviderMarshaler class provides the marshaler used by SOAP provider endpoints.
Note
The default SOAP marshaler does not support the full range of SOAP messages nor does it support marshaling map based messages into JMS messages.
When the default provider marshalers do not suffice for your application, you can provide a custom implementation of the JmsProviderMarshaler interface.

Implementing the marshaler

To create a custom provider marshaler, you implement the org.apache.servicemix.jms.endpoints.JmsProviderMarshaler interface. The JmsProviderMarshaler interface, shown in Example 18.4, “The Provider Marshaler Interface”, has two methods you need to implement:

Example 18.4. The Provider Marshaler Interface

public interface JmsProviderMarshaler
{
  Message createMessage(MessageExchange exchange, NormalizedMessage in, Session session) throws Exception;

  void populateMessage(Message message, MessageExchange exchange, NormalizedMessage normalizedMessage) throws Exception;
}
Copy to Clipboard Toggle word wrap
createMessage()
The createMessage() method uses information from the Red Hat JBoss Fuse core to generate a JMS message. Its parameters include the message exchange, the normalized message that is received by the provider, and the active JMS session.
populateMessage()
The populateMessage() method takes a JMS message and adds it to a message exchange for use by the Red Hat JBoss Fuse core.
Example 18.5, “Provider Marshaler Implementation” shows a simple provider marshaler implementation.

Example 18.5. Provider Marshaler Implementation

package com.widgetVendor.example;

import javax.jbi.messaging.MessageExchange;
import javax.jbi.messaging.NormalizedMessage;
import javax.jms.Message;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.xml.transform.Source;

import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jms.endpoints.JmsProviderMarshaler;

public class widgetProviderMarshaler implements JmsProviderMarshaler
{
    private SourceTransformer transformer = new SourceTransformer();
    
    public Message createMessage(MessageExchange exchange, NormalizedMessage in, Session session) throws Exception
    {
       TextMessage text = session.createTextMessage();
       text.setText(transformer.contentToString(in));
       return text;
    }

    public void populateMessage(Message message, MessageExchange exchange, NormalizedMessage normalizedMessage) throws Exception
    {
      TextMessage textMessage = (TextMessage) message;
      Source source = new StringSource(textMessage.getText());
      normalizedMessage.setContent(source);
    }
}
Copy to Clipboard Toggle word wrap

Configuring the provider

You configure a provider to use a custom marshaler using its marshaler attribute. The marshaler attribute's value is a reference to a bean element specifying the class of your custom marshaler implementation.
Example 18.6, “Configuring a Provider to Use a Customer Marshaler” shows configuration for a provider that uses a custom marshaler.

Example 18.6. Configuring a Provider to Use a Customer Marshaler

<beans xmlns:jms="http://servicemix.apache.org/jms/1.0"
       ... >
  ...
  <jms:soap-provider wsdl="classpath:widgets.wsdl"
                     destinationName="widgetQueue"
                     connectionFactory="#connectionFactory"
                     marshaler="#myProviderMarshaler" />

  <bean id="myProviderMarshaler" class="com.widgetVendor.example.widgetProviderMarshaler" />
  ...
</beans>
Copy to Clipboard Toggle word wrap
Note
You can also configure a provider to use a custom marshaler by adding a child marshaler element to the provider's configuration. The marshaler element simply wraps the bean element that configures the marshaler.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat