cancel
Showing results for 
Search instead for 
Did you mean: 

Java backed web script and ability to forward request

orichaud
Champ in-the-making
Champ in-the-making
Hi,

We are currently planning to develop a java backed webscript whose purpose will be to:
1- retrieve a document stored into Alfresco
2- pass this document for further processing to a second web application collocated on the same application server as Alfresco.
3- return the the result of the processing as the output of the web script.

Naturally, the idea would be to use a RequestDispatcher obtained from the ServletConfig of the processing web application. Unfortunately, it seems this is not exposed or easily accessible from a subclass of AbstractWebScript.

Regards.

OIivier
2 REPLIES 2

orichaud
Champ in-the-making
Champ in-the-making
I made some progress, but I am still not 100% successful:


// Conversion to WebScriptServletRequest allows to access the underlying HttpServletRequest
HttpServletRequest httpRequest = ((WebScriptServletRequest)req).getHttpServletRequest();
HttpSession httpSession = httpRequest.getSession();
ServletContext thisContext = httpSession.getServletContext();

// OK: I can access the other context
ServletContext  bfContext = thisContext.getContext("/betterform");

This is blocking here: the res cannot be converted to a WebScriptServletResponse and
is an instance of org.alfresco.repo.web.scripts.RepositoryContainer.BufferedResponse which
is not accessible. The underlying HttpServletResponse is not accessible.

HttpServletResponse httpResponse = ???? ; // no obvious way to get it

RequestDispatcher dispatcher = bfContext.getRequestDispatcher("process");
xformDispatcher.forward(httpRequest, httpResponse);

At this stage, I can't extract the underlying ServletResponse and consequently can't use the forward method
of the dispatcher.

Any idea?

Olivier

ghl
Champ in-the-making
Champ in-the-making
The HttpServletResponse can be achieved with this line of code

HttpServletResponse httpResponse = WebScriptServletRuntime.getHttpServletResponse(res);

Assumming res is a WebScriptServletResponse