This discussion is archived
0 Replies Latest reply: Feb 15, 2012 1:25 AM by 916092 RSS

NIO Connector Configuration problem in Tomcat 7

916092 Newbie
Currently Being Moderated
Hi All,

I have implemented CometProcessor in my TestComet java class and configure NIO connector in server.xml in Tomcat 7 accordingly.
When I am trying to hit the Servlet class through ajax, init() method of servlet is getting called but failed to call the
"event(CometEvent event)" method, rather it's calling service(HttpServletRequest request, HttpServletResponse response) method. It seems to me NIO is not configured properly. Could any one please suggest me where I went wrong.

The Servlet class :

import java.io.IOException;

import javax.servlet.*;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.catalina.CometEvent;
import org.apache.catalina.CometProcessor;




public class TestComet extends HttpServlet implements CometProcessor {


public void init() throws ServletException {
System.out.println(" in init start ");

}

public void event(CometEvent event)throws IOException, ServletException{
System.out.println(" in event ");
if (event.getEventType() == CometEvent.EventType.BEGIN) {
System.out.println(" in event BEGIN ");
} else if (event.getEventType() == CometEvent.EventType.ERROR) {
System.out.println(" in event ERROR ");
} else if (event.getEventType() == CometEvent.EventType.END) {
System.out.println(" in event END ");
} else if (event.getEventType() == CometEvent.EventType.READ) {
System.out.println(" in event READ ");
}

}

protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
System.out.println(" error ");
}
}

Server.xml

<?xml version="1.0" encoding="utf-8"?>

<Server port="8005" shutdown="SHUTDOWN">
<!--APR library loader. Documentation at /docs/apr.html -->
<Listener className="org.apache.catalina.core.AprLifecycleListener" SSLEngine="on"/>
<Listener className="org.apache.catalina.core.JasperListener"/>
<Listener className="org.apache.catalina.core.JreMemoryLeakPreventionListener"/>
<Listener className="org.apache.catalina.mbeans.GlobalResourcesLifecycleListener"/>
<Listener className="org.apache.catalina.core.ThreadLocalLeakPreventionListener"/>
<GlobalNamingResources>
<Resource name="UserDatabase" auth="Container" type="org.apache.catalina.UserDatabase" description="User database that can be updated and saved" factory="org.apache.catalina.users.MemoryUserDatabaseFactory" pathname="conf/tomcat-users.xml"/>
</GlobalNamingResources>
<Service name="Catalina">
<Connector port="8080"
protocol="org.apache.coyote.http11.Http11NioProtocol"
connectionTimeout="10000"
tomcatAuthentication="false"
keepaliveTimeout="5000"
backlog="50"
maxThreads="300"/>
maxThreads="150" scheme="https" secure="true"
clientAuth="false" sslProtocol="TLS" />
<Engine name="Catalina" defaultHost="localhost">

<Realm className="org.apache.catalina.realm.LockOutRealm">
<Realm className="org.apache.catalina.realm.UserDatabaseRealm" resourceName="UserDatabase"/>
</Realm>
<Host name="localhost" appBase="webapps" unpackWARs="true" autoDeploy="true">
<Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs" prefix="localhost_access_log." suffix=".txt" pattern="%h %l %u %t "%r" %s %b"/>
</Host>
</Engine>
</Service>
</Server>


URL I have hit through Browser :
http://localhost:8080/CometServerHome/TestComet

Response I received in Browser :
message You must be using the APR or NIO connector to get the event method called.
description The server encountered an internal error (You must be using the APR or NIO connector to get the event method called.) that prevented it from fulfilling this request.

In console
in init start
error

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points