Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

I want to Zip the Web Service Response

Posted on 2013-01-08
8
Medium Priority
?
462 Views
Last Modified: 2013-01-09
I want to Zip the Web Service Response

how could i add it below the code

@POST
    @Path("fetchProject")
      @Consumes("application/json")
      ProjectsVO fetchProject(String jsonStr);
0
Comment
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 4
8 Comments
 
LVL 16

Expert Comment

by:Valeri
ID: 38754527
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 38754531
@POST
    @Path("fetchProject")
      @Consumes("application/json")
      ProjectsVO fetchProject(String jsonStr);
No, Here i want to add @gzip what is the syntax tell me
0
 
LVL 16

Expert Comment

by:Valeri
ID: 38754753
"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
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 38754909
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");
                  }
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 38754911
could you give me the java code for unzip from webservice response from the above line
0
 
LVL 16

Expert Comment

by:Valeri
ID: 38755213
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(gzipStream, "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.toString());
0
 
LVL 9

Author Comment

by:Manikandan Thiagarajan
ID: 38757635
could you please apply with my code
0
 
LVL 16

Accepted Solution

by:
Valeri earned 2000 total points
ID: 38757926
Yor code should like this :

      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();
      InputStream gzipStream = new GZIPInputStream(in);
      Reader decoder = new InputStreamReader(gzipStream, "UTF-8");
      br = new BufferedReader(decoder);
      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");
                  }
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
The viewer will learn how to implement Singleton Design Pattern in Java.
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question