Skip to content

Commit

Permalink
A lot more cleanup. Experimented with Rocker. Cleaned up references to
Browse files Browse the repository at this point in the history
JsonMapper.
  • Loading branch information
noboomu committed Apr 28, 2017
1 parent d9f4cb3 commit c1259bf
Show file tree
Hide file tree
Showing 6 changed files with 95 additions and 44 deletions.
10 changes: 4 additions & 6 deletions conf/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,11 @@
<logger name="io.netty" level="ERROR" />
<logger name="io.netty.handler" level="ERROR" />

<logger name="io.sinistral.proteus.server.swagger" level="DEBUG" />
<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" />

io.sinistral.proteus.services
<logger name="com.relayrides" level="ERROR" />
<logger name="org.apache.activemq" level="ERROR" />
<logger name="org.apache.camel" level="ERROR" />
Expand Down Expand Up @@ -98,11 +100,7 @@

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

<logger name="com.wurrly.controllers" level="DEBUG" />
<logger name="com.wurrly.service" level="DEBUG" />
<logger name="com.wurrly.models" level="DEBUG" />
<logger name="com.wurrly.protocol.Serializers" level="ERROR" />


<logger name="java.util.logging.Logger" level="ERROR" />
<logger name="com.google.inject.internal" level="ERROR" />
Expand Down
68 changes: 54 additions & 14 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,26 @@
<goal>testCompile</goal>
</goals>
</pluginExecutionFilter>

<action>
<ignore />
<execute />
</action>
</pluginExecution>
<!-- <pluginExecution>
<pluginExecutionFilter>
<groupId>com.fizzed</groupId>
<artifactId>rocker-maven-plugin</artifactId>
<versionRange>[${rocker.version},)</versionRange>
<goals>
<goal>generate</goal>
</goals>
</pluginExecutionFilter>
<action>
<execute>
<runOnIncremental>true</runOnIncremental>
</execute>
</action>
</pluginExecution> -->
</pluginExecutions>
</lifecycleMappingMetadata>
</configuration>
Expand Down Expand Up @@ -77,7 +93,6 @@
<version>1.6.0</version>
<executions>
<execution>

<goals>
<goal>exec</goal>
</goals>
Expand Down Expand Up @@ -124,30 +139,44 @@
<addClasspath>true</addClasspath>
<classpathPrefix>lib/</classpathPrefix>
<mainClass>io.sinistral.proteus.Application</mainClass>

</manifest>
</archive>
</configuration>
</plugin>
<!-- <plugin>
<groupId>com.fizzed</groupId>
<artifactId>rocker-maven-plugin</artifactId>
<version>0.18.0</version>
<executions>
<execution>
<id>generate-rocker-templates</id>
<phase>generate-sources</phase>
<goals>
<goal>generate</goal>
</goals>
</execution>
</executions>
</plugin> -->
</plugins>
</build>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.2</version>
<scope>test</scope>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.12</version>
</dependency>
<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.2</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mortbay.jetty.alpn</groupId>
<artifactId>alpn-boot</artifactId>
<version>8.1.11.v20170118</version>
<scope>runtime</scope>
<scope>runtime</scope>
</dependency>

<dependency>
Expand Down Expand Up @@ -340,13 +369,24 @@
<dependency>
<groupId>io.sinistral</groupId>
<artifactId>jsoniter</artifactId>
<version>0.9.8</version>
<version>0.9.9-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>com.github.javaparser</groupId>
<artifactId>javaparser-core</artifactId>
<version>[3.2.0,)</version>
</dependency>
<!-- <dependency>
<groupId>com.fizzed</groupId>
<artifactId>rocker-runtime</artifactId>
<version>0.18.0</version>
</dependency>
<dependency>
<groupId>com.fizzed</groupId>
<artifactId>rocker-compiler</artifactId>
<version>0.18.0</version>
<scope>provided</scope>
</dependency> -->
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
Expand Down
13 changes: 11 additions & 2 deletions src/main/java/io/sinistral/proteus/controllers/Benchmarks.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,30 @@

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

import java.io.ByteArrayOutputStream;
import java.io.OutputStream;
import java.nio.ByteBuffer;

import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.xnio.channels.Channels;
import org.xnio.conduits.StreamSinkConduit;

import com.google.common.collect.ImmutableMap;
import com.google.inject.Singleton;
import com.jsoniter.output.JsonStream;

import io.sinistral.proteus.models.User;
import io.sinistral.proteus.models.World;
import io.sinistral.proteus.server.ServerResponse;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.undertow.io.UndertowOutputStream;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.protocol.http.HttpServerConnection;
import io.undertow.util.Headers;

/**
* @author jbauer
Expand Down Expand Up @@ -52,6 +59,8 @@ public void json2(HttpServerExchange exchange)
response( JsonStream.serializeToBytes(ImmutableMap.of("message", "Hello, World!")) ).applicationJson().send(exchange);
}



@GET
@Path("/world")
@ApiOperation(value = "World serialization endpoint", httpMethod = "GET", response = World.class )
Expand Down
20 changes: 5 additions & 15 deletions src/main/java/io/sinistral/proteus/server/ServerResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,22 @@
*/
package io.sinistral.proteus.server;

import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.channels.Channels;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.dataformat.xml.XmlMapper;
import com.jsoniter.any.Any;
import com.jsoniter.output.JsonContext;
import com.jsoniter.output.JsonStream;
import com.jsoniter.spi.Encoder;

import io.sinistral.proteus.server.predicates.ServerPredicates;
import io.undertow.attribute.ExchangeAttributes;
import io.undertow.io.AsyncSenderImpl;
import io.undertow.io.IoCallback;
import io.undertow.predicate.Predicate;
import io.undertow.predicate.Predicates;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.handlers.Cookie;
Expand Down Expand Up @@ -378,16 +376,8 @@ else if (hasEntity)
}
else
{
try
{
exchange.getResponseSender().send(JsonStream.serialize(this.entity, this.jsonContext));
} catch (Exception e)
{
log.error(e.getMessage() + " for entity " + this.entity, e);

throw new IllegalArgumentException(e);
}


exchange.getResponseSender().send(JsonStream.serializeToBytes(this.entity, this.jsonContext));
}

} catch (Exception e)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import java.lang.reflect.Type;
import java.net.URI;
import java.net.URL;
import java.net.URLClassLoader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
Expand Down Expand Up @@ -511,7 +510,7 @@ public Class<? extends Supplier<RoutingHandler>> compileClass()
this.generateRoutes();


log.info("\n\nGenerated Class Source:\n\n" + this.sourceString);
log.debug("\n\nGenerated Class Source:\n\n" + this.sourceString);

// CompilerUtils.addClassPath("./lib");
return CompilerUtils.CACHED_COMPILER.loadFromJava(packageName + "." + className, this.sourceString);
Expand Down
25 changes: 20 additions & 5 deletions src/main/java/io/sinistral/proteus/services/SwaggerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.ObjectWriter;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.google.inject.Inject;
import com.google.inject.name.Named;
import com.mitchellbosecke.pebble.PebbleEngine;
Expand All @@ -41,14 +44,12 @@

public class SwaggerService extends BaseService implements Supplier<RoutingHandler>
{




private static Logger log = LoggerFactory.getLogger(SwaggerService.class.getCanonicalName());

protected io.sinistral.proteus.server.swagger.Reader reader = null;

protected String swaggerResourcePath = "./swagger";
protected final String swaggerResourcePath = "./swagger";

protected final String swaggerThemesPath = "./swagger/themes";

Expand Down Expand Up @@ -158,8 +159,20 @@ public void generateSwaggerSpec()

this.swagger = this.reader.getSwagger();

this.swaggerSpec = JsonMapper.toPrettyJSON(this.swagger);
ObjectMapper mapper = new ObjectMapper();
ObjectWriter writer = mapper.writerWithDefaultPrettyPrinter();
writer.without(SerializationFeature.WRITE_NULL_MAP_VALUES);

try
{

this.swaggerSpec = writer.writeValueAsString(this.swagger);

} catch (Exception e)
{
log.error(e.getMessage(),e);
}


}

Expand All @@ -186,6 +199,8 @@ public void generateSwaggerHTML()
{
try
{


PebbleEngine engine = new PebbleEngine.Builder().build();

PebbleTemplate compiledTemplate = engine.getTemplate("swagger/index.html");
Expand Down

0 comments on commit c1259bf

Please sign in to comment.