`

CXF 提供的Service Transport-Local transport

 
阅读更多

Local transport指RoutingMessage是在一个JVM中,Server端和Client必须在单独的一个JVM中运行。消息在

个端点之间被序列化传输。

 

下面以一个例子来说明,完整代码参考http://springsfeng.iteye.com/blog/1634753附件。

 

在单独的一个JVM中运行意味者在单个JVM中只有一个main()方法在运行。

 

Server端:

import javax.xml.ws.Endpoint;

import org.pbdp.sample.local.OrderProcessImpl;

public class Server {

    public Server() throws Exception {
        OrderProcessImpl orderProcessImpl = new OrderProcessImpl();
		Endpoint.publish("local://OrderProcess", orderProcessImpl);
    }

    public static void main(String args[]) throws Exception {
        new Server();
        System.out.println("Server ready...");
    } 

Cleint端:

import org.pbdp.sample.local.Order;
import org.pbdp.sample.local.OrderProcess;
import org.pbdp.sample.local.server.Server;
import org.springframework.context.support.ClassPathXmlApplicationContext;


public final class Client {

    public Client() {
    }

    public static void main(String args[]) throws Exception {
    	
		Server.main(new String[]{"inProcess"});
        ClassPathXmlApplicationContext context 
            = new ClassPathXmlApplicationContext(new String[] {"org/pbdp/sample/local/client/client-bean.xml"});

        OrderProcess client = (OrderProcess) context.getBean("orderClient");
		Order order = new Order();
		order.setCustomerID("C001");
		order.setItemID("I001");
		order.setQty(100);
		order.setPrice(200.00);

        String orderID = client.processOrder(order);
        String message = (orderID == null) ? "Order not approved" : "Order approved; order ID is " + orderID;
		System.out.println(message);
        System.exit(0);
    }
}

Client配置:

<?xml version="1.0" encoding="UTF-8"?>  
<beans xmlns="http://www.springframework.org/schema/beans"  
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   
    xmlns:jaxws="http://cxf.apache.org/jaxws"  
    xsi:schemaLocation="http://www.springframework.org/schema/beans   
                    http://www.springframework.org/schema/beans/spring-beans.xsd  
                    http://cxf.apache.org/jaxws   
                    http://cxf.apache.org/schemas/jaxws.xsd">  
      
    <jaxws:client id="orderClient" serviceClass="org.pbdp.sample.local.OrderProcess"  address="local://OrderProcess"/>  
</beans>
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics