Consuming Existing Liferay Webservices


Write the following code in view.jsp:

<%@ page import="com.liferay.client.soap.portal.model.OrganizationSoap" %>
<%@ page import="com.liferay.client.soap.portal.service.http.OrganizationServiceSoap" %>
<%@ page import="com.liferay.client.soap.portal.service.http.OrganizationServiceSoapServiceLocator" %>
<%@ page import="com.liferay.portal.kernel.util.GetterUtil" %>

<%@ page import="java.net.URL" %>

You belong to the following organizations:

<br /><br />

<%
String remoteUser = request.getRemoteUser();

long userId = GetterUtil.getLong(remoteUser);

OrganizationServiceSoapServiceLocator locator = new OrganizationServiceSoapServiceLocator();

OrganizationServiceSoap soap = locator.getPortal_OrganizationService(_getURL(remoteUser, "Portal_OrganizationService"));

OrganizationSoap[] organizations = soap.getUserOrganizations(userId);

for (int i = 0; i < organizations.length; i++) {
                OrganizationSoap organization = organizations[i];
%>

                <%= organization.getName() %><br />

<%
}
%>

<%!
private URL _getURL(String remoteUser, String serviceName) throws Exception {

                // Unathenticated url

                String url = "http://localhost:8080/tunnel-web/axis/" + serviceName;

                // Authenticated url

                if (true) {
                                String password = "test";

                                url = "http://" + remoteUser + ":" + password + "@localhost:8080/tunnel-web/secure/axis/" + serviceName;
                }

                return new URL(url);
}
%>

Errors and Solutions:
1. NullPointerException/axis exception
Solution: Change port no in view.jsp to the port no what you are using
2. Refused to connect or Connection Exception:
Solution: Go to plugins/build-common-plugin.xml. Search for
<property name="client.url" value="http://localhost:7070/${plugin.name}/axis" />
Change the port no.

These rae the maximum errors you will get while using this application.

Search This Blog

All the rights are reserved to this blog is belongs to me only.. Powered by Blogger.