POJO SE - how to create NormalizedMessage with binary attachment?

5 messages Options
Embed this post
Permalink
Marian B

POJO SE - how to create NormalizedMessage with binary attachment?

Reply Threaded More More options
Print post
Permalink
Hi,

I am trying to generate binary file in POJO SE and send it to file-bc to write it on harddisk.
However I have troubles with adding this generated file as part1 of an attachment into NormalizedMessage, file bc does not recognize it.

How do you properly create binary attachment and address it in message payload?

My code in POJO is something like this:

...
NormalizedMessage nm = jbiCtx.getMessageExchange().createMessage();
FileBCDataSource ds = FileBCDataSource(myInputStream, "part1");
DataHandler dh = new DataHandler(ds);
//here should be nm.setContent(), but I do not how to insert reference to my attachment
nm.addAttachment(dh.getName(), dh);
nm.setProperty("org.glassfish.openesb.file.outbound.filename", myFileName);
return nm;

Method addAttachment has first parameter cid which is unique identifier of an attachment, but i do not know how to generate it correctly.

I am able to write file with specified myFileName but it has 0 bytes. I know that I could write it to filesystem right from my POJO, but that is not what I want (later I would like not to write in on harddisk, but for example write this file to database trought bpel process and/or database bc etc.).

Please could you give me an advice for creating NormalizedMessage with binary attachment?

Thank you.

Marian
Girish Patil-2

Re: POJO SE - how to create NormalizedMessage with binary attachment?

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
Psuedo code might look like below.
NormalizedMessage nm = jbiCtx.getMessageExchange().createMessage();
Document currDoc = createNewDocument(); /
//Create JBI wrapper message and part elements.
Element jbiMessageWrapper = WrapperUtil.createJBIMessageWrapper(); //See [1] below
currDoc.appendChild(jbiMessageWrapper);
Element jbiPart = WrapperUtil.createJBIWrappedPart(); //See [1] below
jbiMessageWrapper.appendChild(jbiPart);
// Create DataHandler and add it as attachement
DataHandler dh = new DataHandler(ds);
String cid = WrapperUtil.createXopCid(); // See [1] below
nm.addAttachment(cid, dh);
//Create xop:include element append to JBI part element
Element xopIncludeElem = doc.createElementNS(WrapperUtil.XOP_NAMESPACE, "xop:Include");
xopIncludeElem.setAttribute("href", cid);
jbiPart.appendChild(xopIncludeElem);
DOMSource src = new DOMSource(jbiMessageWrapper);
nm.setContent(src);

[1] see methods createXopCid, createJBIMessageWrapper and createJBIWrappedPart http://fisheye5.atlassian.com/browse/~raw,r=1.8/open-jbi-components/ojc-core/component-common/component/src/com/sun/jbi/nms/wsdl11wrapper/util/WrapperUtil.java



[hidden email] wrote:
Hi,

I am trying to generate binary file in POJO SE and send it to file-bc to
write it on harddisk.
However I have troubles with adding this generated file as part1 of an
attachment into NormalizedMessage, file bc does not recognize it.

How do you properly create binary attachment and address it in message
payload?

My code in POJO is something like this:

...
NormalizedMessage nm = jbiCtx.getMessageExchange().createMessage();
FileBCDataSource ds = FileBCDataSource(myInputStream, "part1");
DataHandler dh = new DataHandler(ds);
//here should be nm.setContent(), but I do not how to insert reference to my
attachment
nm.addAttachment(dh.getName(), dh);
nm.setProperty("org.glassfish.openesb.file.outbound.filename", myFileName);
return nm;

Method addAttachment has first parameter cid which is unique identifier of
an attachment, but i do not know how to generate it correctly.

I am able to write file with specified myFileName but it has 0 bytes. I know
that I could write it to filesystem right from my POJO, but that is not what
I want (later I would like not to write in on harddisk, but for example
write this file to database trought bpel process and/or database bc etc.).

Please could you give me an advice for creating NormalizedMessage with
binary attachment?

Thank you.

Marian

  
Marian B

Re: POJO SE - how to create NormalizedMessage with binary attachment?

Reply Threaded More More options
Print post
Permalink
Thank you for your quick answer. I followed your peudo code:

NormalizedMessage nm = jbiCtx.getMessageExchange().createMessage();
Document doc = createNewDocument(); // I created new document using DocumentBuilderFactory
Element jbiMessageWrapper = WrapperUtil.createJBIMessageWrapper(doc, new QName("{http://invoiceanalyzer.se.esb.mycompany.org/InvoiceAnalyzer/}InvoiceAnalyzerOperationResponse"), null);
doc.appendChild(jbiMessageWrapper);
Element jbiPart = WrapperUtil.createJBIWrappedPart(doc, doc.createTextNode("part1"));
jbiMessageWrapper.appendChild(jbiPart);

DataHandler dh = new DataHandler(ds);
String cid = WrapperUtil.createXopCid();
nm.addAttachment(cid, dh);
Element xopIncludeElem = doc.createElementNS("http://www.w3.org/2004/08/xop/include", "xop:Include"); //I hardcoded namespace URI because  WrapperUtil.XOP_NAMESPACE has private acces
jbiPart.appendChild(xopIncludeElem);
DOMSource src = new DOMSource(jbiMessageWrapper);
nm.setContent(src);

Now my problem is that I do not know if I correctly created jbiMessageWrapper and jbiPart because I am getting error
BPJBI-6012: Exception occurred while processing the response for message exchange with id 270480781624089-9570-134767950393060035 error is BPJBI-6032: Could not find the messageType definition {http://invoiceanalyzer.se.esb.mycompany.org/InvoiceAnalyzer/}InvoiceAnalyzerOperationResponse, specified by the type attribute in jbi:message element.

How do I get Qname from my wsdl? Sorry if I am missing some knowledge because I am quite new in jbi and openesb

Thanks

Marian

On Fri, Nov 6, 2009 at 3:07 AM, Girish Patil-2 [via OpenESB Users] <[hidden email]> wrote:
Psuedo code might look like below.
NormalizedMessage nm = jbiCtx.getMessageExchange().createMessage();
Document currDoc = createNewDocument(); /
//Create JBI wrapper message and part elements.
Element jbiMessageWrapper = WrapperUtil.createJBIMessageWrapper(); //See [1] below
currDoc.appendChild(jbiMessageWrapper);
Element jbiPart = WrapperUtil.createJBIWrappedPart(); //See [1] below
jbiMessageWrapper.appendChild(jbiPart);
// Create DataHandler and add it as attachement
DataHandler dh = new DataHandler(ds);
String cid = WrapperUtil.createXopCid(); // See [1] below
nm.addAttachment(cid, dh);
//Create xop:include element append to JBI part element
Element xopIncludeElem = doc.createElementNS(WrapperUtil.XOP_NAMESPACE, "xop:Include");
xopIncludeElem.setAttribute("href", cid);
jbiPart.appendChild(xopIncludeElem);
DOMSource src = new DOMSource(jbiMessageWrapper);
nm.setContent(src);

[1] see methods createXopCid, createJBIMessageWrapper and createJBIWrappedPart http://fisheye5.atlassian.com/browse/~raw,r=1.8/open-jbi-components/ojc-core/component-common/component/src/com/sun/jbi/nms/wsdl11wrapper/util/WrapperUtil.java



[hidden email] wrote:
Hi,

I am trying to generate binary file in POJO SE and send it to file-bc to
write it on harddisk.
However I have troubles with adding this generated file as part1 of an
attachment into NormalizedMessage, file bc does not recognize it.

How do you properly create binary attachment and address it in message
payload?

My code in POJO is something like this:

...
NormalizedMessage nm = jbiCtx.getMessageExchange().createMessage();
FileBCDataSource ds = FileBCDataSource(myInputStream, "part1");
DataHandler dh = new DataHandler(ds);
//here should be nm.setContent(), but I do not how to insert reference to my
attachment
nm.addAttachment(dh.getName(), dh);
nm.setProperty("org.glassfish.openesb.file.outbound.filename", myFileName);
return nm;

Method addAttachment has first parameter cid which is unique identifier of
an attachment, but i do not know how to generate it correctly.

I am able to write file with specified myFileName but it has 0 bytes. I know
that I could write it to filesystem right from my POJO, but that is not what
I want (later I would like not to write in on harddisk, but for example
write this file to database trought bpel process and/or database bc etc.).

Please could you give me an advice for creating NormalizedMessage with
binary attachment?

Thank you.

Marian

  



--
Marian Bystrican
ICQ: 287555380
[hidden email]
Girish Patil-2

Re: POJO SE - how to create NormalizedMessage with binary attachment?

Reply Threaded More More options
Print post
Permalink
Some javascript/style in this post has been disabled (why?)
[hidden email] wrote:
How do I get Qname from my wsdl? Sorry if I am missing some knowledge because I am quite new in jbi and openesb
It is QName of WSDL message, normally, targetNamespace:localWSDLMessageName.

In the example below input message type is
{http://a1.a/NewPOJOProvider/}SomeServiceRequest.
Output message type is
{http://a1.a/NewPOJOProvider/}SomeServiceResponse.
Ex:
<definitions name="NewPOJOProvider" targetNamespace="http://a1.a/NewPOJOProvider/"
    xmlns="http://schemas.xmlsoap.org/wsdl/"
    xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
    xmlns:tns="http://a1.a/NewPOJOProvider/"
...
    <portType name="SomePortType">
        <operation name="SomeOperation">
            <input name="input1" message="tns:SomeServiceRequest"/>
            <output name="output1" message="tns:
SomeServiceResponse"/>
        </operation>
    </portType>
...

Marian B

Re: POJO SE - how to create NormalizedMessage with binary attachment?

Reply Threaded More More options
Print post
Permalink
In reply to this post by Girish Patil-2
Oh i figured it out. I just modified creating QName object to new QName("http://invoiceanalyzer.se.esb.mycompany.org/InvoiceAnalyzer/", "InvoiceAnalyzerOperationResponse") and now it works! You saved my day :-).

Thanks,

Marian

On Fri, Nov 6, 2009 at 11:35 AM, Marian Bystrican <[hidden email]> wrote:
Thank you for your quick answer. I followed your peudo code:


NormalizedMessage nm = jbiCtx.getMessageExchange().createMessage();
Document doc = createNewDocument(); // I created new document using DocumentBuilderFactory
Element jbiMessageWrapper = WrapperUtil.createJBIMessageWrapper(doc, new QName("{http://invoiceanalyzer.se.esb.mycompany.org/InvoiceAnalyzer/}InvoiceAnalyzerOperationResponse"), null);
doc.appendChild(jbiMessageWrapper);
Element jbiPart = WrapperUtil.createJBIWrappedPart(doc, doc.createTextNode("part1"));
jbiMessageWrapper.appendChild(jbiPart);


DataHandler dh = new DataHandler(ds);
String cid = WrapperUtil.createXopCid();
nm.addAttachment(cid, dh);
Element xopIncludeElem = doc.createElementNS("http://www.w3.org/2004/08/xop/include", "xop:Include"); //I hardcoded namespace URI because  WrapperUtil.XOP_NAMESPACE has private acces

jbiPart.appendChild(xopIncludeElem);
DOMSource src = new DOMSource(jbiMessageWrapper);
nm.setContent(src);

Now my problem is that I do not know if I correctly created jbiMessageWrapper and jbiPart because I am getting error
BPJBI-6012: Exception occurred while processing the response for message exchange with id 270480781624089-9570-134767950393060035 error is BPJBI-6032: Could not find the messageType definition {http://invoiceanalyzer.se.esb.mycompany.org/InvoiceAnalyzer/}InvoiceAnalyzerOperationResponse, specified by the type attribute in jbi:message element.

How do I get Qname from my wsdl? Sorry if I am missing some knowledge because I am quite new in jbi and openesb

Thanks

Marian


On Fri, Nov 6, 2009 at 3:07 AM, Girish Patil-2 [via OpenESB Users] <[hidden email]> wrote:
Psuedo code might look like below.
NormalizedMessage nm = jbiCtx.getMessageExchange().createMessage();
Document currDoc = createNewDocument(); /
//Create JBI wrapper message and part elements.
Element jbiMessageWrapper = WrapperUtil.createJBIMessageWrapper(); //See [1] below
currDoc.appendChild(jbiMessageWrapper);
Element jbiPart = WrapperUtil.createJBIWrappedPart(); //See [1] below
jbiMessageWrapper.appendChild(jbiPart);
// Create DataHandler and add it as attachement
DataHandler dh = new DataHandler(ds);
String cid = WrapperUtil.createXopCid(); // See [1] below
nm.addAttachment(cid, dh);
//Create xop:include element append to JBI part element
Element xopIncludeElem = doc.createElementNS(WrapperUtil.XOP_NAMESPACE, "xop:Include");
xopIncludeElem.setAttribute("href", cid);
jbiPart.appendChild(xopIncludeElem);
DOMSource src = new DOMSource(jbiMessageWrapper);
nm.setContent(src);

[1] see methods createXopCid, createJBIMessageWrapper and createJBIWrappedPart http://fisheye5.atlassian.com/browse/~raw,r=1.8/open-jbi-components/ojc-core/component-common/component/src/com/sun/jbi/nms/wsdl11wrapper/util/WrapperUtil.java



[hidden email] wrote:
Hi,

I am trying to generate binary file in POJO SE and send it to file-bc to
write it on harddisk.
However I have troubles with adding this generated file as part1 of an
attachment into NormalizedMessage, file bc does not recognize it.

How do you properly create binary attachment and address it in message
payload?

My code in POJO is something like this:

...
NormalizedMessage nm = jbiCtx.getMessageExchange().createMessage();
FileBCDataSource ds = FileBCDataSource(myInputStream, "part1");
DataHandler dh = new DataHandler(ds);
//here should be nm.setContent(), but I do not how to insert reference to my
attachment
nm.addAttachment(dh.getName(), dh);
nm.setProperty("org.glassfish.openesb.file.outbound.filename", myFileName);
return nm;

Method addAttachment has first parameter cid which is unique identifier of
an attachment, but i do not know how to generate it correctly.

I am able to write file with specified myFileName but it has 0 bytes. I know
that I could write it to filesystem right from my POJO, but that is not what
I want (later I would like not to write in on harddisk, but for example
write this file to database trought bpel process and/or database bc etc.).

Please could you give me an advice for creating NormalizedMessage with
binary attachment?

Thank you.

Marian

  



--
Marian Bystrican
ICQ: 287555380
[hidden email]



--
Marian Bystrican
ICQ: 287555380
[hidden email]