WebService 非阻塞模式

package com.datastruct.sort;
import java.io.IOException;

import javax.xml.namespace.QName;
import org.apache.axis2.addressing.EndpointReference;

import org.apache.axis2.client.Options;

import org.apache.axis2.context.MessageContext;

import org.apache.axis2.rpc.client.RPCServiceClient;

import junit.framework.TestCase;

public class RPCAsyncClient extends TestCase {
	String url = "http://xxxxx:9080/CrmToRps/services/RPSService";
	String method = "RPSOrder";
	String requestXML = "<?xml version=\"1.0\" encoding=\"UTF-8\" ?><ContractRoot><TcpCont><BusCode>BUS21001</BusCode><ServiceCode>SVC21001</ServiceCode><ServiceContractVer>SVC2100120100603</ServiceContractVer><ActionCode>0</ActionCode><TransactionID>1111111245201006031000000014</TransactionID><ServiceLevel>1</ServiceLevel><SrcOrgID>222222</SrcOrgID><SrcSysID>333333</SrcSysID><SrcSysSign></SrcSysSign><DstOrgID>600204</DstOrgID><DstSysID></DstSysID><ReqTime>20100603095739</ReqTime><Request><ReqType></ReqType><ReqCode></ReqCode><ReqDesc></ReqDesc></Request></TcpCont><SvcCont><MDN>18901131234</MDN><CardType>00006</CardType><FromAreaNum></FromAreaNum><ToAreanum></ToAreanum><STAFF_ID>132456</STAFF_ID><STAFF_NAME></STAFF_NAME><CHANNEL_ID>aaaa</CHANNEL_ID><CHANNEL_NAME></CHANNEL_NAME></SvcCont></ContractRoot>";
	public void test() throws IOException{
		RPCServiceClient serviceClient = new RPCServiceClient();
        Options options = serviceClient.getOptions();
        EndpointReference targetEPR = new EndpointReference(url);
        options.setTo(targetEPR);
        Object[] opAddEntryArgs = new Object[]{requestXML};
        QName opAddEntry = new QName("http://service", method);
        serviceClient.invokeNonBlocking(opAddEntry, opAddEntryArgs,
                new org.apache.axis2.client.async.AxisCallback()
                {
                    public void onComplete()
                    {
                    	System.out.println("onComplete");
                    }
                    public void onError(Exception arg0)
                    {
                    	System.out.println("onError"+arg0.getMessage());
                    }
                    public void onFault(MessageContext arg0)
                    {
                    	 System.out.println("onFault");
                    }
                    public void onMessage(MessageContext mc)
                    {
                        //  输出返回值
                        System.out.println(mc.getEnvelope().getFirstElement()
                                .getFirstElement().getFirstElement().getText());
                    }
                });

        System.out.println("异步调用!");
        //  阻止程序退出
        System.in.read();
	}
}
 

你可能感兴趣的:(apache,xml,webservice,JUnit)