users@jersey.java.net

Re: [Jersey] Invoking other Jersey services

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 27 May 2009 13:49:35 -0700

Hi Jon,

On May 27, 2009, at 12:53 PM, Jon Stritar wrote:

> Hey,
>
> We are developing a bunch of services using Jersey. How would you
> recommend handling runtime parameters like the location of other
> services? For example, in production I can just invoke the live
> services
> via their well known URLs, but if I'm developing locally I'd want to
> run
> my dependencies locally and invoke those. Are there any best practices
> for dealing with these runtime configurations or for routing messages
> between Jersey services? I'd want to have something where its easy to
> check projects out from scm and where tests can use the same runtime
> configurations.
>

You could use a properties file, load it and wrap the data around one
or more beans to get the property values.

If you are using an IoC framework like Spring or Guice you can inject
such beans. Or you can use Jersey's IoC support. For example jersey-
multpart does this, see code here:

http://fisheye4.atlassian.com/browse/~raw,r=1740/jersey/trunk/jersey/
contribs/jersey-multipart/src/main/java/com/sun/jersey/multipart/impl/
MultiPartConfigProvider.java

http://fisheye4.atlassian.com/browse/~raw,r=1692/jersey/trunk/jersey/
contribs/jersey-multipart/src/main/java/com/sun/jersey/multipart/
MultiPartConfig.java


>
> Also, one more quick question. Any ideas on why @FormParam isn't
> grabbing the arguments for us... they are always null:
>
> @Path("posttest") @POST @Consumes("application/x-www-form-urlencoded")
> public Response testPost(
> @FormParam("username") String username,
> @FormParam("password") String password) {
>
> LOGGER.info("Username= "+username+" and password="+password);
> }
>
> I'm testing this with curl:
>
> curl -d username=jon -d password=secret "http://....."
>

What version of Jersey are you using? i am guessing that you are using
something like Tomcat with a valve/filter that is logging and
consuming the request entity, see:

https://jersey.dev.java.net/issues/show_bug.cgi?id=188

which was fixed in version 1.0.2.

Paul.