Review Board 1.7.22


FLUME-2200. HTTP Source should be able to use "port" parameter if SSL is enabled

Review Request #14444 - Created Oct. 2, 2013 and submitted

Hari Shreedharan
FLUME-2200
Reviewers
Flume
flume-git
Both normal and SSL should use "port" instead of having separate parameters for each.
All unit tests pass with updated parameter.
flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSource.java
Revision 84ee33b New Change
[20] 35 lines
[+20]
36

    
   
36

   
37
import javax.servlet.http.HttpServlet;
37
import javax.servlet.http.HttpServlet;
38
import javax.servlet.http.HttpServletRequest;
38
import javax.servlet.http.HttpServletRequest;
39
import javax.servlet.http.HttpServletResponse;
39
import javax.servlet.http.HttpServletResponse;
40
import java.io.IOException;
40
import java.io.IOException;
41
import java.util.ArrayList;

   
42
import java.util.Collections;
41
import java.util.Collections;
43
import java.util.List;
42
import java.util.List;
44
import java.util.Map;
43
import java.util.Map;
45

    
   
44

   
46
/**
45
/**
[+20] [20] 41 lines
[+20] [+] public class HTTPSource extends AbstractSource implements
88
  private volatile String host;
87
  private volatile String host;
89
  private HTTPSourceHandler handler;
88
  private HTTPSourceHandler handler;
90
  private SourceCounter sourceCounter;
89
  private SourceCounter sourceCounter;
91

    
   
90

   
92
  // SSL configuration variable
91
  // SSL configuration variable
93
  private volatile Integer sslPort;

   
94
  private volatile String keyStorePath;
92
  private volatile String keyStorePath;
95
  private volatile String keyStorePassword;
93
  private volatile String keyStorePassword;
96
  private volatile Boolean sslEnabled;
94
  private volatile Boolean sslEnabled;
97

    
   
95

   
98

    
   
96

   
[+20] [20] 7 lines
[+20] [+] public void configure(Context context) {
106
      host = context.getString(HTTPSourceConfigurationConstants.CONFIG_BIND,
104
      host = context.getString(HTTPSourceConfigurationConstants.CONFIG_BIND,
107
        HTTPSourceConfigurationConstants.DEFAULT_BIND);
105
        HTTPSourceConfigurationConstants.DEFAULT_BIND);
108

    
   
106

   
109
      Preconditions.checkState(host != null && !host.isEmpty(),
107
      Preconditions.checkState(host != null && !host.isEmpty(),
110
                "HTTPSource hostname specified is empty");
108
                "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"
109
      Preconditions.checkNotNull(port, "HTTPSource requires a port number to be"
114
                + " specified");
110
        + " specified");
115
      }

   
116

    
   
111

   
117
      String handlerClassName = context.getString(
112
      String handlerClassName = context.getString(
118
              HTTPSourceConfigurationConstants.CONFIG_HANDLER,
113
              HTTPSourceConfigurationConstants.CONFIG_HANDLER,
119
              HTTPSourceConfigurationConstants.DEFAULT_HANDLER).trim();
114
              HTTPSourceConfigurationConstants.DEFAULT_HANDLER).trim();
120

    
   
115

   
121
      if(sslEnabled) {
116
      if(sslEnabled) {
122
        LOG.debug("SSL configuration enabled");
117
        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);
118
        keyStorePath = context.getString(HTTPSourceConfigurationConstants.SSL_KEYSTORE);
126
        Preconditions.checkArgument(keyStorePath != null && !keyStorePath.isEmpty(),
119
        Preconditions.checkArgument(keyStorePath != null && !keyStorePath.isEmpty(),
127
                                        "Keystore is required for SSL Conifguration" );
120
                                        "Keystore is required for SSL Conifguration" );
128
        keyStorePassword = context.getString(HTTPSourceConfigurationConstants.SSL_KEYSTORE_PASSWORD);
121
        keyStorePassword = context.getString(HTTPSourceConfigurationConstants.SSL_KEYSTORE_PASSWORD);
129
        Preconditions.checkArgument(keyStorePassword != null, "Keystore password is required for SSL Configuration");
122
        Preconditions.checkArgument(keyStorePassword != null, "Keystore password is required for SSL Configuration");
130
      }
123
      }
131

    
   
124

   

    
   
125

   

    
   
126

   
132
      @SuppressWarnings("unchecked")
127
      @SuppressWarnings("unchecked")
133
      Class<? extends HTTPSourceHandler> clazz =
128
      Class<? extends HTTPSourceHandler> clazz =
134
              (Class<? extends HTTPSourceHandler>)
129
              (Class<? extends HTTPSourceHandler>)
135
              Class.forName(handlerClassName);
130
              Class.forName(handlerClassName);
136
      handler = clazz.getDeclaredConstructor().newInstance();
131
      handler = clazz.getDeclaredConstructor().newInstance();
[+20] [20] 36 lines
[+20] [+] public void start() {
173

    
   
168

   
174
    // Connector Array
169
    // Connector Array
175
    Connector[] connectors = new Connector[1];
170
    Connector[] connectors = new Connector[1];
176

    
   
171

   
177

    
   
172

   
178
    if(sslEnabled) {
173
    if (sslEnabled) {
179
      SslSocketConnector sslSocketConnector = new SslSocketConnector();
174
      SslSocketConnector sslSocketConnector = new SslSocketConnector();
180
      sslSocketConnector.setKeystore(keyStorePath);
175
      sslSocketConnector.setKeystore(keyStorePath);
181
      sslSocketConnector.setKeyPassword(keyStorePassword);
176
      sslSocketConnector.setKeyPassword(keyStorePassword);
182
      sslSocketConnector.setPort(sslPort);

   
183
      connectors[0] = sslSocketConnector;
177
      connectors[0] = sslSocketConnector;
184
    } else {
178
    } else {
185
        SocketConnector connector = new SocketConnector();
179
      SocketConnector connector = new SocketConnector();
186
        connector.setPort(port);

   
187
        connector.setHost(host);

   
188
        connectors[0] = connector;
180
      connectors[0] = connector;
189
    }
181
    }
190

    
   
182

   

    
   
183
    connectors[0].setHost(host);

    
   
184
    connectors[0].setPort(port);
191
    srv.setConnectors(connectors);
185
    srv.setConnectors(connectors);
192
    try {
186
    try {
193
      org.mortbay.jetty.servlet.Context root =
187
      org.mortbay.jetty.servlet.Context root =
194
              new org.mortbay.jetty.servlet.Context(
188
        new org.mortbay.jetty.servlet.Context(
195
              srv, "/", org.mortbay.jetty.servlet.Context.SESSIONS);
189
          srv, "/", org.mortbay.jetty.servlet.Context.SESSIONS);
[+20] [20] 81 lines
flume-ng-core/src/main/java/org/apache/flume/source/http/HTTPSourceConfigurationConstants.java
Revision 205aeab New Change
 
flume-ng-core/src/test/java/org/apache/flume/source/http/TestHTTPSource.java
Revision 9e14648 New Change
 
flume-ng-doc/sphinx/FlumeUserGuide.rst
Revision 5a59b56 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...