You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by MM_at_ANO <ma...@ano.pt> on 2016/01/25 16:32:32 UTC

Issue with REST Sessions in Wicket-Shiro-Hibernate

Good Morning.

I'm currently working in a Wicket 6.19.0 and Hibernate 4.3.6 project with
Shiro authentication.
The code is very high level and I'm having troubles finding a solution for
my problem.
But first of all, let me explain the problem.

In the application there is a REST API service to obtain the information
about a certain User.
In this application there is a "WicketSession" class extending the
org.apache.wicket.Session.
This class is used to inject the SessionFactory, and thus allowing the
manipulation of DAO Implementations for the database, as so:

The Class:
...
WicketSession extends WebSession implements ISessionLogInfo {
    @SpringBean(name = "sessionFactory")
    private SessionFactory sessionFactory;

    public static WicketSession get() {
        return (WicketSession) Session.get();
    }
...

The Web Application Context
    <bean id="sessionFactory" 
class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
...
        <property name="hibernateProperties">
            <props>
                <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
                <prop key="use_sql_comments">${use_sql_comments}</prop>
                <prop
key="hibernate.format_sql">${hibernate.format_sql}</prop>
                <prop key="hibernate.cache.use_query_cache">
${hibernate.cache.use_query_cache} </prop>
                <prop
key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
                <prop key="hibernate.cache.region.factory_class">
${hibernate.cache.region.factory_class}</prop>
                <prop key="hibernate.cache.use_second_level_cache">
${hibernate.cache.use_second_level_cache}</prop>
                <prop
key="hibernate.query.factory_class">${hibernate.query.factory_class}</prop>
                <prop key="hibernate.dialect">${hibernate.dialect}</prop>
                <prop
key="hibernate.auto_close_session">${hibernate.auto_close_session}</prop>
                <prop
key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
                <prop
key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
            </props>
        </property>
    </bean>

The Web Service:
...
UserDaoImpl dao = new UserDaoImpl(WicketSession.get().getSessionFactory());
...

When I call the web service I get a 500 error.
This error is due to a null pointer exception in WicketSession.get(), more
precisely in RequestCycle.get() (executed inside Session.get()).
If the web service is accessed one more time (in browser only) everything
works fine and the web service returns a JSON (as it is supposed to).
Yet if there is another access I get once again the 500 error.
And so on...

I have search many different solutions but nothing worked.
Do you have any idea of what's going on? Any help would be appreciated.

Sorry for my poor English.
Best Regards, Marina.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Issue-with-REST-Sessions-in-Wicket-Shiro-Hibernate-tp4673417.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Issue with REST Sessions in Wicket-Shiro-Hibernate

Posted by Martin Grigorov <mg...@apache.org>.
Glad it works now!

Better move  Injector.get().inject(application); to the constructor of
YourWicketApplication:  Injector.get().inject(this);

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Tue, Jan 26, 2016 at 3:00 PM, MM_at_ANO <ma...@ano.pt> wrote:

> Hi.
>
> Thank you a lot for answering.
> Your suggestion helped me in solving the problem .
> I also had to add an injection call in the WicketApplication getter, as
> follows:
>
> public static WicketApplication get() {
>    Application application = Application.get();
>    Injector.get().inject(application);
>    return (WicketApplication) application;
> }
>
> Without it, the getter kept on returning null.
> Now I can easily access Session and Session factories without problem.
> Once again thank you for your quick answer.
> You help is much appreciated.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Issue-with-REST-Sessions-in-Wicket-Shiro-Hibernate-tp4673417p4673439.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>

Re: Issue with REST Sessions in Wicket-Shiro-Hibernate

Posted by MM_at_ANO <ma...@ano.pt>.
Hi.

Thank you a lot for answering.
Your suggestion helped me in solving the problem .
I also had to add an injection call in the WicketApplication getter, as
follows:

public static WicketApplication get() {
   Application application = Application.get();
   Injector.get().inject(application); 
   return (WicketApplication) application;
}

Without it, the getter kept on returning null.
Now I can easily access Session and Session factories without problem.
Once again thank you for your quick answer.
You help is much appreciated.

--
View this message in context: http://apache-wicket.1842946.n4.nabble.com/Issue-with-REST-Sessions-in-Wicket-Shiro-Hibernate-tp4673417p4673439.html
Sent from the Users forum mailing list archive at Nabble.com.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Issue with REST Sessions in Wicket-Shiro-Hibernate

Posted by Martin Grigorov <mg...@apache.org>.
Hi,

The problem is that your web service and WicketFilter are configured to
listen on different filter paths, e.g. /webservice/* and /wicket/*.
If there was a request to /wicket/* that had bound a Session then the call
to /webservice/* will be OK, but otherwise it will fail because while
trying to create a Session Wicket needs RequestCycle.
The solution is simple - move #getSessionFactory() to YourWicketApplication.

Martin Grigorov
Wicket Training and Consulting
https://twitter.com/mtgrigorov

On Mon, Jan 25, 2016 at 4:32 PM, MM_at_ANO <ma...@ano.pt> wrote:

> Good Morning.
>
> I'm currently working in a Wicket 6.19.0 and Hibernate 4.3.6 project with
> Shiro authentication.
> The code is very high level and I'm having troubles finding a solution for
> my problem.
> But first of all, let me explain the problem.
>
> In the application there is a REST API service to obtain the information
> about a certain User.
> In this application there is a "WicketSession" class extending the
> org.apache.wicket.Session.
> This class is used to inject the SessionFactory, and thus allowing the
> manipulation of DAO Implementations for the database, as so:
>
> The Class:
> ...
> WicketSession extends WebSession implements ISessionLogInfo {
>     @SpringBean(name = "sessionFactory")
>     private SessionFactory sessionFactory;
>
>     public static WicketSession get() {
>         return (WicketSession) Session.get();
>     }
> ...
>
> The Web Application Context
>     <bean id="sessionFactory"
> class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
> ...
>         <property name="hibernateProperties">
>             <props>
>                 <prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
>                 <prop key="use_sql_comments">${use_sql_comments}</prop>
>                 <prop
> key="hibernate.format_sql">${hibernate.format_sql}</prop>
>                 <prop key="hibernate.cache.use_query_cache">
> ${hibernate.cache.use_query_cache} </prop>
>                 <prop
>
> key="hibernate.cache.provider_class">${hibernate.cache.provider_class}</prop>
>                 <prop key="hibernate.cache.region.factory_class">
> ${hibernate.cache.region.factory_class}</prop>
>                 <prop key="hibernate.cache.use_second_level_cache">
> ${hibernate.cache.use_second_level_cache}</prop>
>                 <prop
> key="hibernate.query.factory_class">${hibernate.query.factory_class}</prop>
>                 <prop key="hibernate.dialect">${hibernate.dialect}</prop>
>                 <prop
> key="hibernate.auto_close_session">${hibernate.auto_close_session}</prop>
>                 <prop
> key="hibernate.jdbc.batch_size">${hibernate.jdbc.batch_size}</prop>
>                 <prop
> key="hibernate.max_fetch_depth">${hibernate.max_fetch_depth}</prop>
>             </props>
>         </property>
>     </bean>
>
> The Web Service:
> ...
> UserDaoImpl dao = new UserDaoImpl(WicketSession.get().getSessionFactory());
> ...
>
> When I call the web service I get a 500 error.
> This error is due to a null pointer exception in WicketSession.get(), more
> precisely in RequestCycle.get() (executed inside Session.get()).
> If the web service is accessed one more time (in browser only) everything
> works fine and the web service returns a JSON (as it is supposed to).
> Yet if there is another access I get once again the 500 error.
> And so on...
>
> I have search many different solutions but nothing worked.
> Do you have any idea of what's going on? Any help would be appreciated.
>
> Sorry for my poor English.
> Best Regards, Marina.
>
> --
> View this message in context:
> http://apache-wicket.1842946.n4.nabble.com/Issue-with-REST-Sessions-in-Wicket-Shiro-Hibernate-tp4673417.html
> Sent from the Users forum mailing list archive at Nabble.com.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>