Skip to content

Commit

Permalink
fix for #398
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmcclean committed Apr 25, 2018
1 parent 7ab60a1 commit 25a4548
Show file tree
Hide file tree
Showing 4 changed files with 73 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,5 +71,13 @@ private void logMissingPath(Object resource) {
}
}

public String getNormalizedContextPath(){
if("".equals(module.getContext()))
return "";
else
return "/"+module.getContext();

}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package app.root.context.single;

import com.oath.micro.server.MicroserverApp;
import com.oath.micro.server.auto.discovery.RestResource;
import com.oath.micro.server.config.Microserver;
import com.oath.micro.server.testing.RestAgent;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import java.util.concurrent.ExecutionException;

import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;

@Microserver
@Path("/single")
public class RootSingleClassTest implements RestResource{

RestAgent rest = new RestAgent();

MicroserverApp server;
@Before
public void startServer(){

server = new MicroserverApp( RootSingleClassTest.class, ()-> "");
server.start();

}

@After
public void stopServer(){
server.stop();
}

@Test
public void runAppAndBasicTest() throws InterruptedException, ExecutionException{



assertThat(rest.get("http://localhost:8080/single/ping"),is("ok"));

}

@GET
@Produces("text/plain")
@Path("/ping")
public String ping() {
return "ok";
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,13 @@ public class GrizzlyApplication implements ServerApplication {
private final PersistentList<ServletData> servletData;
private final PersistentList<ServletContextListener> servletContextListenerData;
private final PersistentList<ServletRequestListener> servletRequestListenerData;

public GrizzlyApplication(AllData serverData) {
this.serverData = serverData.getServerData();
this.filterData = serverData.getFilterDataList();
this.servletData = serverData.getServletDataList();
this.servletContextListenerData = serverData.getServletContextListeners();
this.servletRequestListenerData = serverData.getServletRequestListeners();
this.servletRequestListenerData = serverData.getServletRequestListeners();
}

public void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer, CompletableFuture end) {
Expand All @@ -63,7 +63,7 @@ public void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer

new ServletContextListenerConfigurer(serverData, servletContextListenerData, servletRequestListenerData);


jaxRsConfigurer.addServlet(this.serverData,webappContext);

new ServletConfigurer(serverData, servletData).addServlets(webappContext);
Expand All @@ -79,7 +79,7 @@ public void run(CompletableFuture start, JaxRsServletConfigurer jaxRsConfigurer

startServer(webappContext, httpServer, start, end);
}

private void addSSL(HttpServer httpServer) {
SSLProperties sslProperties = serverData.getRootContext().getBean(SSLProperties.class);
if (sslProperties != null) {
Expand All @@ -91,10 +91,10 @@ private void startServer(WebappContext webappContext, HttpServer httpServer, Com
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("Browse to http://localhost:{}{}/application.wadl", serverData.getPort(), serverData.getNormalizedContextPath());
logger.info("Configured resource classes :-");
serverData.extractResources()
.forEach(t -> logger.info(t._1() + " : " + "http://localhost:" + serverData.getPort() + "/" + serverData.getModule().getContext() + t._2()));
.forEach(t -> logger.info(t._1() + " : " + "http://localhost:" + serverData.getPort() + "/" + serverData.getNormalizedContextPath() + t._2()));
;
httpServer.start();
start.complete(true);
Expand Down Expand Up @@ -129,7 +129,7 @@ private void addAccessLog(HttpServer httpServer) {

}
}


private NetworkListener createSSLListener(int port, SSLProperties sslProperties) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,10 +91,10 @@ private void startServer( Tomcat httpServer, CompletableFuture start, Completabl

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("Browse to http://localhost:{}{}/application.wadl", serverData.getPort(), serverData.getNormalizedContextPath());
logger.info("Configured resource classes :-");
serverData.extractResources().forEach(
t -> logger.info(t._1() + " : " + "http://localhost:" + serverData.getPort() + "/" + serverData.getModule().getContext() + t._2()));
t -> logger.info(t._1() + " : " + "http://localhost:" + serverData.getPort() + serverData.getNormalizedContextPath() + t._2()));
;

httpServer.start();
Expand Down

0 comments on commit 25a4548

Please sign in to comment.