Skip to content

Commit

Permalink
Make use of a Logger in the SPDY example and simplify it a bit
Browse files Browse the repository at this point in the history
  • Loading branch information
Norman Maurer committed Jan 21, 2014
1 parent 09fdb08 commit 36166a4
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 18 deletions.
23 changes: 7 additions & 16 deletions example/src/main/java/io/netty/example/spdy/SpdyOrHttpHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,15 @@
import io.netty.channel.ChannelHandler;
import io.netty.handler.codec.spdy.SpdyOrHttpChooser;

import java.util.logging.Logger;

/**
* Negotiates with the browser if SPDY or HTTP is going to be used. Once decided, the Netty pipeline is setup with
* the correct handlers for the selected protocol.
*/
public class SpdyOrHttpHandler extends SpdyOrHttpChooser {
private static final Logger logger = Logger.getLogger(
SpdyOrHttpHandler.class.getName());
private static final int MAX_CONTENT_LENGTH = 1024 * 100;

public SpdyOrHttpHandler() {
Expand All @@ -40,23 +44,10 @@ public SpdyOrHttpHandler(int maxSpdyContentLength, int maxHttpContentLength) {
@Override
protected SelectedProtocol getProtocol(SSLEngine engine) {
SpdyServerProvider provider = (SpdyServerProvider) NextProtoNego.get(engine);
String selectedProtocol = provider.getSelectedProtocol();

System.out.println("Selected Protocol is " + (selectedProtocol == null ? "Unknown" : selectedProtocol));
SelectedProtocol selectedProtocol = provider.getSelectedProtocol();

if (selectedProtocol == null) {
return SpdyOrHttpChooser.SelectedProtocol.UNKNOWN;
} else if (selectedProtocol.equalsIgnoreCase("spdy/3.1")) {
return SpdyOrHttpChooser.SelectedProtocol.SPDY_3_1;
} else if (selectedProtocol.equalsIgnoreCase("spdy/3")) {
return SpdyOrHttpChooser.SelectedProtocol.SPDY_3;
} else if (selectedProtocol.equalsIgnoreCase("http/1.1")) {
return SpdyOrHttpChooser.SelectedProtocol.HTTP_1_1;
} else if (selectedProtocol.equalsIgnoreCase("http/1.0")) {
return SpdyOrHttpChooser.SelectedProtocol.HTTP_1_0;
} else {
return SpdyOrHttpChooser.SelectedProtocol.UNKNOWN;
}
logger.info("Selected Protocol is " + selectedProtocol);
return selectedProtocol;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import java.util.Arrays;
import java.util.List;

import io.netty.handler.codec.spdy.SpdyOrHttpChooser;
import org.eclipse.jetty.npn.NextProtoNego.ServerProvider;

/**
Expand Down Expand Up @@ -53,7 +54,10 @@ public void protocolSelected(String protocol) {
selectedProtocol = protocol;
}

public String getSelectedProtocol() {
return selectedProtocol;
public SpdyOrHttpChooser.SelectedProtocol getSelectedProtocol() {
if (selectedProtocol == null) {
return SpdyOrHttpChooser.SelectedProtocol.UNKNOWN;
}
return SpdyOrHttpChooser.SelectedProtocol.protocol(selectedProtocol);
}
}

0 comments on commit 36166a4

Please sign in to comment.