1

我正在使用 Apache HTTPclient 4 将 SPARQL 查询发送到远程存储库。虽然程序相同,但我的 JAR 包得到的响应是 HTTP 406,错误消息是“找不到可接受的文件格式”。在 Eclipse 中,我的查询成功接收 HTTP 200 响应和所需的结果。

什么可能导致具有相同代码的两个环境运行不同?

Eclipse 消息:(HTTP 200)

19:32:23.584 [main] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager - HttpConnectionManager.getConnection:  config = HostConfiguration[host=http://asimov.ludat.lth.se], timeout = 0
19:32:23.585 [main] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager - Allocating new connection, hostConfig=HostConfiguration[host=http://asimov.ludat.lth.se]
19:32:23.585 [main] DEBUG o.a.c.httpclient.HttpConnection - Open connection to asimov.ludat.lth.se:80
19:32:23.589 [main] DEBUG httpclient.wire.header - >> "POST /openrdf-sesame/repositories/KnowRob HTTP/1.1[\r][\n]"
19:32:23.590 [main] DEBUG o.a.c.httpclient.HttpMethodBase - Adding Host request header
19:32:23.593 [main] DEBUG httpclient.wire.header - >> "Content-Type: application/x-www-form-urlencoded; charset=utf-8[\r][\n]"
19:32:23.594 [main] DEBUG httpclient.wire.header - >> "Accept: application/x-binary-rdf-results-table[\r][\n]"
19:32:23.594 [main] DEBUG httpclient.wire.header - >> "Accept: application/sparql-results+xml;q=0.8[\r][\n]"
19:32:23.595 [main] DEBUG httpclient.wire.header - >> "Accept: application/xml;q=0.8[\r][\n]"
19:32:23.596 [main] DEBUG httpclient.wire.header - >> "Accept: text/tab-separated-values;q=0.8[\r][\n]"
19:32:23.596 [main] DEBUG httpclient.wire.header - >> "Accept: text/csv;q=0.8[\r][\n]"
19:32:23.597 [main] DEBUG httpclient.wire.header - >> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
19:32:23.597 [main] DEBUG httpclient.wire.header - >> "Host: asimov.ludat.lth.se[\r][\n]"
19:32:23.598 [main] DEBUG httpclient.wire.header - >> "Content-Length: 836[\r][\n]"
19:32:23.598 [main] DEBUG httpclient.wire.header - >> "[\r][\n]"
19:32:23.599 [main] DEBUG httpclient.wire.content - >> "quer[...]rue"
19:32:23.600 [main] DEBUG o.a.c.h.m.EntityEnclosingMethod - Request body sent
19:32:24.304 [main] DEBUG httpclient.wire.header - << "HTTP/1.1 200 OK[\r][\n]"
19:32:24.304 [main] DEBUG httpclient.wire.header - << "HTTP/1.1 200 OK[\r][\n]"
19:32:24.305 [main] DEBUG httpclient.wire.header - << "Server: Apache-Coyote/1.1[\r][\n]"
19:32:24.305 [main] DEBUG httpclient.wire.header - << "Vary: Accept[\r][\n]"
19:32:24.306 [main] DEBUG httpclient.wire.header - << "Content-Disposition: attachment; filename=query-result.brt[\r][\n]"
19:32:24.306 [main] DEBUG httpclient.wire.header - << "Content-Type: application/x-binary-rdf-results-table;charset=ISO-8859-1[\r][\n]"
19:32:24.306 [main] DEBUG httpclient.wire.header - << "Content-Language: en-US[\r][\n]"
19:32:24.307 [main] DEBUG httpclient.wire.header - << "Transfer-Encoding: chunked[\r][\n]"
19:32:24.307 [main] DEBUG httpclient.wire.header - << "Date: Thu, 28 Feb 2013 18:28:24 GMT[\r][\n]"
19:32:24.307 [main] DEBUG httpclient.wire.header - << "[\r][\n]"
19:32:24.308 [main] DEBUG org.openrdf.http.client.HTTPClient - reponse MIME type is application/x-binary-rdf-results-table

JAR 消息:(HTTP 406)

19:15:35.178 [main] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager - HttpConnectionManager.getConnection:  config = HostConfiguration[host=http://asimov.ludat.lth.se], timeout = 0
19:15:35.179 [main] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager - Allocating new connection, hostConfig=HostConfiguration[host=http://asimov.ludat.lth.se]
19:15:35.179 [main] DEBUG o.a.c.httpclient.HttpConnection - Open connection to asimov.ludat.lth.se:80
19:15:35.183 [main] DEBUG httpclient.wire.header - >> "POST /openrdf-sesame/repositories/KnowRob HTTP/1.1[\r][\n]"
19:15:35.184 [main] DEBUG o.a.c.httpclient.HttpMethodBase - Adding Host request header
19:15:35.187 [main] DEBUG httpclient.wire.header - >> "Content-Type: application/x-www-form-urlencoded; charset=utf-8[\r][\n]"
19:15:35.188 [main] DEBUG httpclient.wire.header - >> "Accept: text/tab-separated-values;q=0.8[\r][\n]"
19:15:35.188 [main] DEBUG httpclient.wire.header - >> "Accept: text/csv;q=0.8[\r][\n]"
19:15:35.189 [main] DEBUG httpclient.wire.header - >> "User-Agent: Jakarta Commons-HttpClient/3.1[\r][\n]"
19:15:35.189 [main] DEBUG httpclient.wire.header - >> "Host: asimov.ludat.lth.se[\r][\n]"
19:15:35.189 [main] DEBUG httpclient.wire.header - >> "Content-Length: 836[\r][\n]"
19:15:35.190 [main] DEBUG httpclient.wire.header - >> "[\r][\n]"
19:15:35.191 [main] DEBUG httpclient.wire.content - >> "query[...]er=true"
19:15:35.191 [main] DEBUG o.a.c.h.m.EntityEnclosingMethod - Request body sent
19:15:35.717 [main] DEBUG httpclient.wire.header - << "HTTP/1.1 406 Not Acceptable[\r][\n]"
19:15:35.717 [main] DEBUG httpclient.wire.header - << "HTTP/1.1 406 Not Acceptable[\r][\n]"
19:15:35.718 [main] DEBUG httpclient.wire.header - << "Server: Apache-Coyote/1.1[\r][\n]"
19:15:35.718 [main] DEBUG httpclient.wire.header - << "Vary: Accept[\r][\n]"
19:15:35.718 [main] DEBUG httpclient.wire.header - << "Content-Type: text/plain;charset=UTF-8[\r][\n]"
19:15:35.719 [main] DEBUG httpclient.wire.header - << "Content-Language: en-US[\r][\n]"
19:15:35.719 [main] DEBUG httpclient.wire.header - << "Content-Length: 32[\r][\n]"
19:15:35.719 [main] DEBUG httpclient.wire.header - << "Date: Thu, 28 Feb 2013 18:11:35 GMT[\r][\n]"
19:15:35.720 [main] DEBUG httpclient.wire.header - << "[\r][\n]"
19:15:35.720 [main] DEBUG o.a.c.httpclient.HttpMethodBase - Buffering response body
19:15:35.720 [main] DEBUG httpclient.wire.content - << "No acceptable file format found."
19:15:35.721 [main] DEBUG o.a.c.httpclient.HttpMethodBase - Resorting to protocol version default close connection policy
19:15:35.721 [main] DEBUG o.a.c.httpclient.HttpMethodBase - Should NOT close connection, using HTTP/1.1
19:15:35.721 [main] DEBUG o.a.c.httpclient.HttpConnection - Releasing connection back to connection manager.
19:15:35.721 [main] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager - Freeing connection, hostConfig=HostConfiguration[host=http://asimov.ludat.lth.se]
19:15:35.722 [main] DEBUG o.a.c.h.util.IdleConnectionHandler - Adding connection at: 1362075335721
19:15:35.722 [main] DEBUG o.a.c.h.MultiThreadedHttpConnectionManager - Notifying no-one, there are no waiting threads
19:15:35.722 [main] WARN  org.openrdf.http.client.HTTPClient - Server reports problem: No acceptable file format found.
4

1 回答 1

1

在第一种情况下,您的应用程序/环境将标头发送为

19:32:23.594 [main] DEBUG httpclient.wire.header - >> 
"Accept: application/x-binary-rdf-results-table[\r][\n]"

但这在第二种情况下丢失了,因此您的第二种环境不能接受 type 的响应'application/x-binary-rdf-results-table'。你在哪里运行你的第二个查询?jar 部署在哪里?您可能需要将此编码/类型添加到您的应用服务器。

我不太清楚你在哪里使用它,但好的起点是看看为什么"Accept: application/x-binary-rdf-results-table在第二种情况下丢失。

于 2013-02-28T18:42:42.503 回答