@Test public void testRegister() { ServerData data1 = new ServerData(8080, new ArrayList<>(), null, "url", () -> ""); ServerData data2 = new ServerData(8080, new ArrayList<>(), null, "url", () -> ""); ServerData data3 = new ServerData(8080, new ArrayList<>(), null, "url", () -> ""); List<ServerData> datas = Arrays.asList(data1, data2, data3); applicationRegister = new ApplicationRegisterImpl(); ServerData[] dataArray = new ServerData[datas.size()]; applicationRegister.register(datas.toArray(dataArray)); applicationRegister.getApplication().forEach(it -> count++); assertThat(count, is(3)); } }
@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)); }
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){ } }
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(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 addAutoDiscoveredServlets(ServletContext webappContext) { serverData .getRootContext() .getBeansOfType(ServletConfiguration.class) .values() .forEach(servlet -> handleServlet(servlet,webappContext)); }
+ 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); servletRegistration.addMapping(serverData.getBaseUrlPattern());
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; }
@Test public void testExtractNull(){ serverData = new ServerData(8080, Arrays.asList((Object)null), rootContext, "url", ()->"context"); serverData.extractResources(); }
@Test public void testExtractResourceClassName(){ assertThat(serverData.extractResources().toList().get(0)._1(),is(ServletStatusResource.class.getName())); } @Test
public ReactiveSeq<Tuple2<String,String>> extractResources() { return resources.stream().peek(resource -> logMissingPath(resource)) .filter(resource-> resource.getClass().getAnnotation(Path.class)!=null) .map(resource -> Tuple.tuple(resource.getClass().getName(), resource.getClass().getAnnotation(Path.class).value())); }
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 addAutoDiscoveredFilters(ServletContext webappContext) { serverData .getRootContext() .getBeansOfType(FilterConfiguration.class) .values() .stream() .filter(f->f.getMapping()!=null) .filter(f->f.getMapping().length>0) .peek(this::logFilter) .forEach(config->handleFilter(config,webappContext)); }
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){ } }
+ 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); servletRegistration.addMapping(serverData.getBaseUrlPattern());
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; }
@Test public void testExtractResourcePath(){ assertThat(serverData.extractResources().toList().get(0)._2(),is("/servlet")); }
public ReactiveSeq<Tuple2<String,String>> extractResources() { return resources.stream().peek(resource -> logMissingPath(resource)) .filter(resource-> resource.getClass().getAnnotation(Path.class)!=null) .map(resource -> Tuple.tuple(resource.getClass().getName(), resource.getClass().getAnnotation(Path.class).value())); }