Skip to content

Commit

Permalink
Minor improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
noboomu committed Feb 22, 2018
1 parent 6d5a852 commit 445adb3
Show file tree
Hide file tree
Showing 9 changed files with 59 additions and 9 deletions.
Binary file removed assets/video.mp4
Binary file not shown.
2 changes: 1 addition & 1 deletion 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.7.3-SNAPSHOT</version>
<version>0.1.8-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
9 changes: 7 additions & 2 deletions src/main/java/io/sinistral/proteus/ProteusApplication.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ public void run()
shutdown();
} catch (TimeoutException timeout)
{
timeout.printStackTrace();
log.error(timeout.getMessage(),timeout);
}
}
});
Expand All @@ -209,7 +209,12 @@ public void shutdown() throws TimeoutException

log.info("Shutting down...");

serviceManager.stopAsync().awaitStopped(8, TimeUnit.SECONDS);
try {
serviceManager.stopAsync().awaitStopped(1, TimeUnit.SECONDS);

} catch (TimeoutException timeout) {
log.warn("Failed to shutdown within specified timeout.");
}

log.info("Shutdown complete.");
}
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/io/sinistral/proteus/server/MediaType.java
Original file line number Diff line number Diff line change
Expand Up @@ -1232,6 +1232,10 @@ private String join(String name, String[] attributes) {
public byte[] getBytes() {
return bytes;
}

public String contentType() {
return this.contentType;
}

@Override
public String toString() {
Expand Down
15 changes: 14 additions & 1 deletion src/main/java/io/sinistral/proteus/server/ServerRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ public class ServerRequest
protected FormData form;
protected final String contentType;
protected final String method;

protected final String accept;



public ServerRequest()
Expand All @@ -53,6 +54,7 @@ public ServerRequest()
this.path = null;
this.exchange = null;
this.contentType = null;
this.accept = null;

}

Expand All @@ -62,6 +64,7 @@ public ServerRequest(HttpServerExchange exchange) throws IOException
this.path = exchange.getRequestPath();
this.exchange = exchange;
this.contentType = exchange.getRequestHeaders().getFirst(Headers.CONTENT_TYPE);
this.accept = exchange.getRequestHeaders().getFirst(Headers.ACCEPT);

if (this.contentType != null )
{
Expand Down Expand Up @@ -231,6 +234,16 @@ public String method()
{
return this.method;
}

public String accept()
{
return this.accept;
}

public String contentType()
{
return this.contentType;
}

public String path()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@
import io.sinistral.proteus.server.ServerResponse;
import io.sinistral.proteus.server.endpoints.EndpointInfo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.undertow.server.HandlerWrapper;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
Expand Down Expand Up @@ -624,13 +625,13 @@ protected void addClassMethodHandlers(TypeSpec.Builder typeBuilder, Class<?> cla

MethodSpec.Builder initBuilder = MethodSpec.methodBuilder("get").addModifiers(Modifier.PUBLIC).returns(RoutingHandler.class).addStatement("final $T router = new $T()", io.undertow.server.RoutingHandler.class, io.undertow.server.RoutingHandler.class);

final Map<Type, String> parameterizedLiteralsNameMap = Arrays.stream(clazz.getDeclaredMethods()).flatMap(m -> Arrays.stream(m.getParameters()).map(Parameter::getParameterizedType).filter(t -> t.getTypeName().contains("<") && !t.getTypeName().contains("concurrent")))
final Map<Type, String> parameterizedLiteralsNameMap = Arrays.stream(clazz.getDeclaredMethods()).filter( m -> m.getAnnotation(ApiOperation.class) != null).flatMap(m -> Arrays.stream(m.getParameters()).map(Parameter::getParameterizedType).filter(t -> t.getTypeName().contains("<") && !t.getTypeName().contains("concurrent")))
.distinct().filter(t -> {
TypeHandler handler = TypeHandler.forType(t);
return (handler.equals(TypeHandler.ModelType) || handler.equals(TypeHandler.OptionalModelType));
}).collect(Collectors.toMap(java.util.function.Function.identity(), HandlerGenerator::typeLiteralNameForParameterizedType));

final Map<Type, String> literalsNameMap = Arrays.stream(clazz.getDeclaredMethods()).flatMap(m -> Arrays.stream(m.getParameters()).map(Parameter::getParameterizedType)).filter(t -> {
final Map<Type, String> literalsNameMap = Arrays.stream(clazz.getDeclaredMethods()).filter( m -> m.getAnnotation(ApiOperation.class) != null).flatMap(m -> Arrays.stream(m.getParameters()).map(Parameter::getParameterizedType)).filter(t -> {

if (t.getTypeName().contains("java.util"))
{
Expand Down
5 changes: 5 additions & 0 deletions src/main/java/io/sinistral/proteus/server/swagger/Reader.java
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,11 @@ private Operation parseMethod(Class<?> cls, Method method, AnnotatedMethod annot
}
}
}

/*
* @TODO
* Use apiOperation response class instead of unwrapping ServerResponse's inner type
*/

if (apiOperation != null && StringUtils.isNotEmpty(apiOperation.responseReference())) {
Response response = new Response().description(SUCCESSFUL_OPERATION);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,18 +12,20 @@
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.InputStream;
import java.nio.file.Files;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Random;
import java.util.UUID;

import org.apache.commons.io.IOUtils;
import org.hamcrest.CoreMatchers;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

import io.restassured.RestAssured;
import io.restassured.http.ContentType;
import io.sinistral.proteus.models.User;
import io.sinistral.proteus.models.User.UserType;
Expand All @@ -45,8 +47,11 @@ public void setUp()
{
try
{

file = new File(getClass().getClassLoader().getResource("data/video.mp4").toURI());
byte[] bytes = new byte[8388608];
Random random = new Random();
random.nextBytes(bytes);

file = Files.createTempFile("test-asset", ".mp4").toFile();

} catch (Exception e)
{
Expand Down Expand Up @@ -249,5 +254,22 @@ public void responseComplexParameters()
assertThat((map.get("optionalQueryDate").toString()), containsString("1970-01-01"));

}

@After
public void tearDown()
{
try
{
if(file.exists())
{
file.delete();
}

} catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
Binary file removed src/test/resources/data/video.mp4
Binary file not shown.

0 comments on commit 445adb3

Please sign in to comment.