Forums

Home » Liferay Portal » English » 3. Development

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Sameer Srivastava
Facing problem in consuming web service from portlet
October 17, 2012 11:25 AM
Answer

Sameer Srivastava

Rank: New Member

Posts: 14

Join Date: August 22, 2012

Recent Posts

Hello guys,

I am trying to develop a portlet that consumes a web-service.
By consuming I mean that the methods exposed by the web service needs to be called using SOAP.

The requirement is to read an uploaded file and then call the web service using the values (read from the file).

I have been able to read the uploaded file but it is the calling of the web service from within the portlet where I am facing issues.

When I call the web service from stand alone client I get the proper SOAP response but when I use the same code within my portlet I get no response NOT EVEN exception.

I have generated the Java client classes for web service using Eclipse which I am attaching:

The problem is evident when the code is unable to call the constructor for the service locator i.e. ServiceHandlerServiceLocator (name of generated service locator in my case).
I tried to trace this out using the logger statements. No exceptions could be seen when the code is being called from portlet class.

Below is the stand alone client code which is WORKING :


package com.retailsoftware.webservices;

public class WebServiceTest {

public static void main(String[] args) {

String userName = "MYWEBSERVICE";
String password = "HELLO123";
String inputXml = "<![CDATA[<document xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"file:///C:/RETAIL/quoteschema.xsd\"><request><quote owner=\"SAMEER\" request_no=\"123\"/></request></document>]]>";


try {
System.out.println(new ServiceHandlerProxy().postQuote(userName, password, inputXml));
} catch (RemoteException e) {
e.printStackTrace();
}
}
}

This gives proper SOAP response, but when a similar web service call is made from portlet , it lands no where emoticon

Below is the portlet class code which is NOT WORKING :

package uk.co.myCompany.portal.myProject.bean;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ViewScoped;

import org.portletfaces.bridge.GenericFacesPortlet;
import org.portletfaces.logging.Logger;
import org.portletfaces.logging.LoggerFactory;

@ManagedBean(name="myProject")
@ViewScoped
public class FileEntryCallbackBean extends GenericFacesPortlet implements Serializable {

private static final long serialVersionUID = 1L;

private static final Logger logger = LoggerFactory
.getLogger(FileEntryCallbackBean.class);

public void executeListener(FileEntryEvent event)
{
String userName = "MYWEBSERVICE";
String password = "HELLO123";
String inputXml = "<![CDATA[<document xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"file:///C:/RETAIL/quoteschema.xsd\"><request><quote owner=\"SAMEER\" request_no=\"123\"/></request></document>]]>";

try {
logger.info("HERE : 1");
logger.info(new ServiceHandlerProxy());
logger.info("HERE : 2");
logger.info(new ServiceHandlerProxy().postQuote(userName, password, inputXml));
} catch (Exception e) {
e.printStackTrace();
}
}
}

View page i.e. XHTML code :

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:ace="http://www.icefaces.org/icefaces/components"
xmlns:ui="http://java.sun.com/jsf/facelets"
xmlns:fn="http://java.sun.com/jsp/jstl/functions">

<h:head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Add products via CSV</title>
</h:head>

<h:body class="ice-skin-sam">
<h:form id="addProductsForm" enctype="multipart/form-data">
<ace:fileEntry id="fileEntry" label="#{myProject.label}" fileEntryListener="#{myProject.executeListener}" absolutePath="C:\temp" styleClass="ib" />
<h:commandButton styleClass="ib" value="Submit file" />
<div class="messages-holder"><h:messages styleClass="messages" showDetail="true" /></div>
</h:form>
</h:body>
</html>

I am using:
Eclipse Indigo
Java 1.7
Liferay 6.1-ce-ga1


Please help .

Regards,

Sameer
Attachments: Generated code to call WS.zip (11.6k)
Bijan Vakili
RE: Facing problem in consuming web service from portlet
October 18, 2012 1:28 AM
Answer

Bijan Vakili

Rank: Expert

Posts: 354

Join Date: March 10, 2009

Recent Posts

Sameer, without getting into specifics of WS clients since this is a Liferay forum, you can Google "CXF", see http://bit.ly/XrH0s4
Sameer Srivastava
RE: Facing problem in consuming web service from portlet
October 18, 2012 4:08 AM
Answer

Sameer Srivastava

Rank: New Member

Posts: 14

Join Date: August 22, 2012

Recent Posts

Anyone facing this issue ?
Please help.

Regards,

Sameer
Siby Mathew
RE: Facing problem in consuming web service from portlet
October 18, 2012 5:06 AM
Answer

Siby Mathew

Rank: Expert

Posts: 267

Join Date: March 4, 2011

Recent Posts

Hi Sameer,
Can the ICEFaces component be throwing any exception ?
(In my previous proj I had a no-exception case and it was caused due a null value assigned to the ui dropdown component )
Can you remove ICEFaces code and try adding a simple button calling your portlet method ?

Thanks,
Siby
Sameer Srivastava
RE: Facing problem in consuming web service from portlet
October 18, 2012 5:21 AM
Answer

Sameer Srivastava

Rank: New Member

Posts: 14

Join Date: August 22, 2012

Recent Posts

Hello Siby,

thanks for the reply.
I tried that as well. It didn't help.
I saw a post quite relating to the issue I am facing here .
Tried things given there , but still of not help.

Regards,

Sameer
Siby Mathew
RE: Facing problem in consuming web service from portlet
October 18, 2012 7:30 AM
Answer

Siby Mathew

Rank: Expert

Posts: 267

Join Date: March 4, 2011

Recent Posts

Hi Sameer,
I had a classcastexception like this. Please see my post here

Thanks,
Siby
Sameer Srivastava
RE: Facing problem in consuming web service from portlet
October 18, 2012 8:23 AM
Answer

Sameer Srivastava

Rank: New Member

Posts: 14

Join Date: August 22, 2012

Recent Posts

Hello Siby,

Thanks again for your reply.
Although I am not getting any similar exception but I am trying all the steps you have mentioned in the link.

Regards,

Sameer
Neil Griffin
RE: Facing problem in consuming web service from portlet
October 30, 2012 11:36 AM
Answer

Neil Griffin

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2365

Join Date: July 26, 2005

Recent Posts

Hi Sameer,

When you get a chance, please post a comment here with the stacktrace that you are getting.

Neil
Sameer Srivastava
RE: Facing problem in consuming web service from portlet
October 31, 2012 2:23 AM
Answer

Sameer Srivastava

Rank: New Member

Posts: 14

Join Date: August 22, 2012

Recent Posts

Hello All,

thanks for your reply and comments.
I resolved the problem very recently and should have updated it here on the forum.
I used the maven plugin "wsimport" to generate the web services Java artifacts.
Earlier, it seems like due to pointing at the wrong package structure, the application was unable to locate the web services classes like Service handler and Service.
But now it works!

Thanks again.

Regards,
Sameer