wsimport は Apache Axis2 の WSDL2Java みたいなツール。
WSDL から Java のソースコードを生成できる。
JAX-WS 2.0 では wsgen と wsimport という二つのコマンドライン・ツールが提供されています:
* wsgen
- wsgen は JAX-WS を用いた Web サービスの配備/実行を行うために必要なファイルを生成するためのコマンドライン・ユーティリティです。wsgen によって生成されたファイルは基本的に変更せずに使用します。
* wsimport
- wsimport は Web サービスのクライアント・プログラムを作成するときに利用するコマンドライン・ツールです。引数に指定された WSDL ファイルを読み取り、Web サービスを利用するために必要な Java クラスを生成します。wsimport によって生成されたファイルを利用することで、Web サービスのクライアント・プログラムを簡単に作成することができます。
XML サポートJava SE 6 Mustang-TECHSCORE- - 4.3. JAX-WS 2.0 / Web Services Metadata
入手方法
JAX-WS のリファレンス実装の中(binディレクトリの下)に wsimport.bat と wsimport.sh がある。
JAX-WS のリファレンス実装: jax-ws: JAX-WS Reference Implementation
今回は、バージョン 2.1.2 M1 を使用。
必要な Java
たぶん Java 5 が必要 (1.4ではたぶんダメだと思う……)
JREでもいけそうな気はする。
必要なソフトは、
* Requires JDK 5.0 Update 2 or later
* Requires Ant 1.6.2 or later
* Tested to work with Glassfish Promoted Build v2 b50 and Apache Tomcat 5.x
JAX-WS RI 2.1.2 M1-- Release Notes - 4. Required Software
って書いてある。
wsimport のヘルプ
Usage: wsimport [options] <WSDL_URI>
where [options] include:
-b <path> specify jaxws/jaxb binding files or additional schemas
(Each <path> must have its own -b)
-B<jaxbOption> Pass this option to JAXB schema compiler
-catalog <file> specify catalog file to resolve external entity references
supports TR9401, XCatalog, and OASIS XML Catalog format.
-d <directory> specify where to place generated output files
-extension allow vendor extensions - functionality not specified
by the specification. Use of extensions may
result in applications that are not portable or
may not interoperate with other implementations
-help display help
-httpproxy:<host>:<port> specify a HTTP proxy server (port defaults to 8080)
-keep keep generated files
-p <pkg> specifies the target package
-quiet suppress wsimport output
-s <directory> specify where to place generated source files
-target <version> generate code as per the given JAXWS specification version.
version 2.0 will generate compliant code for JAXWS 2.0 spec.
-verbose output messages about what the compiler is doing
-version print version information
-wsdllocation <location> @WebServiceClient.wsdlLocation value
Examples:
wsimport stock.wsdl -b stock.xml -b stock.xjb
wsimport -d generated http://example.org/stock?wsdl
wsimport で Java のソースコードを出力する
経路検索WebサービスRailGo のクライアント用ソースコードを生成してみる。
生成前にソースコードを入れるディレクトリ(今回は railgosrc ディレクトリ)を作っておかないと "directory not found" と怒られる。
C:\work\jaxws-ri\bin>mkdir railgosrc
C:\work\jaxws-ri\bin>wsimport -s railgosrc -p railgo.jaxws http://wstest.railgo.jp/Expservice06.asmx?WSDL
parsing WSDL...
[WARNING] Ignoring SOAP port "ExpService06Soap12": it uses non-standard SOAP 1.2 binding.
You must specify the "-extension" option to use this binding.
line 604 of http://wstest.railgo.jp/Expservice06.asmx?WSDL
generating code...
compiling code...
これで、ソースコードとクラスファイルが生成される。
何か警告が出ているけど、とりあえずスルーで。
生成したソースコード一覧
C:\>tree /F
フォルダ パスの一覧
ボリューム シリアル番号は 00001234 CAFE:BABE です
C:.
└─railgo
└─jaxws
AirlineFareType.java
AreaType.java
ArrayOfArrayOfStation.java
ArrayOfCourse.java
ArrayOfFare.java
ArrayOfFareSection.java
ArrayOfPassSection.java
ArrayOfRouteSection.java
ArrayOfStation.java
ArrayOfStationType.java
ArrayOfString.java
ArrayOfSurchargeSection.java
Authentication.java
CareState.java
Corporation.java
Course.java
ExpService06.java
ExpService06Soap.java
Fare.java
FareSection.java
GeodeticDatum.java
GetDefaultNavigation.java
GetDefaultNavigationResponse.java
GetUserPoints.java
GetUserPointsResponse.java
Line.java
LineType.java
Navigation.java
ObjectFactory.java
package-info.java
PassSection.java
PassType.java
RouteSection.java
SearchCourse.java
SearchCourseAll.java
SearchCourseAllResponse.java
SearchCourseResponse.java
SearchStation.java
SearchStationAll.java
SearchStationAllResponse.java
SearchStationResponse.java
SeatType.java
SortType.java
Station.java
StationType.java
SurchargeSection.java
Train.java
UseState.java
WaitTimeState.java
WSDL2Java の使用例参考: NI-Lab.'s ヅラッシュドット: RailGo Webサービス と Apache Axis2 を試す
tags: zlashdot WebServices JAXWS Java SOAP WSDL WebServices
Posted by NI-Lab. (@nilab)