ASG
IBM
Zystems
Cressida
Icon
Netflexity
 
  MQSeries.net
Search  Search       Tech Exchange      Education      Certifications      Library      Info Center      SupportPacs      LinkedIn  Search  Search                                                                   FAQ  FAQ   Usergroups  Usergroups
 
Register  ::  Log in Log in to check your private messages
 
RSS Feed - WebSphere MQ Support RSS Feed - Message Broker Support

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How we can send attachments as response in http service

Post new topic  Reply to topic
 How we can send attachments as response in http service « View previous topic :: View next topic » 
Author Message
integrationshark
PostPosted: Tue Aug 07, 2018 5:21 am    Post subject: How we can send attachments as response in http service Reply with quote

Newbie

Joined: 07 Aug 2018
Posts: 6

tried something like this but we are getting response in the form of mailserice.htm file.

looking for any alternatives

httpinput----jcn----httpreply

Code:
MbElement outContent1 = outPart1.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-Type", "application/zip; name=httpfile.zip");   
         MbElement outContent2 = outPart1.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-Transfer-Encoding", "binary");   
         MbElement outContent3 = outPart1.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-Disposition", "form-data; name="+'"'+"httpfile.zip"+'"'+"; filename="+'"'+"httpfile.zip"+'"');   
         MbElement outContent4 = outPart1.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Name", "file.zip");   
            
         MbElement outData1 = outPart1.createElementAsLastChild(MbElement.TYPE_NAME, "Data", null);   
         MbElement outBlob1 = outData1.createElementAsLastChild(MbBLOB.PARSER_NAME);
         outBlob1.setName("BLOB");
         MbElement outBlob1a = outBlob1.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", bitstream);
Back to top
View user's profile Send private message
timber
PostPosted: Tue Aug 07, 2018 8:10 am    Post subject: Reply with quote

Grand Master

Joined: 25 Aug 2015
Posts: 1280

Quote:
tried something like this but we are getting response in the form of mailserice.htm file.
Why are you telling us this? What response did you expect to get?

Quote:
looking for any alternatives
It's difficult to advise you when we don't know exactly what you are trying to do. Please explain in more detail what you need to do, what you tried, and what happened.
Back to top
View user's profile Send private message
integrationshark
PostPosted: Tue Aug 07, 2018 8:30 am    Post subject: I am sending an attachment Reply with quote

Newbie

Joined: 07 Aug 2018
Posts: 6

i need to get a response with an attachment from http reply node.

for that i need to construct message tree structure using JCN
Back to top
View user's profile Send private message
integrationshark
PostPosted: Wed Aug 08, 2018 2:56 am    Post subject: Reply with quote

Newbie

Joined: 07 Aug 2018
Posts: 6

@timber need some more info on this ?
Back to top
View user's profile Send private message
Vitor
PostPosted: Wed Aug 08, 2018 4:33 am    Post subject: Reply with quote

Grand High Poobah

Joined: 11 Nov 2005
Posts: 26093
Location: Texas, USA

integrationshark wrote:
@timber need some more info on this ?


As @timber said, so do we.

You said you "tried something like this" and posted some code. If it was "something like that", how about posting the exact code?

You say you got an htm file instead of the attachment you were expecting - what's in the htm file? What's the attachment you expect? It looks like some kind of zip file - zipped from where? how?

What does the user trace say the message tree looks like after it leaves the JCN?

Better information, better advice.
_________________
Honesty is the best policy.
Insanity is the best defence.
Back to top
View user's profile Send private message
integrationshark
PostPosted: Wed Aug 08, 2018 5:38 am    Post subject: Reply with quote

Newbie

Joined: 07 Aug 2018
Posts: 6

Quote:
You said you "tried something like this" and posted some code. If it was "something like that", how about posting the exact code?

this is the same code i am using

Quote:
You say you got an htm file instead of the attachment you were expecting - what's in the htm file? What's the attachment you expect? It looks like some kind of zip file - zipped from where? how?


i mentioned zip file name in Content-type. but i am getting htm file.

Quote:
What does the user trace say the message tree looks like after it leaves the JCN?


will share
Back to top
View user's profile Send private message
integrationshark
PostPosted: Wed Aug 08, 2018 9:15 am    Post subject: actual code to generate attachment using mime Reply with quote

Newbie

Joined: 07 Aug 2018
Posts: 6

Code:
 public void evaluate(MbMessageAssembly contact admin) throws MbException {
        MbOutputTerminal out = getOutputTerminal("out");
        MbOutputTerminal alt = getOutputTerminal("alternate");

        final String multipart = "multipart/mixed; boundary=myBoundary";
       
        MbMessage inMessage = contact admin.getMessage();
       
        MbMessageAssembly outAssembly = null;
        try {
            // create new message as a copy of the input
            MbMessage outMessage = new MbMessage(inMessage);
            outAssembly = new MbMessageAssembly(contact admin, outMessage);
            // ----------------------------------------------------------
            // Add user code below
            String Payload = "A message is a discrete unit of communication intended by the source for consumption by some recipient or group of recipients. A message may be delivered by various means, including courier, telegraphy, carrier pigeon and electronic bus. A message can be the content of a broadcast.";
                   
                    //Set Properties content type to multipart
            MbElement outRoot = outMessage.getRootElement();
           
           
            //outMessage.getRootElement().getLastChild().delete();
            MbElement outProps = outRoot.getFirstElementByPath("/Properties");
            MbElement outPropDomain = outProps.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Domain", "MIME");
            outPropDomain.setValue("MIME");
            MbElement outPropContentType = outRoot.getFirstElementByPath("/Properties/ContentType");
            outPropContentType.setValue(multipart);

            //Set HTTP Header content type to multipart
            MbElement HTTPHdr = outRoot.getFirstElementByPath("/HTTPInputHeader");
            if(HTTPHdr!=null)
            {
            MbElement outMimeHTTPCT = HTTPHdr.getFirstElementByPath("/Content-Type");
           
            if (outMimeHTTPCT == null){
            outMimeHTTPCT = HTTPHdr.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "Content-Type", multipart);   
            }else{
            outMimeHTTPCT.setValue(multipart);
            }
            }

            //Create MIME Header
            MbElement outMime = outRoot.createElementAsLastChild("MIME");
            MbElement outMimeHdrCT = outMime.createElementAsFirstChild(MbElement.TYPE_NAME_VALUE, "Content-Type", multipart);
           
            //Add first part -- copy of xmlns input
            MbElement outParts = outMime.createElementAsLastChild(MbElement.TYPE_NAME, "Parts", null);
            MbElement outPart1 = outParts.createElementAsLastChild(MbElement.TYPE_NAME, "Part", null);
           
            /*Content-Type: application/octet-stream
            Content-Transfer-Encoding: binary
            Content-ID: <claimphoto@example.com>*/
           
           MbElement outContent1 = outPart1.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-Type", "application/zip;name=mdmprovider1.zip");   
           MbElement outContent2 = outPart1.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-Transfer-Encoding", "binary");   
           MbElement outContent3 = outPart1.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-Disposition", "form-data; name=apimessage; filename=mdmprovider.zip");   
               
            MbElement outData1 = outPart1.createElementAsLastChild(MbElement.TYPE_NAME, "Data", null); 
           
            byte[] PaylaodBlob = Payload.getBytes();
            byte[] ConvertMessages = CompressMessage(PaylaodBlob);
            MbElement outBlob1a = outData1.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "BLOB", ConvertMessages);

            // End of user code
            // ----------------------------------------------------------
        } catch (MbException e) {
            // Re-throw to allow Broker handling of MbException
            throw e;
        } catch (RuntimeException e) {
            // Re-throw to allow Broker handling of RuntimeException
            throw e;
        } catch (Exception e) {
            // Consider replacing Exception with type(s) thrown by user code
            // Example handling ensures all exceptions are re-thrown to be handled in the flow
            throw new MbUserException(this, "evaluate()", "", "", e.toString(),
                    null);
        }
        // The following should only be changed
        // if not propagating message to the 'out' terminal
        out.propagate(outAssembly);

    }
Back to top
View user's profile Send private message
integrationshark
PostPosted: Thu Aug 09, 2018 7:32 am    Post subject: we just need to add http reply header it's working good now Reply with quote

Newbie

Joined: 07 Aug 2018
Posts: 6

Created Httpreply header with Content-disposition and type

Code:
MbElement outHttpHeader = outRoot.createElementAsLastChild("HTTPReplyHeader");
           outHttpHeader.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-Disposition", "attachment; filename="+NewString);
           outHttpHeader.createElementAsLastChild(MbElement.TYPE_NAME_VALUE, "Content-Type", "application/zip");
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic  Reply to topic Page 1 of 1

MQSeries.net Forum Index » WebSphere Message Broker (ACE) Support » How we can send attachments as response in http service
Jump to:  



You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Protected by Anti-Spam ACP
 
 


Theme by Dustin Baccetti
Powered by phpBB © 2001, 2002 phpBB Group

Copyright © MQSeries.net. All rights reserved.