0
回答
axis2写的一客户端访问代码,大家帮忙分析分析
利用AWS快速构建适用于生产的无服务器应用程序,免费试用12个月>>>   

import javax.xml.stream.FactoryConfigurationError;
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMFactory;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.client.ServiceClient;
import org.apache.log4j.Logger;

public class TestcGenServer {
	private static Logger log=Logger.getLogger(TestcGenServer.class);
	public static void main(String[] args) {
		System.out.println("\u6b63\u5728\u8c03\u7528\u670d\u52a1\u63a5\u53e3......");
		String uri = "http://127.0.0.1:8080/services/testRestsend.HTTPEndpoint";
		String serverName = "fiEMP";
		String key = "id";
		String num = "001";
		//创建一OMFactory 对象来创建OMElement对象
		OMFactory fac=OMAbstractFactory.getOMFactory();
		OMElement method=fac.createOMElement(serverName,OMAbstractFactory.getOMFactory().createOMNamespace("http://www.com", null));//  <axis2ns1:fiEMP xmlns:axis2ns1="http://www.tyky.com.cn" />
		OMElement value=fac.createOMElement(key,null);//  <id />
		value.addChild(fac.createOMText(value,num));
		method.addChild(value);
		
		Options options=new Options();
		EndpointReference epr=new EndpointReference(uri);//獲得代理服務
		options.setTo(epr);
		options.setAction("urn:"+serverName);//执行方法
		
		options.setTransportInProtocol(Constants.TRANSPORT_HTTP);//传输协议为HTTP
		options.setProperty(Constants.Configuration.ENABLE_REST, Constants.VALUE_TRUE);//方法为rest
		ServiceClient sender=null;
		try {
			sender=new ServiceClient();
			sender.setOptions(options);
				OMElement result= sender.sendReceive(method);
				 System.out.println("\u7ed3\u679c\u8f93\u51fa\uff1a\n"+result.toString());
				 log.info(result.toString());
			System.out.println("\u670d\u52a1\u6210\u529f\u8c03\u7528..........");
		}catch (AxisFault ex) {
			log.error(ex);
			ex.printStackTrace();
        } catch (FactoryConfigurationError err) {
        	log.error(err);
        	err.printStackTrace();
        }finally {
			if( sender !=null){
        		try {
        		 sender.cleanupTransport();
        		}catch (AxisFault e){
                   e.printStackTrace();
        		}
        	}
        }
	}

}
初学,大空帮忙看看看能否再写好点
举报
V
发帖于7年前 0回/2K+阅
顶部