public void testConfiguredHttpsProxy() throws Exception { File testRepo = createMyModuleRepository("testConfiguredHttpsProxy"); File emptyRepo = Files.createTempDirectory("vertx").toFile(); emptyRepo.deleteOnExit(); startRemoteServer(configureTls(createRemoteServer(testRepo))); Server server = new Server(8081); ServletHandler handler = new ServletHandler(); server.setHandler(handler); handler.addServletWithMapping(ProxyServlet.class, "/").setInitParameter("maxThreads", "10"); UrlCollectorFilter urlCollector = new UrlCollectorFilter(); handler.addFilterWithMapping(new FilterHolder(urlCollector), "/*", 0); server.start(); servers.add(server); System.setProperty(MavenVerticleFactory.HTTP_PROXY_SYS_PROP, "http://localhost:8081"); configureRepos(emptyRepo, "https://localhost:8443/"); URL expectedHost = new URL("http://localhost:8443/"); vertx.deployVerticle("maven:my:module:1.0::my.serviceA", new DeploymentOptions(), onSuccess(id -> { assertTrue("Was expecting " + urlCollector.requestedHosts + " to contain " + expectedHost, urlCollector.requestedHosts.contains(expectedHost)); testComplete(); })); await(); }
/** * To test that the CF client is able to go through a proxy, we point the CC client to a broken url that can only be resolved by going * through an inJVM proxy which rewrites the URI. This method starts this inJvm proxy. * * @throws Exception */ private static void startInJvmProxy() throws Exception { inJvmProxyPort = getNextAvailablePort(8080); inJvmProxyServer = new Server(new InetSocketAddress("127.0.0.1", inJvmProxyPort)); // forcing use of loopback // that will be used both for Httpclient proxy and SocketDestHelper QueuedThreadPool threadPool = new QueuedThreadPool(); threadPool.setMinThreads(1); inJvmProxyServer.setThreadPool(threadPool); HandlerCollection handlers = new HandlerCollection(); inJvmProxyServer.setHandler(handlers); ServletHandler servletHandler = new ServletHandler(); handlers.addHandler(servletHandler); nbInJvmProxyRcvReqs = new AtomicInteger(); ChainedProxyServlet chainedProxyServlet = new ChainedProxyServlet(httpProxyConfiguration, nbInJvmProxyRcvReqs); servletHandler.addServletWithMapping(new ServletHolder(chainedProxyServlet), "/*"); // Setup proxy handler to handle CONNECT methods ConnectHandler proxyHandler; proxyHandler = new ChainedProxyConnectHandler(httpProxyConfiguration, nbInJvmProxyRcvReqs); handlers.addHandler(proxyHandler); inJvmProxyServer.start(); }
/** {@inheritDoc} */ @Override public void run() { try { this.server = new Server(this.serverPort); ServletHandler servletHandler = new ServletHandler(); servletHandler.addServletWithMapping(TaskTrackerServlet.class, "/tracker"); this.server.setHandler(servletHandler); this.server.start(); this.server.join(); } catch (Exception ex) { // suppress } }
public static void main(String[] args) throws Exception { initWeixin(); Server server = new Server(8080); ServletHandler servletHandler = new ServletHandler(); server.setHandler(servletHandler); ServletHolder endpointServletHolder = new ServletHolder(new WxCpEndpointServlet(wxCpConfigStorage, wxCpService, wxCpMessageRouter)); servletHandler.addServletWithMapping(endpointServletHolder, "/*"); ServletHolder oauthServletHolder = new ServletHolder(new WxCpOAuth2Servlet(wxCpService)); servletHandler.addServletWithMapping(oauthServletHolder, "/oauth2/*"); server.start(); server.join(); }
public static void main(String[] args) throws Exception { initWeixin(); Server server = new Server(8080); ServletHandler servletHandler = new ServletHandler(); server.setHandler(servletHandler); ServletHolder endpointServletHolder = new ServletHolder( new WxMpEndpointServlet(wxMpConfigStorage, wxMpService, wxMpMessageRouter)); servletHandler.addServletWithMapping(endpointServletHolder, "/*"); ServletHolder oauthServletHolder = new ServletHolder( new WxMpOAuth2Servlet(wxMpService)); servletHandler.addServletWithMapping(oauthServletHolder, "/oauth2/*"); server.start(); server.join(); }
private HandlerList getAllServices() throws Exception{ // File server & Context Handler for root, also setting the index.html // to be the "welcome file", i.e, autolink on root addresses. ContextHandler rootContext = new ContextHandler(); rootContext.setContextPath("/*"); rootContext.setHandler(getResourceHandlers()); // Possible servlet lists, for all servlets or custom services you want to access later. // Warning, it might become a little bit nested if you add to many classes. ServletHandler questionHandler = new ServletHandler(); questionHandler.addServletWithMapping(QuestionHandler.class, "/question"); // Add the ResourceHandler to the server. HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[] { rootContext , questionHandler, }); return handlers; }
private Server createServer() { Server server = new Server(); SelectChannelConnector connector = new SelectChannelConnector(); connector.setPort(8384); server.addConnector(connector); ServletHandler handler = new ServletHandler(); Servlet servlet = new HttpServlet() { private static final long serialVersionUID = 1L; @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { String path = req.getServletPath().substring(1); try { Thread.sleep(1000); } catch (InterruptedException e) { } resp.getWriter().append(path); } }; handler.addServletWithMapping(new ServletHolder(servlet), "/"); server.setHandler(handler); return server; }
@PostConstruct private void init() { internal = new Server(); ServletHandler servletHandler = new ServletHandler(); KasijeServlet servlet = context.find(KasijeServlet.class); ServletHolder servletHolder = new ServletHolder("kasije", servlet); servletHandler.addServletWithMapping(servletHolder, "/*"); internal.setHandler(servletHandler); ConfigProvider configProv = context.find(ConfigProvider.class); ServerConfig config = configProv.getServerConfig(); if (null == config || null == config.getConnectors() || config.getConnectors().isEmpty()) { internal.addConnector(createConnector(null)); } else { for (Connector connectorConfig : config.getConnectors()) { internal.addConnector(createConnector(connectorConfig)); } } }
/** * Ctor. * @param path Server path. * @param storage Storage container. * @param port Server port */ LfsServer(final String path, final ContentManager storage, final int port) { this.server = new Server(); this.http = new ServerConnector(this.server, new HttpConnectionFactory()); this.http.setPort(port); // @checkstyle MagicNumber (1 line) this.http.setIdleTimeout(30000); this.server.addConnector(this.http); final ServletHandler handler = new ServletHandler(); this.server.setHandler(handler); handler.addServletWithMapping( new ServletHolder( new PointerServlet( storage, String.format("%s/info/lfs/storage/", path) ) ), String.format("%s/info/lfs/objects/*", path) ); handler.addServletWithMapping( new ServletHolder(new ContentServlet(storage)), String.format("%s/info/lfs/storage/*", path) ); }
/** * Inits the http server. */ private void initHttpServer() { final int httpPort = this.getServerConfig().getHttpPort(); final DialogListener dialogListener = this; Server server = new Server(httpPort); ServletHandler handler = new ServletHandler(); server.setHandler(handler); ServletHolder sh = new ServletHolder(); EmbeddedServlet embeddedServlet = new EmbeddedServlet(); embeddedServlet.setDialogListener(dialogListener); sh.setServlet(embeddedServlet); handler.addServletWithMapping(sh, "/ussdgw"); HttpServerThread httpServerThread = new HttpServerThread(); httpServerThread.setJettyServer(server); httpServerThread.start(); }
public void startServer1() throws Exception { Server server = new Server(9091); ServletHandler handler = new ServletHandler(); AwesomeService.Processor<AwesomeService.Iface> processor = new AwesomeService.Processor<>(referenceServer); ServletHolder holder = new ServletHolder(new TServlet(processor, new TJSONProtocol.Factory())); handler.addFilterWithMapping(CORSFilter.class, "/*", 0); handler.addServletWithMapping(holder, "/*"); server.setHandler(handler); server.start(); logger.info("Started JSON interface."); joinMethods.add(() -> { try { server.join(); } catch (InterruptedException ignored) { } }); }
@Before public void spawnServer() throws Exception { server = new Server(SERVER_PORT); ServletHandler handler = new ServletHandler(); mockedServer = Mockito.mock(AwesomeService.Iface.class); when(mockedServer.getData(any(Request.class))).thenReturn(new Response(Arrays.asList(new DataPoint(), new DataPoint()))); AwesomeService.Processor<AwesomeService.Iface> processor = new AwesomeService.Processor<>(mockedServer); ServletHolder holder = new ServletHolder(new TServlet(processor, new TJSONProtocol.Factory())); handler.addServletWithMapping(holder, "/*"); server.setHandler(handler); server.start(); }
public static ServletHandler createChatsServlets() { ServletHandler sh = new ServletHandler(); addServletWithMapping(sh, CreateAccount.class); addServletWithMapping(sh, PutOperator.class); addServletWithMapping(sh, RemoveOperator.class); addServletWithMapping(sh, InitUserToken.class); addServletWithMapping(sh, RemoveUserSession.class); addServletWithMapping(sh, UpdateUserSessions.class); addServletWithMapping(sh, SetAccsBlocked.class); addServletWithMapping(sh, GetUnblockedAccs.class); addServletWithMapping(sh, SetAccsPaused.class); addServletWithMapping(sh, GetPausedState.class); addServletWithMapping(sh, UpdateUserContact.class); addServletWithMapping(sh, PutAccConfig.class); return sh; }
private void setup(int port) { if (server == null) { server = new Server(port); ServletHandler servletHandler = new ServletHandler(); webSocketServlet = new WebsocketOutboundServlet(); ServletHolder holder = new ServletHolder(webSocketServlet); servletHandler.addServletWithMapping(holder, uri + URI_SUFFIX); ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setBaseResource(Resource.newClassPathResource("com/example/docroot/")); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[]{servletHandler, resourceHandler, new DefaultHandler()}); server.setHandler(handlers); try { server.start(); String url = "ws://localhost:" + port + uri; System.out.println(ImplMessages.getMessage("WS_SERVER_START_MSG", url)); // add the shutdown hook Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdown())); } catch (Exception error) { System.out.println(ImplMessages.getMessage("INIT_FAILURE", getClass().getName(), error.getMessage())); error.printStackTrace(); } } }
private void setup(int port) { if (server == null) { server = new Server(port); ServletHandler servletHandler = new ServletHandler(); webSocketServlet = new WebsocketOutboundServlet(message -> receive(message)); ServletHolder holder = new ServletHolder(webSocketServlet); servletHandler.addServletWithMapping(holder, uri + URI_SUFFIX); ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setBaseResource(Resource.newClassPathResource("com/example/docroot/")); HandlerList handlers = new HandlerList(); handlers.setHandlers(new Handler[]{servletHandler, resourceHandler, new DefaultHandler()}); server.setHandler(handlers); try { server.start(); String url = "ws://localhost:" + port + uri; System.out.println(ImplMessages.getMessage("WS_SERVER_START_MSG", url)); // add the shutdown hook Runtime.getRuntime().addShutdownHook(new Thread(() -> shutdown())); } catch (Exception error) { System.out.println(ImplMessages.getMessage("INIT_FAILURE", getClass().getName(), error.getMessage())); error.printStackTrace(); } } }
public static boolean startup(int port) { Server server = new Server(port); ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(CrocoWebDecryptor.class, "/*"); for(Connector y : server.getConnectors()) { for(ConnectionFactory x : y.getConnectionFactories()) { if(x instanceof HttpConnectionFactory) { ((HttpConnectionFactory)x).getHttpConfiguration().setSendServerVersion(false); } } } server.setHandler(handler); try { server.start(); return true; } catch (Exception e) { try { server.stop(); } catch (Exception e2) {} } return false; }
private static Server startHttp1() throws Exception { Server server = new Server(0); ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(newServletHolder(thriftServlet), TSERVLET_PATH); handler.addServletWithMapping(newServletHolder(rootServlet), "/"); handler.addFilterWithMapping(new FilterHolder(new ConnectionCloseFilter()), "/*", EnumSet.of(DispatcherType.REQUEST)); server.setHandler(handler); for (Connector c : server.getConnectors()) { for (ConnectionFactory f : c.getConnectionFactories()) { for (String p : f.getProtocols()) { if (p.startsWith("h2c")) { fail("Attempted to create a Jetty server without HTTP/2 support, but failed: " + f.getProtocols()); } } } } server.start(); return server; }
private static Server startHttp2() throws Exception { Server server = new Server(); // Common HTTP configuration. HttpConfiguration config = new HttpConfiguration(); // HTTP/1.1 support. HttpConnectionFactory http1 = new HttpConnectionFactory(config); // HTTP/2 cleartext support. HTTP2CServerConnectionFactory http2c = new HTTP2CServerConnectionFactory(config); // Add the connector. ServerConnector connector = new ServerConnector(server, http1, http2c); connector.setPort(0); server.addConnector(connector); // Add the servlet. ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(newServletHolder(thriftServlet), TSERVLET_PATH); server.setHandler(handler); // Start the server. server.start(); return server; }
public static boolean startup(int port) { Server server = new Server(port); ServletHandler handler = new ServletHandler(); handler.addServletWithMapping(Querler.class, "/*"); for(Connector y : server.getConnectors()) { for(ConnectionFactory x : y.getConnectionFactories()) { if(x instanceof HttpConnectionFactory) { ((HttpConnectionFactory)x).getHttpConfiguration().setSendServerVersion(false); } } } server.setHandler(handler); try { server.start(); return true; } catch (Exception e) { try { server.stop(); } catch (Exception e2) {} } return false; }
public static void main(String[] args) throws Exception { initWeixin(); Server server = new Server(8080); ServletHandler servletHandler = new ServletHandler(); server.setHandler(servletHandler); ServletHolder endpointServletHolder = new ServletHolder(new WxMpEndpointServlet(wxMpConfigStorage, wxMpService, wxMpMessageRouter)); servletHandler.addServletWithMapping(endpointServletHolder, "/*"); ServletHolder oauthServletHolder = new ServletHolder(new WxMpOAuth2Servlet(wxMpService)); servletHandler.addServletWithMapping(oauthServletHolder, "/oauth2/*"); server.start(); server.join(); }
@BeforeClass public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); DummyProvider patientProvider = new DummyProvider(); ServletHandler proxyHandler = new ServletHandler(); RestfulServer servlet = new RestfulServer(); ourCtx = servlet.getFhirContext(); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); ourServer.start(); ourCtx.getRestfulClientFactory().setServerValidationModeEnum(ServerValidationModeEnum.NEVER); }
@BeforeClass public static void beforeClass() throws Exception { ourCtx = new FhirContext(); ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); RestfulServer servlet = new RestfulServer(); servlet.setFhirContext(ourCtx); servlet.setBundleInclusionRule(BundleInclusionRule.BASED_ON_RESOURCE_PRESENCE); servlet.setResourceProviders(patientProvider, new DummyDiagnosticReportResourceProvider()); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); ourServer.start(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setConnectionManager(connectionManager); ourClient = builder.build(); }
@BeforeClass public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); ourServlet = new RestfulServer(); ourServlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); ourServlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(ourServlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); ourServer.start(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setConnectionManager(connectionManager); ourClient = builder.build(); FhirContext fhirContext = ourServlet.getFhirContext(); fhirContext.getResourceDefinition(ExtendedPatient.class); }
@BeforeClass public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); RestfulServer servlet = new RestfulServer(); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); ourServer.start(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setConnectionManager(connectionManager); ourClient = builder.build(); }
@BeforeClass public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); servlet = new RestfulServer(); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); ourServer.start(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setConnectionManager(connectionManager); ourClient = builder.build(); }
@BeforeClass public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); DummyPatientResourceProvider patientProvider = new DummyPatientResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); servlet = new RestfulServer(); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); ourServer.start(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setConnectionManager(connectionManager); ourClient = builder.build(); myInterceptor = new ExceptionHandlingInterceptor(); servlet.registerInterceptor(myInterceptor); }
@BeforeClass public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); ServletHandler proxyHandler = new ServletHandler(); ourRestfulServer = new RestfulServer(); ourCtx = ourRestfulServer.getFhirContext(); ourRestfulServer.setResourceProviders(new PatientProvider()); ServletHolder servletHolder = new ServletHolder(ourRestfulServer); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); ourServer.start(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setConnectionManager(connectionManager); ourClient = builder.build(); }
@Test public void testNoAnnotatedMethods() throws Exception { int port = PortUtil.findFreePort(); ourServer = new Server(port); ResourceProvider patientProvider = new ResourceProvider(); ServletHandler proxyHandler = new ServletHandler(); RestfulServer servlet = new RestfulServer(); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); try { ourServer.start(); fail(); } catch (ServletException e) { assertEquals(e.getCause().getClass(), ConfigurationException.class); } }
@Test public void testNonPublicMethod() throws Exception { int port = PortUtil.findFreePort(); ourServer = new Server(port); NonPublicMethodProvider patientProvider = new NonPublicMethodProvider(); ServletHandler proxyHandler = new ServletHandler(); RestfulServer servlet = new RestfulServer(); servlet.setResourceProviders(patientProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); try { ourServer.start(); fail(); } catch (ServletException e) { assertEquals(e.getCause().getClass(), ConfigurationException.class); } }
@BeforeClass public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); PatientProvider patientProvider = new PatientProvider(); ourReportProvider = new DiagnosticReportProvider(); ServletHandler proxyHandler = new ServletHandler(); RestfulServer servlet = new RestfulServer(); servlet.setResourceProviders(patientProvider, ourReportProvider, new DummyAdverseReactionResourceProvider(), new CustomObservationProvider()); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); ourServer.start(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setConnectionManager(connectionManager); ourClient = builder.build(); }
@BeforeClass public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); ServletHandler proxyHandler = new ServletHandler(); ourServlet = new RestfulServer(); ourServlet.setFhirContext(ourCtx); ourServlet.getFhirContext().setNarrativeGenerator(new DefaultThymeleafNarrativeGenerator()); ServletHolder servletHolder = new ServletHolder(ourServlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setConnectionManager(connectionManager); ourClient = builder.build(); }
@BeforeClass public static void beforeClass() throws Exception { ourPort = PortUtil.findFreePort(); ourServer = new Server(ourPort); ourCtx = new FhirContext(Patient.class); ourProvider = new DummyProvider(); ServletHandler proxyHandler = new ServletHandler(); RestfulServer servlet = new RestfulServer(); servlet.setPlainProviders(ourProvider); ServletHolder servletHolder = new ServletHolder(servlet); proxyHandler.addServletWithMapping(servletHolder, "/*"); ourServer.setHandler(proxyHandler); ourServer.start(); PoolingHttpClientConnectionManager connectionManager = new PoolingHttpClientConnectionManager(5000, TimeUnit.MILLISECONDS); HttpClientBuilder builder = HttpClientBuilder.create(); builder.setConnectionManager(connectionManager); ourClient = builder.build(); }