Solved

I want to Zip the Web Service Response

Posted on 2013-01-08
8
459 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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 500 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

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!

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
V.simple question about Android packages and libraries 1 38
Facing this issue for maven proxy setting 2 27
CSV file parsing thru Java 13 40
Regarding swagger API 1 38
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be u…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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…

726 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