Skip to content

Commit

Permalink
Added more dependencies. Renamed endpointInfo. Added bytes benchmark.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Apr 10, 2017
1 parent 6d30450 commit d69097b
Show file tree
Hide file tree
Showing 8 changed files with 239 additions and 44 deletions.
24 changes: 17 additions & 7 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,19 +30,19 @@
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-annotations</artifactId>
<version>2.8.7</version>
<version>[2.8.7,)</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-core</artifactId>
<version>2.8.7</version>
<version>[2.8.7,)</version>
</dependency>

<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.8.7</version>
<version>[2.8.7,)</version>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
Expand Down Expand Up @@ -80,7 +80,7 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>3.6.0</version>
<version>[3.6.0,)</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
Expand All @@ -90,7 +90,7 @@
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okcurl</artifactId>
<version>3.6.0</version>
<version>[3.6.0,)</version>
</dependency>
<dependency>
<groupId>com.squareup.retrofit2</groupId>
Expand Down Expand Up @@ -135,12 +135,12 @@
<dependency>
<groupId>com.fasterxml.jackson.module</groupId>
<artifactId>jackson-module-afterburner</artifactId>
<version>2.8.7</version>
<version>[2.8.7,)</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jdk8</artifactId>
<version>2.8.7</version>
<version>[2.8.7,)</version>
</dependency>
<dependency>
<groupId>org.glassfish.jersey</groupId>
Expand Down Expand Up @@ -226,5 +226,15 @@
<artifactId>jansi</artifactId>
<version>1.15</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.4.1.Final</version>
</dependency>
<dependency>
<groupId>com.graphql-java</groupId>
<artifactId>graphql-java</artifactId>
<version>2.3.0</version>
</dependency>
</dependencies>
</project>
4 changes: 2 additions & 2 deletions src/main/java/com/wurrly/Application.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
import com.wurrly.controllers.Users;
import com.wurrly.modules.ConfigModule;
import com.wurrly.modules.RoutingModule;
import com.wurrly.server.endpoints.EndpointInfo;
import com.wurrly.server.handlers.HandlerGenerator;
import com.wurrly.server.handlers.benchmark.BenchmarkHandlers;
import com.wurrly.server.route.RouteInfo;
import com.wurrly.services.SwaggerService;

import io.undertow.Undertow;
Expand Down Expand Up @@ -133,7 +133,7 @@ public Undertow buildServer()

StringBuilder sb = new StringBuilder();

Set<RouteInfo> routingInfo = routingModule.getRegisteredRoutes(); //injector.getInstance(Key.get(new TypeLiteral<Set<RouteInfo>>() {},Names.named("routeInfo")));
Set<EndpointInfo> routingInfo = routingModule.getRegisteredEndpoints(); //injector.getInstance(Key.get(new TypeLiteral<Set<RouteInfo>>() {},Names.named("routeInfo")));

routingInfo.stream().forEachOrdered( r -> sb.append(r.toString()).append("\n"));

Expand Down
10 changes: 5 additions & 5 deletions src/main/java/com/wurrly/modules/RoutingModule.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import com.google.inject.TypeLiteral;
import com.google.inject.name.Names;
import com.wurrly.Application.BaseHandlers;
import com.wurrly.server.route.RouteInfo;
import com.wurrly.server.endpoints.EndpointInfo;

import io.undertow.server.RoutingHandler;

Expand All @@ -30,7 +30,7 @@ public class RoutingModule extends AbstractModule
{
private static Logger log = LoggerFactory.getLogger(RoutingModule.class.getCanonicalName());

protected Set<RouteInfo> registeredRoutes = new TreeSet<>();
protected Set<EndpointInfo> registeredEndpoints = new TreeSet<>();
protected Set<Class<?>> registeredControllers = new HashSet<>();

@Override
Expand All @@ -47,11 +47,11 @@ protected void configure()
}

/**
* @return the registeredRoutes
* @return the registeredEndpoints
*/
public Set<RouteInfo> getRegisteredRoutes()
public Set<EndpointInfo> getRegisteredEndpoints()
{
return registeredRoutes;
return registeredEndpoints;
}

/**
Expand Down
180 changes: 168 additions & 12 deletions src/main/java/com/wurrly/server/ServerResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,14 @@
import java.util.HashMap;
import java.util.Map;

import io.undertow.io.IoCallback;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
import io.undertow.server.handlers.Cookie;
import io.undertow.util.HeaderMap;
import io.undertow.util.HeaderValues;
import io.undertow.util.Headers;
import io.undertow.util.HttpString;
import io.undertow.util.StatusCodes;

/**
Expand All @@ -18,36 +23,187 @@
*/
public class ServerResponse
{
private ByteBuffer buffer;
private int status = StatusCodes.OK;
private HeaderMap headers = new HeaderMap();
private Map<String,Cookie> cookies = new HashMap<>();
private ByteBuffer body;

private int status = -1;
private final HeaderMap headers = new HeaderMap();
private final Map<String,Cookie> cookies = new HashMap<>();
private String contentType;
private IoCallback callback;

public ServerResponse()
{

}


public ByteBuffer buffer()
{
return this.buffer;
public ByteBuffer getBody()
{
return body;
}

public int status()
public int getStatus()
{
return this.status;
}

public Map<String,Cookie> cookies()
public Map<String,Cookie> getCookies()
{
return this.cookies;
}

public HeaderMap headers()
public HeaderMap getHeaders()
{
return this.headers;
}

/**
* @return the contentType
*/
public String getContentType()
{
return contentType;
}

/**
* @return the callback
*/
public IoCallback getCallback()
{
return callback;
}

/**
* @param callback the callback to set
*/
public void setCallback(IoCallback callback)
{
this.callback = callback;
}

/**
* @param body the body to set
*/
public void setBody(ByteBuffer body)
{
this.body = body;
}

/**
* @param status the status to set
*/
public void setStatus(int status)
{
this.status = status;
}

/**
* @param contentType the contentType to set
*/
public void setContentType(String contentType)
{
this.contentType = contentType;
}

public void send( final HttpHandler currentHandler, final HttpServerExchange exchange )
{
long itr = this.headers.fastIterateNonEmpty();

while( itr != -1L )
{
final HeaderValues values = this.headers.fiCurrent(itr);

exchange.getResponseHeaders().putAll(values.getHeaderName(), values);

this.headers.fiNextNonEmpty(itr);
}

exchange.getResponseCookies().putAll(this.cookies);

exchange.setStatusCode( this.status != -1 ? this.status : StatusCodes.ACCEPTED);

exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, this.contentType);

if( this.callback != null )
{
exchange.getResponseSender().send(this.body,this.callback);
}
else
{
exchange.getResponseSender().send(this.body);
}

}

/**
* Creates builder to build {@link ServerResponse}.
* @return created builder
*/
public static Builder builder()
{
return new Builder();
}

/**
* Builder to build {@link ServerResponse}.
*/
public static final class Builder
{
private ServerResponse response = new ServerResponse();

private Builder()
{
}

public Builder withBody(ByteBuffer body)
{
this.response.body = body;
return this;
}

public Builder withBody(String body)
{
this.response.body = ByteBuffer.wrap(body.getBytes());
return this;
}


public Builder withStatus(int status)
{
this.response.status = status;
return this;
}

public Builder withHeader(HttpString headerName, String value)
{
this.response.headers.put(headerName, value);
return this;
}

public Builder withCookie(String cookieName, Cookie cookie)
{
this.response.getCookies().put(cookieName, cookie);
return this;
}

public Builder withContentType(String contentType)
{
this.response.contentType = contentType;
return this;
}

public Builder withCallback(IoCallback callback)
{
this.response.callback = callback;
return this;
}

public ServerResponse build()
{
return this.response;
}
}




}
Loading

0 comments on commit d69097b

Please sign in to comment.