从Java 7u21开始,我偶然发现了我制作的JavaFX小程序中的一些奇怪行为。
在服务器端,我有一个Glassfish 3服务器和一个mysql数据库。在客户端,我使用Jersey通过向我的Glassfish服务器发送请求来从db获取数据。当我通过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(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]
最佳答案
关于这个问题,所有这些都与相同的问题有关:
Authentication required window popping up after 7u21 update
并跟进问题:
basic authentication fails with glassfish
您可以在这里找到dennis-the-ace的回答:
https://stackoverflow.com/a/18362271/1527284