Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Eclipse Projects » scout » Access a Scout Service from another servlet
Access a Scout Service from another servlet [message #670772] Sun, 15 May 2011 13:16 Go to next message
Adrian Moser
Messages: 67
Registered: March 2011
Member
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 21:50 Go to previous message
Andreas Hoegger is currently offline Andreas Hoegger
Messages: 174
Registered: February 2010
Senior Member
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
Previous Topic:Recommendation Models for Scout?
Next Topic:Enable validation of keys typed in AbstractStringField
Goto Forum:
  


Current Time: Mon Oct 20 08:12:43 GMT 2014

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

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