private void addSSL(HttpServer httpServer) { try { SSLProperties sslProperties = serverData.getRootContext().getBean(SSLProperties.class); if (sslProperties != null) { httpServer.addListener(this.createSSLListener(serverData.getPort(), sslProperties)); } }catch(BeanNotOfRequiredTypeException e){ } }
@Override public void register(ServerData[] data) { try { final String hostname = Optional.ofNullable(customHostname) .orElse(InetAddress.getLocalHost() .getHostName()); application = new Application( Stream.of(data) .map(next -> new RegisterEntry( next.getPort(), hostname, next.getModule().getContext(), next.getModule().getContext(), null, targetEndpoint, externalPort(next))) .collect(Collectors.toList())); logger.info("Registered application {} ", application); } catch (UnknownHostException e) { throw ExceptionSoftener.throwSoftenedException(e); } }
private void startServer(WebappContext webappContext, HttpServer httpServer, CompletableFuture start, CompletableFuture end) { webappContext.deploy(httpServer); try { logger.info("Starting application {} on port {}", serverData.getModule().getContext(), serverData.getPort()); logger.info("Browse to http://localhost:{}/{}/application.wadl", serverData.getPort(), serverData.getModule().getContext()); logger.info("Configured resource classes :-"); serverData.extractResources() .forEach(t -> logger.info(t._1() + " : " + "http://localhost:" + serverData.getPort() + "/" + serverData.getModule().getContext() + t._2())); ; httpServer.start(); start.complete(true); end.get(); } catch (IOException e) { throw ExceptionSoftener.throwSoftenedException(e); } catch (ExecutionException e) { throw ExceptionSoftener.throwSoftenedException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw ExceptionSoftener.throwSoftenedException(e); } finally { httpServer.stop(); } }
@Test public void testGetters() { assertThat(serverData.getBaseUrlPattern(), is("url")); assertThat(serverData.getResources().size(), is(1)); assertThat(serverData.getRootContext(), is(rootContext)); assertThat(serverData.getModule().getContext(), is("context")); assertThat(serverData.getPort(), is(8080)); }
public void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) { WebappContext webappContext = new WebappContext("WebappContext", ""); new ServletContextListenerConfigurer(serverData, servletContextListenerData, servletRequestListenerData); jaxRsConfigurer.addServlet(this.serverData,webappContext); new ServletConfigurer(serverData, servletData).addServlets(webappContext); new FilterConfigurer(serverData, this.filterData).addFilters(webappContext); addListeners(webappContext); HttpServer httpServer = HttpServer.createSimpleServer(null, "0.0.0.0", serverData.getPort()); serverData.getModule().getServerConfigManager().accept(new WebServerProvider(httpServer)); addAccessLog(httpServer); addSSL(httpServer); startServer(webappContext, httpServer, start, end); }
private void addSSL(HttpServer httpServer) { try { SSLProperties sslProperties = serverData.getRootContext().getBean(SSLProperties.class); if (sslProperties != null) { httpServer.addListener(this.createSSLListener(serverData.getPort(), sslProperties)); } }catch(BeanNotOfRequiredTypeException e){ } }
@Override public void register(ServerData[] data) { try { final String hostname = Optional.ofNullable(customHostname) .orElse(InetAddress.getLocalHost() .getHostName()); application = new Application( Stream.of(data) .map(next -> new RegisterEntry( next.getPort(), hostname, next.getModule().getContext(), next.getModule().getContext(), null, targetEndpoint, externalPort(next))) .collect(Collectors.toList())); logger.info("Registered application {} ", application); } catch (UnknownHostException e) { throw ExceptionSoftener.throwSoftenedException(e); } }
private void startServer(WebappContext webappContext, HttpServer httpServer, CompletableFuture start, CompletableFuture end) { webappContext.deploy(httpServer); try { logger.info("Starting application {} on port {}", serverData.getModule().getContext(), serverData.getPort()); logger.info("Browse to http://localhost:{}/{}/application.wadl", serverData.getPort(), serverData.getModule().getContext()); logger.info("Configured resource classes :-"); serverData.extractResources() .forEach(t -> logger.info(t._1() + " : " + "http://localhost:" + serverData.getPort() + "/" + serverData.getModule().getContext() + t._2())); ; httpServer.start(); start.complete(true); end.get(); } catch (IOException e) { throw ExceptionSoftener.throwSoftenedException(e); } catch (ExecutionException e) { throw ExceptionSoftener.throwSoftenedException(e); } catch (InterruptedException e) { Thread.currentThread().interrupt(); throw ExceptionSoftener.throwSoftenedException(e); } finally { httpServer.stop(); } }
public void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) { Tomcat tomcat = new Tomcat(); tomcat.setPort(serverData.getPort()); tomcat.getHost().setAutoDeploy(false); tomcat.getEngine().setBackgroundProcessorDelay(-1); File docBase = new File("."); StandardContext context =(StandardContext)tomcat.addContext("", docBase.getAbsolutePath()); context.addServletContainerInitializer(new TomcatListener(jaxRsConfigurer, serverData, filterData, servletData, servletContextListenerData, servletRequestListenerData), new HashSet<>()); addAccessLog(tomcat,context); serverData.getModule().getServerConfigManager().accept(new WebServerProvider(tomcat)); addSSL(tomcat.getConnector()); startServer(tomcat, start, end); }
public void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) { WebappContext webappContext = new WebappContext("WebappContext", ""); new ServletContextListenerConfigurer(serverData, servletContextListenerData, servletRequestListenerData); jaxRsConfigurer.addServlet(this.serverData,webappContext); new ServletConfigurer(serverData, servletData).addServlets(webappContext); new FilterConfigurer(serverData, this.filterData).addFilters(webappContext); addListeners(webappContext); HttpServer httpServer = HttpServer.createSimpleServer(null, "0.0.0.0", serverData.getPort()); serverData.getModule().getServerConfigManager().accept(new WebServerProvider(httpServer)); addAccessLog(httpServer); addSSL(httpServer); startServer(webappContext, httpServer, start, end); }