Proxy Jena代理身份验证
在尝试查询SPARQL服务时,我得到一个HTTPException 407。我必须使用需要用户名和密码的代理 我的身份验证代码如下所示:Proxy Jena代理身份验证,proxy,sparql,jena,Proxy,Sparql,Jena,在尝试查询SPARQL服务时,我得到一个HTTPException 407。我必须使用需要用户名和密码的代理 我的身份验证代码如下所示: HttpAuthenticator authenticator = new PreemptiveBasicAuthenticator(new SimpleAuthenticator(USERNAME, PASSWORD),true); QueryExecution qexec = QueryExecutionFactory.sparqlService(ser
HttpAuthenticator authenticator = new PreemptiveBasicAuthenticator(new SimpleAuthenticator(USERNAME, PASSWORD),true);
QueryExecution qexec = QueryExecutionFactory.sparqlService(serverUrl, query,
authenticator);
qexec.execSelect();
然后我尝试如下查询:
HttpAuthenticator authenticator = new PreemptiveBasicAuthenticator(new SimpleAuthenticator(USERNAME, PASSWORD),true);
QueryExecution qexec = QueryExecutionFactory.sparqlService(serverUrl, query,
authenticator);
qexec.execSelect();
在jvm参数中,我传递-Dhttp.proxyHost
和-Dhttp.proxyPort
令人困惑的是,如果我尝试连接到谷歌,它会与我的代理设置一起工作。即使没有用户名/密码
String strUrl = "http://www.google.com";
URL url = new URL(strUrl);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.connect();
String strUrl = "http://www.google.com";
URL url = new URL(strUrl);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.connect();
如果尝试连接到sparql端点,则会出现HTTP 407错误。我可以在浏览器中访问端点,我的同事也可以访问端点
在文档中,他们说,PreemptiveBasicAuthenticator
构造函数中的布尔值用于代理使用。这就是为什么我试着用这个代码
编辑:
记录信息
DEBUG 27139 [2014-03-18 14:05:37,970] [main] org.apache.http.impl.conn.PoolingClientConnectionManager - Connection request: [route: {}->http:*:81->http:*.com][total kept alive: 0; route allocated: 0 of 5; total allocated: 0 of 10]
DEBUG 27146 [2014-03-18 14:05:37,977] [main] org.apache.http.impl.conn.PoolingClientConnectionManager - Connection leased: [id: 0][route: {}->http:*:81->http:*.com][total kept alive: 0; route allocated: 1 of 5; total allocated: 1 of 10]
DEBUG 27148 [2014-03-18 14:05:37,979] [main] org.apache.http.impl.conn.DefaultClientConnectionOperator - Connecting to proxy.*:81
DEBUG 27162 [2014-03-18 14:05:37,993] [main] org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: best-match
DEBUG 27164 [2014-03-18 14:05:37,995] [main] org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context
DEBUG 27164 [2014-03-18 14:05:37,995] [main] org.apache.http.client.protocol.RequestTargetAuthentication - Target auth state: UNCHALLENGED
DEBUG 27165 [2014-03-18 14:05:37,996] [main] org.apache.http.client.protocol.RequestProxyAuthentication - Proxy auth state: UNCHALLENGED
DEBUG 27166 [2014-03-18 14:05:37,997] [main] org.apache.http.impl.client.SystemDefaultHttpClient - Attempt 1 to execute request
DEBUG 27166 [2014-03-18 14:05:37,997] [main] org.apache.http.impl.conn.DefaultClientConnection - Sending request: GET http:* HTTP/1.1
DEBUG 27168 [2014-03-18 14:05:37,999] [main] org.apache.http.wire - >> "GET http:* HTTP/1.1[\r][\n]"
DEBUG 27169 [2014-03-18 14:05:38,000] [main] org.apache.http.wire - >> "Accept: application/sparql-results+xml[\r][\n]"
DEBUG 27169 [2014-03-18 14:05:38,000] [main] org.apache.http.wire - >> "User-Agent: Apache-Jena-ARQ/2.11.1[\r][\n]"
DEBUG 27170 [2014-03-18 14:05:38,001] [main] org.apache.http.wire - >> "Accept-Encoding: gzip,deflate[\r][\n]"
DEBUG 27170 [2014-03-18 14:05:38,001] [main] org.apache.http.wire - >> "Host: *[\r][\n]"
DEBUG 27171 [2014-03-18 14:05:38,002] [main] org.apache.http.wire - >> "Proxy-Connection: Keep-Alive[\r][\n]"
DEBUG 27171 [2014-03-18 14:05:38,002] [main] org.apache.http.wire - >> "[\r][\n]"
DEBUG 27171 [2014-03-18 14:05:38,002] [main] org.apache.http.headers - >> GET http:* HTTP/1.1
DEBUG 27172 [2014-03-18 14:05:38,003] [main] org.apache.http.headers - >> Accept: application/sparql-results+xml
DEBUG 27173 [2014-03-18 14:05:38,004] [main] org.apache.http.headers - >> User-Agent: Apache-Jena-ARQ/2.11.1
DEBUG 27173 [2014-03-18 14:05:38,004] [main] org.apache.http.headers - >> Accept-Encoding: gzip,deflate
DEBUG 27173 [2014-03-18 14:05:38,004] [main] org.apache.http.headers - >> Host: *
DEBUG 27173 [2014-03-18 14:05:38,004] [main] org.apache.http.headers - >> Proxy-Connection: Keep-Alive
DEBUG 27178 [2014-03-18 14:05:38,009] [main] org.apache.http.wire - << "HTTP/1.1 407 Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. )[\r][\n]"
DEBUG 27179 [2014-03-18 14:05:38,010] [main] org.apache.http.wire - << "Via: 1.1 *[\r][\n]"
DEBUG 27179 [2014-03-18 14:05:38,010] [main] org.apache.http.wire - << "Proxy-Authenticate: Negotiate[\r][\n]"
DEBUG 27179 [2014-03-18 14:05:38,010] [main] org.apache.http.wire - << "Proxy-Authenticate: Kerberos[\r][\n]"
DEBUG 27180 [2014-03-18 14:05:38,011] [main] org.apache.http.wire - << "Proxy-Authenticate: NTLM[\r][\n]"
DEBUG 27180 [2014-03-18 14:05:38,011] [main] org.apache.http.wire - << "Connection: Keep-Alive[\r][\n]"
DEBUG 27180 [2014-03-18 14:05:38,011] [main] org.apache.http.wire - << "Proxy-Connection: Keep-Alive[\r][\n]"
DEBUG 27181 [2014-03-18 14:05:38,012] [main] org.apache.http.wire - << "Pragma: no-cache[\r][\n]"
DEBUG 27181 [2014-03-18 14:05:38,012] [main] org.apache.http.wire - << "Cache-Control: no-cache[\r][\n]"
DEBUG 27181 [2014-03-18 14:05:38,012] [main] org.apache.http.wire - << "Content-Type: text/html[\r][\n]"
DEBUG 27182 [2014-03-18 14:05:38,013] [main] org.apache.http.wire - << "Content-Length: 894 [\r][\n]"
DEBUG 27182 [2014-03-18 14:05:38,013] [main] org.apache.http.wire - << "[\r][\n]"
DEBUG 27183 [2014-03-18 14:05:38,014] [main] org.apache.http.impl.conn.DefaultClientConnection - Receiving response: HTTP/1.1 407 Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. )
DEBUG 27183 [2014-03-18 14:05:38,014] [main] org.apache.http.headers - << HTTP/1.1 407 Proxy Authentication Required ( Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. )
DEBUG 27183 [2014-03-18 14:05:38,014] [main] org.apache.http.headers - << Via: 1.1 *
DEBUG 27184 [2014-03-18 14:05:38,015] [main] org.apache.http.headers - << Proxy-Authenticate: Negotiate
DEBUG 27184 [2014-03-18 14:05:38,015] [main] org.apache.http.headers - << Proxy-Authenticate: Kerberos
DEBUG 27184 [2014-03-18 14:05:38,015] [main] org.apache.http.headers - << Proxy-Authenticate: NTLM
DEBUG 27185 [2014-03-18 14:05:38,016] [main] org.apache.http.headers - << Connection: Keep-Alive
DEBUG 27185 [2014-03-18 14:05:38,016] [main] org.apache.http.headers - << Proxy-Connection: Keep-Alive
DEBUG 27185 [2014-03-18 14:05:38,016] [main] org.apache.http.headers - << Pragma: no-cache
DEBUG 27185 [2014-03-18 14:05:38,016] [main] org.apache.http.headers - << Cache-Control: no-cache
DEBUG 27186 [2014-03-18 14:05:38,017] [main] org.apache.http.headers - << Content-Type: text/html
DEBUG 27186 [2014-03-18 14:05:38,017] [main] org.apache.http.headers - << Content-Length: 894
DEBUG 27187 [2014-03-18 14:05:38,018] [main] org.apache.http.impl.client.SystemDefaultHttpClient - Connection can be kept alive indefinitely
DEBUG 27187 [2014-03-18 14:05:38,018] [main] org.apache.http.impl.client.SystemDefaultHttpClient - Authentication required
DEBUG 27187 [2014-03-18 14:05:38,018] [main] org.apache.http.impl.client.SystemDefaultHttpClient - proxy*:81 requested authentication
DEBUG 27188 [2014-03-18 14:05:38,019] [main] org.apache.http.impl.client.ProxyAuthenticationStrategy - Authentication schemes in the order of preference: [negotiate, Kerberos, NTLM, Digest, Basic]
DEBUG 27189 [2014-03-18 14:05:38,020] [main] org.apache.http.impl.auth.SPNegoScheme - Received challenge '' from the auth server
DEBUG 27190 [2014-03-18 14:05:38,021] [main] org.apache.http.impl.auth.KerberosScheme - Received challenge '' from the auth server
DEBUG 27190 [2014-03-18 14:05:38,021] [main] org.apache.http.impl.client.ProxyAuthenticationStrategy - Challenge for Digest authentication scheme not available
DEBUG 27190 [2014-03-18 14:05:38,021] [main] org.apache.http.impl.client.ProxyAuthenticationStrategy - Challenge for Basic authentication scheme not available
DEBUG 27198 [2014-03-18 14:05:38,029] [main] org.apache.http.wire - << "<HTML><HEAD>[\r][\n]"
DEBUG 27198 [2014-03-18 14:05:38,029] [main] org.apache.http.wire - << "<TITLE>Proxy Error Message</TITLE>[\r][\n]"
DEBUG 27198 [2014-03-18 14:05:38,029] [main] org.apache.http.wire - << "</HEAD>[\r][\n]"
DEBUG 27199 [2014-03-18 14:05:38,030] [main] org.apache.http.wire - << "<frameset cols="*">[\r][\n]"
DEBUG 27199 [2014-03-18 14:05:38,030] [main] org.apache.http.wire - << "[0x9]<frame src="http:* Proxy Authentication Required&err=Forefront TMG requires authorization to fulfill the request. Access to the Web Proxy filter is denied. &proxy=*&time=18.03.2014 13:05:38 [GMT]&isa=1&errorhtml=default.htm" name="ProxyError"> [\r][\n]"
DEBUG 27200 [2014-03-18 14:05:38,031] [main] org.apache.http.wire - << " <noframes>[\r][\n]"
DEBUG 27200 [2014-03-18 14:05:38,031] [main] org.apache.http.wire - << " If this site does not automatically reload, click <a href="*">here</a> [\r][\n]"
DEBUG 27201 [2014-03-18 14:05:38,032] [main] org.apache.http.wire - << " </noframes>[\r][\n]"
DEBUG 27201 [2014-03-18 14:05:38,032] [main] org.apache.http.wire - << "</frameset>[\r][\n]"
DEBUG 27202 [2014-03-18 14:05:38,033] [main] org.apache.http.wire - << "</HTML>[\r][\n]"
DEBUG 27202 [2014-03-18 14:05:38,033] [main] org.apache.http.impl.conn.PoolingClientConnectionManager - Connection [id: 0][route: {}->http:*:81->http:* can be kept alive indefinitely
DEBUG 27203 [2014-03-18 14:05:38,034] [main] org.apache.http.impl.conn.PoolingClientConnectionManager - Connection released: [id: 0][route: {}->http:*:81->http:*][total kept alive: 1; route allocated: 1 of 5; total allocated: 1 of 10]
DEBUG 27139[2014-03-18 14:05:37970][main]org.apache.http.impl.conn.poolgclientconnectionmanager-连接请求:[路由:{}->http:::::81->http:.com][总保持活动状态:0;分配的路由:0/5;分配的路由:0/10]
调试27146[2014-03-18 14:05:37977][main]org.apache.http.impl.conn.poolgclientconnectionmanager-租用的连接:[id:0][route:{}->http::::81->http:.com][总保持活动状态:0;分配的路由:5个中的1个;分配的总路由:10个中的1个]
调试27148[2014-03-18 14:05:37979][main]org.apache.http.impl.conn.DefaultClientConnectionOperator-连接到代理。*:81
调试27162[2014-03-18 14:05:37993][main]org.apache.http.client.protocol.RequestAddCookies-CookieSpec选中:最佳匹配
调试27164[2014-03-18 14:05:37995][main]org.apache.http.client.protocol.RequestAuthCache-未在上下文中设置Auth缓存
DEBUG 27164[2014-03-18 14:05:37995][main]org.apache.http.client.protocol.RequestTargetAuthentication-目标身份验证状态:未被质询
DEBUG 27165[2014-03-18 14:05:37996][main]org.apache.http.client.protocol.RequestProxyAuthentication-代理身份验证状态:未被质询
调试27166[2014-03-18 14:05:37997][main]org.apache.http.impl.client.SystemDefaultHttpClient-尝试1执行请求
调试27166[2014-03-18 14:05:37997][main]org.apache.http.impl.conn.DefaultClientConnection-发送请求:获取http:*http/1.1
调试27168[2014-03-18 14:05:37999][main]org.apache.http.wire->“获取http:*http/1.1[\r][\n]”
调试27169[2014-03-18 14:05:38000][main]org.apache.http.wire->“接受:应用程序/sparql结果+xml[\r][\n]”
调试27169[2014-03-18 14:05:38000][main]org.apache.http.wire->“用户代理:apache Jena ARQ/2.11.1[\r][\n]”
调试27170[2014-03-18 14:05:38001][main]org.apache.http.wire->“接受编码:gzip,解压缩[\r][\n]”
调试27170[2014-03-18 14:05:38001][main]org.apache.http.wire->“主机:[\r][\n]”
调试27171[2014-03-18 14:05:38002][main]org.apache.http.wire->>“代理连接:保持活动[\r][\n]”
调试27171[2014-03-18 14:05:38002][main]org.apache.http.wire->>“[\r][\n]”
调试27171[2014-03-18 14:05:38002][main]org.apache.http.headers->>获取http:*http/1.1
调试27172[2014-03-18 14:05:38003][main]org.apache.http.headers->>Accept:application/sparql results+xml
调试27173[2014-03-18 14:05:38004][main]org.apache.http.headers->>用户代理:apache Jena ARQ/2.11.1
调试27173[2014-03-18 14:05:38004][main]org.apache.http.headers->>接受编码:gzip,deflate
调试27173[2014-03-18 14:05:38004][main]org.apache.http.headers->>主机:*
调试27173[2014-03-18 14:05:38004][main]org.apache.http.headers->>代理连接:保持活动状态
DEBUG 27178[2014-03-18 14:05:38009][main]org.apache.http.wire-HttpAuthenticator
适用于您正在查询的远程端点,而不是代理
您需要将http.proxyUser
和http.proxyPassword
设置为JVM参数或设置代理身份验证器
参见导致的示例。令人困惑的是,如果我尝试连接到谷歌,它会与我的代理设置一起工作。即使没有用户名/密码
String strUrl = "http://www.google.com";
URL url = new URL(strUrl);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.connect();
String strUrl = "http://www.google.com";
URL url = new URL(strUrl);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.connect();
如果尝试连接到sparql端点,则会出现HTTP 407错误。我可以在浏览器中访问端点,我的同事也可以访问端点
在文档中,他们说PreemptiveBasicAuthenticator构造函数中的布尔值用于代理使用。这就是为什么我尝试使用这段代码。当抢占式身份验证适用于代理时
使用PreemptiveBasicAuthenticator
并将forProxy
参数设置为true仅在某些情况下相关:
- 您的代理服务器需要身份验证(似乎就是这种情况)
- 代理服务器使用基本HTTP身份验证
从您获得HTTP 407的事实来看,这意味着您的代理服务器不支持基本的HTTP身份验证,并且可能要求您执行摘要或其他类型的HTTP身份验证
调试出了什么问题
请注意,ARQ使用后台,因此您可以打开日志来查看详细的HTTP跟踪。将org.apache.http
包的日志级别设置为DEBUG
,以查看有关请求和响应的一般信息,并将其一直设置为TRACE
,以查看详细的http跟踪,这将允许您精确查看代理返回的响应
特别是要查看服务器响应中的代理身份验证
标头包含的内容,如果此标头的内容不包含单词Basic
,则不能使用PreemptiveBasicAuthenticator
使用非基本身份验证
如果服务器不支持基本身份验证,则您可以直接使用,这将支持基本/摘要身份验证方案,因此可以解决身份验证问题,例如:
HttpAuthenticator authenticator = new SimpleAuthenticator(USERNAME, PASSWORD);
编辑
然而在你的c