Hi !

In fact, the problem was slightly different : it was an MQ issue : the jms
consumer was receiving a BytesMessage and not a TextMessage. I managed this
with the folleowing xbean configuration :

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns:jms="http://servicemix.apache.org/jms/1.0";
       xmlns:util="http://www.springframework.org/schema/util";>

  <jms:consumer service="eu.partecis.simu"
                endpoint="mqin"
                            targetService="eu.partecis.simu"
                targetEndpoint="mqout"
                destination="#inDestination"
                connectionFactory="#inConnectionFactory"
                marshaler="#plainToXmlMarshaler" 
                        />
  <bean id="plainToXmlMarshaler"
class="eu.partecis.esb.toxmlmarshaler.toXMLConsumerMarshaler">
  </bean>
  
  <bean id="inConnectionFactory"
class="com.ibm.mq.jms.MQQueueConnectionFactory">
    <property name="transportType">
      <util:constant
static-field="com.ibm.mq.jms.JMSC.MQJMS_TP_CLIENT_MQ_TCPIP" />
    </property>
    <property name="queueManager" value="QMGR" />
    <property name="hostName" value="HOST" />
    <property name="channel" value="SYSTEM.DEF.SVRCONN" />
    <property name="port" value="1414" />
  </bean> 

  <bean id="inDestination" class="com.ibm.mq.jms.MQQueue">
    <property name="baseQueueName" value="QUEUE" />
    <property name="baseQueueManagerName" value="QMGR" />
    <property name="targetClient" value="1" />
  </bean>   
  <classpath>
   
<location>/home/panaget/apache-servicemix-3.3.1/lib/ext/com.ibm.mqjms.jar</location>
   
<location>/home/panaget/apache-servicemix-3.3.1/lib/ext/com.ibm.mq.jar</location>
   
<location>/home/panaget/apache-servicemix-3.3.1/lib/ext/dhbcore.jar</location>
   
<location>/home/panaget/apache-servicemix-3.3.1/lib/ext/eu.partecis.esb.toxmlmarshaler.jar</location>
   
<location>/home/panaget/apache-servicemix-3.3.1/lib/ext/eu.partecis.esb.toplaintextmarshaler.jar</location>
  </classpath> 

</beans>

The targetClient property (0 or 1) sets the type of message received...

Then I wrote my own marshaler (just to put <data></data> tags around the
incoming message) :

import javax.xml.transform.Source;
/*
import javax.jbi.component.ComponentContext;
import javax.jbi.messaging.Fault;
import javax.jbi.messaging.MessageExchange;
import javax.jms.Session;


import org.apache.servicemix.jbi.jaxp.SourceTransformer;
import org.apache.servicemix.jbi.messaging.MessageExchangeSupport;
*/

public class toXMLConsumerMarshaler extends DefaultConsumerMarshaler {
    
    protected void populateMessage(Message message, NormalizedMessage
normalizedMessage) throws Exception {
if (message instanceof TextMessage) {
            System.out.println("Message de type TextMessage");
            TextMessage textMessage = (TextMessage) message;
            System.out.println(textMessage.getText());
            Source source = new
StringSource("<data>".concat(textMessage.getText()).concat("</data>"));
            normalizedMessage.setContent(source);
        }
        else {
            ;
            throw new UnsupportedOperationException("JMS message is not a
TextMessage : " + message.getClass().getName());
        }
    }
}

And it works fine !

But... once my message has been processed in servicemix it has to be posted
to another MQ queue... without the tags, so I added the following inside
xbean.xml :

  <jms:provider service="eu.partecis.simu"
                endpoint="mqout"
                            destination="#outDestination"
                            connectionFactory="#outConnectionFactory"
                            marshaler="#xmlToPlainTextMarshaler" />
                
  <bean id="xmlToPlainTextMarshaler"
class="eu.partecis.esb.toplaintextmarshaler.toPlainTextProviderMarshaler">
  </bean>


  <bean id="outConnectionFactory"
class="com.ibm.mq.jms.MQQueueConnectionFactory">
          <property name="transportType">
                  <util:constant
static-field="com.ibm.mq.jms.JMSC.MQJMS_TP_CLIENT_MQ_TCPIP" />
          </property>
    <property name="queueManager" value="INFRA.TEST.JMS" />
    <property name="hostName" value="10.77.16.203" />
          <property name="channel" value="SYSTEM.DEF.SVRCONN" />
          <property name="port" value="1414" />
  </bean> 
  
  <bean id="outDestination" class="com.ibm.mq.jms.MQQueue">
          <property name="baseQueueName" value="QLOCAL.INFRA.JMS.ECRITURE" />
          <property name="baseQueueManagerName" value="INFRA.TEST.JMS" />
    <!--  valeur 1 pour ne transmettre un message du type JMSTextMessage -->
          <property name="targetClient" value="1" />
  </bean>


And wrote my own provider marshaler just Ias I did for the consumer... but
it is not taken into acount (I put some System.out.println to debug but they
don't appear in the servicemix console !). Thi is how my custom provider
marshaler look like (for the moment it just changes the message to another
text just to see if it works) :

package eu.partecis.esb.toplaintextmarshaler;

import java.lang.System;

import javax.jms.Message;
import javax.jms.TextMessage;
import javax.jbi.messaging.NormalizedMessage;

import org.apache.servicemix.jbi.jaxp.StringSource;
import org.apache.servicemix.jms.endpoints.DefaultProviderMarshaler;
import javax.xml.transform.Source;

public class toPlainTextProviderMarshaler extends DefaultProviderMarshaler {
    
    public Message createMessage(MessageExchange exchange, NormalizedMessage
in, Session session) throws Exception {
        System.out.println("In Message");
        TextMessage text = session.createTextMessage();
//        text.setText(transformer.contentToString(in));
        text.setText("Message_text");
        if (jmsProperties != null) {
            for (Map.Entry<String, Object> e : jmsProperties.entrySet()) {
                text.setObjectProperty(e.getKey(), e.getValue());
            }
        }
        return text;
    }
    protected void populateMessage(Message message, NormalizedMessage
normalizedMessage) throws Exception {
        if (message instanceof TextMessage) {
            System.out.println("In populateMessage");
            TextMessage textMessage = (TextMessage) message;
            Source source = new StringSource("populateMessage_text"));
            normalizedMessage.setContent(source);
        } 
        else {
            throw new UnsupportedOperationException("JMS message is not a
TextMessage");
        }
    }


}

Any idea why it doesn't work ?

Guilhelm
-- 
View this message in context: 
http://old.nabble.com/servicemix-jms-consumer-with-non-xml-messages-tp28167771p28433531.html
Sent from the ServiceMix - User mailing list archive at Nabble.com.

Reply via email to