使用J2EE Application Server发布WebService来测试EJB
来源:互联网 发布:线切割自动编程软件 编辑:程序博客网 时间:2024/06/06 16:21
作为简单测试EJB的方法,WebService绝对是J2EE的首选,J2EE的标准已经把很多WebService的发布和测试工作简化了,这就使得所有工作看起来变得非常简单。
1. 首先定义自己的接口并实现之
@Remote
public interface StringEncryptionService {
/**
* @param plainText
* @return
*/
String encrypt(String plainText);
/**
* @param cipherText
* @return
*/
String decrypt(String cipherText);
}
这里就简单定义个接口,实现也很简单,就不写了
2. 实现WebService 对其进行测试,
@Stateless
@WebService
public class StringEncryptionWebservice {
@EJB
StringEncryptionService stringEncryptionService;
/**
* {@inheritDoc}
*/
@WebMethod
@WebResult(name = "cipherText")
public String encrypt(@WebParam(name = "plainText") String plainText) {
return stringEncryptionService.encrypt(plainText);
}
/**
* {@inheritDoc}
*/
@WebMethod
@WebResult(name = "plainText")
public String decrypt(@WebParam(name = "cipherText") String cipherText) {
return stringEncryptionService.decrypt(cipherText);
}
}
@EJB 注入自己的实现类,然后使用@WebService注解把这个类变成WebService,
@WebMethod就是WebService所暴露的方法,
@WebResult 和 @WebParam是用来改变参数的名字,使用起来只是把默认的名字分别用
“cipherText”和“plainText”替换就可以了。
3. 在Eclipse里测试WebService
暴露好WebService的EJB一经发布就可以测试,使用JAVA EE工程发布EJB,
可以得到相应的WSDL,比如http://wswincnhz0755:9080/StringEncryptionWebserviceService/StringEncryptionWebservice?wsdl
在Eclipse 里建立Webservice Client,之后就可以方便的使用它了
StringEncryptionWebserviceProxy sewp = new StringEncryptionWebserviceProxy();
System.out.println(sewp.encrypt("123"));
System.out.println(sewp.decrypt("VlXPkr9TSZ9tJVzFwWYs7AIsSOTBnkm9pECY96kqTHY/PfZR8eGx+mibRrq1Fh6MF/jaLA=="));
注意:直接在浏览器中测试时,url后面必须加上?wsdl,客户端无需- 使用J2EE Application Server发布WebService来测试EJB
- Ejb发布成webservice
- EJB发布成WebService总结
- CXF发布WebService使用SoapUI测试
- 使用VS2010创建WebService 发布、测试
- 使用VS2010创建WebService 发布、测试
- 使用vs2010创建WebService发布测试
- 使用JBoss和PostgreSQL-----快速开发EJB和J2EE Web Application
- 带你走进EJB--将EJB发布为Webservice(1)
- 带你走进EJB--将EJB发布为Webservice(2)
- 带你走进EJB--将EJB发布为Webservice(3)
- 带你走进EJB--将EJB发布为Webservice(4)
- 使用jaxws:server 还是使用jaxws:endpoint发布webservice
- 在Websphere Application Server 6.1.0.15下发布cxf2.1的WebService
- 使用 Rational Development 工具和 WebSphere Application Server V8.5 开发基于 EJB 的 OSGi 应用
- 使用Application Center Test (ACT)来做压力测试
- 使用Application Center Test (ACT)来做压力测试
- 使用Application Center Test (ACT)来做压力测试
- ios XIB里的AutoLayout
- android paint 一些效果
- 每秒处理10万订单的支付架构 乐视集团
- 一次XSS攻击过程
- matlab 中 将一组数据归一化到(0,1)之间
- 使用J2EE Application Server发布WebService来测试EJB
- HTML:编写干净的且富有语义的html代码
- Sorry, jqv.attach() only applies to a form
- Android底层字符传递给上层应用举例
- htonl htons
- oracle 00600 [46][1]错误
- 全排列--递归法
- Android NDK开发环境的搭建
- 扩展的sql追踪