Manikandan Thiagarajan
asked on
I want to Zip the Web Service Response
I want to Zip the Web Service Response
how could i add it below the code
@POST
@Path("fetchProject")
@Consumes("application/jso n")
ProjectsVO fetchProject(String jsonStr);
how could i add it below the code
@POST
@Path("fetchProject")
@Consumes("application/jso
ProjectsVO fetchProject(String jsonStr);
ASKER
@POST
@Path("fetchProject")
@Consumes("application/jso n")
ProjectsVO fetchProject(String jsonStr);
No, Here i want to add @gzip what is the syntax tell me
@Path("fetchProject")
@Consumes("application/jso
ProjectsVO fetchProject(String jsonStr);
No, Here i want to add @gzip what is the syntax tell me
"Concerning GZIP encoding, each JAX-RS provider has different approaches"
Jersey provides a filter to accomplish the encoding transparently:
http://jersey.java.net/nonav/apidocs/latest/jersey/index.html
RESTEasy provides an annotation for that:
http://docs.jboss.org/resteasy/2.0.0.GA/userguide/html/gzip.html
Jersey provides a filter to accomplish the encoding transparently:
http://jersey.java.net/nonav/apidocs/latest/jersey/index.html
RESTEasy provides an annotation for that:
http://docs.jboss.org/resteasy/2.0.0.GA/userguide/html/gzip.html
ASKER
conn.setRequestMethod("GET ");
conn.setReadTimeout(600 * 1000);
conn.connect();
long end2 = System.currentTimeMillis() ;
System.out.println("time taken connection : " + (end2 - end1) + " ms");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "+ conn.getResponseCode());
}
is = conn.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
stringBuilder = new StringBuilder();
String line = null;
long startRead = System.currentTimeMillis() ;
System.out.println("time taken ========: " + (startRead-end2) + " ms");
while ((line = br.readLine()) != null) {
stringBuilder.append(line + "\n");
}
conn.setReadTimeout(600 * 1000);
conn.connect();
long end2 = System.currentTimeMillis()
System.out.println("time taken connection : " + (end2 - end1) + " ms");
if (conn.getResponseCode() != 200) {
throw new RuntimeException("Failed : HTTP error code : "+ conn.getResponseCode());
}
is = conn.getInputStream();
isr = new InputStreamReader(is);
br = new BufferedReader(isr);
stringBuilder = new StringBuilder();
String line = null;
long startRead = System.currentTimeMillis()
System.out.println("time taken ========: " + (startRead-end2) + " ms");
while ((line = br.readLine()) != null) {
stringBuilder.append(line + "\n");
}
ASKER
could you give me the java code for unzip from webservice response from the above line
I don't have my own code. I've never done this. found this on i-net :
// The response is gzip encoded, so decompress the response.
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.writeTo(out);
byte[] barr = out.toByteArray();
InputStream gzipStream = new GZIPInputStream(new ByteArrayInputStream(barr) );
Reader decoder = new InputStreamReader(gzipStre am, "UTF-8");
BufferedReader buffered = new BufferedReader(decoder);
int n = 0;
char[] cbuf = new char[1024];
Writer w = new StringWriter();
while ((n = buffered.read(cbuf)) != -1) {
w.write(cbuf,0,n);
}
// the writer now contains unzipped message.
System.out.println(w.toStr ing());
// The response is gzip encoded, so decompress the response.
ByteArrayOutputStream out = new ByteArrayOutputStream();
response.writeTo(out);
byte[] barr = out.toByteArray();
InputStream gzipStream = new GZIPInputStream(new ByteArrayInputStream(barr)
Reader decoder = new InputStreamReader(gzipStre
BufferedReader buffered = new BufferedReader(decoder);
int n = 0;
char[] cbuf = new char[1024];
Writer w = new StringWriter();
while ((n = buffered.read(cbuf)) != -1) {
w.write(cbuf,0,n);
}
// the writer now contains unzipped message.
System.out.println(w.toStr
ASKER
could you please apply with my code
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
probably you need this?