Skip to content

Commit

Permalink
Revert to earlier Undertow.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Sep 20, 2017
1 parent c1f5426 commit 5fbe8fe
Show file tree
Hide file tree
Showing 15 changed files with 269 additions and 57 deletions.
6 changes: 3 additions & 3 deletions conf/application.conf
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ swagger {
undertow
{
server {
enableHttp2 = true
enableHttp2 = false
alwaysSetDate = true
alwaysSetKeepAlive = false
recordRequestStartTime = false
Expand All @@ -100,14 +100,14 @@ undertow


ssl {
enabled=true
enabled=false
keystorePath="development.jks"
truststorePath="development.ts"
keystorePassword="password"
truststorePassword="password"
}

enableHttp2=true
enableHttp2=false
# x AvailableProcessors
ioThreads = 16
workerThreads = 200
Expand Down
117 changes: 117 additions & 0 deletions conf/logback-test.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
<configuration packagingData="true" debug="true">

<turboFilter class="ch.qos.logback.classic.turbo.DuplicateMessageFilter" />

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<withJansi>true</withJansi>
<encoder>
<pattern>%date{ISO8601} %highlight(%-5level) [%boldCyan(%logger)]
[%boldYellow(%method %F) ] - %boldWhite(%message) %n %red(%ex)
</pattern>
</encoder>
</appender>

<logger name="org.apache.http" level="DEBUG" />


<logger name="javax.mail" level="DEBUG" />
<logger name="com.squareup.okhttp" level="WARN" />
<logger name="javax.activation" level="DEBUG" />

<logger name="io.netty" level="DEBUG" />
<logger name="io.netty.handler" level="DEBUG" />

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

io.sinistral.proteus.services
<logger name="com.relayrides" level="DEBUG" />
<logger name="org.apache.activemq" level="DEBUG" />
<logger name="org.apache.camel" level="DEBUG" />
<logger name="org.apache.activemq" level="DEBUG" />
<logger name="sun.net" level="DEBUG" />
<logger name="org.springsource" level="DEBUG" />
<logger name="com.sun.jersey" level="DEBUG" />


<logger name="org.xnio.nio" level="DEBUG" />
<logger name="io.undertow" level="DEBUG" />


<logger name="org.reflections" level="OFF" />
<logger name="org.elasticsearch" level="DEBUG" />
<logger name="org.ajave.ebean" level="DEBUG" />

<logger name="org.avaje.ebean.SQL" level="DEBUG" />
<logger name="org.avaje.ebean.SUM" level="DEBUG" />
<logger name="org.avaje.ebean.TXN" level="DEBUG" />
<logger name="com.avaje.ebeaninternal" level="DEBUG" />
<logger name="org.avaje.ebean.cache.BEAN" level="DEBUG" />

<logger name="io.swagger.converter" level="DEBUG" />
<logger name="io.swagger.jackson" level="DEBUG" />


<logger name="com.avaje.ebean.config.PropertyMapLoader" level="DEBUG" />
<logger name="com.avaje.ebeaninternal.server.core.XmlConfigLoader"
level="DEBUG" />
<logger name="com.avaje.ebeaninternal.server.lib.BackgroundThread"
level="DEBUG" />

<logger name="com.gargoylesoftware.htmlunit.javascript" level="OFF" />
<logger name="swagger" level="DEBUG" />
<logger name="com.zaxxer.hikari" level="DEBUG" />
<logger name="com.zaxxer.hikari.pool" level="DEBUG" />
<logger name="javax.management" level="DEBUG" />
<logger name="javax.management.mbeanserver" level="OFF" />
<logger name="java.jmx" level="DEBUG" />

<logger name="net.sf.ehcache" level="DEBUG" />

<logger name="org.apache.http" level="DEBUG" />
<logger name="com.amazonaws" level="DEBUG" />
<logger name="org.apache.http.wire" level="DEBUG" />

<logger name="com.wordnik" level="OFF" />

<logger name="javax.mail" level="DEBUG" />
<logger name="com.squareup.okhttp" level="WARN" />

<logger name="org.hibernate.validator" level="DEBUG" />
<logger name="org.xnio.nio" level="DEBUG" />


<logger name="org.apache.camel" level="DEBUG" />
<logger name="org.apache.activemq" level="DEBUG" />
<logger name="sun.net" level="DEBUG" />
<logger name="org.springsource" level="DEBUG" />
<logger name="com.sun.jersey" level="DEBUG" />
<logger name="akka.event.EventStream" level="DEBUG" />
<logger name="akka.event.slf4j" level="DEBUG" />
<logger name="com.googlecode.mp4parser" level="DEBUG" />
<logger name="com.googlecode.mp4parser.util" level="DEBUG" />

<logger name="org.elasticsearch.plugins" level="DEBUG" />

<logger name="org.apache.commons.logging.impl.Jdk14Logger"
level="DEBUG" />
<logger name="org.zeroturnaround.exec.ProcessExecutor" level="DEBUG" />
<logger name="org.zeroturnaround.exec" level="DEBUG" />

<!-- <logger name="com.datastax.driver.core.QueryLogger.NORMAL" level="trace"
/> -->

<logger name="org.apache.kafka.clients.NetworkClient" level="DEBUG" />
<logger name="org.apache.kafka.clients.producer" level="DEBUG" />


<logger name="java.util.logging.Logger" level="DEBUG" />
<logger name="com.google.inject.internal" level="DEBUG" />
<logger name="com.google.inject" level="DEBUG" />
<logger name="com.datastax" level="DEBUG" />

<root level="debug">
<appender-ref ref="STDOUT" />
</root>
</configuration>
34 changes: 22 additions & 12 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.3-SNAPSHOT</version>
<version>0.1.6-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 All @@ -29,9 +29,14 @@
<url>http://github.com/noboomu/proteus/tree/master</url>
</scm>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<properties>
<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.2.5.Final</version.undertow>
</properties>

<build>
<resources>
Expand Down Expand Up @@ -182,7 +187,7 @@
<dependency>
<groupId>io.undertow</groupId>
<artifactId>undertow-core</artifactId>
<version>1.4.14.Final</version>
<version>${version.undertow}</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey</groupId>
Expand Down Expand Up @@ -225,35 +230,35 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.7</version>
<version>2.8.0</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.7</version>
<version>2.8.10</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.8.8</version>
<version>2.8.10</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-afterburner</artifactId>
<version>2.8.7</version>
<version>2.8.10</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>2.8.7</version>
<version>2.8.10</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.7</version>
<version>2.8.8.1</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
Expand Down Expand Up @@ -324,6 +329,11 @@
<artifactId>jsoniter</artifactId>
<version>0.9.9</version>
</dependency>
<dependency>
<groupId>org.reactivestreams</groupId>
<artifactId>reactive-streams</artifactId>
<version>1.0.0.final</version>
</dependency>
</dependencies>
<distributionManagement>
<snapshotRepository>
Expand All @@ -337,4 +347,4 @@
<downloadUrl>https://oss.sonatype.org/content/groups/public/io/sinistral/proteus-core</downloadUrl>
</distributionManagement>

</project>
</project>
24 changes: 12 additions & 12 deletions src/main/java/io/sinistral/proteus/ProteusApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,19 +38,12 @@
import com.google.inject.Injector;
import com.google.inject.Module;
import com.google.inject.name.Named;
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.modules.ConfigModule;
import io.sinistral.proteus.server.endpoints.EndpointInfo;
import io.sinistral.proteus.server.handlers.ServerDefaultHttpHandler;
import io.sinistral.proteus.server.handlers.HandlerGenerator;
import io.sinistral.proteus.services.AssetsService;
import io.sinistral.proteus.services.SwaggerService;
import io.sinistral.proteus.server.handlers.ServerDefaultHttpHandler;
import io.sinistral.proteus.utilities.SecurityOps;
import io.undertow.Undertow;
import io.undertow.UndertowOptions;
Expand Down Expand Up @@ -250,10 +243,17 @@ public void buildServer()
handler = rootHandler;
}

Undertow.Builder undertowBuilder = Undertow.builder().addHttpListener(config.getInt("application.ports.http"), config.getString("application.host")).setBufferSize(16 * 1024).setIoThreads(config.getInt("undertow.ioThreads"))
.setServerOption(UndertowOptions.ENABLE_HTTP2, config.getBoolean("undertow.enableHttp2")).setServerOption(UndertowOptions.ALWAYS_SET_DATE, true).setSocketOption(org.xnio.Options.BACKLOG, config.getInt("undertow.socket.backlog"))
.setServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, false).setServerOption(UndertowOptions.RECORD_REQUEST_START_TIME, false).setServerOption(UndertowOptions.MAX_ENTITY_SIZE, config.getBytes("undertow.server.maxEntitySize"))
.setWorkerThreads(config.getInt("undertow.workerThreads")).setHandler(handler);
Undertow.Builder undertowBuilder = Undertow.builder().addHttpListener(config.getInt("application.ports.http"), config.getString("application.host"))
.setBufferSize(16 * 1024)
.setIoThreads(config.getInt("undertow.ioThreads"))
.setServerOption(UndertowOptions.ENABLE_HTTP2, config.getBoolean("undertow.enableHttp2"))
.setServerOption(UndertowOptions.ALWAYS_SET_DATE, true)
.setSocketOption(org.xnio.Options.BACKLOG, config.getInt("undertow.socket.backlog"))
.setServerOption(UndertowOptions.ALWAYS_SET_KEEP_ALIVE, false)
.setServerOption(UndertowOptions.RECORD_REQUEST_START_TIME, false)
.setServerOption(UndertowOptions.MAX_ENTITY_SIZE, config.getBytes("undertow.server.maxEntitySize"))
.setWorkerThreads(config.getInt("undertow.workerThreads"))
.setHandler(handler);

ports.add(config.getInt("application.ports.http"));

Expand Down
23 changes: 23 additions & 0 deletions src/main/java/io/sinistral/proteus/annotations/Blocking.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/**
*
*/
package io.sinistral.proteus.annotations;

import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.ElementType.TYPE;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

import java.lang.annotation.Retention;
import java.lang.annotation.Target;

/**
* Indicates that this route should use a BlockingHandler
*/
@Retention(RUNTIME)
@Target({ TYPE, METHOD })
public @interface Blocking
{
boolean value() default true;
}


4 changes: 2 additions & 2 deletions src/main/java/io/sinistral/proteus/server/Extractors.java
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ public static java.util.Optional<String> string(final HttpServerExchange exchan

public static java.util.Optional<Path> filePath(final HttpServerExchange exchange, final String name)
{
return java.util.Optional.ofNullable(exchange.getAttachment(FormDataParser.FORM_DATA).get(name)).map(Deque::getFirst).map(FormValue::getPath);
return java.util.Optional.ofNullable(exchange.getAttachment(FormDataParser.FORM_DATA).get(name)).map(Deque::getFirst).map( fv -> fv.getFile().toPath());
}

public static java.util.Optional<ByteBuffer> byteBuffer(final HttpServerExchange exchange, final String name)
Expand Down Expand Up @@ -344,7 +344,7 @@ public static Path filePath(final HttpServerExchange exchange, final String nam
{
try
{
return exchange.getAttachment(FormDataParser.FORM_DATA).get(name).getFirst().getPath();
return exchange.getAttachment(FormDataParser.FORM_DATA).get(name).getFirst().getFile().toPath();
} catch(NullPointerException e)
{
throw new IllegalArgumentException("Missing parameter " + name, e);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/sinistral/proteus/server/ServerRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
import java.util.Map;
import java.util.concurrent.Executor;

import org.xnio.Pooled;
import org.xnio.channels.StreamSourceChannel;

import io.sinistral.proteus.server.predicates.ServerPredicates;
import io.undertow.connector.PooledByteBuffer;
import io.undertow.security.api.SecurityContext;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.handlers.form.FormData;
Expand Down Expand Up @@ -143,8 +143,8 @@ private void extractBytes() throws IOException

this.exchange.startBlocking();

try (PooledByteBuffer pooled = exchange.getConnection().getByteBufferPool().getArrayBackedPool().allocate()){
ByteBuffer buf = pooled.getBuffer();
try (Pooled<ByteBuffer> pooled = exchange.getConnection().getBufferPool().allocate()){
ByteBuffer buf = pooled.getResource();

final StreamSourceChannel channel = this.exchange.getRequestChannel();

Expand Down Expand Up @@ -181,7 +181,7 @@ private void parseMultipartForm() throws IOException

this.exchange.startBlocking();
final FormDataParser formDataParser = new MultiPartParserDefinition()
.setTempFileLocation(new File(TMP_DIR).toPath())
.setTempFileLocation(new File(TMP_DIR))
.setDefaultEncoding(CHARSET)
.create(this.exchange);

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/io/sinistral/proteus/server/ServerResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.jsoniter.output.JsonContext;
import com.jsoniter.output.JsonStream;

import io.sinistral.proteus.server.handlers.ServerDefaultResponseListener;
import io.sinistral.proteus.server.predicates.ServerPredicates;
import io.undertow.io.IoCallback;
import io.undertow.server.DefaultResponseListener;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.handlers.Cookie;
Expand Down Expand Up @@ -336,7 +335,7 @@ public void send(final HttpHandler handler, final HttpServerExchange exchange) t
exchange.getResponseCookies().putAll(this.cookies);
}

exchange.setStatusCode(this.status);
exchange.setResponseCode(this.status);

if (this.contentType != null)
{
Expand All @@ -358,7 +357,7 @@ else if (ServerPredicates.ACCEPT_XML_PREDICATE.resolve(exchange))

if (hasError)
{
exchange.putAttachment(DefaultResponseListener.EXCEPTION, throwable);
exchange.putAttachment(ServerDefaultResponseListener.EXCEPTION, throwable);

return;
}
Expand Down
Loading

0 comments on commit 5fbe8fe

Please sign in to comment.