Travelport Universal API Ping通用教程

Unit1 Lesson 1:

标签(空格分隔): 完成第1单元的三个课程后,您可以使用Travelport Universal API来提出服务请求并了解响应。


  • 1、 下载和安装cxf

  • 2、 需要从Travelport的UniversalAPI提供的wsdl和xsd文件生成Java代码

  • 3、 首先要生成的是系统服务的Java代码(System.wsdl)

命令行:

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.wsdl

  • 4、 系统客户端:使用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.


  • 5、 这个lesson中使用了许多服务,需要准备所必须的代码

a) Air service in src/wsdl/air_v26_0/Air.wsdl,
b) Hotel service in src/wsdl/hotel_v26_0/Hotel.wsdl
c) Vehicle service in src/wsdl/vehicle_v26_0/Vehicle.wsdl
d) Universal service in src/wsdl/universal_v26_0/UniversalRecord.wsdl


  • 6、 模型:Travelport Universal API公开一个端口,该端口有一个Service方法,无论使用何种语言,都可以使用方法或函数调用来通过给定端口在网络上发出请求,这个ping的端口仅仅只有一个service方法,image中还有请求和相应参数PingReq和PingRes,这些生成类的源代码可以在src中com.travelport.schema.system_v8_0.PingReq找到。
    在PingRsq/PingRsps的对象结构在XSD中指定rc/wsdl/system_v8_0/System.xsd。XSD文件定义在WSDL文件中使用的各种类型,WSDL引用这些XSD来导入这些定义。

  • 7、 使用System Service(Ping Port Example)
  1. Create an object of type PingReq
  1. PingReq使用其setter方法填写必要字段
    3) Create an instance of SystemService
  2. 访问该SystemService对象以获取类型的对象SystemPingPortType.(Access the SystemService object to get an object of type SystemPingPortType)
  3. Call the method service on the SystemPingPortType instance, passing the PingReq object created in step 1.(在SystemPingPortType实例上调用service方法,然后传递在步骤1中创建的对象)
  4. 通过PingRsp使用其getter方法查看对象来检查请求结果
    With very few exceptions,All the features and functions of Travelport Universal API follow this pattern of first build the request parameters and then use the port object to get the results
    for example:
public static void main(String[] argv) {  
 //
 // PING REQUEST
 //
 String payload= "this my payload; there are many like it but this one is mine";
 String someTraceId = "doesntmatter-8176";
 
 //set up the request parameters into a PingReq object
 PingReq req = new PingReq();
 req.setPayload(payload);
 req.setTraceId(someTraceId);
 
 try {
  //run the ping request
  PingRsp rsp = WSDLService.sysPing.get().service(req);
  //print results.. payload and trace ID are echoed back in response
  System.out.println(rsp.getPayload());
  System.out.println(rsp.getTraceId());
  System.out.println(rsp.getTransactionId());
 } catch (SystemFaultMessage e) {
  //usually only the error message is useful, not the full stack
  //trace, since the stack trace in is your address space...
  System.err.println("Error making ping request: "+e.getMessage());
 }
}

代码解析:上面的代码基本上遵循我们上面所有的变成模型,一个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 mine
doesntmatter-8176
E07E825F0A07580E004DED8EB9130465


  • 8、 Seeing the XML Exchanged
    在你的main方法中加入下面这行代码,可以看到正在交换的XML / SOAP消息
WSDLService.sysPing.showXML(true);

Unit1 Lesson 2:

目标:使用TravelPort Universal API搜索可用航班和价格(how to search for available flights and price itineraries using Travelport Universal API.)


  • 1、 工作流程

在第一课基础上,第二课的目标是为客户预定旅行。代理需要执行两项基本任务:
a) 查找一组可用航班,以便将旅客从出发地到目的地(如果适用的话也可以返回)
b) 根据航班设置,确定该行程的当前价格
准备:可用性搜索端口和价格端口( the Availability Search port and the Price port)这两个接口都可以从Air Service对象访问。


  • 2、 这个Lesson中需要用到的Client-Side

a) Air service in src/wsdl/air_v26_0/Air.wsdl
b) Hotel service in src/wsdl/hotel_v26_0/Hotel.wsdl
c) System service in src/wsdl/system_v8_0/System.wsdl
d) Vehicle service in src/wsdl/vehicle_v26_0/Vehicle.wsdl
e) 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/


  • 3、 Why So Many Packages and Files?
    要生成Air.wsdl和其他服务,是wsdl文件可能会引用其他wsdl文件以及外部类型。官网描述:The Air.wsdl file is the top of a large pyramid of different objects, and since they all can be referenced in a chain that starts from Air.wsdl, the CXF framework is obligated to generate code for them

  • 4、 形式
    此课程可以生成一个给定的城市对行程,eg:巴黎的查塔努加美国田纳西州
Price:GBP941.70 [BasePrice EUR760.00, Taxes GBP315.70]
AF#682 from CDG to ATL at 2012-06-22T10:55:00.000+02:00
AF#8468 from ATL to CHA at 2012-06-22T16:05:00.000-04:00
DL#5023 from CHA to ATL at 2012-06-29T16:06:00.000-04:00
DL#8517 from ATL to CDG at 2012-06-29T17:55:00.000-04:00
---------------
Price:GBP3594.70 [BasePrice EUR3998.00, Taxes GBP301.70]
UA#2331 from CDG to CLT at 2012-06-22T11:10:00.000+02:00
US#3568 from CLT to CHA at 2012-06-22T16:25:00.000-04:00
DL#5023 from CHA to ATL at 2012-06-29T16:06:00.000-04:00
DL#8517 from ATL to CDG at 2012-06-29T17:55:00.000-04:00

解读:行程有虚线分割,第一个行程的价格为941.70英镑,包括6月22日两架法航(AF)和6月29日返回巴黎的两架三角洲(DL)航班。第二个形成价格3594.70英镑,三家航空-美国联合航空(UA),美国航空(US)和达美航空公司(DL)
注意:第二课代码运行时,会生成许多这些行程,以及它们的价格当程序启动时等待从Travelport GDS返回的建议的可用行程时会暂停。在显示每个行程时,在特定行程定价时也会暂停


  • 5、 outline

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 itinerary
Display the resulting price
Display the segments of the journey)
(第一步第三步需要特别小心)


  • 6、 Purely Travelport Universal API

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);

两个示例:一个是从原点到目的地,一个在一周后返回。


  • 7、 解码
    Travelport Universal API服务器实际返回给客户端的XML
    1)构建关键映射
//make tables that map the "key" (or a reference) to the proper
//segment and the proper flight details
Helper.AirSegmentMap allSegments = Helper.createAirSegmentMap(rsp.getAirSegmentList().getAirSegment());
Helper.FlightDetailsMap allDetails = Helper.createFlightDetailsMap(rsp.getFlightDetailsList().getFlightDetails()); 

将响应(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); 

  • 8、 价钱
    我们现在有一个List对象,每个元素表示适合定价的旅程。
    首先构造正确的请求参数,在本例中为AirPricingReq。除了行程之外,AirPricingReq对象还有一些其他参数,例如机舱偏好(如果有多个可用),乘客类型等。
    displayItineraryPrice通过调用另一个方法priceItinerary来调用Travelport Universal API以获取AirItinerary的价格(方法

Unit1 Lesson 3:

目标:将了解如何使用Travelport Universal API的购物设施来查找两个城市之间的最低成本运输,包括使用铁路和低成本航空公司作为旅行方式,您还将了解如何异步从低成本购物API获取数据


  • 1、 LowFareSearch vs. Availability/Pricing

低票价搜索端口(AirService对象上的另一个端口)允许您通过搜索并将搜索结果返回已经定价来组合这两个步骤(可用性,定价)。此外,低票价搜索可以将返回的行程集缩小到最便宜的行程,因为搜索最低价格是常见情况。


  • 2、 Produce
    TravelPort API支持三种不同类型的提供商,Air, Rail, and Low Cost Carriers。

1)Air:Travelport的GDS提供商,Galileo(1G),Apollo(1V)和Worldspan(1P)。这些功能为您提供在线购物和预订航空旅行时所期望的功能。

  1. Raile:基于轨道的旅行的功能以与航空旅行所证明的相同的一般方式访问,但是从Rail.wsdl中定义的RailService开始(在本教程提供的文件中的目录wsdl / rail_v26_0中)
  2. Low Cost Carriers:GDSes(如Galileo,Apollo和Worldspan)通常不会将这些航空公司的票价或可用性分配给他们的网络。这些航空公司通常只在自己的网站上通过互联网销售。为了完整起见,我们在此提及此类提供程序。本教程主要关注GDS和铁路提供商

  • 3、Goal of Lesson 3
    生成输出,然后比较两个i地点之间不同交通工具的价格

  • 4、Low Fare searching
    搜索要使用AirLowFareSearchPortType进行搜索,结合Lesson2的开头,创建搜索请求以及Lesson2的结束,显示生成的定价解决方案。
    流程

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 results
Send a RetrieveLowFareSearchReq to retrieve results from the above search, from a specific provider
Consume the RetrieveLowFareSearchRsp object to get results)


  • 5、 Java Typing, Universal API, and Low Fare Search Responses

异步方法中使用两种基本Java类型来处理响应:LowFareSearchAsyncRsp和RetrieveLowFareSearchRsp。这些是asynchronous search and get-me-more-data ports端口分别返回的响应类型。


  • 6、 PrintableItinerary
    可以使用以下两种方法之一构造此类的实例:
public PrintableItinerary(AirPricingSolution solution, Helper.AirSegmentMap seg,
  String roundTripTurnaround)

public PrintableItinerary(RailPricingSolution solution, Helper.RailJourneyMap jour,     
  Helper.RailSegmentMap seg)

这两个构造器是这一类的air和rail版本,构造完成后,可以简单地在PrintableItinerary对象上调用toString()并打印出可理解的内容。
构造函数的air版本要求调用者提供roundTripTurnaround作为一个airport code,这是因为航空定价解决方案没有RailJourney中存在的方向概念,因此PrintableItinerary中的代码必须确定行程的哪些部分(AirSegments)是出境的以及哪些是入境的


Attention:根据您的测试凭据,铁路,车辆和低成本运营商可能无法使用。如果您看到错误消息,例如未配置提供程序或类似,则是因为您使用的是测试凭据,并且需要升级到生产凭据才能访问提供程序。

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 222,183评论 6 516
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 94,850评论 3 399
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 168,766评论 0 361
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 59,854评论 1 299
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 68,871评论 6 398
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 52,457评论 1 311
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 40,999评论 3 422
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 39,914评论 0 277
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 46,465评论 1 319
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 38,543评论 3 342
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 40,675评论 1 353
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 36,354评论 5 351
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 42,029评论 3 335
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 32,514评论 0 25
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 33,616评论 1 274
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 49,091评论 3 378
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 45,685评论 2 360

推荐阅读更多精彩内容

  • mean to add the formatted="false" attribute?.[ 46% 47325/...
    ProZoom阅读 2,701评论 0 3
  • 我的能量来源一定是不停的动中获得的小小的成就感而产生的正向磁场,而更加积极;还有高质量的独处,而获得的灵感。 我的...
    Rachel_8417阅读 114评论 0 0
  • 我也是后来才知道的,也就是我,改变了她!当她看到看到我内心的挣扎的时候,当她看到我抱着那个女孩的尸体哭泣的时候。她...
    鼎馨蓝天阅读 81评论 0 0
  • 生活中很多案例分享,让我们懂得商业模式的重要性。什么是商业模式,就是靠什么赚钱。 现在好多明星通过卖人设,聚集粉丝...
    云中来阅读 194评论 0 0
  • 每天的坚持,不是为了感动谁,也不是为了证明给谁看,而是我知道,一路奔跑,总比原地踏步要好! 再远的路,走着走着也就...
    思道明理阅读 60评论 0 0