com.sun.jersey.spi.container.servlet.ServletContainer Java Examples
The following examples show how to use
com.sun.jersey.spi.container.servlet.ServletContainer.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WebServer.java From AthenaX with Apache License 2.0 | 6 votes |
public WebServer(URI endpoint) throws IOException { this.server = GrizzlyServerFactory.createHttpServer(endpoint, new HttpHandler() { @Override public void service(Request rqst, Response rspns) throws Exception { rspns.setStatus(HttpStatus.NOT_FOUND_404.getStatusCode(), "Not found"); rspns.getWriter().write("404: not found"); } }); WebappContext context = new WebappContext("WebappContext", BASE_PATH); ServletRegistration registration = context.addServlet("ServletContainer", ServletContainer.class); registration.setInitParameter(ServletContainer.RESOURCE_CONFIG_CLASS, PackagesResourceConfig.class.getName()); StringJoiner sj = new StringJoiner(","); for (String s : PACKAGES) { sj.add(s); } registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, sj.toString()); registration.addMapping(BASE_PATH); context.deploy(server); }
Example #2
Source File: Main.java From hbase-indexer with Apache License 2.0 | 6 votes |
private void startHttpServer() throws Exception { server = new Server(); SelectChannelConnector selectChannelConnector = new SelectChannelConnector(); selectChannelConnector.setPort(11060); server.setConnectors(new Connector[]{selectChannelConnector}); PackagesResourceConfig packagesResourceConfig = new PackagesResourceConfig("com/ngdata/hbaseindexer/rest"); ServletHolder servletHolder = new ServletHolder(new ServletContainer(packagesResourceConfig)); servletHolder.setName("HBase-Indexer"); Context context = new Context(server, "/", Context.NO_SESSIONS); context.addServlet(servletHolder, "/*"); context.setContextPath("/"); context.setAttribute("indexerModel", indexerModel); context.setAttribute("indexerSupervisor", indexerSupervisor); server.setHandler(context); server.start(); }
Example #3
Source File: WebApp.java From hadoop with Apache License 2.0 | 6 votes |
protected void configureWebAppServlets() { // Add in the web services filters/serves if app has them. // Using Jersey/guice integration module. If user has web services // they must have also bound a default one in their webapp code. if (this.wsName != null) { // There seems to be an issue with the guice/jersey integration // where we have to list the stuff we don't want it to serve // through the guicecontainer. In this case its everything except // the the web services api prefix. We can't just change the filter // from /* below - that doesn't work. String regex = "(?!/" + this.wsName + ")"; serveRegex(regex).with(DefaultWrapperServlet.class); Map<String, String> params = new HashMap<String, String>(); params.put(ResourceConfig.FEATURE_IMPLICIT_VIEWABLES, "true"); params.put(ServletContainer.FEATURE_FILTER_FORWARD_ON_404, "true"); params.put(FeaturesAndProperties.FEATURE_XMLROOTELEMENT_PROCESSING, "true"); params.put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, GZIPContentEncodingFilter.class.getName()); params.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, GZIPContentEncodingFilter.class.getName()); filter("/*").through(getWebAppFilterClass(), params); } }
Example #4
Source File: Main.java From wingtips with Apache License 2.0 | 6 votes |
private static ServletContextHandler generateServletContextHandler() throws IOException { ServletContextHandler contextHandler = new ServletContextHandler(); contextHandler.setContextPath("/"); ResourceConfig rc = new WebAppResourceConfig(Collections.<String, Object>emptyMap(), contextHandler.getServletContext()); rc.getSingletons().add(new SampleResource()); ServletContainer jerseyServletContainer = new ServletContainer(rc); contextHandler.addServlet(SampleResource.SampleAsyncServlet.class, SampleResource.ASYNC_PATH); contextHandler.addServlet(SampleResource.SampleBlockingForwardServlet.class, SampleResource.BLOCKING_FORWARD_PATH); contextHandler.addServlet(SampleResource.SampleAsyncForwardServlet.class, SampleResource.ASYNC_FORWARD_PATH); contextHandler.addServlet(SampleResource.SampleAsyncTimeoutServlet.class, SampleResource.ASYNC_TIMEOUT_PATH); contextHandler.addServlet(SampleResource.SampleAsyncErrorServlet.class, SampleResource.ASYNC_ERROR_PATH); contextHandler.addServlet(new ServletHolder(jerseyServletContainer), "/*"); contextHandler.addFilter(RequestTracingFilter.class, "/*", EnumSet.allOf(DispatcherType.class)); return contextHandler; }
Example #5
Source File: EmbeddedJerseyModule.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Inject public EmbeddedServer(SimulatedCloudGateway gateway) { ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); context.setContextPath("/"); jettyServer = new Server(8099); jettyServer.setHandler(context); // Static content DefaultServlet staticContentServlet = new DefaultServlet(); ServletHolder holder = new ServletHolder(staticContentServlet); holder.setInitOrder(1); context.addServlet(holder, "/static/*"); context.setResourceBase(resolveStaticContentLocation()); // Jersey DefaultResourceConfig config = new DefaultResourceConfig(); config.getClasses().add(JsonMessageReaderWriter.class); config.getClasses().add(TitusExceptionMapper.class); config.getSingletons().add(new SimulatedAgentsServiceResource(gateway)); ServletHolder jerseyServlet = new ServletHolder(new ServletContainer(config)); jerseyServlet.setInitOrder(0); context.addServlet(jerseyServlet, "/cloud/*"); }
Example #6
Source File: WebApp.java From big-c with Apache License 2.0 | 6 votes |
protected void configureWebAppServlets() { // Add in the web services filters/serves if app has them. // Using Jersey/guice integration module. If user has web services // they must have also bound a default one in their webapp code. if (this.wsName != null) { // There seems to be an issue with the guice/jersey integration // where we have to list the stuff we don't want it to serve // through the guicecontainer. In this case its everything except // the the web services api prefix. We can't just change the filter // from /* below - that doesn't work. String regex = "(?!/" + this.wsName + ")"; serveRegex(regex).with(DefaultWrapperServlet.class); Map<String, String> params = new HashMap<String, String>(); params.put(ResourceConfig.FEATURE_IMPLICIT_VIEWABLES, "true"); params.put(ServletContainer.FEATURE_FILTER_FORWARD_ON_404, "true"); params.put(FeaturesAndProperties.FEATURE_XMLROOTELEMENT_PROCESSING, "true"); params.put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, GZIPContentEncodingFilter.class.getName()); params.put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, GZIPContentEncodingFilter.class.getName()); filter("/*").through(getWebAppFilterClass(), params); } }
Example #7
Source File: HttpServer2.java From knox with Apache License 2.0 | 5 votes |
/** * Add a Jersey resource package. * @param packageName The Java package name containing the Jersey resource. * @param pathSpec The path spec for the servlet * @param params properties and features for ResourceConfig */ public void addJerseyResourcePackage(final String packageName, final String pathSpec, Map<String, String> params) { LOG.info("addJerseyResourcePackage: packageName=" + packageName + ", pathSpec=" + pathSpec); final ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); sh.setInitParameter("com.sun.jersey.config.property.packages", packageName); for (Map.Entry<String, String> entry : params.entrySet()) { sh.setInitParameter(entry.getKey(), entry.getValue()); } webAppContext.addServlet(sh, pathSpec); }
Example #8
Source File: RestfulServer.java From shardingsphere-elasticjob-cloud with Apache License 2.0 | 5 votes |
private ServletHolder getServletHolder(final String packages) { ServletHolder result = new ServletHolder(ServletContainer.class); result.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, Joiner.on(",").join(RestfulServer.class.getPackage().getName(), packages)); result.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", PackagesResourceConfig.class.getName()); result.setInitParameter("com.sun.jersey.api.json.POJOMappingFeature", Boolean.TRUE.toString()); result.setInitParameter("resteasy.scan.providers", Boolean.TRUE.toString()); result.setInitParameter("resteasy.use.builtin.providers", Boolean.FALSE.toString()); return result; }
Example #9
Source File: HttpServer2.java From knox with Apache License 2.0 | 5 votes |
/** * Add a Jersey resource package. * @param packageName The Java package name containing the Jersey resource. * @param pathSpec The path spec for the servlet * @param params properties and features for ResourceConfig */ public void addJerseyResourcePackage(final String packageName, final String pathSpec, Map<String, String> params) { LOG.info("addJerseyResourcePackage: packageName=" + packageName + ", pathSpec=" + pathSpec); final ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); sh.setInitParameter("com.sun.jersey.config.property.packages", packageName); for (Map.Entry<String, String> entry : params.entrySet()) { sh.setInitParameter(entry.getKey(), entry.getValue()); } webAppContext.addServlet(sh, pathSpec); }
Example #10
Source File: TestMapsWithJersey.java From curator with Apache License 2.0 | 5 votes |
@BeforeMethod public void setup() throws Exception { context = new MapDiscoveryContext(new MockServiceDiscovery<Map<String, String>>(), new RandomStrategy<Map<String, String>>(), 1000); serviceNamesMarshaller = new JsonServiceNamesMarshaller(); serviceInstanceMarshaller = new JsonServiceInstanceMarshaller<Map<String, String>>(context); serviceInstancesMarshaller = new JsonServiceInstancesMarshaller<Map<String, String>>(context); Application application = new DefaultResourceConfig() { @Override public Set<Class<?>> getClasses() { Set<Class<?>> classes = Sets.newHashSet(); classes.add(MapDiscoveryResource.class); return classes; } @Override public Set<Object> getSingletons() { Set<Object> singletons = Sets.newHashSet(); singletons.add(context); singletons.add(serviceNamesMarshaller); singletons.add(serviceInstanceMarshaller); singletons.add(serviceInstancesMarshaller); return singletons; } }; ServletContainer container = new ServletContainer(application); port = InstanceSpec.getRandomPort(); server = new Server(port); Context root = new Context(server, "/", Context.SESSIONS); root.addServlet(new ServletHolder(container), "/*"); server.start(); }
Example #11
Source File: TestObjectPayloadWithJersey.java From curator with Apache License 2.0 | 5 votes |
@BeforeMethod public void setup() throws Exception { context = new ServiceDetailsDiscoveryContext(new MockServiceDiscovery<ServiceDetails>(), new RandomStrategy<ServiceDetails>(), 1000); serviceNamesMarshaller = new JsonServiceNamesMarshaller(); serviceInstanceMarshaller = new JsonServiceInstanceMarshaller<ServiceDetails>(context); serviceInstancesMarshaller = new JsonServiceInstancesMarshaller<ServiceDetails>(context); Application application = new DefaultResourceConfig() { @Override public Set<Class<?>> getClasses() { Set<Class<?>> classes = Sets.newHashSet(); classes.add(ServiceDetailsDiscoveryResource.class); return classes; } @Override public Set<Object> getSingletons() { Set<Object> singletons = Sets.newHashSet(); singletons.add(context); singletons.add(serviceNamesMarshaller); singletons.add(serviceInstanceMarshaller); singletons.add(serviceInstancesMarshaller); return singletons; } }; ServletContainer container = new ServletContainer(application); port = InstanceSpec.getRandomPort(); server = new Server(port); Context root = new Context(server, "/", Context.SESSIONS); root.addServlet(new ServletHolder(container), "/*"); server.start(); }
Example #12
Source File: TestStringsWithJersey.java From curator with Apache License 2.0 | 5 votes |
@BeforeMethod public void setup() throws Exception { context = new StringDiscoveryContext(new MockServiceDiscovery<String>(), new RandomStrategy<String>(), 1000); serviceNamesMarshaller = new JsonServiceNamesMarshaller(); serviceInstanceMarshaller = new JsonServiceInstanceMarshaller<String>(context); serviceInstancesMarshaller = new JsonServiceInstancesMarshaller<String>(context); Application application = new DefaultResourceConfig() { @Override public Set<Class<?>> getClasses() { Set<Class<?>> classes = Sets.newHashSet(); classes.add(StringDiscoveryResource.class); return classes; } @Override public Set<Object> getSingletons() { Set<Object> singletons = Sets.newHashSet(); singletons.add(context); singletons.add(serviceNamesMarshaller); singletons.add(serviceInstanceMarshaller); singletons.add(serviceInstancesMarshaller); return singletons; } }; ServletContainer container = new ServletContainer(application); port = InstanceSpec.getRandomPort(); server = new Server(port); Context root = new Context(server, "/", Context.SESSIONS); root.addServlet(new ServletHolder(container), "/*"); server.start(); }
Example #13
Source File: InjectedWebListener.java From Raigad with Apache License 2.0 | 5 votes |
@Override protected void configureServlets() { Map<String, String> params = new HashMap<String, String>(); params.put(PackagesResourceConfig.PROPERTY_PACKAGES, "unbound"); params.put("com.sun.jersey.config.property.packages", "com.netflix.raigad.resources"); params.put(ServletContainer.PROPERTY_FILTER_CONTEXT_PATH, "/REST"); serve("/REST/*").with(GuiceContainer.class, params); }
Example #14
Source File: EurekaServerAutoConfiguration.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
/** * Register the Jersey filter. * @param eurekaJerseyApp an {@link Application} for the filter to be registered * @return a jersey {@link FilterRegistrationBean} */ @Bean public FilterRegistrationBean<?> jerseyFilterRegistration( javax.ws.rs.core.Application eurekaJerseyApp) { FilterRegistrationBean<Filter> bean = new FilterRegistrationBean<Filter>(); bean.setFilter(new ServletContainer(eurekaJerseyApp)); bean.setOrder(Ordered.LOWEST_PRECEDENCE); bean.setUrlPatterns( Collections.singletonList(EurekaConstants.DEFAULT_PREFIX + "/*")); return bean; }
Example #15
Source File: EurekaServerAutoConfiguration.java From spring-cloud-netflix with Apache License 2.0 | 5 votes |
/** * Construct a Jersey {@link javax.ws.rs.core.Application} with all the resources * required by the Eureka server. * @param environment an {@link Environment} instance to retrieve classpath resources * @param resourceLoader a {@link ResourceLoader} instance to get classloader from * @return created {@link Application} object */ @Bean public javax.ws.rs.core.Application jerseyApplication(Environment environment, ResourceLoader resourceLoader) { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( false, environment); // Filter to include only classes that have a particular annotation. // provider.addIncludeFilter(new AnnotationTypeFilter(Path.class)); provider.addIncludeFilter(new AnnotationTypeFilter(Provider.class)); // Find classes in Eureka packages (or subpackages) // Set<Class<?>> classes = new HashSet<>(); for (String basePackage : EUREKA_PACKAGES) { Set<BeanDefinition> beans = provider.findCandidateComponents(basePackage); for (BeanDefinition bd : beans) { Class<?> cls = ClassUtils.resolveClassName(bd.getBeanClassName(), resourceLoader.getClassLoader()); classes.add(cls); } } // Construct the Jersey ResourceConfig Map<String, Object> propsAndFeatures = new HashMap<>(); propsAndFeatures.put( // Skip static content used by the webapp ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX, EurekaConstants.DEFAULT_PREFIX + "/(fonts|images|css|js)/.*"); DefaultResourceConfig rc = new DefaultResourceConfig(classes); rc.setPropertiesAndFeatures(propsAndFeatures); return rc; }
Example #16
Source File: ServletRegistrationComponentTest.java From roboconf-platform with Apache License 2.0 | 5 votes |
@Test public void testSetEnableCors() throws Exception { // No NPE this.register.setEnableCors( true ); this.register.setEnableCors( false ); // Act like if the component had been started this.register.app = Mockito.spy( new RestApplication( this.manager )); this.register.jerseyServlet = Mockito.mock( ServletContainer.class ); this.register.setEnableCors( true ); Mockito.verify( this.register.app, Mockito.times( 1 )).enableCors( true ); Mockito.verify( this.register.jerseyServlet, Mockito.only()).reload(); Mockito.reset( this.register.app ); Mockito.reset( this.register.jerseyServlet ); this.register.setEnableCors( false ); Mockito.verify( this.register.app, Mockito.times( 1 )).enableCors( false ); Mockito.verify( this.register.jerseyServlet, Mockito.only()).reload(); // Stop... this.register.stopping(); // No NPE this.register.setEnableCors( true ); Assert.assertTrue( this.register.isCorsEnabled()); this.register.setEnableCors( false ); Assert.assertFalse( this.register.isCorsEnabled()); }
Example #17
Source File: RestServer.java From hraven with Apache License 2.0 | 5 votes |
@Override protected void startUp() throws Exception { // setup the jetty config ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.packages", "com.twitter.hraven.rest"); sh.setInitParameter(JSONConfiguration.FEATURE_POJO_MAPPING, "true"); server = new Server(); Connector connector = new SelectChannelConnector(); connector.setPort(this.port); connector.setHost(address); server.addConnector(connector); // TODO: in the future we may want to provide settings for the min and max threads // Jetty sets the default max thread number to 250, if we don't set it. // QueuedThreadPool threadPool = new QueuedThreadPool(); server.setThreadPool(threadPool); server.setSendServerVersion(false); server.setSendDateHeader(false); server.setStopAtShutdown(true); // set up context Context context = new Context(server, "/", Context.SESSIONS); context.addServlet(sh, "/*"); // start server server.start(); }
Example #18
Source File: RestInputIT.java From pentaho-kettle with Apache License 2.0 | 5 votes |
@BeforeClass public static void setUp() throws Exception { KettleEnvironment.init(); tester = new ServletTester(); tester.setContextPath( "/context" ); tester.setResourceBase( RestInputIT.class.getResource( "/" ).getFile() ); final ServletHolder servletHolder = tester.addServlet( ServletContainer.class, "/*" ); servletHolder.setInitParameter( "com.sun.jersey.config.property.classpath", "/" ); servletHolder.setInitParameter( "jersey.config.server.provider.classnames", SimpleRestService.class.getName() ); tester.start(); }
Example #19
Source File: GuestbookResourceTest.java From appengine-angular-guestbook-java with Apache License 2.0 | 5 votes |
@Before public void setUp() throws ServletException { helper.setUp(); // Create a jersey ServletContainer object with mocked ServletConfig and ServletContext. servletContainer = new ServletContainer(Resources.class); ServletConfig servletConfig = mock(ServletConfig.class); ServletContext servletContext = mock(ServletContext.class); when(servletConfig.getServletContext()).thenReturn(servletContext); servletContainer.init(servletConfig); }
Example #20
Source File: JettyServer.java From exhibitor with Apache License 2.0 | 5 votes |
public JettyServer(int port, HttpsConfiguration httpsConf) { server = new Server(); SslSelectChannelConnector connector = new SslSelectChannelConnector(); connector.setPort(port); connector.setKeystore(httpsConf.getServerKeystorePath()); connector.setKeyPassword(httpsConf.getServerKeystorePassword()); if ( httpsConf.isVerifyPeerCert() ) { connector.setTruststore(httpsConf.getTruststorePath()); connector.setTrustPassword(httpsConf.getTruststorePassword()); connector.setNeedClientAuth(true); } connector.setWantClientAuth(httpsConf.isRequireClientCert()); connector.setAcceptors(8); connector.setMaxIdleTime(5000); connector.setAcceptQueueSize(32); server.addConnector(connector); server.setStopAtShutdown(true); DefaultResourceConfig config = new DefaultResourceConfig(JettyServer.RestService.class); ServletContainer container = new ServletContainer(config); Context context = new Context(server, "/", Context.SESSIONS); context.addServlet(new ServletHolder(container), "/*"); }
Example #21
Source File: HttpServer2.java From lucene-solr with Apache License 2.0 | 5 votes |
/** * Add a Jersey resource package. * @param packageName The Java package name containing the Jersey resource. * @param pathSpec The path spec for the servlet */ public void addJerseyResourcePackage(final String packageName, final String pathSpec) { LOG.info("addJerseyResourcePackage: packageName={}, pathcpec={}" , packageName, pathSpec); final ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); sh.setInitParameter("com.sun.jersey.config.property.packages", packageName); webAppContext.addServlet(sh, pathSpec); }
Example #22
Source File: Main.java From backstopper with Apache License 2.0 | 5 votes |
private static ServletContextHandler generateServletContextHandler() throws IOException { ServletContextHandler contextHandler = new ServletContextHandler(); contextHandler.setContextPath("/"); ResourceConfig rc = new WebAppResourceConfig(Collections.<String, Object>emptyMap(), contextHandler.getServletContext()); rc.getSingletons().add(Jersey1SampleConfigHelper.generateJerseyApiExceptionHandler()); rc.getSingletons().add(Jersey1SampleConfigHelper.generateSampleResource()); ServletContainer jerseyServletContainer = new ServletContainer(rc); contextHandler.addServlet(new ServletHolder(jerseyServletContainer), "/*"); return contextHandler; }
Example #23
Source File: HttpServer2.java From big-c with Apache License 2.0 | 5 votes |
/** * Add a Jersey resource package. * @param packageName The Java package name containing the Jersey resource. * @param pathSpec The path spec for the servlet */ public void addJerseyResourcePackage(final String packageName, final String pathSpec) { LOG.info("addJerseyResourcePackage: packageName=" + packageName + ", pathSpec=" + pathSpec); final ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); sh.setInitParameter("com.sun.jersey.config.property.packages", packageName); webAppContext.addServlet(sh, pathSpec); }
Example #24
Source File: HttpServer.java From big-c with Apache License 2.0 | 5 votes |
/** * Add a Jersey resource package. * @param packageName The Java package name containing the Jersey resource. * @param pathSpec The path spec for the servlet */ public void addJerseyResourcePackage(final String packageName, final String pathSpec) { LOG.info("addJerseyResourcePackage: packageName=" + packageName + ", pathSpec=" + pathSpec); final ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); sh.setInitParameter("com.sun.jersey.config.property.packages", packageName); webAppContext.addServlet(sh, pathSpec); }
Example #25
Source File: HttpServer2.java From hadoop with Apache License 2.0 | 5 votes |
/** * Add a Jersey resource package. * @param packageName The Java package name containing the Jersey resource. * @param pathSpec The path spec for the servlet */ public void addJerseyResourcePackage(final String packageName, final String pathSpec) { LOG.info("addJerseyResourcePackage: packageName=" + packageName + ", pathSpec=" + pathSpec); final ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); sh.setInitParameter("com.sun.jersey.config.property.packages", packageName); webAppContext.addServlet(sh, pathSpec); }
Example #26
Source File: HttpServer.java From hadoop with Apache License 2.0 | 5 votes |
/** * Add a Jersey resource package. * @param packageName The Java package name containing the Jersey resource. * @param pathSpec The path spec for the servlet */ public void addJerseyResourcePackage(final String packageName, final String pathSpec) { LOG.info("addJerseyResourcePackage: packageName=" + packageName + ", pathSpec=" + pathSpec); final ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); sh.setInitParameter("com.sun.jersey.config.property.packages", packageName); webAppContext.addServlet(sh, pathSpec); }
Example #27
Source File: EurekaServerAutoConfiguration.java From didi-eureka-server with MIT License | 5 votes |
/** * Construct a Jersey {@link javax.ws.rs.core.Application} with all the resources * required by the Eureka server. */ @Bean public javax.ws.rs.core.Application jerseyApplication(Environment environment, ResourceLoader resourceLoader) { ClassPathScanningCandidateComponentProvider provider = new ClassPathScanningCandidateComponentProvider( false, environment); // Filter to include only classes that have a particular annotation. // provider.addIncludeFilter(new AnnotationTypeFilter(Path.class)); provider.addIncludeFilter(new AnnotationTypeFilter(Provider.class)); // Find classes in Eureka packages (or subpackages) // Set<Class<?>> classes = new HashSet<Class<?>>(); for (String basePackage : EUREKA_PACKAGES) { Set<BeanDefinition> beans = provider.findCandidateComponents(basePackage); for (BeanDefinition bd : beans) { Class<?> cls = ClassUtils.resolveClassName(bd.getBeanClassName(), resourceLoader.getClassLoader()); classes.add(cls); } } // Construct the Jersey ResourceConfig // Map<String, Object> propsAndFeatures = new HashMap<String, Object>(); propsAndFeatures.put( // Skip static content used by the webapp ServletContainer.PROPERTY_WEB_PAGE_CONTENT_REGEX, EurekaConstants.DEFAULT_PREFIX + "/(fonts|images|css|js)/.*"); DefaultResourceConfig rc = new DefaultResourceConfig(classes); rc.setPropertiesAndFeatures(propsAndFeatures); return rc; }
Example #28
Source File: EurekaServerAutoConfiguration.java From didi-eureka-server with MIT License | 5 votes |
/** * Register the Jersey filter */ @Bean public FilterRegistrationBean jerseyFilterRegistration( javax.ws.rs.core.Application eurekaJerseyApp) { FilterRegistrationBean bean = new FilterRegistrationBean(); bean.setFilter(new ServletContainer(eurekaJerseyApp)); bean.setOrder(Ordered.LOWEST_PRECEDENCE); bean.setUrlPatterns( Collections.singletonList(EurekaConstants.DEFAULT_PREFIX + "/*")); return bean; }
Example #29
Source File: HttpServer2.java From hadoop-ozone with Apache License 2.0 | 5 votes |
/** * Add a Jersey resource package. * @param packageName The Java package name containing the Jersey resource. * @param pathSpec The path spec for the servlet */ public void addJerseyResourcePackage(final String packageName, final String pathSpec) { LOG.info("addJerseyResourcePackage: packageName={}, pathSpec={}", packageName, pathSpec); final ServletHolder sh = new ServletHolder(ServletContainer.class); sh.setInitParameter("com.sun.jersey.config.property.resourceConfigClass", "com.sun.jersey.api.core.PackagesResourceConfig"); sh.setInitParameter("com.sun.jersey.config.property.packages", packageName); webAppContext.addServlet(sh, pathSpec); }
Example #30
Source File: HbaseRestLocalCluster.java From hadoop-mini-clusters with Apache License 2.0 | 4 votes |
Pair<FilterHolder, Class<? extends ServletContainer>> loginServerPrincipal(UserProvider userProvider, Configuration conf) throws Exception { Class<? extends ServletContainer> containerClass = ServletContainer.class; return new Pair<>(null, containerClass); }