Foros de discusión

Web Service Consumer Portlet

Todd Peterson, modificado hace 12 años.

Web Service Consumer Portlet

Junior Member Mensajes: 29 Fecha de incorporación: 27/09/10 Mensajes recientes
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: http://thepetersonranch.blogspot.com/2011/10/consuming-web-services-and-ipc-part-one.html

If you find this useful, please let me know.

Thanks,
Todd
Anand Shankar, modificado hace 11 años.

RE: Web Service Consumer Portlet

New Member Mensajes: 8 Fecha de incorporación: 7/03/11 Mensajes recientes
nice one....emoticon


Thanks
Anand Shankar
www.ashankar.com
thumbnail
David H Nebinger, modificado hace 11 años.

RE: Web Service Consumer Portlet

Liferay Legend Mensajes: 14915 Fecha de incorporación: 2/09/06 Mensajes recientes
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
 List<string> countryList = CountryListLocalServiceUtil.getCountryList();</string>
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.