You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@hc.apache.org by "Karr, David" <Da...@wamu.net> on 2003/11/07 00:00:08 UTC

Config alternate ssl socket factory: Getting existing protocol

I'm following the directions for enabling a custom socket factory (the
"easy" one, for self-signed certs).  I noticed that the instructions
hardcode the scheme and port for the new protocol.  Being somewhat anal,
I thought it would be useful to first get the existing protocol, and
just read the scheme and port from that, replacing the ssl socket
factory.

The problem I'm having is that the return I'm getting from
"hostConfig.getProtocol()" is a null pointer.

I have code something like this:

----------------
                HttpClient httpClient  = new HttpClient();
                httpClient.getHostConfiguration().
                    setProxy(getProxyHost(), getProxyPort());
                Credentials credentials =
                    new UsernamePasswordCredentials(getProxyLogin(),
getProxyPassword());
                httpClient.getState().
                    setProxyCredentials(null, null, credentials);
                method  = new PostMethod(getGatewayURL());
                HostConfiguration   hostConfig  =
                    httpClient.getHostConfiguration();
                Protocol   protocol = hostConfig.getProtocol();
                System.out.println("protocol[" + protocol + "]");
----------------

As I described, the println call shows that the "protocol" object is
null.  This makes it difficult to get any information out of it :) .

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


Re: Config alternate ssl socket factory: Getting existing protocol

Posted by Michael Becke <be...@u.washington.edu>.
Hi David,

The port value associated with a protocol is the default port for the 
protocol (i.e. 80 for HTTP).  It is possible to override this value 
using the method URI or via the hostConfig.  The reason that protocol 
is null in the example below is that one has not been set.

Mike

On Nov 6, 2003, at 6:00 PM, Karr, David wrote:

> I'm following the directions for enabling a custom socket factory (the
> "easy" one, for self-signed certs).  I noticed that the instructions
> hardcode the scheme and port for the new protocol.  Being somewhat 
> anal,
> I thought it would be useful to first get the existing protocol, and
> just read the scheme and port from that, replacing the ssl socket
> factory.
>
> The problem I'm having is that the return I'm getting from
> "hostConfig.getProtocol()" is a null pointer.
>
> I have code something like this:
>
> ----------------
>                 HttpClient httpClient  = new HttpClient();
>                 httpClient.getHostConfiguration().
>                     setProxy(getProxyHost(), getProxyPort());
>                 Credentials credentials =
>                     new UsernamePasswordCredentials(getProxyLogin(),
> getProxyPassword());
>                 httpClient.getState().
>                     setProxyCredentials(null, null, credentials);
>                 method  = new PostMethod(getGatewayURL());
>                 HostConfiguration   hostConfig  =
>                     httpClient.getHostConfiguration();
>                 Protocol   protocol = hostConfig.getProtocol();
>                 System.out.println("protocol[" + protocol + "]");
> ----------------
>
> As I described, the println call shows that the "protocol" object is
> null.  This makes it difficult to get any information out of it :) .
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: 
> commons-httpclient-dev-unsubscribe@jakarta.apache.org
> For additional commands, e-mail: 
> commons-httpclient-dev-help@jakarta.apache.org
>


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