Improved toString() methods for frames.

This commit is contained in:
Simone Bordet 2014-08-12 23:01:03 +02:00
parent 14dc4fade0
commit a97d4642ab
5 changed files with 39 additions and 19 deletions

View File

@ -18,7 +18,6 @@
package org.eclipse.jetty.http2;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.Collection;
@ -48,7 +47,6 @@ import org.eclipse.jetty.http2.parser.Parser;
import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.util.Atomics;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.log.Log;
@ -271,7 +269,7 @@ public abstract class HTTP2Session implements ISession, Parser.Listener
{
if (LOG.isDebugEnabled())
{
String reason = tryConvertPayload(frame.getPayload());
String reason = frame.tryConvertPayload();
if (LOG.isDebugEnabled())
LOG.debug("Received {}: {}/'{}'", frame.getType(), frame.getError(), reason);
}
@ -283,21 +281,6 @@ public abstract class HTTP2Session implements ISession, Parser.Listener
return false;
}
private String tryConvertPayload(byte[] payload)
{
if (payload == null)
return "";
ByteBuffer buffer = BufferUtil.toBuffer(payload);
try
{
return BufferUtil.toUTF8String(buffer);
}
catch (Throwable x)
{
return BufferUtil.toDetailString(buffer);
}
}
@Override
public boolean onWindowUpdate(WindowUpdateFrame frame)
{

View File

@ -18,6 +18,10 @@
package org.eclipse.jetty.http2.frames;
import java.nio.ByteBuffer;
import org.eclipse.jetty.util.BufferUtil;
public class GoAwayFrame extends Frame
{
private final int lastStreamId;
@ -46,4 +50,25 @@ public class GoAwayFrame extends Frame
{
return payload;
}
public String tryConvertPayload()
{
if (payload == null)
return "";
ByteBuffer buffer = BufferUtil.toBuffer(payload);
try
{
return BufferUtil.toUTF8String(buffer);
}
catch (Throwable x)
{
return BufferUtil.toDetailString(buffer);
}
}
@Override
public String toString()
{
return String.format("%s,%d/%s", super.toString(), error, tryConvertPayload());
}
}

View File

@ -39,4 +39,10 @@ public class ResetFrame extends Frame
{
return error;
}
@Override
public String toString()
{
return String.format("%s#%d,error=%d", super.toString(), streamId, error);
}
}

View File

@ -47,4 +47,10 @@ public class SettingsFrame extends Frame
{
return reply;
}
@Override
public String toString()
{
return String.format("%s,reply=%b:%s", super.toString(), reply, settings);
}
}

View File

@ -43,6 +43,6 @@ public class WindowUpdateFrame extends Frame
@Override
public String toString()
{
return String.format("%s{delta=%d}", super.toString(), windowDelta);
return String.format("%s,delta=%d", super.toString(), windowDelta);
}
}