private int externalPort(ServerData next) { String ep = props.getProperty("external.port." + next.getModule().getContext()); if (ep == null) { return next.getPort(); } try { return Integer.valueOf(ep); } catch (NumberFormatException e) { return next.getPort(); } } }
@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); } }
public List<Thread> run() { register.ifPresent( reg -> reg.register( apps.stream().map(app -> app.getServerData()) .collect(Collectors.toList()) .toArray(new ServerData[0]))); Map<ServerApplication,CompletableFuture> mapFutures = new HashMap<>(); apps.stream().forEach(app -> mapFutures.put(app,new CompletableFuture())); List<Thread> threads = apps.stream().map(app -> start(app, app.getServerData().getModule(),mapFutures.get(app))).collect(Collectors.toList()); mapFutures.values().forEach(future -> get(future)); logger.info("Started {} Rest applications ", apps.size()); return threads; }
private void addAccessLog(HttpServer httpServer) { try { String accessLogLocation = serverData.getRootContext().getBean(AccessLogLocationBean.class).getAccessLogLocation(); accessLogLocation = accessLogLocation + "/" + replaceSlash(serverData.getModule().getContext()) + "-access.log"; final AccessLogBuilder builder = new AccessLogBuilder(accessLogLocation); builder.rotatedDaily(); builder.rotationPattern("yyyy-MM-dd"); builder.instrument(httpServer.getServerConfiguration()); } catch (Exception e) { logger.error(InternalErrorCode.SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG.toString() + ": " + e.getMessage()); if (e.getCause() != null) logger.error("CAUSED BY: " + InternalErrorCode.SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG.toString() + ": " + e.getCause().getMessage()); } }
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(); } }
+ serverData.getModule() .getContext(), config.getServlet()); Map<String, String> initParams = config.getInitParams(); servletRegistration.setInitParameter("javax.ws.rs.Application", serverData.getModule() .getJaxWsRsApplication()); servletRegistration.setInitParameter(config.getProvidersName(), serverData.getModule() .getProviders()); servletRegistration.setInitParameter("context", serverData.getModule() .getContext()); servletRegistration.setLoadOnStartup(1);
@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 int externalPort(ServerData next) { String ep = props.getProperty("external.port." + next.getModule().getContext()); if (ep == null) { return next.getPort(); } try { return Integer.valueOf(ep); } catch (NumberFormatException e) { return next.getPort(); } } }
@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); } }
public List<Thread> run() { register.ifPresent( reg -> reg.register( apps.stream().map(app -> app.getServerData()) .collect(Collectors.toList()) .toArray(new ServerData[0]))); Map<ServerApplication,CompletableFuture> mapFutures = new HashMap<>(); apps.stream().forEach(app -> mapFutures.put(app,new CompletableFuture())); List<Thread> threads = apps.stream().map(app -> start(app, app.getServerData().getModule(),mapFutures.get(app))).collect(Collectors.toList()); mapFutures.values().forEach(future -> get(future)); logger.info("Started {} Rest applications ", apps.size()); return threads; }
private void addAccessLog(HttpServer httpServer) { try { String accessLogLocation = serverData.getRootContext().getBean(AccessLogLocationBean.class).getAccessLogLocation(); accessLogLocation = accessLogLocation + "/" + replaceSlash(serverData.getModule().getContext()) + "-access.log"; final AccessLogBuilder builder = new AccessLogBuilder(accessLogLocation); builder.rotatedDaily(); builder.rotationPattern("yyyy-MM-dd"); builder.instrument(httpServer.getServerConfiguration()); } catch (Exception e) { logger.error(InternalErrorCode.SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG.toString() + ": " + e.getMessage()); if (e.getCause() != null) logger.error("CAUSED BY: " + InternalErrorCode.SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG.toString() + ": " + e.getCause().getMessage()); } }
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(); } }
private void addAccessLog(Tomcat httpServer, StandardContext context) { try { String accessLogLocation = serverData.getRootContext().getBean(AccessLogLocationBean.class).getAccessLogLocation(); accessLogLocation = accessLogLocation + "/" + replaceSlash(serverData.getModule().getContext()) + "-access.log"; AccessLogValve accessLogValve = new AccessLogValve(); accessLogValve.setDirectory(accessLogLocation); accessLogValve.setPattern(Constants.AccessLog.COMMON_ALIAS); accessLogValve.setSuffix(".log"); accessLogValve.setRotatable(true); context.getPipeline().addValve(accessLogValve); } catch (Exception e) { logger.error(InternalErrorCode.SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG.toString() + ": " + e.getMessage()); if (e.getCause() != null) logger.error("CAUSED BY: " + InternalErrorCode.SERVER_STARTUP_FAILED_TO_CREATE_ACCESS_LOG.toString() + ": " + e.getCause().getMessage()); } }
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); }
+ serverData.getModule() .getContext(), config.getServlet()); Map<String, String> initParams = config.getInitParams(); servletRegistration.setInitParameter("javax.ws.rs.Application", serverData.getModule() .getJaxWsRsApplication()); servletRegistration.setInitParameter(config.getProvidersName(), serverData.getModule() .getProviders()); servletRegistration.setInitParameter("context", serverData.getModule() .getContext()); servletRegistration.setLoadOnStartup(1);
@Override public void onStartup(Set<Class<?>> classes, ServletContext webappContext) throws ServletException { try { ServerThreadLocalVariables.getContext().set(serverData.getModule().getContext()); jaxRsConfigurer.addServlet(this.serverData,webappContext); new ServletConfigurer(serverData, servletData).addServlets(webappContext); new FilterConfigurer(serverData, this.filterData).addFilters(webappContext); new ServletContextListenerConfigurer(serverData, servletContextListenerData, servletRequestListenerData).addListeners(webappContext); } catch (Exception ex) { } }
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); }