Skip to content

Commit

Permalink
Do NOT use InternalLogger in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
trustin committed Feb 11, 2013
1 parent b4f4b95 commit 3f16f0b
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder;
import io.netty.handler.codec.http.multipart.HttpPostRequestEncoder.ErrorDataEncoderException;
import io.netty.handler.codec.http.multipart.InterfaceHttpData;
import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;

import java.io.BufferedWriter;
import java.io.File;
Expand All @@ -44,13 +42,15 @@
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map.Entry;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* This class is meant to be run against {@link HttpUploadServer}.
*/
public class HttpUploadClient {

private static final InternalLogger logger = InternalLoggerFactory.getInstance(HttpUploadClient.class);
private static final Logger logger = Logger.getLogger(HttpUploadClient.class.getName());

private final String baseUri;
private final String filePath;
Expand All @@ -75,7 +75,7 @@ public void run() throws Exception {
try {
uriSimple = new URI(postSimple);
} catch (URISyntaxException e) {
logger.error("Invalid URI syntax" + e.getCause());
logger.log(Level.WARNING, "Invalid URI syntax", e);
return;
}
String scheme = uriSimple.getScheme() == null ? "http" : uriSimple.getScheme();
Expand All @@ -90,7 +90,7 @@ public void run() throws Exception {
}

if (!"http".equalsIgnoreCase(scheme) && !"https".equalsIgnoreCase(scheme)) {
logger.error("Only HTTP(S) is supported.");
logger.log(Level.WARNING, "Only HTTP(S) is supported.");
return;
}

Expand All @@ -100,12 +100,12 @@ public void run() throws Exception {
try {
uriFile = new URI(postFile);
} catch (URISyntaxException e) {
logger.error("Error: " + e.getMessage());
logger.log(Level.WARNING, "Error: ", e);
return;
}
File file = new File(filePath);
if (!file.canRead()) {
logger.error("A correct path is needed");
logger.log(Level.WARNING, "A correct path is needed");
return;
}

Expand Down Expand Up @@ -172,7 +172,7 @@ private static List<Entry<String, String>> formGet(Bootstrap bootstrap, String h
try {
uriGet = new URI(encoder.toString());
} catch (URISyntaxException e) {
logger.error("Error: " + e.getMessage());
logger.log(Level.WARNING, "Error: ", e);
return null;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@
import io.netty.handler.codec.http.HttpResponse;
import io.netty.handler.codec.http.LastHttpContent;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;

import java.util.logging.Logger;

/**
* Handler that just dumps the contents of the response from the server
*/
public class HttpUploadClientHandler extends ChannelInboundMessageHandlerAdapter<Object> {

private static final InternalLogger logger = InternalLoggerFactory.getInstance(HttpUploadClientHandler.class);
private static final Logger logger = Logger.getLogger(HttpUploadClientHandler.class.getName());

private boolean readingChunks;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@
import io.netty.handler.codec.http.multipart.InterfaceHttpData;
import io.netty.handler.codec.http.multipart.InterfaceHttpData.HttpDataType;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;

import java.io.IOException;
import java.net.URI;
Expand All @@ -56,13 +54,15 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

import static io.netty.buffer.Unpooled.*;
import static io.netty.handler.codec.http.HttpHeaders.Names.*;

public class HttpUploadServerHandler extends ChannelInboundMessageHandlerAdapter<Object> {

private static final InternalLogger logger = InternalLoggerFactory.getInstance(HttpUploadServerHandler.class);
private static final Logger logger = Logger.getLogger(HttpUploadServerHandler.class.getName());

private HttpRequest request;

Expand Down Expand Up @@ -422,7 +422,7 @@ private void writeMenu(ChannelHandlerContext ctx) {

@Override
public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
logger.error(responseContent.toString(), cause);
logger.log(Level.WARNING, responseContent.toString(), cause);
ctx.channel().close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;

import java.util.logging.Level;
import java.util.logging.Logger;

import static io.netty.handler.codec.http.HttpHeaders.*;
import static io.netty.handler.codec.http.HttpMethod.*;
Expand All @@ -46,7 +47,7 @@
* Handles handshakes and messages
*/
public class AutobahnServerHandler extends ChannelInboundMessageHandlerAdapter<Object> {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(AutobahnServerHandler.class);
private static final Logger logger = Logger.getLogger(AutobahnServerHandler.class.getName());

private WebSocketServerHandshaker handshaker;

Expand Down Expand Up @@ -84,9 +85,9 @@ private void handleHttpRequest(ChannelHandlerContext ctx, FullHttpRequest req) t
}

private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame frame) {
if (logger.isDebugEnabled()) {
logger.debug(String.format("Channel %s received %s", ctx.channel().id(), frame.getClass()
.getSimpleName()));
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format(
"Channel %s received %s", ctx.channel().id(), frame.getClass().getSimpleName()));
}

if (frame instanceof CloseWebSocketFrame) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,9 @@
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;

import java.util.logging.Level;
import java.util.logging.Logger;

import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaders.*;
Expand All @@ -45,7 +46,7 @@
* Handles handshakes and messages
*/
public class WebSocketServerHandler extends ChannelInboundMessageHandlerAdapter<Object> {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketServerHandler.class);
private static final Logger logger = Logger.getLogger(WebSocketServerHandler.class.getName());

private static final String WEBSOCKET_PATH = "/websocket";

Expand Down Expand Up @@ -121,8 +122,8 @@ private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame fram

// Send the uppercase string back.
String request = ((TextWebSocketFrame) frame).text();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Channel %s received %s", ctx.channel().id(), request));
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format("Channel %s received %s", ctx.channel().id(), request));
}
ctx.channel().write(new TextWebSocketFrame(request.toUpperCase()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshaker;
import io.netty.handler.codec.http.websocketx.WebSocketServerHandshakerFactory;
import io.netty.util.CharsetUtil;
import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;

import java.util.logging.Level;
import java.util.logging.Logger;

import static io.netty.handler.codec.http.HttpHeaders.Names.*;
import static io.netty.handler.codec.http.HttpHeaders.*;
Expand All @@ -46,7 +47,7 @@
* Handles handshakes and messages
*/
public class WebSocketSslServerHandler extends ChannelInboundMessageHandlerAdapter<Object> {
private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketSslServerHandler.class);
private static final Logger logger = Logger.getLogger(WebSocketSslServerHandler.class.getName());

private static final String WEBSOCKET_PATH = "/websocket";

Expand Down Expand Up @@ -123,8 +124,8 @@ private void handleWebSocketFrame(ChannelHandlerContext ctx, WebSocketFrame fram

// Send the uppercase string back.
String request = ((TextWebSocketFrame) frame).text();
if (logger.isDebugEnabled()) {
logger.debug(String.format("Channel %s received %s", ctx.channel().id(), request));
if (logger.isLoggable(Level.FINE)) {
logger.fine(String.format("Channel %s received %s", ctx.channel().id(), request));
}
ctx.channel().write(new TextWebSocketFrame(request.toUpperCase()));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,20 @@
*/
package io.netty.example.http.websocketx.sslserver;

import io.netty.util.internal.InternalLogger;
import io.netty.util.internal.InternalLoggerFactory;

import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import java.io.FileInputStream;
import java.security.KeyStore;
import java.security.Security;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Creates a {@link SSLContext} for just server certificates.
*/
public final class WebSocketSslServerSslContext {

private static final InternalLogger logger = InternalLoggerFactory.getInstance(WebSocketSslServerSslContext.class);
private static final Logger logger = Logger.getLogger(WebSocketSslServerSslContext.class.getName());
private static final String PROTOCOL = "TLS";
private final SSLContext _serverContext;

Expand Down Expand Up @@ -83,9 +82,7 @@ private WebSocketSslServerSslContext() {
throw new Error("Failed to initialize the server-side SSLContext", e);
}
} catch (Exception ex) {
if (logger.isErrorEnabled()) {
logger.error("Error initializing SslContextManager. " + ex.getMessage(), ex);
}
logger.log(Level.WARNING, "Error initializing SslContextManager.", ex);
System.exit(1);
} finally {
_serverContext = serverContext;
Expand Down

0 comments on commit 3f16f0b

Please sign in to comment.