Search in sources :

Example 21 with ServletContainer

use of org.glassfish.jersey.servlet.ServletContainer in project kylo by Teradata.

the class SpringJerseyConfiguration method jerseyServlet.

@Bean(name = "mainJerseyServlet")
public ServletRegistrationBean jerseyServlet(JerseyConfig jerseyConfig) {
    ServletRegistrationBean registration = new ServletRegistrationBean(new ServletContainer(jerseyConfig));
    registration.addUrlMappings("/api/*");
    // our rest resources will be available in the path /api/*
    registration.addInitParameter(ServletProperties.JAXRS_APPLICATION_CLASS, JerseyConfig.class.getName());
    return registration;
}
Also used : ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) Bean(org.springframework.context.annotation.Bean)

Example 22 with ServletContainer

use of org.glassfish.jersey.servlet.ServletContainer in project traccar by tananaev.

the class WebServer method initApi.

private void initApi(Config config, ServletContextHandler servletHandler) {
    servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/api/socket");
    JettyWebSocketServletContainerInitializer.configure(servletHandler, null);
    String mediaPath = config.getString(Keys.MEDIA_PATH);
    if (mediaPath != null) {
        ServletHolder servletHolder = new ServletHolder(DefaultServlet.class);
        servletHolder.setInitParameter("resourceBase", new File(mediaPath).getAbsolutePath());
        servletHolder.setInitParameter("dirAllowed", "false");
        servletHolder.setInitParameter("pathInfoOnly", "true");
        servletHandler.addServlet(servletHolder, "/api/media/*");
        servletHandler.addFilter(MediaFilter.class, "/api/media/*", EnumSet.allOf(DispatcherType.class));
    }
    ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.registerClasses(JacksonFeature.class, ResourceErrorHandler.class, SecurityRequestFilter.class, CorsResponseFilter.class, DateParameterConverterProvider.class);
    resourceConfig.packages(ServerResource.class.getPackage().getName());
    resourceConfig.register(new ContainerLifecycleListener() {

        @Override
        public void onStartup(Container container) {
            var injectionManager = container.getApplicationHandler().getInjectionManager();
            var serviceLocator = ((ImmediateHk2InjectionManager) injectionManager).getServiceLocator();
            GuiceBridge.getGuiceBridge().initializeGuiceBridge(serviceLocator);
            var guiceBridge = serviceLocator.getService(GuiceIntoHK2Bridge.class);
            guiceBridge.bridgeGuiceInjector(Main.getInjector());
        }

        @Override
        public void onReload(Container container) {
        }

        @Override
        public void onShutdown(Container container) {
        }
    });
    servletHandler.addServlet(new ServletHolder(new ServletContainer(resourceConfig)), "/api/*");
}
Also used : Container(org.glassfish.jersey.server.spi.Container) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ContainerLifecycleListener(org.glassfish.jersey.server.spi.ContainerLifecycleListener) GuiceIntoHK2Bridge(org.jvnet.hk2.guice.bridge.api.GuiceIntoHK2Bridge) ServletHolder(org.eclipse.jetty.servlet.ServletHolder) AsyncSocketServlet(org.traccar.api.AsyncSocketServlet) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) DispatcherType(javax.servlet.DispatcherType) File(java.io.File)

Example 23 with ServletContainer

use of org.glassfish.jersey.servlet.ServletContainer in project jersey by jersey.

the class JerseyServletContainerInitializer method addServletWithDefaultConfiguration.

/**
     * Enhance default servlet (named {@link Application}) configuration.
     */
private static void addServletWithDefaultConfiguration(final ServletContext context, final Set<Class<?>> classes) throws ServletException {
    ServletRegistration registration = context.getServletRegistration(Application.class.getName());
    if (registration != null) {
        final Set<Class<?>> appClasses = getRootResourceAndProviderClasses(classes);
        final ResourceConfig resourceConfig = ResourceConfig.forApplicationClass(ResourceConfig.class, appClasses).addProperties(getInitParams(registration)).addProperties(Utils.getContextParams(context));
        if (registration.getClassName() != null) {
            // class name present - complete servlet registration from container point of view
            Utils.store(resourceConfig, context, registration.getName());
        } else {
            // no class name - no complete servlet registration from container point of view
            final ServletContainer servlet = new ServletContainer(resourceConfig);
            registration = context.addServlet(registration.getName(), servlet);
            ((ServletRegistration.Dynamic) registration).setLoadOnStartup(1);
            if (registration.getMappings().isEmpty()) {
                // Error
                LOGGER.log(Level.WARNING, LocalizationMessages.JERSEY_APP_NO_MAPPING(registration.getName()));
            } else {
                LOGGER.log(Level.CONFIG, LocalizationMessages.JERSEY_APP_REGISTERED_CLASSES(registration.getName(), appClasses));
            }
        }
    }
}
Also used : ServletRegistration(javax.servlet.ServletRegistration) ServletContainer(org.glassfish.jersey.servlet.ServletContainer) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) Application(javax.ws.rs.core.Application)

Example 24 with ServletContainer

use of org.glassfish.jersey.servlet.ServletContainer in project jersey by jersey.

the class Activator method rawRegisterServlets.

private void rawRegisterServlets() throws ServletException, NamespaceException, InterruptedException {
    logger.info("JERSEY BUNDLE: REGISTERING SERVLETS");
    logger.info("JERSEY BUNDLE: HTTP SERVICE = " + httpService.toString());
    // TODO - temporary workaround
    // This is a workaround related to issue JERSEY-2093; grizzly (1.9.5) needs to have the correct context
    // classloader set
    ClassLoader myClassLoader = getClass().getClassLoader();
    ClassLoader originalContextClassLoader = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(myClassLoader);
        httpService.registerServlet("/jersey-http-service", new ServletContainer(), getJerseyServletParams(), null);
    } finally {
        Thread.currentThread().setContextClassLoader(originalContextClassLoader);
    }
    // END of workaround - after grizzly updated to the recent version, only the inner call from try block will remain:
    // httpService.registerServlet("/jersey-http-service", new ServletContainer(), getJerseyServletParams(), null);
    sendAdminEvent();
    logger.info("JERSEY BUNDLE: SERVLETS REGISTERED");
}
Also used : ServletContainer(org.glassfish.jersey.servlet.ServletContainer)

Example 25 with ServletContainer

use of org.glassfish.jersey.servlet.ServletContainer in project spring-boot by spring-projects.

the class JerseyAutoConfiguration method jerseyFilterRegistration.

@Bean
@ConditionalOnMissingBean(name = "jerseyFilterRegistration")
@ConditionalOnProperty(prefix = "spring.jersey", name = "type", havingValue = "filter")
public FilterRegistrationBean<ServletContainer> jerseyFilterRegistration() {
    FilterRegistrationBean<ServletContainer> registration = new FilterRegistrationBean<>();
    registration.setFilter(new ServletContainer(this.config));
    registration.setUrlPatterns(Arrays.asList(this.path));
    registration.setOrder(this.jersey.getFilter().getOrder());
    registration.addInitParameter(ServletProperties.FILTER_CONTEXT_PATH, stripPattern(this.path));
    addInitParameters(registration);
    registration.setName("jerseyFilter");
    registration.setDispatcherTypes(EnumSet.allOf(DispatcherType.class));
    return registration;
}
Also used : ServletContainer(org.glassfish.jersey.servlet.ServletContainer) DispatcherType(javax.servlet.DispatcherType) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) RegistrationBean(org.springframework.boot.web.servlet.RegistrationBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) ServletRegistrationBean(org.springframework.boot.web.servlet.ServletRegistrationBean) ConditionalOnBean(org.springframework.boot.autoconfigure.condition.ConditionalOnBean) Bean(org.springframework.context.annotation.Bean) ConditionalOnProperty(org.springframework.boot.autoconfigure.condition.ConditionalOnProperty)

Aggregations

ServletContainer (org.glassfish.jersey.servlet.ServletContainer)49 ServletHolder (org.eclipse.jetty.servlet.ServletHolder)30 ResourceConfig (org.glassfish.jersey.server.ResourceConfig)29 ServletContextHandler (org.eclipse.jetty.servlet.ServletContextHandler)24 Server (org.eclipse.jetty.server.Server)10 IOException (java.io.IOException)7 DispatcherType (javax.servlet.DispatcherType)6 FilterHolder (org.eclipse.jetty.servlet.FilterHolder)6 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)5 ServletRegistrationBean (org.springframework.boot.web.servlet.ServletRegistrationBean)5 Bean (org.springframework.context.annotation.Bean)5 JacksonJaxbJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJaxbJsonProvider)4 DefaultHandler (org.eclipse.jetty.server.handler.DefaultHandler)4 RequestLogHandler (org.eclipse.jetty.server.handler.RequestLogHandler)4 StatisticsHandler (org.eclipse.jetty.server.handler.StatisticsHandler)4 ServletRegistration (javax.servlet.ServletRegistration)3 ConnectException (org.apache.kafka.connect.errors.ConnectException)3 ConnectorPluginsResource (org.apache.kafka.connect.runtime.rest.resources.ConnectorPluginsResource)3 ConnectorsResource (org.apache.kafka.connect.runtime.rest.resources.ConnectorsResource)3 Slf4jRequestLog (org.eclipse.jetty.server.Slf4jRequestLog)3