Skip to content

Commit d046b2c

Browse files
committed
ssl, micro-tomcat-with-jersey
1 parent d5af691 commit d046b2c

File tree

65 files changed

+2198
-25
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+2198
-25
lines changed

micro-core/src/main/java/com/aol/micro/server/config/SSLProperties.java

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
package com.aol.micro.server.config;
22

3+
import java.util.Optional;
4+
5+
import com.aol.cyclops.monad.AnyM;
6+
37
import lombok.AllArgsConstructor;
48
import lombok.Getter;
59
import lombok.experimental.Builder;
@@ -13,4 +17,33 @@ public class SSLProperties {
1317
private final String keyStorePass;
1418
private final String trustStoreFile;
1519
private final String trustStorePass;
20+
private final String keyStoreType;
21+
private final String keyStoreProvider;
22+
private final String trustStoreType;
23+
private final String trustStoreProvider;
24+
private final String clientAuth;
25+
private final String ciphers;
26+
private final String protocol;
27+
28+
public AnyM<String> getKeyStoreType() {
29+
return AnyM.ofNullable(keyStoreType);
30+
}
31+
public AnyM<String> getKeyStoreProvider() {
32+
return AnyM.ofNullable(keyStoreProvider);
33+
}
34+
public AnyM<String> getTrustStoreType() {
35+
return AnyM.ofNullable(trustStoreType);
36+
}
37+
public AnyM<String> getTrustStoreProvider() {
38+
return AnyM.ofNullable(trustStoreProvider);
39+
}
40+
public AnyM<String> getClientAuth() {
41+
return AnyM.ofNullable(clientAuth);
42+
}
43+
public AnyM<String> getCiphers() {
44+
return AnyM.ofNullable(ciphers);
45+
}
46+
public AnyM<String> getProtocol() {
47+
return AnyM.ofNullable(protocol);
48+
}
1649
}

micro-grizzly/src/main/java/com/aol/micro/server/servers/grizzly/SSLConfigurationBuilder.java

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,35 @@ public SSLEngineConfigurator build(SSLProperties sslProperties) {
1212

1313
SSLContextConfigurator sslContext = new SSLContextConfigurator();
1414

15-
sslContext.setKeyStoreFile("./keystore_server"); // contains server keypair
16-
sslContext.setKeyStorePass("asdfgh");
17-
sslContext.setTrustStoreFile("./truststore_server"); // contains client certificate
18-
sslContext.setTrustStorePass("asdfgh");
15+
sslContext.setKeyStoreFile(sslProperties.getKeyStoreFile()); // contains server keypair
16+
sslContext.setKeyStorePass(sslProperties.getKeyStorePass());
17+
sslContext.setTrustStoreFile(sslProperties.getTrustStoreFile()); // contains client certificate
18+
sslContext.setTrustStorePass(sslProperties.getTrustStorePass());
1919

20+
21+
22+
sslProperties.getKeyStoreType().peek(type->sslContext.setKeyStoreType(type));
23+
sslProperties.getKeyStoreProvider().peek(provider->sslContext.setKeyStoreProvider(provider));
24+
25+
26+
sslProperties.getTrustStoreType().peek(type->sslContext.setTrustStoreType(type));
27+
sslProperties.getTrustStoreProvider().peek(provider->sslContext.setTrustStoreProvider(provider));
28+
29+
30+
31+
32+
2033
SSLEngineConfigurator sslConf = new SSLEngineConfigurator(sslContext).setClientMode(false);
34+
sslProperties.getClientAuth().filter(auth-> auth.toLowerCase().equals("want"))
35+
.peek(auth->sslConf.setWantClientAuth(true));
36+
sslProperties.getClientAuth().filter(auth-> auth.toLowerCase().equals("need"))
37+
.peek(auth->sslConf.setNeedClientAuth(true));
38+
sslProperties.getCiphers().peek(ciphers->sslConf.setEnabledCipherSuites(ciphers.split(",")))
39+
.peek(c-> sslConf.setCipherConfigured(true));
40+
sslProperties.getProtocol().peek(pr->sslConf.setEnabledProtocols(pr.split(",")))
41+
.peek(p->sslConf.setProtocolConfigured(true));
42+
43+
2144
return sslConf;
2245
}
2346
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
test=hello world

micro-tomcat-with-jersey/build.gradle

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
description = 'micro-tomcat-with-jersey'
2+
dependencies {
3+
4+
compile project(':micro-core')
5+
compile project(':micro-tomcat')
6+
compile project(':micro-jersey')
7+
compile project(':micro-jackson-configuration')
8+
9+
testCompile group: 'com.aol.simplereact', name:'simple-react', version:"${simpleReactVersion}"
10+
11+
12+
}
13+
14+
modifyPom {
15+
project {
16+
name 'Microserver Tomcat With Jersey'
17+
description 'Opinionated rest microservices'
18+
url 'https://github.com/aol/micro-server'
19+
inceptionYear '2015'
20+
21+
groupId 'com.aol.microservices'
22+
artifactId 'micro-tomcat-with-jersey'
23+
version "$version"
24+
25+
26+
scm {
27+
url 'scm:git@github.com:aol/micro-server.git'
28+
connection 'scm:git@github.com:aol/micro-server.git'
29+
developerConnection 'scm:git@github.com:aol/micro-server.git'
30+
}
31+
32+
licenses {
33+
license {
34+
name 'The Apache Software License, Version 2.0'
35+
url 'http://www.apache.org/licenses/LICENSE-2.0.txt'
36+
distribution 'repo'
37+
}
38+
}
39+
40+
developers {
41+
developer {
42+
id 'johnmcclean-aol'
43+
name 'John McClean'
44+
email 'john.mcclean@teamaol.com'
45+
}
46+
47+
}
48+
49+
}
50+
}
51+
52+
extraArchive {
53+
sources = true
54+
tests = true
55+
javadoc = true
56+
}
57+
58+
nexus {
59+
sign = true
60+
repositoryUrl = 'https://oss.sonatype.org/service/local/staging/deploy/maven2'
61+
snapshotRepositoryUrl = 'https://oss.sonatype.org/content/repositories/snapshots'
62+
}
63+

micro-tomcat-with-jersey/readme.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Tomcat, Jersey and Microserver together
2+
3+
[Example Tomcat & Jersey Apps](https://github.com/aol/micro-server/tree/master/micro-tomcat/src/test/java/app)
4+
5+
Convenience module that packages Tomcat, Jersey, Jackson and Microserver together
6+
7+
## Note
8+
9+
Tomcat does not currently support the Microserver micro-monolith style of development where by multiple Microservers can be rolled up into a single 'monolithic' style services at runtime. If you require that type of functionality take a look at micro-grizzly instead.
10+
11+
12+
## To use
13+
14+
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/com.aol.microservices/micro-grizzly-with-jersey/badge.svg)](https://maven-badges.herokuapp.com/maven-central/com.aol.microservices/micro-grizzly-with-jersey)
15+
16+
Simply add to the classpath
17+
18+
Maven
19+
```xml
20+
<dependency>
21+
<groupId>com.aol.microservices</groupId>
22+
<artifactId>micro-tomcat-with-jersey</artifactId>
23+
<version>x.yz</version>
24+
</dependency>
25+
```
26+
Gradle
27+
```groovy
28+
compile 'com.aol.microservices:micro-tomcat-with-jersey:x.yz'
29+
```
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
package app.async.com.aol.micro.server;
2+
3+
import static org.hamcrest.CoreMatchers.is;
4+
import static org.junit.Assert.assertThat;
5+
6+
import java.io.IOException;
7+
import java.util.Properties;
8+
import java.util.concurrent.ExecutionException;
9+
10+
import org.junit.After;
11+
import org.junit.Before;
12+
import org.junit.Test;
13+
14+
import com.aol.micro.server.MicroserverApp;
15+
import com.aol.micro.server.config.Config;
16+
import com.aol.micro.server.config.Microserver;
17+
import com.aol.micro.server.spring.properties.PropertyFileConfig;
18+
import com.aol.micro.server.testing.RestAgent;
19+
import com.aol.simple.react.stream.traits.LazyFutureStream;
20+
21+
@Microserver
22+
public class AsyncAppRunner {
23+
24+
25+
RestAgent rest = new RestAgent();
26+
27+
MicroserverApp server;
28+
@Before
29+
public void startServer(){
30+
31+
server = new MicroserverApp( ()-> "async-app");
32+
server.start();
33+
34+
}
35+
36+
@After
37+
public void stopServer(){
38+
server.stop();
39+
}
40+
41+
@Test
42+
public void runAppAndBasicTest() throws InterruptedException, ExecutionException{
43+
44+
Thread.sleep(2000);
45+
46+
assertThat(rest.get("http://localhost:8080/async-app/async/expensive"),is(";test!;test!;test!"));
47+
48+
}
49+
50+
@Test
51+
public void loadProperties() throws IOException{
52+
53+
Properties props = new PropertyFileConfig(true).propertyFactory() ;
54+
assertThat(props.getProperty("test"),is("hello world"));
55+
}
56+
57+
58+
59+
}
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package app.async.com.aol.micro.server;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
6+
import javax.ws.rs.GET;
7+
import javax.ws.rs.Path;
8+
import javax.ws.rs.Produces;
9+
import javax.ws.rs.container.AsyncResponse;
10+
import javax.ws.rs.container.Suspended;
11+
12+
import org.springframework.stereotype.Component;
13+
14+
import com.aol.cyclops.sequence.SequenceM;
15+
import com.aol.micro.server.auto.discovery.RestResource;
16+
import com.aol.micro.server.testing.RestAgent;
17+
import com.aol.simple.react.stream.simple.SimpleReact;
18+
import com.aol.simple.react.stream.traits.LazyFutureStream;
19+
20+
@Path("/async")
21+
@Component
22+
public class AsyncResource implements RestResource{
23+
24+
private final SimpleReact simpleReact =new SimpleReact();
25+
private final List<String> urls = Arrays.asList("http://localhost:8080/async-app/async/ping2",
26+
"http://localhost:8080/async-app/async/ping",
27+
"http://localhost:8080/async-app/async/ping",
28+
"http://localhost:8080/async-app/async/ping");
29+
30+
private final RestAgent client = new RestAgent();
31+
32+
@GET
33+
@Path("/expensive")
34+
@Produces("text/plain")
35+
public void expensive(@Suspended AsyncResponse asyncResponse){
36+
37+
LazyFutureStream.lazyFutureStreamFromIterable(urls)
38+
.then(it->client.get(it))
39+
.onFail(it -> "")
40+
.peek(it ->
41+
System.out.println(it))
42+
.convertToSimpleReact()
43+
.<String,Boolean>allOf(data -> {
44+
System.out.println(data);
45+
return asyncResponse.resume(SequenceM.fromIterable(data).join(";")); });
46+
}
47+
48+
@GET
49+
@Produces("text/plain")
50+
@Path("/ping")
51+
public String ping() {
52+
return "test!";
53+
}
54+
55+
56+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package app.async.com.aol.micro.server;
2+
3+
import java.io.IOException;
4+
import java.util.Properties;
5+
6+
import com.aol.micro.server.MicroserverApp;
7+
import com.aol.micro.server.config.Config;
8+
import com.aol.micro.server.spring.properties.PropertyFileConfig;
9+
10+
public class Simple {
11+
12+
public static void main(String[] args) throws IOException{
13+
14+
new MicroserverApp(()->"test-app").run();
15+
}
16+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package app.async.com.aol.micro.server;
2+
3+
import java.util.Arrays;
4+
import java.util.List;
5+
import java.util.concurrent.CompletableFuture;
6+
import java.util.concurrent.ForkJoinPool;
7+
import java.util.function.Supplier;
8+
9+
import javax.ws.rs.GET;
10+
import javax.ws.rs.Path;
11+
12+
import com.aol.micro.server.MicroserverApp;
13+
import com.aol.micro.server.auto.discovery.Rest;
14+
import com.aol.simple.react.stream.simple.SimpleReact;
15+
16+
17+
18+
@Rest
19+
@Path("/test")
20+
public class SimpleApp {
21+
22+
public static void main(String[] args){
23+
new MicroserverApp(()->"test-app").run();
24+
}
25+
@GET
26+
public String myEndPoint(){
27+
return "hello world!";
28+
}
29+
30+
31+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package app.blacklisted.com.aol.micro.server.copy;
2+
3+
import java.util.Arrays;
4+
5+
import org.glassfish.jersey.media.multipart.MultiPartFeature;
6+
7+
import com.aol.micro.server.MicroserverApp;
8+
import com.aol.micro.server.module.ConfigurableModule;
9+
10+
public class SimpleApp {
11+
12+
public static void main(String[] args){
13+
14+
new MicroserverApp(()-> "simple-app").run();
15+
}
16+
17+
18+
}

0 commit comments

Comments
 (0)