Review Board 1.7.22


Patch to add SSL support to HTTP Source, Flume-2109

Review Request #12244 - Created July 3, 2013 and discarded

Ashish Paliwal
master
FLUME-2109
Reviewers
Flume
flume-git
Patch for Flume-2109, to add HTTPS support to HTTP Source
Unit Test added to verify SSL messages being sent to the Source.
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 {
94
      port = context.getInteger(HTTPSourceConfigurationConstants.CONFIG_PORT);
102
      port = context.getInteger(HTTPSourceConfigurationConstants.CONFIG_PORT);
95
      host = context.getString(HTTPSourceConfigurationConstants.CONFIG_BIND,
103
      host = context.getString(HTTPSourceConfigurationConstants.CONFIG_BIND,
96
        HTTPSourceConfigurationConstants.DEFAULT_BIND);
104
        HTTPSourceConfigurationConstants.DEFAULT_BIND);
97
      checkHostAndPort();
105
      checkHostAndPort();
98
      String handlerClassName = context.getString(
106
      String handlerClassName = context.getString(
99
              HTTPSourceConfigurationConstants.CONFIG_HANDLER,
107
              HTTPSourceConfigurationConstants.CONFIG_HANDLER,
100
              HTTPSourceConfigurationConstants.DEFAULT_HANDLER).trim();
108
              HTTPSourceConfigurationConstants.DEFAULT_HANDLER).trim();

    
   
109

   

    
   
110
      // SSL related config

    
   
111
      sslEnabled = context.getBoolean(HTTPSourceConfigurationConstants.SSL_ENABLED);

    
   
112

   

    
   
113
      if(sslEnabled) {

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

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

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

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

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

    
   
119
                                        "Keystore is required for SSL Conifguration" );

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

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

    
   
122
      }

    
   
123

   
101
      @SuppressWarnings("unchecked")
124
      @SuppressWarnings("unchecked")
102
      Class<? extends HTTPSourceHandler> clazz =
125
      Class<? extends HTTPSourceHandler> clazz =
103
              (Class<? extends HTTPSourceHandler>)
126
              (Class<? extends HTTPSourceHandler>)
104
              Class.forName(handlerClassName);
127
              Class.forName(handlerClassName);
105
      handler = clazz.getDeclaredConstructor().newInstance();
128
      handler = clazz.getDeclaredConstructor().newInstance();
[+20] [20] 34 lines
[+20] [+] public void start() {
140
            + "Will not attempt to start.");
163
            + "Will not attempt to start.");
141
    srv = new Server();
164
    srv = new Server();
142
    SocketConnector connector = new SocketConnector();
165
    SocketConnector connector = new SocketConnector();
143
    connector.setPort(port);
166
    connector.setPort(port);
144
    connector.setHost(host);
167
    connector.setHost(host);
145
    srv.setConnectors(new Connector[] { connector });
168

   

    
   
169
    // max size is 2

    
   
170
    List<Connector> socketConnector = new ArrayList<Connector>(2);

    
   
171
    socketConnector.add(connector);

    
   
172

   

    
   
173
    if(sslEnabled) {

    
   
174
      SslSocketConnector sslSocketConnector = new SslSocketConnector();

    
   
175
      sslSocketConnector.setKeystore(keyStorePath);

    
   
176
      sslSocketConnector.setKeyPassword(keyStorePassword);

    
   
177
      sslSocketConnector.setPort(sslPort);

    
   
178
      socketConnector.add(sslSocketConnector);

    
   
179
    }

    
   
180

   

    
   
181
    srv.setConnectors(socketConnector.toArray(new Connector[0]));
146
    try {
182
    try {
147
      org.mortbay.jetty.servlet.Context root =
183
      org.mortbay.jetty.servlet.Context root =
148
              new org.mortbay.jetty.servlet.Context(
184
              new org.mortbay.jetty.servlet.Context(
149
              srv, "/", org.mortbay.jetty.servlet.Context.SESSIONS);
185
              srv, "/", org.mortbay.jetty.servlet.Context.SESSIONS);
150
      root.addServlet(new ServletHolder(new FlumeHTTPServlet()), "/");
186
      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...