Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    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 13:29 Go to next message
Setya Nugdjaja is currently offline Setya NugdjajaFriend
Messages: 567
Registered: July 2009
Senior Member
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 21:54 Go to previous messageGo to next message
Ralf Sternberg is currently offline Ralf SternbergFriend
Messages: 1313
Registered: July 2009
Senior Member

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] Fri, 16 July 2010 03:17 Go to previous message
Setya Nugdjaja is currently offline Setya NugdjajaFriend
Messages: 567
Registered: July 2009
Senior Member
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: Fri Mar 29 06:11:48 GMT 2024

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

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

Back to the top