https://issues.apache.org/bugzilla/show_bug.cgi?id=56327

            Bug ID: 56327
           Summary: Adding non HTTP (e.g AJP) connector using MBeans is
                    not possible
           Product: Tomcat 8
           Version: trunk
          Hardware: PC
                OS: Windows XP
            Status: NEW
          Severity: normal
          Priority: P2
         Component: Catalina
          Assignee: dev@tomcat.apache.org
          Reporter: kgki...@gmail.com

Created attachment 31451
  --> https://issues.apache.org/bugzilla/attachment.cgi?id=31451&action=edit
Source code with the fix

Using MBeans (org.apache.catalina.mbeans.ServiceMBean) it is possible to add a
connector during runtime.

API says:
 public void addConnector(String address, int port, boolean isAjp, boolean
isSSL) 


Even adding AJP should be possible. However upon looking at the code, it is
creating a Connector with default constructor that would set the
protocolHandler to HttpProtocolHandler. In other words, to create an AJP
connector, protocol should be available during the construction of the
Connector.

It is a simple fix. 

   public void addConnector(String address, int port, boolean isAjp, boolean
isSSL) throws MBeanException {

        Service service; 
        try {
            service = (Service)getManagedResource();
        } catch (InstanceNotFoundException e) {
            throw new MBeanException(e);
        } catch (RuntimeOperationsException e) {
            throw new MBeanException(e);
        } catch (InvalidTargetObjectTypeException e) {
            throw new MBeanException(e);
        }
        String protocol = isAjp ? "AJP/1.3" : "HTTP/1.1";


        // Pass the protocol here rather than setting it later
         Connector connector = new Connector(protocol);

        if ((address!=null) && (address.length()>0)) {
            connector.setProperty("address", address);
        }
        connector.setPort(port);
        connector.setSecure(isSSL);
        connector.setScheme(isSSL ? "https" : "http");

        service.addConnector(connector);       

    }

-- 
You are receiving this mail because:
You are the assignee for the bug.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to