1

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.

2 Answers 2

1

We do it like this:

 org.apache.commons.httpclient.protocol.Protocol.registerProtocol("ss-https", 
     new Protocol("ss-https",
     (ProtocolSocketFactory)new EasySSLProtocolSocketFactory(), 443));
Sign up to request clarification or add additional context in comments.

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.