Java Code Examples for javax.servlet.ServletRegistration#setInitParameter()

The following examples show how to use javax.servlet.ServletRegistration#setInitParameter() . 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: WebMvcUtils.java    From spring-webmvc-support with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Append initialized parameter for {@link ApplicationContextInitializer Context Initializer Class} into {@link
 * FrameworkServlet}
 *
 * @param servletContext          {@link ServletContext}
 * @param contextInitializerClass the class of {@link ApplicationContextInitializer}
 * @see FrameworkServlet#applyInitializers(ConfigurableApplicationContext)
 */
public static void appendFrameworkServletContextInitializerClassInitParameter(
        ServletContext servletContext,
        Class<? extends ApplicationContextInitializer> contextInitializerClass) {

    Collection<? extends ServletRegistration> servletRegistrations =
            WebUtils.findServletRegistrations(servletContext, FrameworkServlet.class).values();

    for (ServletRegistration servletRegistration : servletRegistrations) {
        String contextInitializerClassName = servletRegistration.getInitParameter(CONTEXT_INITIALIZER_CLASSES_PARAM);
        String newContextInitializerClassName = appendInitParameter(contextInitializerClassName, contextInitializerClass.getName());
        servletRegistration.setInitParameter(CONTEXT_INITIALIZER_CLASSES_PARAM, newContextInitializerClassName);
    }

}
 
Example 2
Source File: RpcServerManager.java    From nuls-v2 with MIT License 5 votes vote down vote up
public void startServer(String ip, int port) {
    URI serverURI = UriBuilder.fromUri("http://" + ip).port(port).build();
    // Create test web application context.
    WebappContext webappContext = new WebappContext("NULS-V2-SDK-PROVIDER-SERVER", "/");

    ServletRegistration servletRegistration = webappContext.addServlet("jersey-servlet", ServletContainer.class);
    servletRegistration.setInitParameter("javax.ws.rs.Application", "io.nuls.provider.api.config.NulsResourceConfig");
    servletRegistration.addMapping("/*");

    httpServer = new HttpServer();
    NetworkListener listener = new NetworkListener("grizzly2", ip, port);
    TCPNIOTransport transport = listener.getTransport();
    ThreadPoolConfig workerPool = ThreadPoolConfig.defaultConfig()
            .setCorePoolSize(4)
            .setMaxPoolSize(4)
            .setQueueLimit(1000)
            .setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d").build());
    transport.configureBlocking(false);
    transport.setSelectorRunnersCount(2);
    transport.setWorkerThreadPoolConfig(workerPool);
    transport.setIOStrategy(WorkerThreadIOStrategy.getInstance());
    transport.setTcpNoDelay(true);
    listener.setSecure(false);
    httpServer.addListener(listener);

    ServerConfiguration config = httpServer.getServerConfiguration();
    config.setDefaultQueryEncoding(Charsets.UTF8_CHARSET);

    webappContext.deploy(httpServer);

    try {
        ClassLoader loader = this.getClass().getClassLoader();
        httpServer.start();
        Log.info("http restFul server is started!url is " + serverURI.toString());
    } catch (IOException e) {
        Log.error(e);
        httpServer.shutdownNow();
    }
}
 
Example 3
Source File: ServletRegistrationTest.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test getInitParameter method.
 */
@Test
public void testGetInitParameter() {
    webApp.addServlet("servlet", TestServlet.class);
    ServletRegistration registration = webApp.getServletRegistration("servlet");
    registration.setInitParameter("name", "value");
    assertEquals(registration.getInitParameter("name"), "value");
}
 
Example 4
Source File: ServletRegistrationTest.java    From piranha with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Test setInitParameters method.
 */
@Test
public void testSetInitParameters() {
    webApp.addServlet("servlet", TestServlet.class);
    ServletRegistration registration = webApp.getServletRegistration("servlet");
    registration.setInitParameter("name", "value");
    assertTrue(registration.setInitParameters(new HashMap<>()).isEmpty());
}
 
Example 5
Source File: RpcServerManager.java    From nuls-v2 with MIT License 4 votes vote down vote up
public void startServer(String ip, int port) {
    URI serverURI = UriBuilder.fromUri("http://" + ip).port(port).build();
    // Create test web application context.
    WebappContext webappContext = new WebappContext("NULS-RPC-SERVER", "/api");

    ServletRegistration servletRegistration = webappContext.addServlet("jersey-servlet", ServletContainer.class);
    servletRegistration.setInitParameter("javax.ws.rs.Application", "io.nuls.test.controller.NulsResourceConfig");
    servletRegistration.addMapping("/api/*");

    httpServer = new HttpServer();
    NetworkListener listener = new NetworkListener("grizzly2", ip, port);
    TCPNIOTransport transport = listener.getTransport();
    ThreadPoolConfig workerPool = ThreadPoolConfig.defaultConfig()
            .setCorePoolSize(4)
            .setMaxPoolSize(4)
            .setQueueLimit(1000)
            .setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d").build());
    transport.configureBlocking(false);
    transport.setSelectorRunnersCount(2);
    transport.setWorkerThreadPoolConfig(workerPool);
    transport.setIOStrategy(WorkerThreadIOStrategy.getInstance());
    transport.setTcpNoDelay(true);
    listener.setSecure(false);
    httpServer.addListener(listener);

    ServerConfiguration config = httpServer.getServerConfiguration();
    config.setDefaultQueryEncoding(Charsets.UTF8_CHARSET);

    webappContext.deploy(httpServer);

    try {
        ClassLoader loader = this.getClass().getClassLoader();

        addSwagerUi(loader);
        addClientUi(loader);

        httpServer.start();
        log.info("http restFul server is started!url is " + serverURI.toString());
    } catch (IOException e) {
        log.error("",e);
        httpServer.shutdownNow();
    }
}
 
Example 6
Source File: RpcServerManager.java    From nuls with MIT License 4 votes vote down vote up
public void startServer(String ip, int port) {
    URI serverURI = UriBuilder.fromUri("http://" + ip).port(port).build();
    // Create test web application context.
    WebappContext webappContext = new WebappContext("NULS-RPC-SERVER", "/api");

    ServletRegistration servletRegistration = webappContext.addServlet("jersey-servlet", ServletContainer.class);
    servletRegistration.setInitParameter("javax.ws.rs.Application", "io.nuls.client.rpc.config.NulsResourceConfig");
    servletRegistration.addMapping("/api/*");

    httpServer = new HttpServer();
    NetworkListener listener = new NetworkListener("grizzly2", ip, port);
    TCPNIOTransport transport = listener.getTransport();
    ThreadPoolConfig workerPool = ThreadPoolConfig.defaultConfig()
            .setCorePoolSize(4)
            .setMaxPoolSize(4)
            .setQueueLimit(1000)
            .setThreadFactory((new ThreadFactoryBuilder()).setNameFormat("grizzly-http-server-%d").build());
    transport.configureBlocking(false);
    transport.setSelectorRunnersCount(2);
    transport.setWorkerThreadPoolConfig(workerPool);
    transport.setIOStrategy(WorkerThreadIOStrategy.getInstance());
    transport.setTcpNoDelay(true);
    listener.setSecure(false);
    httpServer.addListener(listener);

    ServerConfiguration config = httpServer.getServerConfiguration();
    config.setDefaultQueryEncoding(Charsets.UTF8_CHARSET);

    webappContext.deploy(httpServer);

    try {
        ClassLoader loader = this.getClass().getClassLoader();

        addSwagerUi(loader);
        addClientUi(loader);

        httpServer.start();
        Log.info("http restFul server is started!url is " + serverURI.toString());
    } catch (IOException e) {
        Log.error(e);
        httpServer.shutdownNow();
    }
}