[轉載] WSDL2Java詳細使用說明【官方最全說明】

參考鏈接: Java中的this說明

WSDL to Java?

命名?

wsdl2java - 獲取WSDL文檔并生成完全帶注釋的Java代碼,并實現相關服務。?

概要?

用例 :?

?

wsdl2java -fe|-frontend <front-end-name> -db|-databinding <data-binding-name>?

-wv <wsdl-version> -p <[wsdl-namespace =]package-name>* -sn <service-name>?

-b <binding-file-name>* -reserveClass <class-name>* -catalog <catalog-file-name>?

-d <output-directory> -compile -classdir <compile-classes-directory> -impl -server

-client -clientjar <jar-file-name> -all -autoNameResolution -allowElementReferences|-aer<=true>?

-defaultValues<=class-name-for-DefaultValueProvider> -ant?

-nexclude <schema-namespace [= java-package-name]>* -exsh <(true, false)> -noTypes

-dns <(true, false> -dex <(true, false)> -validate -keep?

-wsdlLocation <wsdlLocation> -xjc<xjc-arguments>* -asyncMethods<[=method1,method2,...]>*?

-bareMethods<[=method1,method2,...]>* -mimeMethods<[=method1,method2,...]>* -noAddressBinding?

-faultSerialVersionUID <fault-serialVersionUID> -exceptionSuper <exceptionSuper>?

-mark-generated -suppress-generated-date -h|-?|-help -version|-v -verbose|-V -quiet|-q|-Q?

-wsdlList <wsdlurl>?

說明?

wsdl2java 獲取WSDL文檔并生成完全帶注釋的Java代碼,從中實現服務。 WSDL文檔必須具有有效的portType元素,但它不需要包含綁定元素或服務元素。 使用可選參數,您可以自定義生成的代碼。 此外,wsdl2java可以生成基于Ant的makefile來構建您的應用程序。?

選項?

用于驗證WSDL文件的選項在下表中進行了總結。?

?選項? 解釋? -?,-h,-help? Displays the online help for this utility and exits.? -fe frontend-name? Specifies the frontend. Default is JAXWS. Currently supports only JAXWS frontend and a "jaxws21" frontend to generate JAX-WS 2.1 compliant code.? -db databinding-name? Specifies the databinding. Default is jaxb. Currently supports jaxb, xmlbeans, sdo (sdo-static and sdo-dynamic), and jibx.? -wv wsdl-version? Specifies the wsdl version .Default is WSDL1.1. Currently suppports only WSDL1.1 version.? -p [ wsdl-namespace= ] PackageName? Specifies zero, or more, package names to use for the generated code. Optionally specifies the WSDL namespace to package name mapping.? -sn service-name? The WSDL service name to use for the generated code.? -b binding-name? Specifies JAXWS or JAXB binding files or XMLBeans context files. Use multiple -b flags to specify multiple entries.? -catalog catalog-file-name? Specify catalog file to map the imported wsdl/schema? -d output-directory? Specifies the directory into which the generated code files are written.? -compile? Compiles generated Java files.? -classdir compile-class-dir? Specifies the directory into which the compiled class files are written.? -client? Generates starting point code for a client mainline.? -clientjar jar-file-name? Generates the jar file which contains all the client classes and wsdl;the specified wsdlLocation won't work when the -clientJar is defined.? -server? Generates starting point code for a server mainline.? -impl? Generates starting point code for an implementation object.? -all? Generates all starting point code: types, service proxy, service interface, server mainline, client mainline, implementation object, and an Ant build.xml file.? -ant? Specify to generate an Ant build.xml script.? -autoNameResolution? Automatically resolve naming conflicts without requiring the use of binding customizations.? -defaultValues=[DefaultValueProvider impl]? Specifies that default values are generated for the impl and client. You can also provide a custom default value provider. The default provider is RandomValueProvider? -nexclude schema-namespace [=java-packagename]? Ignore the specified WSDL schema namespace when generating code. This option may be specified multiple times. Also, optionally specifies the Java package name used by types described in the excluded namespace(s).? -exsh (true/false)? Enables or disables processing of implicit SOAP headers (i.e. SOAP headers defined in the wsdl:binding but not wsdl:portType section.) Processing the SOAP headers requires the SOAP binding jars available on the classpath which was not the default in CXF 2.4.x and older. You may need to add a dependency to cxf-rt-binding-soap for this flag to work. Default is false.? -dns (true/false)? Enables or disables the loading of the default namespace package name mapping. Default is true and http://www.w3.org/2005/08/addressing=org.apache.cxf.ws.addressing namespace package mapping will be enabled.? -dex (true/false)? Enables or disables the loading of the default excludes namespace mapping. Default is true.? -validate? Enables validating the WSDL before generating the code.? -keep? Specifies that the code generator will not overwrite any preexisting files. You will be responsible for resolving any resulting compilation issues.? -wsdlLocation wsdlLocation? Specifies the value of the @WebServiceClient annotation's wsdlLocation property.? -xjc<xjc args>? Specifies a comma separated list of arguments that are passed directly to the XJC processor when using the JAXB databinding. A list of available XJC plugins can be obtained using -xjc-X.? -noAddressBinding? For compatibility with CXF 2.0, this flag directs the code generator to generate the older CXF proprietary WS-Addressing types instead of the JAX-WS 2.1 compliant WS-Addressing types.? -v? Displays the version number for the tool.? -verbose? Displays comments during the code generation process.? -quiet? Suppresses comments during the code generation process.? -exceptionSuper? superclass for fault beans generated from wsdl:fault elements (defaults to java.lang.Exception)? -reserveClass classname? Used with -autoNameResolution, defines a class names for wsdl-to-java not to use when generating classes. Use this option multiple times for multiple classes.? -allowElementReferences<=true>? (or -aer) If true, disregards the rule given in section 2.3.1.2(v) of the JAX-WS 2.2 specification disallowing element references when using wrapper-style mapping.? -asyncMethods=foo,bar,...? List of subsequently generated Java class methods to allow for client-side asynchronous calls, similar to enableAsyncMapping in a JAX-WS binding file.? -bareMethods=foo,bar,...? List of subsequently generated Java class methods to have wrapper style (see below), similar to enableWrapperStyle in JAX-WS binding file.? -mimeMethods=foo,bar,...? List of subsequently generated Java class methods to enable mime:content mapping, similar to enableMIMEContent in JAX-WS binding file.? -faultSerialVersionUID <fault-serialVersionUID>? How to generate suid of fault exceptions. Use NONE, TIMESTAMP, FQCN, or a specific number. Default is NONE.? -mark-generated? Adds the @Generated annotation to classes generated. -suppress-generated-dateSuppresses writing the current timestamp in the generated file (since CXF version 3.2.2) wsdlurl? The path and name of the WSDL file to use in generating the code.?

您必須將WSDL文檔的絕對路徑或相對路徑作為最后一個參數進行聲明。?

??

示例?

wsdl2java HelloWorld.wsdl

?

wsdl2java -p com.mycompany.greeting Greeting.wsdl

?

wsdl2java -client HelloWorld.wsdl?

(See below for usage with Apache Ant and Maven.)?

Using wsdl2java with Ant?

The wsdl2java command can be wrapped inside an Ant target as shown below:?

<?xml version="1.0"?>

?

<project name="cxf wsdl2java" basedir=".">??

?

? ?<property name="cxf.home" location ="/usr/myapps/cxf-2.5.1"/>

?

?

?

? ?<path id="cxf.classpath">

?

? ? ? <fileset dir="${cxf.home}/lib">

?

? ? ? ? ?<include name="*.jar"/>

?

? ? ? </fileset>

?

? ?</path>

?

? ? ? ?

?

? ?<target name="cxfWSDLToJava">

?

? ? ? <java classname="org.apache.cxf.tools.wsdlto.WSDLToJava" fork="true">

?

? ? ? ? ?<arg value="-client"/>

?

? ? ? ? ?<arg value="-d"/>

?

? ? ? ? ?<arg value="src"/>

?

? ? ? ? ?<arg value="MyWSDL.wsdl"/>

?

? ? ? ? ?<classpath>

?

? ? ? ? ? ? <path refid="cxf.classpath"/>

?

? ? ? ? ?</classpath>

?

? ? ? </java>

?

? ?</target>

?

</project>?

Make sure you set the "fork=true" attribute for the <java/> task as shown above. Also, remember to keep each word or flag within the command line options in its own <arg/> element (e.g., do not use <arg value="-d src"/>, but split them up into two <arg/> elements as done here.)?

Although we would recommend using Maven, see the antbuild sample in the CXF distribution for an example of using Ant to create a CXF project.?

JAXWS Customization?

The default JAX-WS frontend created by wsdl2java can be customized by using a customization binding file. For an example, see the async_binding.xmlfile in samples/jaxws_async – if specified when running wsdl2java, it will generate asynchronous methods in the SEI.?

Q: What if I want to change the generated SEI name??

A: We don't have a command-line option to do this, but you can have a binding file like the following snippet to achieve this goal?

?<bindings? ? ?xmlns:xsd="http://www.w3.org/2001/XMLSchema"? ? ?xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"? ? ?wsdlLocation="hello_world.wsdl"? ? ?xmlns="http://java.sun.com/xml/ns/jaxws">? ? ?<bindings node="wsdl:definitions/wsdl:portType[@name='GreeterSE']">? ? ?<class name="GreeterSEI"/>? ? ?</bindings> </bindings>?

Q: How do I pass the binding file to wsdl2java??

A: If you are using wsdl2java via command line tool:?

wsdl2java HelloWorld.wsdl -b my_binding.xml?

For Ant, follow the example above on how to add "-b" and "my_binding.xml" as arg elements.?

For Maven see cxf-codegen-plugin?

Q: How to map xsd:dateTime to java.util.Date? Well, people don't like the XMLGregorianCalendar which is the default mapping from the xsd:dateTime (xsd:time and xsd:date as well), We can use the jaxws customization to change the default mapping, here are some sample binding files If you have schema inside the wsdl, here is the binding file you can use:?

?<jaxws:bindings wsdlLocation="YOUR_WSDL_LOCATION"? ? ? ? ? ?xmlns:jaxws="http://java.sun.com/xml/ns/jaxws"? ? ? ? ? ?xmlns:xs="http://www.w3.org/2001/XMLSchema"? ? ? ? ? ?xmlns:jxb="http://java.sun.com/xml/ns/jaxb"? ? ? ? ? ?xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/">? ?<jaxws:bindings? node="wsdl:definitions/wsdl:types/xs:schema[@targetNamespace='THE_NAMESPACE_OF_YOUR_SCHEMA']">? ? ? ?<jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">? ? ? ? ?<jxb:javaType name="java.util.Date" xmlType="xs:dateTime"? ? ? ? ? ? ? ? ? ? ? ?parseMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.parseDateTime"? ? ? ? ? ? ? ? ? ? ? ?printMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.printDateTime"/>? ? ? ?</jxb:globalBindings>? ?</jaxws:bindings> </jaxws:bindings>?

This requires an additional dependency:?

?<dependency>? ? <groupId>org.apache.cxf.xjc-utils</groupId>? ? <artifactId>cxf-xjc-runtime</artifactId> </dependency>?

??

If you want to use java.util.Calendar, just change the org.apache.cxf.xjc.runtime.DataTypeAdapter to javax.xml.bind.DatatypeConverter, and change the name value to "java.util.Calendar"?

If your schema is out of wsdl, here is an example you can try:?

?<jxb:bindings version="2.0"? ? ? ? ? ? ? ?xmlns:jxb="http://java.sun.com/xml/ns/jaxb"? ? ? ? ? ? ? ?xmlns:xs="http://www.w3.org/2001/XMLSchema">? ?<jxb:bindings schemaLocation="file:<path><name>.xsd" node="/xs:schema">? ? ?<jxb:globalBindings xmlns:jxb="http://java.sun.com/xml/ns/jaxb" xmlns:xs="http://www.w3.org/2001/XMLSchema">? ? ? ?<jxb:javaType name="java.util.Date" xmlType="xs:dateTime"? ? ? ? ? ? ? ? ? ? ?parseMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.parseDateTime"? ? ? ? ? ? ? ? ? ? ?printMethod="org.apache.cxf.xjc.runtime.DataTypeAdapter.printDateTime"/>? ? ?</jxb:globalBindings>? ?</jxb:bindings> </jxb:bindings>?

Q: How can I switch my generated web service method calls from wrapper style to non wrapper-style (or vice-versa)??

A: Create an external binding file and set the value of <enableWrapperStyle/> to true or false as desired:?

?<jaxws:bindings? ? ?xmlns:xsd="http://www.w3.org/2001/XMLSchema"? ? ?xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"? ? ?wsdlLocation="your.wsdl"? ? ?xmlns="http://java.sun.com/xml/ns/jaxws"? ? ?xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">? ? ?<enableWrapperStyle>false</enableWrapperStyle> </jaxws:bindings>?

Alternatively you can embed this instruction within the WSDL file directly, as the immediate child of the wsdl:portType:?

?<wsdl:portType name="MyWebServicePortType">? ? ?<jaxws:bindings xmlns:jaxws="http://java.sun.com/xml/ns/jaxws">? ? ? ? ?<jaxws:enableWrapperStyle>false</jaxws:enableWrapperStyle>? ? ? ? ?... other binding settings if needed ...? ? ?</jaxws:bindings>? ? ?<wsdl:operation name="sayHello">? ? ?... </wsdl:portType>?

Note: The meaning of "wrapper-style" and "non-wrapper style" as defined in the JAX-WS 2.1 specification can be counterintuitive. Wrapper-style indicates that each data element within the request message gets its own Java parameter, while non-wrapper style means that a single Java object containing all the data elements serves as the lone parameter to the web service method call. (See Figure 2.2 of the specification for an example.) Also, note the wrapper style is not always available, the WSDL criteria specified in Section 2.3.1.2 ("Wrapper Style") of the specification must be met or only non-wrapper style will be generated.?

Q: What else can I change with the JAXWS customization binding file??

A: You can find the full list of customization items in Chapter 8 of the JAX-WS Specification.?

??

Using maven to generate java code from WSDL?

see cxf-codegen-plugin?

See Also?

idl2wsdl, java2js, java2ws, wsdl2corba, wsdl2js, wsdl2service, wsdl2soap, wsdl2xml, wsdlvalidator and xsd2wsdl.

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/540333.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/540333.shtml
英文地址,請注明出處:http://en.pswp.cn/news/540333.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

mdm.Dialogs.promptModal()使用

這是prompt的擴展&#xff0c;提供了更多的功能&#xff0c;比如可以添加其他按鈕和圖標import mdm.*;mdm.Application.init(this, onInit);function onInit():void {// 啟動程序...}quit.addEventListener(MouseEvent.CLICK,quitProgram);function quitProgram(evt:MouseEvent…

[轉載] JAVA 構造函數及其重載

參考鏈接&#xff1a; Java重載Overload public class Student{ public int stuId; public String stuName; public int stuAge; public int stuScore; public Student(){ } public Student(int sId,String sName){ stuId sId; sName stuName; } public Student(int sld,S…

學生機房虛擬化(十)系統操作設計實現

引入&#xff1a; 在前篇思路的指導下&#xff0c;進行了為期三個星期的調試最終建立了一個初步成熟的&#xff0c;具有親和力的配置界面&#xff0c;現在此虛擬系統已經初步部署了一個機房&#xff0c;用來學生日常上課。在本篇中&#xff0c;本人并不試圖去花篇幅講解彼此之間…

[轉載] java之重寫toString

參考鏈接&#xff1a; Java程序的輸出| 重寫Override 1.toString()就是是重寫&#xff0c;對于一般的對象來說都會有這個方法&#xff0c;其實這個方法的目的&#xff0c;主要就是將對象按字符串的方式輸出出來&#xff1a;打個比方&#xff0c;比如一個People類&#xff0c;里…

Gson的使用,對于不需要html escape的情況的處理

引入&#xff1a; 雖然是小問題&#xff0c;但是我還是需要記錄下&#xff0c;我們知道&#xff0c;Google提供了一個Gson框架讓我們高效的吧普通對象&#xff08;一般VO為佳&#xff09; 和json字符串之間進行互轉。因為轉換多數是和瀏覽器打交道的&#xff0c;所以一般默認的…

[轉載] Java 重寫paint繪圖

參考鏈接&#xff1a; 用Java重寫Override 感謝原文&#xff1a;https://zhidao.baidu.com/question/260060153.html 這個方法需要注意的地方不多&#xff0c;也就是重寫時&#xff0c;先調用 super.paint(g) 方法 paint方法不需要編寫代碼調用&#xff0c;只需要重寫。 其他…

教你如何進入有密碼的 XP 系統(下)

自動登錄時禁用Shift鍵 當使用自動登錄功能時&#xff0c;用戶可通過按住Shift鍵忽略登錄進程&#xff0c;輸入其他用戶名及密碼進入電腦。該技巧可以禁用自動登錄時的Shift鍵功能。操作步驟如下&#xff1a;打開“注冊表編輯器”&#xff0c;找到[HKEY_LOCAL_MACHINE\Softwar…

[轉載] 2020最新Java面試題,常見面試題及答案匯總

參考鏈接&#xff1a; Java程序的輸出| 18(重寫Override) 發現網上很多Java面試題都沒有答案&#xff0c;所以花了很長時間搜集整理出來了這套Java面試題大全&#xff0c;希望對大家有幫助哈~ 博主已將以下這些面試題整理成了一個Java面試手冊&#xff0c;是PDF版的。 關注…

【心隨筆】敘述你成功完成一件事情的方法

一、situation 先描述你曾經處于的困難狀況 二、task / target 說一說你是怎樣做出打算的 三、action / attitude 告訴別人你做出的行動 四、result 最后獲得了怎樣的成績轉載于:https://www.cnblogs.com/tnxlvlxy/p/7806142.html

[轉載] java排序compareTo:降序輸出學生成績

參考鏈接&#xff1a; Java程序的輸出| 18(重寫Override) 一道簡單程序題&#xff1a; 編寫一個程序&#xff0c;輸入學生的姓名、分數信息&#xff0c;要求程序按照成績降序排序后并輸出。 實現方法有很多 方法一 public class ScoreSort2 { private String name; pr…

300GB*6 SCSI RAID5 LINUX服務器數據恢復手記

[摘要]某數碼沖印網站&#xff0c;采用DELL POWEREDGE2850服務器&#xff0c;存儲部分由6塊300G硬盤組成RAID5&#xff0c;LINUX平臺&#xff0c;1.5T邏輯磁盤中只包含一個卷&#xff0c;文件系統為EXT3&#xff0c;存儲所有客戶數碼照片&#xff0c;服務器的故障導致整個公司無…

[轉載] public static void main(String[] args) 隱含了什么?

參考鏈接&#xff1a; 了解Java中“ public static void main”中的“ static” public class TestSort { public static void main(String[] args) { // 需要分別用Javac和Java命令行編譯和運行 int[] arr; int temp 0; arr new int [9]; for (int i 0; i < arr.length…

在C#中創建DataTable

經常遇到對DataTable進行各種運算&#xff0c;這方面的資料經常散落在各處&#xff0c;使用起來不方面&#xff0c;我想還是把他們集中到博客中&#xff0c;下次要用到的時候可以直接查看。下面是創建一個空白的DataTable&#xff0c;并定義相關的字段&#xff1a;DataTable dt…

[轉載] Java中的靜態方法不能被子類重寫

參考鏈接&#xff1a; 可以在Java中重載或重寫靜態方法嗎 Java中的靜態方法不能被子類重寫 特點&#xff1a;靜態方法屬于類的方法&#xff0c;也屬于對象的方法&#xff0c;但是靜態方法隨類的存在。 結論&#xff1a;Java中的靜態方法不能被子類重寫&#xff0c;實際上&…

2015-03-19 create php alternative for myslq_result in mysqli(PHP)--PDO Tutorial for Mysql Developers

來源&#xff1a;http://www.bestwebframeworks.com/tutorials/php/152/create-php-alternative-for-mysql_result-in-mysqli/ 內容&#xff1a; If you are migrating from PHP 5.5 to a newer version of PHP - you might be interested in a MySQL to MySQLi/PDO migration …

[轉載] [OpenGL] shadow mapping(實時陰影映射)

參考鏈接&#xff1a; Java中靜態函數的陰影(方法隱藏) 轉載原創&#xff1a;ZJU_fish1996 http://blog.csdn.net/zju_fish1996/article/details/51932954 source:原文地址 code:點擊可以直接下載源代碼 1978年&#xff0c;Lance Williams在其發表的論文《Casting cur…

[轉載] java synchronized靜態同步方法與非靜態同步方法,同步語句塊

參考鏈接&#xff1a; Java中的靜態方法與實例方法 java synchronized靜態同步方法與非靜態同步方法&#xff0c;同步語句塊 并發編程 線程同步 靜態方法鎖 非靜態方法鎖 同步塊 進行多線程編程&#xff0c;同步控制是非常重要的&#xff0c;而同步控制就涉及到了鎖。 對代…

SpringBoot安裝和創建簡單的Web應用

SpringBoot安裝 方式一&#xff1a; Eclipese->Help->Eclipse Marketplace ->Finde STS -> Install 注意&#xff1a;安裝過程中挺慢&#xff0c;而且可能會報錯&#xff0c;報錯時需要重復以上步驟&#xff08;重新安裝STS后&#xff0c;安裝進度接之前的繼續進行…

[轉載] JAVA 堆棧 堆 方法區 靜態區 final static 內存分配 詳解

參考鏈接&#xff1a; 在Java中為靜態最終static final變量分配值 轉載來源&#xff1a;https://blog.csdn.net/peterwin1987/article/details/7571808 Java棧與堆 堆:順序隨意 棧:后進先出(Last-in/First-Out). Java的堆是一個運行時數據區,類的對象從中分配空間。這些…

android學習之-Style樣式的定義

這個例子主要是寫了配置文件&#xff0c;main.xml <?xml version"1.0" encoding"utf-8"?> <LinearLayout xmlns:android"http://schemas.android.com/apk/res/android" android:orientation"vertical" android:lay…