网站首页 新闻首页 网页设计图形动画软件编程网站开发办公软件操作系统数据库网络技术认证考试范文资料黑客攻防 书籍教程 进入论坛

Liferay研究之十五:Liferay如何对外提供Service,以及如何调用

http://www.diybl.com/ 2008-1-4  网络 点击:  [ 评论 ]
文章搜索:    【点击打包该文章】

 

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发布的服务?smilingleo原创

1、新建一个项目(或者打开你要调用服务的项目)
2、将Apache AXIS的所有lib文件拷贝到<your-webapp>/WEB-INF/lib下面;
3、将portal-client.jar拷贝到上述目录,如果没有,在portal-client/build.xml中ant build-client(注意,这时,服务器要在开启状态,而且上面编写的服务已经成功deploy到服务器)
4、编写代码,例如;



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);
 }

}




文章整理:DIY部落 http://www.diybl.com (本站)   【点击打包该文章】
如果图片或页面不能正常显示请点击这里 站内搜索:   

文章评论

请您留言

 

最新新闻