users@jersey.java.net

[Jersey] Re: Simple application configuration

From: Koper, Dies <diesk_at_fast.au.fujitsu.com>
Date: Sat, 11 Jan 2014 08:33:51 +1100

Hi Richard,

In my app I use javax.ws.rs.core.Application, and with that I can pass
in init params from web.xml as described in the following SO answer:
http://stackoverflow.com/questions/19596592/jersey-2-how-to-pass-paramet
ers-from-web-xml-to-application/19601197#19601197

I hope that helps you with the second issue, I don't think it will help
with the first.

Regards,
Dies Koper


-----Original Message-----
From: Richard Sand [mailto:rsand_at_idfconnect.com]
Sent: Saturday, January 11, 2014 5:23 AM
To: users_at_jersey.java.net
Subject: [Jersey] Simple application configuration

Hi all - I've been stuck for the longest time trying to figure out how
to
configure a Jersey application with a simple String parameter. Take for
example this extremely simple resource, where I need to initialize the
variable "configvalue":

@Provider
@Path("/thing")
public class ThingResource extends ResourceConfig {
    String configvalue = null;

    @GET
    @Produces( MediaType.TEXT_PLAIN)
    public String getThing(@QueryParam String param) {
         ....
         return str;
   }
}

1) When running this using the Jersey standalone Grizzly Server, how do
I
pass in a parameter to initialize configvalue? I got this far, but I
don't
know how to read the parameter from within ThingResource:

    public static HttpServer startServer() {
        // create a resource config that scans for JAX-RS resources and
providers in com.drf.security.entitlements package
        final ResourceConfig rc = new
ResourceConfig().packages("com.idfconnect.security");
        rc.property("configvalue", "somevale");

        // create and start a new instance of grizzly http server
exposing
the Jersey application at BASE_URI
        return
GrizzlyHttpServerFactory.createHttpServer(URI.create(baseUri), rc);
    }

2) Similarly, when deploying this with Jersey on a Servlet 3.0 container
(Tomcat), how can I initialize ThingResource with context parameters
from
the web.xml?

Thanks for any help!

-Richard