标签(空格分隔): 完成第1单元的三个课程后,您可以使用Travelport Universal API来提出服务请求并了解响应。
命令行:
wsdl2Java -client -d /Users/johndoe/tport-workspace/uapiJava/.cxftmp/src -classdir /Users/johndoe/tport-workspace/uapiJava/build/classes -p http://www.travelport.com/service/system_v8_0=com.travelport.service.system_v8_0 -impl -validate -exsh true -dns true -dex true -autoNameResolution -xjc-Xts,-Xts:style:multiline,-Xlocator,-mark-generated -wsdlLocation http://localhost:8080/kestrel/ExternalCacheAccessService?wsdl -verbose -fe jaxws -db jaxb -wv 1.1 file:/Users/johndoe/tport-workspace/uapiJava/wsdl/system_v8_0/System.wsdl4、 系统客户端:使用WDT查看器查看文件(应该是WSDL生成Java代码的结构)
SystemService.png(1) 看的出来,此WSDL有两个Service暴露,分别是ExternalCacheAccessService and SystemService在你的src文件下你可以看到生成的service,com.travelport.service.system_v8_0.SystemService(关于此服务的所有实现细节可以safely ignore)(2) 在SystemService上有三个端口被暴露,SystemInfoPortType,SystemPingPortType, SystemTimePortType.
a) Air service in src/wsdl/air_v26_0/Air.wsdl,b) Hotel service in src/wsdl/hotel_v26_0/Hotel.wsdlc) Vehicle service in src/wsdl/vehicle_v26_0/Vehicle.wsdld) Universal service in src/wsdl/universal_v26_0/UniversalRecord.wsdl
代码解析:上面的代码基本上遵循我们上面所有的变成模型,一个PingReq使用参数设置对象,然后通过ping端口传递给TravelPort Universal API.调用WSDLService.sysPing.get()返回ping端口对象,get此对象上的方法缓存服务和端口,因此进一步调用以返回同意服务上的相同端口。如果有报错:Exception in thread "main" Java.lang.RuntimeException: One or more of your properties has not been set properly for you to access the travelport uAPI. Check your command line arguments or Eclipse run configuration for these properties:travelport.username,travelport.password,travelport.gds,travelport.targetBranch,则需要配置如果一切都预期正常工作,则会看到这样的输出:this my payload; there are many like it but this one is minedoesntmatter-8176E07E825F0A07580E004DED8EB9130465
目标:使用TravelPort Universal API搜索可用航班和价格(how to search for available flights and price itineraries using Travelport Universal API.)
在第一课基础上,第二课的目标是为客户预定旅行。代理需要执行两项基本任务:a) 查找一组可用航班,以便将旅客从出发地到目的地(如果适用的话也可以返回)b) 根据航班设置,确定该行程的当前价格准备:可用性搜索端口和价格端口( the Availability Search port and the Price port)这两个接口都可以从Air Service对象访问。
a) Air service in src/wsdl/air_v26_0/Air.wsdlb) Hotel service in src/wsdl/hotel_v26_0/Hotel.wsdlc) System service in src/wsdl/system_v8_0/System.wsdld) Vehicle service in src/wsdl/vehicle_v26_0/Vehicle.wsdle) Universal service in src/wsdl/universal_v26_0/UniversalRecord.wsdl生成代码后,很多的包你的项目里,生成的AirService Object's的实现也是包中的一部分(com.travelport.service.air_v26_0)官方提供的API无法访问此gitHub地址(https://github.com/travelport/travelport-uapi-tutorial/blob/master/src/com/travelport/service/air_v26_0/)
解读:行程有虚线分割,第一个行程的价格为941.70英镑,包括6月22日两架法航(AF)和6月29日返回巴黎的两架三角洲(DL)航班。第二个形成价格3594.70英镑,三家航空-美国联合航空(UA),美国航空(US)和达美航空公司(DL)注意:第二课代码运行时,会生成许多这些行程,以及它们的价格当程序启动时等待从Travelport GDS返回的建议的可用行程时会暂停。在显示每个行程时,在特定行程定价时也会暂停
1、构建可用性搜索的必要参数,例如事发地和目的地城市以及旅行日期(Construct the necessary parameters for an availability search, such as the origin and destination city as well as the travel dates)2、 发送可用性搜索请求(Send the availability search request)3、 将搜索结果解码为适当的行程(Decode the results of the search into proper itineraries)4、 循环每个行程,请求此行程的价格,显示结果价格。显示旅程的各个部分(Looping over each itinerary,Request the price of this itineraryDisplay the resulting priceDisplay the segments of the journey)(第一步第三步需要特别小心)
a)、准备搜索
//make the request... paris to chattanooga TN USA String from ="CDG",to="CHA"; //staying a week ... two months from now.. roundtrip AvailabilitySearchRsp rsp = search(from, to, Helper.daysInFuture(60), Helper.daysInFuture(67));Helper方法中的Helper.daysInFuture()两次调用含义。。使用Travelport Universal API的航空旅行搜索不仅需要始发地和目的地,还需要其他详细信息,例如乘客类型。成人是默认的乘客类型,但有超过100种类型的乘客,如军人退伍军人,神职人员。
//R/T journey SearchAirLeg outbound = AirReq.createSearchLeg(origin, dest); AirReq.addSearchDepartureDate(outbound, dateOut); AirReq.addSearchEconomyPreferred(outbound); //coming back SearchAirLeg ret = AirReq.createSearchLeg(dest, origin); AirReq.addSearchDepartureDate(ret, dateBack); //put traveller in econ AirReq.addSearchEconomyPreferred(ret);两个示例:一个是从原点到目的地,一个在一周后返回。
将响应(rsp)中的map allSegments和allDetails构建到我们的可用性搜索请求
2)Air Solutions
//Each "solution" is for a particular part of the journey... on //a round trip there will be two of thes List<AirItinerarySolution> solutions = rsp.getAirItinerarySolution(); AirItinerarySolution outboundSolution = solutions.get(0); AirItinerarySolution inboundSolution = solutions.get(1);针对已搜索的旅程的每个段返回一个AirItinerarySolution,我们的搜索是从CDG(巴黎)到CHA(查塔努加)的第一个segemnt和反向的返回
3)建立路线一个路由是一组航班,以某种顺序,即从起点到终点获得的旅客
//bound the routings by using the connections List<AirItinerary> out = buildRoutings(outboundSolution, 0, allSegments, allDetails); List<AirItinerary> in = buildRoutings(inboundSolution, 1, allSegments, allDetails); //merge in and out itins so we can get pricing for whole deal List<AirItinerary> allItins = mergeOutboundAndInbound(out, in);目标:将了解如何使用Travelport Universal API的购物设施来查找两个城市之间的最低成本运输,包括使用铁路和低成本航空公司作为旅行方式,您还将了解如何异步从低成本购物API获取数据
低票价搜索端口(AirService对象上的另一个端口)允许您通过搜索并将搜索结果返回已经定价来组合这两个步骤(可用性,定价)。此外,低票价搜索可以将返回的行程集缩小到最便宜的行程,因为搜索最低价格是常见情况。
1)Air:Travelport的GDS提供商,Galileo(1G),Apollo(1V)和Worldspan(1P)。这些功能为您提供在线购物和预订航空旅行时所期望的功能。
Raile:基于轨道的旅行的功能以与航空旅行所证明的相同的一般方式访问,但是从Rail.wsdl中定义的RailService开始(在本教程提供的文件中的目录wsdl / rail_v26_0中)Low Cost Carriers:GDSes(如Galileo,Apollo和Worldspan)通常不会将这些航空公司的票价或可用性分配给他们的网络。这些航空公司通常只在自己的网站上通过互联网销售。为了完整起见,我们在此提及此类提供程序。本教程主要关注GDS和铁路提供商a) 通过低成本搜索异步端口的service()方法发送LowCostSearchAsyncReq(Send LowCostSearchAsyncReq via the low cost search async port’s service() method)b) 使用LowCostSearchAsyncRsp响应对象来确定哪些提供者拥有哪些数据(Consume LowCostSearchAsyncRsp response object to determine what providers have what data)c) 遍历所有具有结果的提供者发送RetrieveLowFareSearchReq以从特定提供程序检索上述搜索的结果使用RetrieveLowFareSearchRsp对象来获取结果(Loop over all the providers that have resultsSend a RetrieveLowFareSearchReq to retrieve results from the above search, from a specific providerConsume the RetrieveLowFareSearchRsp object to get results)
异步方法中使用两种基本Java类型来处理响应:LowFareSearchAsyncRsp和RetrieveLowFareSearchRsp。这些是asynchronous search and get-me-more-data ports端口分别返回的响应类型。
这两个构造器是这一类的air和rail版本,构造完成后,可以简单地在PrintableItinerary对象上调用toString()并打印出可理解的内容。构造函数的air版本要求调用者提供roundTripTurnaround作为一个airport code,这是因为航空定价解决方案没有RailJourney中存在的方向概念,因此PrintableItinerary中的代码必须确定行程的哪些部分(AirSegments)是出境的以及哪些是入境的
Attention:根据您的测试凭据,铁路,车辆和低成本运营商可能无法使用。如果您看到错误消息,例如未配置提供程序或类似,则是因为您使用的是测试凭据,并且需要升级到生产凭据才能访问提供程序。
转载于:https://www.cnblogs.com/javallh/p/9297864.html
