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);