hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Oleg Kalnichevski <ol...@apache.org>
Subject Re: Problem in HTTPClient over SSL thru Proxy
Date Thu, 15 Jun 2006 12:45:13 GMT
On Thu, 2006-06-15 at 17:22 +0530, Sanjeev Kumar Neemkar wrote:
> Hi,
>  Am trying to connect to the secure URL say for instance "
> https://java.sun.com/".
>  But unable to get the respose from the server with exception as
>  "Failed to download file.
> org.apache.commons.httpclient.NoHttpResponseException: " (please see full
> logs below)
> 
>  By trying same piece of code with non-secure URL as "http://java.sun.com/",
> able to get the web page content as response.
>  Is there any specifics to be considered in the below code to handle the
> HTTPS case for proxy server settings.
> 

Sanjeev,

(1) What is the proxy server you are sending requests through? Does it
support HTTP/1.1? Anyways, try using HTTP/1.0 and see if that makes any
difference
(2) Fix all deprecation warnings in your code just in case

Oleg

> 
> Sanjeev Kumar
> ----------------------------------------------------------------------------------------------------
> package com.test;
> 
> import java.io.IOException;
> 
> import org.apache.commons.httpclient.Credentials;
> import org.apache.commons.httpclient.DefaultMethodRetryHandler;
> import org.apache.commons.httpclient.HttpClient;
> import org.apache.commons.httpclient.HttpStatus;
> import org.apache.commons.httpclient.UsernamePasswordCredentials;
> import org.apache.commons.httpclient.auth.AuthScope;
> import org.apache.commons.httpclient.methods.GetMethod;
> import org.apache.log4j.BasicConfigurator;
> import org.apache.log4j.Logger;
> 
> import com.adp.ttscli.util.CLIConstants;
> 
> public class MyHttpClient {
> 
>  private static String url = "https://java.sun.com/";
> 
>  static String proxy_host = "proxy.host.comes.here";
>  static int proxy_port = 8080;
> 
>  public static void main(String[] args) {
>   HttpClient client = new HttpClient();
>   GetMethod method = new GetMethod(url);
>   //setProxy(String proxyHost, int proxyPort)
>   client.getHostConfiguration().setProxy(proxy_host, proxy_port);
>   Credentials creds = new UsernamePasswordCredentials("test", "test");
>   //use a null realm
>   client.getState().setProxyCredentials(null, proxy_host, creds);
>   //enable preemptive authentication
>   client.getState().setAuthenticationPreemptive(true);
> 
>   Logger logger = Logger.getLogger(MyHttpClient.class);
>   BasicConfigurator.configure();
>   logger.info("Entering application.");
>   DefaultMethodRetryHandler retryhandler = new DefaultMethodRetryHandler();
>   retryhandler.setRequestSentRetryEnabled(false);
>   retryhandler.setRetryCount(1);
>   method.setMethodRetryHandler(retryhandler);
> 
>   try {
>    int statusCode = client.executeMethod(method);
> 
>    if (statusCode != HttpStatus.SC_OK) {
>     System.err.println("Method failed: " + method.getStatusLine());
>    }
> 
>    byte[] responseBody = method.getResponseBody();
> 
>    System.out.println("**********************");
>    //System.out.println(new String(responseBody));
>   } catch (IOException e) {
>    System.err.println("Failed to download file.");
>    e.printStackTrace();
>   } finally {
>    method.releaseConnection();
>   }
>  }
> }
> 
> 
> Below are the logs generated with http client wire ..................
> ----------------------------------------------------------------------
> 
> log4j:WARN No appenders could be found for logger (
> org.apache.commons.httpclient.HttpClient).
> log4j:WARN Please initialize the log4j system properly.
> 594 [main] INFO com.test.MyHttpClient  - Entering application.
> 594 [main] DEBUG org.apache.commons.httpclient.HttpClient  - enter
> HttpClient.executeMethod(HttpMethod)
> 594 [main] DEBUG org.apache.commons.httpclient.HttpClient  - enter
> HttpClient.executeMethod(HostConfiguration,HttpMethod,HttpState)
> 610 [main] DEBUG org.apache.commons.httpclient.HttpMethodDirector  -
> Preemptively sending default basic credentials
> 625 [main] DEBUG org.apache.commons.httpclient.HttpMethodDirector  -
> Authenticating with BASIC <any realm>@java.sun.com:443
> 625 [main] DEBUG org.apache.commons.httpclient.HttpState  - enter
> HttpState.getCredentials(AuthScope)
> 625 [main] WARN org.apache.commons.httpclient.HttpMethodDirector  - Required
> credentials not available for BASIC <any realm>@java.sun.com:443
> 625 [main] WARN org.apache.commons.httpclient.HttpMethodDirector  -
> Preemptive authentication requested but no default credentials available
> 625 [main] DEBUG org.apache.commons.httpclient.HttpMethodDirector  - Attempt
> number 1 to process request
> 625 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.open()
> 625 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - Open
> connection to proxy.host.comes.here":8080
> 641 [main] DEBUG org.apache.commons.httpclient.HttpMethodDirector  -
> Preemptively sending default basic credentials
> 641 [main] DEBUG org.apache.commons.httpclient.HttpMethodDirector  -
> Authenticating with BASIC <any realm>@proxy.host.comes.here":8080
> 641 [main] DEBUG org.apache.commons.httpclient.HttpState  - enter
> HttpState.getProxyCredentials(AuthScope)
> 641 [main] DEBUG org.apache.commons.httpclient.auth.BasicScheme  - enter
> BasicScheme.authenticate(Credentials, HttpMethod)
> 641 [main] DEBUG org.apache.commons.httpclient.params.HttpMethodParams  -
> Credential charset not configured, using HTTP element charset
> 766 [main] DEBUG org.apache.commons.httpclient.auth.BasicScheme  - enter
> BasicScheme.authenticate(UsernamePasswordCredentials, String)
> 766 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  -
> HttpMethodBase.addRequestHeader(Header)
> 766 [main] DEBUG org.apache.commons.httpclient.ConnectMethod  - enter
> ConnectMethod.execute(HttpState, HttpConnection)
> 766 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.execute(HttpState, HttpConnection)
> 766 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.writeRequest(HttpState, HttpConnection)
> 766 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.printLine(String)
> 766 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.writeLine(byte[])
> 766 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 766 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 766 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.writeLine()
> 766 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 766 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 766 [main] DEBUG httpclient.wire.header  - >> "CONNECT java.sun.com:443HTTP/1.1"
> 766 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection)
> 766 [main] DEBUG org.apache.commons.httpclient.ConnectMethod  - enter
> ConnectMethod.addRequestHeaders(HttpState, HttpConnection)
> 782 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection)
> 782 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection)
> 782 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - Adding Host
> request header
> 782 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.addProxyConnectionHeader(HttpState, HttpConnection)
> 782 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  -
> HttpMethodBase.addRequestHeader(Header)
> 782 [main] DEBUG httpclient.wire.header  - >> "Proxy-Authorization: Basic
> dGVzdDp0ZXN0[\r][\n]"
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.print(String)
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 782 [main] DEBUG httpclient.wire.header  - >> "User-Agent: Jakarta
> Commons-HttpClient/3.0[\r][\n]"
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.print(String)
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 782 [main] DEBUG httpclient.wire.header  - >> "Host: java.sun.com[\r][\n]"
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.print(String)
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 782 [main] DEBUG httpclient.wire.header  - >> "Proxy-Connection:
> Keep-Alive[\r][\n]"
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.print(String)
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.writeLine()
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 782 [main] DEBUG httpclient.wire.header  - >> "[\r][\n]"
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.flushRequestOutputStream()
> 782 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.readResponse(HttpState, HttpConnection)
> 782 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.readStatusLine(HttpState, HttpConnection)
> 782 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.readLine()
> 782 [main] DEBUG org.apache.commons.httpclient.HttpParser  - enter
> HttpParser.readLine(InputStream, String)
> 782 [main] DEBUG org.apache.commons.httpclient.HttpParser  - enter
> HttpParser.readRawLine()
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodDirector  -
> Closing the connection.
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.close()
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.closeSockedAndStreams()
> 23762 [main] INFO org.apache.commons.httpclient.HttpMethodDirector  - I/O
> exception (org.apache.commons.httpclient.NoHttpResponseException) caught
> when processing request: The server java.sun.com failed to respond
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodDirector  - The
> server java.sun.com failed to respond
> org.apache.commons.httpclient.NoHttpResponseException: The server
> java.sun.com failed to respond
>  at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(Unknown
> Source)
>  at org.apache.commons.httpclient.HttpMethodBase.readResponse(Unknown
> Source)
>  at org.apache.commons.httpclient.HttpMethodBase.execute(Unknown Source)
>  at org.apache.commons.httpclient.ConnectMethod.execute(Unknown Source)
>  at org.apache.commons.httpclient.HttpMethodDirector.executeConnect(Unknown
> Source)
>  at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Unknown
> Source)
>  at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(Unknown
> Source)
>  at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source)
>  at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source)
>  at com.test.MyHttpClient.main(MyHttpClient.java:56)
> 23762 [main] INFO org.apache.commons.httpclient.HttpMethodDirector  -
> Retrying request
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodDirector  -
> Attempt number 2 to process request
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.open()
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - Open
> connection to proxy.host.comes.here":8080
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodDirector  -
> Preemptively sending default basic credentials
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodDirector  -
> Authenticating with BASIC <any realm>@proxy.host.comes.here":8080
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpState  - enter
> HttpState.getProxyCredentials(AuthScope)
> 23762 [main] DEBUG org.apache.commons.httpclient.auth.BasicScheme  - enter
> BasicScheme.authenticate(Credentials, HttpMethod)
> 23762 [main] DEBUG org.apache.commons.httpclient.params.HttpMethodParams  -
> Credential charset not configured, using HTTP element charset
> 23762 [main] DEBUG org.apache.commons.httpclient.auth.BasicScheme  - enter
> BasicScheme.authenticate(UsernamePasswordCredentials, String)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  -
> HttpMethodBase.addRequestHeader(Header)
> 23762 [main] DEBUG org.apache.commons.httpclient.ConnectMethod  - enter
> ConnectMethod.execute(HttpState, HttpConnection)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.execute(HttpState, HttpConnection)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.writeRequest(HttpState, HttpConnection)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.printLine(String)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.writeLine(byte[])
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.writeLine()
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 23762 [main] DEBUG httpclient.wire.header  - >> "CONNECT
> java.sun.com:443HTTP/1.1"
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.writeRequestHeaders(HttpState,HttpConnection)
> 23762 [main] DEBUG org.apache.commons.httpclient.ConnectMethod  - enter
> ConnectMethod.addRequestHeaders(HttpState, HttpConnection)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.addUserAgentRequestHeaders(HttpState, HttpConnection)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.addHostRequestHeader(HttpState, HttpConnection)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - Adding
> Host request header
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.addProxyConnectionHeader(HttpState, HttpConnection)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  -
> HttpMethodBase.addRequestHeader(Header)
> 23762 [main] DEBUG httpclient.wire.header  - >> "Proxy-Authorization: Basic
> dGVzdDp0ZXN0[\r][\n]"
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.print(String)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 23762 [main] DEBUG httpclient.wire.header  - >> "User-Agent: Jakarta
> Commons-HttpClient/3.0[\r][\n]"
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.print(String)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 23762 [main] DEBUG httpclient.wire.header  - >> "Host: java.sun.com[\r][\n]"
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.print(String)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 23762 [main] DEBUG httpclient.wire.header  - >> "Proxy-Connection:
> Keep-Alive[\r][\n]"
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.print(String)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.writeLine()
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[])
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.write(byte[], int, int)
> 23762 [main] DEBUG httpclient.wire.header  - >> "[\r][\n]"
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.flushRequestOutputStream()
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.readResponse(HttpState, HttpConnection)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpMethodBase  - enter
> HttpMethodBase.readStatusLine(HttpState, HttpConnection)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.readLine()
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpParser  - enter
> HttpParser.readLine(InputStream, String)
> 23762 [main] DEBUG org.apache.commons.httpclient.HttpParser  - enter
> HttpParser.readRawLine()
> 46742 [main] DEBUG org.apache.commons.httpclient.HttpMethodDirector  -
> Closing the connection.
> 46742 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.close()
> 46742 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.closeSockedAndStreams()
> 46742 [main] DEBUG org.apache.commons.httpclient.HttpMethodDirector  -
> Method retry handler returned false. Automatic recovery will not be
> attempted
> 46742 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - enter
> HttpConnection.releaseConnection()
> 46742 [main] DEBUG org.apache.commons.httpclient.HttpConnection  - Releasing
> connection back to connection manager.
> Failed to download file.
> org.apache.commons.httpclient.NoHttpResponseException: The server
> java.sun.com failed to respond
>  at org.apache.commons.httpclient.HttpMethodBase.readStatusLine(Unknown
> Source)
>  at org.apache.commons.httpclient.HttpMethodBase.readResponse(Unknown
> Source)
>  at org.apache.commons.httpclient.HttpMethodBase.execute(Unknown Source)
>  at org.apache.commons.httpclient.ConnectMethod.execute(Unknown Source)
>  at org.apache.commons.httpclient.HttpMethodDirector.executeConnect(Unknown
> Source)
>  at org.apache.commons.httpclient.HttpMethodDirector.executeWithRetry(Unknown
> Source)
>  at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(Unknown
> Source)
>  at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source)
>  at org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source)
>  at com.test.MyHttpClient.main(MyHttpClient.java:56)


---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: httpclient-user-help@jakarta.apache.org


Mime
View raw message