users@grizzly.java.net

RE: Adding a filter at runtime

From: Meltser Tiran <Tiran.Meltser_at_comverse.com>
Date: Fri, 30 Jan 2015 22:05:23 +0000

Hi Alexey,
I've decided to go with the approach of having the dynamic (TLS in my case) filter in the filterchain but give it the ability to be turned on at will, and it seems to be working quite well.

As for the bug you have requested, since I've never done it before, could you share some starter info on this?

Second, I see in the Maven repository the 2.3.18 release which seems to be latest, is this the latest formal release (since I see the site mentions 2.3.14)?

Tiran Meltser
System Architect
Global Products & Operations
Comverse - Making Your Network Smarter

T +972-3-7678381
M +972-54-5639381
Tiran.Meltser_at_comverse.com <mailto:Tiran.Meltser_at_comverse.com>
www.comverse.com<http://www.comverse.com/>
P Please think of the environment before printing this email

From: Oleksiy Stashok [mailto:oleksiy.stashok_at_oracle.com]
Sent: Wednesday, January 28, 2015 9:46 AM
To: users_at_grizzly.java.net
Subject: Re: Adding a filter at runtime

Hi Tiran,

unfortunately in Grizzly 2.3.x FilterChain modification at runtime is tricky (it's fixed on 3.0 branch).
We suggest to install all the Filters in advance and use a switch to turn the filter logic on and off, like here:
https://github.com/AsyncHttpClient/async-http-client/blob/1.9.x/src/main/java/com/ning/http/client/providers/grizzly/GrizzlyAsyncHttpProvider.java#L2446<http://cp.mcafee.com/d/avndzhJ5xddxB55UQsCXCQQmrFIEEFL6QQmrFIELFL6QQmrIEL3DCjqdXCzB5B-Xz9KsEX3BvfDjUwFsPYqvOVJsPYqvOVJ51AQsLmovW_e8FI9IZuVt55C_8ELzC67emKzp5dl55zBgY-F6lK1FJ4SCrLOabUVUQsI3ChNKVIDeqR4IMzapdIxO-252Qb1usRx8-nMDCQbgIn9PCInIvbUjMwvkxyf6zDw_ahJyKOxwzFDsnO4E4s9PCJBzVv2ubhGpAxYqohz8k53OS1acxgkfb252Qb1usRwJ6FCi7NUhQPE61ldxxMSTjUQbRcg-8a8NAa2xVrx7jeY3jqr3bwUS2_id40wwxa14Qgqq87p7P-9EwSpEwyT2sBvdITdYHPcmWyn>

Specifically in your case the problem could be related to FilterChainBuilder instance, which underneath updates existing FilterChain instead of creating a new FilterChain instance.
You can try to create a separate FilterChainBuilder and initiate it with all the Filters you need.

IMO FilterChainBuilder logic (updating an existing FilterChain) is wrong and it has to be fixed. It has to create new FilterChain instance every time build() is invoked. Will appreciate if you can bug an issue for this.

Thank you.

WBR,
Alexey.



On 27.01.15 09:40, Meltser Tiran wrote:
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<http://cp.mcafee.com/d/FZsS93hJ5xddxB55UQsCXCQQmrFIEEFL6QQmrFIELFL6QQmrIEL3DCjqdXCzB5B-Xz9KsEX3BvfDjUwFsPYqvOVJsPYqvOVJ51AQsLmovW_e8FI9IZuVt55C_8ELzC67emKzp5dl55zBgY-F6lK1FJcSCrLOabUVUQsI3ChNKVIDeqR4IMhQPL0T16ktMx6FyDU4wm6wi18l0Vt5ZOVJKDNEnGoxYgkhz8k53OT2eCtU6CQS6n1NI5-Aq81112k29EwQQgeOfDYjh1IPh15K4Va-rpKrWgq0>, 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<mailto:security_at_comverse.com>. Thank You."

________________________________
"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."