Domanda

I never liked these heavy weight servers like Glassfish, Weblogic etc., but I had to do some implementation by exposing some of the endpoints through http served via Glassfish. In one particular case, I have to send to the Glassfish server a Post request that takes a GZipped input, decompresses it and send a GZipped response back. Here is what I have so far:

On the Glassfish Server:

@Path("/")
class MyService extends BaseService {

  @POST
  @Path("/myService")
  @Consumes(Array("application/json"))
  @Produces(Array("application/json"))
  @GZIP
  def myService(@GZIP json: String): Response = {
    println("Message received") // Not getting printed as well!!!
    Response.status(200).header("Content-Encoding", "gzip").entity(JsonMarshall.deserialize(json)).build()
  }
}

I'm using the JBoss rest easy API's to expose myService endpoint. In my client, I set the necessary headers (snippet shown below)

  post.addHeader("Content-Encoding", "gzip")
  post.addHeader("Accept-Encoding", "gzip, deflate")

But when I run my client, here is what I see as response:

[main] INFO ServerPingTest - Calling URL http://localhost:8080/glassfish-server/myService
[main] INFO ServerPingTest - --- RESPONSE HEADERS ---
[main] INFO ServerPingTest - X-Powered-By: Servlet/3.1 JSP/2.3 (GlassFish Server Open Source Edition  4.0  Java/Oracle Corporation/1.7)
[main] INFO ServerPingTest - Server: GlassFish Server Open Source Edition  4.0 
[main] INFO ServerPingTest - Content-Language: 
[main] INFO ServerPingTest - Content-Type: text/html
[main] INFO ServerPingTest - Date: Tue, 11 Mar 2014 16:39:17 GMT
[main] INFO ServerPingTest - Content-Length: 1217
[main] ERROR ServerPingTest - Error occurred when ping testing !!!!! Please see the stacktrace below!
java.util.zip.ZipException: Not in GZIP format
    at java.util.zip.GZIPInputStream.readHeader(GZIPInputStream.java:164)
    at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:78)
    at java.util.zip.GZIPInputStream.<init>(GZIPInputStream.java:90)
    ......
    ......

This is what I see on the server;

[#|2014-03-11T17:39:17.557+0100|SEVERE|glassfish 4.0||_ThreadID=21;_ThreadName=Thread-4;_TimeMillis=1394555957557;_LevelValue=1000;|
  [http-listener-1(3)] WARN org.jboss.resteasy.core.SynchronousDispatcher - Failed executing POST /myService|#]

I also do not see any stack trace. Can anyone please help as to what went wrong?

È stato utile?

Soluzione

Looks like I have managed to solve this. I did the following:

  1. Used the latest version of the rest easy API (version 3.0.6.Final) against using an older version 2.2.1 (See this post http://sourceforge.net/p/resteasy/mailman/resteasy-developers/thread/BDED22DA-ACDC-47F5-9B14-30A202B52981@redhat.com/)

  2. I added an additional header on my client (post.addHeader("Content-Type", "application/json"))

Bang it worked!

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top