views:

449

answers:

2

I want to be able to access custom URLs with apache httpclient. Something like this:

HttpClient client = new HttpClient();
HttpMethod method = new GetMethod("media:///squishy.jpg");
int statusCode = client.executeMethod(method);

Can I somehow register a custom URL handler? Or should I just register one with Java, using

URL.setURLStreamHandlerFactory(...)

Regards.

A: 

I don't think there's a way to do this in commons httpclient. It doesn't make a whole lot of sense either, after all it is a HTTP client and "media:///squishy.jpg" is not HTTP, so all the code to implement the HTTP protocol probably couldn't be used anyways.

URL.setURLStreamHandlerFactory(...)

could be the way to go, but you'll probably have to do a lot of protocol coding by hand, depending on your "media"-protocol.

WMR
+1  A: 

We do it like this:

 org.apache.commons.httpclient.protocol.Protocol.registerProtocol("ss-https", 
     new Protocol("ss-https",
     (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443));
mitchnull