You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@servicemix.apache.org by Nirav <ni...@i-logicon.co.in> on 2007/01/31 07:04:12 UTC

Attachment in form of byte[]

Hello,

In my project I added message content in normalize message as message
property but I think it is better to add as attachment,

So, Can you help me how can I add byte[] (byte array) as attachment in
Normalize message!
-- 
View this message in context: http://www.nabble.com/Attachment-in-form-of-byte---tf3146867s12049.html#a8723779
Sent from the ServiceMix - Dev mailing list archive at Nabble.com.


Re: Attachment in form of byte[]

Posted by Guillaume Nodet <gn...@gmail.com>.
On 3/21/07, Nirav <ni...@i-logicon.co.in> wrote:
>
>
> Truly Helpful,
>
> Thanks.
>
> I think I can get one more solution from you.
>
> You can have an overview of my project by clicking below link...
>
> http://forum.java.sun.com/thread.jspa?forumID=512&threadID=5132641
>
> Now my problem is after time span like 4-5 hours my NMR stops accepting
> uncompressed messages.


You should check that:
  * the seda queues are empty
  * delivery channels are empty
  * check if threads are waiting for something
All these checks can be done from a JMX console.
One usual problem is when a hand written component does not comply
with the JBI Meps and forget to send an exchange back with a DONE
status for example.
If you see that threads are all waiting for a resource, please post
the thread dump (Ctrl+Break / kill -3).

So, I can say like after uncompression nothing will happen!
>
> Even I am not getting any error message!
> --
> View this message in context:
> http://www.nabble.com/Attachment-in-form-of-byte---tf3146867s12049.html#a9590762
> Sent from the ServiceMix - Dev mailing list archive at Nabble.com.
>
>


-- 
Cheers,
Guillaume Nodet
------------------------
Architect, LogicBlaze (http://www.logicblaze.com/)
Blog: http://gnodet.blogspot.com/

Re: Attachment in form of byte[]

Posted by Nirav <ni...@i-logicon.co.in>.
Truly Helpful,

Thanks.

I think I can get one more solution from you.

You can have an overview of my project by clicking below link...

http://forum.java.sun.com/thread.jspa?forumID=512&threadID=5132641 

Now my problem is after time span like 4-5 hours my NMR stops accepting
uncompressed messages.

So, I can say like after uncompression nothing will happen!

Even I am not getting any error message!
-- 
View this message in context: http://www.nabble.com/Attachment-in-form-of-byte---tf3146867s12049.html#a9590762
Sent from the ServiceMix - Dev mailing list archive at Nabble.com.


Re: [jira] Attachment in form of byte[]

Posted by Bruce Snyder <br...@gmail.com>.
On 3/5/07, Nirav <ni...@i-logicon.co.in> wrote:
>
> OK,
>
> Thanks for help!
>
> And atlast can you help me in getting attachment from Normalized Message?
>
> 'getAttachment()' method of Normalized Message returns DataHandler, How do I
> convert it into byte[] or String object?

>From the DataHandler, you can grab an InputStream. ServiceMix even
provides a utility class that contains a method for copying an
InputStream. See
org.apache.servicemix.jbi.util.FileUtil.copyInputStream for more
information.

Below is an example of grabbing an attachment and using the FileUtil
class to copy the InputStream:

if (in.getAttachmentNames() != null && in.getAttachmentNames().size() > 0) {
    for (Iterator it = in.getAttachmentNames().iterator(); it.hasNext();) {
        String name = (String) it.next();
        DataHandler dh = in.getAttachment(name);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        FileUtil.copyInputStream(dh.getInputStream(), baos);
        // Do something w/ the baos here
    }
}


Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

Apache Geronimo - http://geronimo.apache.org/
Apache ActiveMQ - http://activemq.org/
Apache ServiceMix - http://servicemix.org/
Castor - http://castor.org/

Re: [jira] Attachment in form of byte[]

Posted by Nirav <ni...@i-logicon.co.in>.
OK,

Thanks for help!

And atlast can you help me in getting attachment from Normalized Message?

'getAttachment()' method of Normalized Message returns DataHandler, How do I
convert it into byte[] or String object?


-- 
View this message in context: http://www.nabble.com/Attachment-in-form-of-byte---tf3146867s12049.html#a9307091
Sent from the ServiceMix - Dev mailing list archive at Nabble.com.


Re: Attachment in form of byte[]

Posted by Bruce Snyder <br...@gmail.com>.
On 1/30/07, Nirav <ni...@i-logicon.co.in> wrote:
>
> Hello,
>
> In my project I added message content in normalize message as message
> property but I think it is better to add as attachment,
>
> So, Can you help me how can I add byte[] (byte array) as attachment in
> Normalize message!

Now about the NormalizedMessage.addAttachment() method? Below is an
example of adding a byte[]:

// Grab the attachment from somewhere
byte[] attachment = getAttachment();

// Create a NormalizedMessage using the MessageExchange
NormalizedMessage msg = me.createMessage();
msg.setContent(new StringSource("<hello>Hello World! Message</hello>"));
msg.addAttachment("anAttachment", new DataHandler(new
StreamDataSource(new ByteArrayInputStream(attachment))));

// Set the message on the MessageExchange
me.setMessage(msg, "in");

Bruce
-- 
perl -e 'print unpack("u30","D0G)U8V4\@4VYY9&5R\"F)R=6-E+G-N>61E<D\!G;6%I;\"YC;VT*"
);'

Apache Geronimo - http://geronimo.apache.org/
Apache ActiveMQ - http://activemq.org/
Apache ServiceMix - http://servicemix.org/
Castor - http://castor.org/