当前位置: 首页>>代码示例>>Java>>正文


Java GrizzlyServerFactory类代码示例

本文整理汇总了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);
}
 
开发者ID:uber,项目名称:AthenaX,代码行数:25,代码来源:WebServer.java

示例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);
    }
}
 
开发者ID:johnlcox,项目名称:dagger-servlet,代码行数:24,代码来源:GrizzlyTestServer.java

示例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 );
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:23,代码来源:ManagementWsDelegateTest.java

示例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 );
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:23,代码来源:AuthenticationWsDelegateTest.java

示例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 );
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:27,代码来源:ServletRegistrationComponentTest.java

示例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);
    }
}
 
开发者ID:anotheria,项目名称:moskito-central,代码行数:26,代码来源:RESTConnectorHttpsTest.java

示例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));
}
 
开发者ID:draptik,项目名称:angulardemorestful,代码行数:25,代码来源:ServerProvider.java

示例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;
}
 
开发者ID:markusstocker,项目名称:emrooz,代码行数:10,代码来源:EmroozServer.java

示例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);
}
 
开发者ID:KleeGroup,项目名称:vertigo-labs,代码行数:8,代码来源:ConverterManagerDistributedTest.java

示例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);
}
 
开发者ID:dbpedia,项目名称:MissingBot,代码行数:11,代码来源:Main.java

示例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 );
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:36,代码来源:ApplicationWsDelegateTest.java

示例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 );
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:32,代码来源:TargetWsDelegateTest.java

示例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 );
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:29,代码来源:DebugWsDelegateTest.java

示例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 );
}
 
开发者ID:roboconf,项目名称:roboconf-platform,代码行数:30,代码来源:ServletRegistrationComponentTest.java

示例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 ) );
}
 
开发者ID:SmartBear,项目名称:load-test-target,代码行数:32,代码来源:PredictableResponseServiceTest.java


注:本文中的com.sun.jersey.api.container.grizzly2.GrizzlyServerFactory类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。