前言

博客草稿中“SOA生态系统初探”一文一直没有进展,感觉要将SOA、Web Service(WS)、REST等概念阐述清楚还需要一些酝酿。

顶天须得立地,这里记录一些“下里巴人”的实践,主要考察Apache Axis2和Apache CXF两个Java服务开发框架,首先从CXF着手。

目录

1 工具

2 Eclipse中Apache CXF配置

3 运行实例

4 参考资料

内容

1 工具

Windows 7

Eclipse Juno(4.2.0, JEE version, build-id: 20120614-1722)

Apache CXF 2.4.2(较新版本2.7.11在配置过程中莫名其妙的出现一些错误,回退到较低版本),将CXF解压目录记为CXF_HOME

Apache Tomcat 7.0

2 Eclipse中Apache CXF配置

Window->Preferences->Web Services->CXF 2.x Preferences->CXF Runtime中添加运行时,指定CXF解压目录即可

3 运行实例

预期目标:自底向上(bottom-up)创建WS,将WS部署到Servlet容器中,观察服务的WSDL、通过浏览器调用WS接口。

创建Dynamic Web Project项目

项目结构(添加index.html)

预期的Project Facets

Before

After

编写服务实现类

package com.spike.cxf;

import javax.jws.WebService;

/**
 * Description: HelloService Implementation<br/>
 * Date: 2014-5-11 下午7:59:33
 */
@WebService(targetNamespace = "http://cxf.spike.com/", portName = "HelloServiceImplPort", serviceName = "HelloServiceImplService")
public class HelloServiceImpl {
    public String getVersion() {
        return "1.0";
    }

    public String greeting(String user) {
        return "Hello " + user + "!";
    }

}

基于Dynamic Web Project添加CXF Facets:右键服务实现类,Generate Web Service

配置WS类型

服务端点接口(SEI)选择或创建,这里默认

选择服务方法注解,这里默认

CXF Java2WS配置,这里默认

启动服务(实际是Servlet容器)等待

服务发布方式设置,这里默认

点击Finish后项目结构

Package Explorer

Project Explorer

Servlet容器的“配置”,端口选用了8082

访问服务http://localhost:8082/CXF/services

点击WSDL链接http://localhost:8082/CXF/HelloServiceImplPort?wsdl

生成的WSDL和XSD文件

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions name="HelloServiceImplService" targetNamespace="http://cxf.spike.com/" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:tns="http://cxf.spike.com/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/wsdl/soap/">
  <wsdl:types>
    <schema xmlns="http://www.w3.org/2001/XMLSchema">
<import namespace="http://cxf.spike.com/" schemaLocation="helloserviceimpl_schema1.xsd"/>
</schema>
  </wsdl:types>
  <wsdl:message name="greeting">
    <wsdl:part name="parameters" element="tns:greeting">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="getVersion">
    <wsdl:part name="parameters" element="tns:getVersion">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="getVersionResponse">
    <wsdl:part name="parameters" element="tns:getVersionResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:message name="greetingResponse">
    <wsdl:part name="parameters" element="tns:greetingResponse">
    </wsdl:part>
  </wsdl:message>
  <wsdl:portType name="HelloServiceImpl">
    <wsdl:operation name="greeting">
      <wsdl:input name="greeting" message="tns:greeting">
    </wsdl:input>
      <wsdl:output name="greetingResponse" message="tns:greetingResponse">
    </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getVersion">
      <wsdl:input name="getVersion" message="tns:getVersion">
    </wsdl:input>
      <wsdl:output name="getVersionResponse" message="tns:getVersionResponse">
    </wsdl:output>
    </wsdl:operation>
  </wsdl:portType>
  <wsdl:binding name="HelloServiceImplServiceSoapBinding" type="tns:HelloServiceImpl">
    <soap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>
    <wsdl:operation name="greeting">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="greeting">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="greetingResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
    <wsdl:operation name="getVersion">
      <soap:operation soapAction="" style="document"/>
      <wsdl:input name="getVersion">
        <soap:body use="literal"/>
      </wsdl:input>
      <wsdl:output name="getVersionResponse">
        <soap:body use="literal"/>
      </wsdl:output>
    </wsdl:operation>
  </wsdl:binding>
  <wsdl:service name="HelloServiceImplService">
    <wsdl:port name="HelloServiceImplPort" binding="tns:HelloServiceImplServiceSoapBinding">
      <soap:address location="http://localhost:8082/CXF/services/HelloServiceImplPort"/>
    </wsdl:port>
  </wsdl:service>
</wsdl:definitions>
<?xml version="1.0" encoding="utf-8"?><xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:tns="http://cxf.spike.com/" elementFormDefault="unqualified" targetNamespace="http://cxf.spike.com/" version="1.0">
<xs:element name="getVersion" type="tns:getVersion"/>
<xs:element name="getVersionResponse" type="tns:getVersionResponse"/>
<xs:element name="greeting" type="tns:greeting"/>
<xs:element name="greetingResponse" type="tns:greetingResponse"/>
<xs:complexType name="greeting">
    <xs:sequence>
      <xs:element minOccurs="0" name="arg0" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
<xs:complexType name="greetingResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="return" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
<xs:complexType name="getVersion">
    <xs:sequence/>
  </xs:complexType>
<xs:complexType name="getVersionResponse">
    <xs:sequence>
      <xs:element minOccurs="0" name="return" type="xs:string"/>
    </xs:sequence>
  </xs:complexType>
</xs:schema>

调用服务接口方法

(1)http://localhost:8082/CXF/services/HelloServiceImplPort/getVersion

(2)http://localhost:8082/CXF/services/HelloServiceImplPort/greeting?arg0=zhoujiagen

4 参考资料

[1] JAX-WS with Apache CXF and Eclipse [step1] http://angelozerr.wordpress.com/2011/08/23/jaxwscxf_step1/
[2] JAX-WS with Apache CXF and Eclipse [step2] http://angelozerr.wordpress.com/2011/08/24/jaxwscxf_step2/

Apache CXF 101 Win Eclipse开发环境搭建的更多相关文章

  1. 大数据应用之Windows平台Hbase客户端Eclipse开发环境搭建

    大数据应用之Windows平台Hbase客户端Eclipse开发环境搭建 大数据应用之Windows平台Hbase客户端Eclipse环境搭建-Java版 作者:张子良 版权所有,转载请注明出处 引子 ...

  2. [转]MonkeyRunner在Windows下的Eclipse开发环境搭建步骤(兼解决网上Jython配置出错的问题)

    MonkeyRunner在Windows下的Eclipse开发环境搭建步骤(兼解决网上Jython配置出错的问题)   网上有一篇shangdong_chu网友写的文章介绍如何在Eclipse上配置M ...

  3. Hadoop Eclipse开发环境搭建

        This document is from my evernote, when I was still at baidu, I have a complete hadoop developme ...

  4. (转)Hadoop Eclipse开发环境搭建

    来源:http://www.cnblogs.com/justinzhang/p/4261851.html This document is from my evernote, when I was s ...

  5. zookeeper Eclipse 开发环境搭建及简单示例

    一,下载Zookeeper安装包 从官方网站下载稳定版安装包后,解压. 其中ZK_HOME 为:D:\Program Files\zookeeper-3.4.9 二,启动Zookeeper Serve ...

  6. libgdx for eclipse开发环境搭建

    1.安装jdk1.7以上 2.下载libgdx1.2.0 下载地址:https://libgdx.badlogicgames.com/releases 3.下载项目创建工具(老版本的) 下载地址:ht ...

  7. Hadoop伪分布配置与基于Eclipse开发环境搭建

    国内私募机构九鼎控股打造APP,来就送 20元现金领取地址:http://jdb.jiudingcapital.com/phone.html内部邀请码:C8E245J (不写邀请码,没有现金送)国内私 ...

  8. MAC下Android的Eclipse开发环境搭建

    原文链接:https://www.cnblogs.com/macro-cheng/archive/2011/09/30/android-001.html 一.Eclipse的下载 到网站:http:/ ...

  9. Windows下PHP+Eclipse开发环境搭建 及错误解决(apache2.2服务无法启动 发生服务特定错误:1)

    前言 Eclipse与php/apache的关系:Eclipse只是用来写代码的,如果想要在浏览器查看运行效果就要让php/apache的运行目录指向你的代码目录.Eclipse貌似不会自己和apac ...

随机推荐

  1. php file_get_contents curl发送cookie,使用代理

    $auth = base64_encode('LOGIN:PASSWORD');//LOGIN:PASSWORD 这里是你的账户名及密码 $aContext = array( 'http' => ...

  2. 存储过程Oracle学习(一)

    一.简介 存储过程:就是在数据库中创建的一段程序,供别人调用 .其实我感觉跟定义一个方法相似 二.无参存储过程 如下,经典的输出"Hello World"来入门存储过程 创建一个存 ...

  3. 解决JavaScript中使用$.ajax方式提交数组参数

    一般的,可能有些人在一个参数有多个值的情况下,可能以某个字符分隔的形式传递,比如页面上有多个checkbox: $.ajax{ url:"xxxx", data:{ p: &quo ...

  4. Program E-- CodeForces 18C

    Description Once Bob took a paper stripe of n squares (the height of the stripe is 1 square). In eac ...

  5. 图解傅里叶变换(so easy)

    话不多说先上两个GIF图. 第一个动画和第二个动画其实都是对时域的周期矩形形波(近似看成矩形波,并不是严格意义的矩形方波)进行傅里叶变换分析. 对于第一个图形来说,它侧重展示变换的本质之一:叠加性,每 ...

  6. SharedPreference 存储小量数据,一般首次启动显示引导界面就用这个。

    写://添加一个SharedPreference并传入数据SharedPreference sharedPreferences = getSharedPreferences("share_d ...

  7. java基础之 http

    HTTP(HyperText Transfer Protocol)是一套计算机通过网络进行通信的规则.计算机专家设计出HTTP,使HTTP客户(如Web浏览器)能够从HTTP服务器(Web服务器)请求 ...

  8. SharePoint 2013 Nintex Workflow 工作流帮助(二)

    博客地址 http://blog.csdn.net/foxdave 工作流动作 1. Action Set(Logic and flow分组) 它是一个工作流的集合,可以理解为容器的东西.所以它本身并 ...

  9. JEvaluator Jscript.net

    using Microsoft.JScript; using System; using System.CodeDom.Compiler; using System.Collections.Gener ...

  10. 2016/7/30 div位置设置,表格大小统一

    在做作业过程中遇到的一些问题和我的总结 1.作业中给出了一张背景图,并让我在背景图中一片区域写内容 我的思路是将一个div放在这片区域,那么问题就是如何定义div的位置和大小 查阅资料后发现并不复杂, ...