Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » Equinox » Available protocols for URL/URLConnections?
Available protocols for URL/URLConnections? [message #80645] Wed, 10 January 2007 22:50 Go to next message
Eclipse UserFriend
Originally posted by: slewis.composent.com

At runtime, I would like to determine the protocols that are supported
for URL construction and subsequent URLConnection creation...e.g. http,
https, ftp, platform, file, jar, bundle, any/all others registered by
other bundles via URLStreamHandlerService.

How can I do this? It seems the URLStreamHandlerService (where new
protocols/stream handlers are registered via OSGI) doesn't have a method
for querying the available registered schemes/protocols...which is where
I sort of expected it might be.

Is there some other way to get this info at runtime?

Thanksinadvance,

Scott
Re: Available protocols for URL/URLConnections? [message #80820 is a reply to message #80645] Fri, 12 January 2007 16:46 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas WatsonFriend
Messages: 503
Registered: July 2009
Senior Member
You can get all the service references of type
org.osgi.service.url.URLStreamHandlerService. For example:

ServiceTracker handlers = new ServiceTracker(context,
"org.osgi.service.url.URLStreamHandlerService", null);
handlers.open();
ServiceReference[] refs = handlers.getServiceReferences();


Then you can get the supported protocols by getting all the
"url.handler.protocol" service properties from the references:

Set protocols = new HashSet();
if (refs != null)
for (int i = 0; i < refs.length; i++) {
Object protocol = refs.getProperty("url.handler.protocol");
if (protocol instanceof String)
protocols.add(protocol);
else if (protocol instanceof String[])
for (int j = 0; j < protocol.length; j++)
protocols.add(protocol[j]);
}
// be sure to close your service tracker some time
handlers.close();


This only gets you protocols added by bundles that register
URLStreamHanderService objects. The protocols built into the VM cannot
be discovered this way. There is no API that I know of to figure out
the list of protocols supported by the VM. They are discovered as you
use them by the VM.

HTH

Tom.

Scott Lewis wrote:
> At runtime, I would like to determine the protocols that are supported
> for URL construction and subsequent URLConnection creation...e.g. http,
> https, ftp, platform, file, jar, bundle, any/all others registered by
> other bundles via URLStreamHandlerService.
>
> How can I do this? It seems the URLStreamHandlerService (where new
> protocols/stream handlers are registered via OSGI) doesn't have a method
> for querying the available registered schemes/protocols...which is where
> I sort of expected it might be.
>
> Is there some other way to get this info at runtime?
>
> Thanksinadvance,
>
> Scott
>
Re: Available protocols for URL/URLConnections? [message #80906 is a reply to message #80820] Fri, 12 January 2007 19:44 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: slewis.composent.com

Hi Tom,

Thanks for the info. A couple of follow ups...

Tom Watson wrote:
> You can get all the service references of type
> org.osgi.service.url.URLStreamHandlerService. For example:
>
> ServiceTracker handlers = new ServiceTracker(context,
> "org.osgi.service.url.URLStreamHandlerService", null);
> handlers.open();
> ServiceReference[] refs = handlers.getServiceReferences();
>
>
> Then you can get the supported protocols by getting all the
> "url.handler.protocol" service properties from the references:
>
> Set protocols = new HashSet();
> if (refs != null)
> for (int i = 0; i < refs.length; i++) {
> Object protocol = refs.getProperty("url.handler.protocol");
> if (protocol instanceof String)
> protocols.add(protocol);
> else if (protocol instanceof String[])
> for (int j = 0; j < protocol.length; j++)
> protocols.add(protocol[j]);
> }
> // be sure to close your service tracker some time
> handlers.close();


Thanks much. I missed the "url.handler.protocol" paragraph in the OSGi
R4 spec (for those interested it's in section 11.3 of core R4 spec.

>
>
> This only gets you protocols added by bundles that register
> URLStreamHanderService objects. The protocols built into the VM cannot
> be discovered this way. There is no API that I know of to figure out
> the list of protocols supported by the VM. They are discovered as you
> use them by the VM.


Do you know if there is a specified consist minimal set across all VMs
(Sun, IBM, others)? Obviously http, https, ftp, file, jar have to be
there for all VMs, but is this formalized somewhere that you know of?

Thanksinadvance,

Scott
Re: Available protocols for URL/URLConnections? [message #80916 is a reply to message #80906] Fri, 12 January 2007 20:49 Go to previous messageGo to next message
Thomas Watson is currently offline Thomas WatsonFriend
Messages: 503
Registered: July 2009
Senior Member
Scott Lewis wrote:
>
> Do you know if there is a specified consist minimal set across all VMs
> (Sun, IBM, others)? Obviously http, https, ftp, file, jar have to be
> there for all VMs, but is this formalized somewhere that you know of?
>
> Thanksinadvance,
>
> Scott

Sorry I do not know the answer here. Even your list may be too much,
for example, it is probably a stretch to assume that https is always
available. Any Java Spec Experts know the answer to this one?

Tom
Re: Available protocols for URL/URLConnections? [message #81036 is a reply to message #80916] Sat, 13 January 2007 13:32 Go to previous message
Eclipse UserFriend
Originally posted by: alex_blewitt.yahoo.com

I don't think that there is a standard list; certainly, there's no mention of them in the specs. An article on java.sun.com ( http://java.sun.com/developer/onlineTraining/protocolhandler s/) talks about which ones are in rt.jar by grepping for them; but they're internal Sun classes. The documentation does refer to protocols 'such as http, ftp and gopher' but makes no explicit guarantees that they are there.

That being said, the main reason why Applets worked in the first place was because they came over http; I can't see that that would ever not be there. For a similar reason, I'd expect that (anonymous) ftp would be present.

As for the others ... well, you'll probably have to construct URLs to know whether they are present or not. new URL("foo:localhost") would probably be enough to determine if the protocol handler was available or not on the platform. But I don't think there's a way to list them.

There's a way of finding out more stuff in recent JREs with regard to debugging and finding all instances of a class ... I don't know if that would be something that you could use to find all subtypes of URLStreamHandler dynamically, but it would probably be a bit of a problem to do :-)

Alex.
Previous Topic:Servlet Mapping in Equinox Webapp
Next Topic:EMF models <-> extension points
Goto Forum:
  


Current Time: Fri Apr 26 12:11:13 GMT 2024

Powered by FUDForum. Page generated in 0.03607 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top