You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Miguel <mi...@gmail.com> on 2014/02/11 06:40:20 UTC

REST question

Hi,

A strange situation happens when I load *struts2-rest-plugin-2.3.16.jar*
With out the REST plugin my action and jsp's works as always has worked.
But with the mere inclusion of the REST Plugin, some jsp's stops finding
variables, because the variable name changes.
Here is the snippet:

struts.xml

    <constant name="struts.objectFactory"
value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
    <constant name="struts.objectFactory.spring.autoWire" value="name" />
    <package name="proyectox" extends="json-default" >
<!-- Si no le pones este stack, pues no funciona...-->
        <interceptors>
            <interceptor name="strutsSpring"
class="com.proyectox.ui.interceptor.HibernateOpenSessionInViewInterceptor"/>
            <interceptor name="viewuseragentselector"
class="com.proyectox.ui.interceptor.UserAgentResultInterceptor"/>
            <interceptor-stack name="strutsSpringPPPStack">
                <interceptor-ref name="strutsSpring"/>
                <interceptor-ref name="paramsPrepareParamsStack"/>
                <interceptor-ref name="viewuseragentselector"/>
            </interceptor-stack>
        </interceptors>
...
    </package>

    <package name="cfdi" extends="proyectox" namespace="/cfdi">
        <action name="header_*" class="com.fcm.cfdi.ui.HeaderAction">
            <result type="redirectAction">
                <param name="actionName">edit</param>
            </result>
<!--            <result >printHeader.jsp</result>-->
            <result name="input">headerEdit.jsp</result>
            <result name="error">/facturaerror.jsp</result>
            <interceptor-ref name="scope">
                <param name="session">contribuyente</param>
                <param name="autoCreateSession">true</param>
                <param name="key">contribuyenteActual</param>
            </interceptor-ref>
            <interceptor-ref name="scope">
                <param name="session">factura</param>
                <param name="autoCreateSession">false</param>
                <param name="key">cfdi</param>
            </interceptor-ref>
            <interceptor-ref name="strutsSpringPPPStack"/>
        </action>



HeaderAction.java:

public class HeaderAction extends ActionSupport implements Preparable {
    protected Contribuyente contribuyente;
    protected Long contribuyenteId;

    public void prepare() throws Exception {
    ...
    }


    public String input(){

        dirReceptorId = factura.getDomicilioReceptor().getId();
        dirEmisionId  = factura.getDomicilioEmision().getId();
        return INPUT;
    }
...
    public Contribuyente getContribuyente() {
        return contribuyente;
    }

    public void setContribuyente(Contribuyente contribuyente) {
        this.contribuyente = contribuyente;
    }
...
}

edit.jsp:
...
    <s:select label="Direccion Emision"
       name="dirEmisionId"
       list="*contribuyente*.domicilios"
       listKey="id"
       listValue="nombre"
       multiple="false"
       size="1"
       required="true"
       key="factura.direccionEmision.id"
    />
...

After loading *struts2-rest-plugin-2.3.16.jar* it starts giving the
following exception:
Caused by: org.hibernate.LazyInitializationException: failed to lazily
initialize a collection of role: *contribuyentes.domicilios*, no session or
session was closed
...

I know that's a Hibernate exception, but the jsp works fine without the
REST Plugin.
It's like the REST Plugin appends that extra "s" after the variable name in
the .jsp or the value stack changes or something like that.

The action is invoked without error in either case, and has into it's
fields the required values.


Does anyone has any pointer of what can be happening?

Thanks

Si quieres ser más positivo, pierde un electrón
Miguel Ruiz Velasco Sobrino

RE: REST question

Posted by Martin Gainty <mg...@hotmail.com>.
/*
  * HibernateOpenSessionInViewInterceptor.java
  *
  * Created on March 18, 2006, 3:51 PM
  *
  * To change this template, choose Tools | Template Manager
  * and open the template in the editor.
  */
 
package edu.washington.javawebdevelopment.webwork.interceptor;
 
import com.opensymphony.xwork.ActionInvocation;
import com.opensymphony.xwork.interceptor.AroundInterceptor;
import edu.washington.javawebdevelopment.dao.DaoFactoryHibernate;
import javax.servlet.ServletException;
import org.hibernate.SessionFactory;
import org.hibernate.StaleObjectStateException;
 
/**
  *
  * @author gary
  */
public class HibernateOpenSessionInViewInterceptor extends AroundInterceptor {
     private SessionFactory hibernateSessionFactory;
 
     public void init() {
         System.out.println("Initializing HibernateOpenSessionInViewInterceptor interceptor, obtaining Hibernate SessionFactory from DaoFactoryHibernate");
         hibernateSessionFactory = DaoFactoryHibernate.getSessionFactory();
     }
 
     public void destroy() {
     }
 
     public void before(ActionInvocation invocation) throws Exception {
         System.out.println("Starting a database transaction in the HibernateOpenSessionInViewInterceptor");
         hibernateSessionFactory.getCurrentSession().beginTransaction();
     }
 
     public void after(ActionInvocation invocation, String result) throws Exception {
         // Commit and cleanup
         try {
             System.out.println("Committing the database transaction in the HibernateOpenSessionInViewInterceptor");
             hibernateSessionFactory.getCurrentSession().getTransaction().commit();
         } catch (StaleObjectStateException staleEx) {
             System.err.println("This interceptor does not implement optimistic concurrency control!");
             System.err.println("Your application will not work until you add compensation actions!");
             // Rollback, close everything, possibly compensate for any permanent changes
             // during the conversation, and finally restart business conversation. Maybe
             // give the user of the application a chance to merge some if his work with
             // fresh data... what you do here depends on your applications design.
             throw staleEx;
         } catch (Throwable ex) {
             // Rollback only
             ex.printStackTrace();
             try {
                 if (hibernateSessionFactory.getCurrentSession().getTransaction().isActive()) {
                     System.out.println("Trying to rollback database transaction after exception");
                     hibernateSessionFactory.getCurrentSession().getTransaction().rollback();
                 }
             } catch (Throwable rbEx) {
                 System.err.println("Could not rollback transaction after exception! - " + rbEx);
             }
 
             // Let others handle it... maybe another interceptor for exceptions?
             throw new ServletException(ex);
         }
     }
}

 

?

Martin-

  



> Date: Tue, 11 Feb 2014 14:42:47 -0700
> Subject: Re: REST question
> From: ken.mcwilliams@gmail.com
> To: user@struts.apache.org
> 
> Sounds like you have used the Open Session in View method... probably
> provided by a custom interceptor, when adding the rest plugin you have
> changed your action to the rest package and forgot to put your interceptor
> back in place, so now you don't have a hibernate session and the view
> generates this error.
> 
> 
> On Mon, Feb 10, 2014 at 10:40 PM, Miguel <mi...@gmail.com> wrote:
> 
> > Hi,
> >
> > A strange situation happens when I load *struts2-rest-plugin-2.3.16.jar*
> > With out the REST plugin my action and jsp's works as always has worked.
> > But with the mere inclusion of the REST Plugin, some jsp's stops finding
> > variables, because the variable name changes.
> > Here is the snippet:
> >
> > struts.xml
> >
> > <constant name="struts.objectFactory"
> > value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
> > <constant name="struts.objectFactory.spring.autoWire" value="name" />
> > <package name="proyectox" extends="json-default" >
> > <!-- Si no le pones este stack, pues no funciona...-->
> > <interceptors>
> > <interceptor name="strutsSpring"
> >
> > class="com.proyectox.ui.interceptor.HibernateOpenSessionInViewInterceptor"/>
> > <interceptor name="viewuseragentselector"
> > class="com.proyectox.ui.interceptor.UserAgentResultInterceptor"/>
> > <interceptor-stack name="strutsSpringPPPStack">
> > <interceptor-ref name="strutsSpring"/>
> > <interceptor-ref name="paramsPrepareParamsStack"/>
> > <interceptor-ref name="viewuseragentselector"/>
> > </interceptor-stack>
> > </interceptors>
> > ...
> > </package>
> >
> > <package name="cfdi" extends="proyectox" namespace="/cfdi">
> > <action name="header_*" class="com.fcm.cfdi.ui.HeaderAction">
> > <result type="redirectAction">
> > <param name="actionName">edit</param>
> > </result>
> > <!-- <result >printHeader.jsp</result>-->
> > <result name="input">headerEdit.jsp</result>
> > <result name="error">/facturaerror.jsp</result>
> > <interceptor-ref name="scope">
> > <param name="session">contribuyente</param>
> > <param name="autoCreateSession">true</param>
> > <param name="key">contribuyenteActual</param>
> > </interceptor-ref>
> > <interceptor-ref name="scope">
> > <param name="session">factura</param>
> > <param name="autoCreateSession">false</param>
> > <param name="key">cfdi</param>
> > </interceptor-ref>
> > <interceptor-ref name="strutsSpringPPPStack"/>
> > </action>
> >
> >
> >
> > HeaderAction.java:
> >
> > public class HeaderAction extends ActionSupport implements Preparable {
> > protected Contribuyente contribuyente;
> > protected Long contribuyenteId;
> >
> > public void prepare() throws Exception {
> > ...
> > }
> >
> >
> > public String input(){
> >
> > dirReceptorId = factura.getDomicilioReceptor().getId();
> > dirEmisionId = factura.getDomicilioEmision().getId();
> > return INPUT;
> > }
> > ...
> > public Contribuyente getContribuyente() {
> > return contribuyente;
> > }
> >
> > public void setContribuyente(Contribuyente contribuyente) {
> > this.contribuyente = contribuyente;
> > }
> > ...
> > }
> >
> > edit.jsp:
> > ...
> > <s:select label="Direccion Emision"
> > name="dirEmisionId"
> > list="*contribuyente*.domicilios"
> > listKey="id"
> > listValue="nombre"
> > multiple="false"
> > size="1"
> > required="true"
> > key="factura.direccionEmision.id"
> > />
> > ...
> >
> > After loading *struts2-rest-plugin-2.3.16.jar* it starts giving the
> > following exception:
> > Caused by: org.hibernate.LazyInitializationException: failed to lazily
> > initialize a collection of role: *contribuyentes.domicilios*, no session or
> > session was closed
> > ...
> >
> > I know that's a Hibernate exception, but the jsp works fine without the
> > REST Plugin.
> > It's like the REST Plugin appends that extra "s" after the variable name in
> > the .jsp or the value stack changes or something like that.
> >
> > The action is invoked without error in either case, and has into it's
> > fields the required values.
> >
> >
> > Does anyone has any pointer of what can be happening?
> >
> > Thanks
> >
> > Si quieres ser más positivo, pierde un electrón
> > Miguel Ruiz Velasco Sobrino
> >
 		 	   		  

Re: REST question

Posted by Miguel <mi...@gmail.com>.
Thanks Lukasz, the REST namespace makes everything work well with the REST
Plugin loaded.
Now the real work begins, but that will be for tomorrow morning.

Regards

Miguel

Si quieres ser más positivo, pierde un electrón
Miguel Ruiz Velasco Sobrino


On Tue, Feb 11, 2014 at 11:46 PM, Lukasz Lenart <lu...@apache.org>wrote:

> You can define REST namespace
>
> http://struts.apache.org/release/2.3.x/docs/rest-plugin.html#RESTPlugin-Settings
>
> struts.rest.namespace = /rest
>
>
> Regards
> --
> Łukasz
> + 48 606 323 122 http://www.lenart.org.pl/
>
> 2014-02-12 0:15 GMT+01:00 Miguel <mi...@gmail.com>:
> > Hi Ken,
> >
> > Thanks for the pointer, In fact the app uses open session in view with a
> > custom interceptor, but does the REST Plugin changes the struts-default
> and
> > the json-default packages when you include the
> > struts2-rest-plugin-2.3.16.jar?
> >
> >
> > That could explain what is happening, but, how I assing the rest-default
> > stack to my Rest controllers ONLY, and the other 'old' actions continue
> to
> > work with the custom stack (Spring + Open_session_in_view +
> > paramsPrepareParamsStack), based on package json-default? It's a rather
> big
> > application and can't be refactored to be REST only.
> >
> > Thanks for your time reading an replying the question.
> >
> >
> >
> >
> > Si quieres ser más positivo, pierde un electrón
> > Miguel Ruiz Velasco Sobrino
> >
> >
> > On Tue, Feb 11, 2014 at 3:42 PM, Ken McWilliams <
> ken.mcwilliams@gmail.com>wrote:
> >
> >> Sounds like you have used the Open Session in View method... probably
> >> provided by a custom interceptor, when adding the rest plugin you have
> >> changed your action to the rest package and forgot to put your
> interceptor
> >> back in place, so now you don't have a hibernate session and the view
> >> generates this error.
> >>
> >>
> >> On Mon, Feb 10, 2014 at 10:40 PM, Miguel <mi...@gmail.com> wrote:
> >>
> >> > Hi,
> >> >
> >> > A strange situation happens when I load
> *struts2-rest-plugin-2.3.16.jar*
> >> > With out the REST plugin my action and jsp's works as always has
> worked.
> >> > But with the mere inclusion of the REST Plugin, some jsp's stops
> finding
> >> > variables, because the variable name changes.
> >> > Here is the snippet:
> >> >
> >> > struts.xml
> >> >
> >> >     <constant name="struts.objectFactory"
> >> > value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
> >> >     <constant name="struts.objectFactory.spring.autoWire"
> value="name" />
> >> >     <package name="proyectox" extends="json-default" >
> >> > <!-- Si no le pones este stack, pues no funciona...-->
> >> >         <interceptors>
> >> >             <interceptor name="strutsSpring"
> >> >
> >> >
> >>
> class="com.proyectox.ui.interceptor.HibernateOpenSessionInViewInterceptor"/>
> >> >             <interceptor name="viewuseragentselector"
> >> > class="com.proyectox.ui.interceptor.UserAgentResultInterceptor"/>
> >> >             <interceptor-stack name="strutsSpringPPPStack">
> >> >                 <interceptor-ref name="strutsSpring"/>
> >> >                 <interceptor-ref name="paramsPrepareParamsStack"/>
> >> >                 <interceptor-ref name="viewuseragentselector"/>
> >> >             </interceptor-stack>
> >> >         </interceptors>
> >> > ...
> >> >     </package>
> >> >
> >> >     <package name="cfdi" extends="proyectox" namespace="/cfdi">
> >> >         <action name="header_*" class="com.fcm.cfdi.ui.HeaderAction">
> >> >             <result type="redirectAction">
> >> >                 <param name="actionName">edit</param>
> >> >             </result>
> >> > <!--            <result >printHeader.jsp</result>-->
> >> >             <result name="input">headerEdit.jsp</result>
> >> >             <result name="error">/facturaerror.jsp</result>
> >> >             <interceptor-ref name="scope">
> >> >                 <param name="session">contribuyente</param>
> >> >                 <param name="autoCreateSession">true</param>
> >> >                 <param name="key">contribuyenteActual</param>
> >> >             </interceptor-ref>
> >> >             <interceptor-ref name="scope">
> >> >                 <param name="session">factura</param>
> >> >                 <param name="autoCreateSession">false</param>
> >> >                 <param name="key">cfdi</param>
> >> >             </interceptor-ref>
> >> >             <interceptor-ref name="strutsSpringPPPStack"/>
> >> >         </action>
> >> >
> >> >
> >> >
> >> > HeaderAction.java:
> >> >
> >> > public class HeaderAction extends ActionSupport implements Preparable
> {
> >> >     protected Contribuyente contribuyente;
> >> >     protected Long contribuyenteId;
> >> >
> >> >     public void prepare() throws Exception {
> >> >     ...
> >> >     }
> >> >
> >> >
> >> >     public String input(){
> >> >
> >> >         dirReceptorId = factura.getDomicilioReceptor().getId();
> >> >         dirEmisionId  = factura.getDomicilioEmision().getId();
> >> >         return INPUT;
> >> >     }
> >> > ...
> >> >     public Contribuyente getContribuyente() {
> >> >         return contribuyente;
> >> >     }
> >> >
> >> >     public void setContribuyente(Contribuyente contribuyente) {
> >> >         this.contribuyente = contribuyente;
> >> >     }
> >> > ...
> >> > }
> >> >
> >> > edit.jsp:
> >> > ...
> >> >     <s:select label="Direccion Emision"
> >> >        name="dirEmisionId"
> >> >        list="*contribuyente*.domicilios"
> >> >        listKey="id"
> >> >        listValue="nombre"
> >> >        multiple="false"
> >> >        size="1"
> >> >        required="true"
> >> >        key="factura.direccionEmision.id"
> >> >     />
> >> > ...
> >> >
> >> > After loading *struts2-rest-plugin-2.3.16.jar* it starts giving the
> >> > following exception:
> >> > Caused by: org.hibernate.LazyInitializationException: failed to lazily
> >> > initialize a collection of role: *contribuyentes.domicilios*, no
> session
> >> or
> >> > session was closed
> >> > ...
> >> >
> >> > I know that's a Hibernate exception, but the jsp works fine without
> the
> >> > REST Plugin.
> >> > It's like the REST Plugin appends that extra "s" after the variable
> name
> >> in
> >> > the .jsp or the value stack changes or something like that.
> >> >
> >> > The action is invoked without error in either case, and has into it's
> >> > fields the required values.
> >> >
> >> >
> >> > Does anyone has any pointer of what can be happening?
> >> >
> >> > Thanks
> >> >
> >> > Si quieres ser más positivo, pierde un electrón
> >> > Miguel Ruiz Velasco Sobrino
> >> >
> >>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

Re: REST question

Posted by Lukasz Lenart <lu...@apache.org>.
You can define REST namespace
http://struts.apache.org/release/2.3.x/docs/rest-plugin.html#RESTPlugin-Settings

struts.rest.namespace = /rest


Regards
-- 
Łukasz
+ 48 606 323 122 http://www.lenart.org.pl/

2014-02-12 0:15 GMT+01:00 Miguel <mi...@gmail.com>:
> Hi Ken,
>
> Thanks for the pointer, In fact the app uses open session in view with a
> custom interceptor, but does the REST Plugin changes the struts-default and
> the json-default packages when you include the
> struts2-rest-plugin-2.3.16.jar?
>
>
> That could explain what is happening, but, how I assing the rest-default
> stack to my Rest controllers ONLY, and the other 'old' actions continue to
> work with the custom stack (Spring + Open_session_in_view +
> paramsPrepareParamsStack), based on package json-default? It's a rather big
> application and can't be refactored to be REST only.
>
> Thanks for your time reading an replying the question.
>
>
>
>
> Si quieres ser más positivo, pierde un electrón
> Miguel Ruiz Velasco Sobrino
>
>
> On Tue, Feb 11, 2014 at 3:42 PM, Ken McWilliams <ke...@gmail.com>wrote:
>
>> Sounds like you have used the Open Session in View method... probably
>> provided by a custom interceptor, when adding the rest plugin you have
>> changed your action to the rest package and forgot to put your interceptor
>> back in place, so now you don't have a hibernate session and the view
>> generates this error.
>>
>>
>> On Mon, Feb 10, 2014 at 10:40 PM, Miguel <mi...@gmail.com> wrote:
>>
>> > Hi,
>> >
>> > A strange situation happens when I load *struts2-rest-plugin-2.3.16.jar*
>> > With out the REST plugin my action and jsp's works as always has worked.
>> > But with the mere inclusion of the REST Plugin, some jsp's stops finding
>> > variables, because the variable name changes.
>> > Here is the snippet:
>> >
>> > struts.xml
>> >
>> >     <constant name="struts.objectFactory"
>> > value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
>> >     <constant name="struts.objectFactory.spring.autoWire" value="name" />
>> >     <package name="proyectox" extends="json-default" >
>> > <!-- Si no le pones este stack, pues no funciona...-->
>> >         <interceptors>
>> >             <interceptor name="strutsSpring"
>> >
>> >
>> class="com.proyectox.ui.interceptor.HibernateOpenSessionInViewInterceptor"/>
>> >             <interceptor name="viewuseragentselector"
>> > class="com.proyectox.ui.interceptor.UserAgentResultInterceptor"/>
>> >             <interceptor-stack name="strutsSpringPPPStack">
>> >                 <interceptor-ref name="strutsSpring"/>
>> >                 <interceptor-ref name="paramsPrepareParamsStack"/>
>> >                 <interceptor-ref name="viewuseragentselector"/>
>> >             </interceptor-stack>
>> >         </interceptors>
>> > ...
>> >     </package>
>> >
>> >     <package name="cfdi" extends="proyectox" namespace="/cfdi">
>> >         <action name="header_*" class="com.fcm.cfdi.ui.HeaderAction">
>> >             <result type="redirectAction">
>> >                 <param name="actionName">edit</param>
>> >             </result>
>> > <!--            <result >printHeader.jsp</result>-->
>> >             <result name="input">headerEdit.jsp</result>
>> >             <result name="error">/facturaerror.jsp</result>
>> >             <interceptor-ref name="scope">
>> >                 <param name="session">contribuyente</param>
>> >                 <param name="autoCreateSession">true</param>
>> >                 <param name="key">contribuyenteActual</param>
>> >             </interceptor-ref>
>> >             <interceptor-ref name="scope">
>> >                 <param name="session">factura</param>
>> >                 <param name="autoCreateSession">false</param>
>> >                 <param name="key">cfdi</param>
>> >             </interceptor-ref>
>> >             <interceptor-ref name="strutsSpringPPPStack"/>
>> >         </action>
>> >
>> >
>> >
>> > HeaderAction.java:
>> >
>> > public class HeaderAction extends ActionSupport implements Preparable {
>> >     protected Contribuyente contribuyente;
>> >     protected Long contribuyenteId;
>> >
>> >     public void prepare() throws Exception {
>> >     ...
>> >     }
>> >
>> >
>> >     public String input(){
>> >
>> >         dirReceptorId = factura.getDomicilioReceptor().getId();
>> >         dirEmisionId  = factura.getDomicilioEmision().getId();
>> >         return INPUT;
>> >     }
>> > ...
>> >     public Contribuyente getContribuyente() {
>> >         return contribuyente;
>> >     }
>> >
>> >     public void setContribuyente(Contribuyente contribuyente) {
>> >         this.contribuyente = contribuyente;
>> >     }
>> > ...
>> > }
>> >
>> > edit.jsp:
>> > ...
>> >     <s:select label="Direccion Emision"
>> >        name="dirEmisionId"
>> >        list="*contribuyente*.domicilios"
>> >        listKey="id"
>> >        listValue="nombre"
>> >        multiple="false"
>> >        size="1"
>> >        required="true"
>> >        key="factura.direccionEmision.id"
>> >     />
>> > ...
>> >
>> > After loading *struts2-rest-plugin-2.3.16.jar* it starts giving the
>> > following exception:
>> > Caused by: org.hibernate.LazyInitializationException: failed to lazily
>> > initialize a collection of role: *contribuyentes.domicilios*, no session
>> or
>> > session was closed
>> > ...
>> >
>> > I know that's a Hibernate exception, but the jsp works fine without the
>> > REST Plugin.
>> > It's like the REST Plugin appends that extra "s" after the variable name
>> in
>> > the .jsp or the value stack changes or something like that.
>> >
>> > The action is invoked without error in either case, and has into it's
>> > fields the required values.
>> >
>> >
>> > Does anyone has any pointer of what can be happening?
>> >
>> > Thanks
>> >
>> > Si quieres ser más positivo, pierde un electrón
>> > Miguel Ruiz Velasco Sobrino
>> >
>>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: REST question

Posted by Miguel <mi...@gmail.com>.
Hi Ken,

Thanks for the pointer, In fact the app uses open session in view with a
custom interceptor, but does the REST Plugin changes the struts-default and
the json-default packages when you include the
struts2-rest-plugin-2.3.16.jar?


That could explain what is happening, but, how I assing the rest-default
stack to my Rest controllers ONLY, and the other 'old' actions continue to
work with the custom stack (Spring + Open_session_in_view +
paramsPrepareParamsStack), based on package json-default? It's a rather big
application and can't be refactored to be REST only.

Thanks for your time reading an replying the question.




Si quieres ser más positivo, pierde un electrón
Miguel Ruiz Velasco Sobrino


On Tue, Feb 11, 2014 at 3:42 PM, Ken McWilliams <ke...@gmail.com>wrote:

> Sounds like you have used the Open Session in View method... probably
> provided by a custom interceptor, when adding the rest plugin you have
> changed your action to the rest package and forgot to put your interceptor
> back in place, so now you don't have a hibernate session and the view
> generates this error.
>
>
> On Mon, Feb 10, 2014 at 10:40 PM, Miguel <mi...@gmail.com> wrote:
>
> > Hi,
> >
> > A strange situation happens when I load *struts2-rest-plugin-2.3.16.jar*
> > With out the REST plugin my action and jsp's works as always has worked.
> > But with the mere inclusion of the REST Plugin, some jsp's stops finding
> > variables, because the variable name changes.
> > Here is the snippet:
> >
> > struts.xml
> >
> >     <constant name="struts.objectFactory"
> > value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
> >     <constant name="struts.objectFactory.spring.autoWire" value="name" />
> >     <package name="proyectox" extends="json-default" >
> > <!-- Si no le pones este stack, pues no funciona...-->
> >         <interceptors>
> >             <interceptor name="strutsSpring"
> >
> >
> class="com.proyectox.ui.interceptor.HibernateOpenSessionInViewInterceptor"/>
> >             <interceptor name="viewuseragentselector"
> > class="com.proyectox.ui.interceptor.UserAgentResultInterceptor"/>
> >             <interceptor-stack name="strutsSpringPPPStack">
> >                 <interceptor-ref name="strutsSpring"/>
> >                 <interceptor-ref name="paramsPrepareParamsStack"/>
> >                 <interceptor-ref name="viewuseragentselector"/>
> >             </interceptor-stack>
> >         </interceptors>
> > ...
> >     </package>
> >
> >     <package name="cfdi" extends="proyectox" namespace="/cfdi">
> >         <action name="header_*" class="com.fcm.cfdi.ui.HeaderAction">
> >             <result type="redirectAction">
> >                 <param name="actionName">edit</param>
> >             </result>
> > <!--            <result >printHeader.jsp</result>-->
> >             <result name="input">headerEdit.jsp</result>
> >             <result name="error">/facturaerror.jsp</result>
> >             <interceptor-ref name="scope">
> >                 <param name="session">contribuyente</param>
> >                 <param name="autoCreateSession">true</param>
> >                 <param name="key">contribuyenteActual</param>
> >             </interceptor-ref>
> >             <interceptor-ref name="scope">
> >                 <param name="session">factura</param>
> >                 <param name="autoCreateSession">false</param>
> >                 <param name="key">cfdi</param>
> >             </interceptor-ref>
> >             <interceptor-ref name="strutsSpringPPPStack"/>
> >         </action>
> >
> >
> >
> > HeaderAction.java:
> >
> > public class HeaderAction extends ActionSupport implements Preparable {
> >     protected Contribuyente contribuyente;
> >     protected Long contribuyenteId;
> >
> >     public void prepare() throws Exception {
> >     ...
> >     }
> >
> >
> >     public String input(){
> >
> >         dirReceptorId = factura.getDomicilioReceptor().getId();
> >         dirEmisionId  = factura.getDomicilioEmision().getId();
> >         return INPUT;
> >     }
> > ...
> >     public Contribuyente getContribuyente() {
> >         return contribuyente;
> >     }
> >
> >     public void setContribuyente(Contribuyente contribuyente) {
> >         this.contribuyente = contribuyente;
> >     }
> > ...
> > }
> >
> > edit.jsp:
> > ...
> >     <s:select label="Direccion Emision"
> >        name="dirEmisionId"
> >        list="*contribuyente*.domicilios"
> >        listKey="id"
> >        listValue="nombre"
> >        multiple="false"
> >        size="1"
> >        required="true"
> >        key="factura.direccionEmision.id"
> >     />
> > ...
> >
> > After loading *struts2-rest-plugin-2.3.16.jar* it starts giving the
> > following exception:
> > Caused by: org.hibernate.LazyInitializationException: failed to lazily
> > initialize a collection of role: *contribuyentes.domicilios*, no session
> or
> > session was closed
> > ...
> >
> > I know that's a Hibernate exception, but the jsp works fine without the
> > REST Plugin.
> > It's like the REST Plugin appends that extra "s" after the variable name
> in
> > the .jsp or the value stack changes or something like that.
> >
> > The action is invoked without error in either case, and has into it's
> > fields the required values.
> >
> >
> > Does anyone has any pointer of what can be happening?
> >
> > Thanks
> >
> > Si quieres ser más positivo, pierde un electrón
> > Miguel Ruiz Velasco Sobrino
> >
>

Re: REST question

Posted by Ken McWilliams <ke...@gmail.com>.
Sounds like you have used the Open Session in View method... probably
provided by a custom interceptor, when adding the rest plugin you have
changed your action to the rest package and forgot to put your interceptor
back in place, so now you don't have a hibernate session and the view
generates this error.


On Mon, Feb 10, 2014 at 10:40 PM, Miguel <mi...@gmail.com> wrote:

> Hi,
>
> A strange situation happens when I load *struts2-rest-plugin-2.3.16.jar*
> With out the REST plugin my action and jsp's works as always has worked.
> But with the mere inclusion of the REST Plugin, some jsp's stops finding
> variables, because the variable name changes.
> Here is the snippet:
>
> struts.xml
>
>     <constant name="struts.objectFactory"
> value="org.apache.struts2.spring.StrutsSpringObjectFactory" />
>     <constant name="struts.objectFactory.spring.autoWire" value="name" />
>     <package name="proyectox" extends="json-default" >
> <!-- Si no le pones este stack, pues no funciona...-->
>         <interceptors>
>             <interceptor name="strutsSpring"
>
> class="com.proyectox.ui.interceptor.HibernateOpenSessionInViewInterceptor"/>
>             <interceptor name="viewuseragentselector"
> class="com.proyectox.ui.interceptor.UserAgentResultInterceptor"/>
>             <interceptor-stack name="strutsSpringPPPStack">
>                 <interceptor-ref name="strutsSpring"/>
>                 <interceptor-ref name="paramsPrepareParamsStack"/>
>                 <interceptor-ref name="viewuseragentselector"/>
>             </interceptor-stack>
>         </interceptors>
> ...
>     </package>
>
>     <package name="cfdi" extends="proyectox" namespace="/cfdi">
>         <action name="header_*" class="com.fcm.cfdi.ui.HeaderAction">
>             <result type="redirectAction">
>                 <param name="actionName">edit</param>
>             </result>
> <!--            <result >printHeader.jsp</result>-->
>             <result name="input">headerEdit.jsp</result>
>             <result name="error">/facturaerror.jsp</result>
>             <interceptor-ref name="scope">
>                 <param name="session">contribuyente</param>
>                 <param name="autoCreateSession">true</param>
>                 <param name="key">contribuyenteActual</param>
>             </interceptor-ref>
>             <interceptor-ref name="scope">
>                 <param name="session">factura</param>
>                 <param name="autoCreateSession">false</param>
>                 <param name="key">cfdi</param>
>             </interceptor-ref>
>             <interceptor-ref name="strutsSpringPPPStack"/>
>         </action>
>
>
>
> HeaderAction.java:
>
> public class HeaderAction extends ActionSupport implements Preparable {
>     protected Contribuyente contribuyente;
>     protected Long contribuyenteId;
>
>     public void prepare() throws Exception {
>     ...
>     }
>
>
>     public String input(){
>
>         dirReceptorId = factura.getDomicilioReceptor().getId();
>         dirEmisionId  = factura.getDomicilioEmision().getId();
>         return INPUT;
>     }
> ...
>     public Contribuyente getContribuyente() {
>         return contribuyente;
>     }
>
>     public void setContribuyente(Contribuyente contribuyente) {
>         this.contribuyente = contribuyente;
>     }
> ...
> }
>
> edit.jsp:
> ...
>     <s:select label="Direccion Emision"
>        name="dirEmisionId"
>        list="*contribuyente*.domicilios"
>        listKey="id"
>        listValue="nombre"
>        multiple="false"
>        size="1"
>        required="true"
>        key="factura.direccionEmision.id"
>     />
> ...
>
> After loading *struts2-rest-plugin-2.3.16.jar* it starts giving the
> following exception:
> Caused by: org.hibernate.LazyInitializationException: failed to lazily
> initialize a collection of role: *contribuyentes.domicilios*, no session or
> session was closed
> ...
>
> I know that's a Hibernate exception, but the jsp works fine without the
> REST Plugin.
> It's like the REST Plugin appends that extra "s" after the variable name in
> the .jsp or the value stack changes or something like that.
>
> The action is invoked without error in either case, and has into it's
> fields the required values.
>
>
> Does anyone has any pointer of what can be happening?
>
> Thanks
>
> Si quieres ser más positivo, pierde un electrón
> Miguel Ruiz Velasco Sobrino
>