Review Board 1.7.22


Fix for Flume-2109, with review comments incorporated

Review Request #12440 - Created July 10, 2013 and discarded

Ashish Paliwal
FLUME-2109
Reviewers
Flume
flume-git
Flume patch to support HTTPS support. Review comments incorporated. Now only one mode shall be enabled either normal HTTP or HTTPS.
Unit test case added to verify SSL functionality.
flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java
Revision c90f067 New Change
[20] 26 lines
[+20]
27
import org.apache.flume.instrumentation.SourceCounter;
27
import org.apache.flume.instrumentation.SourceCounter;
28
import org.apache.flume.source.AbstractSource;
28
import org.apache.flume.source.AbstractSource;
29
import org.mortbay.jetty.Connector;
29
import org.mortbay.jetty.Connector;
30
import org.mortbay.jetty.Server;
30
import org.mortbay.jetty.Server;
31
import org.mortbay.jetty.bio.SocketConnector;
31
import org.mortbay.jetty.bio.SocketConnector;

    
   
32
import org.mortbay.jetty.security.SslSocketConnector;
32
import org.mortbay.jetty.servlet.ServletHolder;
33
import org.mortbay.jetty.servlet.ServletHolder;
33
import org.slf4j.Logger;
34
import org.slf4j.Logger;
34
import org.slf4j.LoggerFactory;
35
import org.slf4j.LoggerFactory;
35

    
   
36

   
36
import javax.servlet.http.HttpServlet;
37
import javax.servlet.http.HttpServlet;
[+20] [20] 49 lines
[+20] [+] public class HTTPSource extends AbstractSource implements
86
  private volatile Server srv;
87
  private volatile Server srv;
87
  private volatile String host;
88
  private volatile String host;
88
  private HTTPSourceHandler handler;
89
  private HTTPSourceHandler handler;
89
  private SourceCounter sourceCounter;
90
  private SourceCounter sourceCounter;
90

    
   
91

   

    
   
92
  // SSL configuration variable

    
   
93
  private volatile Integer sslPort;

    
   
94
  private volatile String keyStorePath;

    
   
95
  private volatile String keyStorePassword;

    
   
96
  private volatile Boolean sslEnabled;

    
   
97

   

    
   
98

   
91
  @Override
99
  @Override
92
  public void configure(Context context) {
100
  public void configure(Context context) {
93
    try {
101
    try {

    
   
102
      // SSL related config

    
   
103
      sslEnabled = context.getBoolean(HTTPSourceConfigurationConstants.SSL_ENABLED, false);

    
   
104

   
94
      port = context.getInteger(HTTPSourceConfigurationConstants.CONFIG_PORT);
105
      port = context.getInteger(HTTPSourceConfigurationConstants.CONFIG_PORT);
95
      host = context.getString(HTTPSourceConfigurationConstants.CONFIG_BIND,
106
      host = context.getString(HTTPSourceConfigurationConstants.CONFIG_BIND,
96
        HTTPSourceConfigurationConstants.DEFAULT_BIND);
107
        HTTPSourceConfigurationConstants.DEFAULT_BIND);
97
      checkHostAndPort();
108

   

    
   
109
      Preconditions.checkState(host != null && !host.isEmpty(),

    
   
110
                "HTTPSource hostname specified is empty");

    
   
111
      // verify port only if its not ssl

    
   
112
      if(!sslEnabled) {

    
   
113
        Preconditions.checkNotNull(port, "HTTPSource requires a port number to be"

    
   
114
                + " specified");

    
   
115
      }

    
   
116

   
98
      String handlerClassName = context.getString(
117
      String handlerClassName = context.getString(
99
              HTTPSourceConfigurationConstants.CONFIG_HANDLER,
118
              HTTPSourceConfigurationConstants.CONFIG_HANDLER,
100
              HTTPSourceConfigurationConstants.DEFAULT_HANDLER).trim();
119
              HTTPSourceConfigurationConstants.DEFAULT_HANDLER).trim();

    
   
120

   

    
   
121
      if(sslEnabled) {

    
   
122
        LOG.debug("SSL configuration enabled");

    
   
123
        sslPort = context.getInteger(HTTPSourceConfigurationConstants.SSL_PORT);

    
   
124
        Preconditions.checkArgument(sslPort != null && sslPort > 0, "SSL Port cannot be null or less than 0" );

    
   
125
        keyStorePath = context.getString(HTTPSourceConfigurationConstants.SSL_KEYSTORE);

    
   
126
        Preconditions.checkArgument(keyStorePath != null && !keyStorePath.isEmpty(),

    
   
127
                                        "Keystore is required for SSL Conifguration" );

    
   
128
        keyStorePassword = context.getString(HTTPSourceConfigurationConstants.SSL_KEYSTORE_PASSWORD);

    
   
129
        Preconditions.checkArgument(keyStorePassword != null, "Keystore password is required for SSL Configuration");

    
   
130
      }

    
   
131

   
101
      @SuppressWarnings("unchecked")
132
      @SuppressWarnings("unchecked")
102
      Class<? extends HTTPSourceHandler> clazz =
133
      Class<? extends HTTPSourceHandler> clazz =
103
              (Class<? extends HTTPSourceHandler>)
134
              (Class<? extends HTTPSourceHandler>)
104
              Class.forName(handlerClassName);
135
              Class.forName(handlerClassName);
105
      handler = clazz.getDeclaredConstructor().newInstance();
136
      handler = clazz.getDeclaredConstructor().newInstance();
[+20] [20] 31 lines
[+20] [+] private void checkHostAndPort() {
137
    Preconditions.checkState(srv == null,
168
    Preconditions.checkState(srv == null,
138
            "Running HTTP Server found in source: " + getName()
169
            "Running HTTP Server found in source: " + getName()
139
            + " before I started one."
170
            + " before I started one."
140
            + "Will not attempt to start.");
171
            + "Will not attempt to start.");
141
    srv = new Server();
172
    srv = new Server();

    
   
173

   

    
   
174
    // Connector Array

    
   
175
    Connector[] connectors = new Connector[1];

    
   
176

   

    
   
177

   

    
   
178
    if(sslEnabled) {

    
   
179
      SslSocketConnector sslSocketConnector = new SslSocketConnector();

    
   
180
      sslSocketConnector.setKeystore(keyStorePath);

    
   
181
      sslSocketConnector.setKeyPassword(keyStorePassword);

    
   
182
      sslSocketConnector.setPort(sslPort);

    
   
183
      connectors[0] = sslSocketConnector;

    
   
184
    } else {
142
    SocketConnector connector = new SocketConnector();
185
        SocketConnector connector = new SocketConnector();
143
    connector.setPort(port);
186
        connector.setPort(port);
144
    connector.setHost(host);
187
        connector.setHost(host);
145
    srv.setConnectors(new Connector[] { connector });
188
        connectors[0] = connector;

    
   
189
    }

    
   
190

   

    
   
191
    srv.setConnectors(connectors);
146
    try {
192
    try {
147
      org.mortbay.jetty.servlet.Context root =
193
      org.mortbay.jetty.servlet.Context root =
148
              new org.mortbay.jetty.servlet.Context(
194
              new org.mortbay.jetty.servlet.Context(
149
              srv, "/", org.mortbay.jetty.servlet.Context.SESSIONS);
195
              srv, "/", org.mortbay.jetty.servlet.Context.SESSIONS);
150
      root.addServlet(new ServletHolder(new FlumeHTTPServlet()), "/");
196
      root.addServlet(new ServletHolder(new FlumeHTTPServlet()), "/");
[+20] [20] 80 lines
flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSourceConfigurationConstants.java
Revision f547e0f New Change
 
flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
Revision 8952db3 New Change
 
flume-ng-doc/sphinx/FlumeUserGuide.rst
Revision 63cad21 New Change
 
  1. flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java: Loading...
  2. flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSourceConfigurationConstants.java: Loading...
  3. flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java: Loading...
  4. flume-ng-doc/sphinx/FlumeUserGuide.rst: Loading...