Implement, deploy and call an EJB 3.0 webservice using Glassfish and JAX-WS

本文介绍了如何使用EJB3.0和JAX-WS标准开发并部署一个简单的WebService应用。作者首先在JDeveloper中创建了一个带有WebService方法的无状态会话Bean,并将其部署到Glassfish应用服务器上。接着,在NetBeans中开发了一个客户端来调用这个WebService。

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 them becomes really easy by using annotation and the supplied tools like wsimport. Sun has done a great job with this new standard XML webservice API!

内容概要:本研究聚焦于“绿电直连型电氢氨园区”的优化运行,提出一种直接利用绿色电力驱动制氢与合成氨的综合能源系统架构。通过构建包含风/光发电、电解水制氢、氢气储存、合成氨反应及电能直供等关键环节的系统模型,研究旨在实现能源的高效转化与梯级利用,降低对外部电网依赖,提升园区能源自洽率与经济性。研究综合运用Matlab与Python工具进行建模与仿真,结合实际气象与负荷数据,对系统在不同工况下的运行策略、能量流动、设备容量配置及经济技术指标进行深入分析与优化,并形成完整的Word论文文档,为新型零碳产业园区的规划与建设提供了理论依据和技术支撑。; 适合人群:具备新能源、电力系统、化工或综合能源系统背景的科研人员,以及从事园区规划、能源管理、低碳技术开发的工程技术人员。; 使用场景及目标:①研究绿电如何高效耦合至化工生产流程,实现“电--氨”多能互补;②掌握综合能源系统(IES)的建模、仿真与优化方法,特别是多时间尺度下的运行调度策略;③为撰写高水平学术论文或完成相关课题研究积累数据、代码与写作模板。; 阅读建议:此资源包含代码、数据和完整论文,建议使用者先通读Word论文以理解整体框架与理论基础,再结合Matlab/Python代码进行复现与调试,最后可基于提供的数据和模型进行二次开发,以深化对绿电综合利用技术的理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值