Implement, deploy and call an EJB 3.0 webservice using Glassfish and JAX-WS
来源:互联网 发布:centos 7安装kvm 编辑:程序博客网 时间:2024/05/29 04:04
Playing around with EJB3.0 for a while, I decided to try the special webservice annotations set of EJB3.0 for deploying an EJB as a webservice.Looking at the documentation, I discovered that that this feature is based on the new Java XML webservice API called JAX-WS (JSR-224), which is in real JAX-RPC 2.0. I decided to build a EJB3.0 with special webservice methods in JDeveloper and deploy it on the Glassfish application server. Next, I developed a client for the webservice in Netbeans 5.0 using JAX-WS. I could have used JDeveloper for building the client, but I used Netbeans 5.0 for just trying a different IDE then the one I’m daily using .
I chose JDeveloper 10.1.3 for developing the EJB3.0 webservice, because it has, as one of the few IDEs , build-in support for EJB3.0 development. The code below shows the stateless session bean with a single webservice method that returns a message.
@Stateless@WebService(serviceName = "MyFirstEJB3Service")public class WebserviceEJBBean implements WebserviceEJB { public WebserviceEJBBean() { } @WebMethod(operationName="HelloWorld") public String getHelloMessage(String s) { return "Hello " + s + "/n" +"This is my first EJB3.0 webservice developed in JDeveloper and deployed on the glassfish platform"; } }
After you have generated a jar file for your EJB module, you login into the administration console of your Glassfish installation and deploy the jar file as an EJB module in the console (Applications -> EJB modules). After successfully deployed the module, you can test your webservice in the console (Webservices -> WebserviceEJBBean )
Ok, now we have implemented and deployed an EJB3.0 webservice on the Glassfish application server. It’s now time to make a client that consumes the webservice. Start your Netbeans 5.0 installation and make a new basic application project. Now you have to download the JAX-WS API binaries to you local drive and add them a s a library to your project. Now we have to generate artifacts to make the actual webservice call. JAX-WS contains a tool, called wsimport, to generate artifacts from a given WSDL file. You can integrate this tool as an ANT-task in your build file by inserting the following code in your project build file:
<!-- Overrides -pre-compile target java artifacts that will created and compiled to build/classes directory. --> <target name="-pre-compile"> <mkdir dir="build/classes"/> <taskdef name="wsimport" classname="com.sun.tools.ws.ant.WsImport"> <classpath path="${javac.classpath}"/> </taskdef> <echo>running wsimport</echo> <wsimport debug="true" keep="true" destdir="build/classes" package="wsimport.generated.myfirstejbws" wsdl="http://localhost:8080/MyFirstEJB3Service/WebserviceEJBBean?WSDL"/> </target>
Finally, add the following code to the main method of the application’s main class and run the application to see the message returned by the webservice.
/** * @param args the command line arguments */ public static void main(String[] args) { System.out.println("Response from the webservice: "+"/n"+Main.testService()); } public static String testService(){ //Use the generared artifacts to make the webservice invocation. MyFirstEJB3Service service = new MyFirstEJB3Service(); WebserviceEJBBean proxy = service.getWebserviceEJBBeanPort(); return proxy.helloWorld("Tom Hofte"); }
I think with JAX-WS developing webservices and building clients for thembecomes really easy by using annotation and the supplied tools likewsimport. Sun has done a great job with this new standard XMLwebservice API!
- Implement, deploy and call an EJB 3.0 webservice using Glassfish and JAX-WS
- GlassFish上开发部署JAX-WS WebService应用( by quqi99 )
- Jax-ws server side and client side
- Brief Introduction for jax-ws,jax -rs and iax-rpc
- jax-ws webservice编程
- JAX-WS WebService
- JAX-WS实现WebService
- Jax WS发布webservice
- JAX-WS,WebService实例
- jax-ws webservice编程
- JAX-WS WebService发布
- WebService -- JAX-WS : 入门
- webService之JAX-WS
- jax-ws 处理webservice
- WebService(3):JAX-WS
- WebService JAX-WS 注释
- WebService:JAX-WS实现WebService
- An introduction to JAX-RS and JAXB
- 关于Nhibernate中的hql与sql的转换问题
- ASP常用函数
- 『心不難,事就不難!』
- 金庸人物歷史上真正的遭遇(zt)
- 思维的瞬间,偶尔在这停留
- Implement, deploy and call an EJB 3.0 webservice using Glassfish and JAX-WS
- 工作的尊严... (转)
- ASP.NET中如何操作注册表
- 修之道
- 自我介绍
- 如何获取两个算子之间的距离
- 男人守则一百条
- asp:EditCommandColumn的问题解决
- SQL Server 基础概念集