Skip to content

Commit

Permalink
Merge pull request #17 from noboomu/development
Browse files Browse the repository at this point in the history
Development
  • Loading branch information
noboomu authored May 15, 2019
2 parents 9bf999e + d024cc1 commit 1e1d8ba
Show file tree
Hide file tree
Showing 34 changed files with 618 additions and 137 deletions.
2 changes: 1 addition & 1 deletion core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<groupId>org.apache.maven.plugins</groupId>

</plugin>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@
import com.google.inject.name.Named;
import com.typesafe.config.Config;
import io.sinistral.proteus.modules.ConfigModule;
import io.sinistral.proteus.modules.JacksonModule;
import io.sinistral.proteus.server.Extractors;
import io.sinistral.proteus.server.ServerResponse;
import io.sinistral.proteus.server.endpoints.EndpointInfo;
import io.sinistral.proteus.server.handlers.HandlerGenerator;
import io.sinistral.proteus.server.handlers.ServerDefaultHttpHandler;
Expand Down Expand Up @@ -226,6 +229,8 @@ public boolean isRunning()
public void buildServer()
{



for (Class<?> controllerClass : registeredControllers) {
HandlerGenerator generator = new HandlerGenerator("io.sinistral.proteus.controllers.handlers", controllerClass);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,21 +59,32 @@ public void bindMappers()

this.bind(XmlMapper.class).toInstance(xmlMapper);

ObjectMapper objectMapper = new ObjectMapper();

objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true);
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
objectMapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true);
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
objectMapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
objectMapper.registerModule(new AfterburnerModule());
objectMapper.registerModule(new Jdk8Module());

this.bind(ObjectMapper.class).toInstance(objectMapper);
try {

String className = config.getString("application.jacksonModule");

log.info("Installing JacksonModule " + className);

Class<? extends AbstractModule> clazz = (Class<? extends AbstractModule>) Class.forName(className);

AbstractModule module = clazz.newInstance();

install(module);

} catch (Exception e) {

this.binder().addError(e);

log.error(e.getMessage(), e);

install(new JacksonModule());

}

this.requestStaticInjection(Extractors.class);
this.requestStaticInjection(ServerResponse.class);
}

}

@SuppressWarnings("unchecked")
@Override
Expand Down
12 changes: 12 additions & 0 deletions core/src/main/java/io/sinistral/proteus/modules/ConfigModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ public ConfigModule()
}
}



public ConfigModule(String configFile)
{
this.configFile = configFile;
Expand All @@ -56,6 +58,16 @@ public ConfigModule(URL configURL)
this.configURL = configURL;
}

public Config getConfig()
{
return config;
}

public void setConfig(Config config)
{
this.config = config;
}

@SuppressWarnings("unchecked")
private void bindConfig(final Config config)
{
Expand Down
27 changes: 27 additions & 0 deletions core/src/main/java/io/sinistral/proteus/modules/JacksonModule.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package io.sinistral.proteus.modules;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
import com.google.inject.AbstractModule;

public class JacksonModule extends AbstractModule
{
@Override
protected void configure()
{
ObjectMapper objectMapper = new ObjectMapper();

objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_ARRAY_AS_NULL_OBJECT, true);
objectMapper.configure(DeserializationFeature.ACCEPT_EMPTY_STRING_AS_NULL_OBJECT, true);
objectMapper.configure(DeserializationFeature.EAGER_DESERIALIZER_FETCH, true);
objectMapper.configure(DeserializationFeature.ACCEPT_SINGLE_VALUE_AS_ARRAY, true);
objectMapper.configure(DeserializationFeature.USE_BIG_DECIMAL_FOR_FLOATS, true);
objectMapper.registerModule(new AfterburnerModule());
objectMapper.registerModule(new Jdk8Module());

this.bind(ObjectMapper.class).toInstance(objectMapper);
}
}
35 changes: 34 additions & 1 deletion core/src/main/java/io/sinistral/proteus/server/MediaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,14 @@
*/


import java.lang.reflect.Field;
import java.util.Arrays;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.function.Function;
import java.util.stream.Collectors;

public class MediaType
Expand Down Expand Up @@ -1210,6 +1215,11 @@ public static synchronized MediaType getByFileName(String filename)
}
}

public static synchronized MediaType getByMimeType(String type)
{
return Optional.ofNullable(getTypeMap().get(type)).orElse(MediaType.DEFAULT);
}

public String withCharset(String charset)
{
return charset != null ? String.format("%s; charset=%s", this.contentType, charset.toUpperCase()) : this.contentType;
Expand Down Expand Up @@ -1262,6 +1272,30 @@ public String toString()
return this.contentType;
}

private static final Map<String,MediaType> TYPE_MAP = new HashMap<>();

public static Map<String,MediaType> getTypeMap()
{
if(TYPE_MAP.size() == 0) {
Class<?> clazz = MediaType.class;

Field[] fields = clazz.getDeclaredFields();

Arrays.stream(fields).filter(f -> f.getType().equals(MediaType.class)).forEach( f -> {

try
{
MediaType mt = (MediaType)f.get(MediaType.class);
TYPE_MAP.put(mt.contentType,mt);
} catch( Exception e )
{
e.printStackTrace();
}
});
}

return TYPE_MAP;
}

@Override
public int hashCode()
Expand Down Expand Up @@ -1307,5 +1341,4 @@ public String info()

return toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
* @author jbauer
*
*/
public class ServerException extends Exception
public class ServerException extends RuntimeException
{
/**
*
Expand Down
7 changes: 6 additions & 1 deletion core/src/main/resources/reference.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ application {

defaultResponseListener = "io.sinistral.proteus.server.handlers.ServerDefaultResponseListener"

jacksonModule = "io.sinistral.proteus.modules.JacksonModule"

tmpdir = ${java.io.tmpdir}/${application.name}

# path to default favicon file
Expand Down Expand Up @@ -61,7 +63,6 @@ assets {

openapi {


basePath= ${application.path}"/openapi"

redocPath= "redoc"
Expand Down Expand Up @@ -93,6 +94,10 @@ openapi {
description="Default Server"
}
]

converterClasses = [

]
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package io.sinistral.proteus.swagger.test.controllers;
package io.sinistral.proteus.test.controllers;

import static io.sinistral.proteus.server.ServerResponse.response;

Expand Down Expand Up @@ -37,10 +37,9 @@
import com.google.inject.Singleton;

import io.sinistral.proteus.annotations.Blocking;
import io.sinistral.proteus.annotations.Debug;
import io.sinistral.proteus.server.ServerRequest;
import io.sinistral.proteus.server.ServerResponse;
import io.sinistral.proteus.swagger.test.models.User;
import io.sinistral.proteus.test.models.User;

import io.undertow.server.HttpServerExchange;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package io.sinistral.proteus.swagger.test.models;
package io.sinistral.proteus.test.models;


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/**
*
*/
package io.sinistral.proteus.swagger.test.server;
package io.sinistral.proteus.test.server;

import java.util.List;

import io.sinistral.proteus.swagger.test.controllers.Tests;
import io.sinistral.proteus.test.controllers.Tests;
import org.junit.runner.Description;
import org.junit.runner.Result;
import org.junit.runner.notification.RunListener;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/**
*
*/
package io.sinistral.proteus.swagger.test.server;
package io.sinistral.proteus.test.server;

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.containsString;
Expand Down Expand Up @@ -36,8 +36,8 @@
import com.fasterxml.jackson.databind.ObjectMapper;

import io.restassured.http.ContentType;
import io.sinistral.proteus.swagger.test.models.User;
import io.sinistral.proteus.swagger.test.models.User.UserType;
import io.sinistral.proteus.test.models.User;
import io.sinistral.proteus.test.models.User.UserType;

/*
* import static io.restassured.RestAssured.*; import static io.restassured.matcher.RestAssuredMatchers.*; import static org.hamcrest.Matchers.*;
Expand Down
2 changes: 2 additions & 0 deletions core/src/test/resources/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ application {

defaultResponseListener = "io.sinistral.proteus.server.handlers.ServerDefaultResponseListener"

jacksonModule = "io.sinistral.proteus.modules.JacksonModule"

tmpdir = ${java.io.tmpdir}/${application.name}

# path to default favicon file
Expand Down
6 changes: 1 addition & 5 deletions core/src/test/resources/logback-test.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,8 @@

<logger name="io.netty" level="ERROR" />
<logger name="io.netty.handler" level="ERROR" />
<logger name="io.sinistral.proteus.server.tools.openapi" level="ERROR" />
<logger name="io.sinistral.proteus.server.tools.swagger" level="ERROR" />
<logger name="io.sinistral.proteus.server.handlers" level="DEBUG" />
<logger name="io.sinistral.proteus.server.handlers" level="ERROR" />
<logger name="io.sinistral.proteus.services" level="ERROR" />
<logger name="io.sinistral.proteus.openapi" level="ERROR" />
<logger name="io.sinistral.proteus.swagger" level="ERROR" />

<logger name="com.sun.jersey" level="ERROR" />

Expand Down
12 changes: 10 additions & 2 deletions openapi/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
<directory>src/test/resources</directory>
</testResource>
<testResource>
<directory>src/test/java</directory>
<directory>src/test/java/sinistral/proteus/openapi</directory>
<excludes>
<exclude>**/*.java</exclude>
</excludes>
Expand Down Expand Up @@ -59,7 +59,7 @@
</plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.20.1</version>
<groupId>org.apache.maven.plugins</groupId>

</plugin>
<plugin>
Expand Down Expand Up @@ -109,6 +109,14 @@
<artifactId>swagger-integration</artifactId>
<version>${openapi.version}</version>
</dependency>

<dependency>
<groupId>org.zalando</groupId>
<artifactId>jackson-datatype-money</artifactId>
<version>1.1.1</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>proteus-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public Schema resolve(AnnotatedType annotatedType, ModelConverterContext context

if ((rawClass != null) &&!resolvedType.isPrimitive())
{
// log.debug("resolvedType in " + resolvedType);
if (rawClass.isAssignableFrom(ServerResponse.class))
{
resolvedType = classType.containedType(0);
Expand All @@ -69,14 +68,12 @@ else if (rawClass.isAssignableFrom(CompletableFuture.class))

if (futureCls.isAssignableFrom(ServerResponse.class))
{
// log.debug("class is assignable from ServerResponse");
final JavaType futureType = TypeFactory.defaultInstance().constructType(classType.containedType(0));

resolvedType = futureType.containedType(0);
}
else
{
// log.debug("class is NOT assignable from ServerResponse");
resolvedType = classType.containedType(0);
}
}
Expand Down Expand Up @@ -114,13 +111,11 @@ else if (resolvedType.getTypeName().contains("Optional"))

annotatedType.setType(resolvedType);

// log.debug("resolvedType out " + resolvedType);
}
}

try {

// log.info("Processing " + annotatedType + " " + classType + " " + annotatedType.getName());
return super.resolve(annotatedType, context, next);

} catch (Exception e) {
Expand Down
Loading

0 comments on commit 1e1d8ba

Please sign in to comment.