Hi David,

The values given to the hostConfig on HttpClient are defaults and only used if values are not specified on the methods. My guess is that the URI returned from getGatewayURL() is absolute. If this is the case, the host/protocol/port values are taken from this URI and the values from the HttpClient hostConfig are not used. You can fix this in two ways.

1) Register the your protocol statically:

Protocol.registerProtocol("https", SOME_PROTOCOL);

This will need to be done before creating the HttpMethod, since the protocol is looked up when the URI is parsed.

2) Set the protocol on the method:

GetMethod get = new GetMethod("http://somehost.com:/path";);
get.getHostConfiguration().setHost(host, port, protocol);


Mike


On Nov 6, 2003, at 7:01 PM, Karr, David wrote:

I was able to get around my issue with the protocol returned from
"getHostConfig()" being null.  I'm now getting the URI from the method,
and using the fields from that.  That works fine.

At this point, I believe I've followed all the instructions in the SSL
Guide for setting up an alternate socket factory (the "easy" one, for
self-signed certs). However, I still get the "Could not find trusted
certificate" exception. I tried setting breakpoints in the methods of
the "EasySSLProtocolSocketFactory" class, and I find that only the
constructor is ever called (because I called it when I instantiated it),
the "createSocket()" methods are never called. I guess that makes it
somewhat understandable that I'm still getting the certificate
exception. It obviously means my new socket factory is being ignored.


My code looks somewhat like this:
--------------------
                method  = new PostMethod(getGatewayURL());
                URI  uri   = method.getURI();
                if (uri.getScheme().equals("https"))
                {
                    Class  socketFactoryClass   =
                        Class.forName(getSSLSocketFactory());
                    SecureProtocolSocketFactory factory  =
                        (SecureProtocolSocketFactory)
                        socketFactoryClass.newInstance();
                    Protocol  newProtocol =
                        new Protocol(uri.getScheme(), factory,
uri.getPort());
                    hostConfig.setHost(uri.getHost(), uri.getPort(),
                                       newProtocol);
                    method  = new PostMethod(getGatewayURL());
                }
                httpClient.executeMethod(method);
--------------------

(If I can get this to work, I'll probably not have the double creation
of the "method" object, I'll just create a URI from the URL string and
eventually create the method from that.  I don't believe that will fix
my current problem, so I'm not handling that yet.)

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to