Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Shantanu Puranik
Calling ResourceServingPortlet via java based fat client
May 8, 2012 6:49 AM
Answer

Shantanu Puranik

Rank: Junior Member

Posts: 34

Join Date: January 21, 2011

Recent Posts

Hello,

I'm doing a POC for the following requirement:
Eclipse RCP based fat client requests for a file resource using Apache HttpClient to a portlet which implements ResourceServingPortlet interface. This portlet dynamically generates and returns the requested file.

Current implementation:
A portlet extends com.liferay.util.bridges.mvc.MVCPortlet.
In doView() method, resource url is generated and resource id is set
1ResourceURL resourceUrl = response.createResourceURL();
2resourceUrl.setResourceID("xyz_resourceId");
3String resourceUrlString = resourceUrl.toString();
4response.addProperty("portletResourceUrl", resourceUrlString);

In serveResource() method, content type is set and some string is written onto PortletOutputStream.
1response.setContentType("text/plain");
2response.getPortletOutputStream().write("Hello World".getBytes());


Problem faced:
Resource url is set as header via response.addProperty() but, no header found in the response received by HttpClient.
Logged resource url works perfectly when copy/pasted in address bar of browser. It calls serveResource() and outputs the string Hello World.
What am I missing while setting header? Is there alternate approach to retrieve the resource url at HttpClient end?

Many Thanks.
Shantanu Puranik
RE: Calling ResourceServingPortlet via java based fat client
June 6, 2012 10:27 PM
Answer

Shantanu Puranik

Rank: Junior Member

Posts: 34

Join Date: January 21, 2011

Recent Posts

Any thoughts about the approach above?

There are other two approaches that I tried and they both worked but, does not sounds cleaner to me.

Approach1:
Embed the resourceURL string into some custom xml tag and write it to portlet output stream.
The xml tags with string content is in the body of response. No headers used.
Parse the response at client and retrieve the resourceURL.
Here, response is having much more information than what is required and the whole response string needs to be scanned.

Approach2:
Create a servlet as part of the same application and configure in web.xml
In doView method add resourceURL as request attribute and then, forward the request & response objects to servlet via named dispatcher.
Servlet adds a header containing resourceURL into the response.
Receive the resourceURL header in a response at client.
Here, you require additional servlet which does nothing but adds a header.
Also you need to configure it in web.xml and then used named dispatcher to forward request & response objects from portlet to this servlet.

Experts please comment.