Steps:
1. Create a new plugin (Ex: ConsumerPortlet-portlet)
2. copy following jar files into project lib folder
·
ProducerPortlet-portlet-client.jar file which is
in producer
portlet/docroot/WEB-INF/client
·
axis.jar available at portal/lib/portal folder
·
commons-discovery.jar available at
portal/lib/portal folder
·
jaxrpc.jar available at portal/lib/portal folder
·
wsdl4j.jar available at portal/lib/portal folder
3. Write following code in view.jsp
View.jsp
<%@page import="com.liferay.producer.model.ProducerSoap"%>
<%@page import="com.liferay.producer.service.http.ProducerServiceSoap"%>
<%@page import="com.liferay.producer.service.http.ProducerServiceSoapServiceLocator"%>
<%@page import="java.net.URL"
%>
<%@ taglib
uri="http://java.sun.com/portlet_2_0" prefix="portlet" %>
<portlet:defineObjects />
This is the <b>ConsumerPortlet</b> portlet.
<%
String remoteUser = "test";
ProducerServiceSoapServiceLocator
locator = new ProducerServiceSoapServiceLocator();
ProducerServiceSoap soap=null;
try{
soap =
locator.getPlugin_producer_ProducerService(_getURL(remoteUser, "Plugin_producer_ProducerService"));
}catch(Exception e){}
ProducerSoap foo =
soap.getProducerWebservice(1);
System.out.println(foo);
System.out.println(foo.getPid());
System.out.println(foo.getCompanyId());
System.out.println(foo.getUserName());
%>
<%!
private URL
_getURL(String remoteUser, String serviceName) throws Exception {
//
Unathenticated url
String
url = "http://localhost:7070/ProducerPortlet-portlet/axis/" + serviceName;
//
Authenticated url
if (true) {
String
password = "test";
url
= "http://" + remoteUser + ":" + password + "@localhost:7070/ProducerPortlet-portlet/axis/" + serviceName;
}
System.out.println(url);
return new URL(url);
}
%>
4. Deploy and run
the application(Before deploying please enter data into Producer. Producer
table with primarykey 1 because we are retrieving row with primary key 1)
Errors and
Solutions:
1. Current URL
/ProducerPortletportlet/axis/Plugin_producer_ProducerService generates
exception: null
Solution: Please check the URL given in view.jsp is
working or not by entering that url in web browser
2. No Producer exists with the primary key 1
Solution: Enter row into Producer table with
primarykey 1 because we are retrieving row with primary key 1 using webservice
3. ClassNot FoundExceptions for org.apche.axis.Service, org.apche.axis.ServiceException,
EntitySoapServiceLocator
Solution: Jar files are not copied to lib folder.
Follow Step2.