Foren

Facing problem in consuming web service from portlet

Sameer Srivastava, geändert vor 11 Jahren.

Facing problem in consuming web service from portlet

New Member Beiträge: 14 Beitrittsdatum: 22.08.12 Neueste Beiträge
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
thumbnail
Bijan Vakili, geändert vor 11 Jahren.

RE: Facing problem in consuming web service from portlet

Expert Beiträge: 375 Beitrittsdatum: 10.03.09 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: Facing problem in consuming web service from portlet

New Member Beiträge: 14 Beitrittsdatum: 22.08.12 Neueste Beiträge
Anyone facing this issue ?
Please help.

Regards,

Sameer
Siby Mathew, geändert vor 11 Jahren.

RE: Facing problem in consuming web service from portlet

Expert Beiträge: 268 Beitrittsdatum: 04.03.11 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: Facing problem in consuming web service from portlet

New Member Beiträge: 14 Beitrittsdatum: 22.08.12 Neueste Beiträge
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, geändert vor 11 Jahren.

RE: Facing problem in consuming web service from portlet

Expert Beiträge: 268 Beitrittsdatum: 04.03.11 Neueste Beiträge
Hi Sameer,
I had a classcastexception like this. Please see my post here

Thanks,
Siby
Sameer Srivastava, geändert vor 11 Jahren.

RE: Facing problem in consuming web service from portlet

New Member Beiträge: 14 Beitrittsdatum: 22.08.12 Neueste Beiträge
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
thumbnail
Neil Griffin, geändert vor 11 Jahren.

RE: Facing problem in consuming web service from portlet

Liferay Legend Beiträge: 2655 Beitrittsdatum: 27.07.05 Neueste Beiträge
Hi Sameer,

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

Neil
Sameer Srivastava, geändert vor 11 Jahren.

RE: Facing problem in consuming web service from portlet

New Member Beiträge: 14 Beitrittsdatum: 22.08.12 Neueste Beiträge
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