views:

77

answers:

3

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 Ie. FOO://myhost.tld, BAR://myhost.tld. any application could then send to the URL specific to the custom type and the host would idealy 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.

A: 

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.

Michael Borgwardt
Thanks for the reply. These are things I had kind of guessed at but was unsure. It looks as though I may be able to use the ServerSocketChannel abstract class to achieve something like what I was trying to describe, less the custom protocol as an identifier.
tapi
+1  A: 

MIME is a fairly standard way of communicating content type and disposition.

McDowell
A: 

The solution I ended up going with is using the java nio lib and a thread pool with a collection of ServerSocketChannels with content handlers attached

tapi