JAXWS CXF JAXB + MyEclipse + Maven Byron自學視頻04

    技术2022-05-19  22

    JAXWS CXF JAXB + MyEclipse + Maven Byron自學視頻04

    Description: 使用 Apache CXF 搭配 wsdl2java + JAXB 調用 WebService範例來源: http://svn.apache.org/viewvc/cxf/trunk/distribution/src/main/release/samples/java_first_jaxws/Tags: jaxws, cxf, apache, webservice, myeclipse, maven, hello world, java, eclipse, byron, wsdl2java, wsdl first, jetty, tomcat, jaxb, marshal, unmarshal

     

    Powered by VideoBam - Free Video Hosting

     

    提及技巧:

    * JAXB 中的 @XmlJavaTypeAdapter 使用.

    * 依 cxf-codegen-plugin 內定值 .wsdl 檔案, 應放在 src/main/resources/wsdl 目錄下.

       即 <wsdlRoot>${basedir}/src/main/resources/wsdl</wsdlRoot>, 因是內定值, 故可省略不寫.

       然後用 includes/excludes 決定, 例:

       <includes>        <include>*Service.wsdl</include>   </includes>

     

     

    Client.java

    package junit.test; import org.apache.cxf.jaxws.JaxWsProxyFactoryBean; import com.wyd.cxf.IdentifiedUser; import com.wyd.cxf.IntegerUserMap; import com.wyd.cxf.User; import com.wyd.cxf.XxHelloWorld; public class Client { public static void main(String[] args) { JaxWsProxyFactoryBean factoryBean = new JaxWsProxyFactoryBean(); factoryBean.setServiceClass(XxHelloWorld.class); factoryBean.setAddress("http://localhost:9000/ZzhelloWorld"); XxHelloWorld hw = (XxHelloWorld) factoryBean.create(); System.out.println(hw.sayHi("孫六")); User user = new User("World"); System.out.println(hw.sayHiToUser(user)); // say hi to some more users to fill up the map a bit user = new User("Galaxy"); System.out.println(hw.sayHiToUser(user)); user = new User("Universe"); System.out.println(hw.sayHiToUser(user)); System.out.println(); System.out.println("Users: "); IntegerUserMap users = hw.getUsers(); for (IdentifiedUser e : users.getEntry()) { System.out.println(" " + e.getId() + ": " + e.getUser().getName()); } } }


    最新回复(0)