hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Cumings" <mcumi...@gmail.com>
Subject ConnectMethod usage
Date Thu, 03 Jul 2008 22:12:51 GMT
Hello all,

I've got a question as to the usage of the ConnectMethod.  From the API,
it appears that the only non-deprecated way to create a HTTP CONNECT
connection is to construct a ConnectMethod instance, passing in a
HostConfiguration object configured for the target/destination host and port.
I've modelled this in the test case below:

    public void testConnect() throws IOException {
        this.server.setHttpService(new EchoService());
        // Set default host
        this.client.getHostConfiguration().setHost(
                this.server.getLocalAddress(),
                this.server.getLocalPort(),
                Protocol.getProtocol("http"));

        HostConfiguration hConf = new HostConfiguration();
        hConf.setHost(
                this.server.getLocalAddress(),
                this.server.getLocalPort());
        ConnectMethod conn = new ConnectMethod(hConf);
        try {
            this.client.executeMethod(conn);
            assertEquals(HttpStatus.SC_OK, conn.getStatusCode());
        } finally {
            conn.releaseConnection();
        }
    }

At runtime the above fails with the following stack dump:

     [java] 1) testConnect(org.apache.commons.httpclient.TestConnectMethod)java.lang.IllegalStateException:
unsupported protocol: 'localhost'
     [java]     at
org.apache.commons.httpclient.protocol.Protocol.lazyRegisterProtocol(Unknown
Source)
     [java]     at
org.apache.commons.httpclient.protocol.Protocol.getProtocol(Unknown
Source)
     [java]     at
org.apache.commons.httpclient.HostConfiguration.setHost(Unknown
Source)
     [java]     at
org.apache.commons.httpclient.HostConfiguration.setHost(Unknown
Source)
     [java]     at
org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source)
     [java]     at
org.apache.commons.httpclient.HttpClient.executeMethod(Unknown Source)
     [java]     at
org.apache.commons.httpclient.TestConnectMethod.testConnect(Unknown
Source)
     [java]     at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
     [java]     at
sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
     [java]     at
sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)

Basically, the hostname:port is being interpreted as an absolute URI
such as "localhost:1234"
where the scheme is "localhost" and the path is "1234", which then
breaks in HttpClient.executeMethod(...):

        URI uri = method.getURI();
        if (hostconfig == defaulthostconfig || uri.isAbsoluteURI()) {
            // make a deep copy of the host defaults
            hostconfig = (HostConfiguration) hostconfig.clone();
            if (uri.isAbsoluteURI()) {
                hostconfig.setHost(uri);
            }
        }

So my question is whether this is a bug or operator error?  Thanks in advance,

-- 
Mike Cumings

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


Mime
View raw message