Skip to main content



      Home
Home » Eclipse Projects » Remote Application Platform (RAP) » How to reliably share object between RAP and Servlets ?
How to reliably share object between RAP and Servlets ? [message #546875] Wed, 14 July 2010 09:29 Go to next message
Eclipse UserFriend
Hi all,

I include a servlet into my RAP application using
org.eclipse.equinox.http.registry.servlets ext. point.

When I need to inject some object references into this servlet from RAP
I use the following code :

ServletContext context = RWT.getRequest().getSession().getServletContext();

Object myObject = ...
context.setAttribute("mykey",myobject);

and from my servlet I use the following to get the value:

ServletContext context = request.getSession().getServletContext();
Object myObject = context.getAttribute("mykey");

But it seems that I can not reliably share object this way since
sometimes I get null reference in my servlet.

So what is the more reliable way to do this ?

Any help would be greatly appreciated.


Best Regards,

Setya
Re: How to reliably share object between RAP and Servlets ? [message #547199 is a reply to message #546875] Thu, 15 July 2010 17:54 Go to previous messageGo to next message
Eclipse UserFriend
Hi Setya,

did you consider implementing a custom IServiceHandler instead of using
a servlet? Servlet handlers compare to servlets but can access
application state. They can be registered programmatically or via
extension point. See our FAQ for an example.

Best regards, Ralf

Setya wrote:
> Hi all,
>
> I include a servlet into my RAP application using
> org.eclipse.equinox.http.registry.servlets ext. point.
>
> When I need to inject some object references into this servlet from RAP
> I use the following code :
>
> ServletContext context = RWT.getRequest().getSession().getServletContext();
>
> Object myObject = ...
> context.setAttribute("mykey",myobject);
>
> and from my servlet I use the following to get the value:
>
> ServletContext context = request.getSession().getServletContext();
> Object myObject = context.getAttribute("mykey");
>
> But it seems that I can not reliably share object this way since
> sometimes I get null reference in my servlet.
>
> So what is the more reliable way to do this ?
>
> Any help would be greatly appreciated.
>
>
> Best Regards,
>
> Setya
Re: How to reliably share object between RAP and Servlets ? [message #547229 is a reply to message #547199] Thu, 15 July 2010 23:17 Go to previous message
Eclipse UserFriend
Hi Ralf,

Thank you for your advice.

We use servlet because we need to accept data that comes from HTTP POST
sent by devices. When the data arrives the servlet will notify UI via
Display which is stored in servlet context.

We've never used IServiceHandler before but if it can do the job we
won't hesitate switching to it as it seems to be a lot easier.

Thanks & Regards,

Setya

> Hi Setya,
>
> did you consider implementing a custom IServiceHandler instead of using
> a servlet? Servlet handlers compare to servlets but can access
> application state. They can be registered programmatically or via
> extension point. See our FAQ for an example.
>
> Best regards, Ralf
>
> Setya wrote:
>> Hi all,
>>
>> I include a servlet into my RAP application using
>> org.eclipse.equinox.http.registry.servlets ext. point.
>>
>> When I need to inject some object references into this servlet from RAP
>> I use the following code :
>>
>> ServletContext context = RWT.getRequest().getSession().getServletContext();
>>
>> Object myObject = ...
>> context.setAttribute("mykey",myobject);
>>
>> and from my servlet I use the following to get the value:
>>
>> ServletContext context = request.getSession().getServletContext();
>> Object myObject = context.getAttribute("mykey");
>>
>> But it seems that I can not reliably share object this way since
>> sometimes I get null reference in my servlet.
>>
>> So what is the more reliable way to do this ?
>>
>> Any help would be greatly appreciated.
>>
>>
>> Best Regards,
>>
>> Setya
Previous Topic:Unable to decide wether to show exit confirmation
Next Topic:BIRT integration
Goto Forum:
  


Current Time: Sun Apr 20 22:08:20 EDT 2025

Powered by FUDForum. Page generated in 0.03078 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top