I get a HTTPException 407 when trying to query a SPARQL Service. I have to use a proxy which requires username and password.
My code for the authentification looks as follows:
HttpAuthenticator authenticator = new PreemptiveBasicAuthenticator(new SimpleAuthenticator(USERNAME, PASSWORD),true);
Then I try to query as follows:
QueryExecution qexec = QueryExecutionFactory.sparqlService(serverUrl, query,
authenticator);
qexec.execSelect();
In the jvm arguments I pass -Dhttp.proxyHost
and -Dhttp.proxyPort
.
The confusing thing is that if I try to connect to google, it works with my proxy setting. Even without username/password.
String strUrl = "http://www.google.com";
URL url = new URL(strUrl);
HttpURLConnection urlConn = (HttpURLConnection) url.openConnection();
urlConn.connect();
If I try to connect to the sparql endpoint I get a HTTP 407 error. I can reach the endpoint in the browser and also my colleague has access to the endpoint.
In the documentation they say that the boolean in the PreemptiveBasicAuthenticator
Constructor is for proxy useage. That's why I tried it with this code.
Edit: Logging Information
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]