Solved

I want to Zip the Web Service Response

Posted on 2013-01-08
8
456 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
Question by:stmani2005
  • 4
  • 4
8 Comments
 
LVL 16

Expert Comment

by:Valeri
ID: 38754527
0
 
LVL 8

Author Comment

by:stmani2005
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
 
LVL 8

Author Comment

by:stmani2005
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
DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

 
LVL 8

Author Comment

by:stmani2005
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 8

Author Comment

by:stmani2005
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
for i loop in grovy 1 44
Java and GPO 11 66
Java DateChooser? 3 29
Windows 10 and JDK 7 7u85 4 31
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…
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

919 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

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now