Skip to content

Commit

Permalink
fix for #18
Browse files Browse the repository at this point in the history
  • Loading branch information
johnmcclean committed Apr 2, 2015
1 parent e2d15df commit 200f8b2
Show file tree
Hide file tree
Showing 16 changed files with 184 additions and 25 deletions.
13 changes: 5 additions & 8 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ buildscript {
}


String jerseyVersion = '2.17' //2.5.1
String jerseyVersion = '2.17'
String grizzlyVersion = '2.3.19'

apply plugin: 'com.github.lkishalmi.bill-of-materials'
Expand All @@ -27,9 +27,8 @@ subprojects {
apply plugin: 'com.bmuschko.nexus'
sourceCompatibility = 1.8
targetCompatibility = 1.8
version = '0.53.5'
version = '0.54'

// jerseyVersion = '2.17' //2.5.1
jar {
manifest {
attributes 'Implementation-Title': 'Gradle Quickstart', 'Implementation-Version': version
Expand Down Expand Up @@ -57,9 +56,7 @@ subprojects {
compile ('com.ryantenney.metrics:metrics-spring:3.0.3'){
exclude(module: 'org.springframework')
}
compile ('net.javacrumbs.future-converter:future-converter-spring-java8:0.1.0'){
exclude(module: 'org.springframework')
}

compile group: 'com.aol.simplereact', name:'simple-react', version:'0.83'
compile group: 'org.apache.httpcomponents', name:'httpclient', version:'4.4'
compile group: 'org.apache.httpcomponents', name:'httpasyncclient', version:'4.1-beta1'
Expand Down Expand Up @@ -104,8 +101,8 @@ subprojects {
compile group: 'org.aspectj', name: 'aspectjweaver', version:'1.5.4'
compile group: 'org.glassfish.grizzly', name: 'grizzly-http-server', version:"$grizzlyVersion"
compile group: 'org.glassfish.grizzly', name: 'grizzly-http-all', version:"$grizzlyVersion"
compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version:'2.3'
compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-servlet', version:'2.3'
compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-http', version:"$jerseyVersion"
compile group: 'org.glassfish.jersey.containers', name: 'jersey-container-grizzly2-servlet', version:"$jerseyVersion"
compile "org.glassfish.jersey.ext:jersey-spring3:$jerseyVersion"
compile "org.glassfish.jersey.ext:jersey-bean-validation:$jerseyVersion"
// testCompile ('org.springframework:spring-jdbc-roma:1.0.0-RELEASE'){
Expand Down
2 changes: 1 addition & 1 deletion micro-boot/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ modifyPom {

groupId 'com.aol.microservices'
artifactId 'microserver-boot'
version '0.53.3'
version '0.53.6'

scm {
url 'scm:[email protected]:aol/micro-server.git'
Expand Down
2 changes: 1 addition & 1 deletion micro-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ modifyPom {

groupId 'com.aol.microservices'
artifactId 'microserver-core'
version '0.53.5'
version '0.54'

dependencyManagement {
dependencies{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public MicroserverApp(Class c, Module... modules) {
public MicroserverApp(Config config, Module... modules) {

this.modules = Lists.newArrayList(modules);
if(config.getBasePackages().length==0){
String[] packages = {extractClass().getPackage().getName()};
config = config.withBasePackages(packages);
}
config.set();
springContext = new SpringContextFactory(config,
modules[0].getSpringConfigurationClasses())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public class Config {
private final ImmutableMap<String, List<String>> dataSources;
private final SSLProperties sslProperties;
private final boolean allowCircularReferences;
private final String[] basePackages;

public Config() {
classes = ImmutableSet.of();
Expand All @@ -47,6 +48,7 @@ public Config() {
instancePropertiesName = "instance.properties";
sslProperties = null;
allowCircularReferences = false;
basePackages=new String[0];

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,6 @@
*/
boolean allowCircularDependencies() default false;

@Microserver
static class Instance{}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,23 @@ public class MicroserverConfigurer implements Configurer {

public Config buildConfig(Class class1) {
Microserver microserver = (Microserver) class1.getAnnotation(Microserver.class);
if (microserver == null)
return Config.instance();


if (microserver == null){
microserver = Microserver.Instance.class.getAnnotation(Microserver.class);

}
String[] basePackages=microserver.basePackages();
if(basePackages.length==0){
String[] basePackagesFromClass ={class1.getPackage().getName()};
basePackages = basePackagesFromClass;
}

List<Class> classes = buildClasses(class1, microserver);

Map<String, String> properties = buildProperties(microserver);

return Config.instance().withEntityScan(microserver.entityScan()).withClasses(ImmutableSet.copyOf(classes))
return Config.instance().withBasePackages(basePackages).withEntityScan(microserver.entityScan()).withClasses(ImmutableSet.copyOf(classes))
.withPropertiesName(microserver.propertiesName()).withInstancePropertiesName(microserver.instancePropertiesName())
.withAllowCircularReferences(microserver.allowCircularDependencies()).withProperties(ImmutableMap.copyOf(properties)).set();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.context.ApplicationContext;
import org.springframework.web.filter.DelegatingFilterProxy;

import com.aol.micro.server.auto.discovery.Rest;
import com.aol.micro.server.servers.model.FilterData;
import com.aol.micro.server.servers.model.ServerData;
import com.aol.micro.server.servers.model.ServletData;
Expand All @@ -27,6 +28,8 @@ public ImmutableList getRestResources( ApplicationContext rootContext){

List resources = Lists.newArrayList();
module.getRestResourceClasses().forEach(it -> resources.addAll(rootContext.getBeansOfType(it).values()));
System.out.println(module.getRestAnnotationClasses());
System.out.println("resources " + rootContext.getBeansWithAnnotation(Rest.class));
module.getRestAnnotationClasses().forEach(it -> resources.addAll(rootContext.getBeansWithAnnotation(it).values()));
return ImmutableList.copyOf(resources);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.aol.micro.server.rest.client.nio;

import static net.javacrumbs.futureconverter.springjava.FutureConverter.toCompletableFuture;

import java.net.URI;
import java.util.Map;
Expand All @@ -15,14 +14,15 @@
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import org.springframework.util.concurrent.ListenableFuture;
import org.springframework.util.concurrent.ListenableFutureCallback;
import org.springframework.web.client.AsyncRequestCallback;
import org.springframework.web.client.AsyncRestTemplate;
import org.springframework.web.client.ResponseExtractor;
import org.springframework.web.client.RestClientException;

import com.aol.micro.server.rest.JacksonUtil;


public class SpringRestTemplate {

@Getter
Expand Down Expand Up @@ -59,8 +59,6 @@ public CompletableFuture<HttpHeaders> headForHeaders(String url,
return toCompletableFuture(template.headForHeaders(url, uriVariables));
}



public CompletableFuture<HttpHeaders> headForHeaders(String url,
Map<String, ?> uriVariables) throws RestClientException {
return toCompletableFuture(template.headForHeaders(url, uriVariables));
Expand Down Expand Up @@ -227,11 +225,40 @@ public <T> CompletableFuture<T> execute(URI url, HttpMethod method,

public SpringRestTemplate(AsyncRestTemplate template) {
super();

this.template = template;
MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
converter.setObjectMapper(JacksonUtil.getMapper());
template.getMessageConverters().add(converter);
}

<T> CompletableFuture<T> toCompletableFuture(
final ListenableFuture<T> listenableFuture) {
// create an instance of CompletableFuture
CompletableFuture<T> completable = new CompletableFuture<T>() {
@Override
public boolean cancel(boolean mayInterruptIfRunning) {
// propagate cancel to the listenable future
boolean result = listenableFuture.cancel(mayInterruptIfRunning);
super.cancel(mayInterruptIfRunning);
return result;
}
};

// add callback
listenableFuture.addCallback(new ListenableFutureCallback<T>() {
@Override
public void onSuccess(T result) {
completable.complete(result);
}

@Override
public void onFailure(Throwable t) {
completable.completeExceptionally(t);
}
});
return completable;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,8 @@ public ConfigurableApplicationContext createSpringApp(Config config, Class... cl
rootContext.setAllowCircularReferences(config.isAllowCircularReferences());
rootContext.register(classes);

Optional<Package> basePackage = Stream.of(classes).filter(cl -> cl.getAnnotation(Microserver.class) != null).map(cl -> cl.getPackage())
.findAny();
basePackage.ifPresent(base -> rootContext.scan(Stream.of(classes).map(cl -> cl.getAnnotation(Microserver.class)).filter(ano -> ano != null)
.map(ano -> ((Microserver) ano).basePackages())
.map(packages -> UsefulStaticMethods.eitherArray(packages, new String[] { base.getName() })).findFirst().get()));


rootContext.scan(config.getBasePackages());
rootContext.refresh();
logger.debug("Configuring Additional Spring Beans");
ConfigurableListableBeanFactory beanFactory = ((ConfigurableApplicationContext) rootContext).getBeanFactory();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import com.aol.micro.server.testing.RestAgent;
import com.google.common.collect.ImmutableMap;

@Microserver
//@Microserver
public class JdbcRunnerTest {

private final RestClient<JdbcEntity> listClient = new RestClient(1000,1000).withResponse(JdbcEntity.class);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package app.noanno.com.aol.micro.server.copy;


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

import java.util.concurrent.ExecutionException;

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

import com.aol.micro.server.MicroserverApp;
import com.aol.micro.server.config.Microserver;
import com.aol.micro.server.testing.RestAgent;


public class NoAnnoRunnerTest {

RestAgent rest = new RestAgent();

MicroserverApp server;
@Before
public void startServer(){

server = new MicroserverApp(()-> "simple-app");
server.start();

}

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

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



assertThat(rest.get("http://localhost:8080/simple-app/status/ping"),is("ok"));


}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package app.noanno.com.aol.micro.server.copy;

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

import com.aol.micro.server.auto.discovery.Rest;

@Rest
@Path("/status")
public class NoAnnoStatusResource {



@GET
@Produces("text/plain")
@Path("/ping")
public String ping() {

return "ok";
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package app.noanno.com.aol.micro.server.copy;

import com.aol.micro.server.MicroserverApp;

public class SimpleApp {

public static void main(String[] args){
new MicroserverApp(()-> "simple-app").run();
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package com.windriver.simpleserver;

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

import com.aol.micro.server.auto.discovery.Rest;

@Rest
@Path("/foo")
public class HelloResource {

@GET
@Produces("text/plain")
@Path("/hello")
public String hello() {
return "world";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.windriver.simpleserver;


import com.aol.micro.server.MicroserverApp;

public class TestMicroserverApp {

public static void main(String[] args) {
// SLF4JBridgeHandler.removeHandlersForRootLogger();
// SLF4JBridgeHandler.install();

new MicroserverApp(()->"simple").start();
}

}

0 comments on commit 200f8b2

Please sign in to comment.