[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

I want to Zip the Web Service Response

Posted on 2013-01-08
8
Medium Priority
?
463 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
  • 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
Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

 
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

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

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

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…
International Data Corporation (IDC) prognosticates that before the current the year gets over disbursing on IT framework products to be sent in cloud environs will be $37.1B.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
How to fix incompatible JVM issue while installing Eclipse While installing Eclipse in windows, got one error like above and unable to proceed with the installation. This video describes how to successfully install Eclipse. How to solve incompa…
Suggested Courses
Course of the Month18 days, 20 hours left to enroll

834 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