2

从 Java 7u21 开始,我在自己制作的 JavaFX 小程序中偶然发现了一些奇怪的行为。

在服务器端,我有一个 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>>() {});
}

URISystem.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 (64bit) 获取*

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]
4

1 回答 1

0

It all had to do with the same issues regarding this question:

Authentication required window popping up after 7u21 update

and follow up question:

basic authentication fails with glassfish

Answered by dennis-the-menace which you can find here:

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

于 2013-10-24T16:09:15.163 回答