xfire客户端对返回list很挑剔,所以需要使用泛型。
生活随笔
收集整理的這篇文章主要介紹了
xfire客户端对返回list很挑剔,所以需要使用泛型。
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
cas+ldap異常分析 | xfire+webservice(服務器配置篇) 2008-12-31 package?com.seavision.huayi2.service; ?? ?? import?java.net.MalformedURLException; ?? import?java.util.Collection; ?? import?java.util.HashMap; ?? import?java.util.List; ?? ?? import?javax.xml.bind.JAXBElement; ?? import?javax.xml.namespace.QName; ?? import?org.codehaus.xfire.XFireRuntimeException; ?? import?org.codehaus.xfire.aegis.AegisBindingProvider; ?? import?org.codehaus.xfire.annotations.AnnotationServiceFactory; ?? import?org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations; ?? import?org.codehaus.xfire.client.XFireProxyFactory; ?? import?org.codehaus.xfire.jaxb2.JaxbTypeRegistry; ?? import?org.codehaus.xfire.service.Endpoint; ?? import?org.codehaus.xfire.service.Service; ?? import?org.codehaus.xfire.soap.AbstractSoapBinding; ?? import?org.codehaus.xfire.transport.TransportManager; ?? ?? import?com.seavision.huayi2.domain.ArrayOfTBusinsessLog; ?? import?com.seavision.huayi2.domain.TBusinsessLog; ?? import?com.seavision.huayi2.domain.TStationMonthReport; ?? ?? public?class?IWebserviceClient?{ ?? ?? ????private?static?XFireProxyFactory?proxyFactory?=?new?XFireProxyFactory(); ?? ????private?HashMap?endpoints?=?new?HashMap(); ?? ????private?Service?service0; ?? ?? ????public?IWebserviceClient()?{ ?? ????????create0(); ?? ????????Endpoint?IWebservicePortTypeLocalEndpointEP?=?service0?.addEndpoint(new?QName("http://service.huayi2.seavision.com",?"IWebservicePortTypeLocalEndpoint"),?new?QName("http://service.huayi2.seavision.com",?"IWebservicePortTypeLocalBinding"),?"xfire.local://IWebservice"); ?? ????????endpoints.put(new?QName("http://service.huayi2.seavision.com",?"IWebservicePortTypeLocalEndpoint"),?IWebservicePortTypeLocalEndpointEP); ?? ????????Endpoint?IWebserviceHttpPortEP?=?service0?.addEndpoint(new?QName("http://service.huayi2.seavision.com",?"IWebserviceHttpPort"),?new?QName("http://service.huayi2.seavision.com",?"IWebserviceHttpBinding"),?"http://localhost:8080/seavision/services/IWebservice"); ?? ????????endpoints.put(new?QName("http://service.huayi2.seavision.com",?"IWebserviceHttpPort"),?IWebserviceHttpPortEP); ?? ????} ?? ?? ????public?Object?getEndpoint(Endpoint?endpoint)?{ ?? ????????try?{ ?? ????????????return?proxyFactory.create((endpoint).getBinding(),?(endpoint).getUrl()); ?? ????????}?catch?(MalformedURLException?e)?{ ?? ????????????throw?new?XFireRuntimeException("Invalid?URL",?e); ?? ????????} ?? ????} ?? ?? ????public?Object?getEndpoint(QName?name)?{ ?? ????????Endpoint?endpoint?=?((Endpoint)?endpoints.get((name))); ?? ????????if?((endpoint)?==?null)?{ ?? ????????????throw?new?IllegalStateException("No?such?endpoint!"); ?? ????????} ?? ????????return?getEndpoint((endpoint)); ?? ????} ?? ?? ????public?Collection?getEndpoints()?{ ?? ????????return?endpoints.values(); ?? ????} ?? ?? ????private?void?create0()?{ ?? ????????TransportManager?tm?=?(org.codehaus.xfire.XFireFactory.newInstance().getXFire().getTransportManager()); ?? ????????HashMap?props?=?new?HashMap(); ?? ????????props.put("annotations.allow.interface",?true); ?? ????????AnnotationServiceFactory?asf?=?new?AnnotationServiceFactory(new?Jsr181WebAnnotations(),?tm,?new?AegisBindingProvider(new?JaxbTypeRegistry())); ?? ????????asf.setBindingCreationEnabled(false); ?? ????????service0?=?asf.create((com.seavision.huayi2.service.IWebservicePortType.class),?props); ?? ????????{ ?? ????????????AbstractSoapBinding?soapBinding?=?asf.createSoap11Binding(service0,?new?QName("http://service.huayi2.seavision.com",?"IWebservicePortTypeLocalBinding"),?"urn:xfire:transport:local"); ?? ????????} ?? ????????{ ?? ????????????AbstractSoapBinding?soapBinding?=?asf.createSoap11Binding(service0,?new?QName("http://service.huayi2.seavision.com",?"IWebserviceHttpBinding"),?"http://schemas.xmlsoap.org/soap/http"); ?? ????????} ?? ????} ?? ?? ????public?IWebservicePortType?getIWebservicePortTypeLocalEndpoint()?{ ?? ????????return?((IWebservicePortType)(this).getEndpoint(new?QName("http://service.huayi2.seavision.com",?"IWebservicePortTypeLocalEndpoint"))); ?? ????} ?? ?? ????public?IWebservicePortType?getIWebservicePortTypeLocalEndpoint(String?url)?{ ?? ????????IWebservicePortType?var?=?getIWebservicePortTypeLocalEndpoint(); ?? ????????org.codehaus.xfire.client.Client.getInstance(var).setUrl(url); ?? ????????return?var; ?? ????} ?? ?? ????public?IWebservicePortType?getIWebserviceHttpPort()?{ ?? ????????return?((IWebservicePortType)(this).getEndpoint(new?QName("http://service.huayi2.seavision.com",?"IWebserviceHttpPort"))); ?? ????} ?? ?? ????public?IWebservicePortType?getIWebserviceHttpPort(String?url)?{ ?? ????????IWebservicePortType?var?=?getIWebserviceHttpPort(); ?? ????????org.codehaus.xfire.client.Client.getInstance(var).setUrl(url); ?? ????????return?var; ?? ????} ?? ?? ????public?static?void?main(String[]?args)?{ ?? ???????? ?? ?? ????????IWebserviceClient?client?=?new?IWebserviceClient(); ?? ???????? ?? ????????//create?a?default?service?endpoint ?? ????????IWebservicePortType?service?=?client.getIWebserviceHttpPort(); ?? ??????? ?? ????????/** ? ?????????*?使用ObjectFactory插入 ? ?????????*?*/???? ?? ????????????com.seavision.huayi2.domain.ObjectFactory?cfactory=new?com.seavision.huayi2.domain.ObjectFactory(); ?? ????????????com.seavision.huayi2.domain.TStationMonthReport??newTStationMonthReport?=?cfactory.createTStationMonthReport(); ?? ????????????newTStationMonthReport.setStationMonthReportId(cfactory.createTStationMonthReportStationMonthReportId("123465464864")); ?? //???????????? ?? ????/** ? ?????*?使用JAXBElement插入 ? ?????*?*/?? ???????????? ?? //????????????JAXBElement<String>?id?=?new?JAXBElement<String>(new ?? //????????????????????QName("http://domain.huayi2.seavision.com",?"stationMonthReportId"),String.class,"gefa"); ?? //????????????newTStationMonthReport.setStationMonthReportId(id); ?? ???????????? ?? ????????????service.insertYueJiHua(newTStationMonthReport); ?? ????????/** ? ?????????*?測試返回list結果 ? ?????????*?*/?? ????????ArrayOfTBusinsessLog?aot?=?service.getYeWuList(); ?? ????????List?list?=?aot.getTBusinsessLog(); ?? ????????System.out.println(list.size()); ?? ????????for(int?i=0;i<list.size();i++){ ?? ????????????TBusinsessLog?tlog?=?(TBusinsessLog)?list.get(i); ?? ????????????System.out.println(i+"++++++"+tlog.getLogContent().getValue()); ?? ????????} ?? ????????//TODO:?Add?custom?client?code?here ?? ????????????????// ?? ????????????????//service.yourServiceOperationHere(); ?? ???????? ?? ????????System.out.println("test?client?completed"); ?? ????????????????System.exit(0); ?? ????} ?? ?? }?? package com.seavision.huayi2.service;import java.net.MalformedURLException;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;import javax.xml.bind.JAXBElement;
import javax.xml.namespace.QName;
import org.codehaus.xfire.XFireRuntimeException;
import org.codehaus.xfire.aegis.AegisBindingProvider;
import org.codehaus.xfire.annotations.AnnotationServiceFactory;
import org.codehaus.xfire.annotations.jsr181.Jsr181WebAnnotations;
import org.codehaus.xfire.client.XFireProxyFactory;
import org.codehaus.xfire.jaxb2.JaxbTypeRegistry;
import org.codehaus.xfire.service.Endpoint;
import org.codehaus.xfire.service.Service;
import org.codehaus.xfire.soap.AbstractSoapBinding;
import org.codehaus.xfire.transport.TransportManager;import com.seavision.huayi2.domain.ArrayOfTBusinsessLog;
import com.seavision.huayi2.domain.TBusinsessLog;
import com.seavision.huayi2.domain.TStationMonthReport;public class IWebserviceClient {private static XFireProxyFactory proxyFactory = new XFireProxyFactory();private HashMap endpoints = new HashMap();private Service service0;public IWebserviceClient() {create0();Endpoint IWebservicePortTypeLocalEndpointEP = service0 .addEndpoint(new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalEndpoint"), new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalBinding"), "xfire.local://IWebservice");endpoints.put(new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalEndpoint"), IWebservicePortTypeLocalEndpointEP);Endpoint IWebserviceHttpPortEP = service0 .addEndpoint(new QName("http://service.huayi2.seavision.com", "IWebserviceHttpPort"), new QName("http://service.huayi2.seavision.com", "IWebserviceHttpBinding"), "http://localhost:8080/seavision/services/IWebservice");endpoints.put(new QName("http://service.huayi2.seavision.com", "IWebserviceHttpPort"), IWebserviceHttpPortEP);}public Object getEndpoint(Endpoint endpoint) {try {return proxyFactory.create((endpoint).getBinding(), (endpoint).getUrl());} catch (MalformedURLException e) {throw new XFireRuntimeException("Invalid URL", e);}}public Object getEndpoint(QName name) {Endpoint endpoint = ((Endpoint) endpoints.get((name)));if ((endpoint) == null) {throw new IllegalStateException("No such endpoint!");}return getEndpoint((endpoint));}public Collection getEndpoints() {return endpoints.values();}private void create0() {TransportManager tm = (org.codehaus.xfire.XFireFactory.newInstance().getXFire().getTransportManager());HashMap props = new HashMap();props.put("annotations.allow.interface", true);AnnotationServiceFactory asf = new AnnotationServiceFactory(new Jsr181WebAnnotations(), tm, new AegisBindingProvider(new JaxbTypeRegistry()));asf.setBindingCreationEnabled(false);service0 = asf.create((com.seavision.huayi2.service.IWebservicePortType.class), props);{AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalBinding"), "urn:xfire:transport:local");}{AbstractSoapBinding soapBinding = asf.createSoap11Binding(service0, new QName("http://service.huayi2.seavision.com", "IWebserviceHttpBinding"), "http://schemas.xmlsoap.org/soap/http");}}public IWebservicePortType getIWebservicePortTypeLocalEndpoint() {return ((IWebservicePortType)(this).getEndpoint(new QName("http://service.huayi2.seavision.com", "IWebservicePortTypeLocalEndpoint")));}public IWebservicePortType getIWebservicePortTypeLocalEndpoint(String url) {IWebservicePortType var = getIWebservicePortTypeLocalEndpoint();org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);return var;}public IWebservicePortType getIWebserviceHttpPort() {return ((IWebservicePortType)(this).getEndpoint(new QName("http://service.huayi2.seavision.com", "IWebserviceHttpPort")));}public IWebservicePortType getIWebserviceHttpPort(String url) {IWebservicePortType var = getIWebserviceHttpPort();org.codehaus.xfire.client.Client.getInstance(var).setUrl(url);return var;}public static void main(String[] args) {IWebserviceClient client = new IWebserviceClient();//create a default service endpointIWebservicePortType service = client.getIWebserviceHttpPort();/*** 使用ObjectFactory插入* */ com.seavision.huayi2.domain.ObjectFactory cfactory=new com.seavision.huayi2.domain.ObjectFactory();com.seavision.huayi2.domain.TStationMonthReport newTStationMonthReport = cfactory.createTStationMonthReport();newTStationMonthReport.setStationMonthReportId(cfactory.createTStationMonthReportStationMonthReportId("123465464864"));
// /*** 使用JAXBElement插入* */// JAXBElement<String> id = new JAXBElement<String>(new
// QName("http://domain.huayi2.seavision.com", "stationMonthReportId"),String.class,"gefa");
// newTStationMonthReport.setStationMonthReportId(id);service.insertYueJiHua(newTStationMonthReport);/*** 測試返回list結果* */ArrayOfTBusinsessLog aot = service.getYeWuList();List list = aot.getTBusinsessLog();System.out.println(list.size());for(int i=0;i<list.size();i++){TBusinsessLog tlog = (TBusinsessLog) list.get(i);System.out.println(i+"++++++"+tlog.getLogContent().getValue());}//TODO: Add custom client code here////service.yourServiceOperationHere();System.out.println("test client completed");System.exit(0);}}
xfire+webservice(客戶端調用篇)
???? 服務接口,就是用來調用的,所以客戶端顯得尤為重要,xfire客戶端對返回list很挑剔,所以需要使用泛型。
???? 如何建立webservice client
???? 步驟1,建立webservice? project
???
??? 下一步
???
??? 下一步,默認
???
??? 選擇xfire包
???
??? finish,? 這樣,webservice項目就完成了
??? 接下來是如何進行客戶端開發(fā).
??? 在項目中右鍵,new webservice client
???
??? 接著,選擇你服務文件,wsdl
???
?? 完成。
?? 這樣在你的項目中,會根據wsdl服務文件,生成客戶端所需要的內容。
???自動生成文件,下去就細細體會,給出一個測試代碼
??
Java代碼???注意以下內容,1:返回list內容,先存放入Arrayof**對象當中,再進行l(wèi)ist遍歷。
???????????????????????? 2: 對象屬性取值,getValue();
?????????????????????????3:對象屬性封裝,通過JAXBElement進行封裝后,放入對象。
- 大小: 41.4 KB
- 大小: 46.1 KB
- 大小: 44.1 KB
- 大小: 47 KB
- 大小: 36.7 KB
- 大小: 48.6 KB
- 查看圖片附件
- 16:25
- 瀏覽 (168)
- 論壇瀏覽 (373)
- 評論 (1)
- 收藏
- 相關推薦
轉載于:https://www.cnblogs.com/cy163/archive/2009/03/21/1418153.html
總結
以上是生活随笔為你收集整理的xfire客户端对返回list很挑剔,所以需要使用泛型。的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 自动添加注释
- 下一篇: 双稳态电路的两个稳定状态是什么_电子电路