以 liferay 5.1.0 版本为例.
Liferay是基于SOA理念设计的,很容易通过Web Services对外提供服务接口,下面简单介绍一下。
Liferay如何对外提供服务?
1、在service.xml中编辑,增加一个<entity name="xx" local-service="false" remote-service="true" />
2、ant build-service-xxxx (portal-impl/build.xml)
3、修改XXServiceImpl, 写入你要对外提供的方法逻辑;
4、ant build-service-xxxx (重复2)
5、ant build-wsdd-xxxx in portal-impl/build.xml
6、ant clean deploy in portal-impl/build.xml
这样你就成功发布以了一个服务,在tunnel-web/doc-root/WEB-INF/server-config.wsdd 中查找是否发布成功
这里以 liferay 自带的 UserService 调用为例.
Liferay是基于SOA理念设计的,很容易通过Web Services对外提供服务接口,下面简单介绍一下。
Liferay如何对外提供服务?
1、在service.xml中编辑,增加一个<entity name="xx" local-service="false" remote-service="true" />
2、ant build-service-xxxx (portal-impl/build.xml)
3、修改XXServiceImpl, 写入你要对外提供的方法逻辑;
4、ant build-service-xxxx (重复2)
5、ant build-wsdd-xxxx in portal-impl/build.xml
6、ant clean deploy in portal-impl/build.xml
这样你就成功发布以了一个服务,在tunnel-web/doc-root/WEB-INF/server-config.wsdd 中查找是否发布成功
这里以 liferay 自带的 UserService 调用为例.
package com.yoolive.demo; import java.net.URL; import javax.xml.rpc.ServiceException; import com.liferay.client.portal.model.UserSoap; import com.liferay.client.portal.service.http.UserServiceSoap; import com.liferay.client.portal.service.http.UserServiceSoapServiceLocator; public class WebClient { private static String url; public static void main(String[] args) { UserServiceSoapServiceLocator locator = new UserServiceSoapServiceLocator(); try { // UserServiceSoap soap = locator // .getPortal_UserService(getURL("2", "Portal_UserService")); UserServiceSoap soap =locator.getPortal_UserService(); UserSoap[] users = soap.getGroupUsers(14); for (UserSoap user : users) { System.out.println(user.getEmailAddress()); } } catch (ServiceException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } private static URL getURL(String remoteUser, String serviceName) throws Exception { String password = "test"; url = "http://" + remoteUser + ":" + password + "@localhost:8080/tunnel-web/secure/axis/" + serviceName; return new URL(url); } }