本文整理汇总了Java中com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory类的典型用法代码示例。如果您正苦于以下问题:Java GrizzlyServerFactory类的具体用法?Java GrizzlyServerFactory怎么用?Java GrizzlyServerFactory使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
GrizzlyServerFactory类属于com.sun.jersey.api.container.grizzly2包,在下文中一共展示了GrizzlyServerFactory类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: WebServer
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
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);
}
示例2: startServer
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
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);
}
}
示例3: before
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
@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 );
}
示例4: before
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
@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 );
}
示例5: testJsonSerialization_application
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
@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 );
}
示例6: start
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
public static void start() {
WebappContext webappContext = new WebappContext("TestContext");
ServletRegistration registration = webappContext.addServlet("ServletContainer", ServletContainer.class);
registration.setInitParameter(PackagesResourceConfig.PROPERTY_PACKAGES, "org.moskito.central.connectors.rest;org.codehaus.jackson.jaxrs");
registration.addMapping("/*");
SSLContextConfigurator sslConfigurator = new SSLContextConfigurator();
sslConfigurator.setKeyStoreFile("./target/test-classes/central_server_keystore.jks");
sslConfigurator.setKeyStorePass("moskito");
SSLContext sslContext = sslConfigurator.createSSLContext();
try {
server = GrizzlyServerFactory.createHttpServer(
getBaseURI(),
null,
true,
new SSLEngineConfigurator(sslContext).setClientMode(false).setNeedClientAuth(false)
);
webappContext.deploy(server);
server.start();
} catch (Exception e) {
System.out.println("Error while starting the test server: " + e);
}
}
示例7: createServer
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
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));
}
示例8: getServer
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
private static HttpServer getServer() throws IllegalArgumentException,
NullPointerException, IOException {
ResourceConfig rc = new PackagesResourceConfig(
"fi.uef.envi.emrooz.rest");
HttpServer server = GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
return server;
}
示例9: startServer
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
protected static HttpServer startServer() throws IOException {
System.out.println("Starting grizzly...");
final ResourceConfig rc = new PackagesResourceConfig("io.vertigo.dynamo.plugins.work.rest.master");
rc.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_REQUEST_FILTERS, com.sun.jersey.api.container.filter.GZIPContentEncodingFilter.class.getName());
rc.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, com.sun.jersey.api.container.filter.GZIPContentEncodingFilter.class.getName());
return GrizzlyServerFactory.createHttpServer(BASE_URI, rc);
}
示例10: startServer
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
protected static HttpServer startServer(int port) throws IOException {
System.out.println("Starting grizzly...");
ResourceConfig rc = new PackagesResourceConfig("org/dbpedia/mappings/missingbot/rest/resources");
rc.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, CorsResponseFilter.class.getName());
rc.getProperties().put(ResourceConfig.PROPERTY_CONTAINER_RESPONSE_FILTERS, CharsetResponseFilter.class.getName());
URI baseUri = getBaseURI(port);
return GrizzlyServerFactory.createHttpServer(baseUri, rc);
}
示例11: before
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
@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 );
}
示例12: before
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
@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 );
}
示例13: before
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
@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 );
}
示例14: testJsonSerialization_instance
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
@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 );
}
示例15: startServer
import com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory; //导入依赖的package包/类
@Before
public void startServer() throws IOException {
System.out.println( "Starting grizzly..." );
Injector injector = Guice.createInjector( new ServletModule() {
@Override
protected void configureServlets() {
final ResponsesProvider mockResponses = mock( ResponsesProvider.class );
when( mockResponses.responseFor( MediaType.APPLICATION_XML_TYPE, small(), "0" ) )
.thenReturn( "Small Xml response" );
when( mockResponses.responseFor( MediaType.APPLICATION_XML_TYPE, large(), "0" ) )
.thenReturn( "Large Xml response" );
when( mockResponses.responseFor( MediaType.APPLICATION_JSON_TYPE, small(), "0" ) )
.thenReturn( "Small Json response" );
when( mockResponses.responseFor( MediaType.APPLICATION_JSON_TYPE, small(), Integer.toString( delay ) ) )
.thenReturn( "Small Json response" );
when( mockResponses.responseFor( MediaType.APPLICATION_JSON_TYPE, large(), "0" ) )
.thenReturn( "Large Json response" );
bind( ResponsesProvider.class ).toInstance( mockResponses );
}
} );
ResourceConfig rc = new PackagesResourceConfig( PredictableResponseService.class.getPackage().getName() );
IoCComponentProviderFactory ioc = new GuiceComponentProviderFactory( rc, injector );
server = GrizzlyServerFactory.createHttpServer( BASE_URI + "loadtest/", rc, ioc );
System.out.println( String.format( "Jersey app started with WADL available at "
+ "%sloadtest/application.wadl\nTry out %s{app_name}\nHit enter to stop it...",
BASE_URI, BASE_URI ) );
}