diff --git a/extras/bundles/grizzly-httpservice-bundle/pom.xml b/extras/bundles/grizzly-httpservice-bundle/pom.xml index dace6d2a3a..9d6d90d38a 100644 --- a/extras/bundles/grizzly-httpservice-bundle/pom.xml +++ b/extras/bundles/grizzly-httpservice-bundle/pom.xml @@ -169,7 +169,8 @@ sources provided - junit + org.apache.logging.log4j + junit,slf4j-api diff --git a/extras/connection-pool/src/main/java/org/glassfish/grizzly/connectionpool/MultiEndpointPool.java b/extras/connection-pool/src/main/java/org/glassfish/grizzly/connectionpool/MultiEndpointPool.java index a4c302075e..450d5d9f2f 100644 --- a/extras/connection-pool/src/main/java/org/glassfish/grizzly/connectionpool/MultiEndpointPool.java +++ b/extras/connection-pool/src/main/java/org/glassfish/grizzly/connectionpool/MultiEndpointPool.java @@ -43,8 +43,8 @@ import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + + import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; @@ -57,6 +57,8 @@ import org.glassfish.grizzly.utils.DelayedExecutor; import org.glassfish.grizzly.utils.DelayedExecutor.DelayQueue; import org.glassfish.grizzly.utils.Futures; +import org.slf4j.Logger; + import static org.glassfish.grizzly.connectionpool.SingleEndpointPool.*; /** @@ -628,18 +630,14 @@ public Connection poll(final Endpoint endpoint) throws IOException { public boolean release(final Connection connection) { final ConnectionInfo info = connectionToSubPoolMap.get(connection); if (info != null) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, - "Returning {0} to endpoint pool {1}", - new Object[] {connection, info.endpointPool}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Returning {} to endpoint pool {}", connection, info.endpointPool); } // optimize release() call to avoid redundant map lookup return info.endpointPool.release0(info); } else { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, - "No ConnectionInfo available for {0}. Closing connection.", - connection); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("No ConnectionInfo available for {}. Closing connection.", connection); } connection.closeSilently(); return false; @@ -665,10 +663,8 @@ public boolean attach(final Endpoint endpoint, throws IOException { final SingleEndpointPool sePool = obtainSingleEndpointPool(endpoint); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, - "Associating foreign connection with pool {0} using endpoint key {1}.", - new Object[] {sePool, endpoint}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Associating foreign connection with pool {} using endpoint key {}.", sePool, endpoint); } return sePool.attach(connection); } @@ -688,10 +684,8 @@ public boolean attach(final Endpoint endpoint, */ public boolean detach(final Connection connection) { final ConnectionInfo info = connectionToSubPoolMap.get(connection); - if (info != null && LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, - "Detaching {0} from endpoint pool {1}.", - new Object[] { connection, info.endpointPool}); + if (info != null && LOGGER.isDebugEnabled()) { + LOGGER.debug("Detaching {} from endpoint pool {}.", connection, info.endpointPool); } return info != null && info.endpointPool.detach(connection); } @@ -708,10 +702,8 @@ public boolean detach(final Connection connection) { public void close(final Endpoint endpoint) { final SingleEndpointPool sePool = endpointToPoolMap.remove(endpoint); if (sePool != null) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, - "Closing pool associated with endpoint key {0}", - endpoint); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Closing pool associated with endpoint key {}", endpoint); } sePool.close(); } @@ -729,8 +721,8 @@ public void close() { if (isClosed) { return; } - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine("Shutting down. Closing all pools; shutting down executors as needed."); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Shutting down. Closing all pools; shutting down executors as needed."); } isClosed = true; @@ -782,17 +774,13 @@ protected SingleEndpointPool obtainSingleEndpointPool( sePool = endpointToPoolMap.get(endpoint); if (sePool == null) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, - "Creating new endpoint pool for key {0}", - endpoint); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Creating new endpoint pool for key {}", endpoint); } sePool = createSingleEndpointPool(endpoint); endpointToPoolMap.put(endpoint, sePool); - } else if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, - "Returning existing pool {0} for key {1}", - new Object[]{sePool, endpoint}); + } else if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Returning existing pool {} for key {}", sePool, endpoint); } } } diff --git a/extras/connection-pool/src/main/java/org/glassfish/grizzly/connectionpool/SingleEndpointPool.java b/extras/connection-pool/src/main/java/org/glassfish/grizzly/connectionpool/SingleEndpointPool.java index 106dc35aa9..d4e720047c 100644 --- a/extras/connection-pool/src/main/java/org/glassfish/grizzly/connectionpool/SingleEndpointPool.java +++ b/extras/connection-pool/src/main/java/org/glassfish/grizzly/connectionpool/SingleEndpointPool.java @@ -51,8 +51,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.CloseListener; import org.glassfish.grizzly.CloseType; import org.glassfish.grizzly.CompletionHandler; @@ -70,6 +69,7 @@ import org.glassfish.grizzly.utils.DelayedExecutor; import org.glassfish.grizzly.utils.DelayedExecutor.DelayQueue; import org.glassfish.grizzly.utils.Futures; +import org.slf4j.Logger; /** * The single endpoint {@link Connection} pool implementation, in other words @@ -1252,8 +1252,8 @@ private final class ConnectCompletionHandler @Override public void completed(final Connection connection) { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "Pool connection is established {0}", connection); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Pool connection is established {}", connection); } boolean isOk = false; @@ -1307,8 +1307,8 @@ private void onFailedToConnect(final Throwable t) { // check if there is still a thread(s) waiting for a connection // and reconnect mechanism is enabled if (reconnectQueue != null && !asyncWaitingList.isEmpty()) { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "Pool connect operation failed, schedule reconnect"); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Pool connect operation failed, schedule reconnect"); } if (++failedConnectAttempts > maxReconnectAttempts) { notifyAsyncPollers = true; @@ -1359,8 +1359,8 @@ protected static final class ConnectTimeoutWorker @Override public boolean doWork(final ConnectTimeoutTask connectTimeoutTask) { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "Pool connect timed out"); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Pool connect timed out"); } connectTimeoutTask.connectFuture.cancel(false); return true; @@ -1504,9 +1504,8 @@ public boolean doWork(final Link asyncPollLink) { } if (removed) { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "Async poll timed out for {0}", - asyncPollLink.getValue()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Async poll timed out for {}", asyncPollLink.getValue()); } final AsyncPoll asyncPoll = asyncPollLink.getValue(); @@ -1563,9 +1562,8 @@ protected static final class ConnectionTTLWorker @Override public boolean doWork(final ConnectionInfo ci) { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "Connection {0} TTL expired", - ci.connection); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Connection {} TTL expired", ci.connection); } synchronized(ci.endpointPool.poolSync) { diff --git a/extras/http-server-jaxws/src/main/java/org/glassfish/grizzly/jaxws/JaxwsHandler.java b/extras/http-server-jaxws/src/main/java/org/glassfish/grizzly/jaxws/JaxwsHandler.java index b02a530284..00184d89c8 100644 --- a/extras/http-server-jaxws/src/main/java/org/glassfish/grizzly/jaxws/JaxwsHandler.java +++ b/extras/http-server-jaxws/src/main/java/org/glassfish/grizzly/jaxws/JaxwsHandler.java @@ -58,8 +58,8 @@ import java.util.List; import java.util.Map; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + + import javax.xml.namespace.QName; import javax.xml.parsers.ParserConfigurationException; import javax.xml.transform.Source; @@ -71,6 +71,7 @@ import org.glassfish.grizzly.http.server.HttpHandler; import org.glassfish.grizzly.http.server.Request; import org.glassfish.grizzly.http.server.Response; +import org.slf4j.Logger; import org.xml.sax.EntityResolver; import org.xml.sax.SAXException; @@ -201,7 +202,7 @@ public long getAsyncTimeout(final TimeUnit timeUnit) { */ @Override public void service(Request req, Response res) throws Exception { - LOGGER.log(Level.FINE, "Received a request. The request thread {0} .", Thread.currentThread()); + LOGGER.debug("Received a request. The request thread {} .", Thread.currentThread()); // TODO: synchornous execution for ?wsdl, non AsyncProvider requests final WSHTTPConnection connection = new JaxwsConnection(httpAdapter, req, res, req.isSecure(), isAsync); @@ -231,7 +232,7 @@ public void cancelled() { httpAdapter.handle(connection); } - LOGGER.log(Level.FINE, "Getting out of service(). Done with the request thread {0} .", Thread.currentThread()); + LOGGER.debug("Getting out of service(). Done with the request thread {} .", Thread.currentThread()); } /** @@ -307,4 +308,4 @@ private List buildDocList() { return r; } -} \ No newline at end of file +} diff --git a/extras/http-server-multipart/src/main/java/org/glassfish/grizzly/http/multipart/MultipartScanner.java b/extras/http-server-multipart/src/main/java/org/glassfish/grizzly/http/multipart/MultipartScanner.java index 16b9cc8f0f..143485c587 100644 --- a/extras/http-server-multipart/src/main/java/org/glassfish/grizzly/http/multipart/MultipartScanner.java +++ b/extras/http-server-multipart/src/main/java/org/glassfish/grizzly/http/multipart/MultipartScanner.java @@ -42,12 +42,13 @@ import java.util.HashMap; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; + + import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.Request; import org.glassfish.grizzly.http.io.NIOInputStream; +import org.slf4j.Logger; /** * Entry point for the multipart message processing. @@ -130,7 +131,7 @@ public static void scan(final Request request, if (completionHandler != null) { completionHandler.failed(e); } else { - LOGGER.log(Level.WARNING, "Error occurred, but no CompletionHandler installed to handle it", e); + LOGGER.warn("Error occurred, but no CompletionHandler installed to handle it", e); } } } @@ -193,7 +194,7 @@ public static void scan(final MultipartEntry multipartMixedEntry, if (completionHandler != null) { completionHandler.failed(e); } else { - LOGGER.log(Level.WARNING, "Error occurred, but no CompletionHandler installed to handle it", e); + LOGGER.warn("Error occurred, but no CompletionHandler installed to handle it", e); } } } diff --git a/extras/http-servlet-extras/src/main/java/org/glassfish/grizzly/servlet/extras/MultipartUploadFilter.java b/extras/http-servlet-extras/src/main/java/org/glassfish/grizzly/servlet/extras/MultipartUploadFilter.java index 529280c86e..a64b27000f 100644 --- a/extras/http-servlet-extras/src/main/java/org/glassfish/grizzly/servlet/extras/MultipartUploadFilter.java +++ b/extras/http-servlet-extras/src/main/java/org/glassfish/grizzly/servlet/extras/MultipartUploadFilter.java @@ -41,40 +41,40 @@ package org.glassfish.grizzly.servlet.extras; +import java.io.File; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.atomic.AtomicInteger; + +import javax.servlet.Filter; +import javax.servlet.FilterChain; +import javax.servlet.FilterConfig; +import javax.servlet.ServletException; +import javax.servlet.ServletRequest; +import javax.servlet.ServletResponse; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.EmptyCompletionHandler; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.ReadHandler; +import org.glassfish.grizzly.http.io.NIOInputStream; +import org.glassfish.grizzly.http.io.NIOReader; import org.glassfish.grizzly.http.multipart.ContentDisposition; import org.glassfish.grizzly.http.multipart.MultipartEntry; import org.glassfish.grizzly.http.multipart.MultipartEntryHandler; import org.glassfish.grizzly.http.multipart.MultipartScanner; import org.glassfish.grizzly.http.server.Request; import org.glassfish.grizzly.http.server.Response; -import org.glassfish.grizzly.http.io.NIOInputStream; -import org.glassfish.grizzly.http.io.NIOReader; import org.glassfish.grizzly.http.util.Parameters; import org.glassfish.grizzly.memory.ByteBufferArray; - -import javax.servlet.Filter; -import javax.servlet.FilterChain; -import javax.servlet.FilterConfig; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.ByteBuffer; -import java.nio.channels.FileChannel; -import java.util.ArrayList; -import java.util.List; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.servlet.HttpServletRequestImpl; import org.glassfish.grizzly.servlet.HttpServletResponseImpl; +import org.slf4j.Logger; /** *

@@ -165,7 +165,7 @@ public void completed(final Request request) { try { filterChain.doFilter(servletRequest, servletResponse); } catch (Exception e) { - LOGGER.log(Level.SEVERE, e.toString(), e); + LOGGER.error(e.toString(), e); } finally { if (deleteAfterRequestEnd) { clean(dir); @@ -177,7 +177,7 @@ public void completed(final Request request) { @Override public void failed(Throwable throwable) { // if failed - log the error - LOGGER.log(Level.SEVERE, "Upload failed.", throwable); + LOGGER.error("Upload failed.", throwable); // Complete the asynchronous HTTP request processing. response.resume(); } @@ -219,9 +219,8 @@ private static void clean(final File file) { File[] f = file.listFiles(); if (f.length == 0) { if (!file.delete()) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.warning(String.format("Unable to delete directory %s. Will attempt deletion again upon JVM exit.", - file.getAbsolutePath())); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn("Unable to delete directory {}. Will attempt deletion again upon JVM exit.", file.getAbsolutePath()); } } } else { @@ -231,9 +230,8 @@ private static void clean(final File file) { } } else { if (!file.delete()) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.warning(String.format("Unable to delete file %s. Will attempt deletion again upon JVM exit.", - file.getAbsolutePath())); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn("Unable to delete file {}. Will attempt deletion again upon JVM exit.", file.getAbsolutePath()); } file.deleteOnExit(); } @@ -285,8 +283,7 @@ public void handle(final MultipartEntry multipartEntry) throws Exception { // Get the NIOInputStream to read the multipart entry content final NIOInputStream inputStream = multipartEntry.getNIOInputStream(); - LOGGER.log(Level.FINE, "Uploading file {0}", - new Object[]{filename}); + LOGGER.debug("Uploading file {}", filename); // start asynchronous non-blocking content read. inputStream.notifyAvailable( @@ -394,7 +391,7 @@ public void onAllDataRead() throws Exception { */ @Override public void onError(Throwable t) { - LOGGER.log(Level.WARNING, String.format("Upload of file %s failed.", filename), t); + LOGGER.warn("Upload of file {} failed.", filename, t); // finish the upload finish(); } diff --git a/extras/tls-sni/src/main/java/org/glassfish/grizzly/sni/SNIFilter.java b/extras/tls-sni/src/main/java/org/glassfish/grizzly/sni/SNIFilter.java index 34bbb4e979..0f967b77f6 100644 --- a/extras/tls-sni/src/main/java/org/glassfish/grizzly/sni/SNIFilter.java +++ b/extras/tls-sni/src/main/java/org/glassfish/grizzly/sni/SNIFilter.java @@ -42,7 +42,7 @@ import java.io.IOException; import java.net.InetSocketAddress; -import java.util.logging.Logger; + import javax.net.ssl.SSLEngine; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; @@ -59,6 +59,7 @@ import static org.glassfish.grizzly.ssl.SSLUtils.*; import org.glassfish.grizzly.utils.JdkVersion; +import org.slf4j.Logger; /** * TLS Server Name Indication (SNI) {@link Filter} implementation. @@ -155,7 +156,7 @@ public SNIClientConfigResolver getClientSSLConfigResolver() { */ public void setClientSSLConfigResolver(final SNIClientConfigResolver resolver) { if (!JDK7_OR_HIGHER) { - LOGGER.warning("Client side SNI support requires JDK 1.7+"); + LOGGER.warn("Client side SNI support requires JDK 1.7+"); } this.clientResolver = resolver; diff --git a/modules/bundles/comet/pom.xml b/modules/bundles/comet/pom.xml index 3ea502e0f2..94b6b91ab1 100644 --- a/modules/bundles/comet/pom.xml +++ b/modules/bundles/comet/pom.xml @@ -156,7 +156,8 @@ sources - junit + org.apache.logging.log4j + junit,slf4j-api diff --git a/modules/bundles/core/pom.xml b/modules/bundles/core/pom.xml index a5563db189..17615c4ce5 100644 --- a/modules/bundles/core/pom.xml +++ b/modules/bundles/core/pom.xml @@ -156,7 +156,8 @@ sources - junit + org.apache.logging.log4j + junit,slf4j-api diff --git a/modules/bundles/http-all/pom.xml b/modules/bundles/http-all/pom.xml index 7c3054b2ec..0b479ef179 100644 --- a/modules/bundles/http-all/pom.xml +++ b/modules/bundles/http-all/pom.xml @@ -159,7 +159,8 @@ sources - junit + org.apache.logging.log4j + junit,slf4j-api diff --git a/modules/bundles/http-servlet/pom.xml b/modules/bundles/http-servlet/pom.xml index 0a4ab7ee0f..c755cb8bf6 100755 --- a/modules/bundles/http-servlet/pom.xml +++ b/modules/bundles/http-servlet/pom.xml @@ -158,7 +158,8 @@ sources - junit + org.apache.logging.log4j + junit,slf4j-api diff --git a/modules/bundles/http/pom.xml b/modules/bundles/http/pom.xml index 5d11c5db92..e3259feb21 100755 --- a/modules/bundles/http/pom.xml +++ b/modules/bundles/http/pom.xml @@ -160,7 +160,8 @@ sources - junit + org.apache.logging.log4j + junit,slf4j-api diff --git a/modules/bundles/websockets/pom.xml b/modules/bundles/websockets/pom.xml index 93d3382285..bb4936858e 100644 --- a/modules/bundles/websockets/pom.xml +++ b/modules/bundles/websockets/pom.xml @@ -156,7 +156,8 @@ sources - junit + org.apache.logging.log4j + junit,slf4j-api diff --git a/modules/comet/src/main/java/org/glassfish/grizzly/comet/CometContext.java b/modules/comet/src/main/java/org/glassfish/grizzly/comet/CometContext.java index 14899a088d..c5464af6ce 100644 --- a/modules/comet/src/main/java/org/glassfish/grizzly/comet/CometContext.java +++ b/modules/comet/src/main/java/org/glassfish/grizzly/comet/CometContext.java @@ -45,21 +45,21 @@ import java.util.Map; import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; +import org.glassfish.grizzly.CloseType; import org.glassfish.grizzly.Closeable; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; -import org.glassfish.grizzly.CloseType; import org.glassfish.grizzly.GenericCloseListener; +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.ReadHandler; +import org.glassfish.grizzly.http.io.NIOInputStream; import org.glassfish.grizzly.http.server.Request; import org.glassfish.grizzly.http.server.Response; import org.glassfish.grizzly.http.server.TimeoutHandler; -import org.glassfish.grizzly.http.io.NIOInputStream; import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.utils.DataStructures; +import org.slf4j.Logger; /** * The main object used by {@link CometHandler} and Servlet to push information amongst suspended request/response. The @@ -105,7 +105,7 @@ public class CometContext { protected final static String ALREADY_REMOVED = "CometHandler already been removed or invalid."; private final static String COMET_NOT_ENABLED = "Make sure you have enabled Comet or make sure the thread" + " invoking that method is the same as the Servlet.service() thread."; - protected final static Logger LOGGER = Logger.getLogger(CometContext.class.getName()); + protected final static Logger LOGGER = Grizzly.logger(CometContext.class); private final Map attributes; protected final static ThreadLocal REQUEST_LOCAL = new ThreadLocal(); @@ -516,7 +516,7 @@ private static void notifyOnAsyncRead(CometHandler handler) { try { handler.onEvent(new CometEvent(CometEvent.Type.READ)); } catch (IOException e) { - LOGGER.log(Level.FINE, e.getMessage()); + LOGGER.debug(e.getMessage()); } } @@ -537,7 +537,7 @@ public void failed(Throwable throwable) { try { handler.onInterrupt(eventInterrupt); } catch (IOException e) { - LOGGER.log(Level.FINE, "CometCompletionHandler.failed", e.getMessage()); + LOGGER.debug("CometCompletionHandler.failed", e); } } @@ -546,7 +546,7 @@ public void completed(Response result) { try { handler.onInterrupt(eventInterrupt); } catch (IOException e) { - LOGGER.log(Level.FINE, "CometCompletionHandler.completed", e.getMessage()); + LOGGER.debug("CometCompletionHandler.completed", e); } } @@ -574,7 +574,7 @@ public boolean onTimeout(Response response) { try { handler.onInterrupt(eventInterrupt); } catch (IOException e) { - LOGGER.log(Level.SEVERE, e.getMessage()); + LOGGER.error(e.getMessage()); throw new RuntimeException(e.getMessage(), e); } return true; diff --git a/modules/comet/src/main/java/org/glassfish/grizzly/comet/CometEngine.java b/modules/comet/src/main/java/org/glassfish/grizzly/comet/CometEngine.java index 2f3ed021e2..a571f0f4d3 100644 --- a/modules/comet/src/main/java/org/glassfish/grizzly/comet/CometEngine.java +++ b/modules/comet/src/main/java/org/glassfish/grizzly/comet/CometEngine.java @@ -43,11 +43,11 @@ import java.io.IOException; import java.util.Map; import java.util.concurrent.ExecutorService; -import java.util.logging.Level; -import java.util.logging.Logger; +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.utils.DataStructures; +import org.slf4j.Logger; /** * Main class allowing Comet support on top of Grizzly Asynchronous Request Processing mechanism. This class is the @@ -102,7 +102,7 @@ public class CometEngine { /** * Main logger */ - protected final static Logger logger = Logger.getLogger(CometEngine.class.getName()); + protected final static Logger LOGGER = Grizzly.logger(CometEngine.class); /** * The {@link ExecutorService} used to execute */ @@ -220,10 +220,8 @@ public CometContext register(String topic, Class implements CometHandler { - protected final static Logger logger = Logger.getLogger(DefaultConcurrentCometHandler.class.getName()); /** * used for preventing the worker threads from the executor event queue from adding events to the comet handlers * local queue or starting IO logic after shut down.
@@ -204,4 +202,4 @@ public void onTerminate(CometEvent event) throws IOException { protected void terminate() { } -} \ No newline at end of file +} diff --git a/modules/comet/src/test/java/org/glassfish/grizzly/comet/BasicCometTest.java b/modules/comet/src/test/java/org/glassfish/grizzly/comet/BasicCometTest.java index f152b5b1e5..d6fb378eac 100644 --- a/modules/comet/src/test/java/org/glassfish/grizzly/comet/BasicCometTest.java +++ b/modules/comet/src/test/java/org/glassfish/grizzly/comet/BasicCometTest.java @@ -50,11 +50,15 @@ import java.net.URL; import java.util.Collection; import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; - + import junit.framework.TestCase; import org.glassfish.grizzly.Grizzly; -import org.glassfish.grizzly.http.server.*; +import org.glassfish.grizzly.http.server.HttpHandler; +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.grizzly.http.server.NetworkListener; +import org.glassfish.grizzly.http.server.Request; +import org.glassfish.grizzly.http.server.Response; +import org.slf4j.Logger; /** * Basic Comet Test. @@ -155,7 +159,7 @@ public void testOnTerminate() throws IOException, InterruptedException { } public void testHttpPipeline() throws Exception { - LOGGER.fine("testHttpPipeline"); + LOGGER.debug("testHttpPipeline"); cometContext.setExpirationDelay(10000); cometContext.setDetectClosedConnections(false); final String alias = "/testPipeline"; @@ -248,7 +252,7 @@ public void service(Request request, Response response) throws Exception { } public void testHttpPipeline2() throws Exception { - LOGGER.fine("testHttpPipeline2"); + LOGGER.debug("testHttpPipeline2"); cometContext.setExpirationDelay(10000); cometContext.setDetectClosedConnections(false); final String alias = "/testPipeline2"; diff --git a/modules/comet/src/test/java/org/glassfish/grizzly/comet/DefaultTestCometHandler.java b/modules/comet/src/test/java/org/glassfish/grizzly/comet/DefaultTestCometHandler.java index 81a5816c22..d339b72c9e 100644 --- a/modules/comet/src/test/java/org/glassfish/grizzly/comet/DefaultTestCometHandler.java +++ b/modules/comet/src/test/java/org/glassfish/grizzly/comet/DefaultTestCometHandler.java @@ -40,14 +40,13 @@ package org.glassfish.grizzly.comet; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.Grizzly; import java.io.IOException; import java.util.concurrent.atomic.AtomicBoolean; +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.Response; +import org.slf4j.Logger; public class DefaultTestCometHandler extends DefaultCometHandler implements Comparable { private static final Logger LOGGER = Grizzly.logger(DefaultTestCometHandler.class); @@ -66,7 +65,7 @@ public DefaultTestCometHandler(CometContext cometContext, } public void onEvent(CometEvent event) throws IOException { - LOGGER.log(Level.FINE, " -> onEvent Handler:{0}", hashCode()); + LOGGER.debug(" -> onEvent Handler:{}", hashCode()); onEventCalled.set(true); if (resumeAfterEvent) { getCometContext().resumeCometHandler(this); diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/Context.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/Context.java index a81ab6e664..1b743d2e92 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/Context.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/Context.java @@ -43,7 +43,7 @@ import java.io.IOException; import java.lang.reflect.Array; import java.util.Arrays; -import java.util.logging.Logger; + import org.glassfish.grizzly.asyncqueue.MessageCloner; import org.glassfish.grizzly.attributes.AttributeHolder; import org.glassfish.grizzly.attributes.AttributeStorage; @@ -56,7 +56,6 @@ @SuppressWarnings("deprecation") public class Context implements AttributeStorage, Cacheable { - private static final Logger LOGGER = Grizzly.logger(Context.class); private static final Processor NULL_PROCESSOR = new NullProcessor(); private static final ThreadCache.CachedTypeIndex CACHE_IDX = ThreadCache.obtainIndex(Context.class, 4); diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/Grizzly.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/Grizzly.java index 66fd066225..3440125d8a 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/Grizzly.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/Grizzly.java @@ -41,13 +41,14 @@ package org.glassfish.grizzly; import java.io.IOException; -import java.util.Properties; -import org.glassfish.grizzly.attributes.AttributeBuilder; import java.io.InputStream; -import java.util.logging.Logger; +import java.util.Properties; import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.glassfish.grizzly.attributes.AttributeBuilder; +import org.slf4j.Logger; + /** * Class contains information about Grizzly framework. * @@ -64,9 +65,13 @@ public class Grizzly { private static final int minor; private static boolean isTrackingThreadCache; - - public static Logger logger(Class clazz) { - return Logger.getLogger(clazz.getName()); + + public static Logger logger(Class clazz) { + return logger(clazz.getName()); + } + + public static Logger logger(String name) { + return MuleLoggerProvider.getLogger(name); } /** Reads version from properties and parses it. */ diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/MuleLoggerProvider.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/MuleLoggerProvider.java new file mode 100644 index 0000000000..405f892df6 --- /dev/null +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/MuleLoggerProvider.java @@ -0,0 +1,391 @@ +/* + * Copyright (c) MuleSoft, Inc. All rights reserved. http://www.mulesoft.com + * The software in this package is published under the terms of the CPAL v1.0 + * license, a copy of which has been included with this distribution in the + * LICENSE.txt file. + */ +package org.glassfish.grizzly; + +import static java.lang.Boolean.parseBoolean; +import static java.lang.System.getProperty; + +import java.util.function.Supplier; +import java.util.logging.Level; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.slf4j.Marker; +import org.slf4j.helpers.MessageFormatter; + +class MuleLoggerProvider { + + private static final String DISABLE_LOG_SEPARATION_PROPERTY = "mule.disableLogSeparation"; + private static final String USE_SLF4J_PROPERTY = "mule.grizzly.useSLF4J"; + + private static final boolean isMuleLogSeparationEnabled = getProperty(DISABLE_LOG_SEPARATION_PROPERTY) == null; + + // When log separation is enabled, the isLogEnabled() methods are expensive, and then we would be adding a + // performance degradation. Then, by default we will use JUL if log separation is enabled, and SLF4J otherwise. + // + // If the user still wants to use SLF4J with log separation enabled, or use JUL with log separation disabled, + // then they have to set the property mule.grizzly.useSLF4J + private static final boolean useSlf4j = parseBoolean(getProperty(USE_SLF4J_PROPERTY, isMuleLogSeparationEnabled ? "false" : "true")); + + public static Logger getLogger(String name) { + return useSlf4j ? LoggerFactory.getLogger(name) : new JulAsSlf4jAdapter(name); + } + + private static class JulAsSlf4jAdapter implements org.slf4j.Logger { + + private final java.util.logging.Logger julDelegate; + + public JulAsSlf4jAdapter(String name) { + julDelegate = java.util.logging.Logger.getLogger(name); + } + + @Override + public String getName() { + return julDelegate.getName(); + } + + @Override + public boolean isTraceEnabled() { + return julDelegate.isLoggable(Level.FINEST); + } + + @Override + public void trace(String msg) { + julDelegate.log(Level.FINEST, msg); + } + + @Override + public void trace(String format, Object arg) { + julDelegate.log(Level.FINEST, new MessageSupplier(format, arg)); + } + + @Override + public void trace(String format, Object arg1, Object arg2) { + julDelegate.log(Level.FINEST, new MessageSupplier(format, arg1, arg2)); + } + + @Override + public void trace(String format, Object... arguments) { + julDelegate.log(Level.FINEST, new MessageSupplier(format, arguments)); + } + + @Override + public void trace(String msg, Throwable t) { + julDelegate.log(Level.FINEST, msg, t); + } + + @Override + public boolean isTraceEnabled(Marker marker) { + return julDelegate.isLoggable(Level.FINEST); + } + + @Override + public void trace(Marker marker, String msg) { + julDelegate.log(Level.FINEST, msg); + } + + @Override + public void trace(Marker marker, String format, Object arg) { + julDelegate.log(Level.FINEST, new MessageSupplier(format, arg)); + } + + @Override + public void trace(Marker marker, String format, Object arg1, Object arg2) { + julDelegate.log(Level.FINEST, new MessageSupplier(format, arg1, arg2)); + } + + @Override + public void trace(Marker marker, String format, Object... arguments) { + julDelegate.log(Level.FINEST, new MessageSupplier(format, arguments)); + } + + @Override + public void trace(Marker marker, String msg, Throwable t) { + julDelegate.log(Level.FINEST, msg, t); + } + + @Override + public boolean isDebugEnabled() { + return julDelegate.isLoggable(Level.FINE); + } + + @Override + public void debug(String msg) { + julDelegate.log(Level.FINE, msg); + } + + @Override + public void debug(String format, Object arg) { + julDelegate.log(Level.FINE, new MessageSupplier(format, arg)); + } + + @Override + public void debug(String format, Object arg1, Object arg2) { + julDelegate.log(Level.FINE, new MessageSupplier(format, arg1, arg2)); + } + + @Override + public void debug(String format, Object... arguments) { + julDelegate.log(Level.FINE, new MessageSupplier(format, arguments)); + } + + @Override + public void debug(String msg, Throwable t) { + julDelegate.log(Level.FINE, msg, t); + } + + @Override + public boolean isDebugEnabled(Marker marker) { + return julDelegate.isLoggable(Level.FINE); + } + + @Override + public void debug(Marker marker, String msg) { + julDelegate.log(Level.FINE, msg); + } + + @Override + public void debug(Marker marker, String format, Object arg) { + julDelegate.log(Level.FINE, new MessageSupplier(format, arg)); + } + + @Override + public void debug(Marker marker, String format, Object arg1, Object arg2) { + julDelegate.log(Level.FINE, new MessageSupplier(format, arg1, arg2)); + } + + @Override + public void debug(Marker marker, String format, Object... arguments) { + julDelegate.log(Level.FINE, new MessageSupplier(format, arguments)); + } + + @Override + public void debug(Marker marker, String msg, Throwable t) { + julDelegate.log(Level.FINE, msg, t); + } + + @Override + public boolean isInfoEnabled() { + return julDelegate.isLoggable(Level.INFO); + } + + @Override + public void info(String msg) { + julDelegate.log(Level.INFO, msg); + } + + @Override + public void info(String format, Object arg) { + julDelegate.log(Level.INFO, new MessageSupplier(format, arg)); + } + + @Override + public void info(String format, Object arg1, Object arg2) { + julDelegate.log(Level.INFO, new MessageSupplier(format, arg1, arg2)); + } + + @Override + public void info(String format, Object... arguments) { + julDelegate.log(Level.INFO, new MessageSupplier(format, arguments)); + } + + @Override + public void info(String msg, Throwable t) { + julDelegate.log(Level.INFO, msg, t); + } + + @Override + public boolean isInfoEnabled(Marker marker) { + return julDelegate.isLoggable(Level.INFO); + } + + @Override + public void info(Marker marker, String msg) { + julDelegate.log(Level.INFO, msg); + } + + @Override + public void info(Marker marker, String format, Object arg) { + julDelegate.log(Level.INFO, new MessageSupplier(format, arg)); + } + + @Override + public void info(Marker marker, String format, Object arg1, Object arg2) { + julDelegate.log(Level.INFO, new MessageSupplier(format, arg1, arg2)); + } + + @Override + public void info(Marker marker, String format, Object... arguments) { + julDelegate.log(Level.INFO, new MessageSupplier(format, arguments)); + } + + @Override + public void info(Marker marker, String msg, Throwable t) { + julDelegate.log(Level.INFO, msg, t); + } + + @Override + public boolean isWarnEnabled() { + return julDelegate.isLoggable(Level.WARNING); + } + + @Override + public void warn(String msg) { + julDelegate.log(Level.WARNING, msg); + } + + @Override + public void warn(String format, Object arg) { + julDelegate.log(Level.WARNING, new MessageSupplier(format, arg)); + } + + @Override + public void warn(String format, Object... arguments) { + julDelegate.log(Level.WARNING, new MessageSupplier(format, arguments)); + } + + @Override + public void warn(String format, Object arg1, Object arg2) { + julDelegate.log(Level.WARNING, new MessageSupplier(format, arg1, arg2)); + } + + @Override + public void warn(String msg, Throwable t) { + julDelegate.log(Level.WARNING, msg, t); + } + + @Override + public boolean isWarnEnabled(Marker marker) { + return julDelegate.isLoggable(Level.WARNING); + } + + @Override + public void warn(Marker marker, String msg) { + julDelegate.log(Level.WARNING, msg); + } + + @Override + public void warn(Marker marker, String format, Object arg) { + julDelegate.log(Level.WARNING, new MessageSupplier(format, arg)); + } + + @Override + public void warn(Marker marker, String format, Object arg1, Object arg2) { + julDelegate.log(Level.WARNING, new MessageSupplier(format, arg1, arg2)); + } + + @Override + public void warn(Marker marker, String format, Object... arguments) { + julDelegate.log(Level.WARNING, new MessageSupplier(format, arguments)); + } + + @Override + public void warn(Marker marker, String msg, Throwable t) { + julDelegate.log(Level.WARNING, msg, t); + } + + @Override + public boolean isErrorEnabled() { + return julDelegate.isLoggable(Level.SEVERE); + } + + @Override + public void error(String msg) { + julDelegate.log(Level.SEVERE, msg); + } + + @Override + public void error(String format, Object arg) { + julDelegate.log(Level.SEVERE, new MessageSupplier(format, arg)); + } + + @Override + public void error(String format, Object arg1, Object arg2) { + julDelegate.log(Level.SEVERE, new MessageSupplier(format, arg1, arg2)); + } + + @Override + public void error(String format, Object... arguments) { + julDelegate.log(Level.SEVERE, new MessageSupplier(format, arguments)); + } + + @Override + public void error(String msg, Throwable t) { + julDelegate.log(Level.SEVERE, msg, t); + } + + @Override + public boolean isErrorEnabled(Marker marker) { + return julDelegate.isLoggable(Level.SEVERE); + } + + @Override + public void error(Marker marker, String msg) { + julDelegate.log(Level.SEVERE, msg); + } + + @Override + public void error(Marker marker, String format, Object arg) { + julDelegate.log(Level.SEVERE, new MessageSupplier(format, arg)); + } + + @Override + public void error(Marker marker, String format, Object arg1, Object arg2) { + julDelegate.log(Level.SEVERE, new MessageSupplier(format, arg1, arg2)); + } + + @Override + public void error(Marker marker, String format, Object... arguments) { + julDelegate.log(Level.SEVERE, new MessageSupplier(format, arguments)); + } + + @Override + public void error(Marker marker, String msg, Throwable t) { + julDelegate.log(Level.SEVERE, msg, t); + } + } + + private static class MessageSupplier implements Supplier { + + private final Supplier delegate; + + public MessageSupplier(String format, Object arg) { + delegate = new Supplier() { + + @Override + public String get() { + return MessageFormatter.format(format, arg).getMessage(); + } + }; + } + + public MessageSupplier(String format, Object... arguments) { + delegate = new Supplier() { + + @Override + public String get() { + return MessageFormatter.arrayFormat(format, arguments).getMessage(); + } + }; + } + + public MessageSupplier(String format, Object arg1, Object arg2) { + delegate = new Supplier() { + + @Override + public String get() { + return MessageFormatter.format(format, arg1, arg2).getMessage(); + } + }; + } + + @Override + public String get() { + return delegate.get(); + } + } +} diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/ProcessorExecutor.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/ProcessorExecutor.java index 7b22e19270..80944af606 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/ProcessorExecutor.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/ProcessorExecutor.java @@ -41,9 +41,9 @@ package org.glassfish.grizzly; import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.localization.LogMessages; +import org.slf4j.Logger; /** * @@ -62,11 +62,8 @@ public static void execute(final Connection connection, @SuppressWarnings("unchecked") public static void execute(Context context) { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, - "executing connection ({0}). IOEvent={1} processor={2}", - new Object[]{context.getConnection(), context.getIoEvent(), - context.getProcessor()}); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("executing connection ({}). IOEvent={} processor={}", context.getConnection(), context.getIoEvent(), context.getProcessor()); } boolean isRerun; @@ -86,12 +83,8 @@ public static void execute(Context context) { complete0(context, result); } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_PROCESSOR_ERROR( - context.getConnection(), context.getIoEvent(), - context.getProcessor()), - t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_PROCESSOR_ERROR(context.getConnection(), context.getIoEvent(), context.getProcessor()), t); } try { diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/asyncqueue/AsyncQueueRecord.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/asyncqueue/AsyncQueueRecord.java index 92958248f4..39f07b6531 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/asyncqueue/AsyncQueueRecord.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/asyncqueue/AsyncQueueRecord.java @@ -40,14 +40,13 @@ package org.glassfish.grizzly.asyncqueue; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.Cacheable; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.utils.DebugPoint; +import org.slf4j.Logger; /** * {@link AsyncQueue} element unit @@ -57,7 +56,7 @@ * @author Alexey Stashok */ public abstract class AsyncQueueRecord implements Cacheable { - private final static Logger LOGGER = Grizzly.logger(AsyncQueue.class); + private static final Logger LOGGER = Grizzly.logger(AsyncQueue.class); protected Connection connection; protected Object message; @@ -109,9 +108,8 @@ public void notifyFailure(final Throwable e) { if (completionHandler != null) { completionHandler.failed(e); } else { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, - LogMessages.FINE_GRIZZLY_ASYNCQUEUE_ERROR_NOCALLBACK_ERROR(e)); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(LogMessages.FINE_GRIZZLY_ASYNCQUEUE_ERROR_NOCALLBACK_ERROR(e)); } } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/attributes/AttributeBuilderInitializer.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/attributes/AttributeBuilderInitializer.java index 13f8b606e2..2fbeb808ab 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/attributes/AttributeBuilderInitializer.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/attributes/AttributeBuilderInitializer.java @@ -40,9 +40,7 @@ package org.glassfish.grizzly.attributes; import org.glassfish.grizzly.Grizzly; - -import java.util.logging.Level; -import java.util.logging.Logger; +import org.slf4j.Logger; class AttributeBuilderInitializer { @@ -61,13 +59,11 @@ static AttributeBuilder initBuilder() { AttributeBuilder.class.getClassLoader()); return builderClass.newInstance(); } catch (Exception e) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.log(Level.SEVERE, - "Unable to load or create a new instance of AttributeBuilder {0}. Cause: {1}", - new Object[]{className, e.getMessage()}); + if (LOGGER.isErrorEnabled()) { + LOGGER.error("Unable to load or create a new instance of AttributeBuilder {}. Cause: {}", className, e.getMessage()); } - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, e.toString(), e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(e.toString(), e); } return new DefaultAttributeBuilder(); } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/filterchain/DefaultFilterChain.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/filterchain/DefaultFilterChain.java index c9ccdfdd76..81825f881e 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/filterchain/DefaultFilterChain.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/filterchain/DefaultFilterChain.java @@ -44,10 +44,19 @@ import java.util.ArrayList; import java.util.Collection; import java.util.concurrent.ExecutionException; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.*; + import org.glassfish.grizzly.Appendable; +import org.glassfish.grizzly.Appender; +import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.CompletionHandler; +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.Context; +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.IOEvent; +import org.glassfish.grizzly.ProcessorExecutor; +import org.glassfish.grizzly.ProcessorResult; +import org.glassfish.grizzly.ReadResult; +import org.glassfish.grizzly.WriteResult; import org.glassfish.grizzly.asyncqueue.AsyncQueueEnabledTransport; import org.glassfish.grizzly.asyncqueue.AsyncQueueWriter; import org.glassfish.grizzly.asyncqueue.MessageCloner; @@ -58,6 +67,8 @@ import org.glassfish.grizzly.utils.Exceptions; import org.glassfish.grizzly.utils.Futures; import org.glassfish.grizzly.utils.NullaryFunction; +import org.slf4j.Logger; +import org.slf4j.event.Level; /** * Default {@link FilterChain} implementation @@ -154,8 +165,8 @@ public ProcessorResult execute(FilterChainContext ctx) { } } while (prepareRemainder(ctx, filtersState)); } catch (Throwable e) { - LOGGER.log(e instanceof IOException ? Level.FINE : Level.WARNING, - LogMessages.WARNING_GRIZZLY_FILTERCHAIN_EXCEPTION(), e); + Level level = e instanceof IOException ? Level.DEBUG : Level.WARN; + LOGGER.atLevel(level).log(LogMessages.WARNING_GRIZZLY_FILTERCHAIN_EXCEPTION(), e); throwChain(ctx, executor, e); ctx.getCloseable().closeWithReason(Exceptions.makeIOException(e)); @@ -276,16 +287,14 @@ protected NextAction executeFilter(final FilterExecutor executor, NextAction nextNextAction; do { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINE, "Execute filter. filter={0} context={1}", - new Object[]{currentFilter, ctx}); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Execute filter. filter={} context={}", currentFilter, ctx); } // execute the task nextNextAction = executor.execute(currentFilter, ctx); - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINE, "after execute filter. filter={0} context={1} nextAction={2}", - new Object[]{currentFilter, ctx, nextNextAction}); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("after execute filter. filter={} context={} nextAction={}", currentFilter, ctx, nextNextAction); } } while (nextNextAction.type() == RerunFilterAction.TYPE); diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/filterchain/FilterChainContext.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/filterchain/FilterChainContext.java index 504301117c..aa80317c50 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/filterchain/FilterChainContext.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/filterchain/FilterChainContext.java @@ -43,8 +43,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.Appendable; import org.glassfish.grizzly.Appender; import org.glassfish.grizzly.Buffer; @@ -64,6 +62,7 @@ import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.MemoryManager; import org.glassfish.grizzly.utils.Holder; +import org.slf4j.Logger; /** * {@link FilterChain} {@link Context} implementation. @@ -201,7 +200,7 @@ public void run() { ProcessorExecutor.execute(FilterChainContext.this.internalContext); } catch (Exception e) { - logger.log(Level.FINE, "Exception during running Processor", e); + logger.debug("Exception during running Processor", e); } } }; @@ -252,7 +251,7 @@ public void resume(final NextAction nextAction) { predefinedNextAction = nextAction; ProcessorExecutor.execute(internalContext); } catch (Exception e) { - logger.log(Level.FINE, "Exception during running Processor", e); + logger.debug("Exception during running Processor", e); } } @@ -285,7 +284,7 @@ public void fork(final NextAction nextAction) { predefinedNextAction = getForkAction(nextAction); ProcessorExecutor.execute(internalContext); } catch (Exception e) { - logger.log(Level.FINE, "Exception during running Processor", e); + logger.debug("Exception during running Processor", e); } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/memory/Buffers.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/memory/Buffers.java index 65fe4092cd..cdf889a014 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/memory/Buffers.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/memory/Buffers.java @@ -49,12 +49,12 @@ import java.nio.charset.Charset; import java.util.Arrays; import java.util.Formatter; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Appender; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.localization.LogMessages; +import org.slf4j.Logger; /** * Class has useful methods to simplify the work with {@link Buffer}s. @@ -296,9 +296,7 @@ public static void put(final ByteBuffer srcBuffer, final int srcOffset, final int length, final ByteBuffer dstBuffer) { if (dstBuffer.remaining() < length) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_BUFFERS_OVERFLOW_EXCEPTION( - srcBuffer, srcOffset, length, dstBuffer)); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_BUFFERS_OVERFLOW_EXCEPTION(srcBuffer, srcOffset, length, dstBuffer)); throw new BufferOverflowException(); } @@ -457,8 +455,7 @@ public static Buffer appendBuffers(final MemoryManager memoryManager, } if (buffer1.order() != buffer2.order()) { - LOGGER.fine("Appending buffers with different ByteOrder." - + "The result Buffer's order will be the same as the first Buffer's ByteOrder"); + LOGGER.debug("Appending buffers with different ByteOrder. The result Buffer's order will be the same as the first Buffer's ByteOrder"); buffer2.order(buffer1.order()); } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/memory/MemoryManagerInitializer.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/memory/MemoryManagerInitializer.java index 32ebf52152..40cfc348bf 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/memory/MemoryManagerInitializer.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/memory/MemoryManagerInitializer.java @@ -40,13 +40,11 @@ package org.glassfish.grizzly.memory; -import org.glassfish.grizzly.Grizzly; - -import java.util.logging.Level; -import java.util.logging.Logger; - import static org.glassfish.grizzly.memory.DefaultMemoryManagerFactory.DMMF_PROP_NAME; +import org.glassfish.grizzly.Grizzly; +import org.slf4j.Logger; + class MemoryManagerInitializer { private static final String DMM_PROP_NAME = @@ -101,13 +99,11 @@ private static T newInstance(final String className) { MemoryManager.class.getClassLoader()); return (T) clazz.newInstance(); } catch (Exception e) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.log(Level.SEVERE, - "Unable to load or create a new instance of Class {0}. Cause: {1}", - new Object[]{className, e.getMessage()}); + if (LOGGER.isErrorEnabled()) { + LOGGER.error("Unable to load or create a new instance of Class {}. Cause: {}", className, e.getMessage()); } - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, e.toString(), e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(e.toString(), e); } return null; } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/monitoring/MonitoringUtils.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/monitoring/MonitoringUtils.java index df43892e13..b4fa28e328 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/monitoring/MonitoringUtils.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/monitoring/MonitoringUtils.java @@ -40,9 +40,9 @@ package org.glassfish.grizzly.monitoring; import java.lang.reflect.Constructor; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Grizzly; +import org.slf4j.Logger; /** * The class, which contains utility methods for monitoring support. @@ -85,8 +85,7 @@ public static Object loadJmxObject(final String jmxObjectClassname, final Constructor c = clazz.getDeclaredConstructor(contructorParamType); return c.newInstance(constructorParam); } catch (Exception e) { - LOGGER.log(Level.FINE, "Can not load JMX Object: " + - jmxObjectClassname, e); + LOGGER.debug("Can not load JMX Object: {}", jmxObjectClassname, e); } return null; diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/AbstractNIOAsyncQueueReader.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/AbstractNIOAsyncQueueReader.java index 8e04455720..34ed174f4a 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/AbstractNIOAsyncQueueReader.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/AbstractNIOAsyncQueueReader.java @@ -43,12 +43,20 @@ import java.io.EOFException; import java.io.IOException; import java.net.SocketAddress; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.*; + +import org.glassfish.grizzly.AbstractReader; +import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.CompletionHandler; +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.Context; +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.Interceptor; +import org.glassfish.grizzly.ReadResult; +import org.glassfish.grizzly.Reader; import org.glassfish.grizzly.asyncqueue.AsyncQueueReader; import org.glassfish.grizzly.asyncqueue.AsyncReadQueueRecord; import org.glassfish.grizzly.asyncqueue.TaskQueue; +import org.slf4j.Logger; /** * The {@link AsyncQueueReader} implementation, based on the Java NIO @@ -258,7 +266,7 @@ public AsyncResult processAsync(final Context context) { onReadFailure(nioConnection, queueRecord, e); } catch (Exception e) { String message = "Unexpected exception occurred in AsyncQueueReader"; - LOGGER.log(Level.SEVERE, message, e); + LOGGER.error(message, e); IOException ioe = new IOException(e.getClass() + ": " + message); onReadFailure(nioConnection, queueRecord, ioe); } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/AbstractNIOAsyncQueueWriter.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/AbstractNIOAsyncQueueWriter.java index 2698be064a..6b0f2d161c 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/AbstractNIOAsyncQueueWriter.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/AbstractNIOAsyncQueueWriter.java @@ -42,8 +42,7 @@ import java.io.IOException; import java.net.SocketAddress; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.AbstractWriter; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; @@ -59,6 +58,7 @@ import org.glassfish.grizzly.asyncqueue.RecordWriteResult; import org.glassfish.grizzly.asyncqueue.TaskQueue; import org.glassfish.grizzly.asyncqueue.WritableMessage; +import org.slf4j.Logger; /** @@ -73,7 +73,7 @@ public abstract class AbstractNIOAsyncQueueWriter extends AbstractWriter implements AsyncQueueWriter { - private final static Logger LOGGER = Grizzly.logger(AbstractNIOAsyncQueueWriter.class); + private static final Logger LOGGER = Grizzly.logger(AbstractNIOAsyncQueueWriter.class); protected final NIOTransport transport; @@ -225,7 +225,7 @@ public void write( final int pendingBytes = writeTaskQueue.reserveSpace(bytesToReserve); final boolean isCurrent = (pendingBytes == bytesToReserve); - final boolean isLogFine = LOGGER.isLoggable(Level.FINEST); + final boolean isLogFine = LOGGER.isTraceEnabled(); if (isLogFine) { doFineLog("AsyncQueueWriter.write connection={0}, record={1}, " @@ -302,9 +302,7 @@ public void write( } } catch (IOException e) { if (isLogFine) { - LOGGER.log(Level.FINEST, - "AsyncQueueWriter.write exception. connection=" + - nioConnection + " record=" + queueRecord, e); + LOGGER.trace("AsyncQueueWriter.write exception. connection={} record={}", nioConnection, queueRecord, e); } onWriteFailure(nioConnection, queueRecord, e); @@ -319,7 +317,7 @@ public void write( */ @Override public AsyncResult processAsync(final Context context) { - final boolean isLogFine = LOGGER.isLoggable(Level.FINEST); + final boolean isLogFine = LOGGER.isTraceEnabled(); final NIOConnection nioConnection = (NIOConnection) context.getConnection(); if (!nioConnection.isOpen()) { return AsyncResult.COMPLETE; @@ -419,9 +417,7 @@ public AsyncResult processAsync(final Context context) { return result; } catch (IOException e) { if (isLogFine) { - LOGGER.log(Level.FINEST, "AsyncQueueWriter.processAsync " - + "exception connection=" + nioConnection + " peekRecord=" + - queueRecord, e); + LOGGER.trace("AsyncQueueWriter.processAsync exception connection={} peekRecord={}", nioConnection, queueRecord, e); } onWriteFailure(nioConnection, queueRecord, e); } @@ -431,7 +427,7 @@ public AsyncResult processAsync(final Context context) { private static void finishQueueRecord(final NIOConnection nioConnection, final AsyncWriteQueueRecord queueRecord) { - final boolean isLogFine = LOGGER.isLoggable(Level.FINEST); + final boolean isLogFine = LOGGER.isTraceEnabled(); if (isLogFine) { doFineLog("AsyncQueueWriter.processAsync finished " @@ -455,10 +451,8 @@ private static WritableMessage cloneRecordIfNeeded( final MessageCloner cloner, final WritableMessage message) { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, - "AsyncQueueWriter.write clone. connection={0} cloner={1} size={2}", - new Object[] {connection, cloner, message.remaining()}); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("AsyncQueueWriter.write clone. connection={} cloner={} size={}", connection, cloner, message.remaining()); } return cloner == null ? message : cloner.clone(connection, message); @@ -486,7 +480,7 @@ public final boolean isReady(final Connection connection) { } private static void doFineLog(final String msg, final Object... params) { - LOGGER.log(Level.FINEST, msg, params); + LOGGER.trace(msg, params); } /** diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/DefaultSelectionKeyHandler.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/DefaultSelectionKeyHandler.java index 6dce817bae..b97a960c4c 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/DefaultSelectionKeyHandler.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/DefaultSelectionKeyHandler.java @@ -39,13 +39,15 @@ */ package org.glassfish.grizzly.nio; -import org.glassfish.grizzly.Grizzly; -import org.glassfish.grizzly.IOEvent; import java.io.IOException; import java.nio.channels.SelectionKey; import java.util.Arrays; -import java.util.logging.Level; -import java.util.logging.Logger; + +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.IOEvent; +import org.slf4j.Logger; + + /** * @@ -90,15 +92,15 @@ public final class DefaultSelectionKeyHandler implements SelectionKeyHandler { @Override public void onKeyRegistered(SelectionKey key) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "KEY IS REGISTERED: {0}", key); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("KEY IS REGISTERED: {}", key); } } @Override public void onKeyDeregistered(SelectionKey key) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "KEY IS DEREGISTERED: {0}", key); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("KEY IS DEREGISTERED: {}", key); } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/DefaultSelectorHandler.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/DefaultSelectorHandler.java index 43981843a4..50365843f4 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/DefaultSelectorHandler.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/DefaultSelectorHandler.java @@ -45,16 +45,16 @@ import java.nio.channels.SelectableChannel; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; -import java.util.*; +import java.util.Queue; +import java.util.Set; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; import org.glassfish.grizzly.utils.Futures; -import org.glassfish.grizzly.utils.JdkVersion; +import org.slf4j.Logger; /** * Default implementation of NIO SelectorHandler @@ -496,7 +496,7 @@ public boolean run(final SelectorRunner selectorRunner) throws IOException { completionHandler.completed(task); } } catch (Throwable t) { - logger.log(Level.FINEST, "doExecutePendiongIO failed.", t); + logger.trace("doExecutePendiongIO failed.", t); if (completionHandler != null) { completionHandler.failed(t); diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/GracefulShutdownRunner.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/GracefulShutdownRunner.java index 81f95b9d90..770abbae86 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/GracefulShutdownRunner.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/GracefulShutdownRunner.java @@ -47,14 +47,13 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.GracefulShutdownListener; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.ShutdownContext; import org.glassfish.grizzly.Transport; import org.glassfish.grizzly.localization.LogMessages; +import org.slf4j.Logger; class GracefulShutdownRunner implements Runnable { private static final Logger LOGGER = Grizzly.logger(GracefulShutdownRunner.class); @@ -107,18 +106,13 @@ public void run() { if (gracePeriod <= 0) { shutdownLatch.await(); } else { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_GRACEFULSHUTDOWN_MSG( - transport.getName() + '[' + Integer.toHexString(hashCode()) + ']', - gracePeriod, timeUnit)); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_GRACEFULSHUTDOWN_MSG(transport.getName() + '[' + Integer.toHexString(hashCode()) + ']', gracePeriod, timeUnit)); } final boolean result = shutdownLatch.await(gracePeriod, timeUnit); if (!result) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_GRACEFULSHUTDOWN_EXCEEDED( - transport.getName() + '[' + Integer.toHexString(hashCode()) + ']')); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_GRACEFULSHUTDOWN_EXCEEDED(transport.getName() + '[' + Integer.toHexString(hashCode()) + ']')); } if (!contexts.isEmpty()) { for (GracefulShutdownListener l : contexts.values()) { @@ -128,8 +122,8 @@ public void run() { } } } catch (InterruptedException ie) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.warning(LogMessages.WARNING_GRIZZLY_GRACEFULSHUTDOWN_INTERRUPTED()); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_GRACEFULSHUTDOWN_INTERRUPTED()); } if (!contexts.isEmpty()) { for (GracefulShutdownListener l : contexts.values()) { diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOConnection.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOConnection.java index 9bb0d6da38..4a42f58d99 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOConnection.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOConnection.java @@ -55,8 +55,6 @@ import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.CloseReason; @@ -89,6 +87,7 @@ import org.glassfish.grizzly.utils.DataStructures; import org.glassfish.grizzly.utils.Futures; import org.glassfish.grizzly.utils.NullaryFunction; +import org.slf4j.Logger; /** * Common {@link Connection} implementation for Java NIO Connections. @@ -569,7 +568,7 @@ protected void closeGracefully0( CloseReason closeReason) { if (isCloseScheduled.compareAndSet(false, true)) { - if (LOGGER.isLoggable(Level.FINEST)) { + if (LOGGER.isTraceEnabled()) { // replace close reason: clone the original value and add stacktrace closeReason = new CloseReason(closeReason.getType(), new IOException("Connection is closed at", @@ -612,7 +611,7 @@ protected void terminate0(final CompletionHandler completionHandler, isCloseScheduled.set(true); if (closeReasonUpdater.compareAndSet(this, null, reason)) { - if (LOGGER.isLoggable(Level.FINEST)) { + if (LOGGER.isTraceEnabled()) { // replace close reason: clone the original value and add stacktrace this.closeReason = new CloseReason(reason.getType(), new IOException("Connection is closed at", @@ -631,7 +630,7 @@ public boolean run() { try { doClose(); } catch (IOException e) { - LOGGER.log(Level.FINE, "Error during connection close", e); + LOGGER.debug("Error during connection close", e); } return true; @@ -1103,7 +1102,7 @@ public ProcessorState(Processor processor, Object state) { private static final class StaticMapAccessor { static { - Grizzly.logger(StaticMapAccessor.class).fine("Map is going to " + Grizzly.logger(StaticMapAccessor.class).debug("Map is going to " + "be used as Connection<->ProcessorState storage"); } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOTransport.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOTransport.java index 50265801cf..5ba35b3c98 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOTransport.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/NIOTransport.java @@ -49,8 +49,6 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.AbstractTransport; import org.glassfish.grizzly.Connection; @@ -74,6 +72,7 @@ import org.glassfish.grizzly.threadpool.GrizzlyExecutorService; import org.glassfish.grizzly.threadpool.ThreadPoolConfig; import org.glassfish.grizzly.utils.Futures; +import org.slf4j.Logger; /** * @@ -417,8 +416,7 @@ public void start() throws IOException { try { State currentState = state.getState(); if (currentState != State.STOPPED) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_TRANSPORT_NOT_STOP_STATE_EXCEPTION()); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_TRANSPORT_NOT_STOP_STATE_EXCEPTION()); return; } @@ -455,9 +453,7 @@ public void start() throws IOException { .setMaxPoolSize(selectorRunnersCnt) .setPoolName("grizzly-nio-kernel"); } else if (kernelPoolConfig.getMaxPoolSize() < selectorRunnersCnt) { - LOGGER.log(Level.INFO, "Adjusting kernel thread pool to max " - + "size {0} to handle configured number of SelectorRunners", - selectorRunnersCnt); + LOGGER.info("Adjusting kernel thread pool to max size {} to handle configured number of SelectorRunners", selectorRunnersCnt); kernelPoolConfig.setCorePoolSize(selectorRunnersCnt) .setMaxPoolSize(selectorRunnersCnt); } @@ -656,8 +652,7 @@ public void pause() { lock.lock(); try { if (state.getState() != State.STARTED) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_TRANSPORT_NOT_START_STATE_EXCEPTION()); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_TRANSPORT_NOT_START_STATE_EXCEPTION()); return; } state.setState(State.PAUSING); @@ -682,8 +677,7 @@ public void resume() { lock.lock(); try { if (state.getState() != State.PAUSED) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_TRANSPORT_NOT_PAUSE_STATE_EXCEPTION()); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_TRANSPORT_NOT_PAUSE_STATE_EXCEPTION()); return; } state.setState(State.STARTING); diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/SelectionKeyHandlerInitializer.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/SelectionKeyHandlerInitializer.java index bf7412d726..12c8e43fec 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/SelectionKeyHandlerInitializer.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/SelectionKeyHandlerInitializer.java @@ -40,9 +40,7 @@ package org.glassfish.grizzly.nio; import org.glassfish.grizzly.Grizzly; - -import java.util.logging.Level; -import java.util.logging.Logger; +import org.slf4j.Logger; class SelectionKeyHandlerInitializer { @@ -61,13 +59,11 @@ static SelectionKeyHandler initHandler() { SelectionKeyHandler.class.getClassLoader()); return handlerClass.newInstance(); } catch (Exception e) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.log(Level.SEVERE, - "Unable to load or create a new instance of SelectionKeyHandler {0}. Cause: {1}", - new Object[]{className, e.getMessage()}); + if (LOGGER.isErrorEnabled()) { + LOGGER.error("Unable to load or create a new instance of SelectionKeyHandler {}. Cause: {}", className, e.getMessage()); } - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, e.toString(), e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(e.toString(), e); } return new DefaultSelectionKeyHandler(); } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/SelectorRunner.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/SelectorRunner.java index 11b02e42c9..e05a7fea89 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/SelectorRunner.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/SelectorRunner.java @@ -40,11 +40,6 @@ package org.glassfish.grizzly.nio; -import org.glassfish.grizzly.Connection; -import org.glassfish.grizzly.Grizzly; -import org.glassfish.grizzly.IOEvent; -import org.glassfish.grizzly.IOStrategy; -import org.glassfish.grizzly.Transport.State; import java.io.IOException; import java.nio.channels.CancelledKeyException; import java.nio.channels.ClosedSelectorException; @@ -59,15 +54,21 @@ import java.util.Set; import java.util.WeakHashMap; import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; + +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.IOEvent; +import org.glassfish.grizzly.IOStrategy; +import org.glassfish.grizzly.Transport.State; import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.threadpool.Threads; import org.glassfish.grizzly.utils.StateHolder; +import org.slf4j.Logger; +import org.slf4j.event.Level; /** * Class is responsible for processing certain (single) {@link SelectorHandler} @@ -75,9 +76,9 @@ * @author Alexey Stashok */ public final class SelectorRunner implements Runnable { - private final static Logger LOGGER = Grizzly.logger(SelectorRunner.class); - - private final static String THREAD_MARKER = " SelectorRunner"; + private static final Logger LOGGER = Grizzly.logger(SelectorRunner.class); + + private static final String THREAD_MARKER = " SelectorRunner"; private final NIOTransport transport; private final AtomicReference stateHolder; @@ -138,7 +139,7 @@ private void wakeupSelector() { try { localSelector.wakeup(); } catch (Exception e) { - LOGGER.log(Level.FINE, "Error during selector wakeup", e); + LOGGER.debug("Error during selector wakeup", e); } } } @@ -197,8 +198,7 @@ public void postpone() { public synchronized void start() { if (!stateHolder.compareAndSet(State.STOPPED, State.STARTING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_SELECTOR_RUNNER_NOT_IN_STOPPED_STATE_EXCEPTION()); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_SELECTOR_RUNNER_NOT_IN_STOPPED_STATE_EXCEPTION()); return; } @@ -361,13 +361,13 @@ protected boolean doSelect() { dropConnectionDueToException(key, "Selector was unexpectedly closed", e, - Level.SEVERE, Level.FINE); + Level.ERROR, Level.DEBUG); } catch (Exception e) { dropConnectionDueToException(key, "doSelect exception", e, - Level.SEVERE, Level.FINE); + Level.ERROR, Level.DEBUG); } catch (Throwable t) { - LOGGER.log(Level.SEVERE,"doSelect exception", t); + LOGGER.error("doSelect exception", t); transport.notifyTransportError(t); } @@ -386,10 +386,10 @@ private boolean iterateKeys() { } } catch (IOException e) { keyReadyOps = 0; - dropConnectionDueToException(key, "Unexpected IOException. Channel " + key.channel() + " will be closed.", e, Level.WARNING, Level.FINE); + dropConnectionDueToException(key, "Unexpected IOException. Channel " + key.channel() + " will be closed.", e, Level.WARN, Level.DEBUG); } catch (CancelledKeyException e) { keyReadyOps = 0; - dropConnectionDueToException(key, "Unexpected CancelledKeyException. Channel " + key.channel() + " will be closed.", e, Level.FINE, Level.FINE); + dropConnectionDueToException(key, "Unexpected CancelledKeyException. Channel " + key.channel() + " will be closed.", e, Level.DEBUG, Level.DEBUG); } } return true; @@ -462,7 +462,7 @@ private void dropConnectionDueToException(final SelectionKey key, final Exception e, final Level runLogLevel, final Level stoppedLogLevel) { if (isRunning()) { - LOGGER.log(runLogLevel, description, e); + LOGGER.atLevel(runLogLevel).log(description, e); if (key != null) { try { @@ -477,14 +477,13 @@ private void dropConnectionDueToException(final SelectionKey key, channel.close(); } } catch (IOException cancelException) { - LOGGER.log(Level.FINE, "IOException during cancelling key", - cancelException); + LOGGER.debug("IOException during cancelling key", cancelException); } } transport.notifyTransportError(e); } else { - LOGGER.log(stoppedLogLevel, description, e); + LOGGER.atLevel(stoppedLogLevel).log(description, e); } } @@ -517,7 +516,7 @@ protected final void switchToNewSelector() throws IOException { nioConnection.onSelectionKeyUpdated(newSelectionKey); } catch (Exception e) { - LOGGER.log(Level.FINE, "Error switching channel to a new selector", e); + LOGGER.debug("Error switching channel to a new selector", e); } } } @@ -583,8 +582,8 @@ final SelectionKey checkIfSpinnedKey(final SelectionKey key) { } final void workaroundSelectorSpin() throws IOException { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Workaround selector spin. selector={0}", getSelector()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Workaround selector spin. selector={}", getSelector()); } spinnedSelectorsHistory.put(getSelector(), System.currentTimeMillis()); diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/tmpselectors/TemporarySelectorIO.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/tmpselectors/TemporarySelectorIO.java index fd9822e7ba..537a69bfcf 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/tmpselectors/TemporarySelectorIO.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/tmpselectors/TemporarySelectorIO.java @@ -40,16 +40,15 @@ package org.glassfish.grizzly.nio.tmpselectors; -import org.glassfish.grizzly.Grizzly; - import java.net.SocketAddress; import java.nio.channels.SelectionKey; import java.nio.channels.Selector; -import java.util.logging.Level; + +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.Reader; import org.glassfish.grizzly.Writer; -import java.util.logging.Logger; import org.glassfish.grizzly.localization.LogMessages; +import org.slf4j.Logger; /** * @@ -99,9 +98,7 @@ protected void recycleTemporaryArtifacts(Selector selector, try { selectionKey.cancel(); } catch (Exception e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_TEMPORARY_SELECTOR_IO_CANCEL_KEY_EXCEPTION(selectionKey), - e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_TEMPORARY_SELECTOR_IO_CANCEL_KEY_EXCEPTION(selectionKey), e); } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/tmpselectors/TemporarySelectorPool.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/tmpselectors/TemporarySelectorPool.java index fa73805f39..4d33033704 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/tmpselectors/TemporarySelectorPool.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/tmpselectors/TemporarySelectorPool.java @@ -40,7 +40,6 @@ package org.glassfish.grizzly.nio.tmpselectors; -import org.glassfish.grizzly.Grizzly; import java.io.IOException; import java.nio.channels.Selector; import java.nio.channels.spi.SelectorProvider; @@ -48,10 +47,11 @@ import java.util.concurrent.ConcurrentLinkedQueue; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; + +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.nio.Selectors; +import org.slf4j.Logger; /** * @@ -128,15 +128,12 @@ public Selector poll() throws IOException { try { selector = Selectors.newSelector(selectorProvider); } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_TEMPORARY_SELECTOR_POOL_CREATE_SELECTOR_EXCEPTION(), - e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_TEMPORARY_SELECTOR_POOL_CREATE_SELECTOR_EXCEPTION(), e); } final int missesCount = missesCounter.incrementAndGet(); if (missesCount % MISS_THRESHOLD == 0) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_TEMPORARY_SELECTOR_POOL_MISSES_EXCEPTION(missesCount, maxPoolSize)); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_TEMPORARY_SELECTOR_POOL_MISSES_EXCEPTION(missesCount, maxPoolSize)); } } @@ -187,9 +184,8 @@ private void closeSelector(Selector selector) { try { selector.close(); } catch (IOException e) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "TemporarySelectorFactory: error " + - "occurred when trying to close the Selector", e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("TemporarySelectorFactory: error occurred when trying to close the Selector", e); } } } @@ -199,15 +195,11 @@ private Selector checkSelector(final Selector selector) { selector.selectNow(); return selector; } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_TEMPORARY_SELECTOR_POOL_SELECTOR_FAILURE_EXCEPTION(), - e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_TEMPORARY_SELECTOR_POOL_SELECTOR_FAILURE_EXCEPTION(), e); try { return Selectors.newSelector(selectorProvider); } catch (IOException ee) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_TEMPORARY_SELECTOR_POOL_CREATE_SELECTOR_EXCEPTION(), - ee); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_TEMPORARY_SELECTOR_POOL_CREATE_SELECTOR_EXCEPTION(), ee); } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOAsyncQueueWriter.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOAsyncQueueWriter.java index 900ba6e71f..7d79f2662c 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOAsyncQueueWriter.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOAsyncQueueWriter.java @@ -47,8 +47,7 @@ import java.util.ArrayList; import java.util.Deque; import java.util.Iterator; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.CloseReason; import org.glassfish.grizzly.CloseType; @@ -69,6 +68,7 @@ import org.glassfish.grizzly.nio.DirectByteBufferRecord; import org.glassfish.grizzly.nio.NIOConnection; import org.glassfish.grizzly.nio.NIOTransport; +import org.slf4j.Logger; /** * The TCP transport {@link AsyncQueueWriter} implementation, based on @@ -77,7 +77,7 @@ * @author Alexey Stashok */ public final class TCPNIOAsyncQueueWriter extends AbstractNIOAsyncQueueWriter { - private final static Logger LOGGER = Grizzly.logger(TCPNIOAsyncQueueWriter.class); + private static final Logger LOGGER = Grizzly.logger(TCPNIOAsyncQueueWriter.class); public TCPNIOAsyncQueueWriter(final NIOTransport transport) { super(transport); @@ -160,13 +160,8 @@ private RecordWriteResult writeCompositeRecord(final NIOConnection connection, int written = 0; - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, - "writeCompositeRecord connection={0}, queueRecord={1}," - + " queueRecord.remaining={2}," - + " queueRecord.queue.size()={3}", - new Object[] {connection, queueRecord, queueRecord.remaining(), - queueRecord.queue.size()}); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("writeCompositeRecord connection={}, queueRecord={}, queueRecord.remaining={}, queueRecord.queue.size()={}", connection, queueRecord, queueRecord.remaining(), queueRecord.queue.size()); } if (queueRecord.size > 0) { @@ -416,10 +411,8 @@ public CompositeQueueRecord(final Connection connection) { } public void append(final AsyncWriteQueueRecord queueRecord) { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, - "CompositeQueueRecord.append. connection={0}, this={1}, comp-size={2}, elem-count={3}, queueRecord={4}, newrec-size={5}, isEmpty={6}", - new Object[] {connection, this, size, queue.size(), queueRecord, queueRecord.remaining(), queueRecord.isUncountable()}); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("CompositeQueueRecord.append. connection={}, this={}, comp-size={}, elem-count={}, queueRecord={}, newrec-size={}, isEmpty={}", connection, this, size, queue.size(), queueRecord, queueRecord.remaining(), queueRecord.isUncountable()); } size += queueRecord.remaining(); diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOConnection.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOConnection.java index ab4106e2e3..d0edcc899e 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOConnection.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOConnection.java @@ -46,15 +46,21 @@ import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.*; + +import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.CloseReason; +import org.glassfish.grizzly.Closeable; +import org.glassfish.grizzly.CompletionHandler; +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.WriteHandler; import org.glassfish.grizzly.asyncqueue.AsyncQueueWriter; import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.nio.NIOConnection; import org.glassfish.grizzly.nio.SelectorRunner; import org.glassfish.grizzly.utils.Holder; import org.glassfish.grizzly.utils.NullaryFunction; +import org.slf4j.Logger; /** * {@link org.glassfish.grizzly.Connection} implementation @@ -168,9 +174,7 @@ public int getReadBufferSize() { try { readBufferSize = ((SocketChannel) channel).socket().getReceiveBufferSize(); } catch (IOException e) { - LOGGER.log(Level.FINE, - LogMessages.WARNING_GRIZZLY_CONNECTION_GET_READBUFFER_SIZE_EXCEPTION(), - e); + LOGGER.debug(LogMessages.WARNING_GRIZZLY_CONNECTION_GET_READBUFFER_SIZE_EXCEPTION(), e); readBufferSize = 0; } @@ -191,9 +195,7 @@ public void setReadBufferSize(final int readBufferSize) { this.readBufferSize = readBufferSize; } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_CONNECTION_SET_READBUFFER_SIZE_EXCEPTION(), - e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_CONNECTION_SET_READBUFFER_SIZE_EXCEPTION(), e); } } } @@ -210,9 +212,7 @@ public int getWriteBufferSize() { try { writeBufferSize = ((SocketChannel) channel).socket().getSendBufferSize(); } catch (IOException e) { - LOGGER.log(Level.FINE, - LogMessages.WARNING_GRIZZLY_CONNECTION_GET_WRITEBUFFER_SIZE_EXCEPTION(), - e); + LOGGER.debug(LogMessages.WARNING_GRIZZLY_CONNECTION_GET_WRITEBUFFER_SIZE_EXCEPTION(), e); writeBufferSize = 0; } @@ -232,9 +232,7 @@ public void setWriteBufferSize(int writeBufferSize) { } this.writeBufferSize = writeBufferSize; } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_CONNECTION_SET_WRITEBUFFER_SIZE_EXCEPTION(), - e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_CONNECTION_SET_WRITEBUFFER_SIZE_EXCEPTION(), e); } } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOConnectorHandler.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOConnectorHandler.java index 108d229167..c20aa78178 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOConnectorHandler.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOConnectorHandler.java @@ -44,10 +44,18 @@ import java.net.SocketAddress; import java.nio.channels.SelectionKey; import java.nio.channels.SocketChannel; -import java.util.concurrent.*; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.*; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.glassfish.grizzly.AbstractSocketConnectorHandler; +import org.glassfish.grizzly.CompletionHandler; +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.Context; +import org.glassfish.grizzly.EmptyCompletionHandler; +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.GrizzlyFuture; +import org.glassfish.grizzly.IOEvent; +import org.glassfish.grizzly.IOEventLifeCycleListener; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.ReadyFutureImpl; import org.glassfish.grizzly.nio.NIOChannelDistributor; @@ -55,6 +63,7 @@ import org.glassfish.grizzly.nio.SelectionKeyHandler; import org.glassfish.grizzly.utils.Exceptions; import org.glassfish.grizzly.utils.Futures; +import org.slf4j.Logger; /** * TCP NIO transport client side ConnectorHandler implementation @@ -194,8 +203,7 @@ public void completed(RegisterChannelResult result) { try { connection.onConnect(); } catch (Exception e) { - LOGGER.log(Level.FINE, "Exception happened, when " - + "trying to connect the channel", e); + LOGGER.debug("Exception happened, when trying to connect the channel", e); } } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOServerConnection.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOServerConnection.java index d2d380933c..2e47f3036d 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOServerConnection.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOServerConnection.java @@ -48,9 +48,15 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.*; + +import org.glassfish.grizzly.CloseReason; +import org.glassfish.grizzly.Closeable; +import org.glassfish.grizzly.CompletionHandler; +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.EmptyCompletionHandler; +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.GrizzlyFuture; +import org.glassfish.grizzly.IOEvent; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; import org.glassfish.grizzly.nio.RegisterChannelResult; @@ -59,6 +65,7 @@ import org.glassfish.grizzly.utils.Exceptions; import org.glassfish.grizzly.utils.Holder; import org.glassfish.grizzly.utils.NullaryFunction; +import org.slf4j.Logger; /** * @@ -353,8 +360,7 @@ public void completed(RegisterChannelResult result) { transport.fireIOEvent(IOEvent.ACCEPTED, connection, null); } } catch (Exception e) { - LOGGER.log(Level.FINE, "Exception happened, when " - + "trying to accept the connection", e); + LOGGER.debug("Exception happened, when trying to accept the connection", e); } } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOTransport.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOTransport.java index ee1cc1085e..3e598ebfc1 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOTransport.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOTransport.java @@ -56,18 +56,46 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.*; -import org.glassfish.grizzly.asyncqueue.*; + +import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.CloseReason; +import org.glassfish.grizzly.CloseType; +import org.glassfish.grizzly.CompletionHandler; +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.Context; +import org.glassfish.grizzly.EmptyCompletionHandler; +import org.glassfish.grizzly.FileTransfer; +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.GrizzlyFuture; +import org.glassfish.grizzly.IOEvent; +import org.glassfish.grizzly.IOEventLifeCycleListener; +import org.glassfish.grizzly.PortRange; +import org.glassfish.grizzly.Processor; +import org.glassfish.grizzly.ProcessorExecutor; +import org.glassfish.grizzly.ProcessorSelector; +import org.glassfish.grizzly.Reader; +import org.glassfish.grizzly.StandaloneProcessor; +import org.glassfish.grizzly.StandaloneProcessorSelector; +import org.glassfish.grizzly.WriteResult; +import org.glassfish.grizzly.Writer; +import org.glassfish.grizzly.asyncqueue.AsyncQueueEnabledTransport; +import org.glassfish.grizzly.asyncqueue.AsyncQueueIO; +import org.glassfish.grizzly.asyncqueue.AsyncQueueReader; +import org.glassfish.grizzly.asyncqueue.AsyncQueueWriter; +import org.glassfish.grizzly.asyncqueue.WritableMessage; import org.glassfish.grizzly.filterchain.Filter; import org.glassfish.grizzly.filterchain.FilterChainEnabledTransport; import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.memory.CompositeBuffer; import org.glassfish.grizzly.monitoring.MonitoringUtils; -import org.glassfish.grizzly.nio.*; +import org.glassfish.grizzly.nio.ChannelConfigurator; +import org.glassfish.grizzly.nio.NIOConnection; +import org.glassfish.grizzly.nio.NIOTransport; +import org.glassfish.grizzly.nio.RegisterChannelResult; +import org.glassfish.grizzly.nio.SelectorRunner; import org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorIO; import org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorsEnabledTransport; +import org.slf4j.Logger; /** * TCP Transport NIO implementation @@ -174,9 +202,7 @@ protected void listen() { try { listenServerConnection(serverConnection); } catch (Exception e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_TRANSPORT_START_SERVER_CONNECTION_EXCEPTION(serverConnection), - e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_TRANSPORT_START_SERVER_CONNECTION_EXCEPTION(serverConnection), e); } } } @@ -278,9 +304,7 @@ public void unbind(Connection connection) { future.get(1000, TimeUnit.MILLISECONDS); future.recycle(false); } catch (Exception e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_TRANSPORT_UNBINDING_CONNECTION_EXCEPTION(connection), - e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_TRANSPORT_UNBINDING_CONNECTION_EXCEPTION(connection), e); } } } finally { @@ -297,9 +321,7 @@ public void unbindAll() { try { unbind(serverConnection); } catch (Exception e) { - LOGGER.log(Level.FINE, - "Exception occurred when closing server connection: " - + serverConnection, e); + LOGGER.debug("Exception occurred when closing server connection: {}", serverConnection, e); } } @@ -388,8 +410,7 @@ protected void closeConnection(final Connection connection) throws IOException { try { nioChannel.close(); } catch (IOException e) { - LOGGER.log(Level.FINE, - "TCPNIOTransport.closeChannel exception", e); + LOGGER.debug("TCPNIOTransport.closeChannel exception", e); } } @@ -514,10 +535,8 @@ public void fireIOEvent(final IOEvent ioEvent, try { rebindAddress(connection); } catch (IOException ioe) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.log(Level.SEVERE, - LogMessages.SEVERE_GRIZZLY_TRANSPORT_LISTEN_INTERRUPTED_REBIND_EXCEPTION(connection.getLocalAddress()), - ioe); + if (LOGGER.isErrorEnabled()) { + LOGGER.error(LogMessages.SEVERE_GRIZZLY_TRANSPORT_LISTEN_INTERRUPTED_REBIND_EXCEPTION(connection.getLocalAddress()), ioe); } } } catch (IOException e) { @@ -598,8 +617,8 @@ public Buffer read(final Connection connection, Buffer buffer) read = buffer.position(); tcpConnection.onRead(buffer, read); } catch (Exception e) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "TCPNIOConnection (" + connection + ") (allocated) read exception", e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("TCPNIOConnection ({}) (allocated) read exception", connection, e); } read = -1; @@ -619,8 +638,8 @@ public Buffer read(final Connection connection, Buffer buffer) try { read = TCPNIOUtils.readBuffer(tcpConnection, buffer); } catch (Exception e) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "TCPNIOConnection (" + connection + ") (existing) read exception", e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("TCPNIOConnection ({}) (existing) read exception", connection, e); } read = -1; } @@ -766,8 +785,7 @@ public void preConfigure(NIOTransport transport, try { socket.setReuseAddress(reuseAddress); } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_SOCKET_REUSEADDRESS_EXCEPTION(reuseAddress), e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_SOCKET_REUSEADDRESS_EXCEPTION(reuseAddress), e); } } else { // ServerSocketChannel final ServerSocketChannel serverSocketChannel @@ -779,8 +797,7 @@ public void preConfigure(NIOTransport transport, try { serverSocket.setReuseAddress(tcpNioTransport.isReuseAddress()); } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_SOCKET_REUSEADDRESS_EXCEPTION(tcpNioTransport.isReuseAddress()), e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_SOCKET_REUSEADDRESS_EXCEPTION(tcpNioTransport.isReuseAddress()), e); } } } @@ -800,31 +817,28 @@ public void postConfigure(final NIOTransport transport, socket.setSoLinger(true, linger); } } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_SOCKET_LINGER_EXCEPTION(linger), e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_SOCKET_LINGER_EXCEPTION(linger), e); } final boolean keepAlive = tcpNioTransport.isKeepAlive(); try { socket.setKeepAlive(keepAlive); } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_SOCKET_KEEPALIVE_EXCEPTION(keepAlive), e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_SOCKET_KEEPALIVE_EXCEPTION(keepAlive), e); } final boolean tcpNoDelay = tcpNioTransport.isTcpNoDelay(); try { socket.setTcpNoDelay(tcpNoDelay); } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_SOCKET_TCPNODELAY_EXCEPTION(tcpNoDelay), e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_SOCKET_TCPNODELAY_EXCEPTION(tcpNoDelay), e); } final int clientSocketSoTimeout = tcpNioTransport.getClientSocketSoTimeout(); try { socket.setSoTimeout(clientSocketSoTimeout); } catch (IOException e) { - LOGGER.log(Level.WARNING, LogMessages.WARNING_GRIZZLY_SOCKET_TIMEOUT_EXCEPTION(tcpNioTransport.getClientSocketSoTimeout()), e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_SOCKET_TIMEOUT_EXCEPTION(tcpNioTransport.getClientSocketSoTimeout()), e); } } else { //ServerSocketChannel final ServerSocketChannel serverSocketChannel = @@ -834,8 +848,7 @@ public void postConfigure(final NIOTransport transport, try { serverSocket.setSoTimeout(tcpNioTransport.getServerSocketSoTimeout()); } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_SOCKET_TIMEOUT_EXCEPTION(tcpNioTransport.getServerSocketSoTimeout()), e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_SOCKET_TIMEOUT_EXCEPTION(tcpNioTransport.getServerSocketSoTimeout()), e); } } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOUtils.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOUtils.java index f8457875e4..1655ba8a7c 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOUtils.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/TCPNIOUtils.java @@ -44,8 +44,7 @@ import java.io.IOException; import java.nio.ByteBuffer; import java.nio.channels.SocketChannel; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.memory.BufferArray; import org.glassfish.grizzly.memory.Buffers; @@ -54,6 +53,7 @@ import org.glassfish.grizzly.memory.MemoryManager; import org.glassfish.grizzly.nio.DirectByteBufferRecord; import org.glassfish.grizzly.utils.Exceptions; +import org.slf4j.Logger; /** * TCP NIO Transport utils @@ -87,10 +87,8 @@ public static int writeCompositeBuffer(final TCPNIOConnection connection, ? flushByteBuffers(socketChannel, ioRecord.getArray(), 0, arraySize) : flushByteBuffer(socketChannel, ioRecord.getArray()[0]); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (composite) write {1} bytes", new Object[]{ - connection, written - }); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("TCPNIOConnection ({}) (composite) write {} bytes", connection, written); } } finally { ioRecord.release(); @@ -137,10 +135,8 @@ public static int writeSimpleBuffer(final TCPNIOConnection connection, } Buffers.setPositionLimit(buffer, oldPos + written, oldLim); - if(LOGGER.isLoggable(Level.FINE)) - LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (plain) write {1} bytes", new Object[] { - connection, written - }); + if(LOGGER.isDebugEnabled()) + LOGGER.debug("TCPNIOConnection ({}) (plain) write {} bytes", connection, written); return written; } @@ -271,10 +267,8 @@ public static Buffer allocateAndReadBuffer(final TCPNIOConnection connection) buffer = Buffers.EMPTY_BUFFER; } - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (allocated) read {1} bytes", new Object[]{ - connection, read - }); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("TCPNIOConnection ({}) (allocated) read {} bytes", connection, read); } return buffer; } @@ -305,10 +299,8 @@ public static int readCompositeBuffer(final TCPNIOConnection connection, buffer.position(oldPos + read); } - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, composite) read {1} bytes", new Object[]{ - connection, read - }); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("TCPNIOConnection ({}) (nonallocated, composite) read {} bytes", connection, read); } return read; @@ -329,10 +321,8 @@ public static int readSimpleBuffer(final TCPNIOConnection connection, buffer.position(oldPos + read); } - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "TCPNIOConnection ({0}) (nonallocated, simple) read {1} bytes", new Object[]{ - connection, read - }); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("TCPNIOConnection ({}) (nonallocated, simple) read {} bytes", connection, read); } return read; diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOConnection.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOConnection.java index 0f463b3d4f..2f376629f8 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOConnection.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOConnection.java @@ -53,8 +53,7 @@ import java.util.Iterator; import java.util.Map; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.ConnectionProbe; import org.glassfish.grizzly.Grizzly; @@ -67,6 +66,7 @@ import org.glassfish.grizzly.utils.Holder; import org.glassfish.grizzly.utils.JdkVersion; import org.glassfish.grizzly.utils.NullaryFunction; +import org.slf4j.Logger; /** * {@link org.glassfish.grizzly.Connection} implementation @@ -114,7 +114,7 @@ public class UDPNIOConnection extends NIOConnection { mkUnblock = membershipKeyClass.getDeclaredMethod("unblock", InetAddress.class); isInitialized = true; } catch (Throwable t) { - LOGGER.log(Level.WARNING, LogMessages.WARNING_GRIZZLY_CONNECTION_UDPMULTICASTING_EXCEPTIONE(), t); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_CONNECTION_UDPMULTICASTING_EXCEPTIONE(), t); } } @@ -526,9 +526,7 @@ public int getReadBufferSize() { try { readBufferSize = ((DatagramChannel) channel).socket().getReceiveBufferSize(); } catch (IOException e) { - LOGGER.log(Level.FINE, - LogMessages.WARNING_GRIZZLY_CONNECTION_GET_READBUFFER_SIZE_EXCEPTION(), - e); + LOGGER.debug(LogMessages.WARNING_GRIZZLY_CONNECTION_GET_READBUFFER_SIZE_EXCEPTION(), e); readBufferSize = 0; } @@ -549,9 +547,7 @@ public void setReadBufferSize(final int readBufferSize) { this.readBufferSize = readBufferSize; } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_CONNECTION_SET_READBUFFER_SIZE_EXCEPTION(), - e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_CONNECTION_SET_READBUFFER_SIZE_EXCEPTION(), e); } } } @@ -568,9 +564,7 @@ public int getWriteBufferSize() { try { writeBufferSize = ((DatagramChannel) channel).socket().getSendBufferSize(); } catch (IOException e) { - LOGGER.log(Level.FINE, - LogMessages.WARNING_GRIZZLY_CONNECTION_GET_WRITEBUFFER_SIZE_EXCEPTION(), - e); + LOGGER.debug(LogMessages.WARNING_GRIZZLY_CONNECTION_GET_WRITEBUFFER_SIZE_EXCEPTION(), e); writeBufferSize = 0; } @@ -590,9 +584,7 @@ public void setWriteBufferSize(int writeBufferSize) { } this.writeBufferSize = writeBufferSize; } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_CONNECTION_SET_WRITEBUFFER_SIZE_EXCEPTION(), - e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_CONNECTION_SET_WRITEBUFFER_SIZE_EXCEPTION(), e); } } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOConnectorHandler.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOConnectorHandler.java index c25b046e92..4e19cd0d56 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOConnectorHandler.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOConnectorHandler.java @@ -44,9 +44,18 @@ import java.net.DatagramSocket; import java.net.SocketAddress; import java.nio.channels.DatagramChannel; -import java.util.concurrent.*; -import java.util.logging.Logger; -import org.glassfish.grizzly.*; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + +import org.glassfish.grizzly.AbstractSocketConnectorHandler; +import org.glassfish.grizzly.CompletionHandler; +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.Context; +import org.glassfish.grizzly.EmptyCompletionHandler; +import org.glassfish.grizzly.GrizzlyFuture; +import org.glassfish.grizzly.IOEvent; +import org.glassfish.grizzly.IOEventLifeCycleListener; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.ReadyFutureImpl; import org.glassfish.grizzly.nio.NIOChannelDistributor; @@ -60,8 +69,6 @@ */ public class UDPNIOConnectorHandler extends AbstractSocketConnectorHandler { - private static final Logger LOGGER = Grizzly.logger(UDPNIOConnectorHandler.class); - protected boolean isReuseAddress; protected volatile long connectionTimeoutMillis = DEFAULT_CONNECTION_TIMEOUT; diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOServerConnection.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOServerConnection.java index 00919401ea..219877fffd 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOServerConnection.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOServerConnection.java @@ -44,12 +44,17 @@ import java.nio.channels.DatagramChannel; import java.nio.channels.SelectionKey; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.*; + +import org.glassfish.grizzly.CloseReason; +import org.glassfish.grizzly.Closeable; +import org.glassfish.grizzly.CompletionHandler; +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.Processor; +import org.glassfish.grizzly.ProcessorSelector; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.nio.RegisterChannelResult; import org.glassfish.grizzly.utils.Futures; +import org.slf4j.Logger; /** * Server {@link org.glassfish.grizzly.Connection} implementation @@ -114,8 +119,8 @@ protected void closeGracefully0( @Override protected void terminate0(final CompletionHandler completionHandler, final CloseReason closeReason) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine("UDPNIOServerConnection might be only closed by calling unbind()."); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("UDPNIOServerConnection might be only closed by calling unbind()."); } if (completionHandler != null) { diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOTransport.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOTransport.java index eb5a137224..08349e1f8c 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOTransport.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/nio/transport/UDPNIOTransport.java @@ -53,19 +53,48 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Lock; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.*; -import org.glassfish.grizzly.asyncqueue.*; + +import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.Closeable; +import org.glassfish.grizzly.CompletionHandler; +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.Context; +import org.glassfish.grizzly.EmptyCompletionHandler; +import org.glassfish.grizzly.FileTransfer; +import org.glassfish.grizzly.GracefulShutdownListener; +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.GrizzlyFuture; +import org.glassfish.grizzly.IOEvent; +import org.glassfish.grizzly.IOEventLifeCycleListener; +import org.glassfish.grizzly.PortRange; +import org.glassfish.grizzly.Processor; +import org.glassfish.grizzly.ProcessorExecutor; +import org.glassfish.grizzly.ProcessorSelector; +import org.glassfish.grizzly.ReadResult; +import org.glassfish.grizzly.Reader; +import org.glassfish.grizzly.StandaloneProcessor; +import org.glassfish.grizzly.StandaloneProcessorSelector; +import org.glassfish.grizzly.WriteResult; +import org.glassfish.grizzly.Writer; +import org.glassfish.grizzly.asyncqueue.AsyncQueueIO; +import org.glassfish.grizzly.asyncqueue.AsyncQueueReader; +import org.glassfish.grizzly.asyncqueue.AsyncQueueWriter; +import org.glassfish.grizzly.asyncqueue.WritableMessage; import org.glassfish.grizzly.filterchain.Filter; import org.glassfish.grizzly.filterchain.FilterChainEnabledTransport; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.memory.ByteBufferArray; import org.glassfish.grizzly.monitoring.MonitoringUtils; -import org.glassfish.grizzly.nio.*; +import org.glassfish.grizzly.nio.ChannelConfigurator; +import org.glassfish.grizzly.nio.DirectByteBufferRecord; +import org.glassfish.grizzly.nio.NIOConnection; +import org.glassfish.grizzly.nio.NIOTransport; +import org.glassfish.grizzly.nio.RegisterChannelResult; +import org.glassfish.grizzly.nio.SelectorRunner; import org.glassfish.grizzly.nio.tmpselectors.TemporarySelectorIO; import org.glassfish.grizzly.utils.Futures; +import org.slf4j.Logger; /** * UDP NIO transport implementation @@ -138,10 +167,7 @@ protected void listen() { try { serverConnection.register(); } catch (Exception e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_TRANSPORT_START_SERVER_CONNECTION_EXCEPTION( - serverConnection), - e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_TRANSPORT_START_SERVER_CONNECTION_EXCEPTION(serverConnection), e); } } } @@ -237,9 +263,7 @@ public void unbind(final Connection connection) { future.get(1000, TimeUnit.MILLISECONDS); future.recycle(false); } catch (Exception e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_TRANSPORT_UNBINDING_CONNECTION_EXCEPTION(connection), - e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_TRANSPORT_UNBINDING_CONNECTION_EXCEPTION(connection), e); } } } finally { @@ -256,10 +280,8 @@ public void unbindAll() { try { unbind(serverConnection); } catch (Exception e) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, - "Exception occurred when closing server connection: " - + serverConnection, e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Exception occurred when closing server connection: {}", serverConnection, e); } } } @@ -366,8 +388,7 @@ protected void closeConnection(final Connection connection) try { nioChannel.close(); } catch (IOException e) { - LOGGER.log(Level.FINE, - "UDPNIOTransport.closeChannel exception", e); + LOGGER.debug("UDPNIOTransport.closeChannel exception", e); } } @@ -713,8 +734,7 @@ public void preConfigure(NIOTransport transport, try { datagramSocket.setReuseAddress(udpNioTransport.isReuseAddress()); } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_SOCKET_REUSEADDRESS_EXCEPTION(udpNioTransport.isReuseAddress()), e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_SOCKET_REUSEADDRESS_EXCEPTION(udpNioTransport.isReuseAddress()), e); } } @@ -735,8 +755,7 @@ public void postConfigure(final NIOTransport transport, try { datagramSocket.setSoTimeout(soTimeout); } catch (IOException e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_SOCKET_TIMEOUT_EXCEPTION(soTimeout), e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_SOCKET_TIMEOUT_EXCEPTION(soTimeout), e); } } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLBaseFilter.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLBaseFilter.java index e4f8e3fb4b..20ee8819a2 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLBaseFilter.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLBaseFilter.java @@ -64,8 +64,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.logging.Filter; -import java.util.logging.Level; -import java.util.logging.Logger; + + import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult; @@ -103,6 +103,7 @@ import org.glassfish.grizzly.ssl.SSLConnectionContext.SslResult; import org.glassfish.grizzly.utils.DataStructures; import org.glassfish.grizzly.utils.Futures; +import org.slf4j.Logger; /** * SSL {@link Filter} to operate with SSL encrypted data. @@ -358,10 +359,8 @@ public NextAction handleRead(final FilterChainContext ctx) final FilterChain connectionFilterChain = sslCtx.getNewConnectionFilterChain(); sslCtx.setNewConnectionFilterChain(null); if (connectionFilterChain != null) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Applying new FilterChain after" - + "SSLHandshake. Connection={0} filterchain={1}", - new Object[]{connection, connectionFilterChain}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Applying new FilterChain after SSLHandshake. Connection={} filterchain={}", connection, connectionFilterChain); } connection.setProcessor(connectionFilterChain); @@ -519,7 +518,7 @@ protected Buffer wrapAll(final FilterChainContext ctx, // final SSLEngine sslEngine = sslCtx.getSslEngine(); // final Connection connection = ctx.getConnection(); // -// final boolean isLoggingFinest = LOGGER.isLoggable(Level.FINEST); +// final boolean isLoggingFinest = LOGGER.isTraceEnabled(); // try { // HandshakeStatus handshakeStatus = sslEngine.getHandshakeStatus(); // @@ -658,7 +657,7 @@ protected Buffer doHandshakeStep(final SSLConnectionContext sslCtx, final Connection connection = ctx.getConnection(); - final boolean isLoggingFinest = LOGGER.isLoggable(Level.FINEST); + final boolean isLoggingFinest = LOGGER.isTraceEnabled(); Buffer tmpInputToDispose = null; Buffer tmpNetBuffer = null; @@ -672,15 +671,14 @@ protected Buffer doHandshakeStep(final SSLConnectionContext sslCtx, while (true) { if (isLoggingFinest) { - LOGGER.log(Level.FINEST, "Loop Engine: {0} handshakeStatus={1}", - new Object[]{sslCtx.getSslEngine(), sslCtx.getSslEngine().getHandshakeStatus()}); + LOGGER.trace("Loop Engine: {} handshakeStatus={}", sslCtx.getSslEngine(), sslCtx.getSslEngine().getHandshakeStatus()); } switch (handshakeStatus) { case NEED_UNWRAP: { if (isLoggingFinest) { - LOGGER.log(Level.FINEST, "NEED_UNWRAP Engine: {0}", sslCtx.getSslEngine()); + LOGGER.trace("NEED_UNWRAP Engine: {}", sslCtx.getSslEngine()); } if (inputBuffer == null || !inputBuffer.hasRemaining()) { @@ -718,7 +716,7 @@ protected Buffer doHandshakeStep(final SSLConnectionContext sslCtx, case NEED_WRAP: { if (isLoggingFinest) { - LOGGER.log(Level.FINEST, "NEED_WRAP Engine: {0}", sslCtx.getSslEngine()); + LOGGER.trace("NEED_WRAP Engine: {}", sslCtx.getSslEngine()); } tmpNetBuffer = handshakeWrap( @@ -730,7 +728,7 @@ protected Buffer doHandshakeStep(final SSLConnectionContext sslCtx, case NEED_TASK: { if (isLoggingFinest) { - LOGGER.log(Level.FINEST, "NEED_TASK Engine: {0}", sslCtx.getSslEngine()); + LOGGER.trace("NEED_TASK Engine: {}", sslCtx.getSslEngine()); } executeDelegatedTask(sslCtx.getSslEngine()); handshakeStatus = sslCtx.getSslEngine().getHandshakeStatus(); @@ -818,8 +816,8 @@ protected void renegotiate(final SSLConnectionContext sslCtx, // of an obscure exception stack trace in the server's log. // Note that this probably will only work on Oracle's VM. if (e.toString().toLowerCase().contains("insecure renegotiation")) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.severe("Secure SSL/TLS renegotiation is not " + if (LOGGER.isErrorEnabled()) { + LOGGER.error("Secure SSL/TLS renegotiation is not " + "supported by the peer. This is most likely due" + " to the peer using an older SSL/TLS " + "implementation that does not implement RFC 5746."); @@ -848,8 +846,8 @@ private Buffer silentRehandshake(final FilterChainContext context, return doHandshakeSync( sslCtx, context, null, handshakeTimeoutMillis); } catch (Throwable t) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Error during graceful ssl connection close", t); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Error during graceful ssl connection close", t); } if (t instanceof SSLException) { @@ -876,8 +874,8 @@ private Buffer rehandshake(final FilterChainContext context, } catch (Throwable t) { notifyHandshakeFailed(c, t); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Error during re-handshaking", t); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Error during re-handshaking", t); } if (t instanceof SSLException) { @@ -1008,15 +1006,13 @@ private static X509Certificate[] extractX509Certs(final Certificate[] certs) { x509Certs[i] = (X509Certificate) cf.generateCertificate(stream); } catch(Exception ex) { - LOGGER.log(Level.INFO, - "Error translating cert " + certs[i], - ex); + LOGGER.info("Error translating cert {}", certs[i], ex); return null; } } - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Cert #{0} = {1}", new Object[] {i, x509Certs[i]}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Cert #{} = {}", i, x509Certs[i]); } } return x509Certs; @@ -1026,8 +1022,8 @@ private static Certificate[] getPeerCertificates(final SSLConnectionContext sslC try { return sslCtx.getSslEngine().getSession().getPeerCertificates(); } catch( Throwable t ) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE,"Error getting client certs", t); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Error getting client certs", t); } return null; } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLConnectionContext.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLConnectionContext.java index c3cbe5b636..e4f5dcc9cd 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLConnectionContext.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLConnectionContext.java @@ -40,8 +40,6 @@ package org.glassfish.grizzly.ssl; import java.nio.ByteBuffer; -import java.util.logging.Level; -import java.util.logging.Logger; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLEngineResult.Status; @@ -54,6 +52,7 @@ import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.ByteBufferArray; import org.glassfish.grizzly.memory.MemoryManager; +import org.slf4j.Logger; import static org.glassfish.grizzly.ssl.SSLUtils.*; @@ -175,9 +174,8 @@ SslResult unwrap(int len, final Buffer input, Buffer output, output = ensureBufferSize(output, appBufferSize, allocator); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "unwrap engine: {0} input: {1} output: {2}", - new Object[] {sslEngine, input, output}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("unwrap engine: {} input: {} output: {}", sslEngine, input, output); } final int inPos = input.position(); @@ -224,9 +222,8 @@ SslResult unwrap(int len, final Buffer input, Buffer output, input.position(inPos + inputByteBuffer.position() - initPosition); // GRIZZLY-1827 input.position(inPos + sslEngineResult.bytesConsumed()); output.position(outPos + sslEngineResult.bytesProduced()); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "unwrap done engine: {0} result: {1} input: {2} output: {3}", - new Object[] {sslEngine, sslEngineResult, input, output}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("unwrap done engine: {} result: {} input: {} output: {}", sslEngine, sslEngineResult, input, output); } return new SslResult(output, sslEngineResult); @@ -291,9 +288,8 @@ private SslResult wrap(final Buffer input, final ByteBuffer[] inputArray, output = ensureBufferSize(output, netBufferSize, allocator); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "wrap engine: {0} input: {1} output: {2}", - new Object[] {sslEngine, input, output}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("wrap engine: {} input: {} output: {}", sslEngine, input, output); } final int inPos = input.position(); @@ -331,9 +327,8 @@ private SslResult wrap(final Buffer input, final ByteBuffer[] inputArray, lastOutputBuffer = output; - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "wrap done engine: {0} result: {1} input: {2} output: {3}", - new Object[] {sslEngine, sslEngineResult, input, output}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("wrap done engine: {} result: {} input: {} output: {}", sslEngine, sslEngineResult, input, output); } return new SslResult(output, sslEngineResult); @@ -344,9 +339,8 @@ SslResult wrap(final Buffer input, Buffer output, output = ensureBufferSize(output, netBufferSize, allocator); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "wrap engine: {0} input: {1} output: {2}", - new Object[] {sslEngine, input, output}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("wrap engine: {} input: {} output: {}", sslEngine, input, output); } final int inPos = input.position(); @@ -395,9 +389,8 @@ SslResult wrap(final Buffer input, Buffer output, lastOutputBuffer = output; - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "wrap done engine: {0} result: {1} input: {2} output: {3}", - new Object[] {sslEngine, sslEngineResult, input, output}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("wrap done engine: {} result: {} input: {} output: {}", sslEngine, sslEngineResult, input, output); } return new SslResult(output, sslEngineResult); diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLContextConfigurator.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLContextConfigurator.java index 629174a702..f1745cb77d 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLContextConfigurator.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLContextConfigurator.java @@ -53,12 +53,13 @@ import java.security.UnrecoverableKeyException; import java.security.cert.CertificateException; import java.util.Properties; -import java.util.logging.Level; -import java.util.logging.Logger; + + import javax.net.ssl.KeyManagerFactory; import javax.net.ssl.SSLContext; import javax.net.ssl.TrustManagerFactory; import org.glassfish.grizzly.Grizzly; +import org.slf4j.Logger; /** * Utility class, which helps to configure {@link SSLContext}. @@ -370,29 +371,25 @@ public boolean validateConfiguration(boolean needsKeyStore) { keyManagerFactory.init(keyStore, keyPass != null ? keyPass : keyStorePass); } catch (KeyStoreException e) { - LOGGER.log(Level.FINE, "Error initializing key store", e); + LOGGER.debug("Error initializing key store", e); valid = false; } catch (CertificateException e) { - LOGGER.log(Level.FINE, "Key store certificate exception.", e); + LOGGER.debug("Key store certificate exception.", e); valid = false; } catch (UnrecoverableKeyException e) { - LOGGER.log(Level.FINE, "Key store unrecoverable exception.", e); + LOGGER.debug("Key store unrecoverable exception.", e); valid = false; } catch (FileNotFoundException e) { - LOGGER.log(Level.FINE, "Can't find key store file: " - + keyStoreFile, e); + LOGGER.debug("Can't find key store file: {}", keyStoreFile, e); valid = false; } catch (IOException e) { - LOGGER.log(Level.FINE, "Error loading key store from file: " - + keyStoreFile, e); + LOGGER.debug("Error loading key store from file: {}", keyStoreFile, e); valid = false; } catch (NoSuchAlgorithmException e) { - LOGGER.log(Level.FINE, - "Error initializing key manager factory (no such algorithm)", e); + LOGGER.debug("Error initializing key manager factory (no such algorithm)", e); valid = false; } catch (NoSuchProviderException e) { - LOGGER.log(Level.FINE, - "Error initializing key store (no such provider)", e); + LOGGER.debug("Error initializing key store (no such provider)", e); valid = false; } } else { @@ -424,27 +421,22 @@ public boolean validateConfiguration(boolean needsKeyStore) { .getInstance(tmfAlgorithm); trustManagerFactory.init(trustStore); } catch (KeyStoreException e) { - LOGGER.log(Level.FINE, "Error initializing trust store", e); + LOGGER.debug("Error initializing trust store", e); valid = false; } catch (CertificateException e) { - LOGGER.log(Level.FINE, "Trust store certificate exception.", e); + LOGGER.debug("Trust store certificate exception.", e); valid = false; } catch (FileNotFoundException e) { - LOGGER.log(Level.FINE, "Can't find trust store file: " - + trustStoreFile, e); + LOGGER.debug("Can't find trust store file: {}", trustStoreFile, e); valid = false; } catch (IOException e) { - LOGGER.log(Level.FINE, "Error loading trust store from file: " - + trustStoreFile, e); + LOGGER.debug("Error loading trust store from file: {}", trustStoreFile, e); valid = false; } catch (NoSuchAlgorithmException e) { - LOGGER.log(Level.FINE, - "Error initializing trust manager factory (no such algorithm)", - e); + LOGGER.debug("Error initializing trust manager factory (no such algorithm)", e); valid = false; } catch (NoSuchProviderException e) { - LOGGER.log(Level.FINE, - "Error initializing trust store (no such provider)", e); + LOGGER.debug("Error initializing trust store (no such provider)", e); valid = false; } } @@ -510,37 +502,37 @@ public SSLContext createSSLContext(final boolean throwException) { keyManagerFactory.init(keyStore, keyPass != null ? keyPass : keyStorePass); } catch (KeyStoreException e) { - LOGGER.log(Level.FINE, "Error initializing key store", e); + LOGGER.debug("Error initializing key store", e); if (throwException) { throw new GenericStoreException(e); } } catch (CertificateException e) { - LOGGER.log(Level.FINE, "Key store certificate exception.", e); + LOGGER.debug("Key store certificate exception.", e); if (throwException) { throw new GenericStoreException(e); } } catch (UnrecoverableKeyException e) { - LOGGER.log(Level.FINE, "Key store unrecoverable exception.", e); + LOGGER.debug("Key store unrecoverable exception.", e); if (throwException) { throw new GenericStoreException(e); } } catch (FileNotFoundException e) { - LOGGER.log(Level.FINE, "Can't find key store file: " + keyStoreFile, e); + LOGGER.debug("Can't find key store file: {}", keyStoreFile, e); if (throwException) { throw new GenericStoreException(e); } } catch (IOException e) { - LOGGER.log(Level.FINE, "Error loading key store from file: " + keyStoreFile, e); + LOGGER.debug("Error loading key store from file: {}", keyStoreFile, e); if (throwException) { throw new GenericStoreException(e); } } catch (NoSuchAlgorithmException e) { - LOGGER.log(Level.FINE, "Error initializing key manager factory (no such algorithm)", e); + LOGGER.debug("Error initializing key manager factory (no such algorithm)", e); if (throwException) { throw new GenericStoreException(e); } } catch (NoSuchProviderException e) { - LOGGER.log(Level.FINE, "Error initializing key store (no such provider)", e); + LOGGER.debug("Error initializing key store (no such provider)", e); } } @@ -570,32 +562,32 @@ public SSLContext createSSLContext(final boolean throwException) { .getInstance(tmfAlgorithm); trustManagerFactory.init(trustStore); } catch (KeyStoreException e) { - LOGGER.log(Level.FINE, "Error initializing trust store", e); + LOGGER.debug("Error initializing trust store", e); if (throwException) { throw new GenericStoreException(e); } } catch (CertificateException e) { - LOGGER.log(Level.FINE, "Trust store certificate exception.", e); + LOGGER.debug("Trust store certificate exception.", e); if (throwException) { throw new GenericStoreException(e); } } catch (FileNotFoundException e) { - LOGGER.log(Level.FINE, "Can't find trust store file: " + trustStoreFile, e); + LOGGER.debug("Can't find trust store file: {}", trustStoreFile, e); if (throwException) { throw new GenericStoreException(e); } } catch (IOException e) { - LOGGER.log(Level.FINE, "Error loading trust store from file: " + trustStoreFile, e); + LOGGER.debug("Error loading trust store from file: {}", trustStoreFile, e); if (throwException) { throw new GenericStoreException(e); } } catch (NoSuchAlgorithmException e) { - LOGGER.log(Level.FINE, "Error initializing trust manager factory (no such algorithm)", e); + LOGGER.debug("Error initializing trust manager factory (no such algorithm)", e); if (throwException) { throw new GenericStoreException(e); } } catch (NoSuchProviderException e) { - LOGGER.log(Level.FINE, "Error initializing trust store (no such provider)", e); + LOGGER.debug("Error initializing trust store (no such provider)", e); if (throwException) { throw new GenericStoreException(e); } @@ -612,12 +604,12 @@ public SSLContext createSSLContext(final boolean throwException) { trustManagerFactory != null ? trustManagerFactory .getTrustManagers() : null, null); } catch (KeyManagementException e) { - LOGGER.log(Level.FINE, "Key management error.", e); + LOGGER.debug("Key management error.", e); if (throwException) { throw new GenericStoreException(e); } } catch (NoSuchAlgorithmException e) { - LOGGER.log(Level.FINE, "Error initializing algorithm.", e); + LOGGER.debug("Error initializing algorithm.", e); if (throwException) { throw new GenericStoreException(e); } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLDecoderTransformer.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLDecoderTransformer.java index fd551a09bc..85a754d3b9 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLDecoderTransformer.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLDecoderTransformer.java @@ -41,8 +41,8 @@ package org.glassfish.grizzly.ssl; import java.nio.ByteBuffer; -import java.util.logging.Level; -import java.util.logging.Logger; + + import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLException; @@ -55,6 +55,7 @@ import org.glassfish.grizzly.attributes.AttributeStorage; import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.MemoryManager; +import org.slf4j.Logger; import static org.glassfish.grizzly.ssl.SSLUtils.*; @@ -117,9 +118,8 @@ protected TransformationResult transformImpl( TransformationResult transformationResult = null; try { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "SSLDecoder engine: {0} input: {1} output: {2}", - new Object[]{sslEngine, originalMessage, targetBuffer}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("SSLDecoder engine: {} input: {} output: {}", sslEngine, originalMessage, targetBuffer); } final int pos = originalMessage.position(); @@ -143,9 +143,8 @@ protected TransformationResult transformImpl( final SSLEngineResult.Status status = sslEngineResult.getStatus(); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "SSLDecoderr done engine: {0} result: {1} input: {2} output: {3}", - new Object[]{sslEngine, sslEngineResult, originalMessage, targetBuffer}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("SSLDecoderr done engine: {} result: {} input: {} output: {}", sslEngine, sslEngineResult, originalMessage, targetBuffer); } if (status == SSLEngineResult.Status.OK) { diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLEncoderTransformer.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLEncoderTransformer.java index ec1861a453..a3869bc06f 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLEncoderTransformer.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLEncoderTransformer.java @@ -40,12 +40,14 @@ package org.glassfish.grizzly.ssl; +import static org.glassfish.grizzly.ssl.SSLUtils.sslEngineWrap; + import java.nio.ByteBuffer; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult; import javax.net.ssl.SSLException; + import org.glassfish.grizzly.AbstractTransformer; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; @@ -57,7 +59,7 @@ import org.glassfish.grizzly.memory.ByteBufferArray; import org.glassfish.grizzly.memory.CompositeBuffer; import org.glassfish.grizzly.memory.MemoryManager; -import static org.glassfish.grizzly.ssl.SSLUtils.*; +import org.slf4j.Logger; /** * Transformer, which encrypts plain data, contained in the @@ -131,9 +133,8 @@ private TransformationResult wrapAll( currentTargetBuffer.toByteBuffer(); try { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "SSLEncoder engine: {0} input: {1} output: {2}", - new Object[]{sslEngine, originalByteBuffer, currentTargetByteBuffer}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("SSLEncoder engine: {} input: {} output: {}", sslEngine, originalByteBuffer, currentTargetByteBuffer); } final SSLEngineResult sslEngineResult = @@ -149,9 +150,8 @@ private TransformationResult wrapAll( final SSLEngineResult.Status status = sslEngineResult.getStatus(); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "SSLEncoder done engine: {0} result: {1} input: {2} output: {3}", - new Object[]{sslEngine, sslEngineResult, originalByteBuffer, currentTargetByteBuffer}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("SSLEncoder done engine: {} result: {} input: {} output: {}", sslEngine, sslEngineResult, originalByteBuffer, currentTargetByteBuffer); } if (status == SSLEngineResult.Status.OK) { diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLEngineConfigurator.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLEngineConfigurator.java index 735fe4dc40..76382b3abe 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLEngineConfigurator.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLEngineConfigurator.java @@ -42,10 +42,9 @@ import java.util.ArrayList; import java.util.Arrays; -import java.util.logging.Logger; + import javax.net.ssl.SSLContext; import javax.net.ssl.SSLEngine; -import org.glassfish.grizzly.Grizzly; /** * Utility class, which helps to configure {@link SSLEngine}. @@ -53,7 +52,6 @@ * @author Alexey Stashok */ public class SSLEngineConfigurator implements SSLEngineFactory { - private static final Logger LOGGER = Grizzly.logger(SSLEngineConfigurator.class); private final Object sync = new Object(); diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLFilter.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLFilter.java index b71241b602..73e530a489 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLFilter.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLFilter.java @@ -45,8 +45,8 @@ import java.util.LinkedList; import java.util.List; import java.util.logging.Filter; -import java.util.logging.Level; -import java.util.logging.Logger; + + import javax.net.ssl.SSLEngine; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Closeable; @@ -65,6 +65,7 @@ import static org.glassfish.grizzly.ssl.SSLUtils.*; import org.glassfish.grizzly.utils.JdkVersion; +import org.slf4j.Logger; /** * SSL {@link Filter} to operate with SSL encrypted data. @@ -429,8 +430,7 @@ public void completed(final SSLEngine engine) { resumePendingWrites(); } } catch (Exception e) { - LOGGER.log(Level.FINE, - "Unexpected SSLHandshakeContext.completed() error", e); + LOGGER.debug("Unexpected SSLHandshakeContext.completed() error", e); failed(e); } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLStreamWriter.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLStreamWriter.java index 7a61900cfa..7f84b240e2 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLStreamWriter.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLStreamWriter.java @@ -42,7 +42,6 @@ import java.io.IOException; import java.util.concurrent.Future; -import java.util.logging.Level; import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngineResult.HandshakeStatus; @@ -93,11 +92,10 @@ public Future handshake(final SSLStreamReader sslStreamReader, checkBuffers(connection, sslEngine); } - final boolean isLoggingFinest = logger.isLoggable(Level.FINEST); + final boolean isLoggingFinest = LOGGER.isTraceEnabled(); if (isLoggingFinest) { - logger.log(Level.FINEST, "connection={0} engine={1} handshakeStatus={2}", - new Object[]{connection, sslEngine, sslEngine.getHandshakeStatus()}); + LOGGER.trace("connection={} engine={} handshakeStatus={}", connection, sslEngine, sslEngine.getHandshakeStatus()); } HandshakeStatus handshakeStatus = sslEngine.getHandshakeStatus(); @@ -164,7 +162,7 @@ public boolean check() { public boolean doHandshakeStep() throws IOException { - final boolean isLoggingFinest = logger.isLoggable(Level.FINEST); + final boolean isLoggingFinest = LOGGER.isTraceEnabled(); HandshakeStatus handshakeStatus = sslEngine.getHandshakeStatus(); @@ -176,16 +174,14 @@ public boolean doHandshakeStep() throws IOException { while (true) { if (isLoggingFinest) { - logger.log(Level.FINEST, "Loop Engine: {0} handshakeStatus={1}", - new Object[]{sslEngine, sslEngine.getHandshakeStatus()}); + LOGGER.trace("Loop Engine: {} handshakeStatus={}", sslEngine, sslEngine.getHandshakeStatus()); } switch (handshakeStatus) { case NEED_UNWRAP: { if (isLoggingFinest) { - logger.log(Level.FINEST, "NEED_UNWRAP Engine: {0}", - sslEngine); + LOGGER.trace("NEED_UNWRAP Engine: {}", sslEngine); } return false; @@ -193,8 +189,7 @@ public boolean doHandshakeStep() throws IOException { case NEED_WRAP: { if (isLoggingFinest) { - logger.log(Level.FINEST, "NEED_WRAP Engine: {0}", - sslEngine); + LOGGER.trace("NEED_WRAP Engine: {}", sslEngine); } streamWriter.writeBuffer(Buffers.EMPTY_BUFFER); @@ -206,8 +201,7 @@ public boolean doHandshakeStep() throws IOException { case NEED_TASK: { if (isLoggingFinest) { - logger.log(Level.FINEST, "NEED_TASK Engine: {0}", - sslEngine); + LOGGER.trace("NEED_TASK Engine: {}", sslEngine); } SSLUtils.executeDelegatedTask(sslEngine); handshakeStatus = sslEngine.getHandshakeStatus(); diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLSupportImpl.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLSupportImpl.java index 2726867f00..17a5f539bf 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLSupportImpl.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/ssl/SSLSupportImpl.java @@ -62,19 +62,20 @@ import java.io.ByteArrayInputStream; import java.io.IOException; import java.security.cert.CertificateFactory; -import java.util.logging.Level; -import java.util.logging.Logger; + + import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLSession; import javax.security.cert.X509Certificate; import org.glassfish.grizzly.Grizzly; +import org.slf4j.Logger; /** * * @author oleksiys */ public class SSLSupportImpl implements SSLSupport { - private static final Logger logger = Grizzly.logger(SSLSupportImpl.class); + private static final Logger LOGGER = Grizzly.logger(SSLSupportImpl.class); /** * A mapping table to determine the number of effective bits in the key @@ -148,11 +149,11 @@ protected java.security.cert.X509Certificate[] getX509Certificates( ByteArrayInputStream stream = new ByteArrayInputStream(buffer); x509Certs[i] = (java.security.cert.X509Certificate) cf.generateCertificate(stream); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Cert #" + i + " = " + x509Certs[i]); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Cert #{} = {}", i, x509Certs[i]); } } catch (Exception ex) { - logger.log(Level.INFO, "Error translating " + jsseCerts[i], ex); + LOGGER.info("Error translating {}", jsseCerts[i], ex); return null; } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/AbstractIOStrategy.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/AbstractIOStrategy.java index c2e0712776..86ce645002 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/AbstractIOStrategy.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/AbstractIOStrategy.java @@ -42,12 +42,13 @@ import java.io.IOException; import java.util.EnumSet; import java.util.concurrent.Executor; -import java.util.logging.Level; -import java.util.logging.Logger; + + import org.glassfish.grizzly.*; import org.glassfish.grizzly.asyncqueue.AsyncQueue; import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.threadpool.ThreadPoolConfig; +import org.slf4j.Logger; /** * @@ -111,7 +112,7 @@ protected static void fireIOEvent(final Connection connection, try { connection.getTransport().fireIOEvent(ioEvent, connection, listener); } catch (Exception e) { - logger.log(Level.WARNING, LogMessages.WARNING_GRIZZLY_IOSTRATEGY_UNCAUGHT_EXCEPTION(), e); + logger.warn(LogMessages.WARNING_GRIZZLY_IOSTRATEGY_UNCAUGHT_EXCEPTION(), e); connection.closeSilently(); } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/LeaderFollowerNIOStrategy.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/LeaderFollowerNIOStrategy.java index 8e29cc2fe1..7a9809b2dc 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/LeaderFollowerNIOStrategy.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/LeaderFollowerNIOStrategy.java @@ -42,7 +42,6 @@ import java.io.IOException; import java.util.concurrent.Executor; -import java.util.logging.Logger; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -50,6 +49,7 @@ import org.glassfish.grizzly.IOEventLifeCycleListener; import org.glassfish.grizzly.nio.NIOConnection; import org.glassfish.grizzly.nio.SelectorRunner; +import org.slf4j.Logger; /** * {@link org.glassfish.grizzly.IOStrategy}, which executes {@link org.glassfish.grizzly.Processor}s in a current threads, and @@ -61,7 +61,7 @@ public final class LeaderFollowerNIOStrategy extends AbstractIOStrategy { private static final LeaderFollowerNIOStrategy INSTANCE = new LeaderFollowerNIOStrategy(); - private static final Logger logger = Grizzly.logger(LeaderFollowerNIOStrategy.class); + private static final Logger LOGGER = Grizzly.logger(LeaderFollowerNIOStrategy.class); // ------------------------------------------------------------ Constructors @@ -101,11 +101,11 @@ public boolean executeIoEvent(final Connection connection, final SelectorRunner runner = nioConnection.getSelectorRunner(); runner.postpone(); threadPool.execute(runner); - fireIOEvent(connection, ioEvent, listener, logger); + fireIOEvent(connection, ioEvent, listener, LOGGER); return false; } else { - fireIOEvent(connection, ioEvent, listener, logger); + fireIOEvent(connection, ioEvent, listener, LOGGER); return true; } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/SameThreadIOStrategy.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/SameThreadIOStrategy.java index 50f8751185..a7a1ab2c2d 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/SameThreadIOStrategy.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/SameThreadIOStrategy.java @@ -42,7 +42,6 @@ import java.io.IOException; import java.util.concurrent.Executor; -import java.util.logging.Logger; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Context; @@ -52,6 +51,7 @@ import org.glassfish.grizzly.Transport; import org.glassfish.grizzly.asyncqueue.AsyncQueue; import org.glassfish.grizzly.threadpool.ThreadPoolConfig; +import org.slf4j.Logger; /** * {@link org.glassfish.grizzly.IOStrategy}, which executes {@link org.glassfish.grizzly.Processor}s in a current thread. @@ -62,7 +62,7 @@ public final class SameThreadIOStrategy extends AbstractIOStrategy { private static final SameThreadIOStrategy INSTANCE = new SameThreadIOStrategy(); - private static final Logger logger = Grizzly.logger(SameThreadIOStrategy.class); + private static final Logger LOGGER = Grizzly.logger(SameThreadIOStrategy.class); private static final InterestLifeCycleListenerWhenIoEnabled LIFECYCLE_LISTENER_WHEN_IO_ENABLED = @@ -100,7 +100,7 @@ public boolean executeIoEvent(final Connection connection, : LIFECYCLE_LISTENER_WHEN_IO_DISABLED; } - fireIOEvent(connection, ioEvent, listener, logger); + fireIOEvent(connection, ioEvent, listener, LOGGER); return true; } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/WorkerThreadIOStrategy.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/WorkerThreadIOStrategy.java index eeb8163977..c6749c21d5 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/WorkerThreadIOStrategy.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/strategies/WorkerThreadIOStrategy.java @@ -41,12 +41,13 @@ import java.io.IOException; import java.util.concurrent.Executor; + import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.IOEvent; import org.glassfish.grizzly.IOEventLifeCycleListener; import org.glassfish.grizzly.Processor; -import java.util.logging.Logger; +import org.slf4j.Logger; /** * {@link org.glassfish.grizzly.IOStrategy}, which executes {@link Processor}s in worker thread. @@ -57,7 +58,7 @@ public final class WorkerThreadIOStrategy extends AbstractIOStrategy { private static final WorkerThreadIOStrategy INSTANCE = new WorkerThreadIOStrategy(); - private static final Logger logger = Grizzly.logger(WorkerThreadIOStrategy.class); + private static final Logger LOGGER = Grizzly.logger(WorkerThreadIOStrategy.class); // ------------------------------------------------------------ Constructors @@ -114,7 +115,7 @@ private static void run0(final Connection connection, final IOEvent ioEvent, final IOEventLifeCycleListener lifeCycleListener) { - fireIOEvent(connection, ioEvent, lifeCycleListener, logger); + fireIOEvent(connection, ioEvent, lifeCycleListener, LOGGER); } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/streams/AbstractStreamReader.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/streams/AbstractStreamReader.java index 50ba1373ff..eaead35994 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/streams/AbstractStreamReader.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/streams/AbstractStreamReader.java @@ -43,8 +43,8 @@ import java.io.EOFException; import java.io.IOException; import java.nio.BufferUnderflowException; -import java.util.logging.Level; -import java.util.logging.Logger; +import java.util.concurrent.atomic.AtomicBoolean; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; @@ -57,7 +57,7 @@ import org.glassfish.grizzly.utils.CompletionHandlerAdapter; import org.glassfish.grizzly.utils.ResultAware; import org.glassfish.grizzly.utils.conditions.Condition; -import java.util.concurrent.atomic.AtomicBoolean; +import org.slf4j.Logger; /** * Each method reads data from the current ByteBuffer. If not enough data @@ -87,7 +87,7 @@ public abstract class AbstractStreamReader implements StreamReader { protected final AtomicBoolean isClosed = new AtomicBoolean(false); private static void msg(final String msg) { - LOGGER.log(Level.INFO, "READERSTREAM:DEBUG:{0}", msg); + LOGGER.info("READERSTREAM:DEBUG:{}", msg); } private static void displayBuffer(final String str, diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/streams/AbstractStreamWriter.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/streams/AbstractStreamWriter.java index 6ec5796aa4..cda8e8a2d5 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/streams/AbstractStreamWriter.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/streams/AbstractStreamWriter.java @@ -40,9 +40,10 @@ package org.glassfish.grizzly.streams; -import org.glassfish.grizzly.Transformer; import java.io.IOException; import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicBoolean; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; @@ -51,11 +52,10 @@ import org.glassfish.grizzly.TransformationException; import org.glassfish.grizzly.TransformationResult; import org.glassfish.grizzly.TransformationResult.Status; +import org.glassfish.grizzly.Transformer; import org.glassfish.grizzly.impl.ReadyFutureImpl; - -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.logging.Logger; import org.glassfish.grizzly.memory.Buffers; +import org.slf4j.Logger; /** * Write the primitive Java type to the current ByteBuffer. If it doesn't @@ -66,7 +66,7 @@ * @author Ken Cavanaugh */ public abstract class AbstractStreamWriter implements StreamWriter { - protected static final Logger logger = Grizzly.logger(AbstractStreamWriter.class); + protected static final Logger LOGGER = Grizzly.logger(AbstractStreamWriter.class); protected static final Integer ZERO = 0; protected static final GrizzlyFuture ZERO_READY_FUTURE = diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/threadpool/AbstractThreadPool.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/threadpool/AbstractThreadPool.java index 4b528f68cc..4d49340f3b 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/threadpool/AbstractThreadPool.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/threadpool/AbstractThreadPool.java @@ -40,23 +40,28 @@ package org.glassfish.grizzly.threadpool; -import java.util.*; +import java.util.ArrayList; +import java.util.Collection; +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Queue; import java.util.concurrent.AbstractExecutorService; import java.util.concurrent.RejectedExecutionException; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.memory.MemoryManager; import org.glassfish.grizzly.memory.ThreadLocalPoolProvider; +import org.glassfish.grizzly.monitoring.DefaultMonitoringConfig; import org.glassfish.grizzly.monitoring.MonitoringAware; import org.glassfish.grizzly.monitoring.MonitoringConfig; -import org.glassfish.grizzly.monitoring.DefaultMonitoringConfig; import org.glassfish.grizzly.monitoring.MonitoringUtils; import org.glassfish.grizzly.utils.DelayedExecutor; +import org.slf4j.Logger; /** * Abstract {@link java.util.concurrent.ExecutorService} implementation. @@ -507,8 +512,7 @@ public MonitoringConfig getMonitoringConfig() { */ @Override public void uncaughtException(Thread thread, Throwable throwable) { - logger.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_THREADPOOL_UNCAUGHT_EXCEPTION(thread), throwable); + logger.warn(LogMessages.WARNING_GRIZZLY_THREADPOOL_UNCAUGHT_EXCEPTION(thread), throwable); } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/ActivityCheckFilter.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/ActivityCheckFilter.java index ca1990e040..f6c39d959f 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/ActivityCheckFilter.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/ActivityCheckFilter.java @@ -45,7 +45,7 @@ import java.util.concurrent.Executors; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; + import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.attributes.Attribute; @@ -65,8 +65,7 @@ * @author Alexey Stashok */ public class ActivityCheckFilter extends BaseFilter { - private static final Logger LOGGER = Grizzly.logger(ActivityCheckFilter.class); - + public static final String ACTIVE_ATTRIBUTE_NAME = "connection-active-attribute"; private static final Attribute IDLE_ATTR = Grizzly.DEFAULT_ATTRIBUTE_BUILDER.createAttribute( diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/ChunkingFilter.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/ChunkingFilter.java index 5a2fc27c02..ced952e70d 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/ChunkingFilter.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/ChunkingFilter.java @@ -42,14 +42,12 @@ import org.glassfish.grizzly.AbstractTransformer; import org.glassfish.grizzly.Buffer; -import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.TransformationException; import org.glassfish.grizzly.TransformationResult; import org.glassfish.grizzly.attributes.AttributeStorage; import org.glassfish.grizzly.filterchain.AbstractCodecFilter; import org.glassfish.grizzly.filterchain.FilterChain; import org.glassfish.grizzly.memory.Buffers; -import java.util.logging.Logger; /** @@ -61,7 +59,6 @@ * @author Alexey Stashok */ public class ChunkingFilter extends AbstractCodecFilter { - private static final Logger LOGGER = Grizzly.logger(ChunkingFilter.class); private final int chunkSize; diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/DataStructures.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/DataStructures.java index 25570fcaf4..b078be93da 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/DataStructures.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/DataStructures.java @@ -44,7 +44,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.LinkedBlockingQueue; -import java.util.logging.Level; + import org.glassfish.grizzly.Grizzly; /* @@ -69,12 +69,9 @@ public class DataStructures { : "org.glassfish.grizzly.utils.LinkedTransferQueue"; c = getAndVerify(className); - Grizzly.logger(DataStructures.class).log(Level.FINE, "USING LTQ class:{0}", c); + Grizzly.logger(DataStructures.class).debug("USING LTQ class:{}", c); } catch (Throwable t) { - Grizzly.logger(DataStructures.class).log(Level.FINE, - "failed loading datastructure class:" + className + - " fallback to embedded one", t); - + Grizzly.logger(DataStructures.class).debug("failed loading datastructure class: {} fallback to embedded one", className, t); c = LinkedBlockingQueue.class; // fallback to LinkedBlockingQueue } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/EchoFilter.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/EchoFilter.java index 79460dd2e3..9d9a69fff0 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/EchoFilter.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/EchoFilter.java @@ -40,16 +40,17 @@ package org.glassfish.grizzly.utils; -import org.glassfish.grizzly.Buffer; -import org.glassfish.grizzly.filterchain.BaseFilter; -import org.glassfish.grizzly.filterchain.FilterChainContext; -import org.glassfish.grizzly.filterchain.NextAction; import java.io.IOException; import java.util.logging.Filter; -import java.util.logging.Logger; + +import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; -import java.util.logging.Level; +import org.glassfish.grizzly.filterchain.BaseFilter; +import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.filterchain.NextAction; +import org.slf4j.Logger; + /** * Echo {@link Filter} implementation @@ -67,9 +68,8 @@ public NextAction handleRead(final FilterChainContext ctx) final Connection connection = ctx.getConnection(); final Object address = ctx.getAddress(); - if (logger.isLoggable(Level.FINEST)) { - logger.log(Level.FINEST, "EchoFilter. connection={0} dstAddress={1} message={2}", - new Object[]{connection, address, message}); + if (logger.isTraceEnabled()) { + logger.trace("EchoFilter. connection={} dstAddress={} message={}", connection, address, message); } if (message instanceof Buffer) { diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/JdkVersion.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/JdkVersion.java index 9c8b629e28..d1bbce658d 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/JdkVersion.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/JdkVersion.java @@ -39,11 +39,12 @@ */ package org.glassfish.grizzly.utils; -import java.util.logging.Level; -import java.util.logging.Logger; + + import java.util.regex.Matcher; import java.util.regex.Pattern; import org.glassfish.grizzly.Grizzly; +import org.slf4j.Logger; /** * @@ -104,12 +105,10 @@ public static JdkVersion parseVersion(final String versionString) { parseInt(matcher.group(7))); } - LOGGER.log(Level.FINE, - "Can't parse the JDK version {0}", versionString); + LOGGER.debug("Can't parse the JDK version {}", versionString); } catch (Exception e) { - LOGGER.log(Level.FINE, - "Error parsing the JDK version " + versionString, e); + LOGGER.debug("Error parsing the JDK version {}", versionString, e); } return UNKNOWN_VERSION; diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/LogFilter.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/LogFilter.java index 803420e0b6..61ac3c874a 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/LogFilter.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/LogFilter.java @@ -40,15 +40,16 @@ package org.glassfish.grizzly.utils; +import java.io.IOException; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.Filter; import org.glassfish.grizzly.filterchain.FilterChain; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; +import org.slf4j.Logger; +import org.slf4j.event.Level; /** * Simple log {@link Filter} @@ -91,58 +92,52 @@ public Level getLevel() { @Override public void onAdded(FilterChain filterChain) { - logger.log(level, "LogFilter onAdded"); + logger.atLevel(level).log("LogFilter onAdded"); } @Override public void onRemoved(FilterChain filterChain) { - logger.log(level, "LogFilter onRemoved"); + logger.atLevel(level).log("LogFilter onRemoved"); } @Override public void onFilterChainChanged(FilterChain filterChain) { - logger.log(level, "LogFilter onFilterChainChanged"); + logger.atLevel(level).log("LogFilter onFilterChainChanged"); } @Override public NextAction handleRead(FilterChainContext ctx) throws IOException { - logger.log(level, "LogFilter handleRead. Connection={0} message={1}", - new Object[] {ctx.getConnection(), ctx.getMessage()}); + logger.atLevel(level).log("LogFilter handleRead. Connection={} message={}", ctx.getConnection(), ctx.getMessage()); return ctx.getInvokeAction(); } @Override public NextAction handleWrite(FilterChainContext ctx) throws IOException { - logger.log(level, "LogFilter handleWrite. Connection={0} message={1}", - new Object[] {ctx.getConnection(), ctx.getMessage()}); + logger.atLevel(level).log("LogFilter handleWrite. Connection={} message={}", ctx.getConnection(), ctx.getMessage()); return ctx.getInvokeAction(); } @Override public NextAction handleConnect(FilterChainContext ctx) throws IOException { - logger.log(level, "LogFilter handleConnect. Connection={0} message={1}", - new Object[] {ctx.getConnection(), ctx.getMessage()}); + logger.atLevel(level).log("LogFilter handleConnect. Connection={} message={}", ctx.getConnection(), ctx.getMessage()); return ctx.getInvokeAction(); } @Override public NextAction handleAccept(FilterChainContext ctx) throws IOException { - logger.log(level, "LogFilter handleAccept. Connection={0} message={1}", - new Object[] {ctx.getConnection(), ctx.getMessage()}); + logger.atLevel(level).log("LogFilter handleAccept. Connection={} message={}", ctx.getConnection(), ctx.getMessage()); return ctx.getInvokeAction(); } @Override public NextAction handleClose(FilterChainContext ctx) throws IOException { - logger.log(level, "LogFilter handleClose. Connection={0} message={1}", - new Object[] {ctx.getConnection(), ctx.getMessage()}); + logger.atLevel(level).log("LogFilter handleClose. Connection={} message={}", ctx.getConnection(), ctx.getMessage()); return ctx.getInvokeAction(); } @Override public void exceptionOccurred(FilterChainContext ctx, Throwable error) { - logger.log(level, "LogFilter exceptionOccured. Connection={0} message={1}", - new Object[] {ctx.getConnection(), ctx.getMessage()}); + logger.atLevel(level).log("LogFilter exceptionOccured. Connection={} message={}", ctx.getConnection(), ctx.getMessage()); } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/LoggingFormatter.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/LoggingFormatter.java index 95d65eca7b..dfbe0b3ccf 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/LoggingFormatter.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/LoggingFormatter.java @@ -44,9 +44,11 @@ import java.io.StringWriter; import java.util.Date; import java.util.logging.Formatter; -import java.util.logging.Level; import java.util.logging.LogRecord; -import java.util.logging.Logger; + +import org.glassfish.grizzly.Grizzly; +import org.slf4j.Logger; + /** * @@ -67,7 +69,7 @@ */ public class LoggingFormatter extends Formatter { - private static final Logger log = Logger.getLogger(LoggingFormatter.class.getName()); + private static final Logger LOGGER = Grizzly.logger(LoggingFormatter.class); // took that from the JDK java.util.logging.SimpleFormatter // Line separator string. This is the value of the line.separator // property at the moment that the SimpleFormatter was created. @@ -155,21 +157,21 @@ public String format(LogRecord record) { */ public static void main(String[] args) { - log.info("Info Event"); + LOGGER.info("Info Event"); - log.severe("Severe Event"); + LOGGER.error("Severe Event"); // show the thread info in the logger. Thread t = new Thread(new Runnable() { @Override public void run() { - log.info("Info Event in Thread"); + LOGGER.info("Info Event in Thread"); } }, "Thread into main"); t.start(); - log.log(Level.SEVERE, "exception", new Exception()); + LOGGER.error("exception", new Exception()); } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/SilentConnectionFilter.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/SilentConnectionFilter.java index f834862696..38aeda49b7 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/SilentConnectionFilter.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/SilentConnectionFilter.java @@ -40,15 +40,16 @@ package org.glassfish.grizzly.utils; +import java.io.IOException; +import java.util.concurrent.TimeUnit; + import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.attributes.Attribute; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; -import java.io.IOException; -import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; + /** * Filter, which determines silent connections and closes them. @@ -58,7 +59,6 @@ * @author Alexey Stashok */ public final class SilentConnectionFilter extends BaseFilter { - private static final Logger LOGGER = Grizzly.logger(SilentConnectionFilter.class); public static final long UNLIMITED_TIMEOUT = -1; public static final long UNSET_TIMEOUT = 0; diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/StateHolder.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/StateHolder.java index c41046bf0f..c075550cd8 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/StateHolder.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/StateHolder.java @@ -41,19 +41,19 @@ package org.glassfish.grizzly.utils; import java.util.Collection; +import java.util.Iterator; +import java.util.concurrent.ConcurrentLinkedQueue; +import java.util.concurrent.Future; +import java.util.concurrent.locks.ReentrantReadWriteLock; + import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.ReadyFutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; -import org.glassfish.grizzly.utils.conditions.Condition; -import java.util.Iterator; -import java.util.concurrent.ConcurrentLinkedQueue; -import java.util.concurrent.Future; -import java.util.concurrent.locks.ReentrantReadWriteLock; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.localization.LogMessages; +import org.glassfish.grizzly.utils.conditions.Condition; +import org.slf4j.Logger; /** * Class, which holds the state. @@ -62,7 +62,7 @@ * @author Alexey Stashok */ public final class StateHolder { - private static final Logger _logger = Grizzly.logger(StateHolder.class); + private static final Logger LOGGER = Grizzly.logger(StateHolder.class); private volatile E state; @@ -223,9 +223,7 @@ protected void notifyConditionListeners() { element.future.result(state); } } catch(Exception e) { - _logger.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_STATE_HOLDER_CALLING_CONDITIONLISTENER_EXCEPTION(), - e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_STATE_HOLDER_CALLING_CONDITIONLISTENER_EXCEPTION(), e); } } } diff --git a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/StringDecoder.java b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/StringDecoder.java index df87641ad1..e5108a692b 100644 --- a/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/StringDecoder.java +++ b/modules/grizzly/src/main/java/org/glassfish/grizzly/utils/StringDecoder.java @@ -40,17 +40,17 @@ package org.glassfish.grizzly.utils; -import org.glassfish.grizzly.attributes.AttributeStorage; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; + import org.glassfish.grizzly.AbstractTransformer; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.TransformationException; import org.glassfish.grizzly.TransformationResult; import org.glassfish.grizzly.attributes.Attribute; -import java.util.logging.Level; -import java.util.logging.Logger; +import org.glassfish.grizzly.attributes.AttributeStorage; +import org.slf4j.Logger; /** * String decoder, which decodes {@link Buffer} to {@link String} @@ -123,9 +123,8 @@ protected TransformationResult parseWithLengthPrefix( final AttributeStorage storage, final Buffer input) { Integer stringSize = lengthAttribute.get(storage); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "StringDecoder decode stringSize={0} buffer={1} content={2}", - new Object[]{stringSize, input, input.toStringContent()}); + if (logger.isDebugEnabled()) { + logger.debug("StringDecoder decode stringSize={} buffer={} content={}", stringSize, input, input.toStringContent()); } if (stringSize == null) { diff --git a/modules/grizzly/src/test/java/org/glassfish/grizzly/AsyncWriteQueueTest.java b/modules/grizzly/src/test/java/org/glassfish/grizzly/AsyncWriteQueueTest.java index 081e2635dc..392375cebc 100644 --- a/modules/grizzly/src/test/java/org/glassfish/grizzly/AsyncWriteQueueTest.java +++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/AsyncWriteQueueTest.java @@ -40,6 +40,11 @@ package org.glassfish.grizzly; +import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.IOException; import java.net.SocketAddress; import java.util.ArrayList; @@ -52,8 +57,7 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.asyncqueue.AsyncQueueWriter; import org.glassfish.grizzly.asyncqueue.TaskQueue; import org.glassfish.grizzly.asyncqueue.WritableMessage; @@ -80,9 +84,7 @@ import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; - -import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; -import static org.junit.Assert.*; +import org.slf4j.Logger; /** * AsyncWriteQueue tests. @@ -353,7 +355,7 @@ public Object call() throws Exception { try { available = readFuture.get(10, TimeUnit.SECONDS); } catch (Exception e) { - LOGGER.log(Level.WARNING, "read error", e); + LOGGER.warn("read error", e); } assertTrue("Read timeout. Server received: " +serverRcvdBytes.get() + diff --git a/modules/grizzly/src/test/java/org/glassfish/grizzly/FilterChainReadTest.java b/modules/grizzly/src/test/java/org/glassfish/grizzly/FilterChainReadTest.java index 8806fcf892..8d6e207408 100644 --- a/modules/grizzly/src/test/java/org/glassfish/grizzly/FilterChainReadTest.java +++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/FilterChainReadTest.java @@ -42,6 +42,14 @@ import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; +import java.io.EOFException; +import java.io.IOException; +import java.net.SocketAddress; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import junit.framework.TestCase; import org.glassfish.grizzly.asyncqueue.WritableMessage; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChain; @@ -49,23 +57,15 @@ import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; import org.glassfish.grizzly.filterchain.TransportFilter; +import org.glassfish.grizzly.memory.CompositeBuffer; +import org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; +import org.glassfish.grizzly.utils.DataStructures; import org.glassfish.grizzly.utils.EchoFilter; import org.glassfish.grizzly.utils.StringEncoder; import org.glassfish.grizzly.utils.StringFilter; -import java.io.EOFException; -import java.io.IOException; -import java.net.SocketAddress; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import junit.framework.TestCase; -import org.glassfish.grizzly.memory.CompositeBuffer; -import org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler; -import org.glassfish.grizzly.utils.DataStructures; +import org.slf4j.Logger; /** * Test {@link FilterChain} blocking read. @@ -76,7 +76,7 @@ public class FilterChainReadTest extends TestCase { public final int PORT = findFreePort(); - private static final Logger logger = Grizzly.logger(FilterChainReadTest.class); + private static final Logger LOGGER = Grizzly.logger(FilterChainReadTest.class); public void testBlockingRead() throws Exception { final String[] clientMsgs = {"Hello", "from", "client"}; @@ -95,7 +95,7 @@ public NextAction handleRead(FilterChainContext ctx) String message = ctx.getMessage(); - logger.log(Level.INFO, "First chunk come: {0}", message); + LOGGER.info("First chunk come: {}", message); intermResultQueue.add(message); Connection connection = ctx.getConnection(); @@ -106,7 +106,7 @@ public NextAction handleRead(FilterChainContext ctx) final String blckMsg = (String) rr.getMessage(); rr.recycle(); - logger.log(Level.INFO, "Blocking chunk come: {0}", blckMsg); + LOGGER.info("Blocking chunk come: {}", blckMsg); intermResultQueue.add(blckMsg); message += blckMsg; } @@ -202,7 +202,7 @@ public NextAction handleRead(FilterChainContext ctx) String message = ctx.getMessage(); - logger.log(Level.INFO, "First chunk come: {0}", message); + LOGGER.info("First chunk come: {}", message); intermResultQueue.add(message); Connection connection = ctx.getConnection(); @@ -213,7 +213,7 @@ public NextAction handleRead(FilterChainContext ctx) final String blckMsg = (String) rr.getMessage(); rr.recycle(); - logger.log(Level.INFO, "Blocking chunk come: {0}", blckMsg); + LOGGER.info("Blocking chunk come: {}", blckMsg); intermResultQueue.add(blckMsg); message += blckMsg; } @@ -317,7 +317,7 @@ public NextAction handleRead(FilterChainContext ctx) String message = ctx.getMessage(); - logger.log(Level.INFO, "First chunk come: {0}", message); + LOGGER.info("First chunk come: {}", message); intermResultQueue.add(message); Connection connection = ctx.getConnection(); diff --git a/modules/grizzly/src/test/java/org/glassfish/grizzly/IOStrategyTest.java b/modules/grizzly/src/test/java/org/glassfish/grizzly/IOStrategyTest.java index add7034a95..d7890e42e5 100644 --- a/modules/grizzly/src/test/java/org/glassfish/grizzly/IOStrategyTest.java +++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/IOStrategyTest.java @@ -39,41 +39,43 @@ */ package org.glassfish.grizzly; + +import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; -import org.glassfish.grizzly.filterchain.FilterChainContext; -import org.glassfish.grizzly.filterchain.NextAction; -import org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler; -import org.glassfish.grizzly.filterchain.FilterChain; -import org.glassfish.grizzly.impl.SafeFutureImpl; -import org.glassfish.grizzly.impl.FutureImpl; -import java.util.concurrent.TimeUnit; import java.net.InetSocketAddress; -import java.util.concurrent.Future; -import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; -import org.glassfish.grizzly.nio.transport.TCPNIOTransport; -import org.glassfish.grizzly.filterchain.TransportFilter; -import org.glassfish.grizzly.filterchain.FilterChainBuilder; -import org.junit.Test; -import org.junit.Before; -import org.junit.runners.Parameterized.Parameters; -import java.util.Collection; import java.util.Arrays; +import java.util.Collection; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.asyncqueue.AsyncQueueWriter; import org.glassfish.grizzly.filterchain.BaseFilter; +import org.glassfish.grizzly.filterchain.FilterChain; +import org.glassfish.grizzly.filterchain.FilterChainBuilder; +import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.filterchain.NextAction; +import org.glassfish.grizzly.filterchain.TransportFilter; +import org.glassfish.grizzly.impl.FutureImpl; +import org.glassfish.grizzly.impl.SafeFutureImpl; +import org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler; +import org.glassfish.grizzly.nio.transport.TCPNIOTransport; +import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.strategies.LeaderFollowerNIOStrategy; import org.glassfish.grizzly.strategies.SameThreadIOStrategy; import org.glassfish.grizzly.strategies.SimpleDynamicNIOStrategy; import org.glassfish.grizzly.strategies.WorkerThreadIOStrategy; import org.glassfish.grizzly.utils.Charsets; import org.glassfish.grizzly.utils.StringFilter; -import org.junit.runners.Parameterized; +import org.junit.Before; +import org.junit.Test; import org.junit.runner.RunWith; - -import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; -import static org.junit.Assert.*; +import org.junit.runners.Parameterized; +import org.junit.runners.Parameterized.Parameters; +import org.slf4j.Logger; /** * Basic IOStrategies test. @@ -162,8 +164,7 @@ public void testSimplePackets() throws Exception { connection.write(pattern + j, new EmptyCompletionHandler() { @Override public void failed(Throwable throwable) { - LOGGER.log(Level.WARNING, "connection.write(...) failed. Index=" + num, - throwable); + LOGGER.warn("connection.write(...) failed. Index={}", num, throwable); } }); } @@ -242,8 +243,7 @@ public NextAction handleRead(final FilterChainContext ctx) throws IOException { final String check = pattern + count; if (!check.equals(msg)) { - LOGGER.log(Level.WARNING, "Server EchoFilter: unexpected message came: {0}. Expected response: {1}", - new Object[]{msg, check}); + LOGGER.warn("Server EchoFilter: unexpected message came: {}. Expected response: {}", msg, check); } ctx.write(msg); diff --git a/modules/grizzly/src/test/java/org/glassfish/grizzly/NIOTransportTest.java b/modules/grizzly/src/test/java/org/glassfish/grizzly/NIOTransportTest.java index b6e2a102a4..67f95317e3 100644 --- a/modules/grizzly/src/test/java/org/glassfish/grizzly/NIOTransportTest.java +++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/NIOTransportTest.java @@ -61,6 +61,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; +import org.slf4j.Logger; import java.io.IOException; import java.net.InetSocketAddress; @@ -71,8 +72,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.logging.Level; -import java.util.logging.Logger; + + import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; import static org.junit.Assert.*; @@ -116,7 +117,7 @@ public NIOTransportTest(final Holder transportHolder) { @Test public void testStartStop() throws IOException { - LOGGER.log(Level.INFO, "Running: testStartStop ({0})", transport.getName()); + LOGGER.info("Running: testStartStop ({})", transport.getName()); try { transport.bind(port); @@ -128,7 +129,7 @@ public void testStartStop() throws IOException { @Test public void testStartStopStart() throws Exception { - LOGGER.log(Level.INFO, "Running: testStartStopStart ({0})", transport.getName()); + LOGGER.info("Running: testStartStopStart ({})", transport.getName()); try { transport.bind(port); @@ -156,7 +157,7 @@ public void testStartStopStart() throws Exception { @Test public void testReadWriteTimeout() throws Exception { - LOGGER.log(Level.INFO, "Running: testReadWriteTimeout ({0})", transport.getName()); + LOGGER.info("Running: testReadWriteTimeout ({})", transport.getName()); assertEquals(30, transport.getWriteTimeout(TimeUnit.SECONDS)); assertEquals(30, transport.getReadTimeout(TimeUnit.SECONDS)); @@ -172,7 +173,7 @@ public void testReadWriteTimeout() throws Exception { @Test public void testConnectorHandlerConnect() throws Exception { - LOGGER.log(Level.INFO, "Running: testConnectorHandlerConnect ({0})", transport.getName()); + LOGGER.info("Running: testConnectorHandlerConnect ({})", transport.getName()); Connection connection = null; @@ -194,7 +195,7 @@ public void testConnectorHandlerConnect() throws Exception { @Test public void testPortRangeBind() throws Exception { - LOGGER.log(Level.INFO, "Running: testPortRangeBind ({0})", transport.getName()); + LOGGER.info("Running: testPortRangeBind ({})", transport.getName()); final int portsTest = 10; final int startPort = 7777 + 1234; @@ -232,7 +233,7 @@ public void testPortRangeBind() throws Exception { @Test public void testConnectorHandlerConnectAndWrite() throws Exception { - LOGGER.log(Level.INFO, "Running: testConnectorHandlerConnectAndWrite ({0})", transport.getName()); + LOGGER.info("Running: testConnectorHandlerConnectAndWrite ({})", transport.getName()); Connection connection = null; StreamWriter writer = null; @@ -281,7 +282,7 @@ public void completed(final Connection connection) { @Test public void testSimpleEcho() throws Exception { - LOGGER.log(Level.INFO, "Running: testSimpleEcho ({0})", transport.getName()); + LOGGER.info("Running: testSimpleEcho ({})", transport.getName()); Connection connection = null; StreamReader reader; @@ -344,7 +345,7 @@ public void completed(final Connection connection) { @Test public void testSeveralPacketsEcho() throws Exception { - LOGGER.log(Level.INFO, "Running: testSeveralPacketsEcho ({0})", transport.getName()); + LOGGER.info("Running: testSeveralPacketsEcho ({})", transport.getName()); Connection connection = null; StreamReader reader; @@ -408,7 +409,7 @@ public void completed(final Connection connection) { @Test public void testAsyncReadWriteEcho() throws Exception { - LOGGER.log(Level.INFO, "Running: testAsyncReadWriteEcho ({0})", transport.getName()); + LOGGER.info("Running: testAsyncReadWriteEcho ({})", transport.getName()); Connection connection = null; StreamReader reader; @@ -469,7 +470,7 @@ public void completed(final Connection connection) { @Test public void testSeveralPacketsAsyncReadWriteEcho() throws Exception { - LOGGER.log(Level.INFO, "Running: testSeveralPacketsAsyncReadWriteEcho ({0})", transport.getName()); + LOGGER.info("Running: testSeveralPacketsAsyncReadWriteEcho ({})", transport.getName()); int packetsNumber = 100; final int packetSize = 32; @@ -537,7 +538,7 @@ public void completed(final Connection connection) { @Test public void testFeeder() throws Exception { - LOGGER.log(Level.INFO, "Running: testFeeder ({0})", transport.getName()); + LOGGER.info("Running: testFeeder ({})", transport.getName()); class CheckSizeFilter extends BaseFilter { private int size; @@ -552,8 +553,7 @@ public CheckSizeFilter(int size) { public NextAction handleRead(FilterChainContext ctx) throws IOException { final Buffer buffer = ctx.getMessage(); - LOGGER.log(Level.INFO, "Feeder. Check size filter: {0}", - buffer); + LOGGER.info("Feeder. Check size filter: {}", buffer); if (buffer.remaining() >= size) { latch.countDown(); return ctx.getInvokeAction(); @@ -644,7 +644,7 @@ public void completed(final Connection connection) { @Test public void testWorkerThreadPoolConfiguration() throws Exception { - LOGGER.log(Level.INFO, "Running: testWorkerThreadPoolConfiguration ({0})", transport.getName()); + LOGGER.info("Running: testWorkerThreadPoolConfiguration ({})", transport.getName()); ThreadPoolConfig config = ThreadPoolConfig.defaultConfig(); config.setCorePoolSize(1); @@ -660,7 +660,7 @@ public void testWorkerThreadPoolConfiguration() throws Exception { @Test public void testWorkerThreadPoolConfiguration2() throws Exception { - LOGGER.log(Level.INFO, "Running: testWorkerThreadPoolConfiguration2 ({0})", transport.getName()); + LOGGER.info("Running: testWorkerThreadPoolConfiguration2 ({})", transport.getName()); ThreadPoolConfig config = ThreadPoolConfig.defaultConfig(); config.setCorePoolSize(1); @@ -674,7 +674,7 @@ public void testWorkerThreadPoolConfiguration2() throws Exception { @Test public void testGracefulShutdown() throws Exception { - LOGGER.log(Level.INFO, "Running: testGracefulShutdown ({0})", transport.getName()); + LOGGER.info("Running: testGracefulShutdown ({})", transport.getName()); final CountDownLatch latch = new CountDownLatch(2); final AtomicBoolean forcedNotCalled1 = new AtomicBoolean(); @@ -739,7 +739,7 @@ public void shutdownForced() { @Test public void testGracefulShutdownWithGracePeriod() throws Exception { - LOGGER.log(Level.INFO, "Running: testGracefulShutdownWithGracePeriod ({0})", transport.getName()); + LOGGER.info("Running: testGracefulShutdownWithGracePeriod ({})", transport.getName()); final AtomicBoolean forcedNotCalled1 = new AtomicBoolean(); final AtomicBoolean forcedNotCalled2 = new AtomicBoolean(); @@ -799,7 +799,7 @@ public void shutdownForced() { @Test public void testGracefulShutdownWithGracePeriodTimeout() throws Exception { - LOGGER.log(Level.INFO, "Running: testGracefulShutdownWithGracePeriodTimeout ({0})", transport.getName()); + LOGGER.info("Running: testGracefulShutdownWithGracePeriodTimeout ({})", transport.getName()); final AtomicBoolean forcedCalled1 = new AtomicBoolean(); final AtomicBoolean forcedCalled2 = new AtomicBoolean(); @@ -858,7 +858,7 @@ public void shutdownForced() { @Test public void testGracefulShutdownAndThenForced() throws Exception { - LOGGER.log(Level.INFO, "Running: testGracefulShutdownAndThenForced ({0})", transport.getName()); + LOGGER.info("Running: testGracefulShutdownAndThenForced ({})", transport.getName()); final AtomicBoolean listener1 = new AtomicBoolean(); final AtomicBoolean listener2 = new AtomicBoolean(); @@ -923,7 +923,7 @@ public void shutdownForced() { @Test public void testTimedGracefulShutdownAndThenForced() throws Exception { - LOGGER.log(Level.INFO, "Running: testTimedGracefulShutdownAndThenForced ({0})", transport.getName()); + LOGGER.info("Running: testTimedGracefulShutdownAndThenForced ({})", transport.getName()); final CountDownLatch latch = new CountDownLatch(1); transport.addShutdownListener(new GracefulShutdownListener() { diff --git a/modules/grizzly/src/test/java/org/glassfish/grizzly/ProtocolChainCodecTest.java b/modules/grizzly/src/test/java/org/glassfish/grizzly/ProtocolChainCodecTest.java index d0a79593bd..5a54119582 100644 --- a/modules/grizzly/src/test/java/org/glassfish/grizzly/ProtocolChainCodecTest.java +++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/ProtocolChainCodecTest.java @@ -58,10 +58,11 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + + import org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler; import org.glassfish.grizzly.utils.DataStructures; +import org.slf4j.Logger; /** * @@ -154,7 +155,7 @@ public NextAction handleRead(FilterChainContext ctx) final String message = ctx.getMessage(); - logger.log(Level.FINE, "Server got message: " + message); + logger.debug("Server got message: {}", message); assertEquals(clientMessage + "-" + counter, message); diff --git a/modules/grizzly/src/test/java/org/glassfish/grizzly/SSLTest.java b/modules/grizzly/src/test/java/org/glassfish/grizzly/SSLTest.java index e401a3b0a4..76e2afae06 100644 --- a/modules/grizzly/src/test/java/org/glassfish/grizzly/SSLTest.java +++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/SSLTest.java @@ -40,43 +40,54 @@ package org.glassfish.grizzly; -import java.util.concurrent.ExecutorService; +import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; import java.io.InputStream; import java.net.InetSocketAddress; - -import org.glassfish.grizzly.memory.ByteBufferManager; -import org.glassfish.grizzly.memory.HeapMemoryManager; -import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; -import org.glassfish.grizzly.utils.ClientCheckFilter; -import org.glassfish.grizzly.utils.ParallelWriteFilter; -import org.glassfish.grizzly.utils.RandomDelayOnWriteFilter; -import org.junit.Test; -import org.glassfish.grizzly.memory.ByteBufferWrapper; -import org.junit.Before; - +import java.net.URL; import java.security.KeyStore; import java.security.SecureRandom; import java.security.cert.CertificateException; import java.security.cert.X509Certificate; import java.util.Arrays; import java.util.Collection; -import org.junit.runners.Parameterized.Parameters; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; +import java.util.concurrent.atomic.AtomicBoolean; + +import javax.net.ssl.KeyManager; +import javax.net.ssl.KeyManagerFactory; +import javax.net.ssl.SSLContext; +import javax.net.ssl.SSLEngine; +import javax.net.ssl.SSLHandshakeException; +import javax.net.ssl.TrustManager; +import javax.net.ssl.X509TrustManager; + import org.glassfish.grizzly.attributes.Attribute; -import org.glassfish.grizzly.filterchain.Filter; import org.glassfish.grizzly.filterchain.BaseFilter; +import org.glassfish.grizzly.filterchain.Filter; import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; -import java.io.IOException; -import java.net.URL; -import java.util.concurrent.Executors; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; import org.glassfish.grizzly.filterchain.TransportFilter; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; +import org.glassfish.grizzly.memory.Buffers; +import org.glassfish.grizzly.memory.ByteBufferManager; +import org.glassfish.grizzly.memory.ByteBufferWrapper; +import org.glassfish.grizzly.memory.HeapMemoryManager; import org.glassfish.grizzly.memory.MemoryManager; +import org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; +import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.ssl.SSLContextConfigurator; import org.glassfish.grizzly.ssl.SSLEngineConfigurator; import org.glassfish.grizzly.ssl.SSLFilter; @@ -85,29 +96,19 @@ import org.glassfish.grizzly.streams.StreamReader; import org.glassfish.grizzly.streams.StreamWriter; import org.glassfish.grizzly.utils.ChunkingFilter; +import org.glassfish.grizzly.utils.ClientCheckFilter; import org.glassfish.grizzly.utils.EchoFilter; -import org.glassfish.grizzly.utils.StringFilter; -import java.util.concurrent.TimeoutException; -import java.util.concurrent.atomic.AtomicBoolean; -import java.util.logging.Level; -import java.util.logging.Logger; -import javax.net.ssl.KeyManager; -import javax.net.ssl.KeyManagerFactory; -import javax.net.ssl.SSLContext; -import javax.net.ssl.SSLEngine; -import javax.net.ssl.SSLHandshakeException; -import javax.net.ssl.TrustManager; -import javax.net.ssl.X509TrustManager; - -import org.glassfish.grizzly.memory.Buffers; -import org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler; import org.glassfish.grizzly.utils.Futures; +import org.glassfish.grizzly.utils.ParallelWriteFilter; +import org.glassfish.grizzly.utils.RandomDelayOnWriteFilter; +import org.glassfish.grizzly.utils.StringFilter; +import org.junit.Before; import org.junit.Ignore; +import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; - -import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; -import static org.junit.Assert.*; +import org.junit.runners.Parameterized.Parameters; +import org.slf4j.Logger; /** * Set of SSL tests @@ -550,7 +551,7 @@ protected void doTestPingPongFilterChain(boolean isBlocking, } assertEquals(pingPongTurnArounds, get); } catch (TimeoutException e) { - logger.severe("Server timeout"); + logger.error("Server timeout"); } assertEquals(pingPongTurnArounds, @@ -671,8 +672,7 @@ public void completed(final Connection connection) { String receivedString = new String(receivedMessage); assertEquals(sentString, receivedString); } catch (Exception e) { - logger.log(Level.WARNING, "Error occurred when testing connection#{0} packet#{1}", - new Object[]{i, j}); + logger.warn("Error occurred when testing connection#{} packet#{}", i, j); throw e; } } @@ -767,8 +767,7 @@ protected void doTestPendingSSLClientWrites(int connectionsNum, connection.write(buffer); } } catch (Exception e) { - logger.log(Level.WARNING, "Error occurred when testing connection#{0} packet#{1}", - new Object[]{i, packetNum}); + logger.warn("Error occurred when testing connection#{} packet#{}", i, packetNum); throw e; } @@ -852,7 +851,7 @@ protected void doTestParallelWrites(int packetsNumber, int size) throws Exceptio try { connection.write("start"); } catch (Exception e) { - logger.log(Level.WARNING, "Error occurred when sending start command"); + logger.warn("Error occurred when sending start command"); throw e; } diff --git a/modules/grizzly/src/test/java/org/glassfish/grizzly/StandaloneTest.java b/modules/grizzly/src/test/java/org/glassfish/grizzly/StandaloneTest.java index 1db45adff5..0e43de794f 100644 --- a/modules/grizzly/src/test/java/org/glassfish/grizzly/StandaloneTest.java +++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/StandaloneTest.java @@ -43,13 +43,14 @@ import java.util.Arrays; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + + import org.glassfish.grizzly.nio.transport.TCPNIOServerConnection; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.streams.StreamReader; import org.glassfish.grizzly.streams.StreamWriter; +import org.slf4j.Logger; /** * Test standalone Grizzly implementation. @@ -161,8 +162,7 @@ public void run() { assertTrue(writeFuture.isDone()); } catch (Throwable e) { - logger.log(Level.WARNING, - "Error working with accepted connection", e); + logger.warn("Error working with accepted connection", e); assertTrue("Error working with accepted connection", false); } finally { connection.closeSilently(); @@ -170,8 +170,7 @@ public void run() { } catch (Exception e) { if (!transport.isStopped()) { - logger.log(Level.WARNING, - "Error accepting connection", e); + logger.warn("Error accepting connection", e); assertTrue("Error accepting connection", false); } } diff --git a/modules/grizzly/src/test/java/org/glassfish/grizzly/TCPNIOTransportTest.java b/modules/grizzly/src/test/java/org/glassfish/grizzly/TCPNIOTransportTest.java index d017c3c76d..dc6d7a41d4 100644 --- a/modules/grizzly/src/test/java/org/glassfish/grizzly/TCPNIOTransportTest.java +++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/TCPNIOTransportTest.java @@ -59,8 +59,6 @@ import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChainBuilder; @@ -93,6 +91,7 @@ import org.glassfish.grizzly.utils.StringFilter; import org.junit.Before; import org.junit.Test; +import org.slf4j.Logger; /** @@ -568,7 +567,7 @@ protected void doTestParallelWrites(int packetsNumber, try { connection.write("start"); } catch (Exception e) { - logger.log(Level.WARNING, "Error occurred when sending start command"); + logger.warn("Error occurred when sending start command"); throw e; } diff --git a/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/ByteBufferStreamsTest.java b/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/ByteBufferStreamsTest.java index d20eba7ebf..f5c1b16d50 100644 --- a/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/ByteBufferStreamsTest.java +++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/ByteBufferStreamsTest.java @@ -42,27 +42,15 @@ import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; -import org.glassfish.grizzly.impl.FutureImpl; -import org.glassfish.grizzly.impl.SafeFutureImpl; -import java.util.List; -import java.util.ArrayList; - import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; +import java.util.List; +import java.util.concurrent.BlockingQueue; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import junit.framework.Assert; -import org.glassfish.grizzly.nio.transport.TCPNIOTransport; -import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; -import org.glassfish.grizzly.streams.StreamReader; -import org.glassfish.grizzly.streams.StreamWriter; -import org.glassfish.grizzly.nio.transport.TCPNIOServerConnection; -import org.glassfish.grizzly.streams.AbstractStreamReader; -import org.glassfish.grizzly.streams.BufferedInput; -import org.glassfish.grizzly.utils.conditions.Condition; -import java.util.concurrent.BlockingQueue; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; @@ -70,7 +58,18 @@ import org.glassfish.grizzly.GrizzlyFuture; import org.glassfish.grizzly.GrizzlyTestCase; import org.glassfish.grizzly.StandaloneProcessor; +import org.glassfish.grizzly.impl.FutureImpl; +import org.glassfish.grizzly.impl.SafeFutureImpl; +import org.glassfish.grizzly.nio.transport.TCPNIOServerConnection; +import org.glassfish.grizzly.nio.transport.TCPNIOTransport; +import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; +import org.glassfish.grizzly.streams.AbstractStreamReader; +import org.glassfish.grizzly.streams.BufferedInput; +import org.glassfish.grizzly.streams.StreamReader; +import org.glassfish.grizzly.streams.StreamWriter; import org.glassfish.grizzly.utils.DataStructures; +import org.glassfish.grizzly.utils.conditions.Condition; +import org.slf4j.Logger; /** * Basic idea: @@ -125,24 +124,22 @@ public String toString() { } protected void werrMsg(Object obj, Throwable thr) { - LOGGER.log(Level.SEVERE, "###Checker({0}).write: Caught {1} at parameter {2}", - new Object[]{toString(), thr, obj}); + LOGGER.error("###Checker({}).write: Caught {} at parameter {}", this, thr, obj); } protected void rerrMsg(Object obj, Throwable thr) { - LOGGER.log(Level.SEVERE, "###Checker({0}).readAndCheck: Caught {1} at parameter {2}", - new Object[]{toString(), thr, obj}); + LOGGER.error("###Checker({}).readAndCheck: Caught {} at parameter {}", this, thr, obj); } public void wmsg() { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.SEVERE, "Write:{0}", toString()); + if (LOGGER.isTraceEnabled()) { + LOGGER.error("Write:{}", this); } } public void rmsg() { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.SEVERE, "ReadAndCheck:{0}", toString()); + if (LOGGER.isTraceEnabled()) { + LOGGER.error("ReadAndCheck:{}", this); } } @@ -1170,7 +1167,7 @@ public GrizzlyFuture notifyCondition(Condition condition, try { reader.readByteArray(checkArray, 0, 500); } catch (Exception e) { - LOGGER.log(Level.SEVERE, "Data generate error", e); + LOGGER.error("Data generate error", e); } Assert.assertTrue(Arrays.equals(checkArray, testdata)); @@ -1193,7 +1190,7 @@ public void tearDown() { clienttransport.shutdownNow(); } catch (Exception ex) { - LOGGER.log(Level.SEVERE, "Close", ex); + LOGGER.error("Close", ex); } } @@ -1210,7 +1207,7 @@ public void setupServer() { startEchoServerThread(servertransport, serverConnection); } catch (Exception ex) { - LOGGER.log(Level.SEVERE, "Server start error", ex); + LOGGER.error("Server start error", ex); } } @@ -1242,7 +1239,7 @@ public void setupClient() { getStreamWriter(clientconnection); } catch (Exception ex) { - LOGGER.log(Level.SEVERE, "Client start error", ex); + LOGGER.error("Client start error", ex); } } @@ -1270,9 +1267,8 @@ public void run() { return; } - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "reader.availableDataSize():{0},{1}", - new Object[]{reader.available(), checker.byteSize()}); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("reader.availableDataSize():{},{}", reader.available(), checker.byteSize()); } Future f = reader.notifyAvailable((int) checker.byteSize()); @@ -1293,16 +1289,14 @@ public void run() { } catch (Throwable e) { - LOGGER.log(Level.WARNING, - "Error working with accepted connection", e); + LOGGER.warn("Error working with accepted connection", e); } finally { connection.closeSilently(); } } catch (Exception e) { if (!transport.isStopped()) { - LOGGER.log(Level.WARNING, - "Error accepting connection", e); + LOGGER.warn("Error accepting connection", e); assertTrue("Error accepting connection", false); } } diff --git a/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/CompositeBufferInStreamTest.java b/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/CompositeBufferInStreamTest.java index 8b641248f7..720423421a 100644 --- a/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/CompositeBufferInStreamTest.java +++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/CompositeBufferInStreamTest.java @@ -52,13 +52,14 @@ import org.glassfish.grizzly.utils.Pair; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.GrizzlyTestCase; import org.glassfish.grizzly.StandaloneProcessor; +import org.slf4j.Logger; /** * Test how {@link CompositeBuffer} works with Streams. @@ -188,16 +189,14 @@ public void run() { // Read until whole buffer will be filled out } catch (Throwable e) { portions[i].getSecond().failure(e); - LOGGER.log(Level.WARNING, - "Error working with accepted connection on step: " + i, e); + LOGGER.warn("Error working with accepted connection on step: {}", i, e); } finally { connection.closeSilently(); } } catch (Exception e) { if (!transport.isStopped()) { - LOGGER.log(Level.WARNING, - "Error accepting connection", e); + LOGGER.warn("Error accepting connection", e); assertTrue("Error accepting connection", false); } } diff --git a/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/PooledMemoryManagerTest.java b/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/PooledMemoryManagerTest.java index 35e7a60d19..a99d44a048 100644 --- a/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/PooledMemoryManagerTest.java +++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/PooledMemoryManagerTest.java @@ -39,7 +39,18 @@ */ package org.glassfish.grizzly.memory; -import org.junit.Test; +import static org.glassfish.grizzly.memory.PooledMemoryManager.DEFAULT_BASE_BUFFER_SIZE; +import static org.glassfish.grizzly.memory.PooledMemoryManager.DEFAULT_GROWTH_FACTOR; +import static org.glassfish.grizzly.memory.PooledMemoryManager.DEFAULT_HEAP_USAGE_PERCENTAGE; +import static org.glassfish.grizzly.memory.PooledMemoryManager.DEFAULT_NUMBER_OF_POOLS; +import static org.glassfish.grizzly.memory.PooledMemoryManager.DEFAULT_PREALLOCATED_BUFFERS_PERCENTAGE; +import static org.glassfish.grizzly.memory.PooledMemoryManager.PoolSlice; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; import java.util.ArrayList; import java.util.Arrays; @@ -52,17 +63,14 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.Grizzly; +import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; import org.junit.runners.Parameterized.Parameters; -import static org.glassfish.grizzly.memory.PooledMemoryManager.*; -import static org.junit.Assert.*; - @RunWith(Parameterized.class) public class PooledMemoryManagerTest { @@ -811,10 +819,7 @@ public void run() { if (errorsSeen.get()) { for (int i = 0, len = errors.length; i < len; i++) { if (errors[i] != null) { - Logger.getAnonymousLogger().log(Level.SEVERE, - "Error in test thread " + (i + 1) + ": " + errors[i] - .getMessage(), - errors[i]); + Grizzly.logger(PooledMemoryManagerTest.class).error("Error in test thread {}: {}", i + 1, errors[i].getMessage(), errors[i]); } } fail("Test failed! See log for details."); diff --git a/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/ThreadLocalMemoryManagerTest.java b/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/ThreadLocalMemoryManagerTest.java index 0ca06f48d8..39e23be674 100644 --- a/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/ThreadLocalMemoryManagerTest.java +++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/memory/ThreadLocalMemoryManagerTest.java @@ -40,23 +40,23 @@ package org.glassfish.grizzly.memory; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.nio.ByteOrder; +import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; + +import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; import org.glassfish.grizzly.threadpool.GrizzlyExecutorService; import org.glassfish.grizzly.threadpool.ThreadPoolConfig; -import java.util.concurrent.ExecutorService; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.Buffer; -import org.glassfish.grizzly.Grizzly; import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.slf4j.Logger; /** * @author oleksiys @@ -417,17 +417,17 @@ private static class MyMemoryMonitoringProbe implements MemoryProbe { @Override public void onBufferAllocateEvent(int size) { - LOGGER.log(Level.INFO, "allocateNewBufferEvent: {0}", size); + LOGGER.info("allocateNewBufferEvent: {}", size); } @Override public void onBufferAllocateFromPoolEvent(int size) { - LOGGER.log(Level.INFO, "allocateBufferFromPoolEvent: {0}", size); + LOGGER.info("allocateBufferFromPoolEvent: {}", size); } @Override public void onBufferReleaseToPoolEvent(int size) { - LOGGER.log(Level.INFO, "releaseBufferToPoolEvent: {0}", size); + LOGGER.info("releaseBufferToPoolEvent: {}", size); } } } diff --git a/modules/grizzly/src/test/java/org/glassfish/grizzly/utils/ParallelWriteFilter.java b/modules/grizzly/src/test/java/org/glassfish/grizzly/utils/ParallelWriteFilter.java index 585229834c..9f05ee9e5a 100644 --- a/modules/grizzly/src/test/java/org/glassfish/grizzly/utils/ParallelWriteFilter.java +++ b/modules/grizzly/src/test/java/org/glassfish/grizzly/utils/ParallelWriteFilter.java @@ -39,6 +39,11 @@ */ package org.glassfish.grizzly.utils; +import java.io.IOException; +import java.util.Arrays; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.TimeUnit; + import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -48,13 +53,7 @@ import org.glassfish.grizzly.filterchain.NextAction; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; - -import java.io.IOException; -import java.util.Arrays; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; +import org.slf4j.Logger; public final class ParallelWriteFilter extends BaseFilter { @@ -112,7 +111,7 @@ public void updated(WriteResult result) { completionHandlerFuture.get(10, TimeUnit.SECONDS); } catch (Exception e) { - LOGGER.log(Level.SEVERE, "sending packet #" + packetNumber, e); + LOGGER.error("sending packet #{}", packetNumber, e); } } }); diff --git a/modules/http-ajp/src/main/java/org/glassfish/grizzly/http/ajp/AjpHandlerFilter.java b/modules/http-ajp/src/main/java/org/glassfish/grizzly/http/ajp/AjpHandlerFilter.java index 8f626fad51..005e83dd1f 100644 --- a/modules/http-ajp/src/main/java/org/glassfish/grizzly/http/ajp/AjpHandlerFilter.java +++ b/modules/http-ajp/src/main/java/org/glassfish/grizzly/http/ajp/AjpHandlerFilter.java @@ -44,8 +44,7 @@ import java.security.SecureRandom; import java.util.Properties; import java.util.Queue; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -64,6 +63,7 @@ import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.MemoryManager; import org.glassfish.grizzly.utils.DataStructures; +import org.slf4j.Logger; /** * Filter is working as Codec between Ajp and Http packets. @@ -477,8 +477,7 @@ private NextAction processShutdown(final FilterChainContext ctx, try { handler.onShutdown(connection); } catch (Exception e) { - LOGGER.log(Level.WARNING, - "Exception during ShutdownHandler execution", e); + LOGGER.warn("Exception during ShutdownHandler execution", e); } } diff --git a/modules/http-ajp/src/main/java/org/glassfish/grizzly/http/ajp/AjpHttpRequest.java b/modules/http-ajp/src/main/java/org/glassfish/grizzly/http/ajp/AjpHttpRequest.java index 12a804be74..b665aa8a6f 100644 --- a/modules/http-ajp/src/main/java/org/glassfish/grizzly/http/ajp/AjpHttpRequest.java +++ b/modules/http-ajp/src/main/java/org/glassfish/grizzly/http/ajp/AjpHttpRequest.java @@ -44,8 +44,7 @@ import java.net.InetAddress; import java.security.cert.CertificateFactory; import java.security.cert.X509Certificate; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.ThreadCache; import org.glassfish.grizzly.http.HttpRequestPacket; @@ -54,6 +53,7 @@ import org.glassfish.grizzly.http.util.DataChunk; import org.glassfish.grizzly.ssl.SSLSupport; import org.glassfish.grizzly.utils.BufferInputStream; +import org.slf4j.Logger; /** * {@link HttpRequestPacket} implementation, which also contains AJP @@ -114,7 +114,7 @@ public Object getAttribute(final String name) { jsseCerts = new X509Certificate[1]; jsseCerts[0] = cert; } catch (java.security.cert.CertificateException e) { - LOGGER.log(Level.SEVERE, "Certificate convertion failed", e); + LOGGER.error("Certificate convertion failed", e); return null; } @@ -191,8 +191,8 @@ public DataChunk remoteHost() { remoteAddr().toString()). getHostName()); } catch (IOException iex) { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "Unable to resolve {0}", remoteAddr()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Unable to resolve {}", remoteAddr()); } } } diff --git a/modules/http-ajp/src/test/java/org/glassfish/grizzly/http/ajp/BasicAjpTest.java b/modules/http-ajp/src/test/java/org/glassfish/grizzly/http/ajp/BasicAjpTest.java index 7d6de94374..2a8c739e89 100644 --- a/modules/http-ajp/src/test/java/org/glassfish/grizzly/http/ajp/BasicAjpTest.java +++ b/modules/http-ajp/src/test/java/org/glassfish/grizzly/http/ajp/BasicAjpTest.java @@ -49,7 +49,7 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -71,6 +71,7 @@ import org.glassfish.grizzly.ssl.SSLSupport; import org.junit.Assert; import org.junit.Test; +import org.slf4j.Logger; import static org.junit.Assert.*; @@ -611,7 +612,7 @@ public void service(Request request, Response response) throws Exception { if (isOk) { response.setStatus(200, "FINE"); } else { - LOGGER.warning(errorBuilder.toString()); + LOGGER.warn(errorBuilder.toString()); response.setStatus(500, "ERROR"); } } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/CLStaticHttpHandler.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/CLStaticHttpHandler.java index d425d50fac..348704c01e 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/CLStaticHttpHandler.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/CLStaticHttpHandler.java @@ -50,8 +50,8 @@ import java.net.URLConnection; import java.util.jar.JarEntry; import java.util.jar.JarFile; -import java.util.logging.Level; -import java.util.logging.Logger; + + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.WriteHandler; @@ -64,6 +64,7 @@ import org.glassfish.grizzly.memory.BufferArray; import org.glassfish.grizzly.memory.MemoryManager; import org.glassfish.grizzly.utils.ArraySet; +import org.slf4j.Logger; /** * {@link HttpHandler}, which processes requests to a static resources resolved @@ -267,8 +268,8 @@ protected boolean handle(String resourcePath, } if (!found) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Resource not found {0}", resourcePath); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Resource not found {}", resourcePath); } return false; } @@ -277,9 +278,8 @@ protected boolean handle(String resourcePath, // If it's not HTTP GET - return method is not supported status if (!Method.GET.equals(request.getMethod())) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Resource found {0}, but HTTP method {1} is not allowed", - new Object[] {resourcePath, request.getMethod()}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Resource found {}, but HTTP method {} is not allowed", resourcePath, request.getMethod()); } response.setStatus(HttpStatus.METHOD_NOT_ALLOWED_405); response.setHeader(Header.Allow, "GET"); @@ -319,8 +319,8 @@ protected boolean handle(String resourcePath, private URL lookupResource(String resourcePath) { final String[] docRootsLocal = docRoots.getArray(); if (docRootsLocal == null || docRootsLocal.length == 0) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "No doc roots registered -> resource {0} is not found ", resourcePath); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("No doc roots registered -> resource {} is not found ", resourcePath); } return null; @@ -417,7 +417,7 @@ private static class NonBlockingDownloadHandler implements WriteHandler { @Override public void onWritePossible() throws Exception { - LOGGER.log(Level.FINE, "[onWritePossible]"); + LOGGER.debug("[onWritePossible]"); // send CHUNK of data final boolean isWriteMore = sendChunk(); @@ -429,7 +429,7 @@ public void onWritePossible() throws Exception { @Override public void onError(Throwable t) { - LOGGER.log(Level.FINE, "[onError] ", t); + LOGGER.debug("[onError] ", t); response.setStatus(500, t.getMessage()); complete(true); } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/FileCacheFilter.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/FileCacheFilter.java index 171f77cb1f..69fb5650cc 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/FileCacheFilter.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/FileCacheFilter.java @@ -44,8 +44,8 @@ import java.io.FileInputStream; import java.io.IOException; import java.nio.channels.FileChannel; -import java.util.logging.Level; -import java.util.logging.Logger; + + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.EmptyCompletionHandler; import org.glassfish.grizzly.FileTransfer; @@ -66,6 +66,7 @@ import org.glassfish.grizzly.http.server.filecache.FileCacheEntry; import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.memory.Buffers; +import org.slf4j.Logger; /** * @@ -208,8 +209,7 @@ private NextAction sendFileZeroCopy(final FilterChainContext ctx, ctx.write(f, new EmptyCompletionHandler() { @Override public void failed(Throwable throwable) { - LOGGER.log(Level.FINE, "Error reported during file-send entry: " + - cacheEntry, throwable); + LOGGER.debug("Error reported during file-send entry: {}", cacheEntry, throwable); } }); diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpHandler.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpHandler.java index 9e2d71843f..9e25dda1b8 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpHandler.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpHandler.java @@ -44,8 +44,6 @@ import java.io.IOException; import java.nio.charset.Charset; import java.util.concurrent.Executor; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -61,6 +59,7 @@ import org.glassfish.grizzly.http.util.RequestURIRef; import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.utils.Charsets; +import org.slf4j.Logger; /** * Base class to use when Request/Response/InputStream/OutputStream @@ -179,8 +178,7 @@ boolean doHandle(final Request request, final Response response) throws Exceptio return runService(request, response); } catch (Exception t) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVER_HTTPHANDLER_SERVICE_ERROR(), t); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_HTTPHANDLER_SERVICE_ERROR(), t); HtmlHelper.setErrorAndSendErrorPage(request, response, response.getErrorPageGenerator(), 500, HttpStatus.INTERNAL_SERVER_ERROR_500.getReasonPhrase(), @@ -224,7 +222,7 @@ public void run() { service(request, response); wasSuspended = suspendStatus.getAndInvalidate(); } catch (Throwable e) { - LOGGER.log(Level.FINE, "service exception", e); + LOGGER.debug("service exception", e); if (!response.isCommitted()) { response.reset(); try { diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpHandlerChain.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpHandlerChain.java index c7a6c932d5..9664ac59fb 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpHandlerChain.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpHandlerChain.java @@ -46,8 +46,7 @@ import java.util.Map; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.locks.ReentrantReadWriteLock; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.server.jmxbase.JmxEventListener; @@ -60,6 +59,7 @@ import org.glassfish.grizzly.http.util.RequestURIRef; import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.utils.DataStructures; +import org.slf4j.Logger; /** * The HttpHandlerChain class allows the invocation of multiple {@link HttpHandler}s @@ -228,13 +228,12 @@ boolean doHandle(final Request request, final Response response) } catch (Exception t) { try { response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR_500); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Internal server error", t); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Internal server error", t); } } catch (Exception ex2) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVER_HTTPHANDLERCHAIN_ERRORPAGE(), ex2); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_HTTPHANDLERCHAIN_ERRORPAGE(), ex2); } } } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpServer.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpServer.java index dbfcfe6064..b1f00abb43 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpServer.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpServer.java @@ -54,8 +54,7 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.ConnectionProbe; import org.glassfish.grizzly.EmptyCompletionHandler; @@ -77,8 +76,8 @@ import org.glassfish.grizzly.http.server.filecache.FileCache; import org.glassfish.grizzly.http.server.jmxbase.JmxEventListener; import org.glassfish.grizzly.impl.FutureImpl; -import org.glassfish.grizzly.memory.MemoryProbe; import org.glassfish.grizzly.jmxbase.GrizzlyJmxManager; +import org.glassfish.grizzly.memory.MemoryProbe; import org.glassfish.grizzly.monitoring.MonitoringConfig; import org.glassfish.grizzly.monitoring.MonitoringUtils; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; @@ -91,6 +90,7 @@ import org.glassfish.grizzly.utils.DelayedExecutor; import org.glassfish.grizzly.utils.Futures; import org.glassfish.grizzly.utils.IdleTimeoutFilter; +import org.slf4j.Logger; /** @@ -168,11 +168,9 @@ public synchronized void addListener(final NetworkListener listener) { try { listener.start(); } catch (IOException ioe) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.log(Level.SEVERE, - "Failed to start listener [{0}] : {1}", - new Object[] { listener.toString(), ioe.toString() }); - LOGGER.log(Level.SEVERE, ioe.toString(), ioe); + if (LOGGER.isErrorEnabled()) { + LOGGER.error("Failed to start listener [{}] : {}", listener, ioe.toString()); + LOGGER.error(ioe.toString(), ioe); } } } @@ -226,11 +224,9 @@ public synchronized NetworkListener removeListener(final String name) { try { listener.shutdownNow(); } catch (IOException ioe) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.log(Level.SEVERE, - "Failed to shutdown listener [{0}] : {1}", - new Object[] { listener.toString(), ioe.toString() }); - LOGGER.log(Level.SEVERE, ioe.toString(), ioe); + if (LOGGER.isErrorEnabled()) { + LOGGER.error("Failed to shutdown listener [{}] : {}", listener, ioe.toString()); + LOGGER.error(ioe.toString(), ioe); } } } @@ -276,11 +272,9 @@ public synchronized void start() throws IOException{ try { listener.start(); } catch (IOException ioe) { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, - "Failed to start listener [{0}] : {1}", - new Object[]{listener.toString(), ioe.toString()}); - LOGGER.log(Level.FINEST, ioe.toString(), ioe); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Failed to start listener [{}] : {}", listener, ioe.toString()); + LOGGER.trace(ioe.toString(), ioe); } throw ioe; @@ -295,8 +289,8 @@ public synchronized void start() throws IOException{ } } - if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.log(Level.INFO, "[{0}] Started.", getServerConfiguration().getName()); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("[{}] Started.", getServerConfiguration().getName()); } } @@ -452,7 +446,7 @@ public synchronized void shutdownNow() { } } catch (Exception e) { - LOGGER.log(Level.WARNING, null, e); + LOGGER.warn(null, e); } finally { for (final NetworkListener listener : listeners.values()) { final Processor p = listener.getTransport().getProcessor(); diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpServerFilter.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpServerFilter.java index 6814ec39d0..a6b98a47f5 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpServerFilter.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/HttpServerFilter.java @@ -40,13 +40,21 @@ package org.glassfish.grizzly.http.server; +import java.io.IOException; +import java.util.concurrent.atomic.AtomicInteger; +import java.util.concurrent.atomic.AtomicReference; + +import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.EmptyCompletionHandler; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.ReadHandler; import org.glassfish.grizzly.attributes.Attribute; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.filterchain.FilterChainEvent; import org.glassfish.grizzly.filterchain.NextAction; +import org.glassfish.grizzly.filterchain.TransportFilter; import org.glassfish.grizzly.http.HttpContent; import org.glassfish.grizzly.http.HttpContext; import org.glassfish.grizzly.http.HttpPacket; @@ -54,26 +62,15 @@ import org.glassfish.grizzly.http.HttpResponsePacket; import org.glassfish.grizzly.http.Method; import org.glassfish.grizzly.http.server.util.HtmlHelper; -import org.glassfish.grizzly.http.util.HttpStatus; -import org.glassfish.grizzly.utils.DelayedExecutor; - -import java.io.IOException; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.CompletionHandler; -import org.glassfish.grizzly.EmptyCompletionHandler; -import org.glassfish.grizzly.filterchain.FilterChainEvent; -import org.glassfish.grizzly.filterchain.TransportFilter; - import org.glassfish.grizzly.http.util.Header; +import org.glassfish.grizzly.http.util.HttpStatus; import org.glassfish.grizzly.localization.LogMessages; - import org.glassfish.grizzly.monitoring.DefaultMonitoringConfig; import org.glassfish.grizzly.monitoring.MonitoringAware; import org.glassfish.grizzly.monitoring.MonitoringConfig; import org.glassfish.grizzly.monitoring.MonitoringUtils; +import org.glassfish.grizzly.utils.DelayedExecutor; +import org.slf4j.Logger; /** @@ -237,8 +234,7 @@ public NextAction handleRead(final FilterChainContext ctx) } } } catch (Exception t) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVER_FILTER_HTTPHANDLER_INVOCATION_ERROR(), t); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_FILTER_HTTPHANDLER_INVOCATION_ERROR(), t); request.getProcessingState().setError(true); @@ -251,8 +247,7 @@ public NextAction handleRead(final FilterChainContext ctx) t); } } catch (Throwable t) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVER_FILTER_UNEXPECTED(), t); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_FILTER_UNEXPECTED(), t); throw new IllegalStateException(t); } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/NetworkListener.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/NetworkListener.java index 48c7803b00..82469e48e3 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/NetworkListener.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/NetworkListener.java @@ -46,8 +46,8 @@ import java.util.HashSet; import java.util.Set; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + + import javax.net.ssl.SSLEngine; import org.glassfish.grizzly.CompletionHandler; @@ -75,6 +75,7 @@ import org.glassfish.grizzly.threadpool.ThreadPoolConfig; import org.glassfish.grizzly.utils.ArraySet; import org.glassfish.grizzly.utils.Futures; +import org.slf4j.Logger; public class NetworkListener { private static final Logger LOGGER = Grizzly.logger(NetworkListener.class); @@ -761,10 +762,8 @@ public void shutdownForced() { state = State.RUNNING; - if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.log(Level.INFO, - "Started listener bound to [{0}]", - host + ':' + port); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Started listener bound to [{}]", host + ':' + port); } } @@ -813,10 +812,8 @@ public synchronized void shutdownNow() throws IOException { try { serverConnection = null; transport.shutdownNow(); - if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.log(Level.INFO, - "Stopped listener bound to [{0}]", - host + ':' + port); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Stopped listener bound to [{}]", host + ':' + port); } } finally { state = State.STOPPED; @@ -845,10 +842,8 @@ public synchronized void pause() { } transport.pause(); state = State.PAUSED; - if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.log(Level.INFO, - "Paused listener bound to [{0}]", - host + ':' + port); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Paused listener bound to [{}]", host + ':' + port); } } @@ -862,10 +857,8 @@ public synchronized void resume() { } transport.resume(); state = State.RUNNING; - if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.log(Level.INFO, - "Resumed listener bound to [{0}]", - host + ':' + port); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Resumed listener bound to [{}]", host + ':' + port); } } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/Request.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/Request.java index 9865eb82d2..c59aae6032 100755 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/Request.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/Request.java @@ -58,6 +58,8 @@ package org.glassfish.grizzly.http.server; +import static org.glassfish.grizzly.http.util.Constants.FORM_POST_CONTENT_TYPE; + import java.io.CharConversionException; import java.io.IOException; import java.io.InputStream; @@ -73,9 +75,9 @@ import java.util.Set; import java.util.TreeMap; import java.util.concurrent.Executor; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.security.auth.Subject; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.ReadHandler; @@ -107,8 +109,7 @@ import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.utils.Charsets; import org.glassfish.grizzly.utils.JdkVersion; - -import static org.glassfish.grizzly.http.util.Constants.FORM_POST_CONTENT_TYPE; +import org.slf4j.Logger; /** * Wrapper object for the Coyote request. * @@ -144,8 +145,8 @@ public class Request { Class.forName("org.glassfish.grizzly.http.server.TagLocaleParser"); lp = localeParserClazz.newInstance(); } catch (Throwable e) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Can't load JDK7 TagLocaleParser", e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Can't load JDK7 TagLocaleParser", e); } lp = new LegacyLocaleParser(); } @@ -628,8 +629,7 @@ protected void onAfterService() { try { anAfterServicesList.onAfterService(this); } catch (Exception e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVER_REQUEST_AFTERSERVICE_NOTIFICATION_ERROR(), e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_REQUEST_AFTERSERVICE_NOTIFICATION_ERROR(), e); } } } @@ -2069,8 +2069,8 @@ protected void parseRequestParameters() { } if ((maxFormPostSize > 0) && (len > maxFormPostSize)) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.warning(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_REQUEST_POST_TOO_LARGE()); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_REQUEST_POST_TOO_LARGE()); } throw new IllegalStateException(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_REQUEST_POST_TOO_LARGE()); @@ -2086,8 +2086,7 @@ protected void parseRequestParameters() { try { skipPostBody(read); } catch (Exception e) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVER_REQUEST_BODY_SKIP(), e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_REQUEST_BODY_SKIP(), e); } } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/Response.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/Response.java index da9e83f74b..289b92210f 100755 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/Response.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/Response.java @@ -58,6 +58,8 @@ package org.glassfish.grizzly.http.server; +import static org.glassfish.grizzly.http.util.Constants.DEFAULT_HTTP_CHARACTER_ENCODING; + import java.io.IOException; import java.io.OutputStream; import java.io.Writer; @@ -73,9 +75,7 @@ import java.util.Locale; import java.util.TimeZone; import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.CloseListener; import org.glassfish.grizzly.CloseType; import org.glassfish.grizzly.Closeable; @@ -95,8 +95,6 @@ import org.glassfish.grizzly.http.server.util.Globals; import org.glassfish.grizzly.http.server.util.HtmlHelper; import org.glassfish.grizzly.http.util.CharChunk; - -import static org.glassfish.grizzly.http.util.Constants.*; import org.glassfish.grizzly.http.util.ContentType; import org.glassfish.grizzly.http.util.CookieSerializerUtils; import org.glassfish.grizzly.http.util.FastHttpDateFormat; @@ -109,6 +107,7 @@ import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.utils.DelayedExecutor; import org.glassfish.grizzly.utils.DelayedExecutor.DelayQueue; +import org.slf4j.Logger; /** * Wrapper object for the Coyote response. @@ -516,14 +515,12 @@ public void finish() { try { outputBuffer.endRequest(); } catch (IOException e) { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, - LogMessages.WARNING_GRIZZLY_HTTP_SERVER_RESPONSE_FINISH_ERROR(), e); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_RESPONSE_FINISH_ERROR(), e); } } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVER_RESPONSE_FINISH_ERROR(), t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_RESPONSE_FINISH_ERROR(), t); } } } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/StaticHttpHandler.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/StaticHttpHandler.java index f593927f3a..f9211a5781 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/StaticHttpHandler.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/StaticHttpHandler.java @@ -41,13 +41,13 @@ import java.io.File; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.Method; import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.http.util.HttpStatus; import org.glassfish.grizzly.utils.ArraySet; +import org.slf4j.Logger; /** * {@link HttpHandler}, which processes requests to a static resources. @@ -235,8 +235,8 @@ protected boolean handle(final String uri, } if (!found) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "File not found {0}", resource); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("File not found {}", resource); } return false; } @@ -245,9 +245,8 @@ protected boolean handle(final String uri, // If it's not HTTP GET - return method is not supported status if (!Method.GET.equals(request.getMethod())) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "File found {0}, but HTTP method {1} is not allowed", - new Object[] {resource, request.getMethod()}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("File found {}, but HTTP method {} is not allowed", resource, request.getMethod()); } response.setStatus(HttpStatus.METHOD_NOT_ALLOWED_405); response.setHeader(Header.Allow, "GET"); diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/StaticHttpHandlerBase.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/StaticHttpHandlerBase.java index 3f8a94a869..df66f705d6 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/StaticHttpHandlerBase.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/StaticHttpHandlerBase.java @@ -45,22 +45,22 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.nio.channels.FileChannel; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.WriteHandler; import org.glassfish.grizzly.filterchain.Filter; import org.glassfish.grizzly.filterchain.FilterChain; import org.glassfish.grizzly.filterchain.FilterChainContext; -import org.glassfish.grizzly.http.server.filecache.FileCache; import org.glassfish.grizzly.http.io.NIOOutputStream; import org.glassfish.grizzly.http.io.OutputBuffer; -import org.glassfish.grizzly.http.util.MimeType; +import org.glassfish.grizzly.http.server.filecache.FileCache; import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.http.util.HttpStatus; +import org.glassfish.grizzly.http.util.MimeType; import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.MemoryManager; +import org.slf4j.Logger; /** * The basic class for {@link HttpHandler} implementations, @@ -333,7 +333,7 @@ private static class NonBlockingDownloadHandler implements WriteHandler { @Override public void onWritePossible() throws Exception { - LOGGER.log(Level.FINE, "[onWritePossible]"); + LOGGER.debug("[onWritePossible]"); // send CHUNK of data final boolean isWriteMore = sendChunk(); @@ -345,7 +345,7 @@ public void onWritePossible() throws Exception { @Override public void onError(Throwable t) { - LOGGER.log(Level.FINE, "[onError] ", t); + LOGGER.debug("[onError] ", t); response.setStatus(500, t.getMessage()); complete(true); } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/AccessLogProbe.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/AccessLogProbe.java index 53343b047d..58f5bf8e4b 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/AccessLogProbe.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/AccessLogProbe.java @@ -40,10 +40,7 @@ package org.glassfish.grizzly.http.server.accesslog; -import static java.util.logging.Level.WARNING; - import java.util.Date; -import java.util.logging.Logger; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -52,6 +49,7 @@ import org.glassfish.grizzly.http.server.HttpServerProbe; import org.glassfish.grizzly.http.server.Request; import org.glassfish.grizzly.http.server.Response; +import org.slf4j.Logger; /** * A {@linkplain HttpServerProbe Grizzly probe} used to provide @@ -147,7 +145,7 @@ public void onRequestCompleteEvent(HttpServerFilter filter, Connection connectio try { appender.append(format.format(response, requestMillis, responseNanos)); } catch (Throwable throwable) { - LOGGER.log(WARNING, "Exception caught appending to access log", throwable); + LOGGER.warn("Exception caught appending to access log", throwable); } } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/ApacheLogFormat.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/ApacheLogFormat.java index 1f6cd91694..4d895ace72 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/ApacheLogFormat.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/ApacheLogFormat.java @@ -40,15 +40,12 @@ package org.glassfish.grizzly.http.server.accesslog; -import static java.util.logging.Level.WARNING; - import java.text.SimpleDateFormat; import java.util.ArrayList; import java.util.Date; import java.util.Iterator; import java.util.List; import java.util.TimeZone; -import java.util.logging.Logger; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.Cookie; @@ -58,6 +55,7 @@ import org.glassfish.grizzly.http.server.Request; import org.glassfish.grizzly.http.server.Response; import org.glassfish.grizzly.http.util.MimeHeaders; +import org.slf4j.Logger; /** * An {@link AccessLogFormat} using a standard vaguely similar and heavily @@ -214,7 +212,7 @@ public String format(Response response, Date timeStamp, long responseNanos) { for (Field field: fields) try { field.format(builder, request, response, timeStamp, responseNanos); } catch (Exception exception) { - LOGGER.log(WARNING, "Exception formatting access log entry", exception); + LOGGER.warn("Exception formatting access log entry", exception); builder.append('-'); } return builder.toString(); diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/FileAppender.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/FileAppender.java index aff4d6f38c..8cb6473e0a 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/FileAppender.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/FileAppender.java @@ -43,10 +43,10 @@ import java.io.File; import java.io.FileOutputStream; import java.io.IOException; -import java.util.logging.Logger; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.HttpServer; +import org.slf4j.Logger; /** * An {@link AccessLogAppender appender} writing log entries to {@link File}s. @@ -79,6 +79,6 @@ public FileAppender(File file) public FileAppender(File file, boolean append) throws IOException { super(new FileOutputStream(file, append)); - LOGGER.info("Access log file \"" + file.getAbsolutePath() + "\" opened"); + LOGGER.info("Access log file \"{}\" opened", file.getAbsolutePath()); } } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/QueueingAppender.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/QueueingAppender.java index 9b2e86c45f..2e0d8d2740 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/QueueingAppender.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/QueueingAppender.java @@ -40,15 +40,12 @@ package org.glassfish.grizzly.http.server.accesslog; -import static java.util.logging.Level.FINE; -import static java.util.logging.Level.WARNING; - import java.io.IOException; import java.util.concurrent.LinkedBlockingQueue; -import java.util.logging.Logger; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.HttpServer; +import org.slf4j.Logger; /** * An {@link AccessLogAppender appender} enqueueing log entries into a @@ -90,7 +87,7 @@ public void append(String accessLogEntry) if (thread.isAlive()) try { queue.put(accessLogEntry); } catch (InterruptedException exception) { - LOGGER.log(FINE, "Interrupted adding log entry to the queue", exception); + LOGGER.debug("Interrupted adding log entry to the queue", exception); } } @@ -100,7 +97,7 @@ public void close() throws IOException { try { thread.join(); } catch (InterruptedException exception) { - LOGGER.log(FINE, "Interrupted stopping de-queuer", exception); + LOGGER.debug("Interrupted stopping de-queuer", exception); } finally { appender.close(); } @@ -117,10 +114,10 @@ public void run() { final String accessLogEntry = queue.take(); if (accessLogEntry != null) appender.append(accessLogEntry); } catch (InterruptedException exception) { - LOGGER.log(FINE, "Interrupted waiting for log entry to be queued, exiting!", exception); + LOGGER.debug("Interrupted waiting for log entry to be queued, exiting!", exception); return; } catch (Throwable throwable) { - LOGGER.log(WARNING, "Exception caught appending ququed log entry", throwable); + LOGGER.warn("Exception caught appending ququed log entry", throwable); } } } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/RotatingFileAppender.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/RotatingFileAppender.java index 9aa0dd0004..1d3357e3af 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/RotatingFileAppender.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/accesslog/RotatingFileAppender.java @@ -40,16 +40,14 @@ package org.glassfish.grizzly.http.server.accesslog; -import static java.util.logging.Level.WARNING; - import java.io.File; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.logging.Logger; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.HttpServer; +import org.slf4j.Logger; /** * An {@link AccessLogAppender appender} writing log entries to {@link File}s, @@ -97,7 +95,7 @@ public class RotatingFileAppender implements AccessLogAppender { public RotatingFileAppender(File directory, String filePattern) throws IOException { this(filePattern, filePattern, directory); - LOGGER.fine("Creating rotating log appender in \"" + directory + "\" with file pattern \"" + filePattern+ "\""); + LOGGER.debug("Creating rotating log appender in \"{}\" with file pattern \"{}\"", directory, filePattern); } /** @@ -125,7 +123,7 @@ public RotatingFileAppender(File directory, String filePattern) public RotatingFileAppender(File directory, String fileName, String archivePattern) throws IOException { this(escape(fileName), archivePattern, directory); - LOGGER.fine("Creating rotating log appender in \"" + directory + "\" writing to \"" + fileName + "\" and archive pattern \"" + archivePattern + "\""); + LOGGER.debug("Creating rotating log appender in \"{}\" writing to \"{}\" and archive pattern \"{}\"", directory, fileName, archivePattern); } /* ====================================================================== */ @@ -197,7 +195,7 @@ public void append(String accessLogEntry) appender = new FileAppender(currentFile, true); } catch (IOException exception) { - LOGGER.log(WARNING, "I/O error rotating access log file", exception); + LOGGER.warn("I/O error rotating access log file", exception); } appender.append(accessLogEntry); diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/filecache/FileCache.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/filecache/FileCache.java index ae262c0d1d..370161503b 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/filecache/FileCache.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/filecache/FileCache.java @@ -64,8 +64,8 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; -import java.util.logging.Level; -import java.util.logging.Logger; + + import java.util.zip.GZIPOutputStream; import org.glassfish.grizzly.http.CompressionConfig; import org.glassfish.grizzly.http.Method; @@ -76,6 +76,7 @@ import org.glassfish.grizzly.monitoring.MonitoringConfig; import org.glassfish.grizzly.monitoring.MonitoringUtils; import org.glassfish.grizzly.utils.DataStructures; +import org.slf4j.Logger; /** * This class implements a file caching mechanism used to cache static resources. @@ -328,8 +329,7 @@ public FileCacheEntry get(final HttpRequestPacket request) { notifyProbesError(this, e); // If an unexpected exception occurs, try to serve the page // as if it wasn't in a cache. - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVER_FILECACHE_GENERAL_ERROR(), e); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_FILECACHE_GENERAL_ERROR(), e); } return null; @@ -734,7 +734,7 @@ protected void compressFile(final FileCacheEntry entry) { entry.compressedFileSize = size; entry.compressedFile = tmpCompressedFile; } catch (IOException e) { - LOGGER.log(Level.FINE, "Can not compress file: " + entry.plainFile, e); + LOGGER.debug("Can not compress file: {}", entry.plainFile, e); } } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/filecache/FileCacheEntry.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/filecache/FileCacheEntry.java index 30f2e3729d..d596896dcd 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/filecache/FileCacheEntry.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/filecache/FileCacheEntry.java @@ -43,13 +43,12 @@ import java.io.File; import java.nio.ByteBuffer; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.CompressionConfig; import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.util.ContentType; +import org.slf4j.Logger; /** * The entry value in the file cache map. @@ -186,10 +185,8 @@ public String toString() { protected void finalize() throws Throwable { if (compressedFile != null) { if (!compressedFile.delete()) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, - "Unable to delete file {0}. Will try to delete again upon VM exit.", - compressedFile.getCanonicalPath()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Unable to delete file {}. Will try to delete again upon VM exit.", compressedFile.getCanonicalPath()); } compressedFile.deleteOnExit(); } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/io/ServerOutputBuffer.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/io/ServerOutputBuffer.java index 6c5a37ae25..a2a1087061 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/io/ServerOutputBuffer.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/io/ServerOutputBuffer.java @@ -40,15 +40,14 @@ package org.glassfish.grizzly.http.server.io; +import java.io.File; +import java.util.concurrent.Executor; + import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.WriteResult; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.http.io.OutputBuffer; import org.glassfish.grizzly.http.server.Response; - -import java.io.File; -import java.util.concurrent.Executor; -import java.util.logging.Level; import org.glassfish.grizzly.localization.LogMessages; public class ServerOutputBuffer extends OutputBuffer { @@ -108,19 +107,16 @@ private CompletionHandler createInternalCompletionHandler( ch = new CompletionHandler() { @Override public void cancelled() { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVER_SERVEROUTPUTBUFFER_FILE_TRANSFER_CANCELLED(file.getAbsolutePath())); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_SERVEROUTPUTBUFFER_FILE_TRANSFER_CANCELLED(file.getAbsolutePath())); } serverResponse.resume(); } @Override public void failed(Throwable throwable) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.log(Level.SEVERE, - LogMessages.WARNING_GRIZZLY_HTTP_SERVER_SERVEROUTPUTBUFFER_FILE_TRANSFER_FAILED(file.getAbsolutePath(), throwable.getMessage()), - throwable); + if (LOGGER.isErrorEnabled()) { + LOGGER.error(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_SERVEROUTPUTBUFFER_FILE_TRANSFER_FAILED(file.getAbsolutePath(), throwable.getMessage()), throwable); } serverResponse.resume(); } diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/ClassLoaderUtil.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/ClassLoaderUtil.java index d52a51a5cd..332ce2f17a 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/ClassLoaderUtil.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/ClassLoaderUtil.java @@ -46,9 +46,9 @@ import java.net.URLClassLoader; import java.security.AccessController; import java.security.PrivilegedAction; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Grizzly; +import org.slf4j.Logger; /** * Simple {@link ClassLoader} utility. @@ -197,8 +197,7 @@ public static Object load(String clazzName, ClassLoader classLoader) { className = Class.forName(clazzName, true, classLoader); return className.newInstance(); } catch (Throwable t) { - LOGGER.log(Level.SEVERE, "Unable to load class " - + clazzName, t); + LOGGER.error("Unable to load class {}", clazzName, t); } return null; diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/Mapper.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/Mapper.java index fd75edc1cc..d3c7ceaf20 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/Mapper.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/Mapper.java @@ -61,7 +61,7 @@ import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.util.Constants; import java.io.IOException; -import java.util.logging.Level; + import org.glassfish.grizzly.Grizzly; @@ -69,7 +69,7 @@ import java.util.Map; import java.util.List; import java.util.ArrayList; -import java.util.logging.Logger; + import org.glassfish.grizzly.http.server.naming.DirContext; import org.glassfish.grizzly.http.server.naming.NamingContext; import org.glassfish.grizzly.http.server.naming.NamingException; @@ -79,6 +79,7 @@ import org.glassfish.grizzly.http.util.MessageBytes; import org.glassfish.grizzly.utils.Charsets; +import org.slf4j.Logger; /** * Mapper, which implements the servlet API mapping rules (which are derived @@ -89,7 +90,7 @@ @SuppressWarnings({"UnusedDeclaration"}) public class Mapper { - private final static Logger logger = Grizzly.logger(Mapper.class); + private final static Logger LOGGER = Grizzly.logger(Mapper.class); private static final String DEFAULT_SERVLET = System.getProperty("org.glassfish.grizzly.servlet.defaultServlet", "default"); @@ -342,8 +343,7 @@ public void setContext(String path, String[] welcomeResources, pos = findIgnoreCase(newHosts, hostName); } if (pos < 0) { - logger.log(Level.FINE, "No host found: {0} for Mapper listening on port: {1}", - new Object[]{hostName, port}); + LOGGER.debug("No host found: {} for Mapper listening on port: {}", hostName, port); return; } Host host = newHosts[pos]; @@ -487,7 +487,7 @@ public void addWrapper(String hostName, String contextPath, String path, Context[] contexts = host.contextList.contexts; int pos2 = find(contexts, contextPath); if( pos2<0 ) { - logger.log(Level.SEVERE, "No context found: {0}", contextPath); + LOGGER.error("No context found: {}", contextPath); return; } Context ctx = contexts[pos2]; diff --git a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/RequestUtils.java b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/RequestUtils.java index 94d979d945..a83dcc5e01 100644 --- a/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/RequestUtils.java +++ b/modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/RequestUtils.java @@ -43,8 +43,7 @@ import java.io.File; import java.io.IOException; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.GrizzlyFuture; import org.glassfish.grizzly.http.server.Request; @@ -53,6 +52,7 @@ import org.glassfish.grizzly.ssl.SSLBaseFilter.CertificateEvent; import org.glassfish.grizzly.ssl.SSLSupport; import org.glassfish.grizzly.ssl.SSLSupportImpl; +import org.slf4j.Logger; public class RequestUtils { @@ -79,10 +79,8 @@ public static Object populateCertificateAttribute(final Request request) { // TODO: make the timeout configurable certificates = certFuture.get(30, TimeUnit.SECONDS); } catch (Exception e) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, - "Unable to obtain certificates from peer.", - e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Unable to obtain certificates from peer.", e); } } request.setAttribute(SSLSupport.CERTIFICATE_KEY, certificates); @@ -112,10 +110,8 @@ public static void populateSSLAttributes(final Request request) { request.setAttribute(SSLSupport.SESSION_ID_KEY, sslO); } } catch (Exception ioe) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, - "Unable to populate SSL attributes", - ioe); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Unable to populate SSL attributes", ioe); } } } @@ -127,9 +123,8 @@ public static void handleSendFile(final Request request) { if (f != null) { final Response response = request.getResponse(); if (response.isCommitted()) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVER_REQUESTUTILS_SENDFILE_FAILED()); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVER_REQUESTUTILS_SENDFILE_FAILED()); } return; diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/AggregatorAddOnTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/AggregatorAddOnTest.java index 394c2ad5cd..80cf6fa212 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/AggregatorAddOnTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/AggregatorAddOnTest.java @@ -40,6 +40,8 @@ package org.glassfish.grizzly.http.server; +import static org.junit.Assert.assertEquals; + import java.io.File; import java.io.FileOutputStream; import java.io.IOException; @@ -48,8 +50,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.BaseFilter; @@ -79,8 +80,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; - -import static org.junit.Assert.*; +import org.slf4j.Logger; /** * Test AggregatorAddOn @@ -259,8 +259,7 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException { try { out.close(); - LOGGER.log(Level.INFO, "Client received file ({0} bytes) in {1}ms.", - new Object[]{f.length(), stop - start}); + LOGGER.info("Client received file ({} bytes) in {}ms.", f.length(), stop - start); // result.result(f) should be the last operation in handleRead // otherwise NPE may occur in handleWrite asynchronously result.result(content); @@ -276,7 +275,7 @@ public NextAction handleWrite(FilterChainContext ctx) throws IOException { try { if (f != null) { if (!f.delete()) { - LOGGER.log(Level.WARNING, "Unable to explicitly delete file: {0}", f.getAbsolutePath()); + LOGGER.warn("Unable to explicitly delete file: {}", f.getAbsolutePath()); } f = null; } diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/BackendConfigTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/BackendConfigTest.java index 76a422d4b8..4ff037ad63 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/BackendConfigTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/BackendConfigTest.java @@ -40,6 +40,10 @@ package org.glassfish.grizzly.http.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; + import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; @@ -48,13 +52,21 @@ import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; -import org.glassfish.grizzly.filterchain.*; -import org.glassfish.grizzly.http.*; +import org.glassfish.grizzly.filterchain.BaseFilter; +import org.glassfish.grizzly.filterchain.FilterChainBuilder; +import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.filterchain.NextAction; +import org.glassfish.grizzly.filterchain.TransportFilter; +import org.glassfish.grizzly.http.HttpClientFilter; +import org.glassfish.grizzly.http.HttpContent; +import org.glassfish.grizzly.http.HttpPacket; +import org.glassfish.grizzly.http.HttpRequestPacket; +import org.glassfish.grizzly.http.Method; +import org.glassfish.grizzly.http.Protocol; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; @@ -62,7 +74,7 @@ import org.glassfish.grizzly.utils.Charsets; import org.glassfish.grizzly.utils.ChunkingFilter; import org.junit.Test; -import static org.junit.Assert.*; +import org.slf4j.Logger; /** * {@link BackendConfiguration} related tests. @@ -307,13 +319,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + logger.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (logger.isDebugEnabled()) { + logger.debug("HTTP content size: {}", buffer.remaining()); } if (!httpContent.isLast()) { diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/BasicConfigTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/BasicConfigTest.java index 66f27606c9..a328e0d8a0 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/BasicConfigTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/BasicConfigTest.java @@ -47,8 +47,8 @@ import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -62,6 +62,8 @@ import org.glassfish.grizzly.utils.Charsets; import org.glassfish.grizzly.utils.ChunkingFilter; import org.junit.Test; +import org.slf4j.Logger; + import static org.junit.Assert.*; /** @@ -214,13 +216,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + logger.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (logger.isDebugEnabled()) { + logger.debug("HTTP content size: {}", buffer.remaining()); } if (!httpContent.isLast()) { diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/CLStaticHttpHandlerTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/CLStaticHttpHandlerTest.java index 13f53f5d15..2760af3949 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/CLStaticHttpHandlerTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/CLStaticHttpHandlerTest.java @@ -39,6 +39,9 @@ */ package org.glassfish.grizzly.http.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -54,12 +57,20 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; -import org.glassfish.grizzly.filterchain.*; -import org.glassfish.grizzly.http.*; +import org.glassfish.grizzly.filterchain.BaseFilter; +import org.glassfish.grizzly.filterchain.FilterChainBuilder; +import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.filterchain.NextAction; +import org.glassfish.grizzly.filterchain.TransportFilter; +import org.glassfish.grizzly.http.HttpClientFilter; +import org.glassfish.grizzly.http.HttpContent; +import org.glassfish.grizzly.http.HttpRequestPacket; +import org.glassfish.grizzly.http.HttpResponsePacket; +import org.glassfish.grizzly.http.Method; +import org.glassfish.grizzly.http.Protocol; import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; @@ -67,7 +78,7 @@ import org.junit.AfterClass; import org.junit.BeforeClass; import org.junit.Test; -import static org.junit.Assert.*; +import org.slf4j.Logger; /** * {@link CLStaticHttpHandler} test. @@ -363,8 +374,7 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException { } out.close(); - LOGGER.log(Level.INFO, "Client received file ({0} bytes) in {1}ms.", - new Object[]{f.length(), stop - start}); + LOGGER.info("Client received file ({} bytes) in {}ms.", f.length(), stop - start); // result.result(f) should be the last operation in handleRead // otherwise NPE may occur in handleWrite asynchronously resultQueue.add(Futures.createReadyFuture(f)); @@ -380,7 +390,7 @@ public NextAction handleWrite(FilterChainContext ctx) throws IOException { try { if (f != null) { if (!f.delete()) { - LOGGER.log(Level.WARNING, "Unable to explicitly delete file: {0}", f.getAbsolutePath()); + LOGGER.warn("Unable to explicitly delete file: {}", f.getAbsolutePath()); } f = null; } diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/ErrorPageTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/ErrorPageTest.java index 519fcfef06..b5a1520da9 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/ErrorPageTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/ErrorPageTest.java @@ -40,12 +40,15 @@ package org.glassfish.grizzly.http.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -67,7 +70,7 @@ import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.utils.ChunkingFilter; import org.junit.Test; -import static org.junit.Assert.*; +import org.slf4j.Logger; /** * Test the error page generation. @@ -263,7 +266,7 @@ private HttpServer createWebServer(final HttpHandler... httpHandlers) { private static class ClientFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientFilter.class); private final FutureImpl testFuture; @@ -286,13 +289,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}", buffer.remaining()); } if (!httpContent.isLast()) { diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpInputStreamsTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpInputStreamsTest.java index 3590eef894..51d4838903 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpInputStreamsTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpInputStreamsTest.java @@ -40,6 +40,21 @@ package org.glassfish.grizzly.http.server; +import static junit.framework.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.io.IOException; +import java.io.InputStream; +import java.io.Reader; +import java.nio.CharBuffer; +import java.util.concurrent.BlockingQueue; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.TimeoutException; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -52,38 +67,21 @@ import org.glassfish.grizzly.http.HttpContent; import org.glassfish.grizzly.http.HttpPacket; import org.glassfish.grizzly.http.HttpRequestPacket; +import org.glassfish.grizzly.http.Method; import org.glassfish.grizzly.http.Protocol; +import org.glassfish.grizzly.http.util.HeaderValue; import org.glassfish.grizzly.http.util.HttpStatus; +import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.MemoryManager; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; -import org.glassfish.grizzly.utils.ChunkingFilter; - -import java.io.IOException; -import java.io.InputStream; -import java.io.Reader; -import java.nio.CharBuffer; -import java.util.concurrent.BlockingQueue; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.TimeoutException; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.strategies.WorkerThreadIOStrategy; +import org.glassfish.grizzly.utils.ChunkingFilter; import org.glassfish.grizzly.utils.DataStructures; import org.glassfish.grizzly.utils.DelayFilter; import org.glassfish.grizzly.utils.Futures; -import org.glassfish.grizzly.http.util.HeaderValue; - -import static junit.framework.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.glassfish.grizzly.http.Method; import org.junit.Test; +import org.slf4j.Logger; /** * Test cases to validate the behaviors of {@link org.glassfish.grizzly.http.io.NIOInputStream} and @@ -1448,12 +1446,12 @@ public NextAction handleRead(FilterChainContext ctx) final HttpContent httpContent = ctx.getMessage(); - LOGGER.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); final Buffer buffer = httpContent.getContent(); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}", buffer.remaining()); } if (httpContent.isLast()) { diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpResponseStreamsTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpResponseStreamsTest.java index 4c5da0328b..dffd9b7160 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpResponseStreamsTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpResponseStreamsTest.java @@ -40,6 +40,13 @@ package org.glassfish.grizzly.http.server; +import java.io.IOException; +import java.io.OutputStream; +import java.io.Writer; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + +import junit.framework.TestCase; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -55,19 +62,11 @@ import org.glassfish.grizzly.http.util.HttpStatus; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; +import org.glassfish.grizzly.memory.CompositeBuffer; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.utils.ChunkingFilter; -import junit.framework.TestCase; - -import java.io.IOException; -import java.io.OutputStream; -import java.io.Writer; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.memory.CompositeBuffer; +import org.slf4j.Logger; public class HttpResponseStreamsTest extends TestCase { @@ -1125,7 +1124,7 @@ public void service(Request req, Response res) throws Exception { private static class ClientFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientFilter.class); private final CompositeBuffer buf = CompositeBuffer.newBuffer(); @@ -1157,8 +1156,8 @@ public NextAction handleConnect(FilterChainContext ctx) final HttpRequestPacket httpRequest = HttpRequestPacket.builder().method("GET") .uri("/path").protocol(Protocol.HTTP_1_1) .header("Host", "localhost:" + PORT).build(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Connected... Sending the request: {0}", httpRequest); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Connected... Sending the request: {}", httpRequest); } // Write the request asynchronously @@ -1177,13 +1176,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}", buffer.remaining()); } if (buffer.remaining() > 0) { bytesDownloaded += buffer.remaining(); @@ -1193,8 +1192,8 @@ public NextAction handleRead(FilterChainContext ctx) } if (httpContent.isLast()) { - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Response complete: {0} bytes", bytesDownloaded); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Response complete: {} bytes", bytesDownloaded); } completeFuture.result(buf.toStringContent()); close(); diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpSessionTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpSessionTest.java index 8031da4cbb..2916415f51 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpSessionTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/HttpSessionTest.java @@ -50,8 +50,7 @@ import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import junit.framework.TestCase; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; @@ -78,6 +77,7 @@ import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.utils.ChunkingFilter; +import org.slf4j.Logger; /** * Session parsing tests @@ -455,7 +455,7 @@ private Future send(HttpPacket request) { } private static class ClientFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientFilter.class); private FutureImpl testFuture; @@ -478,13 +478,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}", buffer.remaining()); } if (!httpContent.isLast()) { diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/NIOInputSourcesTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/NIOInputSourcesTest.java index b9ba884f1e..42ddff5f56 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/NIOInputSourcesTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/NIOInputSourcesTest.java @@ -40,11 +40,26 @@ package org.glassfish.grizzly.http.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; + import java.io.EOFException; +import java.io.IOException; +import java.io.UnsupportedEncodingException; +import java.nio.charset.Charset; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.EmptyCompletionHandler; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.ReadHandler; +import org.glassfish.grizzly.Transport; +import org.glassfish.grizzly.WriteResult; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.filterchain.FilterChainContext; @@ -59,37 +74,21 @@ import org.glassfish.grizzly.http.io.NIOInputStream; import org.glassfish.grizzly.http.io.NIOOutputStream; import org.glassfish.grizzly.http.io.NIOReader; +import org.glassfish.grizzly.http.util.ContentType; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; +import org.glassfish.grizzly.memory.Buffers; +import org.glassfish.grizzly.memory.ByteBufferManager; +import org.glassfish.grizzly.memory.ByteBufferWrapper; import org.glassfish.grizzly.memory.CompositeBuffer; import org.glassfish.grizzly.memory.MemoryManager; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; -import org.glassfish.grizzly.utils.ChunkingFilter; - -import java.io.IOException; -import java.io.UnsupportedEncodingException; -import java.nio.charset.Charset; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.EmptyCompletionHandler; -import org.glassfish.grizzly.Transport; -import org.glassfish.grizzly.WriteResult; -import org.glassfish.grizzly.http.util.ContentType; -import org.glassfish.grizzly.memory.Buffers; -import org.glassfish.grizzly.memory.ByteBufferManager; -import org.glassfish.grizzly.memory.ByteBufferWrapper; import org.glassfish.grizzly.threadpool.GrizzlyExecutorService; +import org.glassfish.grizzly.utils.ChunkingFilter; import org.junit.Before; import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import org.slf4j.Logger; /** * Test case to exercise AsyncStreamReader. @@ -1138,7 +1137,7 @@ private static abstract class EchoHandler extends HttpHandler { } private static class ClientFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientFilter.class); private final CompositeBuffer buf = CompositeBuffer.newBuffer(); @@ -1177,8 +1176,8 @@ public ClientFilter(FutureImpl testFuture, public NextAction handleConnect(FilterChainContext ctx) throws IOException { - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Connected... Sending the request: {0}", request); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Connected... Sending the request: {}", request); } if (strategy == null) { @@ -1213,13 +1212,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}", buffer.remaining()); } if (buffer.hasRemaining()) { bytesDownloaded += buffer.remaining(); @@ -1229,9 +1228,8 @@ public NextAction handleRead(FilterChainContext ctx) } if (httpContent.isLast()) { - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Response complete: {0} bytes", - bytesDownloaded); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Response complete: {} bytes", bytesDownloaded); } if (encoding != null) { testFuture.result(buf.toStringContent(Charset.forName(encoding))); diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/NIOOutputSinksTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/NIOOutputSinksTest.java index a7631555e7..7aedb886e2 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/NIOOutputSinksTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/NIOOutputSinksTest.java @@ -40,6 +40,11 @@ package org.glassfish.grizzly.http.server; +import static org.glassfish.grizzly.Writer.Reentrant; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.IOException; import java.util.Arrays; import java.util.concurrent.Executors; @@ -49,8 +54,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; @@ -81,11 +84,7 @@ import org.glassfish.grizzly.threadpool.ThreadPoolConfig; import org.glassfish.grizzly.utils.Futures; import org.junit.Test; - -import static org.glassfish.grizzly.Writer.Reentrant; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; +import org.slf4j.Logger; @SuppressWarnings("Duplicates") public class NIOOutputSinksTest { @@ -233,7 +232,7 @@ public void onError(Throwable t) { assertEquals(writeCounter.get(), length); assertTrue(callbackInvoked.get()); } finally { - LOGGER.log(Level.INFO, "Written {0}", writeCounter); + LOGGER.debug("Written {}", writeCounter); // Close the client connection if (connection != null) { connection.closeSilently(); @@ -633,7 +632,7 @@ public void service(final Request request, final Response response) throws Excep check1(resultStr, LENGTH); } finally { - LOGGER.log(Level.INFO, "Written {0}", writeCounter); + LOGGER.info("Written {}", writeCounter); // Close the client connection if (connection != null) { connection.closeSilently(); diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/PayloadReplayTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/PayloadReplayTest.java index 17f34cf98b..889b7ce4f4 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/PayloadReplayTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/PayloadReplayTest.java @@ -47,10 +47,9 @@ import java.util.concurrent.Future; import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; -import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.SocketConnectorHandler; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChainBuilder; @@ -79,7 +78,6 @@ */ public class PayloadReplayTest { private static final int PORT = 18905; - private static final Logger LOGGER = Grizzly.logger(PayloadReplayTest.class); private HttpServer httpServer; diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/RequestURITest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/RequestURITest.java index 34a001dcac..aeb7560cc0 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/RequestURITest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/RequestURITest.java @@ -48,8 +48,7 @@ import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import junit.framework.TestCase; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; @@ -70,6 +69,7 @@ import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.utils.ChunkingFilter; +import org.slf4j.Logger; /** * Checking the request-uri passed to HttpHandler @@ -249,7 +249,7 @@ private HttpServer createWebServer(final HttpHandler... httpHandlers) { private static class ClientFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientFilter.class); private final FutureImpl testFuture; @@ -272,13 +272,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}", buffer.remaining()); } if (!httpContent.isLast()) { diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SSLAttributesTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SSLAttributesTest.java index fd3f2d25c8..ff06b6a0a0 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SSLAttributesTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SSLAttributesTest.java @@ -53,8 +53,6 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -81,6 +79,7 @@ import org.glassfish.grizzly.utils.DataStructures; import org.junit.After; import org.junit.Test; +import org.slf4j.Logger; /** * Testing SSL attributes. @@ -353,7 +352,7 @@ public void service(Request request, Response response) throws Exception { response.setHeader("PAYLOAD_SIZE", Integer.toString(size)); } catch (Exception e) { - LOGGER.log(Level.SEVERE, "Can't retrieve SSL attribute", e); + LOGGER.error("Can't retrieve SSL attribute", e); response.setStatus(500, "Can't retrieve SSL attribute"); } } diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SendFileTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SendFileTest.java index f67edb2a34..2149b2f1e9 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SendFileTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SendFileTest.java @@ -40,9 +40,18 @@ package org.glassfish.grizzly.http.server; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileOutputStream; +import java.io.IOException; +import java.math.BigInteger; +import java.nio.channels.FileChannel; +import java.security.MessageDigest; +import java.util.Random; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; -import java.util.logging.Level; +import java.util.concurrent.TimeUnit; + import junit.framework.TestCase; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; @@ -53,28 +62,18 @@ import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; import org.glassfish.grizzly.filterchain.TransportFilter; +import org.glassfish.grizzly.http.CompressionConfig.CompressionMode; import org.glassfish.grizzly.http.HttpClientFilter; import org.glassfish.grizzly.http.HttpContent; import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.HttpResponsePacket; import org.glassfish.grizzly.http.Method; import org.glassfish.grizzly.http.Protocol; -import org.glassfish.grizzly.http.util.MimeType; import org.glassfish.grizzly.http.util.Header; +import org.glassfish.grizzly.http.util.MimeType; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; - -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.math.BigInteger; -import java.nio.channels.FileChannel; -import java.security.MessageDigest; -import java.util.Random; -import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; -import org.glassfish.grizzly.http.CompressionConfig.CompressionMode; +import org.slf4j.Logger; public class SendFileTest extends TestCase { @@ -560,8 +559,7 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException { } try { out.close(); - LOGGER.log(Level.INFO, "Client received file ({0} bytes) in {1}ms.", - new Object[]{f.length(), stop - start}); + LOGGER.info("Client received file ({} bytes) in {}ms.", f.length(), stop - start); // result.result(f) should be the last operation in handleRead // otherwise NPE may occur in handleWrite asynchronously result.result(f); @@ -577,7 +575,7 @@ public NextAction handleWrite(FilterChainContext ctx) throws IOException { try { if (f != null) { if (!f.delete()) { - LOGGER.log(Level.WARNING, "Unable to explicitly delete file: {0}", f.getAbsolutePath()); + LOGGER.warn("Unable to explicitly delete file: {}", f.getAbsolutePath()); } f = null; } diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SplitTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SplitTest.java index df7808327b..b9cb35afcd 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SplitTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SplitTest.java @@ -40,12 +40,13 @@ package org.glassfish.grizzly.http.server; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -67,7 +68,7 @@ import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.utils.ChunkingFilter; import org.junit.Test; -import static org.junit.Assert.*; +import org.slf4j.Logger; /** * Test potential split vulnerability @@ -196,7 +197,7 @@ private HttpServer createWebServer(final HttpHandler... httpHandlers) { private static class ClientFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientFilter.class); private final FutureImpl testFuture; @@ -219,13 +220,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}", buffer.remaining()); } if (!httpContent.isLast()) { diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/StaticHttpHandlerTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/StaticHttpHandlerTest.java index 56d637e713..b887c604ae 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/StaticHttpHandlerTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/StaticHttpHandlerTest.java @@ -40,6 +40,10 @@ package org.glassfish.grizzly.http.server; +import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; @@ -53,12 +57,20 @@ import java.util.Collection; import java.util.Random; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; -import org.glassfish.grizzly.filterchain.*; -import org.glassfish.grizzly.http.*; +import org.glassfish.grizzly.filterchain.BaseFilter; +import org.glassfish.grizzly.filterchain.FilterChainBuilder; +import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.filterchain.NextAction; +import org.glassfish.grizzly.filterchain.TransportFilter; +import org.glassfish.grizzly.http.HttpClientFilter; +import org.glassfish.grizzly.http.HttpContent; +import org.glassfish.grizzly.http.HttpRequestPacket; +import org.glassfish.grizzly.http.HttpResponsePacket; +import org.glassfish.grizzly.http.Method; +import org.glassfish.grizzly.http.Protocol; import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.memory.HeapMemoryManager; @@ -75,9 +87,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; - -import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; -import static org.junit.Assert.*; +import org.slf4j.Logger; /** * {@link StaticHttpHandler} test. @@ -277,8 +287,7 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException { } out.close(); - LOGGER.log(Level.INFO, "Client received file ({0} bytes) in {1}ms.", - new Object[]{f.length(), stop - start}); + LOGGER.info("Client received file ({} bytes) in {}ms.", f.length(), stop - start); // result.result(f) should be the last operation in handleRead // otherwise NPE may occur in handleWrite asynchronously result.result(f); @@ -294,7 +303,7 @@ public NextAction handleWrite(FilterChainContext ctx) throws IOException { try { if (f != null) { if (!f.delete()) { - LOGGER.log(Level.WARNING, "Unable to explicitly delete file: {0}", f.getAbsolutePath()); + LOGGER.warn("Unable to explicitly delete file: {}", f.getAbsolutePath()); } f = null; } diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SuspendTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SuspendTest.java index 5fcd82ad66..3809442f8a 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SuspendTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/SuspendTest.java @@ -40,6 +40,10 @@ package org.glassfish.grizzly.http.server; +import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.IOException; import java.net.URL; import java.util.Arrays; @@ -49,12 +53,10 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Logger; import junit.framework.AssertionFailedError; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.EmptyCompletionHandler; -import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.SocketConnectorHandler; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChainBuilder; @@ -72,10 +74,6 @@ import org.glassfish.grizzly.ssl.SSLFilter; import org.glassfish.grizzly.utils.Futures; import org.junit.After; - -import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; @@ -92,8 +90,6 @@ @RunWith(Parameterized.class) public class SuspendTest { - private static final Logger LOGGER = Grizzly.logger(SuspendTest.class); - public final int PORT = findFreePort(); private ScheduledThreadPoolExecutor scheduledThreadPool; private final String testString = "blabla test."; diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/TraceMethodTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/TraceMethodTest.java index dd2a9ff723..b34649f824 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/TraceMethodTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/TraceMethodTest.java @@ -40,6 +40,9 @@ package org.glassfish.grizzly.http.server; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNull; + import java.io.BufferedReader; import java.io.IOException; import java.io.StringReader; @@ -47,13 +50,22 @@ import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; -import org.glassfish.grizzly.filterchain.*; -import org.glassfish.grizzly.http.*; +import org.glassfish.grizzly.filterchain.BaseFilter; +import org.glassfish.grizzly.filterchain.FilterChainBuilder; +import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.filterchain.NextAction; +import org.glassfish.grizzly.filterchain.TransportFilter; +import org.glassfish.grizzly.http.HttpClientFilter; +import org.glassfish.grizzly.http.HttpContent; +import org.glassfish.grizzly.http.HttpPacket; +import org.glassfish.grizzly.http.HttpRequestPacket; +import org.glassfish.grizzly.http.HttpResponsePacket; +import org.glassfish.grizzly.http.Method; +import org.glassfish.grizzly.http.Protocol; import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; @@ -61,7 +73,7 @@ import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.utils.ChunkingFilter; import org.junit.Test; -import static org.junit.Assert.*; +import org.slf4j.Logger; /** * Test HTTP TRACE method processing @@ -211,13 +223,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + logger.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (logger.isDebugEnabled()) { + logger.debug("HTTP content size: {}", buffer.remaining()); } if (!httpContent.isLast()) { diff --git a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/TransferEncodingTest.java b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/TransferEncodingTest.java index b49646941a..cd65f048b0 100644 --- a/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/TransferEncodingTest.java +++ b/modules/http-server/src/test/java/org/glassfish/grizzly/http/server/TransferEncodingTest.java @@ -40,6 +40,9 @@ package org.glassfish.grizzly.http.server; +import static junit.framework.Assert.assertEquals; +import static junit.framework.Assert.assertTrue; + import java.io.IOException; import java.io.OutputStream; import java.io.Writer; @@ -48,8 +51,7 @@ import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -76,9 +78,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; - -import static junit.framework.Assert.assertEquals; -import static junit.framework.Assert.assertTrue; +import org.slf4j.Logger; /** * Test transfer-encoding application @@ -316,7 +316,7 @@ private HttpServer createWebServer(final HttpHandler httpHandler) { private static class ClientFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientFilter.class); private final FutureImpl testFuture; @@ -339,13 +339,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}", buffer.remaining()); } if (!httpContent.isLast()) { @@ -399,13 +399,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + logger.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (logger.isDebugEnabled()) { + logger.debug("HTTP content size: {}", buffer.remaining()); } testFuture.result(httpContent.getHttpHeader()); diff --git a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/ApplicationDispatcher.java b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/ApplicationDispatcher.java index 4f13f083ec..610bdd2727 100644 --- a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/ApplicationDispatcher.java +++ b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/ApplicationDispatcher.java @@ -58,15 +58,15 @@ package org.glassfish.grizzly.servlet; +import static javax.servlet.DispatcherType.INCLUDE; + import java.io.IOException; import java.io.PrintWriter; import java.security.AccessController; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.servlet.DispatcherType; -import static javax.servlet.DispatcherType.INCLUDE; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.ServletOutputStream; @@ -76,8 +76,10 @@ import javax.servlet.ServletResponseWrapper; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.util.Globals; +import org.slf4j.Logger; /** * Standard implementation of RequestDispatcher that allows a @@ -224,9 +226,9 @@ public ApplicationDispatcher(ServletHandler wrapper, this.queryString = queryString; this.name = name; - if( LOGGER.isLoggable( Level.FINE ) ) - LOGGER.log(Level.FINE, "servletPath={0}, pathInfo={1}, queryString={2}, name={3}", - new Object[]{this.servletPath, this.pathInfo, queryString, this.name}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("servletPath={}, pathInfo={}, queryString={}, name={}", this.servletPath, this.pathInfo, queryString, this.name); + } } /** @@ -351,16 +353,18 @@ private void doDispatch(ServletRequest request, ServletResponse response, // Reset any output that has been buffered, but keep // headers/cookies if( response.isCommitted() ) { - if( LOGGER.isLoggable( Level.FINE ) ) - LOGGER.fine( " Forward on committed response --> ISE" ); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(" Forward on committed response --> ISE" ); + } throw new IllegalStateException( "Cannot forward after response has been committed" ); } try { response.resetBuffer(); } catch (IllegalStateException e) { - if(LOGGER.isLoggable( Level.FINE)) - LOGGER.log(Level.FINE, "Forward resetBuffer() returned ISE: {0}", e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Forward resetBuffer() returned ISE: {}", e, e); + } throw e; } } diff --git a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/AsyncContextImpl.java b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/AsyncContextImpl.java index b858e282f6..b13216d736 100644 --- a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/AsyncContextImpl.java +++ b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/AsyncContextImpl.java @@ -47,8 +47,7 @@ import java.util.concurrent.ThreadFactory; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.servlet.AsyncContext; import javax.servlet.AsyncEvent; import javax.servlet.AsyncListener; @@ -59,7 +58,10 @@ import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; + +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.util.Globals; +import org.slf4j.Logger; class AsyncContextImpl implements AsyncContext { @@ -68,8 +70,7 @@ class AsyncContextImpl implements AsyncContext { */ enum AsyncEventType { COMPLETE, TIMEOUT, ERROR, START_ASYNC } - private static final Logger log = - Logger.getLogger(AsyncContextImpl.class.getName()); + private static final Logger LOGGER = Grizzly.logger(AsyncContextImpl.class); // Default timeout for async operations private static final long DEFAULT_ASYNC_TIMEOUT_MILLIS = -1; // No timeout by default @@ -174,7 +175,7 @@ public void dispatch() { } else { // Should never happen, because any unmapped paths will be // mapped to the DefaultServlet - log.warning("Unable to determine target of zero-arg dispatcher"); + LOGGER.warn("Unable to determine target of zero-arg dispatcher"); } } @@ -196,7 +197,7 @@ public void dispatch(String path) { } else { // Should never happen, because any unmapped paths will be // mapped to the DefaultServlet - log.log(Level.WARNING, "Unable to acquire RequestDispatcher for {0}", path); + LOGGER.warn("Unable to acquire RequestDispatcher for {}", path); } } @@ -218,8 +219,7 @@ public void dispatch(ServletContext context, String path) { } else { // Should never happen, because any unmapped paths will be // mapped to the DefaultServlet - log.log(Level.WARNING, "Unable to acquire RequestDispatcher for {0}in servlet context {1}", - new Object[]{path, context.getContextPath()}); + LOGGER.warn("Unable to acquire RequestDispatcher for {}in servlet context {}", path, context.getContextPath()); } } @@ -515,8 +515,7 @@ void notifyAsyncListeners(AsyncEventType asyncEventType, Throwable t) { break; } } catch (IOException ioe) { - log.log(Level.WARNING, "Error invoking AsyncListener", - ioe); + LOGGER.warn("Error invoking AsyncListener", ioe); } } } diff --git a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/FilterChainImpl.java b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/FilterChainImpl.java index 34dae24d47..b69cce049e 100644 --- a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/FilterChainImpl.java +++ b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/FilterChainImpl.java @@ -39,8 +39,8 @@ */ package org.glassfish.grizzly.servlet; -import org.glassfish.grizzly.Grizzly; -import org.glassfish.grizzly.localization.LogMessages; +import java.io.IOException; +import java.util.EventListener; import javax.servlet.Filter; import javax.servlet.FilterChain; @@ -50,10 +50,12 @@ import javax.servlet.ServletRequestEvent; import javax.servlet.ServletRequestListener; import javax.servlet.ServletResponse; -import java.io.IOException; -import java.util.EventListener; -import java.util.logging.Level; -import java.util.logging.Logger; + +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.localization.LogMessages; +import org.slf4j.Logger; + + /** * Implementation of javax.servlet.FilterChain used to manage @@ -180,10 +182,8 @@ private void requestDestroyed(ServletRequestEvent event) { try { ((ServletRequestListener) listeners[i]).requestDestroyed(event); } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_DESTROYED_ERROR("requestDestroyed", "ServletRequestListener", listeners[i].getClass().getName()), - t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_DESTROYED_ERROR("requestDestroyed", "ServletRequestListener", listeners[i].getClass().getName()), t); } } } @@ -198,10 +198,8 @@ private void requestInitialized(ServletRequestEvent event) { try { ((ServletRequestListener) listeners[i]).requestInitialized(event); } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_INITIALIZED_ERROR("requestDestroyed", "ServletRequestListener", listeners[i].getClass().getName()), - t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_INITIALIZED_ERROR("requestDestroyed", "ServletRequestListener", listeners[i].getClass().getName()), t); } } } diff --git a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/HttpServletRequestImpl.java b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/HttpServletRequestImpl.java index 5f4826db85..ec78bee686 100644 --- a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/HttpServletRequestImpl.java +++ b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/HttpServletRequestImpl.java @@ -62,8 +62,8 @@ import java.io.IOException; import java.security.AccessController; import java.security.PrivilegedAction; -import java.util.Collection; import java.util.Arrays; +import java.util.Collection; import java.util.Enumeration; import java.util.EventListener; import java.util.Locale; @@ -71,8 +71,7 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.servlet.AsyncContext; import javax.servlet.DispatcherType; import javax.servlet.RequestDispatcher; @@ -90,6 +89,7 @@ import javax.servlet.http.HttpUpgradeHandler; import javax.servlet.http.Part; import javax.servlet.http.WebConnection; + import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.EmptyCompletionHandler; import org.glassfish.grizzly.Grizzly; @@ -102,6 +102,7 @@ import org.glassfish.grizzly.http.server.util.Enumerator; import org.glassfish.grizzly.http.server.util.Globals; import org.glassfish.grizzly.localization.LogMessages; +import org.slf4j.Logger; /** * Facade class that wraps a {@link Request} request object. @@ -617,10 +618,8 @@ public void setAttribute(String name, Object value) { listener.attributeAdded(event); } } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_ATTRIBUTE_LISTENER_ADD_ERROR("ServletRequestAttributeListener", listener.getClass().getName()), - t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_ATTRIBUTE_LISTENER_ADD_ERROR("ServletRequestAttributeListener", listener.getClass().getName()), t); } } } @@ -657,9 +656,7 @@ public void removeAttribute(String name) { } listener.attributeRemoved(event); } catch (Throwable t) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_ATTRIBUTE_LISTENER_REMOVE_ERROR("ServletRequestAttributeListener", listener.getClass().getName()), - t); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_ATTRIBUTE_LISTENER_REMOVE_ERROR("ServletRequestAttributeListener", listener.getClass().getName()), t); } } } @@ -1210,10 +1207,8 @@ public javax.servlet.http.Cookie[] getCookies() { currentCookie.setVersion(cookie.getVersion()); cookies[cookieIdx++] = currentCookie; } catch (IllegalArgumentException iae) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_COOKIE_CREATE_ERROR( - cookie.getName(), iae.getLocalizedMessage())); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_COOKIE_CREATE_ERROR(cookie.getName(), iae.getLocalizedMessage())); } } } @@ -1555,7 +1550,7 @@ void onAfterService() throws IOException { servletResponse.getOutputStream()); httpUpgradeHandler.init(wc); } else { - LOGGER.log(Level.SEVERE, "HttpUpgradeHandler handler cannot be null"); + LOGGER.error("HttpUpgradeHandler handler cannot be null"); } } } @@ -1592,7 +1587,7 @@ void errorDispatchAndComplete(Throwable t) { // hostValve.postInvoke(this, response); // } } catch (Exception e) { - LOGGER.log(Level.SEVERE, "Unable to perform error dispatch", e); + LOGGER.error("Unable to perform error dispatch", e); } finally { /* * If no matching error page was found, or the error page diff --git a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/HttpSessionImpl.java b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/HttpSessionImpl.java index 54a0ca9b0b..6b2d0cef61 100644 --- a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/HttpSessionImpl.java +++ b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/HttpSessionImpl.java @@ -43,8 +43,7 @@ import java.util.Collections; import java.util.Enumeration; import java.util.EventListener; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.servlet.ServletContext; import javax.servlet.http.HttpSession; import javax.servlet.http.HttpSessionAttributeListener; @@ -53,9 +52,11 @@ import javax.servlet.http.HttpSessionEvent; import javax.servlet.http.HttpSessionIdListener; import javax.servlet.http.HttpSessionListener; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.Session; import org.glassfish.grizzly.localization.LogMessages; +import org.slf4j.Logger; /** * Basic {@link HttpSession} based on {@link Session} support. @@ -235,9 +236,8 @@ public void setAttribute(String key, Object value) { try { ((HttpSessionBindingListener) unbound).valueUnbound(new HttpSessionBindingEvent(this, key)); } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_SESSION_LISTENER_UNBOUND_ERROR(unbound.getClass().getName())); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_SESSION_LISTENER_UNBOUND_ERROR(unbound.getClass().getName())); } } } @@ -251,9 +251,8 @@ public void setAttribute(String key, Object value) { try { ((HttpSessionBindingListener) value).valueBound(event); } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_SESSION_LISTENER_BOUND_ERROR(value.getClass().getName())); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_SESSION_LISTENER_BOUND_ERROR(value.getClass().getName())); } } } @@ -283,10 +282,8 @@ public void setAttribute(String key, Object value) { listener.attributeAdded(event); } } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_ATTRIBUTE_LISTENER_ADD_ERROR("HttpSessionAttributeListener", listener.getClass().getName()), - t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_ATTRIBUTE_LISTENER_ADD_ERROR("HttpSessionAttributeListener", listener.getClass().getName()), t); } } } @@ -333,10 +330,8 @@ public void removeAttribute(String key) { } listener.attributeRemoved(event); } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_ATTRIBUTE_LISTENER_REMOVE_ERROR("HttpSessionAttributeListener", listener.getClass().getName()), - t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_ATTRIBUTE_LISTENER_REMOVE_ERROR("HttpSessionAttributeListener", listener.getClass().getName()), t); } } } @@ -372,10 +367,8 @@ public synchronized void invalidate() { try { listener.sessionDestroyed(event); } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_DESTROYED_ERROR("sessionDestroyed", "HttpSessionListener", listener.getClass().getName()), - t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_DESTROYED_ERROR("sessionDestroyed", "HttpSessionListener", listener.getClass().getName()), t); } } } @@ -413,10 +406,8 @@ protected void notifyNew() { try { listener.sessionCreated(event); } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_INITIALIZED_ERROR("sessionCreated", "HttpSessionListener", listener.getClass().getName()), - t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_INITIALIZED_ERROR("sessionCreated", "HttpSessionListener", listener.getClass().getName()), t); } } } @@ -442,10 +433,8 @@ protected void notifyIdChanged(final String oldId) { try { listener.sessionIdChanged(event, oldId); } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_INITIALIZED_ERROR("sessionCreated", "HttpSessionListener", listener.getClass().getName()), - t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_INITIALIZED_ERROR("sessionCreated", "HttpSessionListener", listener.getClass().getName()), t); } } } diff --git a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/ServletHandler.java b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/ServletHandler.java index f9de739beb..270baa6d43 100644 --- a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/ServletHandler.java +++ b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/ServletHandler.java @@ -40,21 +40,22 @@ package org.glassfish.grizzly.servlet; +import static javax.servlet.DispatcherType.REQUEST; + import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.servlet.DispatcherType; -import static javax.servlet.DispatcherType.REQUEST; import javax.servlet.Servlet; import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.http.HttpServletRequest; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.Note; import org.glassfish.grizzly.http.server.AfterServiceListener; @@ -71,6 +72,7 @@ import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.http.util.HttpRequestURIDecoder; import org.glassfish.grizzly.http.util.HttpStatus; +import org.slf4j.Logger; /** * HttpHandler implementation that provides an entry point for processing @@ -144,7 +146,7 @@ public void start() { try { configureServletEnv(); } catch (Throwable t) { - LOGGER.log(Level.SEVERE, "start", t); + LOGGER.error("start", t); } } @@ -231,7 +233,7 @@ protected void doServletService(final Request request, final Response response) // Request may want to initialize async processing servletRequest.onAfterService(); } catch (Throwable ex) { - LOGGER.log(Level.SEVERE, "service exception:", ex); + LOGGER.error("service exception:", ex); customizeErrorPage(response, "Internal Error", 500, ex); } } @@ -290,10 +292,10 @@ void doServletService(final ServletRequest servletRequest, servletInstance.service(servletRequest, servletResponse); } } catch (ServletException se) { - LOGGER.log(Level.SEVERE, "service exception:", se); + LOGGER.error("service exception:", se); throw se; } catch (IOException ie) { - LOGGER.log(Level.SEVERE, "service exception:", ie); + LOGGER.error("service exception:", ie); throw ie; } } @@ -340,7 +342,7 @@ protected void loadServlet() throws ServletException { throw new RuntimeException(e); } } - LOGGER.log(Level.INFO, "Loading Servlet: {0}", newServletInstance.getClass().getName()); + LOGGER.info("Loading Servlet: {}", newServletInstance.getClass().getName()); newServletInstance.init(servletConfig); servletInstance = newServletInstance; } @@ -471,7 +473,7 @@ public void destroy() { try { onDestroyListeners.get(i).run(); } catch (Throwable t) { - LOGGER.log(Level.WARNING, "onDestroyListener error", t); + LOGGER.warn("onDestroyListener error", t); } } diff --git a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/WebappContext.java b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/WebappContext.java index 209c4edf63..587f72374a 100644 --- a/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/WebappContext.java +++ b/modules/http-servlet/src/main/java/org/glassfish/grizzly/servlet/WebappContext.java @@ -58,31 +58,6 @@ package org.glassfish.grizzly.servlet; -import org.glassfish.grizzly.Grizzly; -import org.glassfish.grizzly.http.server.HttpHandler; -import org.glassfish.grizzly.http.server.ServerConfiguration; -import org.glassfish.grizzly.http.server.HttpServer; -import org.glassfish.grizzly.http.server.SessionManager; -import org.glassfish.grizzly.http.server.StaticHttpHandlerBase; -import org.glassfish.grizzly.http.server.util.ClassLoaderUtil; -import org.glassfish.grizzly.http.server.util.DispatcherHelper; -import org.glassfish.grizzly.http.server.util.Enumerator; -import org.glassfish.grizzly.http.server.util.Mapper; -import org.glassfish.grizzly.http.server.util.MappingData; -import org.glassfish.grizzly.http.util.MimeType; -import org.glassfish.grizzly.http.util.DataChunk; -import org.glassfish.grizzly.localization.LogMessages; - -import javax.servlet.Filter; -import javax.servlet.RequestDispatcher; -import javax.servlet.Servlet; -import javax.servlet.ServletContext; -import javax.servlet.ServletContextAttributeEvent; -import javax.servlet.ServletContextAttributeListener; -import javax.servlet.ServletContextEvent; -import javax.servlet.ServletContextListener; -import javax.servlet.ServletException; -import javax.servlet.SingleThreadModel; import java.io.File; import java.io.IOException; import java.io.InputStream; @@ -105,12 +80,37 @@ import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentMap; -import java.util.logging.Level; -import java.util.logging.Logger; + +import javax.servlet.Filter; +import javax.servlet.RequestDispatcher; +import javax.servlet.Servlet; +import javax.servlet.ServletContext; +import javax.servlet.ServletContextAttributeEvent; +import javax.servlet.ServletContextAttributeListener; +import javax.servlet.ServletContextEvent; +import javax.servlet.ServletContextListener; +import javax.servlet.ServletException; import javax.servlet.SessionTrackingMode; +import javax.servlet.SingleThreadModel; import javax.servlet.descriptor.JspConfigDescriptor; import javax.servlet.http.HttpUpgradeHandler; + +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.http.server.HttpHandler; +import org.glassfish.grizzly.http.server.HttpServer; +import org.glassfish.grizzly.http.server.ServerConfiguration; +import org.glassfish.grizzly.http.server.SessionManager; +import org.glassfish.grizzly.http.server.StaticHttpHandlerBase; +import org.glassfish.grizzly.http.server.util.ClassLoaderUtil; +import org.glassfish.grizzly.http.server.util.DispatcherHelper; +import org.glassfish.grizzly.http.server.util.Enumerator; +import org.glassfish.grizzly.http.server.util.Mapper; +import org.glassfish.grizzly.http.server.util.MappingData; +import org.glassfish.grizzly.http.util.DataChunk; +import org.glassfish.grizzly.http.util.MimeType; +import org.glassfish.grizzly.localization.LogMessages; import org.glassfish.grizzly.utils.DataStructures; +import org.slf4j.Logger; /** *

@@ -132,8 +132,7 @@ */ public class WebappContext implements ServletContext { - private static final Logger LOGGER = - Grizzly.logger(WebappContext.class); + private static final Logger LOGGER = Grizzly.logger(WebappContext.class); private static final Map DEPLOYED_APPS = new HashMap(); @@ -307,10 +306,8 @@ public void setServerInfo(final String serverInfo) { public synchronized void deploy(final HttpServer targetServer) { if (!deployed) { - if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.log(Level.INFO, - "Starting application [{0}] ...", - displayName); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Starting application [{}] ...", displayName); } boolean error = false; try { @@ -335,19 +332,15 @@ public synchronized void deploy(final HttpServer targetServer) { contextInitialized(); initServlets(targetServer); initFilters(); - if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.log(Level.INFO, - "Application [{0}] is ready to service requests. Root: [{1}].", - new Object[] {displayName, contextPath}); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("Application [{}] is ready to service requests. Root: [{}].", displayName, contextPath); } DEPLOYED_APPS.put(this, targetServer); deployed = true; } catch (Exception e) { error = true; - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.log(Level.SEVERE, - "[" + displayName + "] Exception deploying application. See stack trace for details.", - e); + if (LOGGER.isErrorEnabled()) { + LOGGER.error("[{}] Exception deploying application. See stack trace for details.", displayName, e); } } finally { if (error) { @@ -376,10 +369,8 @@ public synchronized void undeploy() { contextDestroyed(); } } catch (Exception e) { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.log(Level.SEVERE, - "[" + displayName + "] Exception undeploying application. See stack trace for details.", - e); + if (LOGGER.isErrorEnabled()) { + LOGGER.error("[{}] Exception undeploying application. See stack trace for details.", displayName, e); } } } @@ -1022,8 +1013,8 @@ public ServletContext getContext(String uri) { } } catch (Exception e) { // Should never happen - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, "Error during mapping", e); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn("Error during mapping", e); } return null; } @@ -1222,8 +1213,8 @@ public RequestDispatcher getRequestDispatcher(String path) { } } catch (Exception e) { // Should never happen - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, "Error during mapping", e); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn("Error during mapping", e); } return null; } @@ -1283,8 +1274,8 @@ public RequestDispatcher getNamedDispatcher(String name) { } catch (Exception e) { // Should never happen - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, "Error during mapping", e); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn("Error during mapping", e); } return null; } @@ -1332,7 +1323,7 @@ public Enumeration getServletNames() { */ @Override public void log(String message) { - LOGGER.log(Level.INFO, String.format("[%s] %s", displayName, message)); + LOGGER.info("[{}] {}", displayName, message); } /** @@ -1351,7 +1342,7 @@ public void log(Exception e, String message) { */ @Override public void log(String message, Throwable throwable) { - LOGGER.log(Level.INFO, String.format("[%s] %s", displayName, message), throwable); + LOGGER.info("[{}] {}", displayName, message, throwable); } /** @@ -1469,10 +1460,8 @@ public void setAttribute(String name, Object value) { listener.attributeAdded(event); } } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_ATTRIBUTE_LISTENER_ADD_ERROR("ServletContextAttributeListener", listener.getClass().getName()), - t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_ATTRIBUTE_LISTENER_ADD_ERROR("ServletContextAttributeListener", listener.getClass().getName()), t); } } } @@ -1502,10 +1491,8 @@ public void removeAttribute(String name) { } listener.attributeRemoved(event); } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_ATTRIBUTE_LISTENER_REMOVE_ERROR("ServletContextAttributeListener", listener.getClass().getName()), - t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_ATTRIBUTE_LISTENER_REMOVE_ERROR("ServletContextAttributeListener", listener.getClass().getName()), t); } } } @@ -1853,7 +1840,7 @@ private void initServlets(final HttpServer server) throws ServletException { } else if (registration.loadOnStartup >= 0) { try { Servlet servletInstance = createServletInstance(registration); - LOGGER.log(Level.INFO, "Loading Servlet: {0}", servletInstance.getClass().getName()); + LOGGER.info("Loading Servlet: {}", servletInstance.getClass().getName()); servletInstance.init(sConfig); } catch (Exception e) { throw new RuntimeException(e); @@ -1890,16 +1877,11 @@ private void initServlets(final HttpServer server) throws ServletException { updateMappings(servletHandler, "")); } servletHandlers.add(servletHandler); - if (LOGGER.isLoggable(Level.INFO)) { + if (LOGGER.isInfoEnabled()) { String p = ((patterns == null) ? "" : Arrays.toString(patterns)); - LOGGER.log(Level.INFO, - "[{0}] Servlet [{1}] registered for url pattern(s) [{2}].", - new Object[]{ - displayName, - registration.className, - p}); + LOGGER.info("[{}] Servlet [{}] registered for url pattern(s) [{}].", displayName, registration.className, p); } } } @@ -1969,14 +1951,8 @@ private void initFilters() { createFilterConfig(registration); registration.filter = f; f.init(filterConfig); - if (LOGGER.isLoggable(Level.INFO)) { - LOGGER.log(Level.INFO, - "[{0}] Filter [{1}] registered for url pattern(s) [{2}] and servlet name(s) [{3}]", - new Object[] { - displayName, - registration.className, - registration.getUrlPatternMappings(), - registration.getServletNameMappings()}); + if (LOGGER.isInfoEnabled()) { + LOGGER.info("[{}] Filter [{}] registered for url pattern(s) [{}] and servlet name(s) [{}]", displayName, registration.className, registration.getUrlPatternMappings(), registration.getServletNameMappings()); } } catch (Exception e) { throw new RuntimeException(e); @@ -2062,10 +2038,8 @@ private void contextInitialized() { try { listener.contextInitialized(event); } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_INITIALIZED_ERROR("contextInitialized", "ServletContextListener", listener.getClass().getName()), - t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_INITIALIZED_ERROR("contextInitialized", "ServletContextListener", listener.getClass().getName()), t); } } } @@ -2089,10 +2063,8 @@ private void contextDestroyed() { try { listener.contextDestroyed(event); } catch (Throwable t) { - if (LOGGER.isLoggable(Level.WARNING)) { - LOGGER.log(Level.WARNING, - LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_DESTROYED_ERROR("contextDestroyed", "ServletContextListener", listener.getClass().getName()), - t); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SERVLET_CONTAINER_OBJECT_DESTROYED_ERROR("contextDestroyed", "ServletContextListener", listener.getClass().getName()), t); } } } @@ -2197,7 +2169,7 @@ protected boolean validateURLPattern(String urlPattern) { return true; } if (urlPattern.indexOf('\n') >= 0 || urlPattern.indexOf('\r') >= 0) { - LOGGER.log(Level.WARNING, "The URL pattern ''{0}'' contains a CR or LF and so can never be matched", urlPattern); + LOGGER.warn("The URL pattern ''{}'' contains a CR or LF and so can never be matched", urlPattern); return false; } if (urlPattern.startsWith("*.")) { @@ -2221,12 +2193,10 @@ protected boolean validateURLPattern(String urlPattern) { * See Bugzilla 34805, 43079 & 43080 */ private void checkUnusualURLPattern(String urlPattern) { - if (LOGGER.isLoggable(Level.INFO)) { + if (LOGGER.isInfoEnabled()) { if(urlPattern.endsWith("*") && (urlPattern.length() < 2 || urlPattern.charAt(urlPattern.length()-2) != '/')) { - LOGGER.log(Level.INFO,"Suspicious url pattern: \"{0}" + "\"" + - " in context - see" + - " section SRV.11.2 of the Servlet specification" , urlPattern); + LOGGER.info("Suspicious url pattern: \"{}\" in context - see section SRV.11.2 of the Servlet specification", urlPattern); } } } diff --git a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/BasicServletTest.java b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/BasicServletTest.java index 2ee7af73fa..75aad2f0fb 100644 --- a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/BasicServletTest.java +++ b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/BasicServletTest.java @@ -56,8 +56,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.net.SocketFactory; import javax.servlet.ServletConfig; import javax.servlet.ServletContextEvent; @@ -66,6 +65,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import junit.framework.AssertionFailedError; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.Request; @@ -73,6 +73,7 @@ import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.utils.Futures; import org.junit.Test; +import org.slf4j.Logger; /** @@ -404,7 +405,7 @@ protected void doPost(HttpServletRequest req, HttpServletResponse resp) assertEquals(param1Value, req.getParameter(param1Name)); assertEquals(param2Value, req.getParameter(param2Name)); } catch (Throwable t) { - LOGGER.log(Level.SEVERE, "Error", t); + LOGGER.error("Error", t); resp.sendError(500, t.getMessage()); } @@ -521,7 +522,7 @@ private ServletRegistration addServlet(final WebappContext ctx, protected void doGet( HttpServletRequest req, HttpServletResponse resp) throws IOException { - LOGGER.log(Level.INFO, "{0} received request {1}", new Object[]{alias, req.getRequestURI()}); + LOGGER.info("{} received request {}", alias, req.getRequestURI()); resp.setStatus(HttpServletResponse.SC_OK); resp.setHeader("Content-Type", header); resp.setHeader("Path-Info", req.getPathInfo()); diff --git a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/ClientUtil.java b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/ClientUtil.java index 37ef90d3e8..1e005db84d 100644 --- a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/ClientUtil.java +++ b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/ClientUtil.java @@ -43,8 +43,7 @@ import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -64,6 +63,7 @@ import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.utils.ChunkingFilter; +import org.slf4j.Logger; /** * Simple helper for sending a request @@ -122,7 +122,7 @@ public static HttpContent sendRequest(final HttpPacket request, } private static class ClientFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientFilter.class); private final FutureImpl testFuture; @@ -145,13 +145,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}", buffer.remaining()); } if (!httpContent.isLast()) { diff --git a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/ComplexHttpServerTest.java b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/ComplexHttpServerTest.java index c2730ee595..0115cc68a1 100644 --- a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/ComplexHttpServerTest.java +++ b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/ComplexHttpServerTest.java @@ -42,14 +42,14 @@ import java.io.IOException; import java.net.HttpURLConnection; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.HttpServer; +import org.slf4j.Logger; /** * {@link HttpServer} tests. @@ -60,7 +60,7 @@ public class ComplexHttpServerTest extends HttpServerAbstractTest { public static final int PORT = 18890 + 10; - private static final Logger logger = Grizzly.logger(ComplexHttpServerTest.class); + private static final Logger LOGGER = Grizzly.logger(ComplexHttpServerTest.class); /** * Want to test multiple servletMapping @@ -115,7 +115,7 @@ private ServletRegistration addServlet(final WebappContext ctx, @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - logger.log(Level.INFO, "{0} received request {1}", new Object[]{alias, req.getRequestURI()}); + LOGGER.info("{} received request {}", alias, req.getRequestURI()); resp.setStatus(HttpServletResponse.SC_OK); resp.getWriter().write(req.getRequestURI()); } diff --git a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/HelloHttpServerTest.java b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/HelloHttpServerTest.java index 4e7cf94a41..233e65d43b 100644 --- a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/HelloHttpServerTest.java +++ b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/HelloHttpServerTest.java @@ -46,8 +46,7 @@ import java.io.PrintWriter; import java.net.HttpURLConnection; import java.net.URL; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; @@ -57,6 +56,7 @@ import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.Processor; import org.glassfish.grizzly.http.server.HttpServer; +import org.slf4j.Logger; /** * {@link HttpServer} tests. @@ -67,7 +67,7 @@ public class HelloHttpServerTest extends TestCase { public static final int PORT = 18890 + 11; - private static final Logger logger = Grizzly.logger(HelloHttpServerTest.class); + private static final Logger LOGGER = Grizzly.logger(HelloHttpServerTest.class); private HttpServer httpServer; public void testNPERegression() throws IOException { @@ -160,7 +160,7 @@ private StringBuffer readResponse(HttpURLConnection conn) throws IOException { String line; while((line = reader.readLine())!=null){ - logger.log(Level.INFO, "received line {0}", line); + LOGGER.info("received line {}", line); sb.append(line).append("\n"); } @@ -168,7 +168,7 @@ private StringBuffer readResponse(HttpURLConnection conn) throws IOException { } private HttpURLConnection getConnection(String path) throws IOException { - logger.log(Level.INFO, "sending request to {0}", path); + LOGGER.info("sending request to {}", path); URL url = new URL("http", "localhost", PORT, path); HttpURLConnection urlConn = (HttpURLConnection) url.openConnection(); urlConn.connect(); diff --git a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/HttpServerTest.java b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/HttpServerTest.java index d626718249..714241d7c6 100644 --- a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/HttpServerTest.java +++ b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/HttpServerTest.java @@ -50,8 +50,7 @@ import java.net.URISyntaxException; import java.net.URL; import java.security.GeneralSecurityException; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.net.ssl.HostnameVerifier; import javax.net.ssl.HttpsURLConnection; import javax.net.ssl.SSLSession; @@ -72,6 +71,7 @@ import org.glassfish.grizzly.http.server.Response; import org.glassfish.grizzly.ssl.SSLContextConfigurator; import org.glassfish.grizzly.ssl.SSLEngineConfigurator; +import org.slf4j.Logger; /** * {@link HttpServer} tests. @@ -448,7 +448,7 @@ private ServletRegistration addServlet(final WebappContext ctx, @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { - logger.log(Level.INFO, "{0} received request {1}", new Object[]{alias, req.getRequestURI()}); + logger.info("{} received request {}", alias, req.getRequestURI()); resp.setStatus(HttpServletResponse.SC_OK); resp.getWriter().write(alias); } diff --git a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/MapperTest.java b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/MapperTest.java index 132edc5977..02ba0f2399 100644 --- a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/MapperTest.java +++ b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/MapperTest.java @@ -42,14 +42,14 @@ import java.io.IOException; import java.net.HttpURLConnection; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.HttpHandlerChain; +import org.slf4j.Logger; /** * Test {@link HttpHandlerChain} use of the {@link MapperTest} @@ -296,7 +296,7 @@ private static ServletRegistration addServlet(final WebappContext ctx, protected void doGet( HttpServletRequest req, HttpServletResponse resp) throws IOException { - LOGGER.log(Level.INFO, "{0} received request {1}", new Object[]{alias, req.getRequestURI()}); + LOGGER.info("{} received request {}", alias, req.getRequestURI()); resp.setStatus(HttpServletResponse.SC_OK); resp.setHeader("Path-Info", req.getPathInfo()); resp.setHeader("Servlet-Path", req.getServletPath()); diff --git a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncContextTest.java b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncContextTest.java index c158079159..cb17ce23dd 100644 --- a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncContextTest.java +++ b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncContextTest.java @@ -48,7 +48,7 @@ import java.util.EnumSet; import java.util.Timer; import java.util.TimerTask; -import java.util.logging.Logger; + import javax.servlet.AsyncContext; import javax.servlet.AsyncEvent; import javax.servlet.AsyncListener; @@ -64,7 +64,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequestWrapper; import javax.servlet.http.HttpServletResponse; -import org.glassfish.grizzly.Grizzly; + import org.glassfish.grizzly.servlet.FilterRegistration; import org.glassfish.grizzly.servlet.HttpServerAbstractTest; import org.glassfish.grizzly.servlet.ServletRegistration; @@ -74,8 +74,7 @@ * Basic {@link AsyncContext} tests. */ public class AsyncContextTest extends HttpServerAbstractTest { - private static final Logger LOGGER = Grizzly.logger(AsyncContextTest.class); - + public static final int PORT = 18890 + 15; public void testAsyncContextComplete() throws IOException { diff --git a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncDispatchTest.java b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncDispatchTest.java index 59405bfdea..164102c20d 100644 --- a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncDispatchTest.java +++ b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncDispatchTest.java @@ -47,7 +47,7 @@ import java.util.Enumeration; import java.util.Timer; import java.util.TimerTask; -import java.util.logging.Logger; + import javax.servlet.AsyncContext; import javax.servlet.AsyncEvent; import javax.servlet.AsyncListener; @@ -57,7 +57,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import org.glassfish.grizzly.Grizzly; + import org.glassfish.grizzly.servlet.HttpServerAbstractTest; import org.glassfish.grizzly.servlet.ServletRegistration; import org.glassfish.grizzly.servlet.WebappContext; @@ -66,8 +66,7 @@ * Basic {@link AsyncContext} tests. */ public class AsyncDispatchTest extends HttpServerAbstractTest { - private static final Logger LOGGER = Grizzly.logger(AsyncDispatchTest.class); - + public static final int PORT = 18890 + 16; public void testAsyncContextDispatchZeroArg() throws IOException { diff --git a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncInputTest.java b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncInputTest.java index 9b67383828..0e552f8249 100644 --- a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncInputTest.java +++ b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncInputTest.java @@ -47,8 +47,7 @@ import java.io.OutputStreamWriter; import java.net.HttpURLConnection; import java.util.EnumSet; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.servlet.AsyncContext; import javax.servlet.DispatcherType; import javax.servlet.Filter; @@ -60,11 +59,13 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.servlet.FilterRegistration; import org.glassfish.grizzly.servlet.HttpServerAbstractTest; import org.glassfish.grizzly.servlet.ServletRegistration; import org.glassfish.grizzly.servlet.WebappContext; +import org.slf4j.Logger; /** * Basic Servlet 3.1 non-blocking input tests. @@ -223,7 +224,7 @@ public void onAllDataRead() { @Override public void onError(Throwable t) { - LOGGER.log(Level.WARNING, "Unexpected error", t); + LOGGER.warn("Unexpected error", t); asyncCtx.complete(); } } diff --git a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncOutputTest.java b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncOutputTest.java index 8b91d59fe6..d5dfa52510 100644 --- a/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncOutputTest.java +++ b/modules/http-servlet/src/test/java/org/glassfish/grizzly/servlet/async/AsyncOutputTest.java @@ -47,8 +47,7 @@ import java.util.Arrays; import java.util.EnumSet; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.servlet.AsyncContext; import javax.servlet.DispatcherType; import javax.servlet.Filter; @@ -59,6 +58,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.servlet.FilterRegistration; @@ -66,6 +66,7 @@ import org.glassfish.grizzly.servlet.ServletRegistration; import org.glassfish.grizzly.servlet.WebappContext; import org.glassfish.grizzly.utils.Futures; +import org.slf4j.Logger; /** * Basic Servlet 3.1 non-blocking output tests. @@ -317,7 +318,7 @@ public void onWritePossible() { @Override public void onError(final Throwable t) { - LOGGER.log(Level.WARNING, "Unexpected error", t); + LOGGER.warn("Unexpected error", t); asyncCtx.complete(); } } diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/Cookies.java b/modules/http/src/main/java/org/glassfish/grizzly/http/Cookies.java index 4ec5920d08..9ec452f250 100644 --- a/modules/http/src/main/java/org/glassfish/grizzly/http/Cookies.java +++ b/modules/http/src/main/java/org/glassfish/grizzly/http/Cookies.java @@ -59,8 +59,7 @@ package org.glassfish.grizzly.http; import java.util.Arrays; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.util.BufferChunk; import org.glassfish.grizzly.http.util.ByteChunk; @@ -69,6 +68,7 @@ import org.glassfish.grizzly.http.util.DataChunk; import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.http.util.MimeHeaders; +import org.slf4j.Logger; /** * A collection of cookies - reusable and tuned for server side performance. @@ -212,7 +212,7 @@ private void processClientCookies() { // Uncomment to test the new parsing code if (cookieValue.getType() == DataChunk.Type.Bytes) { - if (logger.isLoggable(Level.FINE)) { + if (logger.isDebugEnabled()) { log("Parsing b[]: " + cookieValue.toString()); } @@ -221,7 +221,7 @@ private void processClientCookies() { byteChunk.getStart(), byteChunk.getLength()); } else if (cookieValue.getType() == DataChunk.Type.Buffer) { - if (logger.isLoggable(Level.FINE)) { + if (logger.isDebugEnabled()) { log("Parsing buffer: " + cookieValue.toString()); } @@ -230,7 +230,7 @@ private void processClientCookies() { bufferChunk.getStart(), bufferChunk.getLength()); } else { - if (logger.isLoggable(Level.FINE)) { + if (logger.isDebugEnabled()) { log("Parsing string: " + cookieValue.toString()); } @@ -268,7 +268,7 @@ private void processServerCookies() { // Uncomment to test the new parsing code if (cookieValue.getType() == DataChunk.Type.Bytes) { - if (logger.isLoggable(Level.FINE)) { + if (logger.isDebugEnabled()) { log("Parsing b[]: " + cookieValue.toString()); } @@ -279,7 +279,7 @@ private void processServerCookies() { CookieUtils.COOKIE_VERSION_ONE_STRICT_COMPLIANCE, CookieUtils.RFC_6265_SUPPORT_ENABLED); } else if (cookieValue.getType() == DataChunk.Type.Buffer) { - if (logger.isLoggable(Level.FINE)) { + if (logger.isDebugEnabled()) { log("Parsing b[]: " + cookieValue.toString()); } @@ -290,7 +290,7 @@ private void processServerCookies() { CookieUtils.COOKIE_VERSION_ONE_STRICT_COMPLIANCE, CookieUtils.RFC_6265_SUPPORT_ENABLED); } else { - if (logger.isLoggable(Level.FINE)) { + if (logger.isDebugEnabled()) { log("Parsing string: " + cookieValue.toString()); } @@ -313,8 +313,8 @@ public String toString() { } private static void log(String s) { - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Cookies: {0}", s); + if (logger.isDebugEnabled()) { + logger.debug("Cookies: {}", s); } } diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/HttpCodecFilter.java b/modules/http/src/main/java/org/glassfish/grizzly/http/HttpCodecFilter.java index eff244e1b9..19f6a847a1 100644 --- a/modules/http/src/main/java/org/glassfish/grizzly/http/HttpCodecFilter.java +++ b/modules/http/src/main/java/org/glassfish/grizzly/http/HttpCodecFilter.java @@ -48,8 +48,6 @@ import java.io.IOException; import java.util.Arrays; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; @@ -75,6 +73,7 @@ import org.glassfish.grizzly.monitoring.MonitoringUtils; import org.glassfish.grizzly.ssl.SSLUtils; import org.glassfish.grizzly.utils.ArraySet; +import org.slf4j.Logger; /** * The {@link org.glassfish.grizzly.filterchain.Filter}, responsible for transforming {@link Buffer} into @@ -625,7 +624,7 @@ public final NextAction handleRead(final FilterChainContext ctx, httpHeader, headerSizeInBytes); } } catch (Exception e) { - LOGGER.log(Level.FINE, "Error parsing HTTP header", e); + LOGGER.debug("Error parsing HTTP header", e); HttpProbeNotifier.notifyProbesError(this, connection, httpHeader, e); @@ -707,7 +706,7 @@ public final NextAction handleRead(final FilterChainContext ctx, } } } catch (Exception e) { - LOGGER.log(Level.FINE, "Error parsing HTTP payload", e); + LOGGER.debug("Error parsing HTTP payload", e); httpHeader.getProcessingState().setError(true); HttpProbeNotifier.notifyProbesError(this, connection, @@ -1050,7 +1049,7 @@ private static void finalizeKnownHeaderNames(final HttpHeader httpHeader, if (httpHeader.isRequest()) { ((HttpRequestPacket) httpHeader).requiresAcknowledgement(true); } else { - LOGGER.warning("Header 'Expect' was found in a server response. The header will be ignored, but this is a server error"); + LOGGER.warn("Header 'Expect' was found in a server response. The header will be ignored, but this is a server error"); } } } @@ -1329,7 +1328,7 @@ private static void finalizeKnownHeaderNames(final HttpHeader httpHeader, if (httpHeader.isRequest()) { ((HttpRequestPacket) httpHeader).requiresAcknowledgement(true); } else { - LOGGER.warning("Header 'Expect' was found in a server response. The header will be ignored, but this is a server error"); + LOGGER.warn("Header 'Expect' was found in a server response. The header will be ignored, but this is a server error"); } } } diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/io/InputBuffer.java b/modules/http/src/main/java/org/glassfish/grizzly/http/io/InputBuffer.java index 5ae6e56cb1..373204a8b7 100644 --- a/modules/http/src/main/java/org/glassfish/grizzly/http/io/InputBuffer.java +++ b/modules/http/src/main/java/org/glassfish/grizzly/http/io/InputBuffer.java @@ -40,20 +40,9 @@ package org.glassfish.grizzly.http.io; -import org.glassfish.grizzly.http.HttpBrokenContent; -import org.glassfish.grizzly.http.util.MimeHeaders; -import org.glassfish.grizzly.http.HttpHeader; -import org.glassfish.grizzly.http.HttpTrailer; -import java.io.EOFException; -import org.glassfish.grizzly.Buffer; -import org.glassfish.grizzly.Connection; -import org.glassfish.grizzly.ReadResult; -import org.glassfish.grizzly.ReadHandler; -import org.glassfish.grizzly.filterchain.FilterChainContext; -import org.glassfish.grizzly.http.HttpContent; -import org.glassfish.grizzly.threadpool.Threads; -import org.glassfish.grizzly.utils.Charsets; +import static org.glassfish.grizzly.http.util.Constants.DEFAULT_HTTP_CHARACTER_ENCODING; +import java.io.EOFException; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.CharBuffer; @@ -66,15 +55,25 @@ import java.util.concurrent.CancellationException; import java.util.concurrent.Executor; import java.util.concurrent.ExecutorService; -import java.util.logging.Level; -import java.util.logging.Logger; + +import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.ReadHandler; +import org.glassfish.grizzly.ReadResult; +import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.http.HttpBrokenContent; import org.glassfish.grizzly.http.HttpBrokenContentException; +import org.glassfish.grizzly.http.HttpContent; +import org.glassfish.grizzly.http.HttpHeader; +import org.glassfish.grizzly.http.HttpTrailer; +import org.glassfish.grizzly.http.util.MimeHeaders; import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.CompositeBuffer; +import org.glassfish.grizzly.threadpool.Threads; +import org.glassfish.grizzly.utils.Charsets; import org.glassfish.grizzly.utils.Exceptions; - -import static org.glassfish.grizzly.http.util.Constants.*; +import org.slf4j.Logger; /** * Abstraction exposing both byte and character methods to read content @@ -82,8 +81,7 @@ */ public class InputBuffer { private static final Logger LOGGER = Grizzly.logger(InputBuffer.class); - private static final Level LOGGER_LEVEL = Level.FINER; - + /** * The {@link org.glassfish.grizzly.http.HttpHeader} associated with this InputBuffer */ @@ -222,7 +220,7 @@ public void initialize(final HttpHeader httpHeader, contentRead = content.isLast(); content.recycle(); - if (LOGGER.isLoggable(LOGGER_LEVEL)) { + if (LOGGER.isDebugEnabled()) { log("InputBuffer %s initialize with ready content: %s", this, inputContentBuffer); } @@ -308,7 +306,7 @@ public void processingChars() { * @see java.io.InputStream#read() */ public int readByte() throws IOException { - if (LOGGER.isLoggable(LOGGER_LEVEL)) { + if (LOGGER.isDebugEnabled()) { log("InputBuffer %s readByte. Ready content: %s", this, inputContentBuffer); } @@ -332,7 +330,7 @@ public int readByte() throws IOException { * @see java.io.InputStream#read(byte[], int, int) */ public int read(final byte b[], final int off, final int len) throws IOException { - if (LOGGER.isLoggable(LOGGER_LEVEL)) { + if (LOGGER.isDebugEnabled()) { log("InputBuffer %s read byte array of len: %s. Ready content: %s", this, len, inputContentBuffer); } @@ -395,7 +393,7 @@ public int available() { * {@link Buffer} used to buffer incoming request data. */ public Buffer getBuffer() { - if (LOGGER.isLoggable(LOGGER_LEVEL)) { + if (LOGGER.isDebugEnabled()) { log("InputBuffer %s getBuffer. Ready content: %s", this, inputContentBuffer); } @@ -410,7 +408,7 @@ public Buffer getBuffer() { * the {@link Buffer}. */ public Buffer readBuffer() { - if (LOGGER.isLoggable(LOGGER_LEVEL)) { + if (LOGGER.isDebugEnabled()) { log("InputBuffer %s readBuffer. Ready content: %s", this, inputContentBuffer); } @@ -427,7 +425,7 @@ public Buffer readBuffer() { * {@link Buffer}, so user code becomes responsible for handling its life-cycle. */ public Buffer readBuffer(final int size) { - if (LOGGER.isLoggable(LOGGER_LEVEL)) { + if (LOGGER.isDebugEnabled()) { log("InputBuffer %s readBuffer(size), size: %s. Ready content: %s", this, size, inputContentBuffer); } @@ -466,7 +464,7 @@ public ReadHandler getReadHandler() { * @see java.io.Reader#read(java.nio.CharBuffer) */ public int read(final CharBuffer target) throws IOException { - if (LOGGER.isLoggable(LOGGER_LEVEL)) { + if (LOGGER.isDebugEnabled()) { log("InputBuffer %s read(CharBuffer). Ready content: %s", this, inputContentBuffer); } @@ -492,7 +490,7 @@ public int read(final CharBuffer target) throws IOException { * @see java.io.Reader#read() */ public int readChar() throws IOException { - if (LOGGER.isLoggable(LOGGER_LEVEL)) { + if (LOGGER.isDebugEnabled()) { log("InputBuffer %s readChar. Ready content: %s", this, inputContentBuffer); } @@ -522,7 +520,7 @@ public int readChar() throws IOException { */ public int read(final char cbuf[], final int off, final int len) throws IOException { - if (LOGGER.isLoggable(LOGGER_LEVEL)) { + if (LOGGER.isDebugEnabled()) { log("InputBuffer %s read char array, len: %s. Ready content: %s", this, len, inputContentBuffer); } @@ -570,7 +568,7 @@ public boolean ready() { * @throws IOException */ public void fillFully(final int length) throws IOException { - if (LOGGER.isLoggable(LOGGER_LEVEL)) { + if (LOGGER.isDebugEnabled()) { log("InputBuffer %s fillFully, len: %s. Ready content: %s", this, length, inputContentBuffer); } @@ -697,7 +695,7 @@ public long skip(final long n, @SuppressWarnings("UnusedParameters") final boole * @see java.io.Reader#skip(long) */ public long skip(final long n) throws IOException { - if (LOGGER.isLoggable(LOGGER_LEVEL)) { + if (LOGGER.isDebugEnabled()) { log("InputBuffer %s skip %s bytes. Ready content: %s", this, n, inputContentBuffer); } @@ -795,7 +793,7 @@ public void replayPayload(final Buffer buffer) { throw new IllegalStateException("Can't replay when InputBuffer is not closed"); } - if (LOGGER.isLoggable(LOGGER_LEVEL)) { + if (LOGGER.isDebugEnabled()) { log("InputBuffer %s replayPayload to %s", this, buffer); } @@ -1431,10 +1429,10 @@ private static void checkHttpTrailer(final HttpContent httpContent) { private static void log(final String message, Object... params) { final String preparedMsg = String.format(message, params); - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, preparedMsg, new Exception("Logged at")); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace(preparedMsg, new Exception("Logged at")); } else { - LOGGER.log(LOGGER_LEVEL, preparedMsg); + LOGGER.debug(preparedMsg); } } } diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/io/OutputBuffer.java b/modules/http/src/main/java/org/glassfish/grizzly/http/io/OutputBuffer.java index 1217bcd5b6..fd53ebd4f1 100644 --- a/modules/http/src/main/java/org/glassfish/grizzly/http/io/OutputBuffer.java +++ b/modules/http/src/main/java/org/glassfish/grizzly/http/io/OutputBuffer.java @@ -59,8 +59,8 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.logging.Level; -import java.util.logging.Logger; + + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; @@ -87,6 +87,7 @@ import org.glassfish.grizzly.utils.Charsets; import org.glassfish.grizzly.utils.Exceptions; import org.glassfish.grizzly.utils.Futures; +import org.slf4j.Logger; import static org.glassfish.grizzly.Writer.Reentrant; @@ -655,12 +656,8 @@ public void sendfile(final File file, if (handler != null) { handler.failed(e); } else { - if (LOGGER.isLoggable(Level.SEVERE)) { - LOGGER.log(Level.SEVERE, - String.format("Failed to transfer file %s. Cause: %s.", - file.getAbsolutePath(), - e.getMessage()), - e); + if (LOGGER.isErrorEnabled()) { + LOGGER.error("Failed to transfer file {}. Cause: {}.", file.getAbsolutePath(), e.getMessage(), e); } } diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/util/B2CConverter.java b/modules/http/src/main/java/org/glassfish/grizzly/http/util/B2CConverter.java index bc7dd5acee..e2b11f606a 100644 --- a/modules/http/src/main/java/org/glassfish/grizzly/http/util/B2CConverter.java +++ b/modules/http/src/main/java/org/glassfish/grizzly/http/util/B2CConverter.java @@ -58,8 +58,6 @@ package org.glassfish.grizzly.http.util; -import org.glassfish.grizzly.utils.Charsets; -import org.glassfish.grizzly.Grizzly; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.CharBuffer; @@ -67,8 +65,12 @@ import java.nio.charset.CharsetDecoder; import java.nio.charset.CoderResult; import java.nio.charset.CodingErrorAction; -import java.util.logging.Level; -import java.util.logging.Logger; + +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.utils.Charsets; +import org.slf4j.Logger; + + /** Efficient conversion of bytes to character . * @@ -238,8 +240,8 @@ public void reset() throws IOException { } void log(String s) { - if (logger.isLoggable(Level.FINEST)) { - logger.log(Level.FINEST, "B2CConverter: " + s); + if (logger.isTraceEnabled()) { + logger.trace("B2CConverter: " + s); } } diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/util/B2CConverterBlocking.java b/modules/http/src/main/java/org/glassfish/grizzly/http/util/B2CConverterBlocking.java index f3ea163bf4..9c9ffc592e 100644 --- a/modules/http/src/main/java/org/glassfish/grizzly/http/util/B2CConverterBlocking.java +++ b/modules/http/src/main/java/org/glassfish/grizzly/http/util/B2CConverterBlocking.java @@ -61,14 +61,15 @@ import org.glassfish.grizzly.utils.Charsets; import org.glassfish.grizzly.Grizzly; +import org.slf4j.Logger; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.io.UnsupportedEncodingException; import java.nio.charset.Charset; -import java.util.logging.Level; -import java.util.logging.Logger; + + /** Efficient conversion of bytes to character . * @@ -85,7 +86,7 @@ public class B2CConverterBlocking { /** * Default Logger. */ - private final static Logger logger = Grizzly.logger(B2CConverterBlocking.class); + private final static Logger LOGGER = Grizzly.logger(B2CConverterBlocking.class); private IntermediateInputStream iis; private ReadConverter conv; @@ -191,8 +192,9 @@ public void reset() } void log( String s ) { - if (logger.isLoggable(Level.FINEST)) - logger.log(Level.FINEST,"B2CConverter: " + s ); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("B2CConverter: {}", s); + } } // -------------------- Not used - the speed improvement is quite small diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/util/C2BConverter.java b/modules/http/src/main/java/org/glassfish/grizzly/http/util/C2BConverter.java index 5db5b01103..489d29c01c 100644 --- a/modules/http/src/main/java/org/glassfish/grizzly/http/util/C2BConverter.java +++ b/modules/http/src/main/java/org/glassfish/grizzly/http/util/C2BConverter.java @@ -58,16 +58,18 @@ package org.glassfish.grizzly.http.util; -import org.glassfish.grizzly.utils.Charsets; -import org.glassfish.grizzly.Grizzly; import java.io.IOException; import java.nio.ByteBuffer; import java.nio.CharBuffer; -import java.nio.charset.CoderResult; import java.nio.charset.CharsetEncoder; +import java.nio.charset.CoderResult; import java.nio.charset.CodingErrorAction; -import java.util.logging.Level; -import java.util.logging.Logger; + +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.utils.Charsets; +import org.slf4j.Logger; + + /** Efficient conversion of character to bytes. * @@ -76,7 +78,7 @@ public class C2BConverter { - private static final Logger logger = Grizzly.logger(C2BConverter.class); + private static final Logger LOGGER = Grizzly.logger(C2BConverter.class); protected ByteChunk bb; protected final String enc; protected final CharsetEncoder encoder; @@ -183,8 +185,8 @@ public void convert(MessageBytes mb ) throws IOException { charC.getStart(), charC.getLength()); //System.out.println("XXX Converting " + mb.getCharChunk() ); } else { - if (logger.isLoggable(Level.FINE)){ - logger.log(Level.FINE, "XXX unknowon type {0}", type); + if (LOGGER.isDebugEnabled()){ + LOGGER.debug("XXX unknowon type {}", type); } } //System.out.println("C2B: XXX " + bb.getBuffer() + bb.getLength()); diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/util/CookieParserUtils.java b/modules/http/src/main/java/org/glassfish/grizzly/http/util/CookieParserUtils.java index 2999c5b522..855074665a 100644 --- a/modules/http/src/main/java/org/glassfish/grizzly/http/util/CookieParserUtils.java +++ b/modules/http/src/main/java/org/glassfish/grizzly/http/util/CookieParserUtils.java @@ -58,18 +58,25 @@ package org.glassfish.grizzly.http.util; +import static org.glassfish.grizzly.http.util.CookieUtils.COOKIE_VERSION_ONE_STRICT_COMPLIANCE; +import static org.glassfish.grizzly.http.util.CookieUtils.OLD_COOKIE_FORMAT; +import static org.glassfish.grizzly.http.util.CookieUtils.RFC_6265_SUPPORT_ENABLED; +import static org.glassfish.grizzly.http.util.CookieUtils.equalsIgnoreCase; +import static org.glassfish.grizzly.http.util.CookieUtils.getQuotedValueEndPosition; +import static org.glassfish.grizzly.http.util.CookieUtils.getTokenEndPosition; +import static org.glassfish.grizzly.http.util.CookieUtils.isSeparator; +import static org.glassfish.grizzly.http.util.CookieUtils.isWhiteSpace; + import java.text.ParseException; import java.util.Date; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.Cookie; import org.glassfish.grizzly.http.Cookies; import org.glassfish.grizzly.http.LazyCookieState; import org.glassfish.grizzly.utils.Charsets; - -import static org.glassfish.grizzly.http.util.CookieUtils.*; +import org.slf4j.Logger; /** * The set of Cookie utility methods for cookie parsing. @@ -228,7 +235,7 @@ public static void parseClientCookies(Cookies cookies, // INVALID COOKIE, advance to next delimiter // The starting character of the cookie value was // not valid. - LOGGER.fine("Invalid cookie. Value not a token or quoted value"); + LOGGER.debug("Invalid cookie. Value not a token or quoted value"); while (pos < end && buffer.get(pos) != ';' && buffer.get(pos) != ',') { pos++; @@ -316,7 +323,7 @@ public static void parseClientCookies(Cookies cookies, // } // Unknown cookie, complain - LOGGER.fine("Unknown Special Cookie"); + LOGGER.debug("Unknown Special Cookie"); } else { // Normal Cookie cookie = cookies.getNextUnusedCookie(); @@ -478,7 +485,7 @@ public static void parseClientCookies(Cookies cookies, // INVALID COOKIE, advance to next delimiter // The starting character of the cookie value was // not valid. - LOGGER.fine("Invalid cookie. Value not a token or quoted value"); + LOGGER.debug("Invalid cookie. Value not a token or quoted value"); while (pos < end && bytes[pos] != ';' && bytes[pos] != ',') { pos++; @@ -557,7 +564,7 @@ public static void parseClientCookies(Cookies cookies, } // Unknown cookie, complain - LOGGER.fine("Unknown Special Cookie"); + LOGGER.debug("Unknown Special Cookie"); } else { // Normal Cookie cookie = cookies.getNextUnusedCookie(); @@ -701,7 +708,7 @@ public static void parseClientCookies(Cookies cookies, // INVALID COOKIE, advance to next delimiter // The starting character of the cookie value was // not valid. - LOGGER.fine("Invalid cookie. Value not a token or quoted value"); + LOGGER.debug("Invalid cookie. Value not a token or quoted value"); while (pos < end && cookiesStr.charAt(pos) != ';' && cookiesStr.charAt(pos) != ',') { pos++; @@ -777,7 +784,7 @@ public static void parseClientCookies(Cookies cookies, } // Unknown cookie, complain - LOGGER.fine("Unknown Special Cookie"); + LOGGER.debug("Unknown Special Cookie"); } else { // Normal Cookie @@ -919,7 +926,7 @@ public static void parseServerCookies(Cookies cookies, // INVALID COOKIE, advance to next delimiter // The starting character of the cookie value was // not valid. - LOGGER.fine("Invalid cookie. Value not a token or quoted value"); + LOGGER.debug("Invalid cookie. Value not a token or quoted value"); while (pos < end && bytes[pos] != ';' && bytes[pos] != ',') { pos++; @@ -1189,7 +1196,7 @@ public static void parseServerCookies(Cookies cookies, // INVALID COOKIE, advance to next delimiter // The starting character of the cookie value was // not valid. - LOGGER.fine("Invalid cookie. Value not a token or quoted value"); + LOGGER.debug("Invalid cookie. Value not a token or quoted value"); while (pos < end && buffer.get(pos) != ';' && buffer.get(pos) != ',') { pos++; @@ -1446,7 +1453,7 @@ public static void parseServerCookies(Cookies cookies, // INVALID COOKIE, advance to next delimiter // The starting character of the cookie value was // not valid. - LOGGER.fine("Invalid cookie. Value not a token or quoted value"); + LOGGER.debug("Invalid cookie. Value not a token or quoted value"); while (pos < end && cookiesStr.charAt(pos) != ';' && cookiesStr.charAt(pos) != ',') { pos++; @@ -1767,8 +1774,8 @@ public static String unescapeDoubleQuotes(String s, int start, int length) { private static int getMaxAgeDelta(long date1, long date2) { long result = date1 - date2; if (result > Integer.MAX_VALUE) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.fine("Integer overflow when calculating max age delta. Date: " + date1 + ", current date: " + date2 + ". Using Integer.MAX_VALUE for further calculation."); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Integer overflow when calculating max age delta. Date: " + date1 + ", current date: " + date2 + ". Using Integer.MAX_VALUE for further calculation."); } return Integer.MAX_VALUE; } else { diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/util/HttpRequestURIDecoder.java b/modules/http/src/main/java/org/glassfish/grizzly/http/util/HttpRequestURIDecoder.java index 458c1ffad7..1151b0aaa6 100644 --- a/modules/http/src/main/java/org/glassfish/grizzly/http/util/HttpRequestURIDecoder.java +++ b/modules/http/src/main/java/org/glassfish/grizzly/http/util/HttpRequestURIDecoder.java @@ -39,14 +39,15 @@ */ package org.glassfish.grizzly.http.util; +import static org.glassfish.grizzly.utils.Charsets.UTF8_CHARSET; + import java.io.CharConversionException; import java.io.IOException; import java.nio.charset.Charset; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Grizzly; -import static org.glassfish.grizzly.utils.Charsets.*; +import org.slf4j.Logger; /** * Utility class that make sure an HTTP url defined inside a {@link MessageBytes} @@ -211,7 +212,7 @@ private static void convertURI(final MessageBytes uri, final String encoding, } } catch (IOException e) { // Ignore - LOGGER.severe("Invalid URI encoding; using HTTP default"); + LOGGER.error("Invalid URI encoding; using HTTP default"); } if (b2cConverter != null) { try { @@ -220,7 +221,7 @@ private static void convertURI(final MessageBytes uri, final String encoding, cc.getLength()); return; } catch (IOException e) { - LOGGER.severe("Invalid URI character encoding; trying ascii"); + LOGGER.error("Invalid URI character encoding; trying ascii"); cc.recycle(); } } @@ -477,7 +478,7 @@ protected void log(String message) { * @param throwable Associated exception */ protected void log(String message, Throwable throwable) { - LOGGER.log(Level.SEVERE, message, throwable); + LOGGER.error(message, throwable); } /** diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/util/Parameters.java b/modules/http/src/main/java/org/glassfish/grizzly/http/util/Parameters.java index d7491a10dc..743c5d682b 100644 --- a/modules/http/src/main/java/org/glassfish/grizzly/http/util/Parameters.java +++ b/modules/http/src/main/java/org/glassfish/grizzly/http/util/Parameters.java @@ -65,13 +65,11 @@ import java.util.Collections; import java.util.LinkedHashMap; import java.util.Set; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Grizzly; - import org.glassfish.grizzly.localization.LogMessages; +import org.slf4j.Logger; /** * @author Costin Manolache @@ -122,8 +120,8 @@ public void setLimit(int limit) { public void setEncoding(final Charset encoding) { this.encoding = encoding; - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "Set encoding to {0}", encoding); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Set encoding to {}", encoding); } } @@ -133,9 +131,8 @@ public Charset getEncoding() { public void setQueryStringEncoding(final Charset queryStringEncoding) { this.queryStringEncoding = queryStringEncoding; - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "Set query string encoding to {0}", - queryStringEncoding); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Set query string encoding to {}", queryStringEncoding); } } @@ -268,10 +265,9 @@ public Set getParameterNames() { */ private void merge() { // recursive - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "Before merging {0} {1} {2}", - new Object[]{this, parent, didMerge}); - LOGGER.log(Level.FINEST, paramsAsString()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Before merging {} {} {}", this, parent, didMerge); + LOGGER.trace(paramsAsString()); } // Local parameters first - they take precedence as in spec. @@ -294,8 +290,8 @@ private void merge() { // END PWC 6057385 merge2(paramHashValues, parentProps); didMerge = true; - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "After {0}", paramsAsString()); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("After {}", paramsAsString()); } } @@ -324,9 +320,8 @@ public void handleQueryParameters() { if (queryDC == null || queryDC.isNull()) { return; } - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "Decoding query {0} {1}", - new Object[]{queryDC, queryStringEncoding}); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Decoding query {} {}", queryDC, queryStringEncoding); } decodedQuery.duplicate(queryDC); @@ -421,15 +416,8 @@ public void processParameters(final Buffer buffer, final int start, final int le public void processParameters(final Buffer buffer, final int start, final int len, final Charset enc) { - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, - "Process parameters. Buffer: {0} start={1} len={2} content={3}", - new Object[]{ - buffer, - start, - len, - buffer.toStringContent(enc, start, start + len) - }); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Process parameters. Buffer: {} start={} len={} content={}", buffer, start, len, buffer.toStringContent(enc, start, start + len)); } int decodeFailCount = 0; @@ -438,7 +426,7 @@ public void processParameters(final Buffer buffer, final int start, final int le int pos = start; while (pos < end) { if (limit > -1 && parameterCount >= limit) { - LOGGER.warning(LogMessages.WARNING_GRIZZLY_HTTP_SEVERE_GRIZZLY_HTTP_PARAMETERS_MAX_COUNT_FAIL(limit)); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SEVERE_GRIZZLY_HTTP_PARAMETERS_MAX_COUNT_FAIL(limit)); break; } int nameStart = pos; @@ -499,9 +487,8 @@ public void processParameters(final Buffer buffer, final int start, final int le } } - if (LOGGER.isLoggable(Level.FINEST) && valueStart == -1) { - LOGGER.log(Level.FINEST, - LogMessages.FINE_GRIZZLY_HTTP_PARAMETERS_NOEQUAL( + if (LOGGER.isTraceEnabled() && valueStart == -1) { + LOGGER.trace(LogMessages.FINE_GRIZZLY_HTTP_PARAMETERS_NOEQUAL( nameStart, nameEnd, buffer.toStringContent(DEFAULT_CHARSET, @@ -509,8 +496,7 @@ public void processParameters(final Buffer buffer, final int start, final int le } if (nameEnd <= nameStart) { - if (LOGGER.isLoggable(Level.INFO)) { - String extract; + if (LOGGER.isInfoEnabled()) { if (valueEnd < nameStart) { LOGGER.info(LogMessages.INFO_GRIZZLY_HTTP_PARAMETERS_INVALID_CHUNK( nameStart, @@ -527,7 +513,7 @@ public void processParameters(final Buffer buffer, final int start, final int le // Take copies as if anything goes wrong originals will be // corrupted. This means original values can be logged. // For performance - only done for debug - if (LOGGER.isLoggable(Level.FINEST)) { + if (LOGGER.isTraceEnabled()) { origName.setBufferChunk(buffer, nameStart, nameEnd); origValue.setBufferChunk(buffer, valueStart, valueEnd); } @@ -555,21 +541,17 @@ public void processParameters(final Buffer buffer, final int start, final int le addParameter(name, value); } catch (Exception e) { decodeFailCount++; - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, - LogMessages.FINE_GRIZZLY_HTTP_PARAMETERS_DECODE_FAIL_DEBUG( - origName.toString(), origValue.toString())); - } else if (LOGGER.isLoggable(Level.INFO) && decodeFailCount == 1) { + if (LOGGER.isTraceEnabled()) { + LOGGER.trace(LogMessages.FINE_GRIZZLY_HTTP_PARAMETERS_DECODE_FAIL_DEBUG(origName.toString(), origValue.toString())); + } else if (LOGGER.isInfoEnabled() && decodeFailCount == 1) { final String name = ((tmpName.getLength() > 0) ? tmpName.toString() : "unavailable"); final String value = ((tmpValue.getLength() > 0) ? tmpValue.toString() : "unavailable"); - LOGGER.log(Level.INFO, - LogMessages.INFO_GRIZZLY_HTTP_PARAMETERS_DECODE_FAIL_INFO( - e.getMessage(), name, value)); - LOGGER.log(Level.FINE, "Decoding stacktrace.", e); + LOGGER.info(LogMessages.INFO_GRIZZLY_HTTP_PARAMETERS_DECODE_FAIL_INFO(e.getMessage(), name, value)); + LOGGER.debug("Decoding stacktrace.", e); } } finally { tmpName.recycle(); @@ -578,7 +560,7 @@ public void processParameters(final Buffer buffer, final int start, final int le } - if (!LOGGER.isLoggable(Level.FINEST) && decodeFailCount > 1) { + if (!LOGGER.isTraceEnabled() && decodeFailCount > 1) { LOGGER.info(LogMessages.INFO_GRIZZLY_HTTP_PARAMETERS_MULTIPLE_DECODING_FAIL(decodeFailCount)); } } @@ -619,22 +601,13 @@ public void processParameters(char chars[], int start, int len) { int pos = start; int decodeFailCount = 0; - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, - "Process parameters. chars: {0} start={1} len={2} content={3}", - new Object[]{ - chars, - start, - len, - new String(chars, start, len) - }); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Process parameters. chars: {} start={} len={} content={}", chars, start, len, new String(chars, start, len)); } do { if (limit > -1 && parameterCount >= limit) { - LOGGER.warning( - LogMessages.WARNING_GRIZZLY_HTTP_SEVERE_GRIZZLY_HTTP_PARAMETERS_MAX_COUNT_FAIL( - limit)); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SEVERE_GRIZZLY_HTTP_PARAMETERS_MAX_COUNT_FAIL(limit)); break; } boolean noEq = false; @@ -649,15 +622,8 @@ public void processParameters(char chars[], int start, int len) { noEq = true; valStart = nameEnd; valEnd = nameEnd; - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "no equal {0} {1} {2}", - new Object[]{ - nameStart, - nameEnd, - new String(chars, - nameStart, - nameEnd - nameStart) - }); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("no equal {} {} {}", nameStart, nameEnd, new String(chars, nameStart, nameEnd - nameStart)); } } if (nameEnd == -1) { @@ -679,38 +645,30 @@ public void processParameters(char chars[], int start, int len) { try { tmpNameC.append(chars, nameStart, nameEnd - nameStart); tmpValueC.append(chars, valStart, valEnd - valStart); - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "{0}= {1}", - new Object[]{tmpNameC, tmpValueC}); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("{}= {}", tmpNameC, tmpValueC); } URLDecoder.decode(tmpNameC, tmpNameC, true, queryStringEncoding.name()); URLDecoder.decode(tmpValueC, tmpValueC, true, queryStringEncoding.name()); - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "{0}= {1}", - new Object[]{tmpNameC, tmpValueC}); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("{}= {}", tmpNameC, tmpValueC); } addParameter(tmpNameC.toString(), tmpValueC.toString()); } catch (Exception e) { decodeFailCount++; - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, - LogMessages.FINE_GRIZZLY_HTTP_PARAMETERS_DECODE_FAIL_DEBUG( - origName.toString(), - origValue.toString())); - } else if (LOGGER.isLoggable( - Level.INFO) && decodeFailCount == 1) { + if (LOGGER.isTraceEnabled()) { + LOGGER.trace(LogMessages.FINE_GRIZZLY_HTTP_PARAMETERS_DECODE_FAIL_DEBUG(origName.toString(), origValue.toString())); + } else if (LOGGER.isInfoEnabled() && decodeFailCount == 1) { final String name = ((tmpNameC.getLength() > 0) ? tmpNameC.toString() : "unavailable"); final String value = ((tmpValueC.getLength() > 0) ? tmpValueC.toString() : "unavailable"); - LOGGER.log(Level.INFO, - LogMessages.INFO_GRIZZLY_HTTP_PARAMETERS_DECODE_FAIL_INFO( - e.getMessage(), name, value)); - LOGGER.log(Level.FINE, "Decoding stacktrace.", e); + LOGGER.info(LogMessages.INFO_GRIZZLY_HTTP_PARAMETERS_DECODE_FAIL_INFO(e.getMessage(), name, value)); + LOGGER.debug("Decoding stacktrace.", e); } } finally { tmpNameC.recycle(); @@ -719,7 +677,7 @@ public void processParameters(char chars[], int start, int len) { } while (pos < end); - if (!LOGGER.isLoggable(Level.FINEST) && decodeFailCount > 1) { + if (!LOGGER.isTraceEnabled() && decodeFailCount > 1) { LOGGER.info( LogMessages.INFO_GRIZZLY_HTTP_PARAMETERS_MULTIPLE_DECODING_FAIL( decodeFailCount)); @@ -779,16 +737,12 @@ public void processParameters(String str) { int pos = 0; int decodeFailCount = 0; - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, - "Process parameters. String: {0}", - str); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("Process parameters. String: {}", str); } do { if (limit > -1 && parameterCount >= limit) { - LOGGER.warning( - LogMessages.WARNING_GRIZZLY_HTTP_SEVERE_GRIZZLY_HTTP_PARAMETERS_MAX_COUNT_FAIL( - limit)); + LOGGER.warn(LogMessages.WARNING_GRIZZLY_HTTP_SEVERE_GRIZZLY_HTTP_PARAMETERS_MAX_COUNT_FAIL(limit)); break; } boolean noEq = false; @@ -806,13 +760,8 @@ public void processParameters(String str) { noEq = true; valStart = nameEnd; valEnd = nameEnd; - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "no equal {0} {1} {2}", - new Object[]{ - nameStart, - nameEnd, - str.substring(nameStart, nameEnd) - }); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("no equal {} {} {}", nameStart, nameEnd, str.substring(nameStart, nameEnd)); } } if (nameEnd == -1) { @@ -829,43 +778,34 @@ public void processParameters(String str) { if (nameEnd <= nameStart) { continue; } - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "XXX {0} {1} {2} {3}", - new Object[]{nameStart, nameEnd, valStart, valEnd}); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("XXX {} {} {} {}", nameStart, nameEnd, valStart, valEnd); } try { tmpNameC.append(str, nameStart, nameEnd - nameStart); tmpValueC.append(str, valStart, valEnd - valStart); - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "{0}= {1}", - new Object[]{tmpNameC, tmpValueC}); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("{}= {}", tmpNameC, tmpValueC); } URLDecoder.decode(tmpNameC, true); URLDecoder.decode(tmpValueC, true); - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, "{0}= {1}", - new Object[]{tmpNameC, tmpValueC}); + if (LOGGER.isTraceEnabled()) { + LOGGER.trace("{}= {}", tmpNameC, tmpValueC); } addParameter(tmpNameC.toString(), tmpValueC.toString()); } catch (Exception e) { decodeFailCount++; - if (LOGGER.isLoggable(Level.FINEST)) { - LOGGER.log(Level.FINEST, - LogMessages.FINE_GRIZZLY_HTTP_PARAMETERS_DECODE_FAIL_DEBUG( - origName.toString(), - origValue.toString())); - } else if (LOGGER.isLoggable( - Level.INFO) && decodeFailCount == 1) { + if (LOGGER.isTraceEnabled()) { + LOGGER.trace(LogMessages.FINE_GRIZZLY_HTTP_PARAMETERS_DECODE_FAIL_DEBUG(origName.toString(), origValue.toString())); + } else if (LOGGER.isInfoEnabled() && decodeFailCount == 1) { final String name = ((tmpNameC.getLength() > 0) ? tmpNameC.toString() : "unavailable"); final String value = ((tmpValueC.getLength() > 0) ? tmpValueC.toString() : "unavailable"); - LOGGER.log(Level.INFO, - LogMessages.INFO_GRIZZLY_HTTP_PARAMETERS_DECODE_FAIL_INFO( - e.getMessage(), name, value)); - LOGGER.log(Level.FINE, "Decoding stacktrace.", e); + LOGGER.info(LogMessages.INFO_GRIZZLY_HTTP_PARAMETERS_DECODE_FAIL_INFO(e.getMessage(), name, value)); + LOGGER.debug("Decoding stacktrace.", e); } } finally { tmpNameC.recycle(); @@ -873,7 +813,7 @@ public void processParameters(String str) { } } while (pos < end); - if (!LOGGER.isLoggable(Level.FINEST) && decodeFailCount > 1) { + if (!LOGGER.isTraceEnabled() && decodeFailCount > 1) { LOGGER.info( LogMessages.INFO_GRIZZLY_HTTP_PARAMETERS_MULTIPLE_DECODING_FAIL( decodeFailCount)); diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/util/StringCache.java b/modules/http/src/main/java/org/glassfish/grizzly/http/util/StringCache.java index 4ca8a9441a..0f91d14b9b 100644 --- a/modules/http/src/main/java/org/glassfish/grizzly/http/util/StringCache.java +++ b/modules/http/src/main/java/org/glassfish/grizzly/http/util/StringCache.java @@ -58,15 +58,16 @@ package org.glassfish.grizzly.http.util; -import org.glassfish.grizzly.Grizzly; - import java.nio.charset.Charset; import java.util.ArrayList; import java.util.HashMap; import java.util.Iterator; import java.util.TreeMap; -import java.util.logging.Level; -import java.util.logging.Logger; + +import org.glassfish.grizzly.Grizzly; +import org.slf4j.Logger; + + /** * This class implements a String cache for ByteChunk and CharChunk. @@ -322,9 +323,9 @@ public static String toString(ByteChunk bc) { bcCount = 0; bcStats.clear(); bcCache = tempbcCache; - if (logger.isLoggable(Level.FINEST)) { + if (logger.isTraceEnabled()) { long t2 = System.currentTimeMillis(); - logger.log(Level.FINEST,"ByteCache generation time: " + (t2 - t1) + "ms"); + logger.trace("ByteCache generation time: {}ms", t2 - t1); } } else { bcCount++; @@ -435,9 +436,9 @@ public static String toString(CharChunk cc) { ccCount = 0; ccStats.clear(); ccCache = tempccCache; - if (logger.isLoggable(Level.FINEST)) { + if (logger.isTraceEnabled()) { long t2 = System.currentTimeMillis(); - logger.log(Level.FINEST,"CharCache generation time: " + (t2 - t1) + "ms"); + logger.trace("CharCache generation time: {}ms", t2 - t1); } } else { ccCount++; diff --git a/modules/http/src/main/java/org/glassfish/grizzly/http/util/UEncoder.java b/modules/http/src/main/java/org/glassfish/grizzly/http/util/UEncoder.java index c290550f19..259874afdb 100644 --- a/modules/http/src/main/java/org/glassfish/grizzly/http/util/UEncoder.java +++ b/modules/http/src/main/java/org/glassfish/grizzly/http/util/UEncoder.java @@ -58,14 +58,15 @@ package org.glassfish.grizzly.http.util; -import org.glassfish.grizzly.Grizzly; - import java.io.CharArrayWriter; import java.io.IOException; import java.io.Writer; import java.util.BitSet; -import java.util.logging.Level; -import java.util.logging.Logger; + +import org.glassfish.grizzly.Grizzly; +import org.slf4j.Logger; + + /** * Efficient implementation for encoders. @@ -80,7 +81,7 @@ */ public final class UEncoder { - private final static Logger logger = Grizzly.logger(UEncoder.class); + private final static Logger LOGGER = Grizzly.logger(UEncoder.class); private static final BitSet initialSafeChars = new BitSet(128); static { @@ -264,8 +265,8 @@ private static void initSafeChars() { } private static void log(String s) { - if (logger.isLoggable(Level.FINE)) { - logger.fine(s); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug(s); } } } diff --git a/modules/http/src/test/java/org/glassfish/grizzly/http/CompressionSemanticsTest.java b/modules/http/src/test/java/org/glassfish/grizzly/http/CompressionSemanticsTest.java index 26374316cd..22d0170a48 100644 --- a/modules/http/src/test/java/org/glassfish/grizzly/http/CompressionSemanticsTest.java +++ b/modules/http/src/test/java/org/glassfish/grizzly/http/CompressionSemanticsTest.java @@ -66,11 +66,12 @@ import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + + import junit.framework.TestCase; import org.glassfish.grizzly.filterchain.Filter; import org.glassfish.grizzly.memory.Buffers; +import org.slf4j.Logger; /** * @@ -519,7 +520,7 @@ private void doTest(HttpPacket request, ExpectedResult expectedResults, private class ClientFilter extends BaseFilter { - private final Logger logger = Grizzly.logger(ClientFilter.class); + private final Logger LOGGER = Grizzly.logger(ClientFilter.class); private final HttpPacket request; private final FutureImpl testResult; @@ -545,9 +546,8 @@ public ClientFilter(HttpPacket request, @Override public NextAction handleConnect(FilterChainContext ctx) throws IOException { - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Connected... Sending the request: {0}", - request); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Connected... Sending the request: {}", request); } ctx.write(request); @@ -562,7 +562,7 @@ public NextAction handleRead(FilterChainContext ctx) final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk; last: {0}", httpContent.isLast()); + LOGGER.debug("Got HTTP response chunk; last: {}", httpContent.isLast()); if (httpContent.isLast()) { diff --git a/modules/http/src/test/java/org/glassfish/grizzly/http/GZipEncodingTest.java b/modules/http/src/test/java/org/glassfish/grizzly/http/GZipEncodingTest.java index 8214840300..95f36272ae 100644 --- a/modules/http/src/test/java/org/glassfish/grizzly/http/GZipEncodingTest.java +++ b/modules/http/src/test/java/org/glassfish/grizzly/http/GZipEncodingTest.java @@ -40,6 +40,17 @@ package org.glassfish.grizzly.http; +import java.io.ByteArrayOutputStream; +import java.io.IOException; +import java.util.Collections; +import java.util.HashMap; +import java.util.Map; +import java.util.Random; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.zip.GZIPOutputStream; + +import junit.framework.TestCase; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -49,28 +60,17 @@ import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; import org.glassfish.grizzly.filterchain.TransportFilter; -import org.glassfish.grizzly.utils.Charsets; import org.glassfish.grizzly.http.util.DataChunk; import org.glassfish.grizzly.http.util.HttpStatus; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; +import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.MemoryManager; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; +import org.glassfish.grizzly.utils.Charsets; import org.glassfish.grizzly.utils.ChunkingFilter; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.util.Collections; -import java.util.HashMap; -import java.util.Map; -import java.util.Random; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import java.util.zip.GZIPOutputStream; -import junit.framework.TestCase; -import org.glassfish.grizzly.memory.Buffers; +import org.slf4j.Logger; /** * @@ -429,9 +429,8 @@ public ClientFilter(HttpPacket request, @Override public NextAction handleConnect(FilterChainContext ctx) throws IOException { - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Connected... Sending the request: {0}", - request); + if (logger.isDebugEnabled()) { + logger.debug("Connected... Sending the request: {}", request); } ctx.write(request); @@ -446,7 +445,7 @@ public NextAction handleRead(FilterChainContext ctx) final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk; last: {0}", httpContent.isLast()); + logger.debug("Got HTTP response chunk; last: {}", httpContent.isLast()); if (httpContent.isLast()) { diff --git a/modules/http/src/test/java/org/glassfish/grizzly/http/HttpCommTest.java b/modules/http/src/test/java/org/glassfish/grizzly/http/HttpCommTest.java index 61299ba7b0..43f8c8759c 100644 --- a/modules/http/src/test/java/org/glassfish/grizzly/http/HttpCommTest.java +++ b/modules/http/src/test/java/org/glassfish/grizzly/http/HttpCommTest.java @@ -40,19 +40,6 @@ package org.glassfish.grizzly.http; -import org.glassfish.grizzly.Connection; -import org.glassfish.grizzly.Grizzly; -import org.glassfish.grizzly.WriteResult; -import org.glassfish.grizzly.filterchain.BaseFilter; -import org.glassfish.grizzly.filterchain.FilterChain; -import org.glassfish.grizzly.filterchain.FilterChainBuilder; -import org.glassfish.grizzly.filterchain.FilterChainContext; -import org.glassfish.grizzly.filterchain.NextAction; -import org.glassfish.grizzly.filterchain.TransportFilter; -import org.glassfish.grizzly.http.util.HttpStatus; -import org.glassfish.grizzly.nio.transport.TCPNIOTransport; -import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; -import org.glassfish.grizzly.utils.ChunkingFilter; import java.io.IOException; import java.net.InetAddress; import java.net.InetSocketAddress; @@ -61,15 +48,28 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import junit.framework.TestCase; import org.glassfish.grizzly.Buffer; +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.SocketConnectorHandler; +import org.glassfish.grizzly.WriteResult; +import org.glassfish.grizzly.filterchain.BaseFilter; +import org.glassfish.grizzly.filterchain.FilterChain; +import org.glassfish.grizzly.filterchain.FilterChainBuilder; +import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.filterchain.NextAction; +import org.glassfish.grizzly.filterchain.TransportFilter; +import org.glassfish.grizzly.http.util.HttpStatus; import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.MemoryManager; import org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler; +import org.glassfish.grizzly.nio.transport.TCPNIOTransport; +import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; +import org.glassfish.grizzly.utils.ChunkingFilter; import org.glassfish.grizzly.utils.DataStructures; +import org.slf4j.Logger; /** * Test HTTP communication @@ -156,7 +156,7 @@ public NextAction handleRead(FilterChainContext ctx) final HttpContent httpContent = ctx.getMessage(); final HttpRequestPacket request = (HttpRequestPacket) httpContent.getHttpHeader(); - logger.log(Level.FINE, "Got the request: {0}", request); + logger.debug("Got the request: {}", request); assertEquals(PORT, request.getLocalPort()); assertTrue(isLocalAddress(request.getLocalAddress())); diff --git a/modules/http/src/test/java/org/glassfish/grizzly/http/HttpResponseParseTest.java b/modules/http/src/test/java/org/glassfish/grizzly/http/HttpResponseParseTest.java index fd71e5339c..98192fead8 100644 --- a/modules/http/src/test/java/org/glassfish/grizzly/http/HttpResponseParseTest.java +++ b/modules/http/src/test/java/org/glassfish/grizzly/http/HttpResponseParseTest.java @@ -50,8 +50,8 @@ import java.util.Map.Entry; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + + import junit.framework.TestCase; import org.glassfish.grizzly.Buffer; @@ -76,6 +76,7 @@ import org.glassfish.grizzly.streams.StreamWriter; import org.glassfish.grizzly.utils.ChunkingFilter; import org.glassfish.grizzly.utils.Pair; +import org.slf4j.Logger; /** * Testing HTTP response parsing @@ -83,7 +84,7 @@ * @author Alexey Stashok */ public class HttpResponseParseTest extends TestCase { - private static final Logger logger = Grizzly.logger(HttpResponseParseTest.class); + private static final Logger LOGGER = Grizzly.logger(HttpResponseParseTest.class); public final int PORT = findFreePort(); @@ -178,7 +179,7 @@ public void testDecoderOK() { doTestDecoder("HTTP/1.0 404 Not found\n\n", 4096); assertTrue(true); } catch (IllegalStateException e) { - logger.log(Level.SEVERE, "exception", e); + LOGGER.error("exception", e); fail("Unexpected exception"); } } diff --git a/modules/http/src/test/java/org/glassfish/grizzly/http/HttpSemanticsTest.java b/modules/http/src/test/java/org/glassfish/grizzly/http/HttpSemanticsTest.java index d97eddec38..da41dfc1fe 100644 --- a/modules/http/src/test/java/org/glassfish/grizzly/http/HttpSemanticsTest.java +++ b/modules/http/src/test/java/org/glassfish/grizzly/http/HttpSemanticsTest.java @@ -70,13 +70,14 @@ import java.util.Map.Entry; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.http.HttpRequestPacket.Builder; import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.nio.transport.TCPNIOConnection; +import org.slf4j.Logger; /** @@ -1049,8 +1050,8 @@ public ClientFilter(Object request, @Override public NextAction handleConnect(FilterChainContext ctx) throws IOException { - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Connected... Sending the request: {0}", request); + if (logger.isDebugEnabled()) { + logger.debug("Connected... Sending the request: {}", request); } if (request instanceof List) { @@ -1076,7 +1077,7 @@ public NextAction handleRead(FilterChainContext ctx) final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + logger.debug("Got HTTP response chunk"); if (httpContent.isLast()) { accumulatedContent.append(httpContent.getContent().toStringContent(Charsets.UTF8_CHARSET)); validate(httpContent, accumulatedContent.toString()); diff --git a/modules/http/src/test/java/org/glassfish/grizzly/http/LZMAEncodingTest.java b/modules/http/src/test/java/org/glassfish/grizzly/http/LZMAEncodingTest.java index 6b5feef565..4047d05542 100644 --- a/modules/http/src/test/java/org/glassfish/grizzly/http/LZMAEncodingTest.java +++ b/modules/http/src/test/java/org/glassfish/grizzly/http/LZMAEncodingTest.java @@ -62,6 +62,7 @@ import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.utils.ChunkingFilter; import org.junit.Test; +import org.slf4j.Logger; import java.io.IOException; import java.util.Collections; @@ -70,8 +71,8 @@ import java.util.Random; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + + import static junit.framework.Assert.assertEquals; import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; @@ -421,7 +422,7 @@ private void doTest(HttpPacket request, private class ClientFilter extends BaseFilter { - private final Logger logger = Grizzly.logger(ClientFilter.class); + private final Logger LOGGER = Grizzly.logger(ClientFilter.class); private final HttpPacket request; private final FutureImpl testResult; @@ -447,9 +448,8 @@ public ClientFilter(HttpPacket request, @Override public NextAction handleConnect(FilterChainContext ctx) throws IOException { - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Connected... Sending the request: {0}", - request); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Connected... Sending the request: {}", request); } ctx.write(request); @@ -464,7 +464,7 @@ public NextAction handleRead(FilterChainContext ctx) final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk; last: {0}", httpContent.isLast()); + LOGGER.debug("Got HTTP response chunk; last: {}", httpContent.isLast()); if (httpContent.isLast()) { diff --git a/modules/portunif/src/main/java/org/glassfish/grizzly/portunif/PUFilter.java b/modules/portunif/src/main/java/org/glassfish/grizzly/portunif/PUFilter.java index 3cc85e41f9..c7665fc527 100644 --- a/modules/portunif/src/main/java/org/glassfish/grizzly/portunif/PUFilter.java +++ b/modules/portunif/src/main/java/org/glassfish/grizzly/portunif/PUFilter.java @@ -42,8 +42,7 @@ import java.io.IOException; import java.util.Set; import java.util.concurrent.CancellationException; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Context; @@ -61,6 +60,7 @@ import org.glassfish.grizzly.filterchain.FilterChainEvent; import org.glassfish.grizzly.filterchain.NextAction; import org.glassfish.grizzly.utils.ArraySet; +import org.slf4j.Logger; /** * Port unification filter. @@ -321,9 +321,7 @@ protected void findProtocol(final PUContext puContext, puContext.skippedProtocolFinders ^= 1 << i; } } catch (Exception e) { - LOGGER.log(Level.WARNING, - "ProtocolFinder " + protocol.getProtocolFinder() + - " reported error", e); + LOGGER.warn("ProtocolFinder {} reported error", protocol.getProtocolFinder(), e); } } } diff --git a/modules/portunif/src/main/java/org/glassfish/grizzly/portunif/finders/SSLProtocolFinder.java b/modules/portunif/src/main/java/org/glassfish/grizzly/portunif/finders/SSLProtocolFinder.java index c1b5a42ebd..29f85955bd 100644 --- a/modules/portunif/src/main/java/org/glassfish/grizzly/portunif/finders/SSLProtocolFinder.java +++ b/modules/portunif/src/main/java/org/glassfish/grizzly/portunif/finders/SSLProtocolFinder.java @@ -40,17 +40,17 @@ package org.glassfish.grizzly.portunif.finders; -import java.util.logging.Level; +import static org.glassfish.grizzly.ssl.SSLUtils.getSSLPacketSize; -import java.util.logging.Logger; import javax.net.ssl.SSLException; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.portunif.PUContext; import org.glassfish.grizzly.portunif.ProtocolFinder; import org.glassfish.grizzly.ssl.SSLEngineConfigurator; -import static org.glassfish.grizzly.ssl.SSLUtils.*; +import org.slf4j.Logger; /** * @@ -76,7 +76,7 @@ public Result find(final PUContext puContext, final FilterChainContext ctx) { return Result.NEED_MORE_DATA; } } catch (SSLException e) { - LOGGER.log(Level.FINE, "Packet header is not SSL", e); + LOGGER.debug("Packet header is not SSL", e); return Result.NOT_FOUND; } diff --git a/modules/portunif/src/test/java/org/glassfish/grizzly/portunif/AsyncPUTest.java b/modules/portunif/src/test/java/org/glassfish/grizzly/portunif/AsyncPUTest.java index 752c24c9af..0776b967e9 100644 --- a/modules/portunif/src/test/java/org/glassfish/grizzly/portunif/AsyncPUTest.java +++ b/modules/portunif/src/test/java/org/glassfish/grizzly/portunif/AsyncPUTest.java @@ -40,38 +40,37 @@ package org.glassfish.grizzly.portunif; -import org.glassfish.grizzly.utils.NullaryFunction; -import java.util.concurrent.atomic.AtomicInteger; -import org.glassfish.grizzly.attributes.Attribute; -import java.util.logging.Logger; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import java.util.concurrent.Executors; -import java.nio.charset.Charset; +import static org.junit.Assert.assertTrue; -import org.glassfish.grizzly.filterchain.FilterChain; import java.io.IOException; -import org.glassfish.grizzly.filterchain.BaseFilter; -import org.glassfish.grizzly.filterchain.FilterChainContext; -import org.glassfish.grizzly.filterchain.NextAction; +import java.nio.charset.Charset; +import java.util.concurrent.Executors; import java.util.concurrent.Future; - import java.util.concurrent.ScheduledExecutorService; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; -import org.glassfish.grizzly.nio.transport.TCPNIOTransport; -import org.glassfish.grizzly.filterchain.TransportFilter; -import org.glassfish.grizzly.filterchain.FilterChainBuilder; +import java.util.concurrent.atomic.AtomicInteger; + import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.SocketConnectorHandler; +import org.glassfish.grizzly.attributes.Attribute; +import org.glassfish.grizzly.filterchain.BaseFilter; +import org.glassfish.grizzly.filterchain.FilterChain; +import org.glassfish.grizzly.filterchain.FilterChainBuilder; +import org.glassfish.grizzly.filterchain.FilterChainContext; +import org.glassfish.grizzly.filterchain.NextAction; +import org.glassfish.grizzly.filterchain.TransportFilter; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; import org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler; +import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; +import org.glassfish.grizzly.utils.NullaryFunction; import org.glassfish.grizzly.utils.StringFilter; +import org.junit.AfterClass; +import org.junit.BeforeClass; import org.junit.Test; -import static org.junit.Assert.*; /** * Asynchronous port-unification tests @@ -83,8 +82,6 @@ public class AsyncPUTest { public static final int PORT = 17400; public static final Charset CHARSET = Charset.forName("UTF-8"); - private static final Logger LOGGER = Grizzly.logger(AsyncPUTest.class); - private static ScheduledExecutorService tp; @BeforeClass diff --git a/modules/portunif/src/test/java/org/glassfish/grizzly/portunif/FilterChainReadTest.java b/modules/portunif/src/test/java/org/glassfish/grizzly/portunif/FilterChainReadTest.java index 615c40ec46..a1cfe00a66 100644 --- a/modules/portunif/src/test/java/org/glassfish/grizzly/portunif/FilterChainReadTest.java +++ b/modules/portunif/src/test/java/org/glassfish/grizzly/portunif/FilterChainReadTest.java @@ -60,8 +60,8 @@ import java.util.concurrent.BlockingQueue; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + + import junit.framework.TestCase; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; @@ -71,6 +71,7 @@ import org.glassfish.grizzly.WriteResult; import org.glassfish.grizzly.memory.CompositeBuffer; import org.glassfish.grizzly.utils.DataStructures; +import org.slf4j.Logger; /** * Test {@link FilterChain} blocking read. @@ -81,7 +82,7 @@ public class FilterChainReadTest extends TestCase { public final int PORT = findFreePort(); - private static final Logger logger = Grizzly.logger(FilterChainReadTest.class); + private static final Logger LOGGER = Grizzly.logger(FilterChainReadTest.class); public void testBlockingRead() throws Exception { final String[] clientMsgs = {"XXXXX", "Hello", "from", "client"}; @@ -359,7 +360,7 @@ public NextAction handleRead(final FilterChainContext ctx) String message = ctx.getMessage(); - logger.log(Level.INFO, "First chunk come: {0}", message); + LOGGER.info("First chunk come: {}", message); intermResultQueue.add(message); Connection connection = ctx.getConnection(); @@ -371,7 +372,7 @@ public NextAction handleRead(final FilterChainContext ctx) final String blckMsg = (String) rr.getMessage(); rr.recycle(); - logger.log(Level.INFO, "Blocking chunk come: {0}", blckMsg); + LOGGER.info("Blocking chunk come: {}", blckMsg); intermResultQueue.add(blckMsg); message += blckMsg; } diff --git a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/NextProtoNegSupport.java b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/NextProtoNegSupport.java index d2c9ee6edd..9ab7ccffe9 100644 --- a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/NextProtoNegSupport.java +++ b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/NextProtoNegSupport.java @@ -44,8 +44,7 @@ import java.util.WeakHashMap; import java.util.concurrent.locks.ReadWriteLock; import java.util.concurrent.locks.ReentrantReadWriteLock; -import java.util.logging.Level; -import java.util.logging.Logger; + import javax.net.ssl.SSLEngine; import org.glassfish.grizzly.CloseListener; @@ -60,6 +59,7 @@ import org.glassfish.grizzly.ssl.SSLBaseFilter; import org.glassfish.grizzly.ssl.SSLFilter; import org.glassfish.grizzly.ssl.SSLUtils; +import org.slf4j.Logger; /** * Grizzly TLS Next Protocol Negotiation support class. @@ -80,7 +80,7 @@ public class NextProtoNegSupport { ClassLoader.getSystemClassLoader().loadClass("sun.security.ssl.GrizzlyNPN"); isExtensionFound = true; } catch (Throwable e) { - LOGGER.log(Level.FINE, "TLS Next Protocol Negotiation extension is not found:", e); + LOGGER.debug("TLS Next Protocol Negotiation extension is not found:", e); } INSTANCE = isExtensionFound ? new NextProtoNegSupport() : null; diff --git a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyAddOn.java b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyAddOn.java index 55273d62ef..b9e3c122c5 100644 --- a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyAddOn.java +++ b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyAddOn.java @@ -40,6 +40,15 @@ package org.glassfish.grizzly.spdy; +import static org.glassfish.grizzly.spdy.Constants.DEFAULT_INITIAL_WINDOW_SIZE; +import static org.glassfish.grizzly.spdy.Constants.DEFAULT_MAX_CONCURRENT_STREAMS; +import static org.glassfish.grizzly.spdy.Constants.DEFAULT_MAX_FRAME_SIZE; + +import java.util.Arrays; +import java.util.LinkedHashSet; + +import javax.net.ssl.SSLEngine; + import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.Transport; @@ -49,21 +58,13 @@ import org.glassfish.grizzly.http.server.AddOn; import org.glassfish.grizzly.http.server.HttpServerFilter; import org.glassfish.grizzly.http.server.NetworkListener; +import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.npn.ServerSideNegotiator; import org.glassfish.grizzly.ssl.SSLBaseFilter; import org.glassfish.grizzly.ssl.SSLConnectionContext; import org.glassfish.grizzly.ssl.SSLFilter; import org.glassfish.grizzly.ssl.SSLUtils; - -import java.util.Arrays; -import java.util.LinkedHashSet; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.nio.transport.TCPNIOTransport; - -import javax.net.ssl.SSLEngine; - -import static org.glassfish.grizzly.spdy.Constants.*; +import org.slf4j.Logger; /** * FilterChain after being processed by SpdyAddOn: @@ -116,12 +117,12 @@ public void setup(NetworkListener networkListener, FilterChainBuilder builder) { if (mode == SpdyMode.NPN) { if (!networkListener.isSecure()) { - LOGGER.warning("Can not configure NPN (Next Protocol Negotiation) mode on non-secured NetworkListener. SPDY support will not be enabled."); + LOGGER.warn("Can not configure NPN (Next Protocol Negotiation) mode on non-secured NetworkListener. SPDY support will not be enabled."); return; } if (!NextProtoNegSupport.isEnabled()) { - LOGGER.warning("TLS NPN (Next Protocol Negotiation) support is not available. SPDY support will not be enabled."); + LOGGER.warn("TLS NPN (Next Protocol Negotiation) support is not available. SPDY support will not be enabled."); return; } @@ -281,9 +282,9 @@ public ProtocolNegotiator(final FilterChain filterChain, @Override public LinkedHashSet supportedProtocols(final SSLEngine engine) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "NPN supportedProtocols. Connection={0} sslEngine={1} supportedProtocols={2}", - new Object[]{NextProtoNegSupport.getConnection(engine), engine, supportedProtocols}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("NPN supportedProtocols. Connection={} sslEngine={} supportedProtocols={}", + NextProtoNegSupport.getConnection(engine), engine, supportedProtocols); } return supportedProtocols; } @@ -292,9 +293,9 @@ public LinkedHashSet supportedProtocols(final SSLEngine engine) { public void onSuccess(final SSLEngine engine, final String protocol) { final Connection connection = NextProtoNegSupport.getConnection(engine); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "NPN onSuccess. Connection={0} sslEngine={1} protocol={2}", - new Object[]{connection, engine, protocol}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("NPN onSuccess. Connection={} sslEngine={} protocol={}", + connection, engine, protocol); } final SpdyVersion spdyVersion = SpdyVersion.fromString(protocol); @@ -313,9 +314,8 @@ public void onSuccess(final SSLEngine engine, final String protocol) { public void onNoDeal(final SSLEngine engine) { final Connection connection = NextProtoNegSupport.getConnection(engine); // Default to the transport FilterChain. - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "NPN onNoDeal. Connection={0} sslEngine={1}", - new Object[]{connection, engine}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("NPN onNoDeal. Connection={} sslEngine={}", connection, engine); } // TODO: Should we consider making this behavior configurable? connection.closeSilently(); diff --git a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyDecoderUtils.java b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyDecoderUtils.java index 22a801878d..9410720c35 100644 --- a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyDecoderUtils.java +++ b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyDecoderUtils.java @@ -39,8 +39,8 @@ */ package org.glassfish.grizzly.spdy; -import java.util.logging.Level; -import java.util.logging.Logger; + + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Cacheable; import org.glassfish.grizzly.Grizzly; @@ -57,6 +57,7 @@ import org.glassfish.grizzly.http.util.HttpCodecUtils; import org.glassfish.grizzly.http.util.MimeHeaders; import org.glassfish.grizzly.utils.Charsets; +import org.slf4j.Logger; /** * SpdyFrames -> HTTP Packet decoder utils. @@ -224,9 +225,9 @@ private static int processServiceSynStreamHeader(final SpdyRequest spdyRequest, } } - LOGGER.log(Level.FINE, "Skipping unknown service header[{0}={1}", - new Object[]{new String(headersArray, nameStart - 1, nameSize, Charsets.ASCII_CHARSET), - new String(headersArray, valueStart, valueSize, Charsets.ASCII_CHARSET)}); + LOGGER.debug("Skipping unknown service header[{}={}", + new String(headersArray, nameStart - 1, nameSize, Charsets.ASCII_CHARSET), + new String(headersArray, valueStart, valueSize, Charsets.ASCII_CHARSET)); return valueEnd; } @@ -303,10 +304,9 @@ private static int processServiceSynStreamHeader(final SpdyRequest spdyRequest, } } - LOGGER.log(Level.FINE, "Skipping unknown service header[{0}={1}", - new Object[] { - buffer.toStringContent(Charsets.ASCII_CHARSET, nameStart - 1, nameSize), - buffer.toStringContent(Charsets.ASCII_CHARSET, valueStart, valueSize)}); + LOGGER.debug("Skipping unknown service header[{}={}]", + buffer.toStringContent(Charsets.ASCII_CHARSET, nameStart - 1, nameSize), + buffer.toStringContent(Charsets.ASCII_CHARSET, valueStart, valueSize)); return valueEnd; } @@ -406,9 +406,9 @@ private static int processServiceUSynStreamHeader(final SpdyRequest spdyRequest, } } - LOGGER.log(Level.FINE, "Skipping unknown service header[{0}={1}", - new Object[]{new String(headersArray, nameStart - 1, nameSize, Charsets.ASCII_CHARSET), - new String(headersArray, valueStart, valueSize, Charsets.ASCII_CHARSET)}); + LOGGER.debug("Skipping unknown service header[{}={}]", + new String(headersArray, nameStart - 1, nameSize, Charsets.ASCII_CHARSET), + new String(headersArray, valueStart, valueSize, Charsets.ASCII_CHARSET)); return valueEnd; } @@ -508,10 +508,9 @@ private static int processServiceUSynStreamHeader(final SpdyRequest spdyRequest, } } - LOGGER.log(Level.FINE, "Skipping unknown service header[{0}={1}", - new Object[] { - buffer.toStringContent(Charsets.ASCII_CHARSET, nameStart - 1, nameSize), - buffer.toStringContent(Charsets.ASCII_CHARSET, valueStart, valueSize)}); + LOGGER.debug("Skipping unknown service header[{}={}]", + buffer.toStringContent(Charsets.ASCII_CHARSET, nameStart - 1, nameSize), + buffer.toStringContent(Charsets.ASCII_CHARSET, valueStart, valueSize)); return valueEnd; } @@ -577,9 +576,9 @@ private static int processServiceSynReplyHeader(final SpdyResponse spdyResponse, } } - LOGGER.log(Level.FINE, "Skipping unknown service header[{0}={1}", - new Object[]{new String(headersArray, position, nameSize, Charsets.ASCII_CHARSET), - new String(headersArray, valueStart, valueSize, Charsets.ASCII_CHARSET)}); + LOGGER.debug("Skipping unknown service header[{}={}]", + new String(headersArray, position, nameSize, Charsets.ASCII_CHARSET), + new String(headersArray, valueStart, valueSize, Charsets.ASCII_CHARSET)); return valueEnd; } @@ -640,9 +639,9 @@ private static int processServiceSynReplyHeader(final SpdyResponse spdyResponse, } } - LOGGER.log(Level.FINE, "Skipping unknown service header[{0}={1}", - new Object[]{buffer.toStringContent(Charsets.ASCII_CHARSET, position, nameSize), - buffer.toStringContent(Charsets.ASCII_CHARSET, valueStart, valueSize)}); + LOGGER.debug("Skipping unknown service header[{}={}]", + buffer.toStringContent(Charsets.ASCII_CHARSET, position, nameSize), + buffer.toStringContent(Charsets.ASCII_CHARSET, valueStart, valueSize)); return valueEnd; } diff --git a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyFramingFilter.java b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyFramingFilter.java index e3af4b89c4..48902eb7c4 100644 --- a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyFramingFilter.java +++ b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyFramingFilter.java @@ -42,8 +42,6 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; @@ -62,6 +60,7 @@ import org.glassfish.grizzly.spdy.frames.OversizedFrame; import org.glassfish.grizzly.spdy.frames.SpdyFrame; import org.glassfish.grizzly.utils.NullaryFunction; +import org.slf4j.Logger; /** * The {@link Filter} responsible for transforming SPDY {@link SpdyFrame}s @@ -73,7 +72,6 @@ public class SpdyFramingFilter extends BaseFilter { private static final int DEFAULT_MAX_FRAME_LENGTH = 1 << 24; private static final Logger LOGGER = Grizzly.logger(SpdyFramingFilter.class); - private static final Level LOGGER_LEVEL = Level.FINE; static final int HEADER_LEN = 8; @@ -128,10 +126,9 @@ public NextAction handleRead(final FilterChainContext ctx) throws IOException { return ctx.getStopAction(remainder); } - final boolean logit = LOGGER.isLoggable(LOGGER_LEVEL); + final boolean logit = LOGGER.isDebugEnabled(); if (logit) { - LOGGER.log(LOGGER_LEVEL, "Rx [1]: connection={0}, frame={1}", - new Object[] {connection, frame}); + LOGGER.debug("Rx [1]: connection={}, frame={}", connection, frame); } if (frame.isService()) { @@ -160,8 +157,7 @@ public NextAction handleRead(final FilterChainContext ctx) throws IOException { } if (logit) { - LOGGER.log(LOGGER_LEVEL, "Rx [2]: connection={0}, frame={1}", - new Object[] {connection, frame}); + LOGGER.debug("Rx [2]: connection={}, frame={}", connection, frame); } frameList.add(frame); @@ -213,9 +209,8 @@ public void completed(WriteResult result) { public NextAction handleWrite(final FilterChainContext ctx) throws IOException { final Object message = ctx.getMessage(); - if (LOGGER.isLoggable(LOGGER_LEVEL)) { - LOGGER.log(LOGGER_LEVEL, "Tx: connection={0}, frame={1}", - new Object[]{ctx.getConnection(), message}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Tx: connection={}, frame={}", ctx.getConnection(), message); } final MemoryManager memoryManager = ctx.getMemoryManager(); @@ -328,9 +323,8 @@ private SpdyFrame createOversizedFrame( org.glassfish.grizzly.spdy.frames.SpdyHeader.wrap(message); final OversizedFrame oversizedFrame = OversizedFrame.create(spdyHeader); - if (LOGGER.isLoggable(LOGGER_LEVEL)) { - LOGGER.log(LOGGER_LEVEL, "Rx: oversized frame! connection={0}, header={1}", - new Object[]{ctx.getConnection(), spdyHeader}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Rx: oversized frame! connection={}, header={}", ctx.getConnection(), spdyHeader); } return oversizedFrame; diff --git a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyHandlerFilter.java b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyHandlerFilter.java index e33642e6dd..90a530593e 100644 --- a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyHandlerFilter.java +++ b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyHandlerFilter.java @@ -39,6 +39,22 @@ */ package org.glassfish.grizzly.spdy; +import static org.glassfish.grizzly.spdy.Constants.CTRL_FRAMES_WITH_STREAM_ID; +import static org.glassfish.grizzly.spdy.Constants.DEFAULT_INITIAL_WINDOW_SIZE; +import static org.glassfish.grizzly.spdy.Constants.DEFAULT_MAX_CONCURRENT_STREAMS; +import static org.glassfish.grizzly.spdy.Constants.FRAME_TOO_LARGE_TERMINATION; +import static org.glassfish.grizzly.spdy.Constants.IN_FIN_TERMINATION; +import static org.glassfish.grizzly.spdy.Constants.OUT_FIN_TERMINATION; +import static org.glassfish.grizzly.spdy.Constants.SPDY_VERSION; +import static org.glassfish.grizzly.spdy.SpdyDecoderUtils.processSynReplyHeadersArray; +import static org.glassfish.grizzly.spdy.SpdyDecoderUtils.processSynReplyHeadersBuffer; +import static org.glassfish.grizzly.spdy.SpdyDecoderUtils.processSynStreamHeadersArray; +import static org.glassfish.grizzly.spdy.SpdyDecoderUtils.processSynStreamHeadersBuffer; +import static org.glassfish.grizzly.spdy.SpdyDecoderUtils.processUSynStreamHeadersArray; +import static org.glassfish.grizzly.spdy.SpdyDecoderUtils.processUSynStreamHeadersBuffer; +import static org.glassfish.grizzly.spdy.frames.SettingsFrame.SETTINGS_INITIAL_WINDOW_SIZE; +import static org.glassfish.grizzly.spdy.frames.SettingsFrame.SETTINGS_MAX_CONCURRENT_STREAMS; + import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; @@ -47,16 +63,20 @@ import java.util.Map; import java.util.concurrent.ExecutorService; import java.util.concurrent.locks.ReentrantLock; -import java.util.logging.Level; -import java.util.logging.Logger; + +import javax.net.ssl.SSLEngine; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.EmptyCompletionHandler; import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.IOEvent; import org.glassfish.grizzly.filterchain.FilterChain; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.FilterChainContext.TransportContext; import org.glassfish.grizzly.filterchain.FilterChainEvent; import org.glassfish.grizzly.filterchain.NextAction; +import org.glassfish.grizzly.filterchain.TransportFilter; import org.glassfish.grizzly.http.FixedLengthTransferEncoding; import org.glassfish.grizzly.http.HttpBaseFilter; import org.glassfish.grizzly.http.HttpContent; @@ -81,8 +101,10 @@ import org.glassfish.grizzly.spdy.frames.GoAwayFrame; import org.glassfish.grizzly.spdy.frames.HeadersFrame; import org.glassfish.grizzly.spdy.frames.HeadersProviderFrame; +import org.glassfish.grizzly.spdy.frames.OversizedFrame; import org.glassfish.grizzly.spdy.frames.PingFrame; import org.glassfish.grizzly.spdy.frames.RstStreamFrame; +import org.glassfish.grizzly.spdy.frames.ServiceFrame; import org.glassfish.grizzly.spdy.frames.SettingsFrame; import org.glassfish.grizzly.spdy.frames.SettingsFrame.SettingsFrameBuilder; import org.glassfish.grizzly.spdy.frames.SpdyFrame; @@ -90,18 +112,7 @@ import org.glassfish.grizzly.spdy.frames.SynStreamFrame; import org.glassfish.grizzly.spdy.frames.WindowUpdateFrame; import org.glassfish.grizzly.ssl.SSLFilter; - -import javax.net.ssl.SSLEngine; -import org.glassfish.grizzly.EmptyCompletionHandler; -import org.glassfish.grizzly.IOEvent; -import org.glassfish.grizzly.filterchain.TransportFilter; -import org.glassfish.grizzly.spdy.frames.OversizedFrame; -import org.glassfish.grizzly.spdy.frames.ServiceFrame; - -import static org.glassfish.grizzly.spdy.SpdyDecoderUtils.*; -import static org.glassfish.grizzly.spdy.Constants.*; -import static org.glassfish.grizzly.spdy.frames.SettingsFrame.SETTINGS_INITIAL_WINDOW_SIZE; -import static org.glassfish.grizzly.spdy.frames.SettingsFrame.SETTINGS_MAX_CONCURRENT_STREAMS; +import org.slf4j.Logger; /** * The {@link org.glassfish.grizzly.filterchain.Filter} serves as a bridge @@ -235,9 +246,8 @@ public NextAction handleRead(final FilterChainContext ctx) try { processInFrame(spdySession, ctx, frame); } catch (SpdyStreamException e) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "SpdyStreamException occurred on connection=" + - ctx.getConnection() + " during SpdyFrame processing", e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("SpdyStreamException occurred on connection={} during SpdyFrame processing", ctx.getConnection(), e); } final int streamId = e.getStreamId(); @@ -257,9 +267,8 @@ public NextAction handleRead(final FilterChainContext ctx) try { processInFrame(spdySession, ctx, framesList.get(i)); } catch (SpdyStreamException e) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "SpdyStreamException occurred on connection=" + - ctx.getConnection() + " during SpdyFrame processing", e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("SpdyStreamException occurred on connection={} during SpdyFrame processing", ctx.getConnection(), e); } final int streamId = e.getStreamId(); @@ -285,18 +294,16 @@ public NextAction handleRead(final FilterChainContext ctx) } streamsToFlushInput.clear(); } catch (SpdySessionException e) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "SpdySessionException occurred on connection=" + - ctx.getConnection() + " during SpdyFrame processing", e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("SpdySessionException occurred on connection={} during SpdyFrame processing", ctx.getConnection(), e); } sendGoAwayAndClose(ctx, spdySession, e.getStreamId(), e.getGoAwayStatus(), e.getRstReason()); return ctx.getSuspendAction(); } catch (IOException e) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "IOException occurred on connection=" + - ctx.getConnection() + " during SpdyFrame processing", e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("IOException occurred on connection={} during SpdyFrame processing", ctx.getConnection(), e); } sendGoAwayAndClose(ctx, spdySession, -1, @@ -534,11 +541,11 @@ private void processControlFrame(final SpdySession spdySession, case HeadersFrame.TYPE: case CredentialFrame.TYPE: // Will remain unimplemented for the time being. default: { - LOGGER.log(Level.WARNING, "Unknown or unhandled control-frame [version={0} type={1} flags={2} length={3}]", - new Object[]{frame.getHeader().getVersion(), - frame.getHeader().getType(), - frame.getHeader().getFlags(), - frame.getHeader().getLength()}); + LOGGER.warn("Unknown or unhandled control-frame [version={} type={} flags={} length={}]", + frame.getHeader().getVersion(), + frame.getHeader().getType(), + frame.getHeader().getFlags(), + frame.getHeader().getLength()); } } } @@ -558,12 +565,12 @@ private void processWindowUpdateFrame(final SpdySession spdySession, if (stream != null) { stream.getOutputSink().onPeerWindowUpdate(delta); } else { - if (LOGGER.isLoggable(Level.FINE)) { + if (LOGGER.isDebugEnabled()) { final StringBuilder sb = new StringBuilder(64); sb.append("\nStream id=") .append(streamId) .append(" was not found. Ignoring the message."); - LOGGER.fine(sb.toString()); + LOGGER.debug(sb.toString()); } } } @@ -1256,9 +1263,9 @@ private static void processDataFrame(final SpdySession spdySession, if (spdyStream == null) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Data frame received for non-existent stream: connection={0}, frame={1}, stream={2}", - new Object[]{context.getConnection(), dataFrame, dataFrame.getHeader().getStreamId()}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Data frame received for non-existent stream: connection={}, frame={}, stream={}", + context.getConnection(), dataFrame, dataFrame.getHeader().getStreamId()); } final int dataSize = data.remaining(); @@ -1333,8 +1340,7 @@ private void pushAssociatedResoureses(final FilterChainContext ctx, pushStream.getOutputSink().writeDownStream(source, ctx); } catch (Exception e) { - LOGGER.log(Level.FINE, - "Can not push: " + entry.getKey(), e); + LOGGER.debug("Can not push: {}", entry.getKey(), e); } } } finally { @@ -1351,9 +1357,8 @@ private class ClientNpnNegotiator implements ClientSideNegotiator { @Override public boolean wantNegotiate(final SSLEngine engine) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "NPN wantNegotiate. Connection={0}", - new Object[]{NextProtoNegSupport.getConnection(engine)}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("NPN wantNegotiate. Connection={}", NextProtoNegSupport.getConnection(engine)); } return true; } @@ -1361,9 +1366,8 @@ public boolean wantNegotiate(final SSLEngine engine) { @Override public String selectProtocol(final SSLEngine engine, final LinkedHashSet protocols) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "NPN selectProtocol. Connection={0}, protocols={1}", - new Object[]{NextProtoNegSupport.getConnection(engine), protocols}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("NPN selectProtocol. Connection={}, protocols={}", NextProtoNegSupport.getConnection(engine), protocols); } for (SpdyVersion version : supportedSpdyVersions) { @@ -1382,9 +1386,8 @@ public String selectProtocol(final SSLEngine engine, @Override public void onNoDeal(final SSLEngine engine) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "NPN onNoDeal. Connection={0}", - new Object[]{NextProtoNegSupport.getConnection(engine)}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("NPN onNoDeal. Connection={}", NextProtoNegSupport.getConnection(engine)); } } } diff --git a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyRequest.java b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyRequest.java index 996ece3508..a83a0d93f4 100644 --- a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyRequest.java +++ b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdyRequest.java @@ -39,8 +39,7 @@ */ package org.glassfish.grizzly.spdy; -import java.util.logging.Logger; -import org.glassfish.grizzly.Grizzly; + import org.glassfish.grizzly.ThreadCache; import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.ProcessingState; @@ -52,8 +51,7 @@ * @author oleksiys */ class SpdyRequest extends HttpRequestPacket implements SpdyHeader { - private static final Logger LOGGER = Grizzly.logger(SpdyRequest.class); - + private static final ThreadCache.CachedTypeIndex CACHE_IDX = ThreadCache.obtainIndex(SpdyRequest.class, 2); diff --git a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdySession.java b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdySession.java index e466a87f67..bdbdfea685 100644 --- a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdySession.java +++ b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/SpdySession.java @@ -40,14 +40,15 @@ package org.glassfish.grizzly.spdy; +import static org.glassfish.grizzly.spdy.Constants.DEFAULT_INITIAL_WINDOW_SIZE; +import static org.glassfish.grizzly.spdy.Constants.DEFAULT_MAX_CONCURRENT_STREAMS; + import java.io.DataOutputStream; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Map; import java.util.concurrent.locks.ReentrantLock; -import java.util.logging.Level; -import java.util.logging.Logger; import java.util.zip.Deflater; import org.glassfish.grizzly.CloseType; @@ -81,8 +82,7 @@ import org.glassfish.grizzly.utils.DataStructures; import org.glassfish.grizzly.utils.Holder; import org.glassfish.grizzly.utils.NullaryFunction; - -import static org.glassfish.grizzly.spdy.Constants.*; +import org.slf4j.Logger; /** * The SPDY Session abstraction. @@ -91,7 +91,6 @@ */ public abstract class SpdySession { private static final Logger LOGGER = Grizzly.logger(SpdySession.class); - private static final Level LOGGER_LEVEL = Level.FINE; private static final Attribute SPDY_SESSION_ATTR = AttributeBuilder.DEFAULT_ATTRIBUTE_BUILDER.createAttribute( @@ -222,9 +221,8 @@ void setPeerStreamWindowSize(final int peerStreamWindowSize) { try { stream.getOutputSink().onPeerWindowUpdate(delta); } catch (SpdyStreamException e) { - if (LOGGER.isLoggable(LOGGER_LEVEL)) { - LOGGER.log(LOGGER_LEVEL, "SpdyStreamException occurred on stream=" - + stream + " during stream window update", e); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("SpdyStreamException occurred on stream={} during stream window update", stream, e); } outputSink.writeDownStream( diff --git a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/StreamInputBuffer.java b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/StreamInputBuffer.java index cbd8217d38..be36fa9d69 100644 --- a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/StreamInputBuffer.java +++ b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/StreamInputBuffer.java @@ -39,6 +39,8 @@ */ package org.glassfish.grizzly.spdy; +import static org.glassfish.grizzly.spdy.Constants.IN_FIN_TERMINATION; + import java.io.EOFException; import java.io.IOException; import java.util.concurrent.BlockingQueue; @@ -46,8 +48,7 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicReference; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -58,8 +59,7 @@ import org.glassfish.grizzly.memory.CompositeBuffer; import org.glassfish.grizzly.spdy.SpdyStream.Termination; import org.glassfish.grizzly.utils.DataStructures; - -import static org.glassfish.grizzly.spdy.Constants.*; +import org.slf4j.Logger; /** * @@ -233,7 +233,7 @@ private void passPayloadUpstream(final InputElement inputElement, spdySession.sendMessageUpstreamWithParseNotify(spdyStream, content); } catch (IOException e) { // Should never be thrown - LOGGER.log(Level.WARNING, "Unexpected IOException: {0}", e.getMessage()); + LOGGER.warn("Unexpected IOException: {}", e.getMessage()); } } diff --git a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/StreamOutputSink.java b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/StreamOutputSink.java index d37c61273b..9aa5df33e4 100644 --- a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/StreamOutputSink.java +++ b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/StreamOutputSink.java @@ -40,18 +40,17 @@ package org.glassfish.grizzly.spdy; -import org.glassfish.grizzly.spdy.utils.ChunkedCompletionHandler; +import static org.glassfish.grizzly.spdy.Constants.OUT_FIN_TERMINATION; + import java.io.IOException; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.CompletionHandler; -import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.WriteHandler; import org.glassfish.grizzly.WriteResult; -import org.glassfish.grizzly.asyncqueue.MessageCloner; import org.glassfish.grizzly.asyncqueue.AsyncQueueRecord; +import org.glassfish.grizzly.asyncqueue.MessageCloner; import org.glassfish.grizzly.asyncqueue.TaskQueue; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.http.HttpContent; @@ -65,8 +64,7 @@ import org.glassfish.grizzly.spdy.frames.SynReplyFrame; import org.glassfish.grizzly.spdy.frames.SynStreamFrame; import org.glassfish.grizzly.spdy.frames.WindowUpdateFrame; - -import static org.glassfish.grizzly.spdy.Constants.*; +import org.glassfish.grizzly.spdy.utils.ChunkedCompletionHandler; /** * Class represents an output sink associated with specific {@link SpdyStream}. @@ -77,8 +75,6 @@ * @author Alexey Stashok */ final class StreamOutputSink { - private static final Logger LOGGER = Grizzly.logger(StreamOutputSink.class); - private static final Level LOGGER_LEVEL = Level.INFO; private static final int MAX_OUTPUT_QUEUE_SIZE = 65536; diff --git a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/v3/SessionOutputSink3.java b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/v3/SessionOutputSink3.java index 507f369593..eea72f068e 100644 --- a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/v3/SessionOutputSink3.java +++ b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/v3/SessionOutputSink3.java @@ -40,11 +40,10 @@ package org.glassfish.grizzly.spdy.v3; -import org.glassfish.grizzly.spdy.*; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.WriteHandler; +import org.glassfish.grizzly.spdy.SessionOutputSink; +import org.glassfish.grizzly.spdy.SpdySession; +import org.glassfish.grizzly.spdy.SpdyStreamException; /** * Class represents an output sink associated with specific {@link SpdySession}. @@ -55,8 +54,6 @@ * @author Alexey Stashok */ final class SessionOutputSink3 extends SessionOutputSink { - private static final Logger LOGGER = Grizzly.logger(SessionOutputSink3.class); - private static final Level LOGGER_LEVEL = Level.FINE; public SessionOutputSink3(final SpdySession session) { super(session); diff --git a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/v31/SessionOutputSink31.java b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/v31/SessionOutputSink31.java index c1a61bb2d8..bc047f2a6a 100644 --- a/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/v31/SessionOutputSink31.java +++ b/modules/spdy/src/main/java/org/glassfish/grizzly/spdy/v31/SessionOutputSink31.java @@ -40,14 +40,14 @@ package org.glassfish.grizzly.spdy.v31; -import org.glassfish.grizzly.spdy.*; +import static org.glassfish.grizzly.spdy.Constants.DEFAULT_INITIAL_WINDOW_SIZE; + import java.util.LinkedList; import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.locks.LockSupport; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Grizzly; @@ -56,12 +56,14 @@ import org.glassfish.grizzly.asyncqueue.AsyncQueueRecord; import org.glassfish.grizzly.asyncqueue.MessageCloner; import org.glassfish.grizzly.asyncqueue.TaskQueue; +import org.glassfish.grizzly.spdy.SessionOutputSink; +import org.glassfish.grizzly.spdy.SpdySession; +import org.glassfish.grizzly.spdy.SpdyStream; import org.glassfish.grizzly.spdy.frames.DataFrame; import org.glassfish.grizzly.spdy.frames.SpdyFrame; - -import static org.glassfish.grizzly.spdy.Constants.*; import org.glassfish.grizzly.spdy.frames.WindowUpdateFrame; import org.glassfish.grizzly.spdy.utils.ChunkedCompletionHandler; +import org.slf4j.Logger; /** * Class represents an output sink associated with specific {@link SpdySession}. @@ -73,7 +75,6 @@ */ final class SessionOutputSink31 extends SessionOutputSink { private static final Logger LOGGER = Grizzly.logger(SessionOutputSink31.class); - private static final Level LOGGER_LEVEL = Level.FINE; private static final int MAX_OUTPUT_QUEUE_SIZE = 65536; @@ -120,9 +121,8 @@ protected void notifyCanWrite(final WriteHandler writeHandler) { protected void onPeerWindowUpdate(final int delta) { // @TODO check overflow final int newWindowSize = availConnectionWindowSize.addAndGet(delta); - if (LOGGER.isLoggable(LOGGER_LEVEL)) { - LOGGER.log(LOGGER_LEVEL, "SpdySession. Expand connection window size by {0} bytes. Current connection window size is: {1}", - new Object[] {delta, newWindowSize}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("SpdySession. Expand connection window size by {} bytes. Current connection window size is: {}", delta, newWindowSize); } flushOutputQueue(); @@ -224,9 +224,8 @@ private void flushOutputQueue() { if (record == null) { // keep this warning for now // should be reported when null record is spotted - LOGGER.log(Level.WARNING, "UNEXPECTED NULL RECORD. Queue-size: {0} " - + "tmpcnt={1} byteToTransfer={2} queueSizeToFree={3} queueSize={4}", - new Object[]{outputQueue.size(), tmpcnt, bytesToTransfer, queueSizeToFree, queueSize}); + LOGGER.warn("UNEXPECTED NULL RECORD. Queue-size: {} tmpcnt={} byteToTransfer={} queueSizeToFree={} queueSize={}", + outputQueue.size(), tmpcnt, bytesToTransfer, queueSizeToFree, queueSize); } assert record != null; @@ -281,9 +280,9 @@ assert record != null; outputQueue.releaseSpace(queueSizeToFree); needToNotify = true; - if (LOGGER.isLoggable(LOGGER_LEVEL)) { - LOGGER.log(LOGGER_LEVEL, "SpdySession. Shrink connection window size by {0} bytes. Current connection window size is: {1}", - new Object[] {bytesToTransfer, newWindowSize}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("SpdySession. Shrink connection window size by {} bytes. Current connection window size is: {}", + bytesToTransfer, newWindowSize); } } diff --git a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/AbstractSpdyTest.java b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/AbstractSpdyTest.java index 3b3d79a2ce..48941487eb 100644 --- a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/AbstractSpdyTest.java +++ b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/AbstractSpdyTest.java @@ -44,7 +44,7 @@ import java.util.Collection; import java.util.LinkedList; import java.util.Map; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.Filter; @@ -64,6 +64,7 @@ import org.glassfish.grizzly.ssl.SSLContextConfigurator; import org.glassfish.grizzly.ssl.SSLEngineConfigurator; import org.glassfish.grizzly.ssl.SSLFilter; +import org.slf4j.Logger; /** * General Spdy client/server init code. diff --git a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpInputStreamsTest.java b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpInputStreamsTest.java index 05998ecb3b..732a405b31 100644 --- a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpInputStreamsTest.java +++ b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpInputStreamsTest.java @@ -40,6 +40,13 @@ package org.glassfish.grizzly.spdy; +import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.IOException; import java.io.InputStream; import java.io.Reader; @@ -47,8 +54,7 @@ import java.util.Collection; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -75,9 +81,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; - -import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; -import static org.junit.Assert.*; +import org.slf4j.Logger; /** * Test cases to validate the behaviors of {@link org.glassfish.grizzly.http.io.NIOInputStream} and @@ -1368,8 +1372,8 @@ public ClientFilter(HttpPacket request, int chunkSize, FutureImpl testR @Override public NextAction handleConnect(FilterChainContext ctx) throws IOException { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Connected... Sending the request: {0}", request); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Connected... Sending the request: {}", request); } if (HttpContent.isContent(request) && @@ -1409,8 +1413,8 @@ public NextAction handleRead(FilterChainContext ctx) final Buffer buffer = httpContent.getContent(); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "HTTP content size: {0}, isLast: {1}", new Object[] {buffer.remaining(), httpContent.isLast()}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}, isLast: {}", buffer.remaining(), httpContent.isLast()); } if (httpContent.isLast()) { diff --git a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpLayerSemanticsTest.java b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpLayerSemanticsTest.java index a5391eeeb2..1cba70c112 100644 --- a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpLayerSemanticsTest.java +++ b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpLayerSemanticsTest.java @@ -40,12 +40,14 @@ package org.glassfish.grizzly.spdy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + import java.io.IOException; import java.util.Collection; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -68,10 +70,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; - -import static org.glassfish.grizzly.spdy.AbstractSpdyTest.createClientFilterChain; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import org.slf4j.Logger; /** * Tests Spdy semantics on HTTP layer @@ -218,7 +217,7 @@ private HttpContent doTest( } private static class ClientFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientFilter.class); private final FutureImpl testFuture; @@ -241,13 +240,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}", buffer.remaining()); } if (!httpContent.isLast()) { diff --git a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpOutputStreamsTest.java b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpOutputStreamsTest.java index e9fb7fae26..ee5b98573d 100644 --- a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpOutputStreamsTest.java +++ b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/HttpOutputStreamsTest.java @@ -40,18 +40,14 @@ package org.glassfish.grizzly.spdy; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import java.io.OutputStream; import java.io.Writer; import java.util.Collection; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.Parameterized; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; @@ -73,8 +69,10 @@ import org.glassfish.grizzly.memory.CompositeBuffer; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; - -import static org.junit.Assert.*; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.Parameterized; +import org.slf4j.Logger; @RunWith(Parameterized.class) public class HttpOutputStreamsTest extends AbstractSpdyTest { @@ -1189,7 +1187,7 @@ public void service(Request req, Response res) throws Exception { private static class ClientFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientFilter.class); private final CompositeBuffer buf = CompositeBuffer.newBuffer(); @@ -1221,8 +1219,8 @@ public NextAction handleConnect(FilterChainContext ctx) final HttpRequestPacket httpRequest = HttpRequestPacket.builder().method("GET") .uri("/path").protocol(Protocol.HTTP_1_1) .header("Host", "localhost:" + PORT).build(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Connected... Sending the request: {0}", httpRequest); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Connected... Sending the request: {}", httpRequest); } // Write the request asynchronously @@ -1241,13 +1239,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}", buffer.remaining()); } if (buffer.remaining() > 0) { bytesDownloaded += buffer.remaining(); @@ -1257,8 +1255,8 @@ public NextAction handleRead(FilterChainContext ctx) } if (httpContent.isLast()) { - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Response complete: {0} bytes", bytesDownloaded); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Response complete: {} bytes", bytesDownloaded); } completeFuture.result(buf.toStringContent()); close(); diff --git a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/NIOInputSourcesTest.java b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/NIOInputSourcesTest.java index 553f29ba20..aa157dc43f 100644 --- a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/NIOInputSourcesTest.java +++ b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/NIOInputSourcesTest.java @@ -41,14 +41,28 @@ package org.glassfish.grizzly.spdy; import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.fail; import java.io.EOFException; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.Collection; +import java.util.concurrent.ExecutionException; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.EmptyCompletionHandler; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.ReadHandler; import org.glassfish.grizzly.Transport; +import org.glassfish.grizzly.WriteResult; import org.glassfish.grizzly.filterchain.BaseFilter; +import org.glassfish.grizzly.filterchain.FilterChain; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; import org.glassfish.grizzly.http.HttpContent; @@ -59,35 +73,21 @@ import org.glassfish.grizzly.http.io.NIOInputStream; import org.glassfish.grizzly.http.io.NIOOutputStream; import org.glassfish.grizzly.http.io.NIOReader; -import org.glassfish.grizzly.impl.FutureImpl; -import org.glassfish.grizzly.impl.SafeFutureImpl; -import org.glassfish.grizzly.memory.ByteBufferManager; -import org.glassfish.grizzly.memory.CompositeBuffer; -import org.glassfish.grizzly.memory.MemoryManager; -import org.glassfish.grizzly.nio.transport.TCPNIOTransport; -import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; - -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.Collection; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.EmptyCompletionHandler; -import org.glassfish.grizzly.WriteResult; -import org.glassfish.grizzly.filterchain.FilterChain; import org.glassfish.grizzly.http.server.HttpHandler; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.server.NetworkListener; import org.glassfish.grizzly.http.server.Request; import org.glassfish.grizzly.http.server.Response; import org.glassfish.grizzly.http.util.Header; +import org.glassfish.grizzly.impl.FutureImpl; +import org.glassfish.grizzly.impl.SafeFutureImpl; import org.glassfish.grizzly.memory.Buffers; +import org.glassfish.grizzly.memory.ByteBufferManager; import org.glassfish.grizzly.memory.ByteBufferWrapper; +import org.glassfish.grizzly.memory.CompositeBuffer; +import org.glassfish.grizzly.memory.MemoryManager; +import org.glassfish.grizzly.nio.transport.TCPNIOTransport; +import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.threadpool.GrizzlyExecutorService; import org.glassfish.grizzly.utils.Exceptions; import org.junit.Before; @@ -95,8 +95,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; - -import static org.junit.Assert.*; +import org.slf4j.Logger; /** * Test case to exercise AsyncStreamReader. @@ -1122,7 +1121,7 @@ private static abstract class EchoHandler extends HttpHandler { } private static class ClientFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientFilter.class); private final CompositeBuffer buf = CompositeBuffer.newBuffer(); @@ -1157,8 +1156,8 @@ public ClientFilter(FutureImpl testFuture, public NextAction handleConnect(FilterChainContext ctx) throws IOException { - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Connected... Sending the request: {0}", request); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Connected... Sending the request: {}", request); } if (strategy == null) { @@ -1193,13 +1192,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}", buffer.remaining()); } if (buffer.hasRemaining()) { bytesDownloaded += buffer.remaining(); @@ -1209,9 +1208,8 @@ public NextAction handleRead(FilterChainContext ctx) } if (httpContent.isLast()) { - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "Response complete: {0} bytes", - bytesDownloaded); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Response complete: {} bytes", bytesDownloaded); } final String encoding = parseCharacterEncoding( httpContent.getHttpHeader().getHeader(Header.ContentType)); diff --git a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/NIOOutputSinksTest.java b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/NIOOutputSinksTest.java index b06c29699e..8a38e2a34d 100644 --- a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/NIOOutputSinksTest.java +++ b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/NIOOutputSinksTest.java @@ -40,6 +40,10 @@ package org.glassfish.grizzly.spdy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.IOException; import java.util.Arrays; import java.util.Collection; @@ -47,8 +51,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -81,8 +84,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; - -import static org.junit.Assert.*; +import org.slf4j.Logger; @RunWith(Parameterized.class) public class NIOOutputSinksTest extends AbstractSpdyTest { @@ -241,7 +243,7 @@ public void onError(Throwable t) { assertEquals(writeCounter.get(), length); assertTrue(callbackInvoked.get()); } finally { - LOGGER.log(Level.INFO, "Written {0}", writeCounter); + LOGGER.debug("Written {}", writeCounter); // Close the client connection if (connection != null) { connection.closeSilently(); @@ -337,7 +339,7 @@ public void service(final Request request, final Response response) throws Excep writeCounter.addAndGet(bufferSize); } } catch (Throwable e) { - LOGGER.log(Level.SEVERE, "Unexpected error", e); + LOGGER.error("Unexpected error", e); parseResult.failure(new IllegalStateException("Error", e)); } } @@ -358,7 +360,7 @@ public void service(final Request request, final Response response) throws Excep int length = parseResult.get(60, TimeUnit.SECONDS); assertEquals("Received " + length + " bytes", bytesToSend, length); } finally { - LOGGER.log(Level.INFO, "Written {0}", writeCounter); + LOGGER.info("Written {}", writeCounter); // Close the client connection if (connection != null) { connection.closeSilently(); @@ -624,7 +626,7 @@ public void service(final Request request, final Response response) throws Excep int length = parseResult.get(60, TimeUnit.SECONDS); assertEquals("Received " + length + " bytes", bytesToSend, length); } finally { - LOGGER.log(Level.INFO, "Written {0}", writeCounter); + LOGGER.info("Written {}", writeCounter); // Close the client connection if (connection != null) { connection.closeSilently(); @@ -859,7 +861,7 @@ public void service(final Request request, final Response response) throws Excep check1(resultStr, bufferSize); } finally { - LOGGER.log(Level.INFO, "Written {0}", writeCounter); + LOGGER.info("Written {}", writeCounter); // Close the client connection if (connection != null) { connection.closeSilently(); diff --git a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/SpdySemanticsTest.java b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/SpdySemanticsTest.java index 3abd180393..264fb0d056 100644 --- a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/SpdySemanticsTest.java +++ b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/SpdySemanticsTest.java @@ -40,6 +40,12 @@ package org.glassfish.grizzly.spdy; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.IOException; import java.io.InputStream; import java.util.Arrays; @@ -52,8 +58,8 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.LinkedTransferQueue; import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; import java.util.zip.Deflater; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.CloseListener; import org.glassfish.grizzly.CloseType; @@ -71,7 +77,6 @@ import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.Method; import org.glassfish.grizzly.http.Protocol; - import org.glassfish.grizzly.http.server.HttpHandler; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.server.NetworkListener; @@ -97,8 +102,7 @@ import org.glassfish.grizzly.spdy.frames.WindowUpdateFrame; import org.glassfish.grizzly.utils.Futures; import org.junit.Test; - -import static org.junit.Assert.*; +import org.slf4j.Logger; /** * Set of tests, which have to check Spdy semantics. @@ -559,7 +563,7 @@ public void service(Request request, Response response) throws Exception { // closed w/o RST frame - also ok, if the server could no // extract stream-id. // Print a warning just in case - LOGGER.warning("No RST frame"); + LOGGER.warn("No RST frame"); } assertTrue("No GoAway frame", hasGoAwayCome); diff --git a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/SplitTest.java b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/SplitTest.java index 6e7914c551..d97242e1cd 100644 --- a/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/SplitTest.java +++ b/modules/spdy/src/test/java/org/glassfish/grizzly/spdy/SplitTest.java @@ -40,13 +40,14 @@ package org.glassfish.grizzly.spdy; +import static org.junit.Assert.assertEquals; + import java.io.IOException; import java.util.Collection; import java.util.Map; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -72,8 +73,7 @@ import org.junit.Test; import org.junit.runner.RunWith; import org.junit.runners.Parameterized; - -import static org.junit.Assert.*; +import org.slf4j.Logger; /** * Test derived from http-server's "potential split vulnerability". @@ -226,7 +226,7 @@ private HttpServer createWebServer(final HttpHandler... httpHandlers) { private static class ClientFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientFilter.class); private final FutureImpl testFuture; @@ -249,13 +249,13 @@ public NextAction handleRead(FilterChainContext ctx) // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - if (logger.isLoggable(Level.FINE)) { - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("HTTP content size: {}", buffer.remaining()); } if (!httpContent.isLast()) { diff --git a/modules/websockets/pom.xml b/modules/websockets/pom.xml index 20aac94896..160622f640 100644 --- a/modules/websockets/pom.xml +++ b/modules/websockets/pom.xml @@ -123,5 +123,12 @@ javax.servlet-api provided + + org.mule.glassfish.grizzly + grizzly-framework + ${project.version} + test-jar + test + diff --git a/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/BaseWebSocketFilter.java b/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/BaseWebSocketFilter.java index 13d459123a..738caa9179 100644 --- a/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/BaseWebSocketFilter.java +++ b/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/BaseWebSocketFilter.java @@ -42,8 +42,6 @@ import java.io.IOException; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; @@ -59,6 +57,7 @@ import org.glassfish.grizzly.http.HttpServerFilter; import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.utils.IdleTimeoutFilter; +import org.slf4j.Logger; /** * WebSocket {@link Filter} implementation, which supposed to be placed into a {@link FilterChain} right after HTTP @@ -153,9 +152,8 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException { // Try to obtain associated WebSocket final WebSocketHolder holder = WebSocketHolder.get(connection); WebSocket ws = getWebSocket(connection); - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "handleRead websocket: {0} content-size={1} headers=\n{2}", - new Object[]{ws, message.getContent().remaining(), header}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("handleRead websocket: {} content-size={} headers=\n{}", ws, message.getContent().remaining(), header); } if (ws == null || !ws.isConnected()) { // If websocket is null - it means either non-websocket Connection, or websocket with incomplete handshake @@ -169,9 +167,8 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException { // Handle handshake return handleHandshake(ctx, message); } catch (HandshakeException e) { - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "Handshake error. Code: {0} Msg:{1}", - new Object[]{e.getCode(), e.getMessage()}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("Handshake error. Code: {} Msg:{}", e.getCode(), e.getMessage()); } onHandshakeFailure(connection, e); diff --git a/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/DefaultWebSocket.java b/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/DefaultWebSocket.java index 20c7e92daa..c4f75f4417 100644 --- a/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/DefaultWebSocket.java +++ b/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/DefaultWebSocket.java @@ -44,12 +44,12 @@ import java.io.IOException; import java.io.PrintWriter; import java.security.Principal; -import java.util.logging.Logger; + import javax.servlet.ServletInputStream; import javax.servlet.ServletOutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpSession; -import org.glassfish.grizzly.Grizzly; + import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.http.Cookie; import org.glassfish.grizzly.http.HttpRequestPacket; @@ -62,7 +62,6 @@ @SuppressWarnings({"StringContatenationInLoop"}) public class DefaultWebSocket extends SimpleWebSocket { - private static final Logger LOGGER = Grizzly.logger(DefaultWebSocket.class); protected final HttpServletRequest servletRequest; diff --git a/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/WebSocketClientFilter.java b/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/WebSocketClientFilter.java index 8ac0fa34aa..30fa161d5b 100644 --- a/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/WebSocketClientFilter.java +++ b/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/WebSocketClientFilter.java @@ -39,16 +39,15 @@ */ package org.glassfish.grizzly.websockets; +import java.io.IOException; + +import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; import org.glassfish.grizzly.http.HttpContent; import org.glassfish.grizzly.http.HttpResponsePacket; - -import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.Connection; -import org.glassfish.grizzly.Grizzly; +import org.slf4j.Logger; public class WebSocketClientFilter extends BaseWebSocketFilter { private static final Logger LOGGER = Grizzly.logger(WebSocketClientFilter.class); @@ -68,7 +67,7 @@ public class WebSocketClientFilter extends BaseWebSocketFilter { */ @Override public NextAction handleConnect(FilterChainContext ctx) throws IOException { - LOGGER.log(Level.FINEST, "handleConnect"); + LOGGER.trace("handleConnect"); // Get connection final Connection connection = ctx.getConnection(); // check if it's websocket connection diff --git a/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/WebSocketEngine.java b/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/WebSocketEngine.java index 4b5f49f371..084c0e2e7f 100644 --- a/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/WebSocketEngine.java +++ b/modules/websockets/src/main/java/org/glassfish/grizzly/websockets/WebSocketEngine.java @@ -44,13 +44,12 @@ import java.util.ArrayList; import java.util.HashMap; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; +import org.glassfish.grizzly.CloseType; import org.glassfish.grizzly.Closeable; import org.glassfish.grizzly.Connection; -import org.glassfish.grizzly.CloseType; import org.glassfish.grizzly.GenericCloseListener; +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.http.HttpContent; import org.glassfish.grizzly.http.HttpRequestPacket; @@ -58,6 +57,7 @@ import org.glassfish.grizzly.http.server.util.Mapper; import org.glassfish.grizzly.http.util.HttpStatus; import org.glassfish.grizzly.http.util.MimeHeaders; +import org.slf4j.Logger; /** * WebSockets engine implementation (singleton), which handles {@link WebSocketApplication}s registration, responsible @@ -73,7 +73,7 @@ public class WebSocketEngine { public static final int DEFAULT_TIMEOUT = 30; private static final String[] EMPTY_STRING_ARRAY = new String[0]; private static final WebSocketEngine engine = new WebSocketEngine(); - static final Logger logger = Logger.getLogger(Constants.WEBSOCKET); + static final Logger LOGGER = Grizzly.logger(Constants.WEBSOCKET); private final List applications = new ArrayList(); @@ -132,8 +132,8 @@ private WebSocketApplicationReg getApplication( foundWebSocketApp = (WebSocketApplication) data.wrapper; } } catch (Exception e) { - if (logger.isLoggable(Level.WARNING)) { - logger.log(Level.WARNING, e.toString(), e); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(e.toString(), e); } } @@ -163,8 +163,8 @@ private WebSocketApplicationReg getApplication( data, 0); } catch (Exception e) { - if (logger.isLoggable(Level.WARNING)) { - logger.log(Level.WARNING, e.toString(), e); + if (LOGGER.isWarnEnabled()) { + LOGGER.warn(e.toString(), e); } } } @@ -223,7 +223,7 @@ public void onClosed(final Closeable closeable, return true; } } catch (HandshakeException e) { - logger.log(Level.FINE, e.getMessage(), e); + LOGGER.debug(e.getMessage(), e); if (socket != null) { socket.close(); } diff --git a/modules/websockets/src/test/java/org/glassfish/grizzly/websockets/PingPongTest.java b/modules/websockets/src/test/java/org/glassfish/grizzly/websockets/PingPongTest.java index 7a06625c10..ec581ce037 100644 --- a/modules/websockets/src/test/java/org/glassfish/grizzly/websockets/PingPongTest.java +++ b/modules/websockets/src/test/java/org/glassfish/grizzly/websockets/PingPongTest.java @@ -39,6 +39,8 @@ */ package org.glassfish.grizzly.websockets; +import static org.glassfish.grizzly.utils.FreePortFinder.findFreePort; + import org.glassfish.grizzly.PortRange; import org.glassfish.grizzly.utils.Charsets; import org.junit.Test; @@ -50,8 +52,8 @@ import static org.junit.Assert.fail; public class PingPongTest { - - private static final int PORT = 9009; + + public final int PORT = findFreePort(); @Test public void testPingFromClientToServer() throws Exception { diff --git a/modules/websockets/src/test/java/org/glassfish/grizzly/websockets/WebSocketClient.java b/modules/websockets/src/test/java/org/glassfish/grizzly/websockets/WebSocketClient.java index b0168009d9..f81fdfb816 100644 --- a/modules/websockets/src/test/java/org/glassfish/grizzly/websockets/WebSocketClient.java +++ b/modules/websockets/src/test/java/org/glassfish/grizzly/websockets/WebSocketClient.java @@ -48,12 +48,11 @@ import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; import org.glassfish.grizzly.Connection; -import org.glassfish.grizzly.Processor; import org.glassfish.grizzly.EmptyCompletionHandler; +import org.glassfish.grizzly.Grizzly; +import org.glassfish.grizzly.Processor; import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.filterchain.TransportFilter; import org.glassfish.grizzly.http.HttpClientFilter; @@ -62,9 +61,10 @@ import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.utils.Futures; +import org.slf4j.Logger; public class WebSocketClient extends SimpleWebSocket { - private static final Logger logger = Logger.getLogger(Constants.WEBSOCKET); + private static final Logger LOGGER = Grizzly.logger(Constants.WEBSOCKET); private final Version version; private final URI address; private final ExecutorService executorService = Executors.newFixedThreadPool(2); @@ -196,7 +196,7 @@ public void onClose(WebSocket socket, DataFrame frame) { try { transport.shutdownNow(); } catch (IOException e) { - logger.log(Level.INFO, e.getMessage(), e); + LOGGER.info(e.getMessage(), e); } } } diff --git a/modules/websockets/src/test/java/org/glassfish/grizzly/websockets/WebSocketServer.java b/modules/websockets/src/test/java/org/glassfish/grizzly/websockets/WebSocketServer.java index a71f6391c5..67069ad757 100644 --- a/modules/websockets/src/test/java/org/glassfish/grizzly/websockets/WebSocketServer.java +++ b/modules/websockets/src/test/java/org/glassfish/grizzly/websockets/WebSocketServer.java @@ -43,9 +43,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; -import java.util.logging.Logger; -import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.PortRange; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.server.NetworkListener; @@ -53,7 +51,6 @@ import org.glassfish.grizzly.http.server.StaticHttpHandler; public class WebSocketServer { - private static final Logger logger = Grizzly.logger(WebSocketServer.class); private static final Object SYNC = new Object(); private HttpServer httpServer; diff --git a/pom.xml b/pom.xml index 8ad5439efd..607c9f6821 100644 --- a/pom.xml +++ b/pom.xml @@ -495,9 +495,29 @@ org.osgi.compendium 4.2.0 + + org.slf4j + slf4j-api + ${slf4jVersion} + + + org.apache.logging.log4j + log4j-slf4j2-impl + ${log4jVersion} + test + + + org.slf4j + slf4j-api + + + org.apache.logging.log4j + log4j-slf4j2-impl + test + junit junit @@ -522,5 +542,7 @@ 1.7 1.7 3.4.0 + 2.0.16 + 2.24.1 diff --git a/samples/connection-pool-samples/src/main/java/org/glassfish/grizzly/samples/connectionpool/MultiEndpointPoolSample.java b/samples/connection-pool-samples/src/main/java/org/glassfish/grizzly/samples/connectionpool/MultiEndpointPoolSample.java index 966962f60e..c3a30a94bd 100644 --- a/samples/connection-pool-samples/src/main/java/org/glassfish/grizzly/samples/connectionpool/MultiEndpointPoolSample.java +++ b/samples/connection-pool-samples/src/main/java/org/glassfish/grizzly/samples/connectionpool/MultiEndpointPoolSample.java @@ -40,6 +40,18 @@ package org.glassfish.grizzly.samples.connectionpool; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.net.SocketAddress; +import java.util.Collections; +import java.util.Random; +import java.util.Set; +import java.util.concurrent.CountDownLatch; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; +import java.util.concurrent.atomic.AtomicInteger; + import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.ConnectorHandler; import org.glassfish.grizzly.EmptyCompletionHandler; @@ -56,20 +68,9 @@ import org.glassfish.grizzly.utils.Charsets; import org.glassfish.grizzly.utils.DataStructures; import org.glassfish.grizzly.utils.StringFilter; +import org.slf4j.Logger; + -import java.io.IOException; -import java.net.InetSocketAddress; -import java.net.SocketAddress; -import java.util.Collections; -import java.util.Random; -import java.util.Set; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; /** * The sample to demonstrate how Grizzly client-side connection pool could be @@ -155,7 +156,7 @@ public void exec() throws Exception { // initialize count down latch responsesCountDownLatch = new CountDownLatch(requestsCount); - LOGGER.log(Level.INFO, "Making {0} requests...", requestsCount); + LOGGER.info("Making {} requests...", requestsCount); final long startTime = System.currentTimeMillis(); @@ -193,8 +194,7 @@ public void run() { @Override public void failed(Throwable throwable) { - LOGGER.log(Level.WARNING, - "Can't allocate a Connection", throwable); + LOGGER.warn("Can't allocate a Connection", throwable); } @Override @@ -220,11 +220,8 @@ public void completed(final Connection connection) { final long runTime = (System.currentTimeMillis() - startTime) / 1000; // print out stats - LOGGER.log(Level.INFO, "Completed in {0} seconds\nRequests sent: " - + "{1}\nResponses missed: {2}\nConnections created: {3}", - new Object[]{runTime, requestsCount, - responsesCountDownLatch.getCount(), - clientConnectionsCounter.get()}); + LOGGER.info("Completed in {} seconds\nRequests sent: {}\nResponses missed: {}\nConnections created: {}", + runTime, requestsCount, responsesCountDownLatch.getCount(), clientConnectionsCounter.get()); } finally { // shutdown the aux. thread-pool @@ -262,8 +259,7 @@ public void onResponseReceived(final Connection connection, responsesCountDownLatch.countDown(); } else { // if message is not tracked - it's a bug - LOGGER.log(Level.WARNING, "Received unexpected response: {0}", - responseMessage); + LOGGER.warn("Received unexpected response: {}", responseMessage); } // return the connection back to the pool diff --git a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/echo/EchoServer.java b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/echo/EchoServer.java index b557980870..85f2dc92c2 100644 --- a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/echo/EchoServer.java +++ b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/echo/EchoServer.java @@ -42,12 +42,14 @@ import java.io.IOException; import java.nio.charset.Charset; -import java.util.logging.Logger; + +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.filterchain.TransportFilter; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.utils.StringFilter; +import org.slf4j.Logger; /** * Class initializes and starts the echo server, based on Grizzly 2.0 @@ -55,7 +57,7 @@ * @author Alexey Stashok */ public class EchoServer { - private static final Logger logger = Logger.getLogger(EchoServer.class.getName()); + private static final Logger logger = Grizzly.logger(EchoServer.class); public static final String HOST = "localhost"; public static final int PORT = 7777; diff --git a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/Client.java b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/Client.java index bd49c4562e..59546836b8 100644 --- a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/Client.java +++ b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/Client.java @@ -47,14 +47,15 @@ import java.util.List; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.filterchain.TransportFilter; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.utils.Charsets; +import org.slf4j.Logger; /** * Client implementation, which sends a message to a {@link Server} and checks @@ -79,7 +80,7 @@ * @author Alexey Stashok */ public class Client { - private static final Logger logger = Logger.getLogger(Client.class.getName()); + private static final Logger logger = Grizzly.logger(Client.class); @SuppressWarnings("unchecked") public static void main(String[] args) throws Exception { @@ -131,7 +132,7 @@ protected List createInList() { // Send echo message final MultiLinePacket request = MultiLinePacket.create("echo", input); - logger.log(Level.INFO, "--------- Client is sending the request:\n{0}", request); + logger.info("--------- Client is sending the request:\n{}", request); connection.write(request); } diff --git a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/ClientFilter.java b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/ClientFilter.java index c6cce0ddfe..acea6834fb 100644 --- a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/ClientFilter.java +++ b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/ClientFilter.java @@ -40,12 +40,14 @@ package org.glassfish.grizzly.samples.simpleauth; +import java.io.IOException; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; -import java.io.IOException; -import java.util.logging.Logger; +import org.slf4j.Logger; + /** * Simple filter, which prints out the server echo message. @@ -53,7 +55,7 @@ * @author Alexey Stashok */ public class ClientFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientFilter.class); /** * The method is called, when we receive a message from a server. @@ -69,7 +71,7 @@ public NextAction handleRead(FilterChainContext ctx) // Get the message final MultiLinePacket message = ctx.getMessage(); - logger.info("---------Client got a response:\n" + message); + LOGGER.info("---------Client got a response:\n" + message); return ctx.getStopAction(); } diff --git a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/MultiLineFilter.java b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/MultiLineFilter.java index 5718300db7..f7ed88ee0e 100644 --- a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/MultiLineFilter.java +++ b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/MultiLineFilter.java @@ -44,14 +44,14 @@ import java.util.ArrayList; import java.util.Iterator; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.attributes.Attribute; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; +import org.slf4j.Logger; /** * The {@link org.glassfish.grizzly.filterchain.Filter} is responsible for a @@ -123,7 +123,7 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException { // Set MultiLinePacket packet as a context message ctx.setMessage(packet); - LOGGER.log(Level.INFO, "-------- Received from network:\n{0}", packet); + LOGGER.info("-------- Received from network:\n{}", packet); return input.isEmpty() ? ctx.getInvokeAction() @@ -145,7 +145,7 @@ public NextAction handleWrite(FilterChainContext ctx) throws IOException { // Get a processing MultiLinePacket final MultiLinePacket input = ctx.getMessage(); - LOGGER.log(Level.INFO, "------- Sending to network:\n{0}", input); + LOGGER.info("------- Sending to network:\n{}", input); // pass MultiLinePacket as List. // we could've used input.getLines() as collection to be passed diff --git a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/MultiStringFilter.java b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/MultiStringFilter.java index e74c70d824..b0d694e25e 100644 --- a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/MultiStringFilter.java +++ b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/MultiStringFilter.java @@ -45,8 +45,7 @@ import java.nio.charset.Charset; import java.util.ArrayList; import java.util.List; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -58,7 +57,8 @@ import org.glassfish.grizzly.memory.MemoryManager; import org.glassfish.grizzly.utils.BufferOutputStream; import org.glassfish.grizzly.utils.StringFilter; - +import org.slf4j.Logger; + /** * MultiString filter, the codec, that converts Buffer <-> List<String> * @@ -206,9 +206,8 @@ protected DecodeResult parseWithLengthPrefix(final Buffer input, return decodeResult; } - if (LOGGER.isLoggable(Level.FINE)) { - LOGGER.log(Level.FINE, "StringFilter decode stringSize={0} buffer={1} content={2}", - new Object[]{decodeResult.state, input, input.toStringContent()}); + if (LOGGER.isDebugEnabled()) { + LOGGER.debug("StringFilter decode stringSize={} buffer={} content={}", decodeResult.state, input, input.toStringContent()); } int stringSize = decodeResult.state; diff --git a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/Server.java b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/Server.java index 1cc28abf0c..94d7a37569 100644 --- a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/Server.java +++ b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/simpleauth/Server.java @@ -40,17 +40,19 @@ package org.glassfish.grizzly.samples.simpleauth; +import java.io.IOException; +import java.nio.charset.Charset; +import java.util.LinkedList; +import java.util.List; + +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.filterchain.TransportFilter; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.samples.echo.EchoFilter; +import org.slf4j.Logger; -import java.io.IOException; -import java.nio.charset.Charset; -import java.util.LinkedList; -import java.util.List; -import java.util.logging.Logger; /** * Server implementation, which echoes message, only if client was authenticated :) @@ -73,7 +75,7 @@ * @author Alexey Stashok */ public class Server { - private static final Logger logger = Logger.getLogger(Server.class.getName()); + private static final Logger LOGGER = Grizzly.logger(Server.class); public static final String HOST = "localhost"; public static final int PORT = 7777; @@ -112,14 +114,14 @@ protected List createInList() { // start the transport transport.start(); - logger.info("Press any key to stop the server..."); + LOGGER.info("Press any key to stop the server..."); System.in.read(); } finally { - logger.info("Stopping transport..."); + LOGGER.info("Stopping transport..."); // stop the transport transport.shutdownNow(); - logger.info("Stopped transport..."); + LOGGER.info("Stopped transport..."); } } } diff --git a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/tunnel/TunnelFilter.java b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/tunnel/TunnelFilter.java index 6ef1a32703..4ba0879fb2 100644 --- a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/tunnel/TunnelFilter.java +++ b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/tunnel/TunnelFilter.java @@ -43,8 +43,7 @@ import java.io.IOException; import java.net.InetSocketAddress; import java.net.SocketAddress; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.CompletionHandler; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -55,6 +54,7 @@ import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChainContext; import org.glassfish.grizzly.filterchain.NextAction; +import org.slf4j.Logger; /** * Simple tunneling filter, which maps input of one connection to the output of @@ -90,8 +90,7 @@ public TunnelFilter(SocketConnectorHandler transport, SocketAddress redirectAddr @Override public NextAction handleRead(final FilterChainContext ctx) throws IOException { - logger.log(Level.FINEST, "Connection: {0} handleRead: {1}", - new Object[]{ctx.getConnection(), ctx.getMessage()}); + logger.trace("Connection: {} handleRead: {}", ctx.getConnection(), ctx.getMessage()); final Connection connection = ctx.getConnection(); final Connection peerConnection = peerConnectionAttribute.get(connection); @@ -177,8 +176,8 @@ private static void redirectToPeer(final FilterChainContext context, final Connection peerConnection, Object message) throws IOException { final Connection srcConnection = context.getConnection(); - logger.log(Level.FINE, "Redirecting from {0} to {1} message: {2}", - new Object[]{srcConnection.getPeerAddress(), peerConnection.getPeerAddress(), message}); + logger.debug("Redirecting from {} to {} message: {}", + srcConnection.getPeerAddress(), peerConnection.getPeerAddress(), message); peerConnection.write(message); } diff --git a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/tunnel/TunnelServer.java b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/tunnel/TunnelServer.java index 47b8565571..af7a13e62f 100644 --- a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/tunnel/TunnelServer.java +++ b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/tunnel/TunnelServer.java @@ -40,14 +40,16 @@ package org.glassfish.grizzly.samples.tunnel; +import java.io.IOException; + +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.filterchain.TransportFilter; import org.glassfish.grizzly.nio.transport.TCPNIOConnectorHandler; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; +import org.slf4j.Logger; -import java.io.IOException; -import java.util.logging.Logger; /** * Simple tunneling server @@ -55,7 +57,7 @@ * @author Alexey Stashok */ public class TunnelServer { - private static final Logger logger = Logger.getLogger(TunnelServer.class.getName()); + private static final Logger LOGGER = Grizzly.logger(TunnelServer.class); public static final String HOST = "localhost"; public static final int PORT = 7777; @@ -89,14 +91,14 @@ public static void main(String[] args) throws IOException { // start the transport transport.start(); - logger.info("Press any key to stop the server..."); + LOGGER.info("Press any key to stop the server..."); System.in.read(); } finally { - logger.info("Stopping transport..."); + LOGGER.info("Stopping transport..."); // stop the transport transport.shutdownNow(); - logger.info("Stopped transport..."); + LOGGER.info("Stopped transport..."); } } } diff --git a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpecho/EchoClient.java b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpecho/EchoClient.java index 8d8325c175..9b57e38576 100644 --- a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpecho/EchoClient.java +++ b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpecho/EchoClient.java @@ -45,7 +45,8 @@ import java.util.concurrent.ExecutionException; import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; -import java.util.logging.Logger; + +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.BaseFilter; import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.filterchain.FilterChainContext; @@ -56,6 +57,7 @@ import org.glassfish.grizzly.nio.transport.UDPNIOTransport; import org.glassfish.grizzly.nio.transport.UDPNIOTransportBuilder; import org.glassfish.grizzly.utils.StringFilter; +import org.slf4j.Logger; /** * The simple client, which sends a message to the echo server @@ -63,7 +65,7 @@ * @author Alexey Stashok */ public class EchoClient { - private static final Logger logger = Logger.getLogger(EchoClient.class.getName()); + private static final Logger LOGGER = Grizzly.logger(EchoClient.class); public static void main(String[] args) throws IOException, ExecutionException, InterruptedException, TimeoutException { @@ -97,7 +99,7 @@ public static void main(String[] args) throws IOException, // check the result final boolean isEqual = future.get(10, TimeUnit.SECONDS); assert isEqual; - logger.info("Echo came successfully"); + LOGGER.info("Echo came successfully"); } finally { // stop the transport transport.shutdownNow(); diff --git a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpecho/EchoServer.java b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpecho/EchoServer.java index 1dff961527..1507c2a033 100644 --- a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpecho/EchoServer.java +++ b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpecho/EchoServer.java @@ -42,13 +42,15 @@ import java.io.IOException; import java.nio.charset.Charset; -import java.util.logging.Logger; + +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.filterchain.TransportFilter; import org.glassfish.grizzly.nio.transport.UDPNIOTransport; import org.glassfish.grizzly.nio.transport.UDPNIOTransportBuilder; import org.glassfish.grizzly.samples.echo.EchoFilter; import org.glassfish.grizzly.utils.StringFilter; +import org.slf4j.Logger; /** * Class initializes and starts the UDP echo server, based on Grizzly 2.0 @@ -56,7 +58,7 @@ * @author Alexey Stashok */ public class EchoServer { - private static final Logger logger = Logger.getLogger(EchoServer.class.getName()); + private static final Logger logger = Grizzly.logger(EchoServer.class); public static final String HOST = "localhost"; public static final int PORT = 7777; diff --git a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpmulticast/MulticastChat.java b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpmulticast/MulticastChat.java index 54e4b2d9be..7293458a54 100644 --- a/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpmulticast/MulticastChat.java +++ b/samples/framework-samples/src/main/java/org/glassfish/grizzly/samples/udpmulticast/MulticastChat.java @@ -46,8 +46,9 @@ import java.nio.charset.Charset; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; + import org.glassfish.grizzly.Connection; +import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.FilterChain; import org.glassfish.grizzly.filterchain.FilterChainBuilder; import org.glassfish.grizzly.filterchain.TransportFilter; @@ -56,6 +57,7 @@ import org.glassfish.grizzly.nio.transport.UDPNIOTransportBuilder; import org.glassfish.grizzly.utils.JdkVersion; import org.glassfish.grizzly.utils.StringFilter; +import org.slf4j.Logger; /** * Simple chat application based on UDP multicast. @@ -108,7 +110,7 @@ * @author Alexey Stashok */ public class MulticastChat { - private static final Logger logger = Logger.getLogger(MulticastChat.class.getName()); + private static final Logger LOGGER = Grizzly.logger(MulticastChat.class); private static final int PORT = 8888; @@ -187,11 +189,11 @@ private void run() throws Exception { connection.close(); } - logger.fine("Stopping transport..."); + LOGGER.debug("Stopping transport..."); // stop the transport transport.shutdownNow(); - logger.fine("Stopped transport..."); + LOGGER.debug("Stopped transport..."); } } diff --git a/samples/http-ajp-samples/src/main/java/org/glassfish/grizzly/samples/ajp/AjpHelloWorld.java b/samples/http-ajp-samples/src/main/java/org/glassfish/grizzly/samples/ajp/AjpHelloWorld.java index 7aae13cb49..550476e5ac 100644 --- a/samples/http-ajp-samples/src/main/java/org/glassfish/grizzly/samples/ajp/AjpHelloWorld.java +++ b/samples/http-ajp-samples/src/main/java/org/glassfish/grizzly/samples/ajp/AjpHelloWorld.java @@ -42,8 +42,7 @@ import java.io.IOException; import java.io.Writer; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.ajp.AjpAddOn; import org.glassfish.grizzly.http.server.HttpHandler; @@ -52,6 +51,7 @@ import org.glassfish.grizzly.http.server.Request; import org.glassfish.grizzly.http.server.Response; import org.glassfish.grizzly.http.server.ServerConfiguration; +import org.slf4j.Logger; /** * Sample demonstrates how custom {@link HttpHandler}, rigistered on @@ -101,7 +101,7 @@ public static void main(String[] args) { System.out.println("Press enter to stop..."); System.in.read(); } catch (IOException ioe) { - LOGGER.log(Level.SEVERE, ioe.toString(), ioe); + LOGGER.error(ioe.toString(), ioe); } finally { server.shutdownNow(); } diff --git a/samples/http-multipart-samples/src/main/java/org/glassfish/grizzly/samples/httpmultipart/UploadServer.java b/samples/http-multipart-samples/src/main/java/org/glassfish/grizzly/samples/httpmultipart/UploadServer.java index 0abdf2f9e9..40071cd0f2 100644 --- a/samples/http-multipart-samples/src/main/java/org/glassfish/grizzly/samples/httpmultipart/UploadServer.java +++ b/samples/http-multipart-samples/src/main/java/org/glassfish/grizzly/samples/httpmultipart/UploadServer.java @@ -40,12 +40,12 @@ package org.glassfish.grizzly.samples.httpmultipart; import java.io.IOException; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.server.NetworkListener; import org.glassfish.grizzly.http.server.ServerConfiguration; +import org.slf4j.Logger; /** * HTTP upload server, which instantiates two Grizzly {@link org.glassfish.grizzly.http.server.HttpHandler}s: @@ -81,11 +81,11 @@ public static void main(String[] args) { // Start the server server.start(); - LOGGER.log(Level.INFO, "Server listens on port {0}", PORT); - LOGGER.log(Level.INFO, "Press enter to exit"); + LOGGER.info("Server listens on port {}", PORT); + LOGGER.info("Press enter to exit"); System.in.read(); } catch (IOException ioe) { - LOGGER.log(Level.SEVERE, ioe.toString(), ioe); + LOGGER.error(ioe.toString(), ioe); } finally { // Stop the server server.shutdownNow(); diff --git a/samples/http-multipart-samples/src/main/java/org/glassfish/grizzly/samples/httpmultipart/UploaderHttpHandler.java b/samples/http-multipart-samples/src/main/java/org/glassfish/grizzly/samples/httpmultipart/UploaderHttpHandler.java index a6aa90cae0..7360fe45a3 100644 --- a/samples/http-multipart-samples/src/main/java/org/glassfish/grizzly/samples/httpmultipart/UploaderHttpHandler.java +++ b/samples/http-multipart-samples/src/main/java/org/glassfish/grizzly/samples/httpmultipart/UploaderHttpHandler.java @@ -45,11 +45,11 @@ import java.io.IOException; import java.io.Writer; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.EmptyCompletionHandler; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.ReadHandler; +import org.glassfish.grizzly.http.io.NIOInputStream; import org.glassfish.grizzly.http.multipart.ContentDisposition; import org.glassfish.grizzly.http.multipart.MultipartEntry; import org.glassfish.grizzly.http.multipart.MultipartEntryHandler; @@ -57,7 +57,7 @@ import org.glassfish.grizzly.http.server.HttpHandler; import org.glassfish.grizzly.http.server.Request; import org.glassfish.grizzly.http.server.Response; -import org.glassfish.grizzly.http.io.NIOInputStream; +import org.slf4j.Logger; /** * The Grizzly {@link HttpHandler} implementation, which is responsible for @@ -89,7 +89,7 @@ public void service(final Request request, final Response response) // assign uploadNumber for this specific upload final int uploadNumber = uploadsCounter.getAndIncrement(); - LOGGER.log(Level.INFO, "Starting upload #{0}", uploadNumber); + LOGGER.info("Starting upload #{}", uploadNumber); // Initialize MultipartEntryHandler, responsible for handling // multipart entries of this request @@ -107,9 +107,7 @@ public void completed(final Request request) { // Upload is complete final int bytesUploaded = uploader.getBytesUploaded(); - LOGGER.log(Level.INFO, "Upload #{0}: is complete. " - + "{1} bytes uploaded", - new Object[] {uploadNumber, bytesUploaded}); + LOGGER.info("Upload #{}: is complete. {} bytes uploaded", uploadNumber, bytesUploaded); // Compose a server response. try { @@ -127,7 +125,7 @@ public void completed(final Request request) { @Override public void failed(Throwable throwable) { // if failed - log the error - LOGGER.log(Level.INFO, "Upload #" + uploadNumber + " failed", throwable); + LOGGER.info("Upload #{} failed", uploadNumber, throwable); // Complete the asynchronous HTTP request processing. response.resume(); } @@ -172,8 +170,7 @@ public void handle(final MultipartEntry multipartEntry) throws Exception { // Get the NIOInputStream to read the multipart entry content final NIOInputStream inputStream = multipartEntry.getNIOInputStream(); - LOGGER.log(Level.INFO, "Upload #{0}: uploading file {1}", - new Object[]{uploadNumber, filename}); + LOGGER.info("Upload #{}: uploading file {}", uploadNumber, filename); // start asynchronous non-blocking content read. inputStream.notifyAvailable( @@ -181,13 +178,11 @@ public void handle(final MultipartEntry multipartEntry) throws Exception { inputStream, uploadedBytesCounter)); } else if (DESCRIPTION_NAME.equals(name)) { // if multipart entry contains a description field - LOGGER.log(Level.INFO, "Upload #{0}: description came. " - + "Skipping...", uploadNumber); + LOGGER.info("Upload #{}: description came. Skipping...", uploadNumber); // skip the multipart entry multipartEntry.skip(); } else { // Unexpected entry? - LOGGER.log(Level.INFO, "Upload #{0}: unknown multipart entry. " - + "Skipping...", uploadNumber); + LOGGER.info("Upload #{}: unknown multipart entry. Skipping...", uploadNumber); // skip it multipartEntry.skip(); } @@ -266,7 +261,7 @@ public void onAllDataRead() throws Exception { */ @Override public void onError(Throwable t) { - LOGGER.log(Level.WARNING, "Upload #" + uploadNumber + ": failed", t); + LOGGER.warn("Upload #{}: failed", uploadNumber, t); // finish the upload finish(); } diff --git a/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/Client.java b/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/Client.java index 5294b756e8..e683924237 100644 --- a/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/Client.java +++ b/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/Client.java @@ -40,6 +40,7 @@ package org.glassfish.grizzly.samples.http.download; +import org.slf4j.Logger; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.FilterChainBuilder; @@ -56,8 +57,6 @@ import java.net.URISyntaxException; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; /** * Simple asynchronous HTTP client implementation, which downloads HTTP resource @@ -123,12 +122,12 @@ public static void main(String[] args) throws IOException, URISyntaxException { connection = connectFuture.get(10, TimeUnit.SECONDS); // Wait until download will be completed String filename = completeFuture.get(); - logger.log(Level.INFO, "File " + filename + " was successfully downloaded"); + logger.info("File " + filename + " was successfully downloaded"); } catch (Exception e) { if (connection == null) { - logger.log(Level.WARNING, "Can not connect to the target resource"); + logger.warn("Can not connect to the target resource"); } else { - logger.log(Level.WARNING, "Error downloading the resource"); + logger.warn("Error downloading the resource"); } } finally { // Close the client connection diff --git a/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/ClientDownloadFilter.java b/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/ClientDownloadFilter.java index 87f3c049ca..61af7387eb 100644 --- a/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/ClientDownloadFilter.java +++ b/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/ClientDownloadFilter.java @@ -45,8 +45,8 @@ import java.net.URI; import java.nio.ByteBuffer; import java.nio.channels.FileChannel; -import java.util.logging.Level; -import java.util.logging.Logger; + + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.filterchain.BaseFilter; @@ -56,6 +56,7 @@ import org.glassfish.grizzly.http.HttpRequestPacket; import org.glassfish.grizzly.http.Protocol; import org.glassfish.grizzly.impl.FutureImpl; +import org.slf4j.Logger; /** * HTTP client download filter. @@ -65,7 +66,7 @@ * @author Alexey Stashok */ public class ClientDownloadFilter extends BaseFilter { - private final static Logger logger = Grizzly.logger(ClientDownloadFilter.class); + private final static Logger LOGGER = Grizzly.logger(ClientDownloadFilter.class); // URI of a remote resource private final URI uri; @@ -126,7 +127,7 @@ public NextAction handleConnect(FilterChainContext ctx) throws IOException { final HttpRequestPacket httpRequest = HttpRequestPacket.builder().method("GET") .uri(resourcePath).protocol(Protocol.HTTP_1_1) .header("Host", uri.getHost()).build(); - logger.log(Level.INFO, "Connected... Sending the request: {0}", httpRequest); + LOGGER.info("Connected... Sending the request: {}", httpRequest); // Write the request asynchronously ctx.write(httpRequest); @@ -151,11 +152,11 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException { // Cast message to a HttpContent final HttpContent httpContent = ctx.getMessage(); - logger.log(Level.FINE, "Got HTTP response chunk"); + LOGGER.debug("Got HTTP response chunk"); if (output == null) { // If local file wasn't created - create it - logger.log(Level.INFO, "HTTP response: {0}", httpContent.getHttpHeader()); - logger.log(Level.FINE, "Create a file: {0}", fileName); + LOGGER.info("HTTP response: {}", httpContent.getHttpHeader()); + LOGGER.debug("Create a file: {}", fileName); FileOutputStream fos = new FileOutputStream(fileName); output = fos.getChannel(); } @@ -163,7 +164,7 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException { // Get HttpContent's Buffer final Buffer buffer = httpContent.getContent(); - logger.log(Level.FINE, "HTTP content size: {0}", buffer.remaining()); + LOGGER.debug("HTTP content size: {}", buffer.remaining()); if (buffer.remaining() > 0) { bytesDownloaded += buffer.remaining(); @@ -180,7 +181,7 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException { if (httpContent.isLast()) { // it's last HttpContent - we close the local file and // notify about download completion - logger.log(Level.FINE, "Downloaded done: {0} bytes", bytesDownloaded); + LOGGER.debug("Downloaded done: {} bytes", bytesDownloaded); completeFuture.result(fileName); close(); } diff --git a/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/Server.java b/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/Server.java index 0a9e51bdb1..9899d9ecaf 100644 --- a/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/Server.java +++ b/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/Server.java @@ -48,9 +48,11 @@ import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; import org.glassfish.grizzly.utils.DelayedExecutor; import org.glassfish.grizzly.utils.IdleTimeoutFilter; +import org.slf4j.Logger; + import java.io.IOException; import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; + /** * Simple HTTP (Web) server, which listens on a specific TCP port and shares @@ -59,7 +61,7 @@ * @author Alexey Stashok */ public class Server { - private static final Logger logger = Grizzly.logger(Server.class); + private static final Logger LOGGER = Grizzly.logger(Server.class); // TCP Host public static final String HOST = "localhost"; @@ -99,15 +101,15 @@ public static void main(String[] args) throws IOException { // start the transport transport.start(); - logger.info("Press any key to stop the server..."); + LOGGER.info("Press any key to stop the server..."); System.in.read(); } finally { - logger.info("Stopping transport..."); + LOGGER.info("Stopping transport..."); // stop the transport transport.shutdownNow(); timeoutExecutor.stop(); timeoutExecutor.destroy(); - logger.info("Stopped transport..."); + LOGGER.info("Stopped transport..."); } } } diff --git a/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/WebServerFilter.java b/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/WebServerFilter.java index 60eb821eb0..1918b44481 100644 --- a/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/WebServerFilter.java +++ b/samples/http-samples/src/main/java/org/glassfish/grizzly/samples/http/download/WebServerFilter.java @@ -46,8 +46,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.EmptyCompletionHandler; import org.glassfish.grizzly.Grizzly; @@ -61,6 +60,7 @@ import org.glassfish.grizzly.http.HttpResponsePacket; import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.MemoryManager; +import org.slf4j.Logger; /** * Simple Web server implementation, which locates requested resources in a @@ -69,7 +69,7 @@ * @author Alexey Stashok */ public class WebServerFilter extends BaseFilter { - private static final Logger logger = Grizzly.logger(WebServerFilter.class); + private static final Logger LOGGER = Grizzly.logger(WebServerFilter.class); private final File rootFolderFile; /** @@ -129,7 +129,7 @@ public NextAction handleRead(FilterChainContext ctx) // Locate corresponding file final File file = new File(rootFolderFile, localURL); - logger.log(Level.INFO, "Request file: {0}", file.getAbsolutePath()); + LOGGER.info("Request file: {}", file.getAbsolutePath()); if (!file.isFile()) { // If file doesn't exist - response 404 @@ -363,7 +363,7 @@ private void close() { try { in.close(); } catch (IOException e) { - logger.fine("Error closing a downloading file"); + LOGGER.debug("Error closing a downloading file"); } } diff --git a/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/blockinghandler/BlockingHttpHandlerSample.java b/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/blockinghandler/BlockingHttpHandlerSample.java index a11496927e..db3b05a0ac 100644 --- a/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/blockinghandler/BlockingHttpHandlerSample.java +++ b/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/blockinghandler/BlockingHttpHandlerSample.java @@ -40,6 +40,12 @@ package org.glassfish.grizzly.samples.httpserver.blockinghandler; +import java.io.IOException; +import java.io.Reader; +import java.io.Writer; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -60,18 +66,11 @@ import org.glassfish.grizzly.http.util.HeaderValue; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; +import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.MemoryManager; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; - -import java.io.IOException; -import java.io.Reader; -import java.io.Writer; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; +import org.slf4j.Logger; /** @@ -122,7 +121,7 @@ public static void main(String[] args) { Client client = new Client(); client.run(); } catch (IOException ioe) { - LOGGER.log(Level.SEVERE, ioe.toString(), ioe); + LOGGER.error(ioe.toString(), ioe); } finally { server.shutdownNow(); } @@ -178,9 +177,9 @@ public void run() throws IOException { System.out.println("\nEchoed POST Data: " + result + '\n'); } catch (Exception e) { if (connection == null) { - LOGGER.log(Level.WARNING, "Connection failed. Server is not listening."); + LOGGER.warn("Connection failed. Server is not listening."); } else { - LOGGER.log(Level.WARNING, "Unexpected error communicating with the server."); + LOGGER.warn("Unexpected error communicating with the server."); } } finally { // Close the client connection diff --git a/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/nonblockinghandler/DownloadHttpHandlerSample.java b/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/nonblockinghandler/DownloadHttpHandlerSample.java index dbbf69b1b8..17e7bc5d3f 100644 --- a/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/nonblockinghandler/DownloadHttpHandlerSample.java +++ b/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/nonblockinghandler/DownloadHttpHandlerSample.java @@ -44,21 +44,21 @@ import java.io.FileInputStream; import java.io.IOException; import java.nio.channels.FileChannel; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.WriteHandler; +import org.glassfish.grizzly.http.io.NIOOutputStream; import org.glassfish.grizzly.http.server.HttpHandler; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.server.NetworkListener; import org.glassfish.grizzly.http.server.Request; import org.glassfish.grizzly.http.server.Response; import org.glassfish.grizzly.http.server.ServerConfiguration; -import org.glassfish.grizzly.http.io.NIOOutputStream; -import org.glassfish.grizzly.http.util.MimeType; import org.glassfish.grizzly.http.util.HttpStatus; +import org.glassfish.grizzly.http.util.MimeType; import org.glassfish.grizzly.memory.MemoryManager; +import org.slf4j.Logger; /** * The sample shows how the HttpHandler should be implemented in order to @@ -113,7 +113,7 @@ public static void main(String[] args) { LOGGER.info("Press enter to stop the server..."); System.in.read(); } catch (IOException ioe) { - LOGGER.log(Level.SEVERE, ioe.toString(), ioe); + LOGGER.error(ioe.toString(), ioe); } finally { server.shutdownNow(); } @@ -172,7 +172,7 @@ public void service(final Request request, @Override public void onWritePossible() throws Exception { - LOGGER.log(Level.FINE, "[onWritePossible]"); + LOGGER.debug("[onWritePossible]"); // send CHUNK of data final boolean isWriteMore = sendChunk(); @@ -184,7 +184,7 @@ public void onWritePossible() throws Exception { @Override public void onError(Throwable t) { - LOGGER.log(Level.WARNING, "[onError] ", t); + LOGGER.warn("[onError] ", t); response.setStatus(500, t.getMessage()); complete(true); } diff --git a/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/nonblockinghandler/NonBlockingHttpHandlerSample.java b/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/nonblockinghandler/NonBlockingHttpHandlerSample.java index a88e8a1eef..68acdc4ec9 100644 --- a/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/nonblockinghandler/NonBlockingHttpHandlerSample.java +++ b/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/nonblockinghandler/NonBlockingHttpHandlerSample.java @@ -40,6 +40,10 @@ package org.glassfish.grizzly.samples.httpserver.nonblockinghandler; +import java.io.IOException; +import java.util.concurrent.Future; +import java.util.concurrent.TimeUnit; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; @@ -52,27 +56,22 @@ import org.glassfish.grizzly.http.HttpClientFilter; import org.glassfish.grizzly.http.HttpContent; import org.glassfish.grizzly.http.HttpRequestPacket; +import org.glassfish.grizzly.http.io.NIOReader; +import org.glassfish.grizzly.http.io.NIOWriter; import org.glassfish.grizzly.http.server.HttpHandler; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.server.Request; import org.glassfish.grizzly.http.server.Response; import org.glassfish.grizzly.http.server.ServerConfiguration; -import org.glassfish.grizzly.http.io.NIOReader; -import org.glassfish.grizzly.http.io.NIOWriter; import org.glassfish.grizzly.http.util.Header; import org.glassfish.grizzly.http.util.HeaderValue; import org.glassfish.grizzly.impl.FutureImpl; import org.glassfish.grizzly.impl.SafeFutureImpl; +import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.memory.MemoryManager; import org.glassfish.grizzly.nio.transport.TCPNIOTransport; - -import java.io.IOException; -import java.util.concurrent.Future; -import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; -import org.glassfish.grizzly.memory.Buffers; import org.glassfish.grizzly.nio.transport.TCPNIOTransportBuilder; +import org.slf4j.Logger; /** @@ -126,7 +125,7 @@ public static void main(String[] args) { Client client = new Client(); client.run(); } catch (IOException ioe) { - LOGGER.log(Level.SEVERE, ioe.toString(), ioe); + LOGGER.error(ioe.toString(), ioe); } finally { server.shutdownNow(); } @@ -183,9 +182,9 @@ public void run() throws IOException { System.out.println("\nEchoed POST Data: " + result + '\n'); } catch (Exception e) { if (connection == null) { - LOGGER.log(Level.WARNING, "Connection failed. Server is not listening."); + LOGGER.warn("Connection failed. Server is not listening."); } else { - LOGGER.log(Level.WARNING, "Unexpected error communicating with the server."); + LOGGER.warn("Unexpected error communicating with the server."); } } finally { // Close the client connection diff --git a/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/nonblockinghandler/UploadHttpHandlerSample.java b/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/nonblockinghandler/UploadHttpHandlerSample.java index d9c5a72a66..890c90d6c7 100644 --- a/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/nonblockinghandler/UploadHttpHandlerSample.java +++ b/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/nonblockinghandler/UploadHttpHandlerSample.java @@ -45,18 +45,18 @@ import java.nio.ByteBuffer; import java.nio.channels.FileChannel; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Buffer; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.ReadHandler; +import org.glassfish.grizzly.http.io.NIOInputStream; import org.glassfish.grizzly.http.server.HttpHandler; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.server.Request; import org.glassfish.grizzly.http.server.Response; import org.glassfish.grizzly.http.server.ServerConfiguration; -import org.glassfish.grizzly.http.io.NIOInputStream; import org.glassfish.grizzly.http.util.HttpStatus; +import org.slf4j.Logger; /** * The sample shows how the HttpHandler should be implemented in order to @@ -95,7 +95,7 @@ public static void main(String[] args) { LOGGER.info("Press enter to stop the server..."); System.in.read(); } catch (IOException ioe) { - LOGGER.log(Level.SEVERE, ioe.toString(), ioe); + LOGGER.error(ioe.toString(), ioe); } finally { server.shutdownNow(); } @@ -128,14 +128,14 @@ public void service(final Request request, @Override public void onDataAvailable() throws Exception { - LOGGER.log(Level.FINE, "[onDataAvailable] length: {0}", in.readyData()); + LOGGER.debug("[onDataAvailable] length: {}", in.readyData()); storeAvailableData(in, fileChannel); in.notifyAvailable(this); } @Override public void onError(Throwable t) { - LOGGER.log(Level.WARNING, "[onError]", t); + LOGGER.warn("[onError]", t); response.setStatus(500, t.getMessage()); complete(true); @@ -148,7 +148,7 @@ public void onError(Throwable t) { @Override public void onAllDataRead() throws Exception { - LOGGER.log(Level.FINE, "[onAllDataRead] length: {0}", in.readyData()); + LOGGER.debug("[onAllDataRead] length: {}", in.readyData()); storeAvailableData(in, fileChannel); response.setStatus(HttpStatus.ACCEPTED_202); complete(false); diff --git a/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/priorities/Server.java b/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/priorities/Server.java index 29d9b6dab4..5560f6096f 100644 --- a/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/priorities/Server.java +++ b/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/priorities/Server.java @@ -41,8 +41,7 @@ import java.io.IOException; import java.util.concurrent.ExecutorService; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.HttpHandler; import org.glassfish.grizzly.http.server.HttpServer; @@ -51,6 +50,7 @@ import org.glassfish.grizzly.memory.MemoryManager; import org.glassfish.grizzly.threadpool.GrizzlyExecutorService; import org.glassfish.grizzly.threadpool.ThreadPoolConfig; +import org.slf4j.Logger; /** * Example of HTTP server, which assigns different priorities (thread-pools) @@ -135,7 +135,7 @@ public static void main(String[] args) { System.out.println("The server is running. Press enter to stop..."); System.in.read(); } catch (IOException ioe) { - LOGGER.log(Level.SEVERE, ioe.toString(), ioe); + LOGGER.error(ioe.toString(), ioe); } finally { server.shutdownNow(); // !!! Don't forget to shutdown the custom threads diff --git a/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/secure/Server.java b/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/secure/Server.java index 4048ef11f9..f59ce2c50b 100644 --- a/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/secure/Server.java +++ b/samples/http-server-samples/src/main/java/org/glassfish/grizzly/samples/httpserver/secure/Server.java @@ -42,14 +42,14 @@ import java.io.IOException; import java.net.URL; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.server.NetworkListener; import org.glassfish.grizzly.http.server.ServerConfiguration; import org.glassfish.grizzly.ssl.SSLContextConfigurator; import org.glassfish.grizzly.ssl.SSLEngineConfigurator; +import org.slf4j.Logger; /** * Secured standalone Java HTTP server. @@ -81,7 +81,7 @@ public static void main(String[] args) { System.out.println("The secured server is running.\nhttps://localhost:" + NetworkListener.DEFAULT_NETWORK_PORT + "\nPress enter to stop..."); System.in.read(); } catch (IOException ioe) { - LOGGER.log(Level.SEVERE, ioe.toString(), ioe); + LOGGER.error(ioe.toString(), ioe); } finally { server.shutdownNow(); } diff --git a/samples/portunif/src/main/java/org/glassfish/grizzly/samples/portunif/AddClient.java b/samples/portunif/src/main/java/org/glassfish/grizzly/samples/portunif/AddClient.java index 3c0a8d45f8..f55485b95c 100644 --- a/samples/portunif/src/main/java/org/glassfish/grizzly/samples/portunif/AddClient.java +++ b/samples/portunif/src/main/java/org/glassfish/grizzly/samples/portunif/AddClient.java @@ -45,8 +45,7 @@ import java.io.InputStreamReader; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.GrizzlyFuture; @@ -62,6 +61,7 @@ import org.glassfish.grizzly.samples.portunif.addservice.AddRequestMessage; import org.glassfish.grizzly.samples.portunif.addservice.AddResponseMessage; import org.glassfish.grizzly.utils.Charsets; +import org.slf4j.Logger; /** * Client app, which tests deployed ADD-service. @@ -118,7 +118,7 @@ public static void main(String[] args) throws Exception { value1 = Integer.parseInt(values[0].trim()); value2 = Integer.parseInt(values[1].trim()); } catch (Exception e) { - LOGGER.warning("Bad format, repeat pls"); + LOGGER.warn("Bad format, repeat pls"); continue; } @@ -151,7 +151,7 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException { final AddResponseMessage addResponseMessage = ctx.getMessage(); // do output - LOGGER.log(Level.INFO, "Result={0}", addResponseMessage.getResult()); + LOGGER.info("Result={}", addResponseMessage.getResult()); return ctx.getStopAction(); } diff --git a/samples/portunif/src/main/java/org/glassfish/grizzly/samples/portunif/SubClient.java b/samples/portunif/src/main/java/org/glassfish/grizzly/samples/portunif/SubClient.java index cc9800e544..fa707f5377 100644 --- a/samples/portunif/src/main/java/org/glassfish/grizzly/samples/portunif/SubClient.java +++ b/samples/portunif/src/main/java/org/glassfish/grizzly/samples/portunif/SubClient.java @@ -45,8 +45,7 @@ import java.io.InputStreamReader; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Connection; import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.GrizzlyFuture; @@ -62,6 +61,7 @@ import org.glassfish.grizzly.samples.portunif.subservice.SubRequestMessage; import org.glassfish.grizzly.samples.portunif.subservice.SubResponseMessage; import org.glassfish.grizzly.utils.Charsets; +import org.slf4j.Logger; /** * Client app, which tests deployed SUB-service. @@ -118,7 +118,7 @@ public static void main(String[] args) throws Exception { value1 = Integer.parseInt(values[0].trim()); value2 = Integer.parseInt(values[1].trim()); } catch (Exception e) { - LOGGER.warning("Bad format, repeat pls"); + LOGGER.warn("Bad format, repeat pls"); continue; } @@ -151,7 +151,7 @@ public NextAction handleRead(FilterChainContext ctx) throws IOException { final SubResponseMessage subResponseMessage = ctx.getMessage(); // do output - LOGGER.log(Level.INFO, "Result={0}", subResponseMessage.getResult()); + LOGGER.info("Result={}", subResponseMessage.getResult()); return ctx.getStopAction(); } diff --git a/samples/tls-sni-samples/src/main/java/org/glassfish/grizzly/samples/sni/httpserver/Server.java b/samples/tls-sni-samples/src/main/java/org/glassfish/grizzly/samples/sni/httpserver/Server.java index 820b9a1aa2..47fff68883 100644 --- a/samples/tls-sni-samples/src/main/java/org/glassfish/grizzly/samples/sni/httpserver/Server.java +++ b/samples/tls-sni-samples/src/main/java/org/glassfish/grizzly/samples/sni/httpserver/Server.java @@ -42,8 +42,7 @@ import java.io.IOException; import java.net.URL; -import java.util.logging.Level; -import java.util.logging.Logger; + import org.glassfish.grizzly.Grizzly; import org.glassfish.grizzly.http.server.HttpServer; import org.glassfish.grizzly.http.server.NetworkListener; @@ -51,6 +50,7 @@ import org.glassfish.grizzly.sni.SNIServerConfigResolver; import org.glassfish.grizzly.ssl.SSLContextConfigurator; import org.glassfish.grizzly.ssl.SSLEngineConfigurator; +import org.slf4j.Logger; /** * SNI-aware standalone Java HTTP server. @@ -103,7 +103,7 @@ public static void main(String[] args) { System.out.println("The SNI-aware server is running on port " + NetworkListener.DEFAULT_NETWORK_PORT + "\nPress enter to stop..."); System.in.read(); } catch (IOException ioe) { - LOGGER.log(Level.SEVERE, ioe.toString(), ioe); + LOGGER.error(ioe.toString(), ioe); } finally { server.shutdownNow(); }