Make use of a Logger in the SPDY example and simplify it a bit

This commit is contained in:
Norman Maurer 2014-01-21 07:17:40 +01:00
parent 09fdb08fe4
commit 36166a4faa
2 changed files with 13 additions and 18 deletions

View File

@ -22,11 +22,15 @@ import org.eclipse.jetty.npn.NextProtoNego;
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() {
@ -40,23 +44,10 @@ public class SpdyOrHttpHandler extends SpdyOrHttpChooser {
@Override
protected SelectedProtocol getProtocol(SSLEngine engine) {
SpdyServerProvider provider = (SpdyServerProvider) NextProtoNego.get(engine);
String selectedProtocol = provider.getSelectedProtocol();
SelectedProtocol selectedProtocol = provider.getSelectedProtocol();
System.out.println("Selected Protocol is " + (selectedProtocol == null ? "Unknown" : selectedProtocol));
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

View File

@ -18,6 +18,7 @@ package io.netty.example.spdy;
import java.util.Arrays;
import java.util.List;
import io.netty.handler.codec.spdy.SpdyOrHttpChooser;
import org.eclipse.jetty.npn.NextProtoNego.ServerProvider;
/**
@ -53,7 +54,10 @@ public class SpdyServerProvider implements ServerProvider {
selectedProtocol = protocol;
}
public String getSelectedProtocol() {
return selectedProtocol;
public SpdyOrHttpChooser.SelectedProtocol getSelectedProtocol() {
if (selectedProtocol == null) {
return SpdyOrHttpChooser.SelectedProtocol.UNKNOWN;
}
return SpdyOrHttpChooser.SelectedProtocol.protocol(selectedProtocol);
}
}