Forums

Home » Liferay Portal » English » Liferay Legacy »

Combination View Flat View Tree View
Threads [ Previous | Next ]
toggle
Joshua Shaffner
How to Expose and Consume a Method
October 19, 2007 12:53 PM
Answer

Joshua Shaffner

Rank: Junior Member

Posts: 34

Join Date: December 13, 2004

Recent Posts

Use Case: a remote app (CAS for SSO) to authenticate against Liferay Portal

Out of box, Liferay does not expose authentication methods so this is what I did to expose one of their methods in Extension Environment.

1. edit service.xml to include the following

<entity name="MyUser" local-service="true" remote-service="true"></entity>

2. build service, add a method in MyUserServiceImpl, and rebuild service

public int authenticateByEmailAddress(
        long companyId, String emailAddress, String password)
    throws PortalException, SystemException {

    Map headerMap = null;
    Map parameterMap = null;
   
    int isAuthenticated = UserLocalServiceUtil.authenticateByEmailAddress(companyId, emailAddress, password, headerMap, parameterMap);
   
    return isAuthenticated;
}

3. "ant build-wsdd" in ext-impl/ to generate /ext-web/docroot/WEB-INF/server-config.wsdd for SOAP calls

4. ant clean deploy and you are done exposing a method. Check it out at /tunnel-web/secure/axis. emoticon

To consume the newly exposed method, I wanted to generate ext-client.jar just like Liferay did with portal-client.jar so I did the following.

1. create ext-client/

2. copy over build.xml from portal-client/ and edit to use ext-client instead of portal-ext and to pass in server-config.wsdd from ext-web instead of tunnel-web

3. create namespaceMapping.properties and put in a mapping (package=namespace). Hint: use namespace from the value of wsdlTargetNamespace in server-config.wsdd

com.company.portal.service.http=http.service.portal.company.com

4. While localhost is up and running, run "ant build-client" to generate ext-client.jar

5. Test consuming with ext-client.jar

import java.net.URL;

import com.company.portal.service.http.MyUserServiceSoap;
import com.company.portal.service.http.MyUserServiceSoapServiceLocator;

public class LiferayClient {
    public static void main(String [] args) {
        long userId = 54321L;
        long companyId = 12345L;
        String email = "me@company.com";
        String password = "notTellingYou";
       
        try {
            MyUserServiceSoapServiceLocator locator = new MyUserServiceSoapServiceLocator();
            MyUserServiceSoap soap = locator.getPortal_MyUserService(_getURL(Long.toString(userId), "Portal_MyUserService"));
            int isAuthenticated = soap.authenticateByEmailAddress(companyId, email, password);
            System.out.println("is user authenticated? " + isAuthenticated);
        } catch (Exception e) {
            System.err.println(e.toString());
        }
       
    }
    private static URL _getURL(String remoteUser, String serviceName) throws Exception {
        String password = "secret";
        url = "http://" + remoteUser + ":" + password + "@localhost:8080/tunnel-web/secure/axis/" + serviceName;

        return new URL(url);
    }
}

Hope this help. If it does, we could turn this thread into a wiki post.
Jorge Ferrer
RE: How to Expose and Consume a Method
October 28, 2007 4:03 PM
Answer

Jorge Ferrer

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2645

Join Date: August 31, 2006

Recent Posts

Hi Joshua,

Thanks for sharing this. I think it's a great idea to convert it to a wiki article so that it doesn't get lost in the forum archives.
Joshua Shaffner
RE: How to Expose and Consume a Method
October 30, 2007 2:19 PM
Answer

Joshua Shaffner

Rank: Junior Member

Posts: 34

Join Date: December 13, 2004

Recent Posts

There it is. http://wiki.liferay.com/index.php/How_to_Expose_and_Consume_a_Method
Jorge Ferrer
RE: How to Expose and Consume a Method
October 30, 2007 5:18 PM
Answer

Jorge Ferrer

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2645

Join Date: August 31, 2006

Recent Posts

Great! Thanks a lot.
Anonymous
RE: How to Expose and Consume a Method
November 4, 2007 10:08 PM
Answer

Anonymous

how to write a handler for authentication in liefray 4.3.3
Jorge Ferrer
RE: How to Expose and Consume a Method
November 5, 2007 2:25 AM
Answer

Jorge Ferrer

LIFERAY STAFF

Rank: Liferay Legend

Posts: 2645

Join Date: August 31, 2006

Recent Posts

Hi Anonymous,

Sorry, I'm not sure what you mean. I would recommend adding as many details as possible when asking questions to maximize the chances of getting an answer. Also, please ask new questions as new threads to allow others to find it easily.
xia ning
RE: How to Expose and Consume a Method
March 18, 2008 10:39 AM
Answer

xia ning

Rank: New Member

Posts: 3

Join Date: February 12, 2008

Recent Posts

4. ant clean deploy and you are done exposing a method. Check it out at /tunnel-web/secure/axis. emoticon



But I can not find any different compared to before deploy emoticon

What change is expected?

oh i am using liferay 4.3.6
Joshua Shaffner
RE: How to Expose and Consume a Method
March 25, 2008 8:54 AM
Answer

Joshua Shaffner

Rank: Junior Member

Posts: 34

Join Date: December 13, 2004

Recent Posts

xia ning:
But I can not find any different compared to before deploy


What was the difference you hoped to see?
Julien M
RE: How to Expose and Consume a Method
April 2, 2008 7:54 AM
Answer

Julien M

Rank: New Member

Posts: 21

Join Date: March 31, 2008

Recent Posts

I created a new thread in the new liferay forum to keep the subject alive as I'm having difficulties exposing methods :
How to properly register a new webservice
Vladimir Linhart
RE: How to Expose and Consume a Method
April 22, 2008 3:16 PM
Answer

Vladimir Linhart

Rank: New Member

Posts: 4

Join Date: April 22, 2008

Recent Posts

Joshua Shaffner:

1. edit service.xml to include the following

<entity name="MyUser" local-service="true" remote-service="true"></entity>



Hello,
can you tell me which sevice.xml did you edited?
is it one in ext corresponding to this one?
/trunk/portal-impl/src/com/liferay/portal/service.xml


thanks
Joshua Shaffner
RE: How to Expose and Consume a Method
April 23, 2008 9:29 AM
Answer

Joshua Shaffner

Rank: Junior Member

Posts: 34

Join Date: December 13, 2004

Recent Posts

It depends on whether the method is portal-wide (ie: authentication) or portlet-specific (ie: add a folder in doc library). If it is portal-wide, then I would add/edit a service.xml within ext-impl/src/com/company/portal/, otherwise, ext-impl/src/com/company/portlet/<portlet_name>/.

Hope this helps.
Mohamed Ali
RE: How to Expose and Consume a Method
October 8, 2008 2:18 AM
Answer

Mohamed Ali

Rank: Junior Member

Posts: 26

Join Date: October 29, 2007

Recent Posts

Hi,
We tried to create a client for one of the methods we exposed as webservice. As your advise we created ext-client folder under ext and also the build-client file taken from portlet-client and also provided the namespaceMapping.properties file. But while buiding the build file from under ext-client, our ext-client.jar file is not generated.

As I understand there should be src and classes folder in ext-client. But you have not mentioned what source files to keep inside the src. I checked in portlet-client source also but there is nothing except the portlet-client.jar file.

One more thing, the file you mentioned "MyUserServiceSoapServiceLocator", will be avilable when the jar file called ext-client.jar is created?

Pls clarify advice how to resolve this issue.
Rafal D
RE: How to Expose and Consume a Method
April 14, 2009 7:59 AM
Answer

Rafal D

Rank: New Member

Posts: 1

Join Date: April 10, 2009

Recent Posts

Hi everone,

Joshua, Thanks a lot for tutorial You've made. I managed to generate remote service, I can see it at my: http://127.0.0.1:8080/tunnel-web//axis .

However I have problem during client generation.
I prepared ext-client directory in my ext environment, put there build.xml as mentioned in tutorial, then prepare mappings and ran "ant build-client" and then error occured:

Here is the output from ant:
...
[java] Loading file:/C:/Users/myname/workspace/myproject/ext-impl/classes/portal-ext.properties
[java] 2009-04-14 12:21:49,363 ERROR [main] DialectDetector.java:114: java.sql.SQLException: Connections could not be acquired from the underlying database!
[java] java.sql.SQLException: Connections could not be acquired from the underlying database!
[java] at com.mchange.v2.sql.SqlUtils.toSQLException(SqlUtils.java:106)
[java] at com.mchange.v2.c3p0.impl.C3P0PooledConnectionPool.checkoutPooledConnection(C3P0PooledConnectionPool.java:529)
[java] at com.mchange.v2.c3p0.impl.AbstractPoolBackedDataSource.getConnection(AbstractPoolBackedDataSource.java:128)
...

I use Tomcat 6.0.18 and liferay 5.2.2. DB in my portal-ext.properties is not configured so I suppose liferay to use HSQLDB, I am sure my tomcat with liferay is set up.

Could anyone please help me ?
Jason Fabbri
RE: How to Expose and Consume a Method
December 2, 2010 10:27 AM
Answer

Jason Fabbri

Rank: New Member

Posts: 3

Join Date: January 22, 2009

Recent Posts

I'm using 5.2.3 and am working this exact scenario. It may have been mentioned elsewhere but for the life of me I can't find the answer... which specific service.xml file is Joshua referencing to modify?

For example, grabbing the source I have:

../liferay-portal-src-5.2.3/portal-impl/src/com/liferay/portal/service.xml

Which from what I can determine here is the service.xml file you would want to modify if you wish to expose authentication portal wide. Once you have modified this file, where would you run the "ant build-service" from? Or is there the assumption that you have also built a portlet previously that is also required?

If anyone has explicit steps to creating a service that exposes authentication I would be forever grateful!

Thanks!
Jason Fabbri
RE: How to Expose and Consume a Method
December 2, 2010 1:10 PM
Answer

Jason Fabbri

Rank: New Member

Posts: 3

Join Date: January 22, 2009

Recent Posts

After some more serious head banging Joshua (if you happen to be subscribed) or anyone else, any pointers to the following questions would be great:
1) Josh notes "edit service.xml..." As one other asked, which specific service.xml file? Is it one included with the Extension environment (as it implies) or is it one located in the source from the LR trunk (as Vladimir Linhart asked)?

2) Josh notes "2. build service, add a method in MyUserServiceImpl, and rebuild service" is that indicate to build the service within the Extension environment tree or build the service within the SDK location?

I'm in a real bind in needing to get this authentication functionality up and running and continue to hit challenges around the steps here..

Thanks for any help.

Jas
Jason Fabbri
RE: How to Expose and Consume a Method
December 2, 2010 4:36 PM
Answer

Jason Fabbri

Rank: New Member

Posts: 3

Join Date: January 22, 2009

Recent Posts

Jorge,
I am trying to ask a specific question with regards to this thread. Perhaps I could get an email exchange with you regarding it?

Best,
Jason