Skip to content

Commit

Permalink
Merge pull request #21 from aol/expose-http-server
Browse files Browse the repository at this point in the history
A mechanism to expose Grizzly HttpServer to clients for further configuration.
  • Loading branch information
johnmcclean committed Apr 13, 2015
2 parents bfd1c4e + e021b3c commit 3521be6
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 9 deletions.
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ subprojects {
apply plugin: 'com.bmuschko.nexus'
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '0.54'
version = '0.55'

jar {
manifest {
Expand Down Expand Up @@ -57,7 +57,7 @@ subprojects {
exclude(module: 'org.springframework')
}

compile group: 'com.aol.simplereact', name:'simple-react', version:'0.83'
compile group: 'com.aol.simplereact', name:'simple-react', version:'0.84'
compile group: 'org.apache.httpcomponents', name:'httpclient', version:'4.4'
compile group: 'org.apache.httpcomponents', name:'httpasyncclient', version:'4.1-beta1'
compile group: 'com.wordnik', name: 'swagger-jersey2-jaxrs_2.10', version:'1.3.10'
Expand Down
2 changes: 1 addition & 1 deletion micro-boot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ dependencies {
compile 'org.springframework.boot:spring-boot:1.2.1.RELEASE'
compile 'org.springframework.boot:spring-boot-autoconfigure:1.2.1.RELEASE'
//compile project(':micro-core')
compile group: 'com.aol.microservices', name:'microserver-core', version:'0.53.3'
compile group: 'com.aol.microservices', name:'microserver-core', version:'0.54'

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;
import java.util.function.Supplier;

import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletContextListener;

import org.glassfish.grizzly.http.server.HttpServer;

import lombok.AllArgsConstructor;
import lombok.experimental.Builder;
import lombok.experimental.Wither;
Expand Down Expand Up @@ -38,8 +41,17 @@ public class ConfigurableModule implements Module{
private final Set<Class> springConfigurationClasses;
private final Map<String,String> propertyOverrides;
private final List<String> defaultJaxRsPackages;
private final Consumer<HttpServer> serverConfigManager;
private final boolean resetAll;

@Override
public Consumer<HttpServer> getServerConfigManager(){
if(serverConfigManager!=null)
return serverConfigManager;

return Module.super.getServerConfigManager();
}

@Override
public List<String> getDefaultJaxRsPackages() {
if(defaultJaxRsPackages!=null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,13 @@
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletContextListener;

import org.glassfish.grizzly.http.server.HttpServer;
import org.springframework.web.context.ContextLoaderListener;
import org.springframework.web.context.WebApplicationContext;

Expand All @@ -32,6 +34,9 @@

public interface Module {

default Consumer<HttpServer> getServerConfigManager(){
return server->{};
}
default List<String> getPackages(){
return ImmutableList.of();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public void run(CompletableFuture start, CompletableFuture end) {
addListeners(webappContext);

HttpServer httpServer = HttpServer.createSimpleServer(null, "0.0.0.0", serverData.getPort());

serverData.getModule().getServerConfigManager().accept(httpServer);
addAccessLog(httpServer);
if (SSLProperties != null)
this.createSSLListener(serverData.getPort());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package app.single.serverconfig.com.aol.micro.server;

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

import java.util.concurrent.ExecutionException;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;

import com.aol.micro.server.MicroserverApp;
import com.aol.micro.server.auto.discovery.RestResource;
import com.aol.micro.server.config.Microserver;
import com.aol.micro.server.module.ConfigurableModule;
import com.aol.micro.server.testing.RestAgent;


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

RestAgent rest = new RestAgent();

boolean called;
MicroserverApp server;
@Before
public void startServer(){
called = false;
server = new MicroserverApp( ConfigurableModule.builder()
.context("hello")
.serverConfigManager(server->called=true)
.build());
server.start();

}

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

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



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

}

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


}
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,20 @@

import static org.hamcrest.Matchers.hasItem;
import static org.hamcrest.Matchers.is;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.*;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.function.Consumer;

import javax.servlet.Filter;
import javax.servlet.Servlet;
import javax.servlet.ServletContextListener;

import org.glassfish.grizzly.http.server.HttpServer;
import org.junit.Before;
import org.junit.Test;

Expand All @@ -40,6 +42,7 @@ public class ConfigurableModuleTest {
private List<String> defaultJaxRsPackages;

private Module m = () -> "module";
Consumer<HttpServer> serverConfigManager = server-> {};
@Before
public void setup(){

Expand All @@ -55,7 +58,9 @@ public void setup(){
servlets = new HashMap<>();
springConfigurationClasses = ImmutableSet.of(this.getClass());


module = ConfigurableModule.builder()
.serverConfigManager(serverConfigManager )
.defaultJaxRsPackages(defaultJaxRsPackages)
.context(context)
.defaultResources(defaultResources)
Expand All @@ -73,6 +78,19 @@ public void setup(){
.build();
}
@Test
public void testGetServerConfigManager() {
assertThat(module.withResetAll(true).getServerConfigManager(),is(serverConfigManager));
}
@Test
public void testGetServerConfigManagerNull() {
try {
module.withServerConfigManager(null)
.getServerConfigManager().accept(null);
}catch(Exception e){
fail(e.getMessage());
}
}
@Test
public void testGetRestResourceClassesResetAll() {
assertThat(module.withResetAll(true).getRestResourceClasses(),is(resourceClasses));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class ServerRunnerTest {
private GrizzlyApplication serverApplication1;
private GrizzlyApplication serverApplication2;
private ServerData[] registered;
int server1Count =0;
int server2Count =0;
volatile int server1Count =0;
volatile int server2Count =0;
@Before
public void setUp() {

Expand All @@ -35,14 +35,16 @@ public void setUp() {

serverApplication1 = new GrizzlyApplication(AllData.builder().serverData(data1).build()){
public void run(CompletableFuture start,CompletableFuture end) {
start.complete(true);
server1Count++;
start.complete(true);

}
};
serverApplication2 = new GrizzlyApplication(AllData.builder().serverData(data2).build()){
public void run(CompletableFuture start,CompletableFuture end) {
start.complete(true);
server2Count++;
start.complete(true);

}
};

Expand Down

0 comments on commit 3521be6

Please sign in to comment.