有效URI导致Content-Length:-1

时间:2013-06-05 19:09:00

标签: java rest jersey uri

自Java 7u21以来,我偶然发现了我制作的JavaFX applet中的一些奇怪行为。

在服务器端,我有一个Glassfish 3服务器和一个mysql数据库。在客户端,我使用Jersey通过向Glassfish服务器发送请求来从数据库中获取数据。当我通过JAR文件启动程序时,一切正常,但是当我通过我的JNLP文件启动它时,我注意到自7u21以来的一些奇怪的行为。让我试着告诉你:

我做了一个简单的请求,它应该给出一个XML响应:

方法(客户端):

public List<Users> getUsersHierarchyTreeFilteredByUserlevel(int id, int betweenStart, int betweenEnd) throws UniformInterfaceException {
    WebResource resource = webResource;
    resource = resource.path(java.text.MessageFormat.format("users/{0}/hierarchy", String.valueOf(id))).queryParam("start", "" + String.valueOf(betweenStart)).queryParam("end", "" + String.valueOf(betweenEnd));
    System.out.println(resource.getURI());
    return resource.accept(javax.ws.rs.core.MediaType.APPLICATION_XML).get(new GenericType<List<Users>>() {});
}

URI System.out.println(resource.getURI());

http://localhost:8080/myWS/webresources/entities.users/users/4/hierarchy?start=5&end=5

Java控制台:

network: Cache entry not found [url: http://localhost:8080/myWS/webresources/entities.users/users/4/hierarchy?start=5&end=5, version: null]
network: Connecting http://localhost:8080/myWS/webresources/entities.users/users/4/hierarchy?start=5&end=5 with proxy=DIRECT
network: Connecting socket://localhost:8080 with proxy=DIRECT
network: Downloading resource: http://localhost:8080/myWS/webresources/entities.users/users/4/hierarchy?start=5&end=5
Content-Length: -1
Content-Encoding: null
network: Wrote URL http://localhost:8080/myWS/webresources/entities.users/users/4/hierarchy?start=5&end=5 to File C:\Users\Steven\AppData\LocalLow\Sun\Java\Deployment\cache\6.0\33\d7edc21-130fad10-temp
cache: Adding MemoryCache entry: http://localhost:8080/myWS/webresources/entities.users/users/4/hierarchy
java.io.IOException: stream is closed

正如您所看到的,我收到了IOException。这似乎发生在 getUsersHierarchyTreeFilteredByUserlevel(...)方法中的 resource.accept(...)。但是,当我在浏览器中粘贴URI时,它会显示正确的XML数据吗?我不知道为什么......它在运行JAR本身或使用7u17时有效。

有什么想法吗? 提前谢谢!

更新 * 使用wget(64位) *

获取
D:\>WGET64.EXE -S --http-user=*** --http-passwd=*** "http://localhost:8080/myWS/webresources/entities.users/users/4/hierarchy?start=5&end=5"
--22:06:53--  http://localhost:8080/myWS/webresources/entities.users/users/4/hierarchy?start=5&end=5
       => `hierarchy@start=5&end=5'
Resolving localhost... 127.0.0.1
Connecting to localhost[127.0.0.1]:8080... connected.
HTTP request sent, awaiting response...
 1 HTTP/1.1 200 OK
 2 X-Powered-By: Servlet/3.0 JSP/2.2 (GlassFish Server Open Source Edition 3.1.2.2 Java/Oracle Corporation/1.7)
 3 Server: GlassFish Server Open Source Edition 3.1.2.2
 4 Pragma: No-cache
 5 Cache-Control: no-cache
 6 Expires: Thu, 01 Jan 1970 01:00:00 CET
 7 Content-Type: application/xml
 8 Date: Wed, 05 Jun 2013 20:06:53 GMT
 9 Connection: close

    [ <=>                                 ] 9,610         --.--K/s

22:06:53 (9.16 MB/s) - `hierarchy@start=5&end=5' saved [9610]

1 个答案:

答案 0 :(得分:0)

这一切都与这个问题的相同问题有关:

Authentication required window popping up after 7u21 update

并跟进问题:

basic authentication fails with glassfish

你可以在这里找到dennis-the-menace的答案:

https://stackoverflow.com/a/18362271/1527284