成人免费xxxxx在线视频软件_久久精品久久久_亚洲国产精品久久久_天天色天天色_亚洲人成一区_欧美一级欧美三级在线观看

Apache CXF實戰之一:Hello World Web Service

開發 后端
Apache的CXF現在幾乎成了Java領域構建Web Service的首選類庫,并且它也確實簡單易用,下面就通過幾篇系列文章做一下簡單介紹。

Apache的CXF現在幾乎成了Java領域構建Web Service的***類庫,并且它也確實簡單易用,下面就通過幾篇系列文章做一下簡單介紹。

當然首先想到的當然還是那個Hello World示例。這個系列文章中用到的例子都是基于Maven構建的工程,下面是我的pom.xml文件內容

  1. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  2.     xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">  
  3.     <modelVersion>4.0.0</modelVersion>  
  4.     <groupId>com.googlecode.garbagecan.cxfstudy</groupId>  
  5.     <artifactId>cxfstudy</artifactId>  
  6.     <packaging>war</packaging>  
  7.     <version>1.0-SNAPSHOT</version>  
  8.     <name>cxfstudy Maven Webapp</name>  
  9.     <url>http://maven.apache.org</url>  
  10.       
  11.     <properties>  
  12.         <cxf.version>2.2.7</cxf.version>  
  13.     </properties>  
  14.       
  15.     <dependencies>  
  16.         <dependency>  
  17.             <groupId>org.apache.cxf</groupId>  
  18.             <artifactId>cxf-rt-frontend-jaxws</artifactId>  
  19.             <version>${cxf.version}</version>  
  20.         </dependency>  
  21.         <dependency>  
  22.             <groupId>org.apache.cxf</groupId>  
  23.             <artifactId>cxf-rt-transports-http</artifactId>  
  24.             <version>${cxf.version}</version>  
  25.         </dependency>  
  26.         <dependency>  
  27.             <groupId>org.apache.cxf</groupId>  
  28.             <artifactId>cxf-rt-transports-http-jetty</artifactId>  
  29.             <version>${cxf.version}</version>  
  30.         </dependency>  
  31.         <dependency>  
  32.             <groupId>org.apache.cxf</groupId>  
  33.             <artifactId>cxf-rt-ws-security</artifactId>  
  34.             <version>${cxf.version}</version>  
  35.         </dependency>  
  36.         <dependency>  
  37.             <groupId>org.apache.cxf</groupId>  
  38.             <artifactId>cxf-rt-ws-policy</artifactId>  
  39.             <version>${cxf.version}</version>  
  40.         </dependency>  
  41.         <dependency>  
  42.             <groupId>org.apache.cxf</groupId>  
  43.             <artifactId>cxf-bundle-jaxrs</artifactId>  
  44.             <version>${cxf.version}</version>  
  45.         </dependency>  
  46.         <dependency>  
  47.             <groupId>javax.ws.rs</groupId>  
  48.             <artifactId>jsr311-api</artifactId>  
  49.             <version>1.1.1</version>  
  50.         </dependency>  
  51.         <dependency>  
  52.             <groupId>org.slf4j</groupId>  
  53.             <artifactId>slf4j-api</artifactId>  
  54.             <version>1.5.8</version>  
  55.         </dependency>  
  56.         <dependency>  
  57.             <groupId>org.slf4j</groupId>  
  58.             <artifactId>slf4j-jdk14</artifactId>  
  59.             <version>1.5.8</version>  
  60.         </dependency>  
  61.         <dependency>  
  62.             <groupId>commons-httpclient</groupId>  
  63.             <artifactId>commons-httpclient</artifactId>  
  64.             <version>3.0</version>  
  65.         </dependency>  
  66.         <dependency>  
  67.             <groupId>commons-io</groupId>  
  68.             <artifactId>commons-io</artifactId>  
  69.             <version>1.4</version>  
  70.         </dependency>  
  71.         <dependency>  
  72.             <groupId>junit</groupId>  
  73.             <artifactId>junit</artifactId>  
  74.             <version>4.8.1</version>  
  75.             <scope>test</scope>  
  76.         </dependency>  
  77.     </dependencies>  
  78.       
  79.     <build>  
  80.         <finalName>cxfstudy</finalName>  
  81.         <resources>  
  82.             <resource>  
  83.                 <directory>src/main/resources</directory>  
  84.             </resource>  
  85.             <resource>  
  86.                 <directory>src/main/java</directory>  
  87.                 <includes>  
  88.                     <include>**</include>  
  89.                 </includes>  
  90.                 <excludes>  
  91.                     <exclude>**/*.java</exclude>  
  92.                 </excludes>  
  93.             </resource>  
  94.         </resources>  
  95.         <plugins>  
  96.             <plugin>  
  97.                 <groupId>org.mortbay.jetty</groupId>  
  98.                 <artifactId>maven-jetty-plugin</artifactId>  
  99.                 <configuration>  
  100.                     <contextPath>/</contextPath>  
  101.                     <connectors>  
  102.                         <connector implementation="org.mortbay.jetty.nio.SelectChannelConnector">  
  103.                             <port>9000</port>  
  104.                         </connector>  
  105.                     </connectors>  
  106.                 </configuration>  
  107.             </plugin>  
  108.             <plugin>  
  109.                 <groupId>org.apache.maven.plugins</groupId>  
  110.                 <artifactId>maven-compiler-plugin</artifactId>  
  111.                 <configuration>  
  112.                     <source>1.5</source>  
  113.                     <target>1.5</target>  
  114.                 </configuration>  
  115.             </plugin>  
  116.         </plugins>  
  117.     </build>  
  118.  
  119. </project> 

#p#

下面來看看HelloWorld的具體例子。

1.創建HelloWorld 接口類

  1. package com.googlecode.garbagecan.cxfstudy.helloworld;  
  2.  
  3. import javax.jws.WebMethod;  
  4. import javax.jws.WebParam;  
  5. import javax.jws.WebResult;  
  6. import javax.jws.WebService;  
  7.  
  8. @WebService 
  9. public interface HelloWorld {  
  10.     @WebMethod 
  11.     @WebResult String sayHi(@WebParam String text);  

2.創建HelloWorld實現類

  1. package com.googlecode.garbagecan.cxfstudy.helloworld;  
  2.  
  3. public class HelloWorldImpl implements HelloWorld {  
  4.  
  5.     public String sayHi(String name) {  
  6.         String msg = "Hello " + name + "!";  
  7.         return msg;  
  8.     }  

3.創建Server端測試類

  1. package com.googlecode.garbagecan.cxfstudy.helloworld;  
  2.  
  3. import org.apache.cxf.jaxws.JaxWsServerFactoryBean;  
  4.  
  5. // http://localhost:9000/HelloWorld?wsdl  
  6. public class Server {  
  7.     public static void main(String[] args) throws Exception {  
  8.         JaxWsServerFactoryBean factory = new JaxWsServerFactoryBean();  
  9.         factory.setServiceClass(HelloWorldImpl.class);  
  10.           
  11.         factory.setAddress("http://localhost:9000/ws/HelloWorld");  
  12.         factory.create();  
  13.  
  14.         System.out.println("Server start...");  
  15.         Thread.sleep(60 * 1000);  
  16.         System.out.println("Server exit...");  
  17.         System.exit(0);  
  18.     }  
  19. }  

4.創建Client端測試類

  1. package com.googlecode.garbagecan.cxfstudy.helloworld;  
  2.  
  3. import org.apache.cxf.jaxws.JaxWsProxyFactoryBean;  
  4.  
  5. public class Client {  
  6.     public static void main(String[] args) {  
  7.         JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();  
  8.         factory.setServiceClass(HelloWorld.class);  
  9.         factory.setAddress("http://localhost:9000/ws/HelloWorld");  
  10.         HelloWorld helloworld = (HelloWorld) factory.create();  
  11.         System.out.println(helloworld.sayHi("kongxx"));  
  12.         System.exit(0);  
  13.     }  

5.測試

首先運行Server類來啟動Web Service服務,然后訪問http://localhost:9000/ws/HelloWorld?wsdl地址來確定web service啟動正確。

運行Client測試類,會在命令行輸出Hello kongxx!的message。

原文鏈接:http://blog.csdn.net/kongxx/article/details/7525476

【系列文章】

  1. Apache CXF實戰之五:壓縮Web Service數據
  2. Apache CXF實戰之四:構建RESTful Web Service
  3. Apache CXF實戰之三:傳輸Java對象
  4. Apache CXF實戰之二:集成Sping與Web容器
  5. Apache CXF實戰之一:Hello World Web Service
責任編輯:林師授 來源: kongxx的博客
相關推薦

2012-05-03 11:51:59

ApacheCXFJava

2012-05-03 11:43:32

ApacheCXFRESTful

2012-05-07 14:15:41

ApacheCXFJava

2012-05-07 14:08:20

ApacheCXFJava

2012-05-03 11:30:04

ApacheCXFJava

2009-10-19 14:14:19

OSGi Web應用

2012-05-03 11:35:56

ApacheCXFJava

2014-12-19 10:07:10

C

2017-11-23 17:45:46

Yii框架IntelYii框架深度剖析

2012-02-20 14:26:48

JavaPlay Framew

2009-07-30 13:21:17

Scala入門Hello World

2023-01-06 08:18:44

2009-08-11 10:32:23

什么是Groovy

2023-09-04 07:30:03

Wasm匯編語言

2009-09-16 17:15:19

OSGi Bundle

2011-06-08 14:39:06

Qt 教程

2022-04-27 10:51:00

PythonMLCubePodman

2009-08-14 16:54:19

C# Hello Wo

2021-11-26 08:22:01

Java動態開發

2011-08-05 09:48:46

iPhone Interface
點贊
收藏

51CTO技術棧公眾號

主站蜘蛛池模板: www.日韩 | 国产欧美精品区一区二区三区 | 黑人中文字幕一区二区三区 | 久久亚洲国产精品日日av夜夜 | 日韩国产精品一区二区三区 | 日韩视频一区 | 亚洲欧美中文日韩在线v日本 | 国产精品美女 | 水蜜桃久久夜色精品一区 | 天天色综网 | 51ⅴ精品国产91久久久久久 | 男人天堂手机在线视频 | 手机看黄av免费网址 | 最新av在线网址 | 日韩成人免费中文字幕 | 欧美日韩国产一区二区三区 | 国产一区2区 | 亚洲精品一区二区另类图片 | 91xxx在线观看 | 亚洲伊人久久综合 | 91极品欧美视频 | 精品伊人久久 | 91在线观| 日韩美女一区二区三区在线观看 | 伊久在线| 日本高清在线一区 | 高清视频一区二区三区 | 美女视频黄的免费 | 三级视频在线观看电影 | 激情国产视频 | 91精品国产乱码久久久久久 | 久久精品国产一区二区电影 | 日本免费黄色一级片 | 91精品国产一区 | 伊人狠狠干 | 精品无码久久久久久国产 | 亚洲精品免费视频 | 91在线视频观看 | 亚洲精品一区中文字幕乱码 | 毛片入口| 日韩一级电影免费观看 |