Java Code Examples for org.eclipse.jetty.servlet.ServletContextHandler#NO_SECURITY

The following examples show how to use org.eclipse.jetty.servlet.ServletContextHandler#NO_SECURITY . 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: EngineWebServer.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
public EngineWebServer(final int port)
{
    // Configure Jetty to use java.util.logging, and don't announce that it's doing that
    System.setProperty("org.eclipse.jetty.util.log.announce", "false");
    System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.JavaUtilLog");

    server = new Server(port);

    final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);

    // Our servlets
    context.addServlet(MainServlet.class, "/main/*");
    context.addServlet(DisconnectedServlet.class, "/disconnected/*");
    context.addServlet(GroupsServlet.class, "/groups/*");
    context.addServlet(GroupServlet.class, "/group/*");
    context.addServlet(ChannelServlet.class, "/channel/*");
    context.addServlet(RestartServlet.class, "/restart/*");
    context.addServlet(StopServlet.class, "/stop/*");

    // Serve static files from webroot to "/"
    context.setContextPath("/");
    context.setResourceBase(EngineWebServer.class.getResource("/webroot").toExternalForm());
    context.addServlet(DefaultServlet.class, "/");

    server.setHandler(context);
}
 
Example 2
Source File: ScanWebServer.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
public ScanWebServer(final int port)
{
    // Configure Jetty to use java.util.logging, and don't announce that it's doing that
    System.setProperty("org.eclipse.jetty.util.log.announce", "false");
    System.setProperty("org.eclipse.jetty.util.log.class", "org.eclipse.jetty.util.log.JavaUtilLog");

    server = new Server(port);

    final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);

    // Our servlets
    context.addServlet(ServerServlet.class, "/server/*");
    context.addServlet(ScansServlet.class, "/scans/*");
    context.addServlet(ScanServlet.class, "/scan/*");
    context.addServlet(SimulateServlet.class, "/simulate/*");

    // Serve static files from webroot to "/"
    context.setContextPath("/");
    context.setResourceBase(ScanServerInstance.class.getResource("/webroot").toExternalForm());
    context.addServlet(DefaultServlet.class, "/");

    server.setHandler(context);
}
 
Example 3
Source File: WebServletsDemo.java    From phoebus with Eclipse Public License 1.0 6 votes vote down vote up
public static void main(String[] args) throws Exception
{
    final Server server = new Server(8080);

    final ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);

    // Our servlets
    context.addServlet(HelloServlet.class, "/hello");
    context.addServlet(StopServlet.class, "/stop");

    // Serve static files from webroot to "/"
    context.setContextPath("/");
    context.setResourceBase(WebServletsDemo.class.getResource("/webroot").toExternalForm());
    context.addServlet(DefaultServlet.class, "/");

    server.setHandler(context);

    server.start();
    System.out.println("Running web server, check http://localhost:8080, http://localhost:8080/hello");
    do
        System.out.println("Main thread could do other things while web server is running...");
    while (! done.await(5, TimeUnit.SECONDS));
    server.stop();
    server.join();
    System.out.println("Done.");
}
 
Example 4
Source File: HelloWebServerServlet.java    From FrameworkBenchmarks with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
public static void main(String[] args) throws Exception
{
    Server server = new Server(8080);
    ServerConnector connector = server.getBean(ServerConnector.class);
    HttpConfiguration config = connector.getBean(HttpConnectionFactory.class).getHttpConfiguration();
    config.setSendDateHeader(true);
    config.setSendServerVersion(true);

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY|ServletContextHandler.NO_SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);

    context.addServlet(org.eclipse.jetty.servlet.DefaultServlet.class,"/");
    context.addServlet(JsonServlet.class,"/json");
    context.addServlet(PlaintextServlet.class,"/plaintext");

    server.start();
    server.join();
}
 
Example 5
Source File: JaxWsClientToSpringWsServerIT.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Before
public void before() throws Exception {
	// Start jetty to provide spring webservice
	server = new Server(new InetSocketAddress("127.0.0.1", 0));
	ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
	contextHandler.setContextPath("/");
	final MessageDispatcherServlet messageDispatcherServlet = new MessageDispatcherServlet();
	messageDispatcherServlet.setContextConfigLocation("classpath:springWsServer.xml");
	messageDispatcherServlet.setTransformWsdlLocations(true);
	contextHandler.addServlet(new ServletHolder(messageDispatcherServlet), "/*");
	server.setHandler(contextHandler);
	server.start();
	final String serverUrl = "http://" + server.getConnectors()[0].getName() + "/springws/TestserviceEndpoint";

	// Init jaxws client with TraceeClientHandler
	final JaxwsTestserviceEndpointService endpointService = new JaxwsTestserviceEndpointService();
	endpointService.setHandlerResolver(new TraceeClientHandlerResolver());
	testservice = endpointService.getCurrentTraceeContextPort();
	((BindingProvider) testservice).getRequestContext().put(BindingProvider.ENDPOINT_ADDRESS_PROPERTY, serverUrl);
}
 
Example 6
Source File: WebIntegrationIT.java    From tracee with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@Before
public void startJetty() throws Exception {
	Tracee.getBackend().clear();

	server = new Server(new InetSocketAddress("127.0.0.1", 0));
	ServletContextHandler context = new ServletContextHandler(null, "/", ServletContextHandler.NO_SECURITY);
	final DispatcherServlet dispatcherServlet = new DispatcherServlet();
	dispatcherServlet.setContextClass(AnnotationConfigWebApplicationContext.class);
	dispatcherServlet.setContextInitializerClasses(TraceeInterceptorSpringApplicationInitializer.class.getCanonicalName());
	dispatcherServlet.setContextConfigLocation(TraceeInterceptorSpringConfig.class.getName());
	context.addServlet(new ServletHolder(dispatcherServlet), "/");
	server.setHandler(context);
	server.start();
	ENDPOINT_URL = "http://" + server.getConnectors()[0].getName() + "/";

}
 
Example 7
Source File: HttpTransportConfiguration.java    From chassis with Apache License 2.0 5 votes vote down vote up
@Bean
public ServletContextHandler servletContextHandler(){
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
    context.setErrorHandler(null);
    context.setWelcomeFiles(new String[] { "/" });

    return context;
}
 
Example 8
Source File: ChassisEurekaTestConfiguration.java    From chassis with Apache License 2.0 5 votes vote down vote up
@Order(0)
@Bean(initMethod="start", destroyMethod="stop")
public Server httpServer(
        @Value("${http.hostname}") String hostname,
        @Value("${http.port}") int port,
        ConfigurableWebApplicationContext webApplicationContext) {

    // set up servlets
    ServletHandler servlets = new ServletHandler();
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
    context.setErrorHandler(null);
    context.setWelcomeFiles(new String[] { "/" });

    // set up spring with the servlet context
    setServletContext(context.getServletContext());

    // configure the spring mvc dispatcher
    DispatcherServlet dispatcher = new DispatcherServlet(webApplicationContext);

    // map application servlets
    context.addServlet(new ServletHolder(dispatcher), "/");

    servlets.setHandler(context);

    // create the server
    InetSocketAddress address = StringUtils.isBlank(hostname) ? new InetSocketAddress(port) : new InetSocketAddress(hostname, port);
    Server server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setHost(address.getHostName());
    connector.setPort(address.getPort());
    server.setConnectors(new Connector[]{ connector });
    server.setHandler(servlets);

    return server;
}
 
Example 9
Source File: TestSpringWebApp.java    From chassis with Apache License 2.0 5 votes vote down vote up
@Bean(initMethod = "start", destroyMethod = "stop", name = "httpServer")
@Order(0)
public Server httpServer(ConfigurableWebApplicationContext webApplicationContext) {

    // set up servlets
    ServletHandler servlets = new ServletHandler();
    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SECURITY);
    context.setErrorHandler(null);
    context.setWelcomeFiles(new String[]{"/"});

    // set up spring with the servlet context
    setServletContext(context.getServletContext());

    // configure the spring mvc dispatcher
    DispatcherServlet dispatcher = new DispatcherServlet(webApplicationContext);

    // map application servlets
    context.addServlet(new ServletHolder(dispatcher), "/");

    servlets.setHandler(context);

    // create the server
    InetSocketAddress address = new InetSocketAddress(SocketUtils.findAvailableTcpPort());

    Server server = new Server();
    ServerConnector connector = new ServerConnector(server);
    connector.setHost(address.getHostName());
    connector.setPort(address.getPort());
    server.setConnectors(new Connector[]{connector});
    server.setHandler(servlets);
    server.setStopAtShutdown(true);

    return server;
}
 
Example 10
Source File: JettyHttpServer.java    From vespa with Apache License 2.0 4 votes vote down vote up
private ServletContextHandler createServletContextHandler() {
    ServletContextHandler servletContextHandler = new ServletContextHandler(ServletContextHandler.NO_SECURITY | ServletContextHandler.NO_SESSIONS);
    servletContextHandler.setContextPath("/");
    servletContextHandler.setDisplayName(getDisplayName(listenedPorts));
    return servletContextHandler;
}
 
Example 11
Source File: AdminTransportConfiguration.java    From chassis with Apache License 2.0 4 votes vote down vote up
@Bean(initMethod="start", destroyMethod="stop")
@Order(0)
public Server adminServer(
           @Value("${admin.hostname}") String hostname,
           @Value("${admin.port}") int port) {

       // set up servlets
       ServletContextHandler context = new ServletContextHandler(ServletContextHandler.NO_SESSIONS | ServletContextHandler.NO_SECURITY);
	context.setErrorHandler(null);
	context.setWelcomeFiles(new String[] { "/" });
	
	// enable gzip
	context.addFilter(GzipFilter.class, "/*", null);
	
	// add common admin servlets
	context.addServlet(new ServletHolder(new HealthServlet(healthCheckRegistry)), "/healthcheck");
	context.addServlet(new ServletHolder(new ClasspathResourceServlet("com/kixeye/chassis/transport/admin", "/admin/", "index.html")), "/admin/*");
	context.addServlet(new ServletHolder(new PropertiesServlet()), "/admin/properties");
	context.addServlet(new ServletHolder(new ClasspathDumpServlet()), "/admin/classpath");

       // add websocket servlets if WebSockets have been initialized
       if (mappingRegistry != null && messageRegistry != null) {
           context.addServlet(new ServletHolder(new ProtobufMessagesDocumentationServlet(appName, mappingRegistry, messageRegistry)), "/schema/messages/protobuf");
           context.addServlet(new ServletHolder(new ProtobufEnvelopeDocumentationServlet()), "/schema/envelope/protobuf");
       }
	
       // add metric servlets if Metric has been initialized
       if (metricRegistry != null && healthCheckRegistry != null) {
           context.getServletContext().setAttribute(MetricsServlet.METRICS_REGISTRY, metricRegistry);
           context.getServletContext().setAttribute(HealthCheckServlet.HEALTH_CHECK_REGISTRY, healthCheckRegistry);
           
           ServletHolder holder = new ServletHolder(new AdminServlet());
           holder.setInitParameter("service-name", System.getProperty("app.name"));
           context.addServlet(holder, "/metrics/*");
       }

       // create the server
   	InetSocketAddress address = StringUtils.isBlank(hostname) ? new InetSocketAddress(port) : new InetSocketAddress(hostname, port);
   	
   	Server server = new Server();

   	JettyConnectorRegistry.registerHttpConnector(server, address);
       server.setHandler(context);
   
	return server;
}