Package com.sun.jersey.api.core

Examples of com.sun.jersey.api.core.ResourceConfig


    private void deployRestApi(final RexsterApplication application) throws ClassNotFoundException, InstantiationException, IllegalAccessException {
        if (hasAnythingChanged()) {
            wacJersey = new WebappContext("jersey", "");

            // explicitly load resources so that the "RexsterApplicationProvider" class is not loaded
            final ResourceConfig rc = constructResourceConfig();

            // constructs an injectable for the RexsterApplication instance.  This get constructed externally
            // and is passed into the HttpRexsterServer.  The SingletonTypeInjectableProvider is responsible for
            // pushing that instance into the context.
            rc.getSingletons().add(new SingletonTypeInjectableProvider<Context, RexsterApplication>(
                    RexsterApplication.class, application) {
            });
            rc.getSingletons().add(new InstrumentedResourceMethodDispatchAdapter(application.getMetricRegistry()));

            if (this.debugMode) {
                rc.getContainerRequestFilters().add(new LoggingFilter());
                rc.getContainerResponseFilters().add(new LoggingFilter());
            }

            rc.getContainerResponseFilters().add(new HeaderResponseFilter(defaultCharacterEncoding));

            if (!securityFilterType.equals(Tokens.REXSTER_SECURITY_NONE)) {
                final AbstractSecurityFilter securityFilter;
                if (securityFilterType.equals(Tokens.REXSTER_SECURITY_DEFAULT)) {
                    wacJersey.addContextInitParameter(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, DefaultSecurityFilter.class.getName());
                    securityFilter = new DefaultSecurityFilter();
                } else {
                    wacJersey.addContextInitParameter(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, securityFilterType);
                    final Class clazz = Class.forName(securityFilterType, true, Thread.currentThread().getContextClassLoader());
                    securityFilter = (AbstractSecurityFilter) clazz.newInstance();
                }

                securityFilter.configure(properties.getConfiguration());
                rc.getContainerRequestFilters().add(securityFilter);
            }

            final ServletRegistration sg = wacJersey.addServlet("jersey", new ServletContainer(rc));
            sg.addMapping("/*");
            wacJersey.deploy(this.httpServer);
View Full Code Here


            wacJersey.deploy(this.httpServer);
        }
    }

    private ResourceConfig constructResourceConfig() {
        ResourceConfig rc;
        if (enableDogHouse) {
            rc = new ClassNamesResourceConfig(
                EdgeResource.class,
                GraphResource.class,
                IndexResource.class,
View Full Code Here

    private ApplicationDescription createApplication(String[] paths) {
        final ClassLoader cl = Thread.currentThread().getContextClassLoader();
        final ClassLoader ncl = new Loader(classpath.list(), this.getClass().getClassLoader());
        Thread.currentThread().setContextClassLoader(ncl);
        try {
            ResourceConfig rc = new ClasspathResourceConfig(classpath.list());
            rc.validate();
            Set<AbstractResource> s = new HashSet<AbstractResource>();
            for (Class c : rc.getRootResourceClasses()) {
                s.add(IntrospectionModeller.createResource(c));
            }
           
            return new WadlBuilder().generate(s);
        } catch(Exception e) {
View Full Code Here

   
    public static void main(String[] args) throws IOException {
       
        final String baseUri = "http://localhost:9998/sparklines/";

        ResourceConfig rc = new PackagesResourceConfig("com.sun.jersey.samples.sparklines");

        System.out.println("Starting grizzly...");
        HttpServer httpServer = GrizzlyServerFactory.createHttpServer(baseUri, rc);
        System.out.println(String.format("Jersey app started with WADL available at %sapplication.wadl\n" +
                "Try out %sdiscrete?d=88,84,82,92,82,86,66,82,44,64,66,88,96,80,24,26,14,0,0,26,8,6,6,24,52,66,36,6,10,14,30\n" +
View Full Code Here

     * @throws java.io.IOException if there is an error starting the Grizzly
     *         HTTP container.
     */
    protected static HttpServer startServer() throws IOException {

        ResourceConfig rc = new PackagesResourceConfig("com.sun.jersey.samples.storageservice.resources");

        System.out.println("Starting grizzly...");
        return GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
    }
View Full Code Here


        Adapter adapter = null;
        Reloader r = new Reloader();

        ResourceConfig rc = new DefaultResourceConfig(classes);
        rc.getMediaTypeMappings().put("xml", MediaType.APPLICATION_XML_TYPE);
        rc.getMediaTypeMappings().put("json", MediaType.APPLICATION_JSON_TYPE);
        rc.getMediaTypeMappings().put("html", MediaType.TEXT_HTML_TYPE);
        rc.getMediaTypeMappings().put("js", new MediaType("application", "x-javascript"));

        RestConfig restConf = getRestConfig(habitat);
        if (restConf != null) {
            if (restConf.getLogOutput().equalsIgnoreCase("true")) { //enable output logging
                rc.getContainerResponseFilters().add(LoggingFilter.class);
            }
            if (restConf.getLogInput().equalsIgnoreCase("true")) { //enable input logging
                rc.getContainerRequestFilters().add(LoggingFilter.class);
            }
            if (restConf.getWadlGeneration().equalsIgnoreCase("false")) { //disable WADL
                rc.getFeatures().put(ResourceConfig.FEATURE_DISABLE_WADL, Boolean.TRUE);
            }
        }

        rc.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_NOTIFIER, r);
        rc.getClasses().add(ReloadResource.class);

        //We can only inject these 4 extra classes in Jersey resources...
        rc.getSingletons().add(new SingletonTypeInjectableProvider<Context, Reloader>(Reloader.class, r) {});
        rc.getSingletons().add(new SingletonTypeInjectableProvider<Context, ServerContext>(ServerContext.class, sc) {});
        rc.getSingletons().add(new SingletonTypeInjectableProvider<Context, Habitat>(Habitat.class, habitat) {});
        rc.getSingletons().add(new SingletonTypeInjectableProvider<Context, SessionManager>(SessionManager.class, habitat.getComponent(SessionManager.class)) {});
        rc.getSingletons().add(new SingletonTypeInjectableProvider<Context, SessionManager>(SessionManager.class, habitat.getComponent(SessionManager.class)) {});

        //Use common classloader. Jersey artifacts are not visible through
        //module classloader
        ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
        try {
View Full Code Here

    public static final URI BASE_URI = getBaseURI();
    public static final int defaultPort = 9998;

    protected static HttpServer startServer() throws IOException {

        ResourceConfig rc = new PackagesResourceConfig("com.sun.jersey.samples.console");

        System.out.println("Starting grizzly...");
        return GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
    }
View Full Code Here

    public static <A> A createContainer(Class<A> type, String packageName)
    throws ContainerException, IllegalArgumentException {
        String resourcesClassName = packageName + ".WebResources";
        try {
            Class<?> resourcesClass = ContainerFactory.class.getClassLoader().loadClass(resourcesClassName);
            ResourceConfig config = (ResourceConfig) resourcesClass.newInstance();
            return createContainer(type, config, null);
        } catch (ClassNotFoundException e) {
            throw new ContainerException(e);
        } catch (InstantiationException e) {
            throw new ContainerException(e);
View Full Code Here

    public static final URI BASE_URI = getBaseURI();

    protected static HttpServer startServer() throws IOException {
        System.out.println("Starting grizzly...");
        ResourceConfig rc = new PackagesResourceConfig("com.sun.jersey.samples.helloworld.resources");
        return GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
    }
View Full Code Here

TOP

Related Classes of com.sun.jersey.api.core.ResourceConfig

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.