From 2a765afdc63c12c3371c1defc73c88eaf948842f Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Wed, 4 Nov 2015 10:43:14 +0100 Subject: [PATCH] Improved javadocs and logging. --- .../client/http/HttpConnectionOverFCGI.java | 2 +- .../parser/BeginRequestContentParser.java | 10 ++++++ .../jetty/fcgi/parser/HeaderParser.java | 21 +++++++++++ .../fcgi/parser/ParamsContentParser.java | 35 ++++++++++++++++++- .../org/eclipse/jetty/fcgi/parser/Parser.java | 10 ++++++ .../fcgi/parser/ResponseContentParser.java | 10 +++--- .../fcgi/parser/StreamContentParser.java | 4 +-- 7 files changed, 83 insertions(+), 9 deletions(-) diff --git a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/client/http/HttpConnectionOverFCGI.java b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/client/http/HttpConnectionOverFCGI.java index 4be9cbf1960..4d9691de506 100644 --- a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/client/http/HttpConnectionOverFCGI.java +++ b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/client/http/HttpConnectionOverFCGI.java @@ -181,7 +181,7 @@ public class HttpConnectionOverFCGI extends AbstractConnection implements Connec if (channels.isEmpty()) close(); else - failAndClose(new EOFException()); + failAndClose(new EOFException(String.valueOf(getEndPoint()))); } @Override diff --git a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/BeginRequestContentParser.java b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/BeginRequestContentParser.java index 2367fb65fb8..912f4f8140a 100644 --- a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/BeginRequestContentParser.java +++ b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/BeginRequestContentParser.java @@ -22,6 +22,16 @@ import java.nio.ByteBuffer; import org.eclipse.jetty.fcgi.FCGI; +/** + *

Parser for the BEGIN_REQUEST frame body.

+ *
+ * struct begin_request_body {
+ *     ushort role;
+ *     ubyte flags;
+ *     ubyte[5] reserved;
+ * }
+ * 
+ */ public class BeginRequestContentParser extends ContentParser { private final ServerParser.Listener listener; diff --git a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/HeaderParser.java b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/HeaderParser.java index 078105a9f37..7d431125694 100644 --- a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/HeaderParser.java +++ b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/HeaderParser.java @@ -21,9 +21,28 @@ package org.eclipse.jetty.fcgi.parser; import java.nio.ByteBuffer; import org.eclipse.jetty.fcgi.FCGI; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; +/** + *

Parser for FastCGI frame headers.

+ *
+ * struct frame_header {
+ *     ubyte version;
+ *     ubyte type;
+ *     ushort requestId;
+ *     ushort contentLength;
+ *     ubyte paddingLength;
+ *     ubyte reserved;
+ * }
+ * 
+ * + * @see Parser + */ public class HeaderParser { + private static final Logger LOG = Log.getLogger(Parser.class); + private State state = State.VERSION; private int cursor; private int version; @@ -109,6 +128,8 @@ public class HeaderParser case RESERVED: { buffer.get(); + if (LOG.isDebugEnabled()) + LOG.debug("Parsed request {} header {} length={}", getRequest(), getFrameType(), getContentLength()); return true; } default: diff --git a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/ParamsContentParser.java b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/ParamsContentParser.java index 4678ad5ebe6..dcf34fefc8a 100644 --- a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/ParamsContentParser.java +++ b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/ParamsContentParser.java @@ -20,11 +20,44 @@ package org.eclipse.jetty.fcgi.parser; import java.nio.ByteBuffer; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import org.eclipse.jetty.http.HttpField; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; +/** + *

Parser for the PARAMS frame body.

+ *
+ * struct small_name_small_value_params_body {
+ *     ubyte nameLength;
+ *     ubyte valueLength;
+ *     ubyte[] nameBytes;
+ *     ubyte[] valueBytes;
+ * }
+ *
+ * struct small_name_large_value_params_body {
+ *     ubyte nameLength;
+ *     uint valueLength;
+ *     ubyte[] nameBytes;
+ *     ubyte[] valueBytes;
+ * }
+ *
+ * struct large_name_small_value_params_body {
+ *     uint nameLength;
+ *     ubyte valueLength;
+ *     ubyte[] nameBytes;
+ *     ubyte[] valueBytes;
+ * }
+ *
+ * struct large_name_large_value_params_body {
+ *     uint nameLength;
+ *     uint valueLength;
+ *     ubyte[] nameBytes;
+ *     ubyte[] valueBytes;
+ * }
+ * 
+ */ public class ParamsContentParser extends ContentParser { private static final Logger LOG = Log.getLogger(ParamsContentParser.class); @@ -179,7 +212,7 @@ public class ParamsContentParser extends ContentParser } case PARAM: { - Charset utf8 = Charset.forName("UTF-8"); + Charset utf8 = StandardCharsets.UTF_8; onParam(new String(nameBytes, utf8), new String(valueBytes, utf8)); partialReset(); if (length == 0) diff --git a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/Parser.java b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/Parser.java index 402f3a48970..be2ac480c6a 100644 --- a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/Parser.java +++ b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/Parser.java @@ -22,6 +22,8 @@ import java.nio.ByteBuffer; import org.eclipse.jetty.fcgi.FCGI; import org.eclipse.jetty.http.HttpField; +import org.eclipse.jetty.util.log.Log; +import org.eclipse.jetty.util.log.Logger; /** *

The FastCGI protocol exchanges frames.

@@ -39,9 +41,14 @@ import org.eclipse.jetty.http.HttpField; * *

Depending on the {@code type}, the content may have a different format, * so there are specialized content parsers.

+ * + * @see HeaderParser + * @see ContentParser */ public abstract class Parser { + private static final Logger LOG = Log.getLogger(Parser.class); + protected final HeaderParser headerParser = new HeaderParser(); private State state = State.HEADER; private int padding; @@ -73,6 +80,9 @@ public abstract class Parser else { ContentParser.Result result = contentParser.parse(buffer); + if (LOG.isDebugEnabled()) + LOG.debug("Parsed request {} content {} result={}", headerParser.getRequest(), headerParser.getFrameType(), result); + if (result == ContentParser.Result.PENDING) { // Not enough data, signal to read/parse more. diff --git a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/ResponseContentParser.java b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/ResponseContentParser.java index def4394cc17..6d0fefae64f 100644 --- a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/ResponseContentParser.java +++ b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/ResponseContentParser.java @@ -35,8 +35,8 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; /** - *

The parser for STDOUT type frames.

- *

STDOUT frames contain both the HTTP headers (but not the response line) + *

The parser for STDOUT type frame bodies.

+ *

STDOUT frame bodies contain both the HTTP headers (but not the response line) * and the HTTP content (either Content-Length delimited or chunked).

*

For this reason, a special HTTP parser is used to parse the frames body. * This special HTTP parser is configured to skip the response line, and to @@ -99,12 +99,12 @@ public class ResponseContentParser extends StreamContentParser public boolean parse(ByteBuffer buffer) { - if (LOG.isDebugEnabled()) - LOG.debug("Response {} {} content {} {}", request, FCGI.StreamType.STD_OUT, state, buffer); - int remaining = buffer.remaining(); while (remaining > 0) { + if (LOG.isDebugEnabled()) + LOG.debug("Response {} {}, state {} {}", request, FCGI.StreamType.STD_OUT, state, buffer); + switch (state) { case HEADERS: diff --git a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/StreamContentParser.java b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/StreamContentParser.java index ae7f7bc0419..70602a626a7 100644 --- a/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/StreamContentParser.java +++ b/jetty-fcgi/fcgi-client/src/main/java/org/eclipse/jetty/fcgi/parser/StreamContentParser.java @@ -25,8 +25,8 @@ import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; /** - *

A stream content parser parses frames of type STDIN, STDOUT and STDERR.

- *

STDOUT frames are handled specially by {@link ResponseContentParser}. + *

A stream content parser parses frame bodies of type STDIN, STDOUT and STDERR.

+ *

STDOUT frame bodies are handled specially by {@link ResponseContentParser}. */ public class StreamContentParser extends ContentParser {