You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Ramirez, Edwin" <ed...@mssm.edu> on 2013/11/20 23:27:19 UTC

Embedded Tomcat AJP Issue

Hello,

I am new to Tomcat and I was wondering if you could help me.  I am trying to use tomcat in an embedded scenario, but I am unable to get the tomcat connector to support AJP connections.
During startup I get the following messages:
...
Nov 20, 2013 4:43:56 PM org.apache.coyote.AbstractProtocol init
INFO: Initializing ProtocolHandler ["http-bio-9010"]
...
INFO: Starting ProtocolHandler ["http-bio-9010"]
I was expecting it to say ["AJP-bio-9010"].  And mod_jk2 is unable to connect to it.

The code is as follows:
    void TomcatStartup(TreeMap conf) {
        Tomcat tomcat = new Tomcat();
        tomcat.setHostname("localhost");
        tomcat.setPort(conf.getInt("Listener.service.port"));

        org.apache.catalina.connector.Connector ajp = tomcat.getConnector();
        ajp.setProtocol("AJP/1.3");
        ajp.setAttribute("protocol", "AJP/1.3");
        ajp.setAttribute("tomcatAuthentication", false);
        ajp.setAttribute("port", conf.getInt("Listener.service.port"));

        tomcat.setConnector(ajp);
        org.apache.catalina.Context ctx =
            tomcat.addContext("/", new File(".").getAbsolutePath());

        TomcatHandler th = new TomcatHandler();
        th.conf = conf;

        Tomcat.addServlet(ctx, "sc", th);
        ctx.addServletMapping("/*", "sc");
        try {
            tomcat.start();
        } catch(Exception ex) {
            ex.printStackTrace();
        }
    }

What I am doing wrong?

Thanks,
Edwin S. Ramirez
Senior Developer, Information Technology
Mount Sinai Medical Center

875 Avenue of the Americas (6th Ave.)
New York, NY 10001

Phone: 646-217-3112
Fax:  212-356-0085


Re: Embedded Tomcat AJP Issue

Posted by Christopher Schultz <ch...@christopherschultz.net>.
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA256

Edwin,

On 11/20/13, 5:27 PM, Ramirez, Edwin wrote:
> I am new to Tomcat and I was wondering if you could help me.  I am
>  trying to use tomcat in an embedded scenario, but I am unable to 
> get the tomcat connector to support AJP connections.

What version of Tomcat are you using?

> During startup I get the following messages: ... Nov 20, 2013 
> 4:43:56 PM org.apache.coyote.AbstractProtocol init INFO: 
> Initializing ProtocolHandler ["http-bio-9010"] ... INFO: Starting 
> ProtocolHandler ["http-bio-9010"] I was expecting it to say 
> ["AJP-bio-9010"].

Let's take a look.

> And mod_jk2 is unable to connect to it.

Good. You shouldn't use mod_jk2 for anything. Use mod_jk instead if
you actually need to use a non-HTTP connector.

> The code is as follows: void TomcatStartup(TreeMap conf) { Tomcat 
> tomcat = new Tomcat(); tomcat.setHostname("localhost"); 
> tomcat.setPort(conf.getInt("Listener.service.port"));

What is Listener.service.port set to? 9010?

> org.apache.catalina.connector.Connector ajp = 
> tomcat.getConnector(); ajp.setProtocol("AJP/1.3"); 
> ajp.setAttribute("protocol", "AJP/1.3"); 
> ajp.setAttribute("tomcatAuthentication", false); 
> ajp.setAttribute("port", conf.getInt("Listener.service.port"));

Calling Tomcat.getConnector() will create an HTTP connector if one was
not already added. From the Javadoc (emphasis mine):

"Get the *default http connector*. You can set more parameters - the
port is already initialized. Alternatively, you can construct a
Connector and set any params, then call addConnector(Connector) "

Ref:
http://tomcat.apache.org/tomcat-7.0-doc/api/org/apache/catalina/startup/Tomcat.html#getConnector()

> What I am doing wrong?

You should probably start with a new connector and add it yourself.
Once a Connector object has been created, you cannot change its protocol.

Try this:

Connector c = new Connector("AJP/1.3");
c.setPort(...);
...
tomcat.setConnector(c);

Hope that helps,
- -chris
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.15 (Darwin)
Comment: GPGTools - http://gpgtools.org
Comment: Using GnuPG with Thunderbird - http://www.enigmail.net/

iQIcBAEBCAAGBQJSjrECAAoJEBzwKT+lPKRYEaEQAIsRkpu83En+9nhIji28cC9P
SzGMzjHS2EcGx4wtIU7yk0dtCtaCXpK7l68iNWKfuT7Ns1VB2oMhcGqUggcgUeU2
GZweQMaUKSRwC828ptuc4/MKj485HxiFx7dMHJzRzDMU2nsc4/Lx6yfVy/uNA3qo
4QIXP7l+AUrdZ5oCrkI9CFUCU6zXTpeav5SeLnFCZAl61w3V3RnaEh1QN6MAR1Fq
dfJp6BiyDKrajrU3rGS+v01qcUuh6eWAzV417yHNAccXniV1fzQmTS7HTbM5gAw2
L8Eb8YoRSB844hC7ATwlHir4uqYvxybLo/PEHwNx5zSYZbMSJxkJHtTN+p0/FQFm
nVJdktpWhWwWO65evQN5nVCorJ7Z7ejsHGSQ+tE2nrrksO7wERbb40GXNg73FDST
mugZWu4QYf8o4jilt6BmfW4Ic/erj+FqV2WP/ygFQXH3c4fSfhX0X3Zg+/WrSitD
GoNzI9qLVxOhVpHmE4z8qdlPQEzXwTp3aT3jPlT7xea2jHBmHkyqiLpist/a+yGo
u8q3yDGCFw1Hsq/QhtkYYld/RK4Q88sLd9BCETIw4fgkdTfeT5XdYPHWwdO9RRBX
or15xadhp0AjGK0Md0HKobJw+JpN8VtBThb77ifTNclKYfIVPkWgsmdettzXyHFC
tPTUrO5yDnYkqsJ7Qm65
=wir6
-----END PGP SIGNATURE-----

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org