Mating Tomcat to JXTA
Modernizing a neat idea discovered while reading Sean Kelly’s RegistryVous, comes a rough work called BridgeServlet.
BridgeServlet is a Java servlet that has a view into a JXTA peer to peer network. In fact, BridgeServlet functions as a servlet and JXTA peer simultaneously, processing HTTP requests on one side and JXTA peergroup services on the other. Very cool, Sean.
The BridgeServlet main class file
ant dist builds dist/bridge.war, which is copied into Tomcat’s webapps/

directory in the usual way. ConfigurationFactory.java, found in the servlet code, is basically what you would find in platform/binding/java/contrib/rendezvous/. It’s a quick way to configure the platform without going through the GUI that JXTA config is (in)famous for.
Thus far, what does BridgeServlet actually do? Very little, beyond using modern JXTA APIs, starting the JXTA Platform, joining a sample peergroup — in this case the AE6RT Beacon peergroup — and serve up a list of peers joined to the group. The goal might be to set the JXTA side of the bridge toiling away, monitoring advertisements, or even accept advertisements originated as HTTP POSTs and publishing them to the JXTA network. Seti@Home does something like this, giving web clients a way to browse the productions of its network.
Note how the servlet.destroy() method is overridden to affect a resignation from the application peergroup, followed by stopping the application and Net peergroups. Stopping the Net peergroup causes the JXTA platform to shutdown.
Finally, a screenshot, showing a list of peers currently joined to the group. This sort of production rapidly approaches a situation where Struts or JSF or Grails are needed to do the really interesting apps.
Update: New uploads include ConfigurationFactory.java, log4j.properties, and a sample peergroup advertisement so that BridgeServlet.java can compile and run.
Update 8 Dec 2006: The ConfigurationFactory class should be replaced with its near-equivalent NetworkConfigurator, which is now part of the JXTA platform distribution.
[tags]p2p,jxta,servlet,tomcat[/tags]
Around line 204 of BridgeServlet.java, you don’t catch a NullPointerException that might be thrown if you don’t have the log4j.properties file.
I ran into a similar problem for other configuration files, such as ones referenced in the servet’s init function. I tried to download the Beacon source, thinking that might have hints, but I didn’t have any luck. I’ll keep playing…
Jason K
April 19, 2006 at 6:09 pm
http://wiki.java.net/bin/view/Jxta/LoggingConfiguration shows a typical log4j.properties file, or rather a good starting point for one. Here is the one I use in the BridgeServlet app.
ConfigurationFactory.java, used in BridgeServlet.java, can be found in its original form at platform/binding/java/contrib/rendezvous in the platform source.
http://platform.jxta.org/source/browse/platform/binding/java/contrib/rendezvous/ConfigurationFactory.java
I modified my copy to take a String argument for log level.
Any application PeerGroupAdvertisement would do for the one I referenced in “org/carpediem/jxtaweb/pgadv.xml”. Here’s a sample you can use.
ae6rt
April 19, 2006 at 8:59 pm
Mark, thanks for updating this dusty old project. Much appreciated. ^_^
Sean Kelly
April 24, 2006 at 5:31 am
Very interesting !
Testing your servlet with Java Studio Creator in a JSF application, here an hint to fetch in your code the peer advertisement the servlet put in the servlet context :
ServletContext context = (ServletContext) getExternalContext().getContext();
PeerGroupAdvertisement pgAdv = (PeerGroupAdvertisement) context.getAttribute(”pgadv”);
You can use this kind of code in a backing bean method. In the same way, you might be able to fetch the JXTA discovevy service for example.
I hope it will be the start of superb web applications using JXTA !
Bertrand Goetzmann
September 27, 2006 at 4:15 am
Using your servlet to do the bridge between the JXTA virtual network and a JSF application, I made a web application that is able to deploy and execute Groovy code via JXTA services !
You can find an article (in french) here :
http://www.object-everywhere.com/JXTAWorks/JXTAOnWeb.xml
Bertrand Goetzmann
November 2, 2006 at 10:38 am
Awesome, Bertrand.
JSF, JXTA, Groovy, Servlets. Was there any Java technology you didn’t use in your work
Very cool!
Mark
ae6rt
November 2, 2006 at 11:00 am
hello,
jxta use Jetty by way of HTTP solution, well then should may construct peer to peer + web application.Building web site on peer.
How converting PeerID to Web URL? It puzzles me.
Do you help to me?
Thanks
chenliguo
November 28, 2006 at 10:00 pm
You’ll have to create your own URL to PeerID mapping scheme. There is no standard or “right” way to do this, so you would just invent a technique as your needs require.
ae6rt
November 28, 2006 at 10:05 pm
I was puzzled how to do it.
Do you can provide example code?
Thanks.
chenliguo
November 28, 2006 at 10:58 pm
Unfortunately, I do not have example code. Sorry.
ae6rt
November 29, 2006 at 7:19 am
|> Thus far, what does BridgeServlet actually do? Very little,
|> beyond using modern JXTA APIs, starting the JXTA Platform,
|> joining a sample peergroup — in this case the AE6RT Beacon
|> peergroup
Are there any pre-requirements for joining a jxta-group with this servlet? Can I simply use my own group? Are there special peers, e.g. rendezvous-peers, required for this?
Thanks.
martin
September 27, 2007 at 3:02 pm
Your question is actually a “big” question, which is good.
The short answer is yes, the servlet, which on one side is connected to clients via http, can join any peergroup for which you arrange membership. Making the “back-side” of the process connected to a JXTA p2p network.
The BridgeServlet is a hyper=simple example. But it does demonstrate how to bridge the two networks. http on the front, JXTA on the back, or viceversa, depending on your perspective.
hth
Mark
ae6rt
September 27, 2007 at 7:15 pm
I see. Thanks.
Has anyone rewritten the example using the new JXTA API (using the NetworkConfigurator, etc)?
martin
October 3, 2007 at 9:53 pm
Hmm, if the servlet just connects to a already existing jxta-network, why it is started as RendezVous peer?
|> pg.getRendezVousService().startRendezVous();
martin
October 3, 2007 at 10:01 pm
Martin, good day.
afaik, no one has ported the example to the more modern JXTA APIs, which include NetworkConfigurator and such. There should be a number of folks on the java.net jxta mailing list who can suggest how to do that.
Secondly, if I recall correctly, the peer that ran inside the servlet was intentionally also a rendezvous, so the 2nd peer running outside the view of this blog post could connect to something. Or something like that. But there’s no reason the servlet peer cannot be a rendezvous if that’s a role you want it to play.
hth
Mark
ae6rt
October 4, 2007 at 6:05 am