我从不喜欢像Glassfish,Weblogic等这些重量级服务器,但我不得不通过Glassfish提供的http来暴露一些端点来做一些实现。在一个特定情况下,我必须向Glassfish服务器发送一个Post请求,该请求接受GZipped输入,解压缩并发回GZipped响应。以下是我到目前为止的情况:
在Glassfish服务器上:
@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()
}
}
我使用JBoss rest easy API来公开myService端点。在我的客户端,我设置了必要的标题(下面显示的代码段)
post.addHeader("Content-Encoding", "gzip")
post.addHeader("Accept-Encoding", "gzip, deflate")
但是当我运行我的客户端时,我认为这是响应:
[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)
......
......
这是我在服务器上看到的内容;
[#|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|#]
我也没有看到任何堆栈跟踪。有人可以帮忙解决问题吗?
答案 0 :(得分:1)
看起来我设法解决了这个问题。我做了以下事情:
使用最新版本的rest easy API(版本3.0.6.Final)反对使用旧版本2.2.1(请参阅此帖子http://sourceforge.net/p/resteasy/mailman/resteasy-developers/thread/BDED22DA-ACDC-47F5-9B14-30A202B52981@redhat.com/)
我在客户端添加了一个额外的标题(post.addHeader(&#34; Content-Type&#34;,&#34; application / json&#34;))
Bang it working!