Quantcast

Problem using the Spring's AOP in Struts2's Actions with json-plugin

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problem using the Spring's AOP in Struts2's Actions with json-plugin

developer researcher
Hello,

I am using Strust 2 with spring-plugin and json-plugin to use: 

1. Injection of dependencies: apparently everything is working well.
2. Spring's AOP: works when applied over methods of injected objects in the Struts Actions but not when applied over methods of actions (my class extends from ActionSupport and I use the @Action annotation at method level)

This situation has generated the following questions:

1. Are the actions created and managed by Spring or Struts? It's supposed to be Spring, but I have this doubt because Spring's AOP is supposed to work on Spring beans but in my case it does not work and because I do not use the Spring's @Component annotation in the Action class

2. Is there a way to use Spring AOP in Struts2 Actions using the "JDK dynamic proxies"? I have tested with the following results:

a) When Spring uses "JDK dynamic proxies" the Struts2 Action is not executed and the following exception is thrown: NoSuchMethodException (see NoSuchMethodException.txt)
b) When Spring uses "CGLIB proxy" in an Action whose result is of the default type: the Action works correctly
c) When Spring uses "CGLIB proxy" in an Action whose result is of type json: the Struts2 Action is executed but the following exception is thrown: OperationNotSupportedException (see OperationNotSupportedException.txt). When I do not use AOP this Action works correctly.

Thanks


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

NoSuchMethodException.txt (9K) Download Attachment
OperationNotSupportedException.txt (21K) Download Attachment
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem using the Spring's AOP in Struts2's Actions with json-plugin

Martin Gainty
MG>below

________________________________
From: developer researcher <[hidden email]>
Sent: Friday, May 5, 2017 10:09 PM
To: Struts Users Mailing List
Subject: Problem using the Spring's AOP in Struts2's Actions with json-plugin

Hello,

I am using Strust 2 <sp?> with spring-plugin and json-plugin to use:

1. Injection of dependencies: apparently everything is working well.
2. Spring's AOP: works when applied over methods of injected objects in the Struts Actions but not when applied over methods of actions (my class extends from ActionSupport and I use the @Action annotation at method level)

MG>spring does not know what ActionSupport as it is a Struts classes besides which ActionSupport are not considered
MG>spring beans which are simple pojos with a no-arg constructor
https://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html
7. The IoC container - Spring<https://docs.spring.io/spring/docs/current/spring-framework-reference/html/beans.html>
docs.spring.io
As the preceding diagram shows, the Spring IoC container consumes a form of configuration metadata; this configuration metadata represents how you as an application ...


This situation has generated the following questions:

1. Are the actions created and managed by Spring or Struts? It's supposed to be Spring, but I have this doubt because Spring's AOP is supposed to work on Spring beans but in my case it does not work and because I do not use the Spring's @Component annotation in the Action class

MG>correct but you can also specify a spring-bean in spring-beans.xml in your classpath e.g.:
<bean id="springTest" name="springTest" class="org.struts.SpringTest"/>

2. Is there a way to use Spring AOP in Struts2 Actions using the "JDK dynamic proxies"? I have tested with the following results:

a) When Spring uses "JDK dynamic proxies" the Struts2 Action is not executed and the following exception is thrown: NoSuchMethodException (see NoSuchMethodException.txt)
b) When Spring uses "CGLIB proxy" in an Action whose result is of the default type: the Action works correctly
c) When Spring uses "CGLIB proxy" in an Action whose result is of type json: the Struts2 Action is executed but the following exception is thrown: OperationNotSupportedException (see OperationNotSupportedException.txt). When I do not use AOP this Action works correctly.

MG>builder.bind does not recognise json result-set as a valid javax.sql.DataSource..here is an example of builder.bind
 org.springframework.mock.jndi.SimpleNamingContextBuilder builder = new org.springframework.mock.jndi.SimpleNamingContextBuilder();
 * DataSource ds = new org.springframework.jdbc.datasource.DriverManagerDataSource(...);
 * builder.bind("java:comp/env/jdbc/myds", ds);

MG>as of now JSON is not a valid javax.sql.DataSourceHere is Doc:
<p>In a J2EE container, it is recommended to use a JNDI DataSource provided by
 * the container. Such a javax.sql.DataSource can be exposed as a javax.sql.DataSource bean in a Spring
 * ApplicationContext via {@link org.springframework.jndi.JndiObjectFactoryBean},
 * for seamless switching to and from a local javax.sql.DataSource bean like this class.
 * For tests, you can then either set up a mock JNDI environment through Spring's
 * {@link org.springframework.mock.jndi.SimpleNamingContextBuilder}, or switch the
 * bean definition to a local javax.sql.DataSource(which is simpler and thus recommended).
 *
 * <p>If you need a "real" connection pool outside of a J2EE container, consider
 * <a href="http://commons.apache.org/proper/commons-dbcp">Apache Commons DBCP</a>
 * or <a href="http://sourceforge.net/projects/c3p0">C3P0</a>.
 * Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource are full
 * connection pool beans, supporting the same basic properties as this class
 * plus specific settings (such as minimal/maximal pool size etc).
mg>JSON is not yet a valid javax.sql.DataSource according to Spring

MG>also you have not declared a namespace that NamingContext can reference which is causing exception

MG>HTH

Thanks
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem using the Spring's AOP in Struts2's Actions with json-plugin

developer researcher
Hello Martin,

First of all thanks for the reply, but I'm not sure if my queries have been
understood. I am using Struts 2.5.10.1

My main query is: *Is there a way to use Spring AOP in Struts2 Actions
using the "JDK dynamic proxies"? Does anyone have an example?*

Sorry, but I can not find any relationship between your answers and the
exceptions attached in my previous message:

*1. NoSuchMethodException:* The code I'm testing does not have anything
from javax.sql.DataSource

*2. OperationNotSupportedException:* Without using AOP there is no
exception for some namespace. This is very strange because the code in the
advice is simply "System.out.println ()" for testing purposes.

Thanks


2017-05-06 8:21 GMT-05:00 Martin Gainty <[hidden email]>:

> MG>below
>
> ________________________________
> From: developer researcher <[hidden email]>
> Sent: Friday, May 5, 2017 10:09 PM
> To: Struts Users Mailing List
> Subject: Problem using the Spring's AOP in Struts2's Actions with
> json-plugin
>
> Hello,
>
> I am using Strust 2 <sp?> with spring-plugin and json-plugin to use:
>
> 1. Injection of dependencies: apparently everything is working well.
> 2. Spring's AOP: works when applied over methods of injected objects in
> the Struts Actions but not when applied over methods of actions (my class
> extends from ActionSupport and I use the @Action annotation at method level)
>
> MG>spring does not know what ActionSupport as it is a Struts classes
> besides which ActionSupport are not considered
> MG>spring beans which are simple pojos with a no-arg constructor
> https://docs.spring.io/spring/docs/current/spring-framework-
> reference/html/beans.html
> 7. The IoC container - Spring<https://docs.spring.io/
> spring/docs/current/spring-framework-reference/html/beans.html>
> docs.spring.io
> As the preceding diagram shows, the Spring IoC container consumes a form
> of configuration metadata; this configuration metadata represents how you
> as an application ...
>
>
> This situation has generated the following questions:
>
> 1. Are the actions created and managed by Spring or Struts? It's supposed
> to be Spring, but I have this doubt because Spring's AOP is supposed to
> work on Spring beans but in my case it does not work and because I do not
> use the Spring's @Component annotation in the Action class
>
> MG>correct but you can also specify a spring-bean in spring-beans.xml in
> your classpath e.g.:
> <bean id="springTest" name="springTest" class="org.struts.SpringTest"/>
>
> 2. Is there a way to use Spring AOP in Struts2 Actions using the "JDK
> dynamic proxies"? I have tested with the following results:
>
> a) When Spring uses "JDK dynamic proxies" the Struts2 Action is not
> executed and the following exception is thrown: NoSuchMethodException (see
> NoSuchMethodException.txt)
> b) When Spring uses "CGLIB proxy" in an Action whose result is of the
> default type: the Action works correctly
> c) When Spring uses "CGLIB proxy" in an Action whose result is of type
> json: the Struts2 Action is executed but the following exception is thrown:
> OperationNotSupportedException (see OperationNotSupportedException.txt).
> When I do not use AOP this Action works correctly.
>
> MG>builder.bind does not recognise json result-set as a valid
> javax.sql.DataSource..here is an example of builder.bind
>  org.springframework.mock.jndi.SimpleNamingContextBuilder builder = new
> org.springframework.mock.jndi.SimpleNamingContextBuilder();
>  * DataSource ds = new org.springframework.jdbc.datasource.
> DriverManagerDataSource(...);
>  * builder.bind("java:comp/env/jdbc/myds", ds);
>
> MG>as of now JSON is not a valid javax.sql.DataSourceHere is Doc:
> <p>In a J2EE container, it is recommended to use a JNDI DataSource
> provided by
>  * the container. Such a javax.sql.DataSource can be exposed as a
> javax.sql.DataSource bean in a Spring
>  * ApplicationContext via {@link org.springframework.jndi.
> JndiObjectFactoryBean},
>  * for seamless switching to and from a local javax.sql.DataSource bean
> like this class.
>  * For tests, you can then either set up a mock JNDI environment through
> Spring's
>  * {@link org.springframework.mock.jndi.SimpleNamingContextBuilder}, or
> switch the
>  * bean definition to a local javax.sql.DataSource(which is simpler and
> thus recommended).
>  *
>  * <p>If you need a "real" connection pool outside of a J2EE container,
> consider
>  * <a href="http://commons.apache.org/proper/commons-dbcp">Apache Commons
> DBCP</a>
>  * or <a href="http://sourceforge.net/projects/c3p0">C3P0</a>.
>  * Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource are full
>  * connection pool beans, supporting the same basic properties as this
> class
>  * plus specific settings (such as minimal/maximal pool size etc).
> mg>JSON is not yet a valid javax.sql.DataSource according to Spring
>
> MG>also you have not declared a namespace that NamingContext can reference
> which is causing exception
>
> MG>HTH
>
> Thanks
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem using the Spring's AOP in Struts2's Actions with json-plugin

adam brin
Hi,

I presume you’ve read this: https://struts.apache.org/docs/json-plugin.html#JSONPlugin-Proxiedobjects

It may be that the issue is not Struts2, but the JSON library that the Struts2 Json plugin uses… and thus, you may need to handle the JSON serialization using Jackson or another library.


- adam
--
_________________________________________________________
Adam Brin
Director of Technology, Digital Antiquity
480.965.1278

> On May 8, 2017, at 12:27 PM, developer researcher <[hidden email]> wrote:
>
> Hello Martin,
>
> First of all thanks for the reply, but I'm not sure if my queries have been
> understood. I am using Struts 2.5.10.1
>
> My main query is: *Is there a way to use Spring AOP in Struts2 Actions
> using the "JDK dynamic proxies"? Does anyone have an example?*
>
> Sorry, but I can not find any relationship between your answers and the
> exceptions attached in my previous message:
>
> *1. NoSuchMethodException:* The code I'm testing does not have anything
> from javax.sql.DataSource
>
> *2. OperationNotSupportedException:* Without using AOP there is no
> exception for some namespace. This is very strange because the code in the
> advice is simply "System.out.println ()" for testing purposes.
>
> Thanks
>
>
> 2017-05-06 8:21 GMT-05:00 Martin Gainty <[hidden email]>:
>
>> MG>below
>>
>> ________________________________
>> From: developer researcher <[hidden email]>
>> Sent: Friday, May 5, 2017 10:09 PM
>> To: Struts Users Mailing List
>> Subject: Problem using the Spring's AOP in Struts2's Actions with
>> json-plugin
>>
>> Hello,
>>
>> I am using Strust 2 <sp?> with spring-plugin and json-plugin to use:
>>
>> 1. Injection of dependencies: apparently everything is working well.
>> 2. Spring's AOP: works when applied over methods of injected objects in
>> the Struts Actions but not when applied over methods of actions (my class
>> extends from ActionSupport and I use the @Action annotation at method level)
>>
>> MG>spring does not know what ActionSupport as it is a Struts classes
>> besides which ActionSupport are not considered
>> MG>spring beans which are simple pojos with a no-arg constructor
>> https://docs.spring.io/spring/docs/current/spring-framework-
>> reference/html/beans.html
>> 7. The IoC container - Spring<https://docs.spring.io/
>> spring/docs/current/spring-framework-reference/html/beans.html>
>> docs.spring.io
>> As the preceding diagram shows, the Spring IoC container consumes a form
>> of configuration metadata; this configuration metadata represents how you
>> as an application ...
>>
>>
>> This situation has generated the following questions:
>>
>> 1. Are the actions created and managed by Spring or Struts? It's supposed
>> to be Spring, but I have this doubt because Spring's AOP is supposed to
>> work on Spring beans but in my case it does not work and because I do not
>> use the Spring's @Component annotation in the Action class
>>
>> MG>correct but you can also specify a spring-bean in spring-beans.xml in
>> your classpath e.g.:
>> <bean id="springTest" name="springTest" class="org.struts.SpringTest"/>
>>
>> 2. Is there a way to use Spring AOP in Struts2 Actions using the "JDK
>> dynamic proxies"? I have tested with the following results:
>>
>> a) When Spring uses "JDK dynamic proxies" the Struts2 Action is not
>> executed and the following exception is thrown: NoSuchMethodException (see
>> NoSuchMethodException.txt)
>> b) When Spring uses "CGLIB proxy" in an Action whose result is of the
>> default type: the Action works correctly
>> c) When Spring uses "CGLIB proxy" in an Action whose result is of type
>> json: the Struts2 Action is executed but the following exception is thrown:
>> OperationNotSupportedException (see OperationNotSupportedException.txt).
>> When I do not use AOP this Action works correctly.
>>
>> MG>builder.bind does not recognise json result-set as a valid
>> javax.sql.DataSource..here is an example of builder.bind
>> org.springframework.mock.jndi.SimpleNamingContextBuilder builder = new
>> org.springframework.mock.jndi.SimpleNamingContextBuilder();
>> * DataSource ds = new org.springframework.jdbc.datasource.
>> DriverManagerDataSource(...);
>> * builder.bind("java:comp/env/jdbc/myds", ds);
>>
>> MG>as of now JSON is not a valid javax.sql.DataSourceHere is Doc:
>> <p>In a J2EE container, it is recommended to use a JNDI DataSource
>> provided by
>> * the container. Such a javax.sql.DataSource can be exposed as a
>> javax.sql.DataSource bean in a Spring
>> * ApplicationContext via {@link org.springframework.jndi.
>> JndiObjectFactoryBean},
>> * for seamless switching to and from a local javax.sql.DataSource bean
>> like this class.
>> * For tests, you can then either set up a mock JNDI environment through
>> Spring's
>> * {@link org.springframework.mock.jndi.SimpleNamingContextBuilder}, or
>> switch the
>> * bean definition to a local javax.sql.DataSource(which is simpler and
>> thus recommended).
>> *
>> * <p>If you need a "real" connection pool outside of a J2EE container,
>> consider
>> * <a href="http://commons.apache.org/proper/commons-dbcp">Apache Commons
>> DBCP</a>
>> * or <a href="http://sourceforge.net/projects/c3p0">C3P0</a>.
>> * Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource are full
>> * connection pool beans, supporting the same basic properties as this
>> class
>> * plus specific settings (such as minimal/maximal pool size etc).
>> mg>JSON is not yet a valid javax.sql.DataSource according to Spring
>>
>> MG>also you have not declared a namespace that NamingContext can reference
>> which is causing exception
>>
>> MG>HTH
>>
>> Thanks
>>


---------------------------------------------------------------------
To unsubscribe, e-mail: [hidden email]
For additional commands, e-mail: [hidden email]

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem using the Spring's AOP in Struts2's Actions with json-plugin

developer researcher
Hello Adam,

Yes, I am using the "ignoreInterfaces" param set to "false". My result is:
"@Result(name="success",type="json", params={"contentType", "text/html",
"ignoreInterfaces", "false"})"

The file "struts-2.5.10.1-all.zip" contains the jackson's jars, so I guess
the json-plugin use jackson.In any case, how would you use your own
serialization instead of the provided by json-plugin for actions that need
AOP?

In new tests, the problem is focused on actions with a json result.

*1. For **results of **default **type:* If the class extends ActionSupport,
it is necessary to use "CGLIB proxy", if the class does not extend from
ActionSupport it is possible to use both "CGLIB proxy" and "JDK dynamic
proxy".
*2. For results of json **type **:* without AOP everything works fine, with
AOP both using "JDK dynamic proxy" and "CGLIB proxy" the action is
executed, the advice also but in both cases occurs the
OperationNotSupportedException

Thanks


2017-05-08 15:50 GMT-05:00 Adam Brin <[hidden email]>:

> Hi,
>
> I presume you’ve read this: https://struts.apache.org/
> docs/json-plugin.html#JSONPlugin-Proxiedobjects
>
> It may be that the issue is not Struts2, but the JSON library that the
> Struts2 Json plugin uses… and thus, you may need to handle the JSON
> serialization using Jackson or another library.
>
>
> - adam
> --
> _________________________________________________________
> Adam Brin
> Director of Technology, Digital Antiquity
> 480.965.1278
>
> > On May 8, 2017, at 12:27 PM, developer researcher <
> [hidden email]> wrote:
> >
> > Hello Martin,
> >
> > First of all thanks for the reply, but I'm not sure if my queries have
> been
> > understood. I am using Struts 2.5.10.1
> >
> > My main query is: *Is there a way to use Spring AOP in Struts2 Actions
> > using the "JDK dynamic proxies"? Does anyone have an example?*
> >
> > Sorry, but I can not find any relationship between your answers and the
> > exceptions attached in my previous message:
> >
> > *1. NoSuchMethodException:* The code I'm testing does not have anything
> > from javax.sql.DataSource
> >
> > *2. OperationNotSupportedException:* Without using AOP there is no
> > exception for some namespace. This is very strange because the code in
> the
> > advice is simply "System.out.println ()" for testing purposes.
> >
> > Thanks
> >
> >
> > 2017-05-06 8:21 GMT-05:00 Martin Gainty <[hidden email]>:
> >
> >> MG>below
> >>
> >> ________________________________
> >> From: developer researcher <[hidden email]>
> >> Sent: Friday, May 5, 2017 10:09 PM
> >> To: Struts Users Mailing List
> >> Subject: Problem using the Spring's AOP in Struts2's Actions with
> >> json-plugin
> >>
> >> Hello,
> >>
> >> I am using Strust 2 <sp?> with spring-plugin and json-plugin to use:
> >>
> >> 1. Injection of dependencies: apparently everything is working well.
> >> 2. Spring's AOP: works when applied over methods of injected objects in
> >> the Struts Actions but not when applied over methods of actions (my
> class
> >> extends from ActionSupport and I use the @Action annotation at method
> level)
> >>
> >> MG>spring does not know what ActionSupport as it is a Struts classes
> >> besides which ActionSupport are not considered
> >> MG>spring beans which are simple pojos with a no-arg constructor
> >> https://docs.spring.io/spring/docs/current/spring-framework-
> >> reference/html/beans.html
> >> 7. The IoC container - Spring<https://docs.spring.io/
> >> spring/docs/current/spring-framework-reference/html/beans.html>
> >> docs.spring.io
> >> As the preceding diagram shows, the Spring IoC container consumes a form
> >> of configuration metadata; this configuration metadata represents how
> you
> >> as an application ...
> >>
> >>
> >> This situation has generated the following questions:
> >>
> >> 1. Are the actions created and managed by Spring or Struts? It's
> supposed
> >> to be Spring, but I have this doubt because Spring's AOP is supposed to
> >> work on Spring beans but in my case it does not work and because I do
> not
> >> use the Spring's @Component annotation in the Action class
> >>
> >> MG>correct but you can also specify a spring-bean in spring-beans.xml in
> >> your classpath e.g.:
> >> <bean id="springTest" name="springTest" class="org.struts.SpringTest"/>
> >>
> >> 2. Is there a way to use Spring AOP in Struts2 Actions using the "JDK
> >> dynamic proxies"? I have tested with the following results:
> >>
> >> a) When Spring uses "JDK dynamic proxies" the Struts2 Action is not
> >> executed and the following exception is thrown: NoSuchMethodException
> (see
> >> NoSuchMethodException.txt)
> >> b) When Spring uses "CGLIB proxy" in an Action whose result is of the
> >> default type: the Action works correctly
> >> c) When Spring uses "CGLIB proxy" in an Action whose result is of type
> >> json: the Struts2 Action is executed but the following exception is
> thrown:
> >> OperationNotSupportedException (see OperationNotSupportedException
> .txt).
> >> When I do not use AOP this Action works correctly.
> >>
> >> MG>builder.bind does not recognise json result-set as a valid
> >> javax.sql.DataSource..here is an example of builder.bind
> >> org.springframework.mock.jndi.SimpleNamingContextBuilder builder = new
> >> org.springframework.mock.jndi.SimpleNamingContextBuilder();
> >> * DataSource ds = new org.springframework.jdbc.datasource.
> >> DriverManagerDataSource(...);
> >> * builder.bind("java:comp/env/jdbc/myds", ds);
> >>
> >> MG>as of now JSON is not a valid javax.sql.DataSourceHere is Doc:
> >> <p>In a J2EE container, it is recommended to use a JNDI DataSource
> >> provided by
> >> * the container. Such a javax.sql.DataSource can be exposed as a
> >> javax.sql.DataSource bean in a Spring
> >> * ApplicationContext via {@link org.springframework.jndi.
> >> JndiObjectFactoryBean},
> >> * for seamless switching to and from a local javax.sql.DataSource bean
> >> like this class.
> >> * For tests, you can then either set up a mock JNDI environment through
> >> Spring's
> >> * {@link org.springframework.mock.jndi.SimpleNamingContextBuilder}, or
> >> switch the
> >> * bean definition to a local javax.sql.DataSource(which is simpler and
> >> thus recommended).
> >> *
> >> * <p>If you need a "real" connection pool outside of a J2EE container,
> >> consider
> >> * <a href="http://commons.apache.org/proper/commons-dbcp">Apache
> Commons
> >> DBCP</a>
> >> * or <a href="http://sourceforge.net/projects/c3p0">C3P0</a>.
> >> * Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource are
> full
> >> * connection pool beans, supporting the same basic properties as this
> >> class
> >> * plus specific settings (such as minimal/maximal pool size etc).
> >> mg>JSON is not yet a valid javax.sql.DataSource according to Spring
> >>
> >> MG>also you have not declared a namespace that NamingContext can
> reference
> >> which is causing exception
> >>
> >> MG>HTH
> >>
> >> Thanks
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem using the Spring's AOP in Struts2's Actions with json-plugin

adam brin
We just set content-type to application json and output a stream or a
string.  In the action, I just convert the object to a stream.

But, here's the question:  does your spring AOP proxy work properly with
Jackson outside of struts2?



On Mon, May 8, 2017 at 7:14 PM, developer researcher <
[hidden email]> wrote:

> Hello Adam,
>
> Yes, I am using the "ignoreInterfaces" param set to "false". My result is:
> "@Result(name="success",type="json", params={"contentType", "text/html",
> "ignoreInterfaces", "false"})"
>
> The file "struts-2.5.10.1-all.zip" contains the jackson's jars, so I guess
> the json-plugin use jackson.In any case, how would you use your own
> serialization instead of the provided by json-plugin for actions that need
> AOP?
>
> In new tests, the problem is focused on actions with a json result.
>
> *1. For **results of **default **type:* If the class extends ActionSupport,
> it is necessary to use "CGLIB proxy", if the class does not extend from
> ActionSupport it is possible to use both "CGLIB proxy" and "JDK dynamic
> proxy".
> *2. For results of json **type **:* without AOP everything works fine, with
> AOP both using "JDK dynamic proxy" and "CGLIB proxy" the action is
> executed, the advice also but in both cases occurs the
> OperationNotSupportedException
>
> Thanks
>
>
> 2017-05-08 15:50 GMT-05:00 Adam Brin <[hidden email]>:
>
> > Hi,
> >
> > I presume you’ve read this: https://struts.apache.org/
> > docs/json-plugin.html#JSONPlugin-Proxiedobjects
> >
> > It may be that the issue is not Struts2, but the JSON library that the
> > Struts2 Json plugin uses… and thus, you may need to handle the JSON
> > serialization using Jackson or another library.
> >
> >
> > - adam
> > --
> > _________________________________________________________
> > Adam Brin
> > Director of Technology, Digital Antiquity
> > 480.965.1278
> >
> > > On May 8, 2017, at 12:27 PM, developer researcher <
> > [hidden email]> wrote:
> > >
> > > Hello Martin,
> > >
> > > First of all thanks for the reply, but I'm not sure if my queries have
> > been
> > > understood. I am using Struts 2.5.10.1
> > >
> > > My main query is: *Is there a way to use Spring AOP in Struts2 Actions
> > > using the "JDK dynamic proxies"? Does anyone have an example?*
> > >
> > > Sorry, but I can not find any relationship between your answers and the
> > > exceptions attached in my previous message:
> > >
> > > *1. NoSuchMethodException:* The code I'm testing does not have anything
> > > from javax.sql.DataSource
> > >
> > > *2. OperationNotSupportedException:* Without using AOP there is no
> > > exception for some namespace. This is very strange because the code in
> > the
> > > advice is simply "System.out.println ()" for testing purposes.
> > >
> > > Thanks
> > >
> > >
> > > 2017-05-06 8:21 GMT-05:00 Martin Gainty <[hidden email]>:
> > >
> > >> MG>below
> > >>
> > >> ________________________________
> > >> From: developer researcher <[hidden email]>
> > >> Sent: Friday, May 5, 2017 10:09 PM
> > >> To: Struts Users Mailing List
> > >> Subject: Problem using the Spring's AOP in Struts2's Actions with
> > >> json-plugin
> > >>
> > >> Hello,
> > >>
> > >> I am using Strust 2 <sp?> with spring-plugin and json-plugin to use:
> > >>
> > >> 1. Injection of dependencies: apparently everything is working well.
> > >> 2. Spring's AOP: works when applied over methods of injected objects
> in
> > >> the Struts Actions but not when applied over methods of actions (my
> > class
> > >> extends from ActionSupport and I use the @Action annotation at method
> > level)
> > >>
> > >> MG>spring does not know what ActionSupport as it is a Struts classes
> > >> besides which ActionSupport are not considered
> > >> MG>spring beans which are simple pojos with a no-arg constructor
> > >> https://docs.spring.io/spring/docs/current/spring-framework-
> > >> reference/html/beans.html
> > >> 7. The IoC container - Spring<https://docs.spring.io/
> > >> spring/docs/current/spring-framework-reference/html/beans.html>
> > >> docs.spring.io
> > >> As the preceding diagram shows, the Spring IoC container consumes a
> form
> > >> of configuration metadata; this configuration metadata represents how
> > you
> > >> as an application ...
> > >>
> > >>
> > >> This situation has generated the following questions:
> > >>
> > >> 1. Are the actions created and managed by Spring or Struts? It's
> > supposed
> > >> to be Spring, but I have this doubt because Spring's AOP is supposed
> to
> > >> work on Spring beans but in my case it does not work and because I do
> > not
> > >> use the Spring's @Component annotation in the Action class
> > >>
> > >> MG>correct but you can also specify a spring-bean in spring-beans.xml
> in
> > >> your classpath e.g.:
> > >> <bean id="springTest" name="springTest" class="org.struts.SpringTest"/
> >
> > >>
> > >> 2. Is there a way to use Spring AOP in Struts2 Actions using the "JDK
> > >> dynamic proxies"? I have tested with the following results:
> > >>
> > >> a) When Spring uses "JDK dynamic proxies" the Struts2 Action is not
> > >> executed and the following exception is thrown: NoSuchMethodException
> > (see
> > >> NoSuchMethodException.txt)
> > >> b) When Spring uses "CGLIB proxy" in an Action whose result is of the
> > >> default type: the Action works correctly
> > >> c) When Spring uses "CGLIB proxy" in an Action whose result is of type
> > >> json: the Struts2 Action is executed but the following exception is
> > thrown:
> > >> OperationNotSupportedException (see OperationNotSupportedException
> > .txt).
> > >> When I do not use AOP this Action works correctly.
> > >>
> > >> MG>builder.bind does not recognise json result-set as a valid
> > >> javax.sql.DataSource..here is an example of builder.bind
> > >> org.springframework.mock.jndi.SimpleNamingContextBuilder builder =
> new
> > >> org.springframework.mock.jndi.SimpleNamingContextBuilder();
> > >> * DataSource ds = new org.springframework.jdbc.datasource.
> > >> DriverManagerDataSource(...);
> > >> * builder.bind("java:comp/env/jdbc/myds", ds);
> > >>
> > >> MG>as of now JSON is not a valid javax.sql.DataSourceHere is Doc:
> > >> <p>In a J2EE container, it is recommended to use a JNDI DataSource
> > >> provided by
> > >> * the container. Such a javax.sql.DataSource can be exposed as a
> > >> javax.sql.DataSource bean in a Spring
> > >> * ApplicationContext via {@link org.springframework.jndi.
> > >> JndiObjectFactoryBean},
> > >> * for seamless switching to and from a local javax.sql.DataSource bean
> > >> like this class.
> > >> * For tests, you can then either set up a mock JNDI environment
> through
> > >> Spring's
> > >> * {@link org.springframework.mock.jndi.SimpleNamingContextBuilder},
> or
> > >> switch the
> > >> * bean definition to a local javax.sql.DataSource(which is simpler and
> > >> thus recommended).
> > >> *
> > >> * <p>If you need a "real" connection pool outside of a J2EE container,
> > >> consider
> > >> * <a href="http://commons.apache.org/proper/commons-dbcp">Apache
> > Commons
> > >> DBCP</a>
> > >> * or <a href="http://sourceforge.net/projects/c3p0">C3P0</a>.
> > >> * Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource are
> > full
> > >> * connection pool beans, supporting the same basic properties as this
> > >> class
> > >> * plus specific settings (such as minimal/maximal pool size etc).
> > >> mg>JSON is not yet a valid javax.sql.DataSource according to Spring
> > >>
> > >> MG>also you have not declared a namespace that NamingContext can
> > reference
> > >> which is causing exception
> > >>
> > >> MG>HTH
> > >>
> > >> Thanks
> > >>
> >
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [hidden email]
> > For additional commands, e-mail: [hidden email]
> >
> >
>



--
_________________________________________________________
Adam Brin
Director of Technology, Digital Antiquity
480.965.1278
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem using the Spring's AOP in Struts2's Actions with json-plugin

Martin Gainty
In reply to this post by developer researcher
MG>below

________________________________
From: developer researcher <[hidden email]>
Sent: Monday, May 8, 2017 10:14 PM
To: Struts Users Mailing List
Subject: Re: Problem using the Spring's AOP in Struts2's Actions with json-plugin

Hello Adam,

Yes, I am using the "ignoreInterfaces" param set to "false". My result is:
"@Result(name="success",type="json", params={"contentType", "text/html",
"ignoreInterfaces", "false"})"

The file "struts-2.5.10.1-all.zip" contains the jackson's jars, so I guess
the json-plugin use jackson.In any case, how would you use your own
serialization instead of the provided by json-plugin for actions that need
AOP?

MG>i was perusing Jackson when i came upon JSON deserialization issue  for JsonType.defaultImpl
https://github.com/FasterXML/jackson-databind/issues/1083
[https://avatars2.githubusercontent.com/u/1130553?v=3&s=400]<https://github.com/FasterXML/jackson-databind/issues/1083>

Field in base class is not recognized, when using ...<https://github.com/FasterXML/jackson-databind/issues/1083>
github.com
When deserializing JSON to Java POJOS, a field inherited from a base class is not recognized. Here is the stack: com.fasterxml.jackson.databind.exc ...

MG>which is manifested only in Jackson 2.7.0..more importantly does current Jackson codebase care about JsonType.defaultImpl issue?
MG>apparently yes as i see this comment in com.fasterxml.jackson.databind.ser.std.StdJdkSerializers
        // 09-Jan-2015, tatu: As per [databind#1073], let's try to guard against possibility
        //   of some environments missing `java.sql.` types
MG>in the case of when com.fasterxml.jackson.annotation.JsonTypeInfo references a Class for reflection instead of a declared type a
MG>OperationNotSupportedException is thrown

MG>in any case the jackson fix for #1073 JsonType.defaultImpl is supposedly in one of the 2.8.x versions @
MG>https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.8
[https://avatars3.githubusercontent.com/u/382692?v=3&s=400]<https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.8>

Jackson Release 2.8 · FasterXML/jackson Wiki · GitHub<https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.8>
github.com
jackson - Main Portal page for Jackson project ... Version 2.8 was released 4th of July, 2016. Patches. Beyond initial 2.8.0 (described here), following patch ...


[https://avatars3.githubusercontent.com/u/382692?v=3&s=400]<https://github.com/FasterXML/jackson-databind>

GitHub - FasterXML/jackson-databind: General data-binding ...<https://github.com/FasterXML/jackson-databind>
github.com
jackson-databind - General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)

MG>which i could not find...i would revert to jackson-2.6.3
MG>this wont coerce the jackson datatype to Spring java.sql type for bind operation but one it should at least fix the jackson error

In new tests, the problem is focused on actions with a json result.

*1. For **results of **default **type:* If the class extends ActionSupport,
it is necessary to use "CGLIB proxy", if the class does not extend from
ActionSupport it is possible to use both "CGLIB proxy" and "JDK dynamic
proxy".
*2. For results of json **type **:* without AOP everything works fine, with
AOP both using "JDK dynamic proxy" and "CGLIB proxy" the action is
executed, the advice also but in both cases occurs the
OperationNotSupportedException

MG>yes in later jdks that support JDK Dynamic Proxy you should not proxy the class
MG>but allow JDKDynamicProxy to instantiate using the declared "type"
MG>(provided the lookup on type is successful)

Thanks


2017-05-08 15:50 GMT-05:00 Adam Brin <[hidden email]>:

> Hi,
>
> I presume you’ve read this: https://struts.apache.org/
Welcome to the Apache Struts project<https://struts.apache.org/>
struts.apache.org
Google's Patch Reward program. During SFHTML5 Google announced that they extend their program to cover the Apache Struts project as well.



> docs/json-plugin.html#JSONPlugin-Proxiedobjects
>
> It may be that the issue is not Struts2, but the JSON library that the
> Struts2 Json plugin uses… and thus, you may need to handle the JSON
> serialization using Jackson or another library.
>
>
> - adam
> --
> _________________________________________________________
> Adam Brin
> Director of Technology, Digital Antiquity
> 480.965.1278
>
> > On May 8, 2017, at 12:27 PM, developer researcher <
> [hidden email]> wrote:
> >
> > Hello Martin,
> >
> > First of all thanks for the reply, but I'm not sure if my queries have
> been
> > understood. I am using Struts 2.5.10.1
> >
> > My main query is: *Is there a way to use Spring AOP in Struts2 Actions
> > using the "JDK dynamic proxies"? Does anyone have an example?*
> >
> > Sorry, but I can not find any relationship between your answers and the
> > exceptions attached in my previous message:
> >
> > *1. NoSuchMethodException:* The code I'm testing does not have anything
> > from javax.sql.DataSource
> >
> > *2. OperationNotSupportedException:* Without using AOP there is no
> > exception for some namespace. This is very strange because the code in
> the
> > advice is simply "System.out.println ()" for testing purposes.
> >
> > Thanks
> >
> >
> > 2017-05-06 8:21 GMT-05:00 Martin Gainty <[hidden email]>:
> >
> >> MG>below
> >>
> >> ________________________________
> >> From: developer researcher <[hidden email]>
> >> Sent: Friday, May 5, 2017 10:09 PM
> >> To: Struts Users Mailing List
> >> Subject: Problem using the Spring's AOP in Struts2's Actions with
> >> json-plugin
> >>
> >> Hello,
> >>
> >> I am using Strust 2 <sp?> with spring-plugin and json-plugin to use:
> >>
> >> 1. Injection of dependencies: apparently everything is working well.
> >> 2. Spring's AOP: works when applied over methods of injected objects in
> >> the Struts Actions but not when applied over methods of actions (my
> class
> >> extends from ActionSupport and I use the @Action annotation at method
> level)
> >>
> >> MG>spring does not know what ActionSupport as it is a Struts classes
> >> besides which ActionSupport are not considered
> >> MG>spring beans which are simple pojos with a no-arg constructor
> >> https://docs.spring.io/spring/docs/current/spring-framework-
> >> reference/html/beans.html
> >> 7. The IoC container - Spring<https://docs.spring.io/
> >> spring/docs/current/spring-framework-reference/html/beans.html>
> >> docs.spring.io
> >> As the preceding diagram shows, the Spring IoC container consumes a form
> >> of configuration metadata; this configuration metadata represents how
> you
> >> as an application ...
> >>
> >>
> >> This situation has generated the following questions:
> >>
> >> 1. Are the actions created and managed by Spring or Struts? It's
> supposed
> >> to be Spring, but I have this doubt because Spring's AOP is supposed to
> >> work on Spring beans but in my case it does not work and because I do
> not
> >> use the Spring's @Component annotation in the Action class
> >>
> >> MG>correct but you can also specify a spring-bean in spring-beans.xml in
> >> your classpath e.g.:
> >> <bean id="springTest" name="springTest" class="org.struts.SpringTest"/>
> >>
> >> 2. Is there a way to use Spring AOP in Struts2 Actions using the "JDK
> >> dynamic proxies"? I have tested with the following results:
> >>
> >> a) When Spring uses "JDK dynamic proxies" the Struts2 Action is not
> >> executed and the following exception is thrown: NoSuchMethodException
> (see
> >> NoSuchMethodException.txt)
> >> b) When Spring uses "CGLIB proxy" in an Action whose result is of the
> >> default type: the Action works correctly
> >> c) When Spring uses "CGLIB proxy" in an Action whose result is of type
> >> json: the Struts2 Action is executed but the following exception is
> thrown:
> >> OperationNotSupportedException (see OperationNotSupportedException
> .txt).
> >> When I do not use AOP this Action works correctly.
> >>
> >> MG>builder.bind does not recognise json result-set as a valid
> >> javax.sql.DataSource..here is an example of builder.bind
> >> org.springframework.mock.jndi.SimpleNamingContextBuilder builder = new
> >> org.springframework.mock.jndi.SimpleNamingContextBuilder();
> >> * DataSource ds = new org.springframework.jdbc.datasource.
> >> DriverManagerDataSource(...);
> >> * builder.bind("java:comp/env/jdbc/myds", ds);
> >>
> >> MG>as of now JSON is not a valid javax.sql.DataSourceHere is Doc:
> >> <p>In a J2EE container, it is recommended to use a JNDI DataSource
> >> provided by
> >> * the container. Such a javax.sql.DataSource can be exposed as a
> >> javax.sql.DataSource bean in a Spring
> >> * ApplicationContext via {@link org.springframework.jndi.
> >> JndiObjectFactoryBean},
> >> * for seamless switching to and from a local javax.sql.DataSource bean
> >> like this class.
> >> * For tests, you can then either set up a mock JNDI environment through
> >> Spring's
> >> * {@link org.springframework.mock.jndi.SimpleNamingContextBuilder}, or
> >> switch the
> >> * bean definition to a local javax.sql.DataSource(which is simpler and
> >> thus recommended).
> >> *
> >> * <p>If you need a "real" connection pool outside of a J2EE container,
> >> consider
> >> * <a href="http://commons.apache.org/proper/commons-dbcp">Apache
> Commons
> >> DBCP</a>
> >> * or <a href="http://sourceforge.net/projects/c3p0">C3P0</a>.
> >> * Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource are
> full
> >> * connection pool beans, supporting the same basic properties as this
> >> class
> >> * plus specific settings (such as minimal/maximal pool size etc).
> >> mg>JSON is not yet a valid javax.sql.DataSource according to Spring
> >>
> >> MG>also you have not declared a namespace that NamingContext can
> reference
> >> which is causing exception
> >>
> >> MG>HTH
> >>
> >> Thanks
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem using the Spring's AOP in Struts2's Actions with json-plugin

developer researcher
In reply to this post by adam brin
Hi Adam,

I have not tried Jackson and the Spring AOP outside of Struts2. My context
is: modify a Struts web application (with spring-plugin and json-plugin) to
add some functionality (advices) through AOP. I would have to test in
another application to see if there is any problem between Jackson and
Spring AOP proxies.

On the other hand, when you say "*We just set content-type to application
json*" Are you using json-plugin? In my case I have used both "text/html"
and "application/json" (using json-plugin) but in both cases the
serialization is executed by json-plugin automatically.

According to the documentation, the results supported are
https://cwiki.apache.org/confluence/display/WW/Result+Types Have you
implemented a custom result?

Thanks


2017-05-08 21:38 GMT-05:00 Adam Brin <[hidden email]>:

> We just set content-type to application json and output a stream or a
> string.  In the action, I just convert the object to a stream.
>
> But, here's the question:  does your spring AOP proxy work properly with
> Jackson outside of struts2?
>
>
>
> On Mon, May 8, 2017 at 7:14 PM, developer researcher <
> [hidden email]> wrote:
>
> > Hello Adam,
> >
> > Yes, I am using the "ignoreInterfaces" param set to "false". My result
> is:
> > "@Result(name="success",type="json", params={"contentType", "text/html",
> > "ignoreInterfaces", "false"})"
> >
> > The file "struts-2.5.10.1-all.zip" contains the jackson's jars, so I
> guess
> > the json-plugin use jackson.In any case, how would you use your own
> > serialization instead of the provided by json-plugin for actions that
> need
> > AOP?
> >
> > In new tests, the problem is focused on actions with a json result.
> >
> > *1. For **results of **default **type:* If the class extends
> ActionSupport,
> > it is necessary to use "CGLIB proxy", if the class does not extend from
> > ActionSupport it is possible to use both "CGLIB proxy" and "JDK dynamic
> > proxy".
> > *2. For results of json **type **:* without AOP everything works fine,
> with
> > AOP both using "JDK dynamic proxy" and "CGLIB proxy" the action is
> > executed, the advice also but in both cases occurs the
> > OperationNotSupportedException
> >
> > Thanks
> >
> >
> > 2017-05-08 15:50 GMT-05:00 Adam Brin <[hidden email]>:
> >
> > > Hi,
> > >
> > > I presume you’ve read this: https://struts.apache.org/
> > > docs/json-plugin.html#JSONPlugin-Proxiedobjects
> > >
> > > It may be that the issue is not Struts2, but the JSON library that the
> > > Struts2 Json plugin uses… and thus, you may need to handle the JSON
> > > serialization using Jackson or another library.
> > >
> > >
> > > - adam
> > > --
> > > _________________________________________________________
> > > Adam Brin
> > > Director of Technology, Digital Antiquity
> > > 480.965.1278
> > >
> > > > On May 8, 2017, at 12:27 PM, developer researcher <
> > > [hidden email]> wrote:
> > > >
> > > > Hello Martin,
> > > >
> > > > First of all thanks for the reply, but I'm not sure if my queries
> have
> > > been
> > > > understood. I am using Struts 2.5.10.1
> > > >
> > > > My main query is: *Is there a way to use Spring AOP in Struts2
> Actions
> > > > using the "JDK dynamic proxies"? Does anyone have an example?*
> > > >
> > > > Sorry, but I can not find any relationship between your answers and
> the
> > > > exceptions attached in my previous message:
> > > >
> > > > *1. NoSuchMethodException:* The code I'm testing does not have
> anything
> > > > from javax.sql.DataSource
> > > >
> > > > *2. OperationNotSupportedException:* Without using AOP there is no
> > > > exception for some namespace. This is very strange because the code
> in
> > > the
> > > > advice is simply "System.out.println ()" for testing purposes.
> > > >
> > > > Thanks
> > > >
> > > >
> > > > 2017-05-06 8:21 GMT-05:00 Martin Gainty <[hidden email]>:
> > > >
> > > >> MG>below
> > > >>
> > > >> ________________________________
> > > >> From: developer researcher <[hidden email]>
> > > >> Sent: Friday, May 5, 2017 10:09 PM
> > > >> To: Struts Users Mailing List
> > > >> Subject: Problem using the Spring's AOP in Struts2's Actions with
> > > >> json-plugin
> > > >>
> > > >> Hello,
> > > >>
> > > >> I am using Strust 2 <sp?> with spring-plugin and json-plugin to use:
> > > >>
> > > >> 1. Injection of dependencies: apparently everything is working well.
> > > >> 2. Spring's AOP: works when applied over methods of injected objects
> > in
> > > >> the Struts Actions but not when applied over methods of actions (my
> > > class
> > > >> extends from ActionSupport and I use the @Action annotation at
> method
> > > level)
> > > >>
> > > >> MG>spring does not know what ActionSupport as it is a Struts classes
> > > >> besides which ActionSupport are not considered
> > > >> MG>spring beans which are simple pojos with a no-arg constructor
> > > >> https://docs.spring.io/spring/docs/current/spring-framework-
> > > >> reference/html/beans.html
> > > >> 7. The IoC container - Spring<https://docs.spring.io/
> > > >> spring/docs/current/spring-framework-reference/html/beans.html>
> > > >> docs.spring.io
> > > >> As the preceding diagram shows, the Spring IoC container consumes a
> > form
> > > >> of configuration metadata; this configuration metadata represents
> how
> > > you
> > > >> as an application ...
> > > >>
> > > >>
> > > >> This situation has generated the following questions:
> > > >>
> > > >> 1. Are the actions created and managed by Spring or Struts? It's
> > > supposed
> > > >> to be Spring, but I have this doubt because Spring's AOP is supposed
> > to
> > > >> work on Spring beans but in my case it does not work and because I
> do
> > > not
> > > >> use the Spring's @Component annotation in the Action class
> > > >>
> > > >> MG>correct but you can also specify a spring-bean in
> spring-beans.xml
> > in
> > > >> your classpath e.g.:
> > > >> <bean id="springTest" name="springTest"
> class="org.struts.SpringTest"/
> > >
> > > >>
> > > >> 2. Is there a way to use Spring AOP in Struts2 Actions using the
> "JDK
> > > >> dynamic proxies"? I have tested with the following results:
> > > >>
> > > >> a) When Spring uses "JDK dynamic proxies" the Struts2 Action is not
> > > >> executed and the following exception is thrown:
> NoSuchMethodException
> > > (see
> > > >> NoSuchMethodException.txt)
> > > >> b) When Spring uses "CGLIB proxy" in an Action whose result is of
> the
> > > >> default type: the Action works correctly
> > > >> c) When Spring uses "CGLIB proxy" in an Action whose result is of
> type
> > > >> json: the Struts2 Action is executed but the following exception is
> > > thrown:
> > > >> OperationNotSupportedException (see OperationNotSupportedException
> > > .txt).
> > > >> When I do not use AOP this Action works correctly.
> > > >>
> > > >> MG>builder.bind does not recognise json result-set as a valid
> > > >> javax.sql.DataSource..here is an example of builder.bind
> > > >> org.springframework.mock.jndi.SimpleNamingContextBuilder builder =
> > new
> > > >> org.springframework.mock.jndi.SimpleNamingContextBuilder();
> > > >> * DataSource ds = new org.springframework.jdbc.datasource.
> > > >> DriverManagerDataSource(...);
> > > >> * builder.bind("java:comp/env/jdbc/myds", ds);
> > > >>
> > > >> MG>as of now JSON is not a valid javax.sql.DataSourceHere is Doc:
> > > >> <p>In a J2EE container, it is recommended to use a JNDI DataSource
> > > >> provided by
> > > >> * the container. Such a javax.sql.DataSource can be exposed as a
> > > >> javax.sql.DataSource bean in a Spring
> > > >> * ApplicationContext via {@link org.springframework.jndi.
> > > >> JndiObjectFactoryBean},
> > > >> * for seamless switching to and from a local javax.sql.DataSource
> bean
> > > >> like this class.
> > > >> * For tests, you can then either set up a mock JNDI environment
> > through
> > > >> Spring's
> > > >> * {@link org.springframework.mock.jndi.SimpleNamingContextBuilder},
> > or
> > > >> switch the
> > > >> * bean definition to a local javax.sql.DataSource(which is simpler
> and
> > > >> thus recommended).
> > > >> *
> > > >> * <p>If you need a "real" connection pool outside of a J2EE
> container,
> > > >> consider
> > > >> * <a href="http://commons.apache.org/proper/commons-dbcp">Apache
> > > Commons
> > > >> DBCP</a>
> > > >> * or <a href="http://sourceforge.net/projects/c3p0">C3P0</a>.
> > > >> * Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource
> are
> > > full
> > > >> * connection pool beans, supporting the same basic properties as
> this
> > > >> class
> > > >> * plus specific settings (such as minimal/maximal pool size etc).
> > > >> mg>JSON is not yet a valid javax.sql.DataSource according to Spring
> > > >>
> > > >> MG>also you have not declared a namespace that NamingContext can
> > > reference
> > > >> which is causing exception
> > > >>
> > > >> MG>HTH
> > > >>
> > > >> Thanks
> > > >>
> > >
> > >
> > > ---------------------------------------------------------------------
> > > To unsubscribe, e-mail: [hidden email]
> > > For additional commands, e-mail: [hidden email]
> > >
> > >
> >
>
>
>
> --
> _________________________________________________________
> Adam Brin
> Director of Technology, Digital Antiquity
> 480.965.1278
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem using the Spring's AOP in Struts2's Actions with json-plugin

Martin Gainty
In reply to this post by Martin Gainty
MG>

here is an example which uses Springs AOP to set a interface to a AOP Context type

http://techqa.info/programming/question/29553557/issue-configuring-multiple-datasources-in-spring-data-jpa

first creates a context
populates context type with DataSource interface

this is of course predicated that jdbc/myapp will lookup successfully:

@Override
        protected void postProcessContext(Context context) {
            ContextResource appDBResource = new ContextResource();
            appDBResource.setName("jdbc/myapp");
            appDBResource.setType(DataSource.class.getName());

he identified his type to be DataSource interface
since DataSource is indeed an interface then Spring will create Aop-proxy with JdkDynamicAopProxy

at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:187)


DISPLAY CONVERSION:

provided you can  populate kendo #grid with ascii data from datasource jdbc/myapp

you can then use kendo magic to convert to JSON for html

kendo.stringify( $("#grid").data("kendoGrid").dataSource.view() );

http://www.telerik.com/forums/how-to-convert-datasource-to-json-to-send-back-to-a-mvc-controller

MG>

[http://www.telerik.com/sfimages/default-source/logos/telerik1200x630.png]<http://www.telerik.com/forums/how-to-convert-datasource-to-json-to-send-back-to-a-mvc-controller>

How to Convert dataSource to JSON to send back to a mvc ...<http://www.telerik.com/forums/how-to-convert-datasource-to-json-to-send-back-to-a-mvc-controller>
www.telerik.com
Forum thread about How to Convert dataSource to JSON to send back to a mvc controller? in Kendo UI. Join the conversation now.




Martin Gainty
______________________________________________

 _____ _          _____             _          _____     ___ _                        _____               _     _   _          |_   _| |_ ___   |  _  |___ ___ ___| |_ ___   |   __|___|  _| |_ _ _ _ ___ ___ ___   |   __|___ _ _ ___ _| |___| |_|_|___ ___    | | |   | -_|  |     | . | .'|  _|   | -_|  |__   | . |  _|  _| | | | .'|  _| -_|  |   __| . | | |   | . | .'|  _| | . |   |   |_| |_|_|___|  |__|__|  _|__,|___|_|_|___|  |_____|___|_| |_| |_____|__,|_| |___|  |__|  |___|___|_|_|___|__,|_| |_|___|_|_|                        |_|



________________________________
From: Martin Gainty <[hidden email]>
Sent: Tuesday, May 9, 2017 8:05 AM
To: Struts Users Mailing List
Subject: Re: Problem using the Spring's AOP in Struts2's Actions with json-plugin

MG>below

________________________________
From: developer researcher <[hidden email]>
Sent: Monday, May 8, 2017 10:14 PM
To: Struts Users Mailing List
Subject: Re: Problem using the Spring's AOP in Struts2's Actions with json-plugin

Hello Adam,

Yes, I am using the "ignoreInterfaces" param set to "false". My result is:
"@Result(name="success",type="json", params={"contentType", "text/html",
"ignoreInterfaces", "false"})"

The file "struts-2.5.10.1-all.zip" contains the jackson's jars, so I guess
the json-plugin use jackson.In any case, how would you use your own
serialization instead of the provided by json-plugin for actions that need
AOP?

MG>i was perusing Jackson when i came upon JSON deserialization issue  for JsonType.defaultImpl
https://github.com/FasterXML/jackson-databind/issues/1083
[https://avatars2.githubusercontent.com/u/1130553?v=3&s=400]<https://github.com/FasterXML/jackson-databind/issues/1083>

Field in base class is not recognized, when using ...<https://github.com/FasterXML/jackson-databind/issues/1083>
github.com
When deserializing JSON to Java POJOS, a field inherited from a base class is not recognized. Here is the stack: com.fasterxml.jackson.databind.exc ...



[https://avatars2.githubusercontent.com/u/1130553?v=3&s=400]<https://github.com/FasterXML/jackson-databind/issues/1083>

Field in base class is not recognized, when using ...<https://github.com/FasterXML/jackson-databind/issues/1083>
[https://avatars2.githubusercontent.com/u/1130553?v=3&s=400]<https://github.com/FasterXML/jackson-databind/issues/1083>

Field in base class is not recognized, when using ...<https://github.com/FasterXML/jackson-databind/issues/1083>
github.com
When deserializing JSON to Java POJOS, a field inherited from a base class is not recognized. Here is the stack: com.fasterxml.jackson.databind.exc ...



github.com
When deserializing JSON to Java POJOS, a field inherited from a base class is not recognized. Here is the stack: com.fasterxml.jackson.databind.exc ...

MG>which is manifested only in Jackson 2.7.0..more importantly does current Jackson codebase care about JsonType.defaultImpl issue?
MG>apparently yes as i see this comment in com.fasterxml.jackson.databind.ser.std.StdJdkSerializers
        // 09-Jan-2015, tatu: As per [databind#1073], let's try to guard against possibility
        //   of some environments missing `java.sql.` types
MG>in the case of when com.fasterxml.jackson.annotation.JsonTypeInfo references a Class for reflection instead of a declared type a
MG>OperationNotSupportedException is thrown

MG>in any case the jackson fix for #1073 JsonType.defaultImpl is supposedly in one of the 2.8.x versions @
MG>https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.8
[https://avatars3.githubusercontent.com/u/382692?v=3&s=400]<https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.8>

Jackson Release 2.8 · FasterXML/jackson Wiki · GitHub<https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.8>
[https://avatars3.githubusercontent.com/u/382692?v=3&s=400]<https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.8>

Jackson Release 2.8 · FasterXML/jackson Wiki · GitHub<https://github.com/FasterXML/jackson/wiki/Jackson-Release-2.8>
github.com
jackson - Main Portal page for Jackson project ... Version 2.8 was released 4th of July, 2016. Patches. Beyond initial 2.8.0 (described here), following patch ...



github.com
jackson - Main Portal page for Jackson project ... Version 2.8 was released 4th of July, 2016. Patches. Beyond initial 2.8.0 (described here), following patch ...


[https://avatars3.githubusercontent.com/u/382692?v=3&s=400]<https://github.com/FasterXML/jackson-databind>

GitHub - FasterXML/jackson-databind: General data-binding ...<https://github.com/FasterXML/jackson-databind>
[https://avatars3.githubusercontent.com/u/382692?v=3&s=400]<https://github.com/FasterXML/jackson-databind>

GitHub - FasterXML/jackson-databind: General data-binding ...<https://github.com/FasterXML/jackson-databind>
github.com
jackson-databind - General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)



github.com
jackson-databind - General data-binding package for Jackson (2.x): works on streaming API (core) implementation(s)

MG>which i could not find...i would revert to jackson-2.6.3
MG>this wont coerce the jackson datatype to Spring java.sql type for bind operation but one it should at least fix the jackson error

In new tests, the problem is focused on actions with a json result.

*1. For **results of **default **type:* If the class extends ActionSupport,
it is necessary to use "CGLIB proxy", if the class does not extend from
ActionSupport it is possible to use both "CGLIB proxy" and "JDK dynamic
proxy".
*2. For results of json **type **:* without AOP everything works fine, with
AOP both using "JDK dynamic proxy" and "CGLIB proxy" the action is
executed, the advice also but in both cases occurs the
OperationNotSupportedException

MG>yes in later jdks that support JDK Dynamic Proxy you should not proxy the class
MG>but allow JDKDynamicProxy to instantiate using the declared "type"
MG>(provided the lookup on type is successful)

Thanks


2017-05-08 15:50 GMT-05:00 Adam Brin <[hidden email]>:

> Hi,
>
> I presume you’ve read this: https://struts.apache.org/
Welcome to the Apache Struts project<https://struts.apache.org/>
struts.apache.org
Google's Patch Reward program. During SFHTML5 Google announced that they extend their program to cover the Apache Struts project as well.



Welcome to the Apache Struts project<https://struts.apache.org/>
Welcome to the Apache Struts project<https://struts.apache.org/>
struts.apache.org
Google's Patch Reward program. During SFHTML5 Google announced that they extend their program to cover the Apache Struts project as well.



struts.apache.org
Google's Patch Reward program. During SFHTML5 Google announced that they extend their program to cover the Apache Struts project as well.



> docs/json-plugin.html#JSONPlugin-Proxiedobjects
>
> It may be that the issue is not Struts2, but the JSON library that the
> Struts2 Json plugin uses… and thus, you may need to handle the JSON
> serialization using Jackson or another library.
>
>
> - adam
> --
> _________________________________________________________
> Adam Brin
> Director of Technology, Digital Antiquity
> 480.965.1278
>
> > On May 8, 2017, at 12:27 PM, developer researcher <
> [hidden email]> wrote:
> >
> > Hello Martin,
> >
> > First of all thanks for the reply, but I'm not sure if my queries have
> been
> > understood. I am using Struts 2.5.10.1
> >
> > My main query is: *Is there a way to use Spring AOP in Struts2 Actions
> > using the "JDK dynamic proxies"? Does anyone have an example?*
> >
> > Sorry, but I can not find any relationship between your answers and the
> > exceptions attached in my previous message:
> >
> > *1. NoSuchMethodException:* The code I'm testing does not have anything
> > from javax.sql.DataSource
> >
> > *2. OperationNotSupportedException:* Without using AOP there is no
> > exception for some namespace. This is very strange because the code in
> the
> > advice is simply "System.out.println ()" for testing purposes.
> >
> > Thanks
> >
> >
> > 2017-05-06 8:21 GMT-05:00 Martin Gainty <[hidden email]>:
> >
> >> MG>below
> >>
> >> ________________________________
> >> From: developer researcher <[hidden email]>
> >> Sent: Friday, May 5, 2017 10:09 PM
> >> To: Struts Users Mailing List
> >> Subject: Problem using the Spring's AOP in Struts2's Actions with
> >> json-plugin
> >>
> >> Hello,
> >>
> >> I am using Strust 2 <sp?> with spring-plugin and json-plugin to use:
> >>
> >> 1. Injection of dependencies: apparently everything is working well.
> >> 2. Spring's AOP: works when applied over methods of injected objects in
> >> the Struts Actions but not when applied over methods of actions (my
> class
> >> extends from ActionSupport and I use the @Action annotation at method
> level)
> >>
> >> MG>spring does not know what ActionSupport as it is a Struts classes
> >> besides which ActionSupport are not considered
> >> MG>spring beans which are simple pojos with a no-arg constructor
> >> https://docs.spring.io/spring/docs/current/spring-framework-
> >> reference/html/beans.html
> >> 7. The IoC container - Spring<https://docs.spring.io/
> >> spring/docs/current/spring-framework-reference/html/beans.html>
> >> docs.spring.io
> >> As the preceding diagram shows, the Spring IoC container consumes a form
> >> of configuration metadata; this configuration metadata represents how
> you
> >> as an application ...
> >>
> >>
> >> This situation has generated the following questions:
> >>
> >> 1. Are the actions created and managed by Spring or Struts? It's
> supposed
> >> to be Spring, but I have this doubt because Spring's AOP is supposed to
> >> work on Spring beans but in my case it does not work and because I do
> not
> >> use the Spring's @Component annotation in the Action class
> >>
> >> MG>correct but you can also specify a spring-bean in spring-beans.xml in
> >> your classpath e.g.:
> >> <bean id="springTest" name="springTest" class="org.struts.SpringTest"/>
> >>
> >> 2. Is there a way to use Spring AOP in Struts2 Actions using the "JDK
> >> dynamic proxies"? I have tested with the following results:
> >>
> >> a) When Spring uses "JDK dynamic proxies" the Struts2 Action is not
> >> executed and the following exception is thrown: NoSuchMethodException
> (see
> >> NoSuchMethodException.txt)
> >> b) When Spring uses "CGLIB proxy" in an Action whose result is of the
> >> default type: the Action works correctly
> >> c) When Spring uses "CGLIB proxy" in an Action whose result is of type
> >> json: the Struts2 Action is executed but the following exception is
> thrown:
> >> OperationNotSupportedException (see OperationNotSupportedException
> .txt).
> >> When I do not use AOP this Action works correctly.
> >>
> >> MG>builder.bind does not recognise json result-set as a valid
> >> javax.sql.DataSource..here is an example of builder.bind
> >> org.springframework.mock.jndi.SimpleNamingContextBuilder builder = new
> >> org.springframework.mock.jndi.SimpleNamingContextBuilder();
> >> * DataSource ds = new org.springframework.jdbc.datasource.
> >> DriverManagerDataSource(...);
> >> * builder.bind("java:comp/env/jdbc/myds", ds);
> >>
> >> MG>as of now JSON is not a valid javax.sql.DataSourceHere is Doc:
> >> <p>In a J2EE container, it is recommended to use a JNDI DataSource
> >> provided by
> >> * the container. Such a javax.sql.DataSource can be exposed as a
> >> javax.sql.DataSource bean in a Spring
> >> * ApplicationContext via {@link org.springframework.jndi.
> >> JndiObjectFactoryBean},
> >> * for seamless switching to and from a local javax.sql.DataSource bean
> >> like this class.
> >> * For tests, you can then either set up a mock JNDI environment through
> >> Spring's
> >> * {@link org.springframework.mock.jndi.SimpleNamingContextBuilder}, or
> >> switch the
> >> * bean definition to a local javax.sql.DataSource(which is simpler and
> >> thus recommended).
> >> *
> >> * <p>If you need a "real" connection pool outside of a J2EE container,
> >> consider
> >> * <a href="http://commons.apache.org/proper/commons-dbcp">Apache
> Commons
> >> DBCP</a>
> >> * or <a href="http://sourceforge.net/projects/c3p0">C3P0</a>.
> >> * Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource are
> full
> >> * connection pool beans, supporting the same basic properties as this
> >> class
> >> * plus specific settings (such as minimal/maximal pool size etc).
> >> mg>JSON is not yet a valid javax.sql.DataSource according to Spring
> >>
> >> MG>also you have not declared a namespace that NamingContext can
> reference
> >> which is causing exception
> >>
> >> MG>HTH
> >>
> >> Thanks
> >>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [hidden email]
> For additional commands, e-mail: [hidden email]
>
>
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem using the Spring's AOP in Struts2's Actions with json-plugin

adam brin
In reply to this post by developer researcher
Hi,
  I don't use the JSON plugin. My suggestion is, you're using a number of
tools in a chain, one isn't working, so what's the minimum viable way out?
Clearly something with the JSON plugin isn't working, so try and verify
where the problem is and work around it.  Alternately, it might make sense
to go grab the source of the JSON plugin and try and work through that.

Here's how we handle JSON output, we use the stream result:
https://struts.apache.org/docs/stream-result.html

On Tue, May 9, 2017 at 2:41 PM, developer researcher <
[hidden email]> wrote:

> Hi Adam,
>
> I have not tried Jackson and the Spring AOP outside of Struts2. My context
> is: modify a Struts web application (with spring-plugin and json-plugin) to
> add some functionality (advices) through AOP. I would have to test in
> another application to see if there is any problem between Jackson and
> Spring AOP proxies.
>
> On the other hand, when you say "*We just set content-type to application
> json*" Are you using json-plugin? In my case I have used both "text/html"
> and "application/json" (using json-plugin) but in both cases the
> serialization is executed by json-plugin automatically.
>
> According to the documentation, the results supported are
> https://cwiki.apache.org/confluence/display/WW/Result+Types Have you
> implemented a custom result?
>
> Thanks
>
>
> 2017-05-08 21:38 GMT-05:00 Adam Brin <[hidden email]>:
>
> > We just set content-type to application json and output a stream or a
> > string.  In the action, I just convert the object to a stream.
> >
> > But, here's the question:  does your spring AOP proxy work properly with
> > Jackson outside of struts2?
> >
> >
> >
> > On Mon, May 8, 2017 at 7:14 PM, developer researcher <
> > [hidden email]> wrote:
> >
> > > Hello Adam,
> > >
> > > Yes, I am using the "ignoreInterfaces" param set to "false". My result
> > is:
> > > "@Result(name="success",type="json", params={"contentType",
> "text/html",
> > > "ignoreInterfaces", "false"})"
> > >
> > > The file "struts-2.5.10.1-all.zip" contains the jackson's jars, so I
> > guess
> > > the json-plugin use jackson.In any case, how would you use your own
> > > serialization instead of the provided by json-plugin for actions that
> > need
> > > AOP?
> > >
> > > In new tests, the problem is focused on actions with a json result.
> > >
> > > *1. For **results of **default **type:* If the class extends
> > ActionSupport,
> > > it is necessary to use "CGLIB proxy", if the class does not extend from
> > > ActionSupport it is possible to use both "CGLIB proxy" and "JDK dynamic
> > > proxy".
> > > *2. For results of json **type **:* without AOP everything works fine,
> > with
> > > AOP both using "JDK dynamic proxy" and "CGLIB proxy" the action is
> > > executed, the advice also but in both cases occurs the
> > > OperationNotSupportedException
> > >
> > > Thanks
> > >
> > >
> > > 2017-05-08 15:50 GMT-05:00 Adam Brin <[hidden email]>:
> > >
> > > > Hi,
> > > >
> > > > I presume you’ve read this: https://struts.apache.org/
> > > > docs/json-plugin.html#JSONPlugin-Proxiedobjects
> > > >
> > > > It may be that the issue is not Struts2, but the JSON library that
> the
> > > > Struts2 Json plugin uses… and thus, you may need to handle the JSON
> > > > serialization using Jackson or another library.
> > > >
> > > >
> > > > - adam
> > > > --
> > > > _________________________________________________________
> > > > Adam Brin
> > > > Director of Technology, Digital Antiquity
> > > > 480.965.1278
> > > >
> > > > > On May 8, 2017, at 12:27 PM, developer researcher <
> > > > [hidden email]> wrote:
> > > > >
> > > > > Hello Martin,
> > > > >
> > > > > First of all thanks for the reply, but I'm not sure if my queries
> > have
> > > > been
> > > > > understood. I am using Struts 2.5.10.1
> > > > >
> > > > > My main query is: *Is there a way to use Spring AOP in Struts2
> > Actions
> > > > > using the "JDK dynamic proxies"? Does anyone have an example?*
> > > > >
> > > > > Sorry, but I can not find any relationship between your answers and
> > the
> > > > > exceptions attached in my previous message:
> > > > >
> > > > > *1. NoSuchMethodException:* The code I'm testing does not have
> > anything
> > > > > from javax.sql.DataSource
> > > > >
> > > > > *2. OperationNotSupportedException:* Without using AOP there is no
> > > > > exception for some namespace. This is very strange because the code
> > in
> > > > the
> > > > > advice is simply "System.out.println ()" for testing purposes.
> > > > >
> > > > > Thanks
> > > > >
> > > > >
> > > > > 2017-05-06 8:21 GMT-05:00 Martin Gainty <[hidden email]>:
> > > > >
> > > > >> MG>below
> > > > >>
> > > > >> ________________________________
> > > > >> From: developer researcher <[hidden email]>
> > > > >> Sent: Friday, May 5, 2017 10:09 PM
> > > > >> To: Struts Users Mailing List
> > > > >> Subject: Problem using the Spring's AOP in Struts2's Actions with
> > > > >> json-plugin
> > > > >>
> > > > >> Hello,
> > > > >>
> > > > >> I am using Strust 2 <sp?> with spring-plugin and json-plugin to
> use:
> > > > >>
> > > > >> 1. Injection of dependencies: apparently everything is working
> well.
> > > > >> 2. Spring's AOP: works when applied over methods of injected
> objects
> > > in
> > > > >> the Struts Actions but not when applied over methods of actions
> (my
> > > > class
> > > > >> extends from ActionSupport and I use the @Action annotation at
> > method
> > > > level)
> > > > >>
> > > > >> MG>spring does not know what ActionSupport as it is a Struts
> classes
> > > > >> besides which ActionSupport are not considered
> > > > >> MG>spring beans which are simple pojos with a no-arg constructor
> > > > >> https://docs.spring.io/spring/docs/current/spring-framework-
> > > > >> reference/html/beans.html
> > > > >> 7. The IoC container - Spring<https://docs.spring.io/
> > > > >> spring/docs/current/spring-framework-reference/html/beans.html>
> > > > >> docs.spring.io
> > > > >> As the preceding diagram shows, the Spring IoC container consumes
> a
> > > form
> > > > >> of configuration metadata; this configuration metadata represents
> > how
> > > > you
> > > > >> as an application ...
> > > > >>
> > > > >>
> > > > >> This situation has generated the following questions:
> > > > >>
> > > > >> 1. Are the actions created and managed by Spring or Struts? It's
> > > > supposed
> > > > >> to be Spring, but I have this doubt because Spring's AOP is
> supposed
> > > to
> > > > >> work on Spring beans but in my case it does not work and because I
> > do
> > > > not
> > > > >> use the Spring's @Component annotation in the Action class
> > > > >>
> > > > >> MG>correct but you can also specify a spring-bean in
> > spring-beans.xml
> > > in
> > > > >> your classpath e.g.:
> > > > >> <bean id="springTest" name="springTest"
> > class="org.struts.SpringTest"/
> > > >
> > > > >>
> > > > >> 2. Is there a way to use Spring AOP in Struts2 Actions using the
> > "JDK
> > > > >> dynamic proxies"? I have tested with the following results:
> > > > >>
> > > > >> a) When Spring uses "JDK dynamic proxies" the Struts2 Action is
> not
> > > > >> executed and the following exception is thrown:
> > NoSuchMethodException
> > > > (see
> > > > >> NoSuchMethodException.txt)
> > > > >> b) When Spring uses "CGLIB proxy" in an Action whose result is of
> > the
> > > > >> default type: the Action works correctly
> > > > >> c) When Spring uses "CGLIB proxy" in an Action whose result is of
> > type
> > > > >> json: the Struts2 Action is executed but the following exception
> is
> > > > thrown:
> > > > >> OperationNotSupportedException (see OperationNotSupportedException
> > > > .txt).
> > > > >> When I do not use AOP this Action works correctly.
> > > > >>
> > > > >> MG>builder.bind does not recognise json result-set as a valid
> > > > >> javax.sql.DataSource..here is an example of builder.bind
> > > > >> org.springframework.mock.jndi.SimpleNamingContextBuilder builder
> =
> > > new
> > > > >> org.springframework.mock.jndi.SimpleNamingContextBuilder();
> > > > >> * DataSource ds = new org.springframework.jdbc.datasource.
> > > > >> DriverManagerDataSource(...);
> > > > >> * builder.bind("java:comp/env/jdbc/myds", ds);
> > > > >>
> > > > >> MG>as of now JSON is not a valid javax.sql.DataSourceHere is Doc:
> > > > >> <p>In a J2EE container, it is recommended to use a JNDI DataSource
> > > > >> provided by
> > > > >> * the container. Such a javax.sql.DataSource can be exposed as a
> > > > >> javax.sql.DataSource bean in a Spring
> > > > >> * ApplicationContext via {@link org.springframework.jndi.
> > > > >> JndiObjectFactoryBean},
> > > > >> * for seamless switching to and from a local javax.sql.DataSource
> > bean
> > > > >> like this class.
> > > > >> * For tests, you can then either set up a mock JNDI environment
> > > through
> > > > >> Spring's
> > > > >> * {@link org.springframework.mock.jndi.
> SimpleNamingContextBuilder},
> > > or
> > > > >> switch the
> > > > >> * bean definition to a local javax.sql.DataSource(which is simpler
> > and
> > > > >> thus recommended).
> > > > >> *
> > > > >> * <p>If you need a "real" connection pool outside of a J2EE
> > container,
> > > > >> consider
> > > > >> * <a href="http://commons.apache.org/proper/commons-dbcp">Apache
> > > > Commons
> > > > >> DBCP</a>
> > > > >> * or <a href="http://sourceforge.net/projects/c3p0">C3P0</a>.
> > > > >> * Commons DBCP's BasicDataSource and C3P0's ComboPooledDataSource
> > are
> > > > full
> > > > >> * connection pool beans, supporting the same basic properties as
> > this
> > > > >> class
> > > > >> * plus specific settings (such as minimal/maximal pool size etc).
> > > > >> mg>JSON is not yet a valid javax.sql.DataSource according to
> Spring
> > > > >>
> > > > >> MG>also you have not declared a namespace that NamingContext can
> > > > reference
> > > > >> which is causing exception
> > > > >>
> > > > >> MG>HTH
> > > > >>
> > > > >> Thanks
> > > > >>
> > > >
> > > >
> > > > ------------------------------------------------------------
> ---------
> > > > To unsubscribe, e-mail: [hidden email]
> > > > For additional commands, e-mail: [hidden email]
> > > >
> > > >
> > >
> >
> >
> >
> > --
> > _________________________________________________________
> > Adam Brin
> > Director of Technology, Digital Antiquity
> > 480.965.1278
> >
>



--
_________________________________________________________
Adam Brin
Director of Technology, Digital Antiquity
480.965.1278
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problem using the Spring's AOP in Struts2's Actions with json-plugin

developer researcher
Of course Adam,

If no solution is found by configuration, there is to try other
alternatives without the json-plugin. As you indicate using the stream
result.

Thanks and regards.

2017-05-09 17:52 GMT-05:00 Adam Brin <[hidden email]>:

> Hi,
>   I don't use the JSON plugin. My suggestion is, you're using a number of
> tools in a chain, one isn't working, so what's the minimum viable way out?
> Clearly something with the JSON plugin isn't working, so try and verify
> where the problem is and work around it.  Alternately, it might make sense
> to go grab the source of the JSON plugin and try and work through that.
>
> Here's how we handle JSON output, we use the stream result:
> https://struts.apache.org/docs/stream-result.html
>
> On Tue, May 9, 2017 at 2:41 PM, developer researcher <
> [hidden email]> wrote:
>
> > Hi Adam,
> >
> > I have not tried Jackson and the Spring AOP outside of Struts2. My
> context
> > is: modify a Struts web application (with spring-plugin and json-plugin)
> to
> > add some functionality (advices) through AOP. I would have to test in
> > another application to see if there is any problem between Jackson and
> > Spring AOP proxies.
> >
> > On the other hand, when you say "*We just set content-type to application
> > json*" Are you using json-plugin? In my case I have used both "text/html"
> > and "application/json" (using json-plugin) but in both cases the
> > serialization is executed by json-plugin automatically.
> >
> > According to the documentation, the results supported are
> > https://cwiki.apache.org/confluence/display/WW/Result+Types Have you
> > implemented a custom result?
> >
> > Thanks
> >
> >
> > 2017-05-08 21:38 GMT-05:00 Adam Brin <[hidden email]>:
> >
> > > We just set content-type to application json and output a stream or a
> > > string.  In the action, I just convert the object to a stream.
> > >
> > > But, here's the question:  does your spring AOP proxy work properly
> with
> > > Jackson outside of struts2?
> > >
> > >
> > >
> > > On Mon, May 8, 2017 at 7:14 PM, developer researcher <
> > > [hidden email]> wrote:
> > >
> > > > Hello Adam,
> > > >
> > > > Yes, I am using the "ignoreInterfaces" param set to "false". My
> result
> > > is:
> > > > "@Result(name="success",type="json", params={"contentType",
> > "text/html",
> > > > "ignoreInterfaces", "false"})"
> > > >
> > > > The file "struts-2.5.10.1-all.zip" contains the jackson's jars, so I
> > > guess
> > > > the json-plugin use jackson.In any case, how would you use your own
> > > > serialization instead of the provided by json-plugin for actions that
> > > need
> > > > AOP?
> > > >
> > > > In new tests, the problem is focused on actions with a json result.
> > > >
> > > > *1. For **results of **default **type:* If the class extends
> > > ActionSupport,
> > > > it is necessary to use "CGLIB proxy", if the class does not extend
> from
> > > > ActionSupport it is possible to use both "CGLIB proxy" and "JDK
> dynamic
> > > > proxy".
> > > > *2. For results of json **type **:* without AOP everything works
> fine,
> > > with
> > > > AOP both using "JDK dynamic proxy" and "CGLIB proxy" the action is
> > > > executed, the advice also but in both cases occurs the
> > > > OperationNotSupportedException
> > > >
> > > > Thanks
> > > >
> > > >
> > > > 2017-05-08 15:50 GMT-05:00 Adam Brin <[hidden email]>:
> > > >
> > > > > Hi,
> > > > >
> > > > > I presume you’ve read this: https://struts.apache.org/
> > > > > docs/json-plugin.html#JSONPlugin-Proxiedobjects
> > > > >
> > > > > It may be that the issue is not Struts2, but the JSON library that
> > the
> > > > > Struts2 Json plugin uses… and thus, you may need to handle the JSON
> > > > > serialization using Jackson or another library.
> > > > >
> > > > >
> > > > > - adam
> > > > > --
> > > > > _________________________________________________________
> > > > > Adam Brin
> > > > > Director of Technology, Digital Antiquity
> > > > > 480.965.1278
> > > > >
> > > > > > On May 8, 2017, at 12:27 PM, developer researcher <
> > > > > [hidden email]> wrote:
> > > > > >
> > > > > > Hello Martin,
> > > > > >
> > > > > > First of all thanks for the reply, but I'm not sure if my queries
> > > have
> > > > > been
> > > > > > understood. I am using Struts 2.5.10.1
> > > > > >
> > > > > > My main query is: *Is there a way to use Spring AOP in Struts2
> > > Actions
> > > > > > using the "JDK dynamic proxies"? Does anyone have an example?*
> > > > > >
> > > > > > Sorry, but I can not find any relationship between your answers
> and
> > > the
> > > > > > exceptions attached in my previous message:
> > > > > >
> > > > > > *1. NoSuchMethodException:* The code I'm testing does not have
> > > anything
> > > > > > from javax.sql.DataSource
> > > > > >
> > > > > > *2. OperationNotSupportedException:* Without using AOP there is
> no
> > > > > > exception for some namespace. This is very strange because the
> code
> > > in
> > > > > the
> > > > > > advice is simply "System.out.println ()" for testing purposes.
> > > > > >
> > > > > > Thanks
> > > > > >
> > > > > >
> > > > > > 2017-05-06 8:21 GMT-05:00 Martin Gainty <[hidden email]>:
> > > > > >
> > > > > >> MG>below
> > > > > >>
> > > > > >> ________________________________
> > > > > >> From: developer researcher <[hidden email]
> >
> > > > > >> Sent: Friday, May 5, 2017 10:09 PM
> > > > > >> To: Struts Users Mailing List
> > > > > >> Subject: Problem using the Spring's AOP in Struts2's Actions
> with
> > > > > >> json-plugin
> > > > > >>
> > > > > >> Hello,
> > > > > >>
> > > > > >> I am using Strust 2 <sp?> with spring-plugin and json-plugin to
> > use:
> > > > > >>
> > > > > >> 1. Injection of dependencies: apparently everything is working
> > well.
> > > > > >> 2. Spring's AOP: works when applied over methods of injected
> > objects
> > > > in
> > > > > >> the Struts Actions but not when applied over methods of actions
> > (my
> > > > > class
> > > > > >> extends from ActionSupport and I use the @Action annotation at
> > > method
> > > > > level)
> > > > > >>
> > > > > >> MG>spring does not know what ActionSupport as it is a Struts
> > classes
> > > > > >> besides which ActionSupport are not considered
> > > > > >> MG>spring beans which are simple pojos with a no-arg constructor
> > > > > >> https://docs.spring.io/spring/docs/current/spring-framework-
> > > > > >> reference/html/beans.html
> > > > > >> 7. The IoC container - Spring<https://docs.spring.io/
> > > > > >> spring/docs/current/spring-framework-reference/html/beans.html>
> > > > > >> docs.spring.io
> > > > > >> As the preceding diagram shows, the Spring IoC container
> consumes
> > a
> > > > form
> > > > > >> of configuration metadata; this configuration metadata
> represents
> > > how
> > > > > you
> > > > > >> as an application ...
> > > > > >>
> > > > > >>
> > > > > >> This situation has generated the following questions:
> > > > > >>
> > > > > >> 1. Are the actions created and managed by Spring or Struts? It's
> > > > > supposed
> > > > > >> to be Spring, but I have this doubt because Spring's AOP is
> > supposed
> > > > to
> > > > > >> work on Spring beans but in my case it does not work and
> because I
> > > do
> > > > > not
> > > > > >> use the Spring's @Component annotation in the Action class
> > > > > >>
> > > > > >> MG>correct but you can also specify a spring-bean in
> > > spring-beans.xml
> > > > in
> > > > > >> your classpath e.g.:
> > > > > >> <bean id="springTest" name="springTest"
> > > class="org.struts.SpringTest"/
> > > > >
> > > > > >>
> > > > > >> 2. Is there a way to use Spring AOP in Struts2 Actions using the
> > > "JDK
> > > > > >> dynamic proxies"? I have tested with the following results:
> > > > > >>
> > > > > >> a) When Spring uses "JDK dynamic proxies" the Struts2 Action is
> > not
> > > > > >> executed and the following exception is thrown:
> > > NoSuchMethodException
> > > > > (see
> > > > > >> NoSuchMethodException.txt)
> > > > > >> b) When Spring uses "CGLIB proxy" in an Action whose result is
> of
> > > the
> > > > > >> default type: the Action works correctly
> > > > > >> c) When Spring uses "CGLIB proxy" in an Action whose result is
> of
> > > type
> > > > > >> json: the Struts2 Action is executed but the following exception
> > is
> > > > > thrown:
> > > > > >> OperationNotSupportedException (see
> OperationNotSupportedException
> > > > > .txt).
> > > > > >> When I do not use AOP this Action works correctly.
> > > > > >>
> > > > > >> MG>builder.bind does not recognise json result-set as a valid
> > > > > >> javax.sql.DataSource..here is an example of builder.bind
> > > > > >> org.springframework.mock.jndi.SimpleNamingContextBuilder
> builder
> > =
> > > > new
> > > > > >> org.springframework.mock.jndi.SimpleNamingContextBuilder();
> > > > > >> * DataSource ds = new org.springframework.jdbc.datasource.
> > > > > >> DriverManagerDataSource(...);
> > > > > >> * builder.bind("java:comp/env/jdbc/myds", ds);
> > > > > >>
> > > > > >> MG>as of now JSON is not a valid javax.sql.DataSourceHere is
> Doc:
> > > > > >> <p>In a J2EE container, it is recommended to use a JNDI
> DataSource
> > > > > >> provided by
> > > > > >> * the container. Such a javax.sql.DataSource can be exposed as a
> > > > > >> javax.sql.DataSource bean in a Spring
> > > > > >> * ApplicationContext via {@link org.springframework.jndi.
> > > > > >> JndiObjectFactoryBean},
> > > > > >> * for seamless switching to and from a local
> javax.sql.DataSource
> > > bean
> > > > > >> like this class.
> > > > > >> * For tests, you can then either set up a mock JNDI environment
> > > > through
> > > > > >> Spring's
> > > > > >> * {@link org.springframework.mock.jndi.
> > SimpleNamingContextBuilder},
> > > > or
> > > > > >> switch the
> > > > > >> * bean definition to a local javax.sql.DataSource(which is
> simpler
> > > and
> > > > > >> thus recommended).
> > > > > >> *
> > > > > >> * <p>If you need a "real" connection pool outside of a J2EE
> > > container,
> > > > > >> consider
> > > > > >> * <a href="http://commons.apache.org/proper/commons-dbcp">
> Apache
> > > > > Commons
> > > > > >> DBCP</a>
> > > > > >> * or <a href="http://sourceforge.net/projects/c3p0">C3P0</a>.
> > > > > >> * Commons DBCP's BasicDataSource and C3P0's
> ComboPooledDataSource
> > > are
> > > > > full
> > > > > >> * connection pool beans, supporting the same basic properties as
> > > this
> > > > > >> class
> > > > > >> * plus specific settings (such as minimal/maximal pool size
> etc).
> > > > > >> mg>JSON is not yet a valid javax.sql.DataSource according to
> > Spring
> > > > > >>
> > > > > >> MG>also you have not declared a namespace that NamingContext can
> > > > > reference
> > > > > >> which is causing exception
> > > > > >>
> > > > > >> MG>HTH
> > > > > >>
> > > > > >> Thanks
> > > > > >>
> > > > >
> > > > >
> > > > > ------------------------------------------------------------
> > ---------
> > > > > To unsubscribe, e-mail: [hidden email]
> > > > > For additional commands, e-mail: [hidden email]
> > > > >
> > > > >
> > > >
> > >
> > >
> > >
> > > --
> > > _________________________________________________________
> > > Adam Brin
> > > Director of Technology, Digital Antiquity
> > > 480.965.1278
> > >
> >
>
>
>
> --
> _________________________________________________________
> Adam Brin
> Director of Technology, Digital Antiquity
> 480.965.1278
>
Loading...