Skip to content

Commit

Permalink
Merge pull request #3 from noboomu/jackson
Browse files Browse the repository at this point in the history
Jackson
  • Loading branch information
noboomu authored Jul 18, 2018
2 parents 793f557 + 7c2cc52 commit 2f59835
Show file tree
Hide file tree
Showing 22 changed files with 730 additions and 180 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,4 @@ bin
.settings/org.scala-ide.sdt.core.prefs
.cache-tests
/proteus/
/pom.xml.versionsBackup
39 changes: 25 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@

![Alt logo](https://cdn.rawgit.com/noboomu/proteus/master/src/main/resources/io/sinistral/proteus/proteus-logo.svg)

* An extremely lightweight, flexible, and fast [Swagger](http://swagger.io/) first REST API framework atop [Undertow](http://undertow.io).
* An extremely lightweight, flexible, and fast [Swagger](http://swagger.io/) first MVC REST framework atop [Undertow](http://undertow.io).
* Inspired by: [Play](http://playframework.com), [Jooby](http://jooby.org), and [light-4j](https://github.com/networknt/light-4j).
* Verifiably [fast AF](https://www.techempower.com/benchmarks/previews/round15/#section=data-r15&hw=ph&test=db).
* Waaaaaaaay faster than Play and Spring, checkout the latest Techempower benchmarks.
* Verifiably [FAST AF](https://www.techempower.com/benchmarks/).
* [Latest benchmarks](https://www.techempower.com/benchmarks/) show Proteus at least 6x faster than Spring and Play across the board.

## Motivation

Expand Down Expand Up @@ -34,7 +34,7 @@ Prior to calling `start` on the `ProteusApplication` instance:

Out of the box you get a [Swagger UI](https://github.com/swagger-api/swagger-ui) at `/swagger` and [Redoc](https://github.com/Rebilly/ReDoc) at `/swagger/redoc`.

> A `Service` extends `com.google.common.util.concurrent.AbstractIdleService` or `io.sinistral.proteus.servicesBaseService`.
> A `Service` extends `com.google.common.util.concurrent.AbstractIdleService` or `io.sinistral.proteus.services.BaseService`.
> A `Module` implements `com.google.inject.Module`.
Expand Down Expand Up @@ -102,17 +102,20 @@ public class Examples
```


## Controller Classes
### Annotations
##### Class
# Controllers

### Controller Class Annotations
---
Controller classes respect standard Swagger / JAX-RS annotations:
```java
@Api(tags="benchmarks")
@Path("/benchmarks")
@Produces((MediaType.APPLICATION_JSON))
@Consumes((MediaType.MEDIA_TYPE_WILDCARD))
```
##### Method

### Controller Method Annotations
---
Controller class methods also respect standard Swagger / JAX-RS annotations:
```java
@GET
Expand All @@ -124,9 +127,10 @@ public void plaintext(HttpServerExchange exchange)
response("Hello, World!").contentType(PLAINTEXT_TYPE).send(exchange);
}
```
In addition, the `io.sinistral.proteus.annotations.Blocking` annotation can be used to explicitly mark a method for blocked request handling.

### Return Types

---
##### HttpServerExchange = Total Control

For total control and maximum performance the raw `HttpServerExchange` can be passed to the controller method.
Expand Down Expand Up @@ -198,6 +202,7 @@ public void handleRequest(final io.undertow.server.HttpServerExchange exchange)
```

### Arguments
---
A ```io.sinistral.proteus.server.ServerRequest``` can be added as an endpoint argument if the user wishes to access request properties that are not included in the argument list.

Proteus is capable of parsing most types of endpoint arguments automatically so long as the type has a ```fromString```, ```valueOf```, or can be deserialized from JSON.
Expand Down Expand Up @@ -243,9 +248,11 @@ public ServerResponse<Map<String,Object>> complexParameters(
return response(responseMap).applicationJson();
}
```
## Services
### Services
---
Proteus comes with two standard services that extend the ```io.sinistral.proteus.services.BaseService``` class.
##### AssetsService
#### AssetsService
---
The AssetsService mounts an asset directory at a given path and is configured in your ```application.conf``` file.

The default configuration:
Expand All @@ -261,7 +268,8 @@ assets {
}
}
```
##### SwaggerService
#### SwaggerService
---
The SwaggerService generates a swagger-spec file from your endpoints and serves a swagger-ui and spec.

The service is configured in your ```application.conf``` file.
Expand Down Expand Up @@ -294,13 +302,16 @@ swagger {
schemes = ["http"]
}
```

---
## Getting Started
COMING SOON


---

## Examples
COMING SOON

---

### Dependencies

Expand Down
6 changes: 3 additions & 3 deletions conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@
<logger name="io.netty" level="ERROR" />
<logger name="io.netty.handler" level="ERROR" />

<logger name="io.sinistral.proteus.server.swagger" level="INFO" />
<logger name="io.sinistral.proteus.server.handlers" level="INFO" />
<logger name="io.sinistral.proteus.services" level="INFO" />
<logger name="io.sinistral.proteus.server.swagger" level="ERROR" />
<logger name="io.sinistral.proteus.server.handlers" level="ERROR" />
<logger name="io.sinistral.proteus.services" level="ERROR" />

io.sinistral.proteus.services
<logger name="com.relayrides" level="ERROR" />
Expand Down
21 changes: 8 additions & 13 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>io.sinistral</groupId>
<artifactId>proteus-core</artifactId>
<version>0.1.9-SNAPSHOT</version>
<version>0.3.1-SNAPSHOT</version>
<name>proteus core</name>
<description>Proteus is an extremely light, fast, and flexible Java REST API framework built atop Undertow.</description>
<url>http://github.com/noboomu/proteus</url>
Expand Down Expand Up @@ -33,9 +33,9 @@
<maven.compiler.source>1.8</maven.compiler.source>
<maven.compiler.target>1.8</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<version.jackson>2.8.8.1</version.jackson>
<version.maven-shade-plugin>3.0.0</version.maven-shade-plugin>
<version.undertow>1.4.13.Final</version.undertow>
<version.jackson>2.9.6</version.jackson>
</properties>

<build>
Expand Down Expand Up @@ -247,35 +247,35 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.0</version>
<version>${version.jackson}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.10</version>
<version>${version.jackson}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.8.10</version>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-afterburner</artifactId>
<version>2.8.10</version>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>2.8.10</version>
<version>${version.jackson}</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.8.1</version>
<version>${version.jackson}</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
Expand Down Expand Up @@ -341,11 +341,6 @@
<artifactId>jansi</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>io.sinistral</groupId>
<artifactId>jsoniter</artifactId>
<version>0.9.9</version>
</dependency>
<dependency>
<groupId>org.reactivestreams</groupId>
<artifactId>reactive-streams</artifactId>
Expand Down
17 changes: 16 additions & 1 deletion src/main/java/io/sinistral/proteus/ProteusApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,24 @@ public void start()
return;
}

log.info("Configuring modules...");
log.info("Configuring modules: " + registeredModules);

Set<Module> modules = registeredModules.stream().map(mc -> injector.getInstance(mc)).collect(Collectors.toSet());

//boolean needsMappingModule = true;

// for(Module m : modules)
// {
// if(m.getClass().getSuperclass().equals(MappingModule.class))
// {
// needsMappingModule = false;
// }
// }
//
// if(needsMappingModule)
// {
// modules.add(injector.getInstance(MappingModule.class));
// }

injector = injector.createChildInjector(modules);

Expand Down
45 changes: 36 additions & 9 deletions src/main/java/io/sinistral/proteus/modules/ApplicationModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,20 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.fasterxml.jackson.datatype.jdk8.Jdk8Module;
import com.fasterxml.jackson.module.afterburner.AfterburnerModule;
import com.google.common.util.concurrent.Service;
import com.google.inject.AbstractModule;
import com.google.inject.Singleton;
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.jsoniter.DecodingMode;
import com.jsoniter.JsonIterator;
import com.jsoniter.annotation.JsoniterAnnotationSupport;
import com.jsoniter.output.EncodingMode;
import com.jsoniter.output.JsonStream;
import com.typesafe.config.Config;

import io.sinistral.proteus.server.Extractors;
import io.sinistral.proteus.server.ServerResponse;
import io.sinistral.proteus.server.endpoints.EndpointInfo;
import io.undertow.server.DefaultResponseListener;
import io.undertow.server.HandlerWrapper;
Expand Down Expand Up @@ -102,12 +103,38 @@ protected void configure()
{
}).annotatedWith(Names.named("registeredHandlerWrappers")).toInstance(registeredHandlerWrappers);

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

this.bindMappers();

JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH);
JsonStream.setMode(EncodingMode.DYNAMIC_MODE);
JsoniterAnnotationSupport.enable();
}

/**
* Override for customizing XmlMapper and ObjectMapper
*/
public void bindMappers()
{
this.bind(XmlMapper.class).toInstance(new XmlMapper());

// JsonIterator.setMode(DecodingMode.DYNAMIC_MODE_AND_MATCH_FIELD_WITH_HASH);
// JsonStream.setMode(EncodingMode.DYNAMIC_MODE);
// JsoniterAnnotationSupport.enable();

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);

this.requestStaticInjection(Extractors.class);

this.requestStaticInjection(ServerResponse.class);
}

}
Loading

0 comments on commit 2f59835

Please sign in to comment.