|   | 
	 
  
    | 
RSS Feed - WebSphere MQ Support
 | 
RSS Feed - Message Broker Support
 |   
 
  
	     | 
	 | 
   
 
  
	|  How we can send attachments as response in http service | 
	« View previous topic :: View next topic »  | 
   
  
  	
	  
		
		
		  | Author | 
		  Message
		 |  
		
		  | integrationshark | 
		  
		    
			  
				 Posted: Tue Aug 07, 2018 5:21 am    Post subject: How we can send attachments as response in http service | 
				     | 
			   
			 
		   | 
		 
		
		   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 | 
		  
		  	
		   | 
		 
		
		    | 
		 
		
		  | timber | 
		  
		    
			  
				 Posted: Tue Aug 07, 2018 8:10 am    Post subject:  | 
				     | 
			   
			 
		   | 
		 
		
		    Grand Master
 
 Joined: 25 Aug 2015 Posts: 1292
  
  | 
		  
		    
			  
				
   
	| 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 | 
		  
		  	
		   | 
		 
		
		    | 
		 
		
		  | integrationshark | 
		  
		    
			  
				 Posted: Tue Aug 07, 2018 8:30 am    Post subject: I am sending an attachment | 
				     | 
			   
			 
		   | 
		 
		
		   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 | 
		  
		  	
		   | 
		 
		
		    | 
		 
		
		  | integrationshark | 
		  
		    
			  
				 Posted: Wed Aug 08, 2018 2:56 am    Post subject:  | 
				     | 
			   
			 
		   | 
		 
		
		   Newbie
 
 Joined: 07 Aug 2018 Posts: 6
  
  | 
		  
		    
			  
				| @timber need some more info on this ? | 
			   
			 
		   | 
		 
		
		  | Back to top | 
		  
		  	
		   | 
		 
		
		    | 
		 
		
		  | Vitor | 
		  
		    
			  
				 Posted: Wed Aug 08, 2018 4:33 am    Post subject:  | 
				     | 
			   
			 
		   | 
		 
		
		    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 | 
		  
		  	
		   | 
		 
		
		    | 
		 
		
		  | integrationshark | 
		  
		    
			  
				 Posted: Wed Aug 08, 2018 5:38 am    Post subject:  | 
				     | 
			   
			 
		   | 
		 
		
		   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 | 
		  
		  	
		   | 
		 
		
		    | 
		 
		
		  | integrationshark | 
		  
		    
			  
				 Posted: Wed Aug 08, 2018 9:15 am    Post subject: actual code to generate attachment using mime | 
				     | 
			   
			 
		   | 
		 
		
		   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 | 
		  
		  	
		   | 
		 
		
		    | 
		 
		
		  | integrationshark | 
		  
		    
			  
				 Posted: Thu Aug 09, 2018 7:32 am    Post subject: we just need to add http reply header it's working good now | 
				     | 
			   
			 
		   | 
		 
		
		   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 | 
		  
		  	
		   | 
		 
		
		    | 
		 
		
		  | 
		    
		   | 
		 
	   
	 | 
   
 
  
	     | 
	 | 
	Page 1 of 1 | 
   
 
 
 
  
  	
	  
		
		  
 
  | 
		  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
  | 
  		 
	   
	 | 
   
 
  	 | 
	  |