| Call Scout Service from webpage [message #1110840] |
Tue, 17 September 2013 07:47  |
Eclipse User |
|
|
|
Hi,
I need to get some data from and transfer some results back from a web page. (Regular site HTML5 CSS and Javascript) This data is already available for a swing client in a Scout Server and whats even more important when the data is stored, all the business rules are already implemented in the Scout Service.
Is it advisable to get and send data from a regular website to a Scout Server and if yes what is the best way to do this.
Regards Bertin
|
|
|
| Re: Call Scout Service from webpage [message #1110849 is a reply to message #1110840] |
Tue, 17 September 2013 08:02   |
Eclipse User |
|
|
|
Hi Bertin,
indeed i would re-use those services whenever possible.
Html 5 Webpages exist with or without back-end servlet/jsp/php,...
A) Page with server side php/jsp/..:
Simply call the Scout Service using a Scout Transaction. Therefore you Need a Scout Server session for that user as well as a security subject (javax.security).
The session can be obtained in the same way as the Scout servlet
does it.
private IServerSession lookupScoutServerSessionOnHttpSession(HttpServletRequest req, HttpServletResponse res, Subject subject, UserAgent userAgent) throws ProcessingException, ServletException {
//external request: apply locking, this is the session initialization phase
synchronized (req.getSession()) {
IServerSession serverSession = (IServerSession) req.getSession().getAttribute(IServerSession.class.getName());
if (serverSession == null) {
serverSession = SERVICES.getService(IServerSessionRegistryService.class).newServerSession(m_serverSessionClass, subject, userAgent);
req.getSession().setAttribute(IServerSession.class.getName(), serverSession);
}
return serverSession;
}
}
The subject can be used either from the webcontainer itself (WLS)
Subject subject = Subject.getSubject(AccessController.getContext());
or by creating one
Subject subject=new Subject();
subject.getPrincipals().add(new org.eclipse.scout.commons.security.SimplePrincipal(...));
Finally simply use
new ServerJob("web",session, subject){
protected IStatus runTransaction(IProgressMonitor monitor){
//your code goes here, you can use HttpServletRequest, HttpServletResponse etc. as well
SERVICES.getService(...).doWhatever();
}
}
B) Page without server side php/jsp/..:
In this case i would create a subclass of and override and .
There detect your Webpage request for example by using an additional URL path or a URL Parameter. Then it continues similar to A).
B2) You may also write a complete new servlet and using the concepts in A) Server Ajax Clients with exactly the protocol you Need, for example json.
Does this help?
|
|
|
|
Powered by
FUDForum. Page generated in 0.03476 seconds