One requirement now is that flume can be used as a tomcat-like server that can be accessed via a POST request and that the path requires: Ip:port/contextpath format.
After some information, Httpsource is just a toy tool httpsource, can be said that the rough version, currently only supported by Ip:port access, does not have the function of the servlet.
Then open the source to see:
This is the Httpsource source code, you can see the main is 5 classes: httpbadrequestexception,httpsource,httpsourceconfigurationconstants, Httpsourcehandler,jsonhandler.
The function of the distinction is:
Httpbadrequestexception: Defines some HTTP exceptions, commonly used such as 404.
Httpsourceconfigurationconstants: The main definition of some source constants, from the configuration file. such as: Port,host, etc.
Httpsourcehandler: An interface that acts as a handler template.
Jsonhandler: Provide the default implementation of handler, select is ["Header":, "body":] This format, the author is not accustomed to this, in fact, there are several types of event mode, do not know why to choose this.
Httpsource: This is the main class, which has a start method similar to the main method.
In essence, Httpsource is a server embedded in the jetty, by accepting the POST request (currently written to only process the POST request). Convert data to event to be issued. So, the modification is simple.
You only need to add a contextpath parameter to the httpsourceconfigurationconstants:
public static final String Context_path = "ContextPath";
Then jump to the Httpsource class,
In the preceding statement, add:
private volatile String contextpath;
The Configure method is added to get this path:
ContextPath = context.getstring (Httpsourceconfigurationconstants.context_path);
The next step is to add the path to the jetty server and see this part of the code:
public void Start () {preconditions.checkstate (SRV = = null, "Running HTTP Server found in Source:" + Getnam E () + "before I started one." + "won't attempt to start."); SRV = new Server (); Connector Array connector[] connectors = new CONNECTOR[1]; if (sslenabled) {sslsocketconnector sslsocketconnector = new Httpsourcesocketconnector (excludedprotocols); Sslsocketconnector.setkeystore (Keystorepath); Sslsocketconnector.setkeypassword (Keystorepassword); Sslsocketconnector.setreuseaddress (TRUE); Connectors[0] = Sslsocketconnector; } else {Selectchannelconnector connector = new Selectchannelconnector (); Connector.setreuseaddress (TRUE); Connectors[0] = connector; } connectors[0].sethost (host); Connectors[0].setport (port); Srv.setconnectors (connectors); try {org.mortbay.jetty.servlet.Context root = new Org.mortbay.jetty.servlet.Context (SRV, "/", ORG.M Ortbay.jEtty.servlet.Context.SESSIONS); Root.addservlet (New Servletholder (New Flumehttpservlet ()), "/"); Httpserverconstraintutil.enforceconstraints (root); Srv.start (); Preconditions.checkargument (Srv.gethandler (). equals (root); } catch (Exception ex) {Log.error ("error while starting Httpsource. Exception follows. ", ex); Throwables.propagate (ex); } preconditions.checkargument (Srv.isrunning ()); Sourcecounter.start (); Super.start (); }
Just add the configured path to the Root.addservlet, and we can access it based on the path:
Root.addservlet (New Servletholder (New Flumehttpservlet ()), "/" +contextpath);
All right, it's done.
Modify flume source code, make it httpsource with access path function