使用CXF中的Aegis开发WS使用

阅读更多

package com.easyway.cxf.service;

import java.util.List;

import com.easyway.cxf.model.User;
/**
 *
 * @author longgangbai
 *
 */
public interface HelloService {
 /**
  * The @WebParam annotation is necessary as java interfaces do not store the Parameter name in the .class file. So if you leave out the annotation your parameter will be named arg0.
  * @param name
  * @return
  */
  public String hello(String name);
 
  /**
   * Advanced usecase of passing an Interface in.  JAX-WS/JAXB does not
   * support interfaces directly.  Special XmlAdapter classes need to
   * be written to handle them
   */
  public String sayHi(User user);

  public String[] getAllUseNames(List userList);
}
package com.easyway.cxf.service;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.easyway.cxf.model.User;
/**
 * 采用Aegis CXF 的使用发布WS
 * @author longgangbai
 *
 */
public class HelloServiceImpl implements HelloService {

    Map users = new LinkedHashMap();
   

 public String hello(String username) {
        return "Hello " + username;
 }

 public String sayHi(User user) {
         users.put(users.size() + 1, user);
         return "Hello "  + user.getUsername();
 }
 public String[] getAllUseNames(List userList) {
  String[] userListArr=new String[userList.size()];
  for (int i=0;i   userListArr[i]=userList.get(i).getUsername();
  }
  return userListArr;
 }

}




   
       
           
       

   

 

 

package com.easyway.cxf.test.server;

import org.apache.cxf.aegis.databinding.AegisDatabinding;
import org.apache.cxf.frontend.ServerFactoryBean;

import com.easyway.cxf.service.HelloService;
import com.easyway.cxf.service.HelloServiceImpl;

public class AegisCXFServer {
 public static final String SERVICE_ADDRESS="http://localhost:8080/services/helloService";
      public static void main(String args[]) throws Exception {
       HelloService helloworldImpl = new HelloServiceImpl();
          ServerFactoryBean svrFactory = new ServerFactoryBean();
          svrFactory.setServiceClass(HelloService.class);
          svrFactory.setAddress(SERVICE_ADDRESS);
          svrFactory.setServiceBean(helloworldImpl);
          svrFactory.getServiceFactory().setDataBinding(new AegisDatabinding());
          svrFactory.create();
          System.out.println("Server ready...");
 
          Thread.sleep(5 * 60 * 1000);
          System.out.println("Server exiting");
          System.exit(0);
      }
 }
package com.easyway.cxf.test.client;


import org.apache.cxf.aegis.databinding.AegisDatabinding;
import org.apache.cxf.frontend.ClientProxyFactoryBean;

import com.easyway.cxf.service.HelloService;
import com.easyway.cxf.test.server.AegisCXFServer;

 

public final class AegisCXFClient {

    private AegisCXFClient() {
    }

    public static void main(String args[]) throws Exception {
        ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
        factory.setServiceClass(HelloService.class);
        if (args != null && args.length > 0 && !"".equals(args[0])) {
            factory.setAddress(args[0]);
        } else {
            factory.setAddress(AegisCXFServer.SERVICE_ADDRESS);
        }
        factory.getServiceFactory().setDataBinding(new AegisDatabinding());
        HelloService client = (HelloService)factory.create();
        System.out.println("Invoke hello()....");
        System.out.println(client.hello(System.getProperty("user.name")));
        System.exit(0);
    }

}

  • AegisCxf.part1.rar (5.2 MB)
  • 下载次数: 35
  • AegisCxf.part2.rar (5.2 MB)
  • 下载次数: 29
  • AegisCxf.part3.rar (5.2 MB)
  • 下载次数: 28
  • AegisCxf.part4.rar (5.2 MB)
  • 下载次数: 24
  • AegisCxf.part5.rar (1.9 MB)
  • 下载次数: 31

你可能感兴趣的:(Apache,UseCase,XML,thread)