Access a Scout Service from another servlet [message #670772] |
Sun, 15 May 2011 09:16  |
Eclipse User |
|
|
|
What is the easiest way to use Scout Services from another Non-Scout-Servlet, e.g. a GWT RemoteServiceServlet?
So far I figured out that I could create a subject and a server session and use a ServerJob:
Subject sub = new Subject();
sub.getPrincipals().add(new SimplePrincipal("admin"));
ServerSession s = SERVICES.getService(IServerSessionRegistryService.class).newServerSession(ServerSession.class, sub);
ServerJob test = new ServerJob("", s) {
@Override
protected IStatus runTransaction(IProgressMonitor monitor) throws Exception {
SERVICES.getService(I...Service.class)...();
return null;
}
};
test.setSubject(sub);
test.runNow(null);
Any ideas?
Kind regards,
Adrian
|
|
|
Re: Access a Scout Service from another servlet [message #670852 is a reply to message #670772] |
Sun, 15 May 2011 17:50  |
Eclipse User |
|
|
|
1. Use services without a session:
----------------------------------
If you do not need any session information (userId, username,...) you
can register global service.
<extension point="org.eclipse.scout.service.services">
<service
class=" bsiag.testapp.server.services.custom.test.ServiceWithoutSess ionService "
factory="org.eclipse.scout.service.DefaultServiceFactory"/ >
</extension>
Importend is to use the DefaultServiceFactory.
2. Use session based services:
------------------------------
In this case the solution is pretty similar you have done. Instead of
creating a new subject and session for every call you could create a
member on the Activator (e.g. get/setBackendSession) and create the
backend session once in the ServerApplication.start method.
ServerApplication
public Object start(IApplicationContext context) throws Exception {
....
ServerSession session =
SERVICES.getService(IServerSessionRegistryService.class).new ServerSession(ServerSession.class,
Activator.getDefault().getBackendSubject());
Activator.getDefault().setBackendSession(session);
...
logger.info("testapp server initialized");
return EXIT_OK;
}
Later instantiate the ServerJob with the backend session.
ServerJob job = new
ServerJob("",Activator.getDefault().getBackendSession()) {
...
}
-Andreas
On 15.05.2011 15:16, Adrian wrote:
> What is the easiest way to use Scout Services from another
> Non-Scout-Servlet, e.g. a GWT RemoteServiceServlet?
>
> So far I figured out that I could create a subject and a
> server session and use a ServerJob:
>
> Subject sub = new Subject();
> sub.getPrincipals().add(new
> SimplePrincipal("admin"));
>
> ServerSession s =
> SERVICES.getService(IServerSessionRegistryService.class).new ServerSession(ServerSession.class,
>
> sub);
> ServerJob test = new ServerJob("", s) {
>
> @Override
> protected IStatus runTransaction(IProgressMonitor
> monitor) throws Exception {
> SERVICES.getService(I...Service.class)...();
> return null;
> }
>
> };
>
> test.setSubject(sub);
> test.runNow(null);
>
>
> Any ideas?
>
> Kind regards,
> Adrian
|
|
|
Powered by
FUDForum. Page generated in 0.02935 seconds