Question

I am running Liferay 6.1 CE on Glassfish 3.1.1.

It is my understanding that Liferay exposes its API via web service. I am hoping to use this feature of Liferay, as I would like to have an application that is external to Liferay (in our case, our sales proposal application) create portal users. I have tried everything I can find online and am still not able to get a valid request through. As a simple use case, I started by just trying to consume the getUserByEmailAddress service and I can't even get that work. The closest that I feel I have come is by querying http://localhost:8080/api/secure/axis/Portal_UserService, and getting

java.rmi.RemoteException: No User exists with the key {companyId=12098, emailAddress=ben2@greenportal.com}

for a user that does NOT exist, ie. this response is valid, and getting

java.rmi.RemoteException: PermissionChecker not initialized

for a user that actually exists. I get these same response whether I'm running the SOAP request through soapUI or my JUnit code.

I have modified my portal-ext.properties to have the appropriate (?) entries:

#for web service access
axis.servlets.hosts.allowed=127.0.0.1,SERVER_IP,localhost,XXX.XXX.XXX.XXX
axis.servlet.https.required=false

(The XXX.XXX... is my machine's actual IP address) And the relevant portion of my code:

UserAdmin.java

...
static UserServiceSoap proxy = null;

public UserAdmin() {
    try {
        proxy = PortalProxy.getProxy();
    } catch (MalformedURLException e) {
        logger.error("Malformed URL encountered when generating proxy in UserAdmin constructor");
        e.printStackTrace();
    } catch (ServiceException e) {
        logger.error("Service Exception encountered when generating proxy in UserAdmin constructor");
        e.printStackTrace();
    }
}

public UserSoap getUser(long companyId, String emailAddress) {
    UserSoap requestedUser = null;
    String possibleError = null;

    //if proxy hasn't been created yet, create it now.
    checkProxyConnection();
    try {
        requestedUser = proxy.getUserByEmailAddress(companyId, emailAddress);
        logger.debug("Found user for "+emailAddress);
    } catch (RemoteException e) {
        requestedUser = null;
        possibleError = e.getMessage();
    }
    if(requestedUser != null) {
        logger.info("Returning requested user: " + requestedUser.getEmailAddress());
    } else {
        logger.info("Requested user for email address \""+emailAddress+"\" not found. Returning null.");
        logger.info(possibleError);
    }
    return requestedUser;
}

...

PortalProxy.java

...
    public static UserServiceSoap getProxy()
        throws MalformedURLException, ServiceException {

    UserServiceSoapServiceLocator svc = new UserServiceSoapServiceLocator();
    UserServiceSoap userSoap = svc.getPortal_UserService(new URL("http://localhost:8080/api/axis/Portal_UserService"));

//      makes no difference if these are commented or uncommented       
//      ((Portal_UserServiceSoapBindingStub)userSoap).setUsername(Constants.LIFERAY_USERNAME);
//      ((Portal_UserServiceSoapBindingStub)userSoap).setPassword(Constants.LIFERAY_PASSWORD);

        return userSoap;
    }
...

All of the liferay forum posts that I find on this subject have not yielded anything useful, most of it applies to the Tomcat bundle. Is it possible this is a Glassfish specific problem? I have been struggling, off-and-on, with this issue for several weeks now and am completely out of ideas. If anyone has any advice, help, links, tutorials, etc for consuming Liferay services, I'd be very grateful.

Thanks

Was it helpful?

Solution 2

I fixed this by dropping and recreating the Liferay database.

Something must have gotten hosed in my 'lportal' database. I dropped the database and deleted my portal-setup-wizard.properties & portal-ext.properties files. After the server restarted and I completed the setup wizard, I retried my Junit test and IT WORKED! No code changes or anything, just a database wipe and recreate and everything works great now. So frustrating!

Obviously, this is not an ideal solution and it makes me very nervous about how Liferay is going to behave once we get to production.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top