JAX-WS Web Service -春秋航空销售部分接口使用

栏目: 服务器 · 发布时间: 7年前

内容简介:JAX-WS Web Service -春秋航空销售部分接口使用

JAX-WS Web Service -春秋航空销售部分接口使用

春秋航空销售部分接口由于使用的是Web Service方式,只知道有这么一种接口类型,大多数我们还是用的RESTful Web Services,不过 java 已经实现了对应的标准接口:

jax-ws 、jax-rs。

对于服务的和客户端,java都支持 工具 一键生成,省下了很多时间。下面用java的命令wsimport 来生成春秋航空部分接口客户端代码。

wsimport命令的参数如下:(java 8 环境)

beaverdeMBP:~ beaver$ wsimport -h
无法识别的参数-h


用法: wsimport [options] <WSDL_URI>

\其中 [options] 包括:
  -b <path>                 指定 jaxws/jaxb 绑定文件或附加模式
                            (每个 <path> 都必须具有自己的 -b)
  -B<jaxbOption>            将此选项传递给 JAXB 模式编译器
  -catalog <file>           指定用于解析外部实体引用的目录文件
                            支持 TR9401, XCatalog 和 OASIS XML 目录格式。
  -d <directory>            指定放置生成的输出文件的位置
  -encoding <encoding>      指定源文件所使用的字符编码
  -extension                允许供应商扩展 - 不按规范
                            指定功能。使用扩展可能会
                            导致应用程序不可移植或
                            无法与其他实现进行互操作
  -help                     显示帮助
  -httpproxy:<host>:<port>  指定 HTTP 代理服务器 (端口默认为 8080)
  -keep                     保留生成的文件
  -p <pkg>                  指定目标程序包
  -quiet                    隐藏 wsimport 输出
  -s <directory>            指定放置生成的源文件的位置
  -target <version>         按给定的 JAXWS 规范版本生成代码
                            默认为 2.2, 接受的值为 2.0, 2.1 和 2.2
                            例如, 2.0 将为 JAXWS 2.0 规范生成兼容的代码
  -verbose                  有关编译器在执行什么操作的输出消息
  -version                  输出版本信息
  -wsdllocation <location>  @WebServiceClient.wsdlLocation 值
  -clientjar <jarfile>      创建生成的 Artifact 的 jar 文件以及
                            调用 Web 服务所需的 WSDL 元数据。
  -generateJWS              生成存根 JWS 实现文件
  -implDestDir <directory>  指定生成 JWS 实现文件的位置
  -implServiceName <name>   生成的 JWS 实现的服务名的本地部分
  -implPortName <name>      生成的 JWS 实现的端口名的本地部分

\扩展:
  -XadditionalHeaders              映射标头不绑定到请求或响应消息不绑定到
                                   Java 方法参数
  -Xauthfile                       用于传送以下格式的授权信息的文件: 
                                   http://username:password@example.org/stock?wsdl
  -Xdebug                          输出调试信息
  -Xno-addressing-databinding      允许 W3C EndpointReferenceType 到 Java 的绑定
  -Xnocompile                      不编译生成的 Java 文件
  -XdisableAuthenticator           禁用由 JAX-WS RI 使用的验证程序,
                                   将忽略 -Xauthfile 选项 (如果设置)
  -XdisableSSLHostnameVerification 在提取 wsdl 时禁用 SSL 主机名
                                   验证

\示例:
  wsimport stock.wsdl -b stock.xml -b stock.xjb
  wsimport -d generated http://example.org/stock?wsdl

beaverdeMBP:~ beaver$
主要参数有-generateJWS   -Xnocompile    -s    -p   :
beaverdeMBP:demo beaver$ wsimport -Xnocompile -generateJWS   -keep -p com.xx.airlines.springairlines   [wsdlUrl]
正在解析 WSDL...



正在生成代码...
[wsdlUrl] 为wsdl地址。

生成了很多接口实现代码:

beaverdeMBP:demo beaver$ tree 
.
       └── com
            └── xxx
                └── airlines
                    └── springairlines
                        ├── AirportCityInfo.java
                        ├── ApplyReturnTicket.java
                        ├── ApplyReturnTicket2.java
                        ├── ApplyReturnTicket2Response.java
                        ├── ApplyReturnTicketInputBean.java
                        ├── ApplyReturnTicketResponse.java
                        ├── ApplyReturnTicketResultBean.java
                        ├── ApplyReturnTicketResultBean2.java
                        ├── BgFlightInfo.java
                        ├── BgPairInfo.java
                        ├── BgSeatInfo.java
                        ├── BookOrder.java
                        ├── BookOrderBookBean.java
                        ├── BookOrderResponse.java
                        ├── BookOrderResultBean.java
                        ├── BookSubProdBatch.java
                        ├── BookSubProdBatchInputBean.java
                        ├── BookSubProdBatchResponse.java
                        ├── BookSubProdBatchResultBean.java
                        ├── CalcRetTktFee.java
                        ├── CalcRetTktFeeInputBean.java
                        ├── CalcRetTktFeeResponse.java
                        ├── CalcRetTktFeeResultBean.java
                        ├── CancelFlightBgApp.java
                        ├── CancelFlightBgAppInputBean.java
                        ├── CancelFlightBgAppResponse.java
                        ├── CancelFlightBgAppResultBean.java
                        ├── CancelOrder.java
                        ├── CancelOrderInputBean.java
                        ├── CancelOrderResponse.java
                        ├── CancelOrderResultBean.java
                        ├── CommonInParameter.java
                        ├── CommonOutParameter.java
                        ├── CountryAreaInfo.java
                        ├── FlightBasicInfo.java
                        ├── FlightBgAppBasicInfo.java
                        ├── FlightBgAppHeadInfo.java
                        ├── FlightBgAppInfo.java
                        ├── FlightEndPointInfo.java
                        ├── FlightInfo.java
                        ├── FlightInfo2.java
                        ├── FlightSeatNoBean.java
                        ├── FlightSeatsInfoBean.java
                        ├── FlightTimeInfo.java
                        ├── GetBeanOfReceptionFlights.java
                        ├── GetCountryAreaCode.java
                        ├── GetCountryAreaCodeResponse.java
                        ├── GetCountryAreaCodeResultBean.java
                        ├── GetCountryAreaCodeSearchBean.java
                        ├── GetFlightBgApp.java
                        ├── GetFlightBgAppInputBean.java
                        ├── GetFlightBgAppResponse.java
                        ├── GetFlightBgAppResultBean.java
                        ├── GetFlightSeats.java
                        ├── GetFlightSeatsResponse.java
                        ├── GetFlightsCanBg.java
                        ├── GetFlightsCanBgInputBean.java
                        ├── GetFlightsCanBgResponse.java
                        ├── GetFlightsCanBgResultBean.java
                        ├── GetKeguiTotalDescription.java
                        ├── GetKeguiTotalDescription2.java
                        ├── GetKeguiTotalDescription2Response.java
                        ├── GetKeguiTotalDescriptionInputBean.java
                        ├── GetKeguiTotalDescriptionResponse.java
                        ├── GetKeguiTotalDescriptionResultBean.java
                        ├── GetMoneyClass.java
                        ├── GetMoneyClassResponse.java
                        ├── GetMoneyClassResultBean.java
                        ├── GetMoneyClassSearchBean.java
                        ├── GetOrderDetailInfo.java
                        ├── GetOrderDetailInfoQueryBean.java
                        ├── GetOrderDetailInfoResponse.java
                        ├── GetOrderDetailInfoResultBean.java
                        ├── GetOrderSumInfo.java
                        ├── GetOrderSumInfoQueryBean.java
                        ├── GetOrderSumInfoResponse.java
                        ├── GetOrderSumInfoResultBean.java
                        ├── GetOtherFyDetail.java
                        ├── GetOtherFyDetailInputBean.java
                        ├── GetOtherFyDetailResponse.java
                        ├── GetOtherFyDetailResultBean.java
                        ├── GetRetBeanOfQueryFlightSeatNo.java
                        ├── GetRetFlightSeatsBean.java
                        ├── GetSpecificPrice.java
                        ├── GetSpecificPriceInputBean.java
                        ├── GetSpecificPriceResponse.java
                        ├── GetSpecificPriceResultBean.java
                        ├── GetSubProdBooked.java
                        ├── GetSubProdBookedResponse.java
                        ├── GetSubProdBookedResultBean.java
                        ├── GetSubProdBySeg.java
                        ├── GetSubProdBySegInputBean.java
                        ├── GetSubProdBySegResponse.java
                        ├── GetSubProdBySegResultBean.java
                        ├── GetSubProdByTkt.java
                        ├── GetSubProdByTktResponse.java
                        ├── GetTravelBaoJiDetailInfo.java
                        ├── GetTravelBaoJiDetailInfoQueryBean.java
                        ├── GetTravelBaoJiDetailInfoResponse.java
                        ├── GetTravelBaoJiDetailInfoResultBean.java
                        ├── GetXprodCheckBind.java
                        ├── GetXprodCheckBindResponse.java
                        ├── InfoBeanOfGetSubProdBooked.java
                        ├── InfoBeanOfGetSubProdByTkt.java
                        ├── InsuranceBookInfo.java
                        ├── KeguiMultInfo.java
                        ├── MoneyClass.java
                        ├── NormSeatPriceInfo.java
                        ├── NormSeatPriceInfo2.java
                        ├── ObjectFactory.java
                        ├── OrderInfoForSlt.java
                        ├── OrderInfoForSltList.java
                        ├── OrderSumInfo.java
                        ├── OtherFeePolicy.java
                        ├── OtherFyDetailInfo.java
                        ├── PassengerBookInfo.java
                        ├── PassengerDetailInfo.java
                        ├── PriceCalcResult.java
                        ├── QueryFlightBgAppInfo.java
                        ├── QueryFlightBgAppInfoInputBean.java
                        ├── QueryFlightBgAppInfoResponse.java
                        ├── QueryFlightBgAppInfoResultBean.java
                        ├── QueryFlightSeatNo.java
                        ├── QueryFlightSeatNoResponse.java
                        ├── QueryOrderInfoForSlt.java
                        ├── QueryOrderInfoForSltQueryBean.java
                        ├── QueryOrderInfoForSltResponse.java
                        ├── QueryOrderInfoForSltResultBean.java
                        ├── ReceptionFlightsInfo.java
                        ├── RetBeanOfQueryFlightSeatNo.java
                        ├── RetFlightSeatsBean.java
                        ├── SearchBeanOfReceptionFlights.java
                        ├── SearchBeanOfSearchFlightsSP.java
                        ├── SearchFlightsBatch.java
                        ├── SearchFlightsBatchResponse.java
                        ├── SearchFlightsBatchResultBean.java
                        ├── SearchFlightsBatchResultBean2.java
                        ├── SearchFlightsBatchSP.java
                        ├── SearchFlightsBatchSPResponse.java
                        ├── SearchFlightsBatchSearchBean.java
                        ├── SearchFlightsBySegId.java
                        ├── SearchFlightsBySegId2.java
                        ├── SearchFlightsBySegId2Response.java
                        ├── SearchFlightsBySegIdBean.java
                        ├── SearchFlightsBySegIdResponse.java
                        ├── SearchReceptionFlights.java
                        ├── SearchReceptionFlightsResponse.java
                        ├── SearchTicketDetail.java
                        ├── SearchTicketDetailBean.java
                        ├── SearchTicketDetailResponse.java
                        ├── SearchTicketDetailResultBean.java
                        ├── SingleBookBeanOfBbookSubProdBatch.java
                        ├── SpringServiceSearchBookInterface.java
                        ├── SpringServiceSearchBookInterfaceService.java
                        ├── SubmitFlightBgApp.java
                        ├── SubmitFlightBgApp2.java
                        ├── SubmitFlightBgApp2Response.java
                        ├── SubmitFlightBgAppInputBean.java
                        ├── SubmitFlightBgAppResponse.java
                        ├── SubmitFlightBgAppResultBean.java
                        ├── SuperSeatPriceInfo.java
                        ├── SuperSeatPriceInfo2.java
                        ├── TicketBasicInfo.java
                        ├── TicketDetailInfo.java
                        ├── TicketInfo.java
                        ├── TravelBaoJiInfo.java
                        ├── UsernameToken.java
                        ├── XprodBeanOfCheckBind.java
                        ├── XprodBeanOfCheckBindInputBean.java
                        ├── XprodBeanOfCheckBindResultBean.java
                        ├── XprodBeanOfGetSubProd.java
                        ├── XprodBeanOfGetSubProdBooked.java
                        ├── XprodBookInfo.java
                        └── package-info.java

6 directories, 174 files
beaverdeMBP:demo beaver$

代码中接口的实现文件:

├── SpringServiceSearchBookInterface.java
                        ├── SpringServiceSearchBookInterfaceService.java
我们测试一下看是否能调用接口成功:        查询币种  接口
SpringServiceSearchBookInterface bookInterface = service.getPort(SpringServiceSearchBookInterface.class);
        GetMoneyClassSearchBean searchInfo = new GetMoneyClassSearchBean();
        UsernameToken usernameToken = new UsernameToken();
        usernameToken.setUsername("Username");
        usernameToken.setPassword("Password");
        searchInfo.setUsernameToken(usernameToken);
        final GetMoneyClassResultBean moneyClass = bookInterface.getMoneyClass(searchInfo);
        ObjectMapper objectMapper = new ObjectMapper();
        System.out.println("==================");
        System.out.println(objectMapper.writeValueAsString(moneyClass));

输出的json:

==================
{"errCode":null,"ifSuccess":"Y","moneyClassList":[{"moneyClassCode":"THB","moneyClassId":101},{"moneyClassCode":"CNY","moneyClassId":0},{"moneyClassCode":"JPY","moneyClassId":1},{"moneyClassCode":"USD","moneyClassId":21},{"moneyClassCode":"HKD","moneyClassId":61},{"moneyClassCode":"KRW","moneyClassId":62},{"moneyClassCode":"MOP","moneyClassId":81},{"moneyClassCode":"GBP","moneyClassId":41},{"moneyClassCode":"MYR","moneyClassId":121},{"moneyClassCode":"TWD","moneyClassId":141},{"moneyClassCode":"SGD","moneyClassId":161}]}

{

"errCode":null,

"ifSuccess":"Y",

"moneyClassList":[

{

"moneyClassCode":"THB",

"moneyClassId":101

},

{

"moneyClassCode":"CNY",

"moneyClassId":0

},

{

"moneyClassCode":"JPY",

"moneyClassId":1

},

{

"moneyClassCode":"USD",

"moneyClassId":21

},

{

"moneyClassCode":"HKD",

"moneyClassId":61

},

{

"moneyClassCode":"KRW",

"moneyClassId":62

},

{

"moneyClassCode":"MOP",

"moneyClassId":81

},

{

"moneyClassCode":"GBP",

"moneyClassId":41

},

{

"moneyClassCode":"MYR",

"moneyClassId":121

},

{

"moneyClassCode":"TWD",

"moneyClassId":141

},

{

"moneyClassCode":"SGD",

"moneyClassId":161

}

]

}

用了wsimport工具,生成客户端代码很方便,


以上所述就是小编给大家介绍的《JAX-WS Web Service -春秋航空销售部分接口使用》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Anatomy

Web Anatomy

Robert Hoekman Jr.、Jared Spool / New Riders / 2009-12-11 / USD 39.99

At the start of every web design project, the ongoing struggles reappear. We want to design highly usable and self-evident applications, but we also want to devise innovative, compelling, and exciting......一起来看看 《Web Anatomy》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

RGB转16进制工具
RGB转16进制工具

RGB HEX 互转工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换