camel-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From brenthale <br...@empowers.com>
Subject Re: Is it possible to create a custom DataFormat to translate a message into a BlobMessage?
Date Thu, 02 Aug 2012 22:13:34 GMT
Thanks for all the suggestions.

I've been trying to create a DataFormat to handle this.  I'm stuck trying to
integrate an ActiveMQ ActiveMQBlobMessage with the org.apache.camel.Exchange
class working with org.apache.camel.Message's.  You can't typecast one into
the other.

Here's my current unmarshal method:

  public Object unmarshal(Exchange exchange, InputStream stream) throws
Exception {
    ActiveMQConnection connection;
    ActiveMQSession session;

    ActiveMQBlobMessage blobMessage;

    connection = (ActiveMQConnection)
activeMQConnectionFactory.createConnection();
    connection.start();

    session = (ActiveMQSession) connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);

    blobMessage = (ActiveMQBlobMessage) session.createBlobMessage(stream);
    blobMessage.setMessageId(new
MessageId(exchange.getIn().getMessageId()));

    // Get the data uploaded to the ActiveMQ fileserver
    blobMessage.getBlobUploader().upload(blobMessage);

    // org.apache.camel.Exchange is a Camel object expecting a
org.apache.camel.Message in the Out.
    // BlobMessage is an ActiveMQ
org.apache.activemq.command.ActiveMQBlobMessage.
    // This line doesn't work. They don't cast.
//    exchange.setOut(blobMessage);

    // And this was a sad attempt at trying to get around it.
//    DefaultMessage camelMessage = new DefaultMessage();
//    camelMessage.setExchange(exchange);
//    camelMessage.setBody(blobMessage,
org.apache.activemq.command.Message.class);
//    camelMessage.setMessageId(blobMessage.getMessageId().toString());
//    exchange.setOut(camelMessage);    // kinda by-passes things.

//    if (! (((JmsMessage) message).getJmsMessage() instanceof BlobMessage))
{
    exchange.setOut((JmsMessage)(BlobMessage)blobMessage);
//      ((JmsMessage)exchange.getOut()).setJmsMessage(blobMessage);

    return blobMessage;
  }


When the setOut() is made I get the following exception.

exchange.setOut((JmsMessage)(BlobMessage)blobMessage) = Type mismatch Can't
assign org.apache.activemq.command.ActiveMQBlobMessage to
org.apache.camel.Message


When working with BlobMessages sent normally (via a producer.send()) I am
able to retrieve the BlobMessage this way:

    if (! (((JmsMessage) message).getJmsMessage() instanceof BlobMessage)) {
      throw new CdsMsgException("Error processing batch message: Expected a
BlobMessage");
    }
    BlobMessage blobMessage = (BlobMessage) ((JmsMessage)
message).getJmsMessage();

But I'm at a loss as to how to change the Message to a BlobMessage inside of
a DataFormat.   

I assume I'm missing something fairly trivial.

Thanks,




-----

Brent
--
View this message in context: http://camel.465427.n5.nabble.com/Is-it-possible-to-create-a-custom-DataFormat-to-translate-a-message-into-a-BlobMessage-tp5716679p5716720.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Mime
View raw message