Skip to content

Commit

Permalink
Merge pull request #9 from aol/log-configured-resources
Browse files Browse the repository at this point in the history
Log configured resources. Merging into head, will create another one to log filters and servlets.
  • Loading branch information
johnmcclean committed Mar 19, 2015
2 parents 6610661 + 228af24 commit b1db025
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public class AccessLogLocationBean {
private final String accessLogLocation;

@Autowired
public AccessLogLocationBean(@Value("${access.log.output:/data/servers/logs/}") String accessLogLocation) {
public AccessLogLocationBean(@Value("${access.log.output:./logs/}") String accessLogLocation) {
this.accessLogLocation = accessLogLocation;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.glassfish.grizzly.http.server.accesslog.AccessLogBuilder;
import org.glassfish.grizzly.servlet.ServletRegistration;
import org.glassfish.grizzly.servlet.WebappContext;
import org.glassfish.jersey.server.ResourceConfig;
import org.glassfish.jersey.servlet.ServletContainer;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down Expand Up @@ -85,6 +86,10 @@ private void startServer(WebappContext webappContext, HttpServer httpServer, Com
.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.v1 + " : " + "http://localhost:"+serverData.getPort()
+"/"+serverData.getModule().getContext() + t.v2 ));;
httpServer.start();
start.complete(true);
end.get();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
package com.aol.micro.server.servers.model;

import static org.jooq.lambda.tuple.Tuple.tuple;

import java.util.List;
import java.util.stream.Stream;

import javax.ws.rs.Path;

import lombok.Getter;
import lombok.experimental.Builder;

import org.jooq.lambda.tuple.Tuple2;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationContext;

import com.aol.micro.server.module.Module;
Expand All @@ -13,6 +21,8 @@
@Getter
@Builder
public class ServerData {

private final Logger logger = LoggerFactory.getLogger(getClass());

private final int port;

Expand All @@ -32,5 +42,14 @@ public ServerData(int port, List resources,
this.baseUrlPattern = baseUrlPattern;
}

public Stream<Tuple2<String,String>> extractResources() {


return resources.stream().map(resource -> tuple(resource.getClass().getName(),
resource.getClass().getAnnotation(Path.class).value()));


}


}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,15 @@
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;

import java.util.stream.Collectors;

import org.junit.Before;
import org.junit.Test;
import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;

import app.servlet.com.aol.micro.server.ServletStatusResource;

import com.aol.micro.server.module.Module;
import com.aol.micro.server.rest.swagger.SwaggerInitializer;
import com.aol.micro.server.servers.model.ServerData;
import com.google.common.collect.Lists;

Expand All @@ -38,6 +35,30 @@ public void testGetters() {
assertThat(serverData.getModule().getContext(), is("context"));
assertThat(serverData.getPort(), is(8080));
}

@Test(expected=NullPointerException.class)
public void testExtractNull(){

serverData = new ServerData(8080, Lists.newArrayList((Object)null), rootContext, "url",
()->"context");
serverData.extractResources();

}

@Test
public void testExtractResourceClassName(){


assertThat(serverData.extractResources().collect(Collectors.toList()).get(0).v1,is(ServletStatusResource.class.getName()));

}
@Test
public void testExtractResourcePath(){


assertThat(serverData.extractResources().collect(Collectors.toList()).get(0).v2,is("/servlet"));

}


}

0 comments on commit b1db025

Please sign in to comment.