Combination View Flat View Tree View
Threads [ Previous | Next ]
Todd Peterson
Web Service Consumer Portlet
October 12, 2011 7:09 AM

Todd Peterson

Rank: Junior Member

Posts: 29

Join Date: September 27, 2010

Recent Posts

I am not the blogging type, but in the interest of documenting/retaining some of my recent Liferay learnings I decided to post a couple of how-to's, in the event others are struggling with some seemingly simple Liferay concepts, as I was.

My first post documents how to create a portlet, using the Liferay plug-ins SDK for Eclipse, that consumes an internet based web service, and presents the data in an HTML SELECT dropdown. I must warn you that I make some assumptions about the environment, such as Eclipse is the IDE, the Liferay plug-ins SDK is installed, and you understand how to build and deploy portlets (I use the Tomcat server instance running in Eclipse, and the hot-deploy feature).

If folks find the how-to of value, I would be happy to move onto my second post, describing Inter Portlet Communication (IPC), using my first post as the starting point.

You will find the post at:

If you find this useful, please let me know.

Joy Y
RE: Web Service Consumer Portlet
January 16, 2013 11:28 AM

Joy Y

Rank: New Member

Posts: 7

Join Date: March 6, 2011

Recent Posts

nice one....emoticon

Anand Shankar
David H Nebinger
RE: Web Service Consumer Portlet
January 16, 2013 12:22 PM

David H Nebinger

Community Moderator

Rank: Liferay Legend

Posts: 12994

Join Date: September 1, 2006

Recent Posts

Hate to nit pick, but just a couple of suggestions to help future readers the blog entry:

* Why read the result of the web service call line by line? You could just read the whole thing into a single string, perform the same replacements on that one string, and be done with it. Line by line processing will incur unnecessary overhead.

* Just my own preference here, rather than using a heavyweight process like DOM to hold the whole document in memory, I'd use SAX (actually for this I'd use a simple commons-digester implementation) to handle getting the single element (the country name) you're interested in grabbing.

* Why return a Map<Integer, String> where the key is just the list index of the country in the XML list? Just return a List<String> and eliminate the unnecessary key.

* System.out.println() for exception handling will not do you any good. Identifying what piece of code generated an exception and resolving the problem, especially in a large-scale production system, would be like finding a needle in a haystack. Logging should always be done using some logging framework (for this case you'd use Liferay's), and leave System.out.println() to console applications.

* Do not use the <script /> tag directly in your jsp page. Script imports should either go into liferay-portlet.xml or built into your theme. Yes this method will work, but it will break down when you have multiple portlets on the page trying to do the same thing.

* The list of countries is, for the most part a static list. Your code, however, will re-retrieve and process the list every time a user lands on the page. Caching the list would improve the performance and reduce your network impact.

* You might consider using a service builder entity to encapsulate the retrieval of the list. That way, if you have multiple portlets that need access to the same data, they just defer to your CountryListLocalServiceUtil class to retrieve the map... The country list may not be a good candidate for this (I mean, how many portlets need to list all of the countries), but it would define a precedent that other readers would also follow... More importantly, you would not need to override MVCPortlet to populate the render request attribute before the actual JSP page is loaded - the JSP page could just do a
1 List<String> countryList = CountryListLocalServiceUtil.getCountryList();
call to access the list directly.

That said, it was a nice blog and I certainly do encourage you to continue with it. I hope you don't take this criticism too harshly, I'm offering it only as helpful pointers for your readers.