开发EJB容器模型的WEB服务

1.开发服务端

  1.1.Order.java  //是实体类

  1.2.OrderService.java  //服务接口

  1.3.OrderServiceBean.java  //服务接口的实现类

  1.4.build.xml //ant的部署文件

2.开发客户端

  2.1.OrderTest.java //juit测试类

  2.2.build.xml //Ant任务类生成webservice辅助类

  2.3需要jax2.1的jar文件支持,http://dldx.csdn.net/fd.php?i=987830727246899&s=55184deee4b4aa959bb33700d85ddc98

3.发布WebService.jar到jboss下

4.查看jboss中的webservice http://localhost:8080/jbossws/中View a list of deployed services 选项就可以看到自己的web service了

 

Order.java 

package cn.cmcc.bean;

 

import java.io.Serializable;

 

 

public class Order  implements Serializable{

 

/**

*/

private static final long serialVersionUID = -1037122931899348746L;

private String orderId;

private String name;

public Order(){}

 

public Order(String orderId, String name) {

super();

this.orderId = orderId;

this.name = name;

}

public String getOrderId() {

return orderId;

}

public void setOrderId(String orderId) {

this.orderId = orderId;

}

public String getName() {

return name;

}

public void setName(String name) {

this.name = name;

}

 

}

 

 

 

OrderService.java

package cn.cmcc.service;

 

import java.util.List;

 

import cn.cmcc.bean.Order;

 

 

public interface OrderService {

 

public Order getOrder(String orderId);

public List getOrders();

public String getName(String name);

}

 

 

 

OrderServiceBean.java

package cn.cmcc.service.impl;

 

import java.util.ArrayList;

import java.util.List;

 

import javax.ejb.Remote;

import javax.ejb.Stateless;

import javax.jws.WebService;

 

import cn.cmcc.bean.Order;

import cn.cmcc.service.OrderService;

 

@WebService(

name = "OrderService",  //接口名

serviceName = "OrderServiceBean", //接口实现名

targetNamespace = "http://www.cmcc.cn") //命名空间

@Stateless

@Remote

public class OrderServiceBean  implements OrderService{

 

@Override

public String getName(String name) {

 

return name;

}

 

@Override

public Order getOrder(String orderId) {

Order order =new Order();

order.setName("zhangsan");

order.setOrderId(orderId);

return order;

}

 

@Override

public List getOrders() {

List list=new ArrayList();

 

Order order =new Order();

order.setName("zhangsan");

order.setOrderId("1");

 

list.add(order);

order =new Order();

order.setName("lisi");

order.setOrderId("2");

 

list.add(order);

return list;

}

 

 

 

}

 

 

 

build.xml  //服务端的ant 的build文件

 

 

 

 

OrderTest.xml

package juit.test;

 

import org.junit.BeforeClass;

import org.junit.Test;

 

import cn.cmcc.ws.client.Order;

import cn.cmcc.ws.client.OrderService;

import cn.cmcc.ws.client.OrderServiceBean;

 

public class OrderTest {

 

private static OrderServiceBean serviceBean=new OrderServiceBean();

private static OrderService orderService;

@BeforeClass

public static void setUpBeforeClass() throws Exception {

orderService=serviceBean.getOrderServicePort();

 

}

@Test

public void getOrder(){

Order order= orderService.getOrder("1");

System.out.println(order.getName());

}

@Test

public void getOrders(){

for(Order order:orderService.getOrders()){

System.out.println(order.getOrderId()+"\t"+order.getName());

}

}

@Test

public void getName(){

System.out.println(orderService.getName("zhangsan"));

 

}

 

}

 

 

 

build.xml

   

   

       

           

       

   

 

   

   

   

    sourcedestdir="${src.dir}" package="cn.cmcc.ws.client" keep="true" 

    verbose="true" destdir="${basedir}/bin"/>

   

 

 

你可能感兴趣的:(开发EJB容器模型的WEB服务)