com.sun.jersey.api.core.DefaultResourceConfig Java Examples
The following examples show how to use
com.sun.jersey.api.core.DefaultResourceConfig.
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: 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 #2
Source File: JerseyModule.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Advises @Singleton @Named("governator") UnaryOperator<DefaultResourceConfig> getConfig() { return config -> { // providers config.getClasses().add(JsonMessageReaderWriter.class); config.getClasses().add(TitusExceptionMapper.class); config.getClasses().add(InstrumentedResourceMethodDispatchAdapter.class); // resources config.getClasses().add(HealthResource.class); config.getClasses().add(FederationSchedulerResource.class); config.getClasses().add(JobManagementResource.class); config.getClasses().add(AutoScalingResource.class); config.getClasses().add(LoadBalancerResource.class); config.getClasses().add(FederationV2CapacityGroupResource.class); config.getClasses().add(MachineResource.class); return config; }; }
Example #3
Source File: GatewayJerseyModule.java From titus-control-plane with Apache License 2.0 | 6 votes |
@Advises @Singleton @Named("governator") UnaryOperator<DefaultResourceConfig> getConfig() { return config -> { // providers config.getClasses().add(JsonMessageReaderWriter.class); config.getClasses().add(TitusExceptionMapper.class); config.getClasses().add(InstrumentedResourceMethodDispatchAdapter.class); // resources config.getClasses().add(HealthResource.class); config.getClasses().add(AgentManagementResource.class); config.getClasses().add(JobManagementResource.class); config.getClasses().add(EvictionResource.class); config.getClasses().add(AutoScalingResource.class); config.getClasses().add(SchedulerResource.class); config.getClasses().add(LoadBalancerResource.class); config.getClasses().add(MachineResource.class); return config; }; }
Example #4
Source File: JerseySupport.java From exhibitor with Apache License 2.0 | 6 votes |
/** * Return a new Jersey config instance that correctly supplies all needed Exhibitor * objects * * @param context the UIContext * @return new config */ public static DefaultResourceConfig newApplicationConfig(UIContext context) { final Set<Object> singletons = getSingletons(context); final Set<Class<?>> classes = getClasses(); return new DefaultResourceConfig() { @Override public Set<Class<?>> getClasses() { return classes; } @Override public Set<Object> getSingletons() { return singletons; } }; }
Example #5
Source File: DaggerComponentProviderFactoryTest.java From dagger-servlet with Apache License 2.0 | 6 votes |
@Test public void testClassesFromProvidesMethodsWithModuleInjectsAndNoInjectsConstructorAreRegistered() { ResourceConfig config = new DefaultResourceConfig(); ObjectGraph objectGraph = ObjectGraph.create(SomeInjectableProvidesModule.class, new SomeOtherInjectableProvidesModule()); IoCComponentProviderFactory factory = new DaggerComponentProviderFactory(config, objectGraph, new Object[]{SomeInjectableProvidesModule.class, new SomeOtherInjectableProvidesModule()}); assertTrue(config.getClasses().contains(SomeProvidesInjectableResource.class)); assertTrue(config.getClasses().contains(SomeOtherProvidesInjectableResource.class)); assertTrue(config.getClasses().contains(SomeProvidesInjectableProvider.class)); SomeProvidesInjectableResource someResource = (SomeProvidesInjectableResource) factory. getComponentProvider(SomeProvidesInjectableResource.class).getInstance(); SomeOtherProvidesInjectableResource someOtherResource = (SomeOtherProvidesInjectableResource) factory .getComponentProvider(SomeOtherProvidesInjectableResource.class).getInstance(); SomeProvidesInjectableProvider someProvider = (SomeProvidesInjectableProvider) factory .getComponentProvider(SomeProvidesInjectableProvider.class).getInstance(); assertNotNull(someResource); assertNotNull(someOtherResource); assertNotNull(someProvider); }
Example #6
Source File: TrimouViewRendererTest.java From trimou with Apache License 2.0 | 5 votes |
@Override protected AppDescriptor configure() { final DefaultResourceConfig config = new DefaultResourceConfig(); final ViewRenderer renderer = new TrimouViewRenderer.Builder().build(); config.getSingletons().add(new ViewMessageBodyWriter(new MetricRegistry(), ImmutableList.of(renderer))); config.getSingletons().add(new TestResource()); return new LowLevelAppDescriptor.Builder(config).build(); }
Example #7
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 #8
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 #9
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 #10
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 #11
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 #12
Source File: DaggerComponentProviderFactoryTest.java From dagger-servlet with Apache License 2.0 | 5 votes |
@Test public void testProviderClassesAreRegistered() { ResourceConfig config = new DefaultResourceConfig(); ObjectGraph objectGraph = ObjectGraph.create(SomeModule.class, new SomeOtherModule()); new DaggerComponentProviderFactory(config, objectGraph, new Object[]{SomeModule.class, new SomeOtherModule()}); assertTrue(config.getClasses().contains(SomeProvider.class)); }
Example #13
Source File: DaggerComponentProviderFactoryTest.java From dagger-servlet with Apache License 2.0 | 5 votes |
@Test public void testClassesFromProvidesMethodsWithoutModuleInjectsAreNotRegistered() { ResourceConfig config = new DefaultResourceConfig(); ObjectGraph objectGraph = ObjectGraph.create(SomeProvidesModule.class, new SomeOtherProvidesModule()); new DaggerComponentProviderFactory(config, objectGraph, new Object[]{SomeProvidesModule.class, new SomeOtherProvidesModule()}); assertFalse(config.getClasses().contains(SomeResource.class)); assertFalse(config.getClasses().contains(SomeOtherResource.class)); assertFalse(config.getClasses().contains(SomeProvider.class)); }
Example #14
Source File: DaggerComponentProviderFactoryTest.java From dagger-servlet with Apache License 2.0 | 5 votes |
@Test public void testClassesFromModuleInstancesAndModuleClassesAreRegistered() { ResourceConfig config = new DefaultResourceConfig(); ObjectGraph objectGraph = ObjectGraph.create(SomeModule.class, new SomeOtherModule()); new DaggerComponentProviderFactory(config, objectGraph, new Object[]{SomeModule.class, new SomeOtherModule()}); assertTrue(config.getClasses().contains(SomeResource.class)); assertTrue(config.getClasses().contains(SomeOtherResource.class)); }
Example #15
Source File: DaggerComponentProviderFactoryTest.java From dagger-servlet with Apache License 2.0 | 5 votes |
@Test public void testModuleAnnotationRequiredOnModules() { ObjectGraph objectGraph = ObjectGraph.create(SomeModule.class); try { new DaggerComponentProviderFactory(new DefaultResourceConfig(), objectGraph, new Object[]{SomeNonModule.class}); fail(); } catch (IllegalStateException e) { assertEquals("All dagger modules must be annotated with @Module", e.getMessage()); } }
Example #16
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 #17
Source File: JerseyModule.java From titus-control-plane with Apache License 2.0 | 5 votes |
@Advises @Singleton @Named("governator") public UnaryOperator<DefaultResourceConfig> getConfig() { return config -> { // Providers config.getClasses().add(JsonMessageReaderWriter.class); config.getClasses().add(TitusExceptionMapper.class); config.getClasses().add(InstrumentedResourceMethodDispatchAdapter.class); // Runtime (diagnostic) resources config.getClasses().add(HealthCheckResource.class); config.getClasses().add(LeaderResource.class); config.getClasses().add(FitResource.class); config.getClasses().add(LocalSchedulerResource.class); config.getClasses().add(ServerStatusResource.class); config.getClasses().add(SupervisorResource.class); config.getClasses().add(OpportunisticAvailabilityResource.class); // V2 resources config.getClasses().add(VmManagementResource.class); config.getClasses().add(ApplicationSlaManagementResource.class); config.getClasses().add(ResourceConsumptionResource.class); return config; }; }
Example #18
Source File: DaggerContainer.java From dagger-servlet with Apache License 2.0 | 4 votes |
@Override protected ResourceConfig getDefaultResourceConfig(Map<String, Object> properties, WebConfig webConfig) throws ServletException { return new DefaultResourceConfig(); }