From c6ee584b1b35fd2e5a02496f96d67e884e7182e8 Mon Sep 17 00:00:00 2001 From: joshua bauer Date: Fri, 5 May 2017 14:27:01 -0700 Subject: [PATCH] Cleanup warnings. --- .../sinistral/proteus/server/Extractors.java | 8 +- .../proteus/server/ServerRequest.java | 26 +- .../proteus/server/ServerResponse.java | 3 +- .../server/endpoints/EndpointInfo.java | 2 +- .../server/handlers/DefaultHttpHandler.java | 4 - .../handlers/benchmark/BenchmarkHandlers.java | 348 ------------------ .../swagger/ServerParameterExtension.java | 8 +- .../proteus/services/AssetsService.java | 4 - .../proteus/services/BaseService.java | 2 - .../proteus/utilities/SecurityOps.java | 1 - .../proteus/server/DefaultServer.java | 5 - .../server/TestControllerEndpoints.java | 2 + 12 files changed, 17 insertions(+), 396 deletions(-) delete mode 100644 src/main/java/io/sinistral/proteus/server/handlers/benchmark/BenchmarkHandlers.java diff --git a/src/main/java/io/sinistral/proteus/server/Extractors.java b/src/main/java/io/sinistral/proteus/server/Extractors.java index dc97909..91fb3ad 100644 --- a/src/main/java/io/sinistral/proteus/server/Extractors.java +++ b/src/main/java/io/sinistral/proteus/server/Extractors.java @@ -9,7 +9,6 @@ import java.nio.channels.FileChannel; import java.nio.file.Path; import java.nio.file.StandardOpenOption; -import java.time.Instant; import java.time.OffsetDateTime; import java.time.ZonedDateTime; import java.util.Arrays; @@ -18,9 +17,6 @@ import java.util.Objects; import java.util.function.Function; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.fasterxml.jackson.dataformat.xml.XmlMapper; import com.jsoniter.JsonIterator; import com.jsoniter.any.Any; @@ -38,9 +34,7 @@ */ public class Extractors { - private static Logger log = LoggerFactory.getLogger(Extractors.class.getCanonicalName()); - - + protected static final XmlMapper XML_MAPPER = new XmlMapper(); public static class Optional diff --git a/src/main/java/io/sinistral/proteus/server/ServerRequest.java b/src/main/java/io/sinistral/proteus/server/ServerRequest.java index 2f9b5cc..088ebe5 100644 --- a/src/main/java/io/sinistral/proteus/server/ServerRequest.java +++ b/src/main/java/io/sinistral/proteus/server/ServerRequest.java @@ -6,14 +6,11 @@ import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; -import java.net.URLDecoder; import java.nio.ByteBuffer; import java.util.Deque; import java.util.Map; import java.util.concurrent.Executor; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; import org.xnio.channels.StreamSourceChannel; import io.sinistral.proteus.server.predicates.ServerPredicates; @@ -34,24 +31,21 @@ * */ public class ServerRequest -{ - private static Logger log = LoggerFactory.getLogger(ServerRequest.class.getCanonicalName()); - - +{ public static final AttachmentKey BYTE_BUFFER_KEY = AttachmentKey.create(ByteBuffer.class); - - private static final String CHARSET = "UTF-8"; - + + protected static final String CHARSET = "UTF-8"; + protected static final String TMP_DIR = System.getProperty("java.io.tmpdir"); + public final HttpServerExchange exchange; - private final String path; - private FormData form; - private final String contentType; - private final String method; + protected final String path; + protected FormData form; + protected final String contentType; + protected final String method; - private static final String TMP_DIR = System.getProperty("java.io.tmpdir"); - + public ServerRequest() { this.method = null; diff --git a/src/main/java/io/sinistral/proteus/server/ServerResponse.java b/src/main/java/io/sinistral/proteus/server/ServerResponse.java index 4826262..ccce8c5 100644 --- a/src/main/java/io/sinistral/proteus/server/ServerResponse.java +++ b/src/main/java/io/sinistral/proteus/server/ServerResponse.java @@ -424,7 +424,8 @@ public static ServerResponse response(T entity) return new ServerResponse().entity(entity); } - public static ServerResponse response() + @SuppressWarnings("rawtypes") + public static ServerResponse response() { return new ServerResponse(); } diff --git a/src/main/java/io/sinistral/proteus/server/endpoints/EndpointInfo.java b/src/main/java/io/sinistral/proteus/server/endpoints/EndpointInfo.java index 7b3dc3b..acbe516 100644 --- a/src/main/java/io/sinistral/proteus/server/endpoints/EndpointInfo.java +++ b/src/main/java/io/sinistral/proteus/server/endpoints/EndpointInfo.java @@ -5,8 +5,8 @@ import org.apache.commons.lang3.builder.CompareToBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; + import io.undertow.util.HttpString; -import javax.annotation.Generated; /** * @author jbauer diff --git a/src/main/java/io/sinistral/proteus/server/handlers/DefaultHttpHandler.java b/src/main/java/io/sinistral/proteus/server/handlers/DefaultHttpHandler.java index c23d967..90541d9 100644 --- a/src/main/java/io/sinistral/proteus/server/handlers/DefaultHttpHandler.java +++ b/src/main/java/io/sinistral/proteus/server/handlers/DefaultHttpHandler.java @@ -6,9 +6,6 @@ import java.util.Map; import java.util.stream.Collectors; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.inject.Inject; import com.typesafe.config.Config; @@ -25,7 +22,6 @@ */ public class DefaultHttpHandler implements HttpHandler { - private static Logger log = LoggerFactory.getLogger(DefaultHttpHandler.class.getCanonicalName()); @Inject(optional=true) protected DefaultResponseListener defaultResponseListener; diff --git a/src/main/java/io/sinistral/proteus/server/handlers/benchmark/BenchmarkHandlers.java b/src/main/java/io/sinistral/proteus/server/handlers/benchmark/BenchmarkHandlers.java deleted file mode 100644 index 8acb434..0000000 --- a/src/main/java/io/sinistral/proteus/server/handlers/benchmark/BenchmarkHandlers.java +++ /dev/null @@ -1,348 +0,0 @@ -/** - * - */ -package io.sinistral.proteus.server.handlers.benchmark; - -import java.io.ByteArrayOutputStream; -import java.nio.ByteBuffer; -import java.nio.file.Path; -import java.nio.file.Paths; -import java.util.Collections; -import java.util.Deque; -import java.util.concurrent.CompletableFuture; -import java.util.concurrent.CompletionStage; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.function.Consumer; -import java.util.function.Supplier; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import com.google.common.io.Files; -import com.jsoniter.output.JsonStream; - -import io.sinistral.proteus.server.MediaType; -import io.sinistral.proteus.server.ServerResponse; -import io.sinistral.proteus.server.handlers.HandlerGenerator.StatementParameterType; -import io.undertow.attribute.ExchangeAttributes; -import io.undertow.predicate.Predicates; -import io.undertow.server.HttpHandler; -import io.undertow.server.HttpServerExchange; -import io.undertow.server.RoutingHandler; -import io.undertow.server.handlers.resource.FileResourceManager; -import io.undertow.server.handlers.resource.ResourceHandler; -import io.undertow.util.Headers; -import io.undertow.util.Methods; -import io.undertow.util.StatusCodes; - -/** - * @author jbauer - * - */ -public class BenchmarkHandlers implements Supplier -{ - - private static Logger log = LoggerFactory.getLogger(BenchmarkHandlers.class.getCanonicalName()); - - private final static String PLAIN_TEXT = "text/plain".intern(); - - public final static class BenchmarkMessage - { - public String message = "hello world"; - } - - final static ByteBuffer msgBuffer = ByteBuffer.wrap("hello world".getBytes()); - - public RoutingHandler get() - { - - final RoutingHandler handler = new RoutingHandler(); - - handler.add(Methods.GET, "/".intern(), new HttpHandler(){ - - - - @Override - public void handleRequest(HttpServerExchange exchange) throws Exception - { - // TODO Auto-generated method stub - - - exchange.getResponseSender().send(msgBuffer); - - } - } ); - - handler.add(Methods.GET, "/json".intern(), new HttpHandler(){ - - @Override - public void handleRequest(HttpServerExchange exchange) throws Exception - { - // TODO Auto-generated method stub - - exchange.getResponseSender().send(JsonStream.serialize(Collections.singletonMap("message", "Hello, World!"))); - - } - } ); - - - - handler.add(Methods.GET, "/string4".intern(), new HttpHandler(){ - - @Override - public void handleRequest(HttpServerExchange exchange) throws Exception - { - // TODO Auto-generated method stub - - exchange.getResponseSender().send(msgBuffer); - - } - } ); - - handler.add(Methods.GET, "/string2".intern(), new HttpHandler(){ - - @Override - public void handleRequest(HttpServerExchange exchange) throws Exception - { - // TODO Auto-generated method stub - - final ServerResponse resp = ServerResponse.response(String.class).body(msgBuffer); - - resp.send(this, exchange); - - } - } ); - - - - handler.add(Methods.GET, "/mvc/json", new HttpHandler(){ - - @Override - public void handleRequest(HttpServerExchange exchange) throws Exception - { - // TODO Auto-generated method stub - - final ServerResponse resp = ServerResponse.response(String.class).body(JsonStream.serialize(new BenchmarkMessage())); - - resp.send(this, exchange); - - } - } ); - - handler.add(Methods.GET, "/async", new HttpHandler(){ - - @Override - public void handleRequest(HttpServerExchange exchange) throws Exception - { - // TODO Auto-generated method stub - - //exchange.getResponseSender().send(JsonStream.serialize(new BenchmarkMessage())); - - if (exchange.isInIoThread()) { - exchange.dispatch(this); - return; - } - - CompletionStage future = authenticate(); - - future.thenAccept( (passed) -> { - - exchange.setStatusCode(StatusCodes.ACCEPTED); - exchange.getResponseSender().send("User authenticated"); - - }); - - future.exceptionally( (throwable) -> { - - - exchange.setStatusCode(StatusCodes.FORBIDDEN); - exchange.getResponseSender().send(throwable.getMessage()); - - return null; - - }); - - } - } ); - - handler.add(Methods.GET, "/video.mp4", new HttpHandler(){ - - @Override - public void handleRequest(HttpServerExchange exchange) throws Exception - { - // TODO Auto-generated method stub - -// if (exchange.isInIoThread()) { -// exchange.dispatch(this); -// return; -// } -// - - Path filePath = Paths.get("./assets"); - - exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, MediaType.VIDEO_MP4.toString()); - -// java.util.Optional> optionalStringArgs = java.util.Optional.ofNullable(exchange.getQueryParameters().get("optionalStringArgs")).map(java.util.Deque::stream).map( p -> p.map(java.lang.String::valueOf).collect(java.util.stream.Collectors.toList() )); - - FileResourceManager mgr = new FileResourceManager(filePath.toFile()); - - ResourceHandler hdlr = new ResourceHandler(mgr); - - hdlr.handleRequest(exchange); - - - } - } ); - - handler.add(Methods.GET, "/bytes.mp4".intern(), new HttpHandler(){ - - @Override - public void handleRequest(HttpServerExchange exchange) throws Exception - { - // TODO Auto-generated method stub - -// if (exchange.isInIoThread()) { -// exchange.dispatch(this); -// return; -// } -// - Path filePath = Paths.get("./assets/video.mp4"); - - - byte[] bytes = Files.toByteArray(filePath.toFile()); - - exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, bytes.length); - exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, MediaType.AUDIO_MP4.toString()); - - exchange.getResponseSender().send(ByteBuffer.wrap(bytes)); - - - - - - // exchange.getResponseHeaders().put(Headers.CONTENT_LENGTH, length); -// try( SeekableByteChannel channel = Files.newByteChannel(filePath, StandardOpenOption.READ) ) -// { - //FileChannel fileChannel = FileChannel.open(filePath, StandardOpenOption.READ); - - -// int bufferLength = pooled.getBuffer().capacity(); -// -// byte[] bytes = Files.readAllBytes(filePath); -// -// ByteBuffer allBytes = ByteBuffer.wrap(bytes); -// -// int buffers = (int) Math.ceil(bytes.length / bufferLength); -// -// ByteBuffer[] byteBuffers = new ByteBuffer[buffers]; -// -// int pos = 0; -// -// log.debug("buffers: " + buffers + " " + ); -// -// for( int i = 0; i < buffers; i++ ) -// { -// byte[] bb = new byte[bufferLength]; -// int offset = i * bufferLength; -// -// int cLength = (offset + bufferLength) > bytes.length ? (bytes.length - offset) : bufferLength; -// -// log.debug("bsize: " + bufferLength + " offset: " + offset + " cLength: " + cLength); -// allBytes.get(bb, offset, cLength); -// -// byteBuffers[i] = ByteBuffer.wrap(bb); -// } -// -// // channel.read(buffer); -// // buffer.flip(); -// exchange.getResponseSender().send(byteBuffers); -// -// //} - - - -// SeekableByteChannel channel = Files.newByteChannel(filePath, StandardOpenOption.READ) ; -// { -// ChunkedStream stream = new ChunkedStream(); -// stream.send(channel, exchange,new IoCallback(){ -// -// @Override -// public void onComplete(HttpServerExchange exchange, Sender sender) -// { -// // TODO Auto-generated method stub -// IoCallback.END_EXCHANGE.onComplete(exchange, sender); -// -// -// } -// -// @Override -// public void onException(HttpServerExchange exchange, Sender sender, IOException exception) -// { -// // TODO Auto-generated method stub -// log.debug("exception"); -// -// IoCallback.END_EXCHANGE.onException(exchange, sender,exception); -// -// -// }}); -// } - // exchange.getResponseSender().send(JsonStream.serialize(new BenchmarkMessage())); - - } - } ); - - - - handler.add(Methods.GET, "/string3".intern(), new HttpHandler(){ - - @Override - public void handleRequest(HttpServerExchange exchange) throws Exception - { - // TODO Auto-generated method stub - - exchange.setStatusCode( 200 ); - - //exchange.getResponseHeaders().put(Headers.CONTENT_TYPE, PLAIN_TEXT); - - exchange.getResponseSender().send(msgBuffer); - - } - } ); - - - - return handler; - } - - private static ExecutorService EXECUTOR = Executors.newCachedThreadPool(); - - public static CompletionStage authenticate() - { - CompletableFuture future = new CompletableFuture<>(); - - - int passed = (int)((Math.random() * 1000)); - - try - { - Thread.sleep(4000L); - - } catch (Exception e) - { - // TODO: handle exception - } - if(passed > 500) - { - future.complete(true); - } - else - { - future.completeExceptionally(new Exception("Failed to authenticate")); - } - - return future; - } - - -} diff --git a/src/main/java/io/sinistral/proteus/server/swagger/ServerParameterExtension.java b/src/main/java/io/sinistral/proteus/server/swagger/ServerParameterExtension.java index c1ceb0c..9cb5eba 100644 --- a/src/main/java/io/sinistral/proteus/server/swagger/ServerParameterExtension.java +++ b/src/main/java/io/sinistral/proteus/server/swagger/ServerParameterExtension.java @@ -5,14 +5,10 @@ import java.lang.annotation.Annotation; import java.lang.reflect.Type; -import java.util.ArrayList; import java.util.Iterator; import java.util.List; import java.util.Set; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.fasterxml.jackson.databind.JavaType; import io.swagger.jaxrs.DefaultParameterExtension; @@ -25,7 +21,6 @@ */ public class ServerParameterExtension extends DefaultParameterExtension { - private static Logger log = LoggerFactory.getLogger(ServerParameterExtension.class.getCanonicalName()); public ServerParameterExtension() { @@ -42,8 +37,7 @@ public List extractParameters(List annotations, Type type { type = java.io.File.class; - } - + } return super.extractParameters(annotations, type, typesToSkip, chain); diff --git a/src/main/java/io/sinistral/proteus/services/AssetsService.java b/src/main/java/io/sinistral/proteus/services/AssetsService.java index 51d722e..8b3975d 100644 --- a/src/main/java/io/sinistral/proteus/services/AssetsService.java +++ b/src/main/java/io/sinistral/proteus/services/AssetsService.java @@ -7,9 +7,6 @@ import java.util.Set; import java.util.function.Supplier; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - import com.google.inject.Inject; import com.google.inject.name.Named; import com.typesafe.config.Config; @@ -27,7 +24,6 @@ */ public class AssetsService extends BaseService implements Supplier { - private static Logger log = LoggerFactory.getLogger(AssetsService.class.getCanonicalName()); @Inject @Named("registeredEndpoints") diff --git a/src/main/java/io/sinistral/proteus/services/BaseService.java b/src/main/java/io/sinistral/proteus/services/BaseService.java index 939f563..2f8bb4a 100644 --- a/src/main/java/io/sinistral/proteus/services/BaseService.java +++ b/src/main/java/io/sinistral/proteus/services/BaseService.java @@ -13,8 +13,6 @@ import com.google.inject.Singleton; import com.typesafe.config.Config; -import io.sinistral.proteus.modules.ConfigModule; - /** * @author jbauer * diff --git a/src/main/java/io/sinistral/proteus/utilities/SecurityOps.java b/src/main/java/io/sinistral/proteus/utilities/SecurityOps.java index 9e1e6bb..7b01fb3 100644 --- a/src/main/java/io/sinistral/proteus/utilities/SecurityOps.java +++ b/src/main/java/io/sinistral/proteus/utilities/SecurityOps.java @@ -7,7 +7,6 @@ import java.nio.file.Files; import java.nio.file.Paths; import java.security.KeyStore; -import java.util.function.Function; import javax.net.ssl.KeyManager; import javax.net.ssl.KeyManagerFactory; diff --git a/src/test/java/io/sinistral/proteus/server/DefaultServer.java b/src/test/java/io/sinistral/proteus/server/DefaultServer.java index 79fcaa7..d0bb850 100644 --- a/src/test/java/io/sinistral/proteus/server/DefaultServer.java +++ b/src/test/java/io/sinistral/proteus/server/DefaultServer.java @@ -5,7 +5,6 @@ import org.junit.runner.Description; import org.junit.runner.Result; -import org.junit.runner.notification.Failure; import org.junit.runner.notification.RunListener; import org.junit.runner.notification.RunNotifier; import org.junit.runners.BlockJUnit4ClassRunner; @@ -16,10 +15,6 @@ import io.sinistral.proteus.services.AssetsService; import io.sinistral.proteus.services.SwaggerService; -import static io.restassured.RestAssured.*; -import static io.restassured.matcher.RestAssuredMatchers.*; -import static org.hamcrest.Matchers.*; - /** * @author jbauer */ diff --git a/src/test/java/io/sinistral/proteus/server/TestControllerEndpoints.java b/src/test/java/io/sinistral/proteus/server/TestControllerEndpoints.java index 79a0358..9e556e9 100644 --- a/src/test/java/io/sinistral/proteus/server/TestControllerEndpoints.java +++ b/src/test/java/io/sinistral/proteus/server/TestControllerEndpoints.java @@ -115,6 +115,7 @@ public void responseMap() given().accept(ContentType.JSON).log().uri().when().get("tests/response/future/map").then().statusCode(200).and().body("message", is("success")); } + @SuppressWarnings("resource") @Test public void responseUploadFilePathParameter() { @@ -139,6 +140,7 @@ public void responseUploadFilePathParameter() } + @SuppressWarnings("resource") @Test public void responseUploadByteBufferParameter() {