Hi,
Not sure if anyone has used NIO connector in embedded tomcat 7 but I am
out of luck so far. It seems so simple but I could not get it work. I am
wondering if this is a bug in embedded version of tomcat because it works
fine on standalone version. If this turns out to be a bug in tomcat 7
embedded, then I may have to think about moving to Jetty but it would be
ideal if I can figure this out with tomcat 7 itself.

I am pasting the complete method that create Tomcat instance with NIO
connector and starts it. If I don't have NIO connector all rest requests
works perfectly. But with this NIO connector I can't connect to server. I
looked at the tomcat unit tests and they don't seem to be doing anything
special for NIO connector. Any help would be appreciated.

public void init() throws LifecycleException, IOException {

                log.debug("Initializing Tomcat");

                final File base = createBaseDirectory();
                log.info("Using base folder: " + base.getAbsolutePath());

                final Tomcat tomcat = new Tomcat();
                tomcat.setPort(TOMCAT_PORT);
                tomcat.setBaseDir(base.getAbsolutePath());

                Context context = tomcat.addContext("/perfmon", 
base.getAbsolutePath());
                //handle rest requests
                Wrapper cxfServlet = Tomcat.addServlet(context, "CXFServlet", 
new
CXFServlet());

                cxfServlet.addInitParameter("config-location",
"classpath:perfmon-rest-server.xml");
                cxfServlet.setLoadOnStartup(1);

                context.addServletMapping("/rest/*", "CXFServlet");
                
context.addApplicationListener(ContextLoaderListener.class.getName());
                context.setLoader(new
WebappLoader(Thread.currentThread().getContextClassLoader()));

                //atmosphere websocket support
                Wrapper atmosphereServlet = Tomcat.addServlet(context,
"AtmosphereServlet", new TomcatAtmosphereServlet());
                atmosphereServlet
                                .addInitParameter("org.atmosphere.cpr.packages",
"com.kiva.perfmon.prototype.pubsub.websocket");
                atmosphereServlet.setLoadOnStartup(0);
                context.addServletMapping("/pubsub/*", "AtmosphereServlet");

                context.addParameter("contextConfigLocation",
"classpath:perfmon-context.xml");

                // add nio connector for websocket support
                Connector nioConnector = new
Connector(Http11NioProtocol.class.getName());
                nioConnector.setPort(TOMCAT_PORT);
                nioConnector.setProperty("address",
InetAddress.getByName("localhost").getHostAddress());
tomcat.setConnector(nioConnector);

                tomcat.start();
                tomcat.getServer().await();
        }


Thanks in advance.
Praveen

On 4/23/13 Apr 23, 12:21 PM, "Praveen Peddi" <ppe...@kivasystems.com>
wrote:

>Sorry I meant "nio" connector not bio connector. Outlook auto-correct is
>not smart enough :)
>
>On 4/23/13 Apr 23, 12:08 PM, "Praveen Peddi" <ppe...@kivasystems.com>
>wrote:
>
>>I am not sure if this is the same issue I am having but apparently I am
>>also using atmosphere for web sockets and make it work in embedded
>>tomcat.
>>
>>I looked at the tomcat unit tests for bio connector and the tests are not
>>doing anything special. They set the address to localhost. I tried the
>>below code similar to the unit tests but I still can't connect to tomcat
>>when I use this connector.
>>
>>Connector nioConnector = new
>>Connector(Http11NioProtocol.class.getName());
>>              nioConnector.setPort(TOMCAT_PORT);
>>              nioConnector.setProperty("address",
>>                InetAddress.getByName("localhost").getHostAddress());
>>tomcat.setConnector(nioConnector);
>>
>>
>>Unit test I saw is here:
>>http://svn.apache.org/repos/asf/tomcat/trunk/test/org/apache/catalina/non
>>b
>>l
>>ocking/TestNonBlockingAPI.java
>>And 
>>http://svn.apache.org/repos/asf/tomcat/trunk/test/org/apache/catalina/sta
>>r
>>t
>>up/TomcatBaseTest.java
>>
>>
>>Thanks
>>Praveen
>>
>>On 4/23/13 Apr 23, 10:40 AM, "Tribon Cheng" <tribon1...@gmail.com> wrote:
>>
>>>Just like this issue:
>>>
>>>http://atmosphere-framework.2306103.n4.nabble.com/WebSocket-not-working-
>>>o
>>>n
>>>-Tomcat-7-With-NIO-connector-was-WebSocket-not-working-on-Tomcat-7-td465
>>>2
>>>3
>>>51.html
>>>
>>>
>>>On Tue, Apr 23, 2013 at 10:16 PM, Mark Thomas <ma...@apache.org> wrote:
>>>
>>>> On 23/04/2013 15:11, Praveen Peddi wrote:
>>>> > Hi all, I am trying to set Nio connector in tomcat7 so I can use
>>>> > WebSocket support. I did the following (as simple as it can get) but
>>>> > it doesn't seem to work. When I do this I can't connect to the
>>>> > server. For example I have a GET REST request that should work but I
>>>> > get connection refused. Same with WebSocket request.
>>>> >
>>>> >
>>>> > Connector nioConnector = new Connector();
>>>> >
>>>> > nioConnector.setPort(TOMCAT_PORT);
>>>> >
>>>> > nioConnector.setProtocol(Http11NioProtocol.class.getName());
>>>> >
>>>> > tomcat.setConnector(nioConnector);
>>>> >
>>>> >
>>>> > If I comment out above lines and use default Http connector, REST
>>>> > requests work fine but WebSockets are not supported with default
>>>>http
>>>> > connector.
>>>>
>>>> Yes they are.
>>>>
>>>> > So I am wondering if anyone has enabled bio connector in
>>>> > embedded tomcat before. I am using embedded tomcat 7.0.34.
>>>>
>>>> You mean NIO right?
>>>>
>>>> Look at the source code for the unit tests and/or the source code for
>>>> Connector. You aren't changing what you think you are changing. (Too
>>>> many attributes call Protocol or something similar).
>>>>
>>>> Mark
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>>>> For additional commands, e-mail: users-h...@tomcat.apache.org
>>>>
>>>>
>>>
>>>
>>>-- 
>>>Contribute to Enterprise Integration
>>
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>>For additional commands, e-mail: users-h...@tomcat.apache.org
>>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
>For additional commands, e-mail: users-h...@tomcat.apache.org
>


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

Reply via email to