Improved logging.
This commit is contained in:
parent
c8184077c7
commit
36e7c41b2f
|
@ -125,4 +125,10 @@ public class HTTP2Stream implements IStream
|
|||
});
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s@%x", getClass().getSimpleName(), hashCode());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,4 +34,10 @@ public abstract class Frame
|
|||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("%s@%x", getClass().getSimpleName(), hashCode());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,9 @@
|
|||
|
||||
package org.eclipse.jetty.http2.frames;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public enum FrameType
|
||||
{
|
||||
DATA(0),
|
||||
|
@ -33,15 +36,26 @@ public enum FrameType
|
|||
ALTSVC(10),
|
||||
BLOCKED(11);
|
||||
|
||||
public static FrameType from(int type)
|
||||
{
|
||||
return Types.types.get(type);
|
||||
}
|
||||
|
||||
private final int type;
|
||||
|
||||
private FrameType(int type)
|
||||
{
|
||||
this.type = type;
|
||||
Types.types.put(type, this);
|
||||
}
|
||||
|
||||
public int getType()
|
||||
{
|
||||
return type;
|
||||
}
|
||||
|
||||
private static class Types
|
||||
{
|
||||
private static final Map<Integer, FrameType> types = new HashMap<>();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -71,6 +71,8 @@ public class Parser
|
|||
|
||||
public boolean parse(ByteBuffer buffer)
|
||||
{
|
||||
LOG.debug("Parsing {}", buffer);
|
||||
|
||||
while (true)
|
||||
{
|
||||
switch (state)
|
||||
|
@ -114,10 +116,14 @@ public class Parser
|
|||
{
|
||||
// The content will be processed asynchronously, stop parsing;
|
||||
// the asynchronous operation will eventually resume parsing.
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Parsed {} frame, asynchronous processing", FrameType.from(type));
|
||||
return true;
|
||||
}
|
||||
case COMPLETE:
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Parsed {} frame, synchronous processing", FrameType.from(type));
|
||||
reset();
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -81,11 +81,11 @@ public class HTTP2ServerConnectionFactory extends AbstractConnectionFactory
|
|||
@Override
|
||||
public Stream.Listener onNewStream(Stream stream, HeadersFrame frame)
|
||||
{
|
||||
LOG.debug("Received {} on {}", frame, stream);
|
||||
LOG.debug("Processing {} on {}", frame, stream);
|
||||
|
||||
HttpTransportOverHTTP2 transport = new HttpTransportOverHTTP2((IStream)stream, frame);
|
||||
HttpInputOverHTTP2 input = new HttpInputOverHTTP2();
|
||||
HttpChannelOverHTTP2 channel = new HttpChannelOverHTTP2(connector, httpConfiguration, endPoint, transport, input);
|
||||
HttpChannelOverHTTP2 channel = new HttpChannelOverHTTP2(connector, httpConfiguration, endPoint, transport, input, stream);
|
||||
stream.setAttribute(CHANNEL_ATTRIBUTE, channel);
|
||||
|
||||
channel.requestHeaders(frame);
|
||||
|
@ -96,6 +96,8 @@ public class HTTP2ServerConnectionFactory extends AbstractConnectionFactory
|
|||
@Override
|
||||
public void onData(Stream stream, DataFrame frame, Callback callback)
|
||||
{
|
||||
LOG.debug("Processing {} on {}", frame, stream);
|
||||
|
||||
HttpChannelOverHTTP2 channel = (HttpChannelOverHTTP2)stream.getAttribute(CHANNEL_ATTRIBUTE);
|
||||
channel.requestContent(frame, callback);
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import org.eclipse.jetty.http.HttpField;
|
|||
import org.eclipse.jetty.http.HttpScheme;
|
||||
import org.eclipse.jetty.http.HttpURI;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.http2.api.Stream;
|
||||
import org.eclipse.jetty.http2.frames.DataFrame;
|
||||
import org.eclipse.jetty.http2.frames.HeadersFrame;
|
||||
import org.eclipse.jetty.http2.hpack.MetaData;
|
||||
|
@ -37,12 +38,18 @@ import org.eclipse.jetty.server.HttpInput;
|
|||
import org.eclipse.jetty.server.HttpTransport;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
public class HttpChannelOverHTTP2 extends HttpChannel<ByteBufferCallback>
|
||||
{
|
||||
public HttpChannelOverHTTP2(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport, HttpInput<ByteBufferCallback> input)
|
||||
private static final Logger LOG = Log.getLogger(HttpChannelOverHTTP2.class);
|
||||
private final Stream stream;
|
||||
|
||||
public HttpChannelOverHTTP2(Connector connector, HttpConfiguration configuration, EndPoint endPoint, HttpTransport transport, HttpInput<ByteBufferCallback> input, Stream stream)
|
||||
{
|
||||
super(connector, configuration, endPoint, transport, input);
|
||||
this.stream = stream;
|
||||
}
|
||||
|
||||
public void requestHeaders(HeadersFrame frame)
|
||||
|
@ -84,6 +91,17 @@ public class HttpChannelOverHTTP2 extends HttpChannel<ByteBufferCallback>
|
|||
messageComplete();
|
||||
}
|
||||
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
StringBuilder headers = new StringBuilder();
|
||||
for (HttpField field : fields)
|
||||
{
|
||||
headers.append(field).append(System.lineSeparator());
|
||||
}
|
||||
LOG.debug("HTTP2 Request #{}:{}{} {} {}{}{}",
|
||||
stream.getId(), System.lineSeparator(), method, uri, version, System.lineSeparator(), headers);
|
||||
}
|
||||
|
||||
// TODO: pending refactoring of HttpChannel API.
|
||||
// Here we "cheat", knowing that headerComplete() will always return true
|
||||
// and that content() and messageComplete() will always return false.
|
||||
|
|
|
@ -23,6 +23,7 @@ import java.util.concurrent.atomic.AtomicBoolean;
|
|||
|
||||
import org.eclipse.jetty.http.HttpGenerator;
|
||||
import org.eclipse.jetty.http.HttpMethod;
|
||||
import org.eclipse.jetty.http.HttpVersion;
|
||||
import org.eclipse.jetty.http2.IStream;
|
||||
import org.eclipse.jetty.http2.frames.DataFrame;
|
||||
import org.eclipse.jetty.http2.frames.HeadersFrame;
|
||||
|
@ -30,9 +31,13 @@ import org.eclipse.jetty.http2.hpack.MetaData;
|
|||
import org.eclipse.jetty.server.HttpTransport;
|
||||
import org.eclipse.jetty.util.BufferUtil;
|
||||
import org.eclipse.jetty.util.Callback;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
|
||||
public class HttpTransportOverHTTP2 implements HttpTransport
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(HttpTransportOverHTTP2.class);
|
||||
|
||||
private final AtomicBoolean commit = new AtomicBoolean();
|
||||
private final IStream stream;
|
||||
private final HeadersFrame request;
|
||||
|
@ -89,6 +94,12 @@ public class HttpTransportOverHTTP2 implements HttpTransport
|
|||
|
||||
private void commit(HttpGenerator.ResponseInfo info, boolean endStream, Callback callback)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("HTTP2 Response #{}:{}{} {}{}{}",
|
||||
stream.getId(), System.lineSeparator(), HttpVersion.HTTP_2_0, info.getStatus(), System.lineSeparator(), info.getHttpFields());
|
||||
}
|
||||
|
||||
MetaData metaData = new MetaData.Response(info.getStatus(), info.getHttpFields());
|
||||
HeadersFrame frame = new HeadersFrame(stream.getId(), metaData, null, endStream);
|
||||
stream.headers(frame, callback);
|
||||
|
@ -97,6 +108,12 @@ public class HttpTransportOverHTTP2 implements HttpTransport
|
|||
@Override
|
||||
public void send(ByteBuffer content, boolean lastContent, Callback callback)
|
||||
{
|
||||
if (LOG.isDebugEnabled())
|
||||
{
|
||||
LOG.debug("HTTP2 Response #{}: {} {}content bytes",
|
||||
stream.getId(), lastContent ? "last " : "", content.remaining());
|
||||
}
|
||||
|
||||
DataFrame frame = new DataFrame(stream.getId(), content, lastContent);
|
||||
stream.data(frame, callback);
|
||||
}
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
|
||||
org.eclipse.jetty.http2.LEVEL=DEBUG
|
Loading…
Reference in New Issue