Sample Java Service API program

I’ve had some requests for a “How To” on the Java Services API.

I’ve put together a small example. It’s hardly comprehensive, but it does show you how to check out, open, modify and save and check in a single content item with the Rhythmyx Java Services API.

Remember this is intended as Sample Code, it’s not well tested, nor does it do any error checking: most of that is left out for the sake of clarity.

The attached ZIP file is a copy of my Eclipse project folder. In that folder you will find the deployment zip file, source, API doc, etc. There is also a sample JSP page that can be used to invoke the Java code.

Any questions, feel free to post responses or new threads as you see fit.

One thing I forgot to mention is that a server restart is required to pick up the changes when you install this package.

Rhythmyx does not Hot Deploy. Several common operations require restarting the server, among them:

  1. Adding JARs to the any of lib directories
  2. Adding or Changing Spring configurations under rxapp.war/WEB-INF/config/user/spring
  3. Changing Relationship configurations in the Workbench.

I should note that there are several things you may do WITHOUT restarting:

  1. Adding or Changing Extensions via the Workbench.
  2. Modifying AppServer/server/rx/conf/log4j.xml
  3. Modifying rxapp.war/WEB-INF/config/user/security/user-security-conf.xml

I should also have added that although I built and tested this on Rhythmyx 6.5, I expect that it would work equally well on 6.1.

I’ve had a few questions in email, some of which I will repeat here.

Can I set the debug option on, which jboss run scipt should I set the java debug option

To debug, create a text file in your RHYTHMYX_HOME folder. This file is named “RhythmyxServer.ja”

-enableassertions -Xdebug -Xrunjdwp:transport=dt_socket,server=y,address=8100,suspend=n

When you restart your server, you will see a message on the console that says “Listening on port 8100”…

Assuming you are using Eclipse, you use the “Run - Debug…” menu and select the “new” button at the bottom of the dialog. This will create a new “Remote Debugger” in Eclipse, and connect it to the server. Make sure that this remote debugger uses port 8100 (you can use any available port, but the .ja file and Eclipse must match).

Of course, you’ll have to compile your code with the Java Debug flags turned on. The “Compile” target in the build.xml in my example shows how to do this. The PSOToolkit and related classes are compiled with Debug mode, but the server itself is not, of course.

I do this quite frequently, and it works well even over the Internet (I’ve done it from home while running Rhythmyx on my office computer via VPN).

You can also make certain code changes without needing a Rhythmyx restart, which will save you lots of time. New classes or methods and some configuration changes still force a restart as described in my previous post.

Another question from a customer…

what are the steps to deploy a servlet to rhythmyx ? copy jar file to …/server/rx/deploy/rxapp.ear/rxapp.war/WEB-INF/lib and change…/server/rx/deploy/rxapp.ear/rxapp.war/WEB-INF/config/user/spring/UserDispatch- servlet.xml

Assuming you need to go beyond JSP pages, which are after all the simplest form of servlet, you need to put your code in the rxapp.war/WEB-INF/lib directory.

There are any number of ways to deploy the actual servlet. You should NOT edit the web.xml directly. My personal favorite is:

  1. Create a new subdirectory named WEB-INF/config/user/spring/dispatch
  2. Create a new beans file for each Application and place it the new dispatch directory
  3. Modify WEB-INF/config/user/spring/UserDispatcher-servlet.xml. Add the line at the top of the file:

<import resource=“dispatch/xxxx-beans.xml” />

where xxx-beans.xml is the name of the beans file from step 2. (For some past projects, we’ve actually written Ant scripts that use XSLT to insert the <import> statement. This is probably going a bit overboard. The key is to keep your different projects from overwriting each other in UserDispatcher-servlet.xml.

Usually we wind up implementing the Spring Web MVC Controller interface (or one of its subclasses) rather than building an HttpServlet and using Spring’s ServletWrappingController. The Controller interface is pretty simple, and since you’re working with HttpServletRequest and HttpServletResponse items, it’s familiar to many programmers. This is simply a matter of personal preference. If you’re comfortable with Servlets, use Servlets. We’re using Spring 2.0 in Rhythmyx 6.5 ( is a good place to start.) Rhythmyx 6.1 uses Spring 1.2, and there are some minor differences.

Note also that you CAN use Struts. The Spring documentation describes how.

The Spring Framework documentation has moved to here.

Hi Dave

Can you provide some examples (just written not code) of the types of things you’ve created using the api? This is so people can gauge what they can and can’t do with them.


Does anyone have some sample code that will create a new content item using the API or any other method? We have several hundred content items to create using an old database and a way of doing this automatically would save us a lot of work. Once created I can use the example below to populate them but how to get started?


You are not alone


PSO has the XML Batch Importer. That’s what we’re going to be using. Sorry I can’t offer more info than that.

Is this tool available from Percussion then?