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