Adding a filter at runtime

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|

Adding a filter at runtime

Meltser Tiran

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: [hidden email]. Thank You.”
Reply | Threaded
Open this post in threaded view
|

Re: Adding a filter at runtime

oleksiys
Administrator
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

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, 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: [hidden email]. Thank You.”

Reply | Threaded
Open this post in threaded view
|

RE: Adding a filter at runtime

Meltser Tiran

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
ComverseMaking Your Network Smarter

 

T   +972-3-7678381
M +972-54-5639381
[hidden email]
www.comverse.com

P Please think of the environment before printing this email

 

From: Oleksiy Stashok [mailto:[hidden email]]
Sent: Wednesday, January 28, 2015 9:46 AM
To: [hidden email]
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

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, 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: [hidden email]. 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: [hidden email]. Thank You.”
Reply | Threaded
Open this post in threaded view
|

Re: Adding a filter at runtime

oleksiys
Administrator
Hi Tiran,

On 30.01.15 14:05, Meltser Tiran wrote:
 

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

You can file the bug @
https://java.net/jira/browse/GRIZZLY

 

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)?

Yes, 2.3.18 is the latest, I'll update the webpages.

Thanks.

WBR,
Alexey.

 

Tiran Meltser
System Architect
Global Products & Operations
ComverseMaking Your Network Smarter

 

T   +972-3-7678381
M +972-54-5639381
[hidden email]
www.comverse.com

P Please think of the environment before printing this email

 

From: Oleksiy Stashok [[hidden email]]
Sent: Wednesday, January 28, 2015 9:46 AM
To: [hidden email]
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

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, 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: [hidden email]. 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: [hidden email]. Thank You.”

Reply | Threaded
Open this post in threaded view
|

RE: Adding a filter at runtime

Meltser Tiran

1.    GRIZZLY-1735 created as requested.

Tiran Meltser

From: Oleksiy Stashok [mailto:[hidden email]]
Sent: Saturday, January 31, 2015 3:06 AM
To: [hidden email]
Subject: Re: Adding a filter at runtime

 

Hi Tiran,

On 30.01.15 14:05, Meltser Tiran wrote:

 

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

You can file the bug @
https://java.net/jira/browse/GRIZZLY


 

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)?

Yes, 2.3.18 is the latest, I'll update the webpages.

Thanks.

WBR,
Alexey.


 

Tiran Meltser
System Architect
Global Products & Operations
ComverseMaking Your Network Smarter

 

T   +972-3-7678381
M +972-54-5639381
[hidden email]
www.comverse.com

P Please think of the environment before printing this email

 

From: Oleksiy Stashok [[hidden email]]
Sent: Wednesday, January 28, 2015 9:46 AM
To: [hidden email]
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

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, 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: [hidden email]. 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: [hidden email]. 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: [hidden email]. Thank You.”
Reply | Threaded
Open this post in threaded view
|

Re: Adding a filter at runtime

oleksiys
Administrator
Fixed,

thank you!

On 31.01.15 09:09, Meltser Tiran wrote:

1.    GRIZZLY-1735 created as requested.

Tiran Meltser

From: Oleksiy Stashok [[hidden email]]
Sent: Saturday, January 31, 2015 3:06 AM
To: [hidden email]
Subject: Re: Adding a filter at runtime

 

Hi Tiran,

On 30.01.15 14:05, Meltser Tiran wrote:

 

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

You can file the bug @
https://java.net/jira/browse/GRIZZLY


 

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)?

Yes, 2.3.18 is the latest, I'll update the webpages.

Thanks.

WBR,
Alexey.


 

Tiran Meltser
System Architect
Global Products & Operations
ComverseMaking Your Network Smarter

 

T   +972-3-7678381
M +972-54-5639381
[hidden email]
www.comverse.com

P Please think of the environment before printing this email

 

From: Oleksiy Stashok [[hidden email]]
Sent: Wednesday, January 28, 2015 9:46 AM
To: [hidden email]
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

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, 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: [hidden email]. 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: [hidden email]. 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: [hidden email]. Thank You.”