Package org.glassfish.jersey.server

Examples of org.glassfish.jersey.server.ResourceConfig


    private static final Logger LOGGER = Logger.getLogger(ErrorTest.class.getName());

    @Override
    protected Application configure() {
        ResourceConfig config = new ResourceConfig(ErrorResource.class);
        config.register(new LoggingFilter(LOGGER, true));
        return config;
    }
View Full Code Here


     * @return Grizzly HTTP server.
     */
    public static HttpServer startServer() {
        // create a resource config that scans for JAX-RS resources and providers
        // in $package package
        final ResourceConfig rc = new ResourceConfig().packages("$package");

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

        }
    }

    @Override
    protected Application configure() {
        ResourceConfig config = new ResourceConfig(AuthResource.class);
        config.register(new LoggingFilter(LOGGER, true));
        return config;
    }
View Full Code Here

     */
    private static ResourceConfig createResourceConfig(final WebConfig config) throws ServletException {
        final ServletContext servletContext = config.getServletContext();

        // check if ResourceConfig has already been created, if so use it
        ResourceConfig resourceConfig = Utils.retrieve(config.getServletContext());
        if (resourceConfig != null) {
            return resourceConfig;
        }

        final Map<String, Object> initParams = getInitParams(config);
        final Map<String, Object> contextParams = Utils.getContextParams(servletContext);

        // check if the JAX-RS application config class property is present
        final String jaxrsApplicationClassName = config.getInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS);

        if (jaxrsApplicationClassName == null) {
            // If no resource config class property is present, create default config
            resourceConfig = new ResourceConfig().addProperties(initParams).addProperties(contextParams);

            final String webApp = config.getInitParameter(ServletProperties.PROVIDER_WEB_APP);
            if (webApp != null && !"false".equals(webApp)) {
                resourceConfig.registerFinder(new WebAppResourcesScanner(servletContext));
            }
            return resourceConfig;
        }

        try {
View Full Code Here

     *
     * @param context servlet context to load resource config from.
     * @return previously stored resource config or {@code null} if no resource config has been stored.
     */
    public static ResourceConfig retrieve(final ServletContext context) {
        final ResourceConfig config = (ResourceConfig) context.getAttribute(RESOURCE_CONFIG);
        context.removeAttribute(RESOURCE_CONFIG);
        return config;
    }
View Full Code Here

        }
    }

    @Override
    protected Application configure() {
        ResourceConfig config = new ResourceConfig(TimeoutResource.class);
        config.register(new LoggingFilter(LOGGER, true));
        return config;
    }
View Full Code Here

        }
    }

    @Override
    protected Application configure() {
        ResourceConfig config = new ResourceConfig(PublicResource.class, InternalResource.class, CustomHeaderFeature.class)
                .property(ClientA.class.getName() + ".baseUri", this.getBaseUri().toString() + "internal");
        config.register(new LoggingFilter(LOGGER, true));
        return config;
    }
View Full Code Here

    public UriBuilder getUri() {
        return UriBuilder.fromUri("http://localhost").port(getPort()).path(CONTEXT);
    }

    public void startServer(Class... resources) {
        ResourceConfig config = new ResourceConfig(resources);
        config.register(new LoggingFilter(LOGGER, true));
        final URI baseUri = getBaseUri();
        server = JettyHttpContainerFactory.createServer(baseUri, config);
        LOGGER.log(Level.INFO, "Jetty-http server started on base uri: " + baseUri);
    }
View Full Code Here

        }
    }

    @Override
    protected Application configure() {
        ResourceConfig config = new ResourceConfig(EntityResource.class, JacksonFeature.class);
        config.register(new LoggingFilter(LOGGER, true));
        return config;
    }
View Full Code Here

    }

    @Test
    public void testReload() {
        final ResourceConfig rc = new ResourceConfig(One.class);

        Reloader reloader = new Reloader();
        rc.registerInstances(reloader);

        startServer(rc);

        Client client = ClientBuilder.newClient();
        WebTarget r = client.target(getUri().path("/").build());

        assertEquals("one", r.path("one").request().get(String.class));
        assertEquals(404, r.path("two").request().get(Response.class).getStatus());

        // add Two resource
        reloader.reload(new ResourceConfig(One.class, Two.class));

        assertEquals("one", r.path("one").request().get(String.class));
        assertEquals("two", r.path("two").request().get(String.class));
    }
View Full Code Here

TOP

Related Classes of org.glassfish.jersey.server.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.