users@grizzly.java.net

Adding a filter at runtime

From: Meltser Tiran <Tiran.Meltser_at_comverse.com>
Date: Tue, 27 Jan 2015 17:40:45 +0000

Hi all,
I'm trying to add a filter (SSLFilter) at runtime to support a STARTTLS IMAP command.

I tried the following code:

                                Pair<NIOTransport,FilterChainBuilder> transportData = mTransportsMap.get(aServiceGate.getSecurityLevel());

                                if (transportData != null)
                                {
                                                FilterChainBuilder filterChainBuilder = transportData.getSecond();

                                                if (filterChainBuilder != null)
                                                {
                                                                // We'll place the SSLFilter right after the TransportFilter
                                                                int indexOfTransportFilter = filterChainBuilder.indexOfType(TransportFilter.class);

                                                                // Initialize and add SSLFilter
                                                                filterChainBuilder.add(indexOfTransportFilter + 1,obtainSSLFilter());

                                                                // Secure the entry point connection (build a proper filter chain for this connection)
                                                                aEntryPointConnection.setProcessor(filterChainBuilder.build());
                                                }
                                }

But got the following Exception:

java.lang.ArrayIndexOutOfBoundsException: 6
                at org.glassfish.grizzly.filterchain.DefaultFilterChain$FiltersState.peekUnparsedIdx(DefaultFilterChain.java:619)
                at org.glassfish.grizzly.filterchain.DefaultFilterChain.prepareRemainder(DefaultFilterChain.java:301)
                at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:154)
                at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)
                at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
                at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)
                at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)
                at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)
                at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56)
                at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)
                at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
                at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
                at java.lang.Thread.run(Thread.java:745)

I came across the following item: https://java.net/jira/browse/GRIZZLY-1560, which seems to be my problem. I saw that the issue was solved:

1. In which version was it solved (I'm using 2.3.18)?

2. Can someone share a pseudo code (suitable to the 2.3.18 line) of the recommended way to perform a dynamic adding of a filter at runtime?

Thanks,
Tiran Meltser


________________________________
"This e-mail message may contain confidential, commercial or privileged information that constitutes proprietary information of Comverse Inc. or its subsidiaries. If you are not the intended recipient of this message, you are hereby notified that any review, use or distribution of this information is absolutely prohibited and we request that you delete all copies and contact us by e-mailing to: security_at_comverse.com. Thank You."