users@jersey.java.net

[Jersey] Re: configure Grizzly Server

From: Richard Sand <rsand_at_idfconnect.com>
Date: Mon, 27 Jan 2014 11:43:43 -0500

Any takers on this Grizzly question? If anyone is using the Grizzly Jersey
server for unit testing I'm sure a web app I'm sure you've run into the
question of how to pass in configuration parameters.

Richard Sand | CEO
IDF Connect, Inc.
2207 Concord Ave, #359
Wilmington | Delaware 19803 | USA
Office: +1 888 765 1611 | Fax: +1 866 765 7284
Mobile: +1 267 984 3651


-----Original Message-----
From: Richard Sand [mailto:rsand_at_idfconnect.com]
Sent: Tuesday, January 21, 2014 12:11 PM
To: 'users_at_jersey.java.net'
Subject: configure Grizzly Server

Hi all-

I've got a service I've written which extends ResourceConfig and contains
a setter method to pass in a configuration string. How can I call that
setter from the Grizzly server at init time?

@Provider
@Singleton
@Path("/entitlement")
public class EntitlementResource extends ResourceConfig {
    String entitlementStoreClass =
SampleEntitlementsStore.class.getName();
    public void setEntitlementStoreClass(String entitlementStoreClass) {
        this.entitlementStoreClass = entitlementStoreClass;
    }
....
}

My Grizzly Server:

public class EntitlementResourceServer {
    /**
     * Starts Grizzly HTTP server exposing JAX-RS resources defined in
this application.
     *
     * @return Grizzly HTTP server.
     */
    public static HttpServer startServer(String baseUri, String
entitlementStoreClass) {
        // create a resource config that scans for JAX-RS resources and
providers in com.idfconnect.security.entitlements package
        final ResourceConfig rc = new
ResourceConfig().packages("com.idfconnect.security");

// HOW DO I CONFIGURE THE APPLICATION HERE?

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

Richard Sand | CEO
IDF Connect, Inc.
2207 Concord Ave, #359
Wilmington | Delaware 19803 | USA
Office: +1 888 765 1611 | Fax: +1 866 765 7284
Mobile: +1 267 984 3651