The Problem:
I need to receive different types of content from a number of different sources normalize them and then make them persistent through JDO.
Naive Solution?:
Create and listen on a specific port for each data type.
OR
Do a bunch of complicated parsing
A Seemingly Ideal Solution:
Have custom URL types i.e. FOO://myhost.tld, BAR://myhost.tld. any application could then send to the URL specific to the custom type and the host would ideally use Java’s URLConnection and URLStreamHandler abstract classes to create a factory that would spawn the appropriate normalization thread. Or if there is anyway other way to retrieve the connection URL I think that would be sufficient
Is this possible? I have looked through the API and other docs put cannot figure out if it is possible to use these with a Java server socket.
I should mention that in some (many? most?) cases I am not responsible for the client code.
What you’re calling ‘URL type’ is the protocol part of the URL, and all it does is tell the client which protocol the server at that URL is going to expect it to talk.
It is NOT part of a ‘meta-protocol’ that would allow the server to find out the URL it’s being called with, unless you use a protocol that contains this information as a header – which is not commonly the case. Note also that protocols usually imply a default port unless the URL also specifies a port.
The entire URLConnection / URLStreamHandler API of Java is geared towards usage in a client, not a server, so I don’t believe it can be used the way you want.
The first two alternatives you came up with are pretty much your options: either use different ports for the different kinds of input, or have the clients send a header that specifies the kind of input that follows.