TravelPort官方API解读

摘要:
在PingRsq/PingRssps_v8_0/system.XSD的对象结构中指定XSD中的rc/wsdl/systemXSD文件定义了WSDL文件中使用的各种类型,WSDL引用这些XSD来导入这些定义。
TravelPort 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
    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:根据您的测试凭据,铁路,车辆和低成本运营商可能无法使用。如果您看到错误消息,例如未配置提供程序或类似,则是因为您使用的是测试凭据,并且需要升级到生产凭据才能访问提供程序。

免责声明:文章转载自《TravelPort官方API解读》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇NETTY4中的BYTEBUF 内存管理VSCode插件开发全攻略(五)跳转到定义、自动补全、悬停提示下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Socket编程 (一)

<<Linux 网络编程>>摘要           注意: 其中的大部分成员是网络字节序(大端字节序); 编程: 服务器先要做的事情: socket() 初始化Socket bind() 绑定本地端口 listen() 监听端口 accept() 响应客户端请求 一个例子   客户端(Windows 系统, Java...

telnet 查看端口是否可访问

  1. 首先为什么要写这篇文章   说到为什么还得从DNS服务器说起。我在我的电脑上安装了DNS服务器,但是用网络去访问还怎么都访问都不上去。于是我就打开dos窗口,用ping命令查看是否可以ping(如 ping 125.34.49.211)通。一查能够ping通。既然可以通,那么就说明这个地址是有效的,那问题出现在那边呢,只能出现在访问的端口po...

运维配置环境中间件

日常Linux运维环境配置笔记---不定期更新 声明:本文为个人维护笔记,当中的例子或者步骤都是借鉴网络上的方法或者方案,后自己一步步的进行试验后得出来的。有可能会写错,也有可能是缺少某部分没有记录,如发现请大家指出。谢谢 版权声明:本文为博主原创文章,未经博主允许不得转载。 1.环境建立 输入用户、密码登录Luinx 查看网络情况如何,有没有加载网...

Nmap 扫描器的使用技巧

1.nmap语法  -A 全面扫描/综合扫描   例如:nmap -A 127.0.0.1  扫描指定段   例如:nmap 127.0.0.1-200&nmap 127.0.0.1/24 2.Nmap 主机发现  -sP   -sP ping扫描   例如:nmap -sP 127.0.0.1  -P0   -P0 无pin...

centos 端口测试之nc使用

服务器端口测试是否正常,运维一般使用telnet来检查,但它有局限性,服务器的端口必须存在服务运行。 这时使用nc可以在服务端模拟开启一个端口,再通过nc测试此端口,好用! nc是netcat工具的简称,一个网络工具,可以用来端口扫描、文件传输等功能。 centos上面安装也很简单: yum install nc -y nc常用功能 1、实现任意TCP/U...

Socket详解(转)

      在客户/服务器通信模式中, 客户端需要主动创建与服务器连接的 Socket(套接字), 服务器端收到了客户端的连接请求, 也会创建与客户连接的 Socket. Socket可看做是通信连接两端的收发器, 服务器与客户端都通过 Socket 来收发数据. 这篇文章首先介绍Socket类的各个构造方法, 以及成员方法的用法, 接着介绍 Sock...