Updated Branches: refs/heads/trunk 7a6e3db00 -> 458a1a2f7
FLUME-2036. Make hostname optional for HTTPSource. (Hari Shreedharan via Mike Percy) Project: http://git-wip-us.apache.org/repos/asf/flume/repo Commit: http://git-wip-us.apache.org/repos/asf/flume/commit/458a1a2f Tree: http://git-wip-us.apache.org/repos/asf/flume/tree/458a1a2f Diff: http://git-wip-us.apache.org/repos/asf/flume/diff/458a1a2f Branch: refs/heads/trunk Commit: 458a1a2f758fa03b56c46246f830354151089c16 Parents: 7a6e3db Author: Mike Percy <[email protected]> Authored: Wed May 8 15:19:29 2013 -0700 Committer: Mike Percy <[email protected]> Committed: Wed May 8 15:19:29 2013 -0700 ---------------------------------------------------------------------- .../org/apache/flume/source/http/HTTPSource.java | 27 ++++++-------- .../http/HTTPSourceConfigurationConstants.java | 4 ++- flume-ng-doc/sphinx/FlumeUserGuide.rst | 1 + 3 files changed, 16 insertions(+), 16 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/flume/blob/458a1a2f/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java ---------------------------------------------------------------------- diff --git a/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java b/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java index a96fc0d..a4c3eb3 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java +++ b/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java @@ -37,6 +37,7 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.util.ArrayList; +import java.util.Collections; import java.util.List; import java.util.Map; @@ -89,12 +90,12 @@ public class HTTPSource extends AbstractSource implements public void configure(Context context) { try { port = context.getInteger(HTTPSourceConfigurationConstants.CONFIG_PORT); - checkPort(); - host = context.getString(HTTPSourceConfigurationConstants.CONFIG_HOST); - checkHost(); + host = context.getString(HTTPSourceConfigurationConstants.CONFIG_BIND, + HTTPSourceConfigurationConstants.DEFAULT_BIND); + checkHostAndPort(); String handlerClassName = context.getString( HTTPSourceConfigurationConstants.CONFIG_HANDLER, - HTTPSourceConfigurationConstants.DEFAULT_HANDLER); + HTTPSourceConfigurationConstants.DEFAULT_HANDLER).trim(); @SuppressWarnings("unchecked") Class<? extends HTTPSourceHandler> clazz = (Class<? extends HTTPSourceHandler>) @@ -119,14 +120,15 @@ public class HTTPSource extends AbstractSource implements } } - private void checkHost() { - Preconditions.checkNotNull(host, "HTTPSource requires a hostname to be" - + "specified"); - } + private void checkHostAndPort() { + Preconditions.checkState(host != null && !host.isEmpty(), + "HTTPSource hostname specified is empty"); + Preconditions.checkNotNull(port, "HTTPSource requires a port number to be" + + " specified"); + } @Override public void start() { - checkPort(); Preconditions.checkState(srv == null, "Running HTTP Server found in source: " + getName() + " before I started one." @@ -162,11 +164,6 @@ public class HTTPSource extends AbstractSource implements } } - private void checkPort() { - Preconditions.checkNotNull(port, "HTTPSource requires a port number to be" - + "specified"); - } - private class FlumeHTTPServlet extends HttpServlet { private static final long serialVersionUID = 4891924863218790344L; @@ -174,7 +171,7 @@ public class HTTPSource extends AbstractSource implements @Override public void doPost(HttpServletRequest request, HttpServletResponse response) throws IOException { - List<Event> events = new ArrayList<Event>(0); //create empty list + List<Event> events = Collections.emptyList(); //create empty list try { events = handler.getEvents(request); } catch (HTTPBadRequestException ex) { http://git-wip-us.apache.org/repos/asf/flume/blob/458a1a2f/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSourceConfigurationConstants.java ---------------------------------------------------------------------- diff --git a/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSourceConfigurationConstants.java b/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSourceConfigurationConstants.java index e7b3c7a..f547e0f 100644 --- a/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSourceConfigurationConstants.java +++ b/flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSourceConfigurationConstants.java @@ -27,7 +27,9 @@ public class HTTPSourceConfigurationConstants { public static final String CONFIG_HANDLER = "handler"; public static final String CONFIG_HANDLER_PREFIX = CONFIG_HANDLER + "."; - public static final String CONFIG_HOST = "host"; + public static final String CONFIG_BIND = "bind"; + + public static final String DEFAULT_BIND = "0.0.0.0"; public static final String DEFAULT_HANDLER = "org.apache.flume.source.http.JSONHandler"; http://git-wip-us.apache.org/repos/asf/flume/blob/458a1a2f/flume-ng-doc/sphinx/FlumeUserGuide.rst ---------------------------------------------------------------------- diff --git a/flume-ng-doc/sphinx/FlumeUserGuide.rst b/flume-ng-doc/sphinx/FlumeUserGuide.rst index 83e96f5..d09a3f7 100644 --- a/flume-ng-doc/sphinx/FlumeUserGuide.rst +++ b/flume-ng-doc/sphinx/FlumeUserGuide.rst @@ -1168,6 +1168,7 @@ Property Name Default Description ============== ============================================ ==================================================================== **type** The component type name, needs to be ``http`` **port** -- The port the source should bind to. +bind 0.0.0.0 The hostname or IP address to listen on handler ``org.apache.flume.source.http.JSONHandler`` The FQCN of the handler class. handler.* -- Config parameters for the handler selector.type replicating replicating or multiplexing
