com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory Java Examples
The following examples show how to use
com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory.
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: ManagementWsDelegateTest.java From roboconf-platform with Apache License 2.0 | 6 votes |
@Before public void before() throws Exception { // Create the manager this.manager = new Manager(); this.manager.setTargetResolver( new TestTargetResolver()); this.manager.setMessagingType(MessagingConstants.FACTORY_TEST); this.manager.configurationMngr().setWorkingDirectory( this.folder.newFolder()); this.manager.start(); // Create the wrapper and complete configuration this.managerWrapper = new TestManagerWrapper( this.manager ); this.managerWrapper.configureMessagingForTest(); this.manager.reconfigure(); // Prepare the client URI uri = UriBuilder.fromUri( REST_URI ).build(); RestApplication restApp = new RestApplication( this.manager ); this.httpServer = GrizzlyServerFactory.createHttpServer( uri, restApp ); this.client = new WsClient( REST_URI ); }
Example #3
Source File: AuthenticationWsDelegateTest.java From roboconf-platform with Apache License 2.0 | 6 votes |
@Before public void before() throws Exception { // Prevent NPE during tests Manager manager = Mockito.mock( Manager.class ); IPreferencesMngr preferencesMngr = Mockito.mock( IPreferencesMngr.class ); Mockito.when( manager.preferencesMngr()).thenReturn( preferencesMngr ); // Create the application URI uri = UriBuilder.fromUri( REST_URI ).build(); RestApplication restApp = new RestApplication( manager ); // Configure the authentication part AuthenticationManager authenticationMngr = new AuthenticationManager( "whatever" ); this.authService = Mockito.mock( IAuthService.class ); authenticationMngr.setAuthService( this.authService ); restApp.setAuthenticationManager( authenticationMngr ); // Launch the application in a real web server this.httpServer = GrizzlyServerFactory.createHttpServer( uri, restApp ); this.client = new WsClient( REST_URI ); }
Example #4
Source File: PreferencesWsDelegateTest.java From roboconf-platform with Apache License 2.0 | 6 votes |
@Before public void before() throws Exception { // Create the manager this.manager = new Manager(); this.manager.setTargetResolver( new TestTargetResolver()); this.manager.setMessagingType(MessagingConstants.FACTORY_TEST); this.manager.configurationMngr().setWorkingDirectory( this.folder.newFolder()); this.manager.start(); // Create the wrapper and complete configuration this.managerWrapper = new TestManagerWrapper( this.manager ); this.managerWrapper.configureMessagingForTest(); this.manager.reconfigure(); // Prepare the client URI uri = UriBuilder.fromUri( REST_URI ).build(); RestApplication restApp = new RestApplication( this.manager ); this.httpServer = GrizzlyServerFactory.createHttpServer( uri, restApp ); this.client = new WsClient( REST_URI ); }
Example #5
Source File: ServletRegistrationComponentTest.java From roboconf-platform with Apache License 2.0 | 6 votes |
@Test public void testJsonSerialization_application() throws Exception { // This test guarantees that in an non-OSGi environment, // our REST application uses the properties we define. // And, in particular, the JSon serialization that we tailored. URI uri = UriBuilder.fromUri( "http://localhost/" ).port( 8090 ).build(); RestApplication restApp = new RestApplication( this.manager ); HttpServer httpServer = null; String received = null; try { httpServer = GrizzlyServerFactory.createHttpServer( uri, restApp ); Assert.assertTrue( httpServer.isStarted()); URI targetUri = UriBuilder.fromUri( uri ).path( UrlConstants.APPLICATIONS ).build(); received = Utils.readUrlContent( targetUri.toString()); } finally { if( httpServer != null ) httpServer.stop(); } String expected = JSonBindingUtils.createObjectMapper().writeValueAsString( Arrays.asList( this.app )); Assert.assertEquals( expected, received ); }
Example #6
Source File: ServerProvider.java From angulardemorestful with MIT License | 6 votes |
public void createServer() throws IOException { System.out.println("Starting grizzly..."); Injector injector = Guice.createInjector(new ServletModule() { @Override protected void configureServlets() { bind(UserService.class).to(UserServiceImpl.class); bind(UserRepository.class).to(UserMockRepositoryImpl.class); bind(DummyService.class).to(DummyServiceImpl.class); bind(DummyRepository.class).to(DummyMockRepositoryImpl.class); // hook Jackson into Jersey as the POJO <-> JSON mapper bind(JacksonJsonProvider.class).in(Scopes.SINGLETON); } }); ResourceConfig rc = new PackagesResourceConfig("ngdemo.web"); IoCComponentProviderFactory ioc = new GuiceComponentProviderFactory(rc, injector); server = GrizzlyServerFactory.createHttpServer(BASE_URI + "web/", rc, ioc); System.out.println(String.format("Jersey app started with WADL available at " + "%srest/application.wadl\nTry out %sngdemo\nHit enter to stop it...", BASE_URI, BASE_URI)); }
Example #7
Source File: GrizzlyTestServer.java From dagger-servlet with Apache License 2.0 | 5 votes |
public <T extends DaggerServletContextListener> void startServer(Class<T> listenerClass) { LOGGER.info("Starting test server"); WebappContext context = new WebappContext("Test", getUri().getRawPath()); context.addListener(listenerClass); daggerFilter = new DaggerFilter(); FilterRegistration filterRegistration = context.addFilter("daggerFilter", daggerFilter); filterRegistration.addMappingForUrlPatterns(null, "/*"); ServletRegistration servletRegistration = context.addServlet("TestServlet", new HttpServlet() { }); servletRegistration.addMapping("/dagger-jersey/*"); try { httpServer = GrizzlyServerFactory.createHttpServer(getUri(), (HttpHandler) null); context.deploy(httpServer); httpServer.start(); LOGGER.info("Test server started"); } catch (IOException e) { throw Throwables.propagate(e); } }
Example #8
Source File: ApplicationWsDelegateTest.java From roboconf-platform with Apache License 2.0 | 5 votes |
@Before public void before() throws Exception { // Create the manager this.manager = new Manager(); this.manager.setMessagingType( MessagingConstants.FACTORY_TEST ); this.manager.setTargetResolver( new TestTargetResolver()); this.manager.configurationMngr().setWorkingDirectory( this.folder.newFolder()); this.manager.start(); // Create the wrapper and complete configuration this.managerWrapper = new TestManagerWrapper( this.manager ); this.managerWrapper.configureMessagingForTest(); this.manager.reconfigure(); // Get the messaging client this.msgClient = (TestClient) this.managerWrapper.getInternalMessagingClient(); this.msgClient.clearMessages(); // Disable the messages timer for predictability TestUtils.getInternalField( this.manager, "timer", Timer.class).cancel(); URI uri = UriBuilder.fromUri( REST_URI ).build(); RestApplication restApp = new RestApplication( this.manager ); this.httpServer = GrizzlyServerFactory.createHttpServer( uri, restApp );; // Load an application this.app = new TestApplication(); this.app.setDirectory( this.folder.newFolder()); this.ma = new ManagedApplication( this.app ); this.managerWrapper.addManagedApplication( this.ma ); this.client = new WsClient( REST_URI ); }
Example #9
Source File: TargetWsDelegateTest.java From roboconf-platform with Apache License 2.0 | 5 votes |
@Before public void before() throws Exception { // Create the manager this.manager = new Manager(); this.manager.setMessagingType(MessagingConstants.FACTORY_TEST); this.manager.setTargetResolver( new TestTargetResolver()); this.manager.configurationMngr().setWorkingDirectory( this.folder.newFolder()); this.manager.start(); // Create the wrapper and complete configuration this.managerWrapper = new TestManagerWrapper( this.manager ); this.managerWrapper.configureMessagingForTest(); this.manager.reconfigure(); // Disable the messages timer for predictability TestUtils.getInternalField( this.manager, "timer", Timer.class).cancel(); URI uri = UriBuilder.fromUri( REST_URI ).build(); RestApplication restApp = new RestApplication( this.manager ); this.httpServer = GrizzlyServerFactory.createHttpServer( uri, restApp ); // Load an application this.app = new TestApplication(); this.app.setDirectory( this.folder.newFolder()); this.ma = new ManagedApplication( this.app ); this.managerWrapper.addManagedApplication( this.ma ); this.client = new WsClient( REST_URI ); }
Example #10
Source File: DebugWsDelegateTest.java From roboconf-platform with Apache License 2.0 | 5 votes |
@Before public void before() throws Exception { // Create the manager this.manager = new Manager(); this.manager.setMessagingType(MessagingConstants.FACTORY_TEST); this.manager.setTargetResolver( new TestTargetResolver()); this.manager.configurationMngr().setWorkingDirectory( this.folder.newFolder()); this.manager.start(); // Create the wrapper and complete configuration this.managerWrapper = new TestManagerWrapper( this.manager ); this.managerWrapper.configureMessagingForTest(); this.manager.reconfigure(); // Disable the messages timer for predictability TestUtils.getInternalField( this.manager, "timer", Timer.class).cancel(); // Configure a single application to be used by the tests this.app = new TestApplication(); this.app.setDirectory( this.folder.newFolder()); URI uri = UriBuilder.fromUri( REST_URI ).build(); RestApplication restApp = new RestApplication( this.manager ); this.httpServer = GrizzlyServerFactory.createHttpServer( uri, restApp );; this.client = new WsClient( REST_URI ); }
Example #11
Source File: ServletRegistrationComponentTest.java From roboconf-platform with Apache License 2.0 | 5 votes |
@Test public void testJsonSerialization_instance() throws Exception { // This test guarantees that in an non-OSGi environment, // our REST application uses the properties we define. // And, in particular, the JSon serialization that we tailored. URI uri = UriBuilder.fromUri( "http://localhost/" ).port( 8090 ).build(); RestApplication restApp = new RestApplication( this.manager ); HttpServer httpServer = null; String received = null; try { httpServer = GrizzlyServerFactory.createHttpServer( uri, restApp ); Assert.assertTrue( httpServer.isStarted()); URI targetUri = UriBuilder.fromUri( uri ) .path( UrlConstants.APP ).path( this.app.getName()).path( "instances" ) .queryParam( "instance-path", "/tomcat-vm" ).build(); received = Utils.readUrlContent( targetUri.toString()); } finally { if( httpServer != null ) httpServer.stop(); } String expected = JSonBindingUtils.createObjectMapper().writeValueAsString( Arrays.asList( this.app.getTomcat())); Assert.assertEquals( expected, received ); }
Example #12
Source File: SchedulerWsDelegateTest.java From roboconf-platform with Apache License 2.0 | 4 votes |
@Before public void before() throws Exception { this.targetFile = this.folder.newFile(); // Create the manager this.manager = new Manager(); this.manager.setMessagingType(MessagingConstants.FACTORY_TEST); this.manager.setTargetResolver( new TestTargetResolver()); this.manager.configurationMngr().setWorkingDirectory( this.folder.newFolder()); this.manager.start(); // Create the wrapper and complete configuration this.managerWrapper = new TestManagerWrapper( this.manager ); this.managerWrapper.configureMessagingForTest(); this.manager.reconfigure(); // Disable the messages timer for predictability TestUtils.getInternalField( this.manager, "timer", Timer.class).cancel(); URI uri = UriBuilder.fromUri( REST_URI ).build(); RestApplication restApp = new RestApplication( this.manager ); this.httpServer = GrizzlyServerFactory.createHttpServer( uri, restApp ); // Load an application this.app = new TestApplication(); this.app.setDirectory( this.folder.newFolder()); this.ma = new ManagedApplication( this.app ); this.managerWrapper.addManagedApplication( this.ma ); // Create a command this.manager.commandsMngr().createOrUpdateCommand( this.app, "write 1", "Write this into " + this.targetFile.getAbsolutePath()); this.manager.commandsMngr().createOrUpdateCommand( this.app, "write 2", "Write this into " + this.targetFile.getAbsolutePath()); // Initialize the scheduler this.scheduler = new RoboconfScheduler(); this.scheduler.setManager( this.manager ); this.scheduler.start(); restApp.setScheduler( this.scheduler ); this.client = new WsClient( REST_URI ); }