diff --git a/assets/video.mp4 b/assets/video.mp4 deleted file mode 100644 index 81a7d5c..0000000 Binary files a/assets/video.mp4 and /dev/null differ diff --git a/pom.xml b/pom.xml index ffb86d4..d26d362 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ 4.0.0 io.sinistral proteus-core - 0.1.7.3-SNAPSHOT + 0.1.8-SNAPSHOT proteus core Proteus is an extremely light, fast, and flexible Java REST API framework built atop Undertow. http://github.com/noboomu/proteus diff --git a/src/main/java/io/sinistral/proteus/ProteusApplication.java b/src/main/java/io/sinistral/proteus/ProteusApplication.java index e1908f5..aaacf74 100644 --- a/src/main/java/io/sinistral/proteus/ProteusApplication.java +++ b/src/main/java/io/sinistral/proteus/ProteusApplication.java @@ -190,7 +190,7 @@ public void run() shutdown(); } catch (TimeoutException timeout) { - timeout.printStackTrace(); + log.error(timeout.getMessage(),timeout); } } }); @@ -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."); } diff --git a/src/main/java/io/sinistral/proteus/server/MediaType.java b/src/main/java/io/sinistral/proteus/server/MediaType.java index d99ba97..645fb13 100644 --- a/src/main/java/io/sinistral/proteus/server/MediaType.java +++ b/src/main/java/io/sinistral/proteus/server/MediaType.java @@ -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() { diff --git a/src/main/java/io/sinistral/proteus/server/ServerRequest.java b/src/main/java/io/sinistral/proteus/server/ServerRequest.java index cbaab40..f281b23 100644 --- a/src/main/java/io/sinistral/proteus/server/ServerRequest.java +++ b/src/main/java/io/sinistral/proteus/server/ServerRequest.java @@ -44,7 +44,8 @@ public class ServerRequest protected FormData form; protected final String contentType; protected final String method; - + protected final String accept; + public ServerRequest() @@ -53,6 +54,7 @@ public ServerRequest() this.path = null; this.exchange = null; this.contentType = null; + this.accept = null; } @@ -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 ) { @@ -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() { diff --git a/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java b/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java index 19e18fb..a9f84f4 100644 --- a/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java +++ b/src/main/java/io/sinistral/proteus/server/handlers/HandlerGenerator.java @@ -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; @@ -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 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 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 literalsNameMap = Arrays.stream(clazz.getDeclaredMethods()).flatMap(m -> Arrays.stream(m.getParameters()).map(Parameter::getParameterizedType)).filter(t -> { + final Map 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")) { diff --git a/src/main/java/io/sinistral/proteus/server/swagger/Reader.java b/src/main/java/io/sinistral/proteus/server/swagger/Reader.java index 3ee89ba..bd72e02 100644 --- a/src/main/java/io/sinistral/proteus/server/swagger/Reader.java +++ b/src/main/java/io/sinistral/proteus/server/swagger/Reader.java @@ -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); diff --git a/src/test/java/io/sinistral/proteus/server/TestControllerEndpoints.java b/src/test/java/io/sinistral/proteus/server/TestControllerEndpoints.java index accdb6e..ff20379 100644 --- a/src/test/java/io/sinistral/proteus/server/TestControllerEndpoints.java +++ b/src/test/java/io/sinistral/proteus/server/TestControllerEndpoints.java @@ -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; @@ -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) { @@ -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(); + } + } } diff --git a/src/test/resources/data/video.mp4 b/src/test/resources/data/video.mp4 deleted file mode 100644 index 3905f79..0000000 Binary files a/src/test/resources/data/video.mp4 and /dev/null differ