How to use event to send session parameter

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

How to use event to send session parameter

Nattanicha Rittammanart
Dear all,
  I need to work with session information. I knew that we can send
session information to Java engine by using event. Anyway, I don't know
how to do this. Who used to do this please tell me or tell me where I
can read this is also OK. Thanks in advance.

Nattanicha
Reply | Threaded
Open this post in threaded view
|

Re: How to use event to send session parameter

Mridul Pathak-2
There can be two cases:
1) In the request-map you are using Java Engine.  In this case of a Java
Event you can get the session object from a request object available to you
in the event by useing *getSession()* method on request object.  Now you can
get all your required session infromation from the session object.
    There are lots of examples that you can find in OFBiz for this approach.

2) In the request-map you are using Service engine, and in the service
definition you are using engine type of Java.  In this case session object
is not available to you, but it can be made availabel by adding an IN
attribute to your service definition in the following way: <attribute
mode="IN" name="session" optional="true" type="
javax.servlet.http.HttpSession"/>.
    Now you can get this session object in your Java Service from the
context map in the following way:
    HttpSession session = (HttpSession)context.get("session");

I think this way you can access the session information.


On Sat, Mar 22, 2008 at 7:03 AM, Nattanicha Rittammanart <[hidden email]>
wrote:

> Dear all,
>  I need to work with session information. I knew that we can send
> session information to Java engine by using event. Anyway, I don't know
> how to do this. Who used to do this please tell me or tell me where I
> can read this is also OK. Thanks in advance.
>
> Nattanicha
>



--
Thanks & Regards
Mridul Pathak
Hotwax Media
http://www.hotwaxmedia.com
[hidden email]
__________________________________
Office : 509.855.4113
Mobile : +919425926892
Reply | Threaded
Open this post in threaded view
|

Re: How to use event to send session parameter

Nattanicha Rittammanart
Dear Miridul,
   I use Service engine and I tried follows your suggestion. But I got
problem like this:

2008-03-24 20:03:16,468 (http-0.0.0.0-8080-Processor3) [      
AssetServices.java:37 :INFO ] session : null

but in log file I can see:

2008-03-24 20:03:16,437 (http-0.0.0.0-8080-Processor3) [    
RequestHandler.java:245:INFO ] [Processing Request]:
createAssetPrototype sessionId=C24B7F75CEE3F8413665F3D314BAFE98.jvm1

This line is print from RequestHandler.java. How can I get this
sessionId in createAssetPrototype
*
My code*
sevicedef.xml
<service engine="java" name="createAssetPrototype"
location="org.ofbiz.prototype.AssetServices" invoke="createAssetPrototype">
    <description>create asset</description>
    <auto-attributes mode="IN" entity-name="SimpleAcc" include="nonpk"
optional="true"></auto-attributes>
    <attribute type="String" mode="OUT" name="accid"
optional="false"></attribute>
    <attribute mode="IN" name="session" optional="true"
type="javax.servlet.http.HttpSession"/>
    </service>
*
Java code*
AssetServices.java
    public static Map createAssetPrototype(DispatchContext dctx, Map
context)throws IOException{
       ....
        HttpSession session = (HttpSession)context.get("session");
        Debug.logInfo("session Kae: "+session, module);
        .....
}

Please help me,
Nattanicha

Mridul Pathak wrote:

> There can be two cases:
> 1) In the request-map you are using Java Engine.  In this case of a Java
> Event you can get the session object from a request object available to you
> in the event by useing *getSession()* method on request object.  Now you can
> get all your required session infromation from the session object.
>     There are lots of examples that you can find in OFBiz for this approach.
>
> 2) In the request-map you are using Service engine, and in the service
> definition you are using engine type of Java.  In this case session object
> is not available to you, but it can be made availabel by adding an IN
> attribute to your service definition in the following way: <attribute
> mode="IN" name="session" optional="true" type="
> javax.servlet.http.HttpSession"/>.
>     Now you can get this session object in your Java Service from the
> context map in the following way:
>     HttpSession session = (HttpSession)context.get("session");
>
> I think this way you can access the session information.
>
>
> On Sat, Mar 22, 2008 at 7:03 AM, Nattanicha Rittammanart <[hidden email]>
> wrote:
>
>  
>> Dear all,
>>  I need to work with session information. I knew that we can send
>> session information to Java engine by using event. Anyway, I don't know
>> how to do this. Who used to do this please tell me or tell me where I
>> can read this is also OK. Thanks in advance.
>>
>> Nattanicha
>>
>>    
>
>
>
>  

Reply | Threaded
Open this post in threaded view
|

Re: How to use event to send session parameter

Mridul Pathak-2
Nattanicha,
     You have just added the session object as an IN parameter in your
service.  You will also need to pass the session object to the service.  I
mean to say that wherever you are preparing the input map for this
service/request, may be from some form or some other event, you will get the
session object there and pass it to the service in the input map.
e.g. If you are using an ftl, you can write following code in your form:
<#assign session = request.getSession()>
<input type="hidden" name="session" value="${session}"/>
I think this way you can get the session object in your service.
If you are using form-widgets than you may use bsh to get the session object
from request.

On Mon, Mar 24, 2008 at 6:47 PM, Nattanicha Rittammanart <[hidden email]>
wrote:

> Dear Miridul,
>   I use Service engine and I tried follows your suggestion. But I got
> problem like this:
>
> 2008-03-24 20:03:16,468 (http-0.0.0.0-8080-Processor3) [
> AssetServices.java:37 :INFO ] session : null
>
> but in log file I can see:
>
> 2008-03-24 20:03:16,437 (http-0.0.0.0-8080-Processor3) [
> RequestHandler.java:245:INFO ] [Processing Request]:
> createAssetPrototype sessionId=C24B7F75CEE3F8413665F3D314BAFE98.jvm1
>
> This line is print from RequestHandler.java. How can I get this
> sessionId in createAssetPrototype
> *
> My code*
> sevicedef.xml
> <service engine="java" name="createAssetPrototype"
> location="org.ofbiz.prototype.AssetServices"
> invoke="createAssetPrototype">
>    <description>create asset</description>
>    <auto-attributes mode="IN" entity-name="SimpleAcc" include="nonpk"
> optional="true"></auto-attributes>
>    <attribute type="String" mode="OUT" name="accid"
> optional="false"></attribute>
>     <attribute mode="IN" name="session" optional="true"
> type="javax.servlet.http.HttpSession"/>
>     </service>
> *
> Java code*
> AssetServices.java
>    public static Map createAssetPrototype(DispatchContext dctx, Map
> context)throws IOException{
>       ....
>         HttpSession session = (HttpSession)context.get("session");
>         Debug.logInfo("session Kae: "+session, module);
>        .....
> }
>
> Please help me,
> Nattanicha
>
> Mridul Pathak wrote:
> > There can be two cases:
> > 1) In the request-map you are using Java Engine.  In this case of a Java
> > Event you can get the session object from a request object available to
> you
> > in the event by useing *getSession()* method on request object.  Now you
> can
> > get all your required session infromation from the session object.
> >     There are lots of examples that you can find in OFBiz for this
> approach.
> >
> > 2) In the request-map you are using Service engine, and in the service
> > definition you are using engine type of Java.  In this case session
> object
> > is not available to you, but it can be made availabel by adding an IN
> > attribute to your service definition in the following way: <attribute
> > mode="IN" name="session" optional="true" type="
> > javax.servlet.http.HttpSession"/>.
> >     Now you can get this session object in your Java Service from the
> > context map in the following way:
> >     HttpSession session = (HttpSession)context.get("session");
> >
> > I think this way you can access the session information.
> >
> >
> > On Sat, Mar 22, 2008 at 7:03 AM, Nattanicha Rittammanart <
> [hidden email]>
> > wrote:
> >
> >
> >> Dear all,
> >>  I need to work with session information. I knew that we can send
> >> session information to Java engine by using event. Anyway, I don't know
> >> how to do this. Who used to do this please tell me or tell me where I
> >> can read this is also OK. Thanks in advance.
> >>
> >> Nattanicha
> >>
> >>
> >
> >
> >
> >
>
>


--
Thanks & Regards
Mridul Pathak
Hotwax Media
http://www.hotwaxmedia.com
[hidden email]
__________________________________
Office : 509.855.4113
Mobile : +919425926892
Reply | Threaded
Open this post in threaded view
|

RE: How to use event to send session parameter

SkipDever
mridul

I tried this and got this exception:

Type conversion of field [session] to type [javax.servlet.http.HttpSession]
failed for value "org.apache.catalina.session.StandardSessionFacade@79ae56":
org.ofbiz.base.util.GeneralException: Conversion from String to
javax.servlet.http.HttpSession not currently supported


The ftl file looks like this:

        <#assign session = request.getSession()>
      <input type="hidden" name="session" value="${session}"/>

The servicedef looks like this:

    ....
        <attribute name="session" type="javax.servlet.http.HttpSession"
mode="IN" optional="true"/>
    </service>

This would really be nice to get right to avoid using the alternative
 public static String mymethod(HttpServletRequest request,
HttpServletResponse response)


I looked in ObjectType.java file and the only supported conversions are for
simple types like Double, Integer, etc.

Note that the url parameter is passed as
?session=org.apache.catalina.session.StandardSessionFacade@79ae56

Hopefully, there is something I am missing.

Skip

-----Original Message-----
From: [hidden email] [mailto:[hidden email]]On Behalf Of
Mridul Pathak
Sent: Monday, March 24, 2008 9:14 PM
To: [hidden email]
Subject: Re: How to use event to send session parameter


Nattanicha,
     You have just added the session object as an IN parameter in your
service.  You will also need to pass the session object to the service.  I
mean to say that wherever you are preparing the input map for this
service/request, may be from some form or some other event, you will get the
session object there and pass it to the service in the input map.
e.g. If you are using an ftl, you can write following code in your form:
<#assign session = request.getSession()>
<input type="hidden" name="session" value="${session}"/>
I think this way you can get the session object in your service.
If you are using form-widgets than you may use bsh to get the session object
from request.

On Mon, Mar 24, 2008 at 6:47 PM, Nattanicha Rittammanart
<[hidden email]>
wrote:

> Dear Miridul,
>   I use Service engine and I tried follows your suggestion. But I got
> problem like this:
>
> 2008-03-24 20:03:16,468 (http-0.0.0.0-8080-Processor3) [
> AssetServices.java:37 :INFO ] session : null
>
> but in log file I can see:
>
> 2008-03-24 20:03:16,437 (http-0.0.0.0-8080-Processor3) [
> RequestHandler.java:245:INFO ] [Processing Request]:
> createAssetPrototype sessionId=C24B7F75CEE3F8413665F3D314BAFE98.jvm1
>
> This line is print from RequestHandler.java. How can I get this
> sessionId in createAssetPrototype
> *
> My code*
> sevicedef.xml
> <service engine="java" name="createAssetPrototype"
> location="org.ofbiz.prototype.AssetServices"
> invoke="createAssetPrototype">
>    <description>create asset</description>
>    <auto-attributes mode="IN" entity-name="SimpleAcc" include="nonpk"
> optional="true"></auto-attributes>
>    <attribute type="String" mode="OUT" name="accid"
> optional="false"></attribute>
>     <attribute mode="IN" name="session" optional="true"
> type="javax.servlet.http.HttpSession"/>
>     </service>
> *
> Java code*
> AssetServices.java
>    public static Map createAssetPrototype(DispatchContext dctx, Map
> context)throws IOException{
>       ....
>         HttpSession session = (HttpSession)context.get("session");
>         Debug.logInfo("session Kae: "+session, module);
>        .....
> }
>
> Please help me,
> Nattanicha
>
> Mridul Pathak wrote:
> > There can be two cases:
> > 1) In the request-map you are using Java Engine.  In this case of a Java
> > Event you can get the session object from a request object available to
> you
> > in the event by useing *getSession()* method on request object.  Now you
> can
> > get all your required session infromation from the session object.
> >     There are lots of examples that you can find in OFBiz for this
> approach.
> >
> > 2) In the request-map you are using Service engine, and in the service
> > definition you are using engine type of Java.  In this case session
> object
> > is not available to you, but it can be made availabel by adding an IN
> > attribute to your service definition in the following way: <attribute
> > mode="IN" name="session" optional="true" type="
> > javax.servlet.http.HttpSession"/>.
> >     Now you can get this session object in your Java Service from the
> > context map in the following way:
> >     HttpSession session = (HttpSession)context.get("session");
> >
> > I think this way you can access the session information.
> >
> >
> > On Sat, Mar 22, 2008 at 7:03 AM, Nattanicha Rittammanart <
> [hidden email]>
> > wrote:
> >
> >
> >> Dear all,
> >>  I need to work with session information. I knew that we can send
> >> session information to Java engine by using event. Anyway, I don't know
> >> how to do this. Who used to do this please tell me or tell me where I
> >> can read this is also OK. Thanks in advance.
> >>
> >> Nattanicha
> >>
> >>
> >
> >
> >
> >
>
>


--
Thanks & Regards
Mridul Pathak
Hotwax Media
http://www.hotwaxmedia.com
[hidden email]
__________________________________
Office : 509.855.4113
Mobile : +919425926892

No virus found in this incoming message.
Checked by AVG.
Version: 7.5.519 / Virus Database: 269.21.8/1339 - Release Date: 3/22/2008
4:43 PM

No virus found in this outgoing message.
Checked by AVG.
Version: 7.5.519 / Virus Database: 269.21.8/1339 - Release Date: 3/22/2008
4:43 PM

Reply | Threaded
Open this post in threaded view
|

Re: How to use event to send session parameter

Mridul Pathak-2
I think you can try to typecast the session object when you get it from the
context map in your service.  If still you didn't get any success with that
then I think the best and most preferable approach would be to simply right
a Java Event as you mentioned in your last mail, like as public static
String mymethod(HttpServletRequest request, HttpServletResponse response).
 Generally in a case where we need to access and work on request and session
objects, I think the preferred approach is to write a Java or Simple event.
   I would have personally preferred that :).

On Thu, Mar 27, 2008 at 12:19 PM, skip@thedevers <[hidden email]> wrote:

> mridul
>
> I tried this and got this exception:
>
> Type conversion of field [session] to type [javax.servlet.http.HttpSession
> ]
> failed for value "org.apache.catalina.session.StandardSessionFacade@79ae56
> ":
> org.ofbiz.base.util.GeneralException: Conversion from String to
> javax.servlet.http.HttpSession not currently supported
>
>
> The ftl file looks like this:
>
>        <#assign session = request.getSession()>
>      <input type="hidden" name="session" value="${session}"/>
>
> The servicedef looks like this:
>
>    ....
>        <attribute name="session" type="javax.servlet.http.HttpSession"
> mode="IN" optional="true"/>
>    </service>
>
> This would really be nice to get right to avoid using the alternative
>  public static String mymethod(HttpServletRequest request,
> HttpServletResponse response)
>
>
> I looked in ObjectType.java file and the only supported conversions are
> for
> simple types like Double, Integer, etc.
>
> Note that the url parameter is passed as
> ?session=org.apache.catalina.session.StandardSessionFacade@79ae56
>
> Hopefully, there is something I am missing.
>
> Skip
>
> -----Original Message-----
> From: [hidden email] [mailto:[hidden email]]On Behalf Of
> Mridul Pathak
> Sent: Monday, March 24, 2008 9:14 PM
> To: [hidden email]
> Subject: Re: How to use event to send session parameter
>
>
> Nattanicha,
>     You have just added the session object as an IN parameter in your
> service.  You will also need to pass the session object to the service.  I
> mean to say that wherever you are preparing the input map for this
> service/request, may be from some form or some other event, you will get
> the
> session object there and pass it to the service in the input map.
> e.g. If you are using an ftl, you can write following code in your form:
> <#assign session = request.getSession()>
> <input type="hidden" name="session" value="${session}"/>
> I think this way you can get the session object in your service.
> If you are using form-widgets than you may use bsh to get the session
> object
> from request.
>
> On Mon, Mar 24, 2008 at 6:47 PM, Nattanicha Rittammanart
> <[hidden email]>
> wrote:
>
> > Dear Miridul,
> >   I use Service engine and I tried follows your suggestion. But I got
> > problem like this:
> >
> > 2008-03-24 20:03:16,468 (http-0.0.0.0-8080-Processor3) [
> > AssetServices.java:37 :INFO ] session : null
> >
> > but in log file I can see:
> >
> > 2008-03-24 20:03:16,437 (http-0.0.0.0-8080-Processor3) [
> > RequestHandler.java:245:INFO ] [Processing Request]:
> > createAssetPrototype sessionId=C24B7F75CEE3F8413665F3D314BAFE98.jvm1
> >
> > This line is print from RequestHandler.java. How can I get this
> > sessionId in createAssetPrototype
> > *
> > My code*
> > sevicedef.xml
> > <service engine="java" name="createAssetPrototype"
> > location="org.ofbiz.prototype.AssetServices"
> > invoke="createAssetPrototype">
> >    <description>create asset</description>
> >    <auto-attributes mode="IN" entity-name="SimpleAcc" include="nonpk"
> > optional="true"></auto-attributes>
> >    <attribute type="String" mode="OUT" name="accid"
> > optional="false"></attribute>
> >     <attribute mode="IN" name="session" optional="true"
> > type="javax.servlet.http.HttpSession"/>
> >     </service>
> > *
> > Java code*
> > AssetServices.java
> >    public static Map createAssetPrototype(DispatchContext dctx, Map
> > context)throws IOException{
> >       ....
> >         HttpSession session = (HttpSession)context.get("session");
> >         Debug.logInfo("session Kae: "+session, module);
> >        .....
> > }
> >
> > Please help me,
> > Nattanicha
> >
> > Mridul Pathak wrote:
> > > There can be two cases:
> > > 1) In the request-map you are using Java Engine.  In this case of a
> Java
> > > Event you can get the session object from a request object available
> to
> > you
> > > in the event by useing *getSession()* method on request object.  Now
> you
> > can
> > > get all your required session infromation from the session object.
> > >     There are lots of examples that you can find in OFBiz for this
> > approach.
> > >
> > > 2) In the request-map you are using Service engine, and in the service
> > > definition you are using engine type of Java.  In this case session
> > object
> > > is not available to you, but it can be made availabel by adding an IN
> > > attribute to your service definition in the following way: <attribute
> > > mode="IN" name="session" optional="true" type="
> > > javax.servlet.http.HttpSession"/>.
> > >     Now you can get this session object in your Java Service from the
> > > context map in the following way:
> > >     HttpSession session = (HttpSession)context.get("session");
> > >
> > > I think this way you can access the session information.
> > >
> > >
> > > On Sat, Mar 22, 2008 at 7:03 AM, Nattanicha Rittammanart <
> > [hidden email]>
> > > wrote:
> > >
> > >
> > >> Dear all,
> > >>  I need to work with session information. I knew that we can send
> > >> session information to Java engine by using event. Anyway, I don't
> know
> > >> how to do this. Who used to do this please tell me or tell me where I
> > >> can read this is also OK. Thanks in advance.
> > >>
> > >> Nattanicha
> > >>
> > >>
> > >
> > >
> > >
> > >
> >
> >
>
>
> --
> Thanks & Regards
> Mridul Pathak
> Hotwax Media
> http://www.hotwaxmedia.com
> [hidden email]
> __________________________________
> Office : 509.855.4113
> Mobile : +919425926892
>
> No virus found in this incoming message.
> Checked by AVG.
> Version: 7.5.519 / Virus Database: 269.21.8/1339 - Release Date: 3/22/2008
> 4:43 PM
>
> No virus found in this outgoing message.
> Checked by AVG.
> Version: 7.5.519 / Virus Database: 269.21.8/1339 - Release Date: 3/22/2008
> 4:43 PM
>
>


--
Thanks & Regards
Mridul Pathak
Hotwax Media
http://www.hotwaxmedia.com
[hidden email]
__________________________________
Office : 509.855.4113
Mobile : +919425926892