java - How to return TIFF image from remote api using multiple header parameters -
i'm creating spring application access remote api returns tiff image. api expecting few parameters send in header. i'm attempting following code examples i've found.. when return responseentity respond, it's of 0 length , byte[] respond null.
{content-length=[0], content-type=[application/octet-stream], server=[microsoft-iis/7.5], x-powered-by=[asp.net], date=[wed, 19 aug 2015 15:14:17 gmt]}
list<httpmessageconverter<?>> messageconverters = new arraylist<httpmessageconverter<?>>(); messageconverters.add(new bytearrayhttpmessageconverter()); resttemplate resttemplate = new resttemplate(messageconverters); httpheaders headers = new httpheaders(); headers.set("accept", "application/octet-stream"); uricomponentsbuilder builder = uricomponentsbuilder.fromhttpurl("http://webservices.imagestorehouse.com/getdata.svc/getdocs") .queryparam("token", "a80d4978c12549dbafcd1922c1efdaa5") .queryparam("company_id", "sw1112b") .queryparam("document", "1" ) .queryparam("field_1", "2627594") .queryparam("field_4", "028000"); httpentity<string> entity = new httpentity<string>(headers); //responseentity<byte[]> respond = resttemplate.execute(builder.build().encode().touri(), httpmethod.get, entity, byte[].class); byte[] respond = resttemplate.getforobject(builder.build().encode().touri(), byte[].class);
you need add few more parameters in response header.
header.setcontentlength(respond.length); //also set content type accordingly //header.setcontenttype(new mediatype("application", "xml"));
Comments
Post a Comment