IBM webMethods Hybrid Integration

IBM webMethods Hybrid Integration

Join this online group to communicate across IBM product users and experts by sharing advice and best practices with peers and staying up to date regarding product enhancements.

 View Only
  • 1.  Downloading a binary file through an IS service

    Posted Mon January 29, 2007 12:03 AM

    Hello -

    I’m trying build a webMethods service that returns a binary file for download. The built-in WmPublic service pub.flow:setResponse service only works for a string response.

    After some headache, I got the following Java service going - it sets the appropriate headers that prompt the user to download a binary file, and uses Service.setResponse() to set a binary HTTP response.

    However, setResponse requires a Values object. The only way I could get a Values object from the pipeline here was to use Values.use() which is deprecated. Does anyone know a better way to do this?

    Regards,
    Sonam

    // pipeline
    IDataCursor pipelineCursor = pipeline.getCursor();
    byte[]	responseBytes = (byte []) IDataUtil.get( pipelineCursor, "responseBytes" );
    pipelineCursor.destroy();
    
    
    //Set HTTP Response for client to do Binary Download 
    com.wm.net.HttpHeader h = Service.getHttpResponseHeader(null); 
    h.setResponse(200, "OK"); 
    h.addField("Content-type", "application/binary");
    h.addField("Content-disposition", "attachment; filename=somefile.der");
    //Note, Values.use is deprecated 
    Values in = Values.use(pipeline);
    Service.setResponse(in, responseBytes);

    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 2.  RE: Downloading a binary file through an IS service

    Posted Mon January 29, 2007 12:54 AM

    Here’s code I’ve used in the past:
    [highlight=java]
    setResponseBytes(IData pipeline)
    IDataCursor idc = pipeline.getCursor();
    byte bytes = (byte )IDataUtil.get(idc, “bytes”);
    String encoding = IDataUtil.getString(idc, “encoding”);
    String contentType = IDataUtil.getString(idc, “contentType”);
    String remoteFilename = IDataUtil.getString(idc, “remoteFilename”);
    idc.destroy();

    com.wm.net.HttpHeader httpheader = Service.getHttpResponseHeader();

    if(httpheader != null)
    {
    if(contentType!=null && !contentType.equals(“”))
    httpheader.addField(“content-type”, contentType);
    if(encoding!=null && !encoding.equals(“”))
    httpheader.addField(“encoding”,encoding);
    if(remoteFilename!=null && !remoteFilename.equals(“”))
    httpheader.addField(“content-disposition”, “inline;filename= "”+ remoteFilename+ “"”);
    }
    Service.setResponse(bytes);
    [/highlight]


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services


  • 3.  RE: Downloading a binary file through an IS service

    Posted Mon January 29, 2007 01:20 AM

    Thanks Rob - that was a quick reply!

    The key difference was the last line of your code:
    Service.setResponse(bytes);

    The webMethods Java API for ‘Service’ documents only one setResponse method:

    Is using ‘setResponse(bytes)’ without the Values object safe?


    #Flow-and-Java-services
    #Integration-Server-and-ESB
    #webMethods


  • 4.  RE: Downloading a binary file through an IS service

    Posted Mon January 29, 2007 05:55 PM

    I don’t recall where I found that method reference but clearly it is undocumented and it is possible (though unlikely) that it could go away.


    #webMethods
    #Flow-and-Java-services
    #Integration-Server-and-ESB


  • 5.  RE: Downloading a binary file through an IS service

    Posted Thu February 01, 2007 03:36 AM

    Thanks Rob!

    On another note, I put up a thread with info on HTTP uploading binary data into IS:
    “HTTP uploading a binary file to IS”
    [url]wmusers.com


    #Integration-Server-and-ESB
    #webMethods
    #Flow-and-Java-services