`
longgangbai
  • 浏览: 7315881 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

使用CXF中的Aegis开发WS使用

阅读更多

package com.easyway.cxf.service;

import java.util.List;

import com.easyway.cxf.model.User;
/**
 *
 * @author longgangbai
 *
 */
public interface HelloService {
 /**
  * The @WebParam annotation is necessary as java interfaces do not store the Parameter name in the .class file. So if you leave out the annotation your parameter will be named arg0.
  * @param name
  * @return
  */
  public String hello(String name);
 
  /**
   * Advanced usecase of passing an Interface in.  JAX-WS/JAXB does not
   * support interfaces directly.  Special XmlAdapter classes need to
   * be written to handle them
   */
  public String sayHi(User user);

  public String[] getAllUseNames(List<User> userList);
}
package com.easyway.cxf.service;

import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

import com.easyway.cxf.model.User;
/**
 * 采用Aegis CXF 的使用发布WS
 * @author longgangbai
 *
 */
public class HelloServiceImpl implements HelloService {

    Map<Integer, User> users = new LinkedHashMap<Integer, User>();
   

 public String hello(String username) {
        return "Hello " + username;
 }

 public String sayHi(User user) {
         users.put(users.size() + 1, user);
         return "Hello "  + user.getUsername();
 }
 public String[] getAllUseNames(List<User> userList) {
  String[] userListArr=new String[userList.size()];
  for (int i=0;i<userList.size();i++) {
   userListArr[i]=userList.get(i).getUsername();
  }
  return userListArr;
 }

}

<?xml version="1.0" encoding="UTF-8"?>
<!--
  Licensed to the Apache Software Foundation (ASF) under one
  or more contributor license agreements. See the NOTICE file
  distributed with this work for additional information
  regarding copyright ownership. The ASF licenses this file
  to you under the Apache License, Version 2.0 (the
  "License"); you may not use this file except in compliance
  with the License. You may obtain a copy of the License at

  http://www.apache.org/licenses/LICENSE-2.0

  Unless required by applicable law or agreed to in writing,
  software distributed under the License is distributed on an
  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
  KIND, either express or implied. See the License for the
  specific language governing permissions and limitations
  under the License.
-->
<mappings>
    <mapping name="HelloService">
        <method name="hello">
            <parameter index="0" name="greeting" nillable='false' />
        </method>
    </mapping>
</mappings>

 

 

package com.easyway.cxf.test.server;

import org.apache.cxf.aegis.databinding.AegisDatabinding;
import org.apache.cxf.frontend.ServerFactoryBean;

import com.easyway.cxf.service.HelloService;
import com.easyway.cxf.service.HelloServiceImpl;

public class AegisCXFServer {
 public static final String SERVICE_ADDRESS="http://localhost:8080/services/helloService";
      public static void main(String args[]) throws Exception {
       HelloService helloworldImpl = new HelloServiceImpl();
          ServerFactoryBean svrFactory = new ServerFactoryBean();
          svrFactory.setServiceClass(HelloService.class);
          svrFactory.setAddress(SERVICE_ADDRESS);
          svrFactory.setServiceBean(helloworldImpl);
          svrFactory.getServiceFactory().setDataBinding(new AegisDatabinding());
          svrFactory.create();
          System.out.println("Server ready...");
 
          Thread.sleep(5 * 60 * 1000);
          System.out.println("Server exiting");
          System.exit(0);
      }
 }
package com.easyway.cxf.test.client;


import org.apache.cxf.aegis.databinding.AegisDatabinding;
import org.apache.cxf.frontend.ClientProxyFactoryBean;

import com.easyway.cxf.service.HelloService;
import com.easyway.cxf.test.server.AegisCXFServer;

 

public final class AegisCXFClient {

    private AegisCXFClient() {
    }

    public static void main(String args[]) throws Exception {
        ClientProxyFactoryBean factory = new ClientProxyFactoryBean();
        factory.setServiceClass(HelloService.class);
        if (args != null && args.length > 0 && !"".equals(args[0])) {
            factory.setAddress(args[0]);
        } else {
            factory.setAddress(AegisCXFServer.SERVICE_ADDRESS);
        }
        factory.getServiceFactory().setDataBinding(new AegisDatabinding());
        HelloService client = (HelloService)factory.create();
        System.out.println("Invoke hello()....");
        System.out.println(client.hello(System.getProperty("user.name")));
        System.exit(0);
    }

}

分享到:
评论

相关推荐

    CXF关于Aegis的简单示例

    在Aegis示例中,我们可能会学习如何配置Spring来创建一个CXF客户端,该客户端能够调用使用Aegis绑定的服务。 4. **XML与Java对象的转换**:Aegis的核心功能在于XML与Java对象之间的转换。在实际操作中,我们需要...

    Spring中使用CXF

    本文将深入探讨如何在Spring项目中整合并使用CXF,以便实现高效的Web服务交互。 **1. Spring与CXF的集成** Spring与CXF的集成主要通过Spring的`&lt;bean&gt;`标签和CXF的JAX-WS或JAX-RS组件来完成。首先,需要在项目中...

    apache cxf_jar包

    Apache CXF是一个开源的Java框架,它主要用于构建和开发服务导向架构(SOA)中的Web服务。这个"apache cxf_jar包"包含了实现基于Java的Web服务所需的一系列核心库。下面我们将深入探讨这些jar文件及其在Web服务实现...

    apache-cxf-3.1.4

    在"apache-cxf-3.1.4-src.tar.gz"源码包中,你可以找到CXF框架的所有源代码,这对于开发者深入理解框架的工作原理、进行定制开发或贡献代码非常有帮助。源码包通常包含以下部分: 1. **核心库**:实现CXF的主要功能...

    apache-cxf-3.1.8.zip

    同时,CXF还支持其他数据绑定框架,如 JiBX 和 Aegis。 5. **协议栈支持**:CXF实现了多种WS-*协议,如WS-Security(安全)、WS-Addressing(地址)和WS-ReliableMessaging(可靠消息传递),增强了Web服务的安全性...

    CXF3.1.10.jar

    这个jar包是开发人员在使用CXF框架时所必需的依赖之一,它集成了各种接口、类和实用工具,使得开发者能够方便地实现基于SOAP或RESTful的Web服务。 Apache CXF的主要特点和功能包括: 1. **Web服务支持**:CXF支持...

    cxf所需jar包

    在Java开发环境中,使用CXF进行Web服务开发时,通常需要依赖一系列的JAR包来实现其功能。这些JAR包包含了CXF框架的核心组件、XML解析器、WS-I兼容性模块、HTTP传输机制等关键部分。 "2积分.txt"可能是一个文本文件...

    CXF资源架包完整版下载

    5. **强类型数据绑定**:CXF支持JAXB(Java Architecture for XML Binding)和Aegis数据绑定,允许对象直接映射到XML消息,简化了Web服务的开发。 6. **支持WS-*规范**:CXF实现了许多WS-*规范,如WS-Security、WS-...

    cxf相关的jar

    这使得在企业级应用中使用CXF变得更加便捷和灵活。 总之,"cxf相关的jar"压缩包是开发和运行CXF Web服务的必备资源,包含了各种功能模块,可以满足从简单的SOAP服务到复杂的RESTful API的开发需求。对于Java开发者...

    apache-cxf-2.4.6.zip

    9. **插件支持**:CXF提供了Maven插件,可以方便地在Maven项目中使用,简化构建流程。 在"apache-cxf-2.4.6.zip"压缩包内,你会找到CXF的库文件、文档、示例代码和配置文件等。通过解压并导入到你的项目中,你可以...

    apache-cxf-3.1.1跟3.1.6所有jar包

    Apache CXF是一个开源的Java框架,它...通过这个压缩包,你可以直接在你的项目中使用这些已测试过的版本,避免版本不兼容或找不到合适依赖的问题。同时,作者也欢迎对Web服务有疑问的开发者留言交流,共同学习和进步。

    CXF源码及其lib包

    1. **Web服务开发**:CXF提供了一种基于JAX-WS(Java API for XML Web Services)的高级API,使得开发人员能够轻松地创建和部署Web服务。它支持WS-I基本配置、WS-Security、WS-ReliableMessaging等高级特性。 2. **...

    apache-cxf-2.5.9

    Apache CXF是一个开源的Java框架,它主要用于构建和开发Web服务。这个压缩包"apache-cxf-...这个压缩包"apache-cxf-2.5.9"是开发人员在使用CXF 2.5.9版本时所需的所有组件的集合,包含了运行和测试Web服务所需的库。

    apache-cxf-2.2.4

    安装和使用"apache-cxf-2.2.4"时,开发者需要根据自己的项目需求选择合适的组件,配置相应的服务和客户端,并通过Maven或Gradle等构建工具将其依赖引入到项目中。同时,阅读官方文档和示例代码可以帮助更好地理解和...

    apache-cxf-3.3.6.zip

    1. JAX-WS(Java API for XML Web Services):CXF提供了对JAX-WS的全面支持,允许开发人员以Java编程的方式创建和使用SOAP Web服务。开发者可以使用注解或XML配置来定义服务接口和服务实现。 2. JAX-RS(Java API ...

    cxf webservice所需jar包

    在实际开发中,为了简化依赖管理,许多开发者会选择使用Maven或Gradle等构建工具,通过指定CXF的依赖项,让这些工具自动下载并管理所需的jar包。这不仅避免了手动收集和管理jar包的麻烦,还能确保所有依赖的一致性和...

    cxf和springnvc整合

    首先,为了在 Spring 应用程序中使用 CXF,我们需要在项目的 `pom.xml` 文件中添加相应的 CXF 依赖。这些依赖包括 CXF 的核心组件、前端模块(如 JAX-WS 和 JAX-RS)、数据绑定模块以及传输模块。以下是一些常见的 ...

    最新apache-cxf-3.2.7

    4. **使用CXF开发Web服务**: - 首先,你需要在项目中引入CXF的依赖,这可以通过Maven或Gradle完成。 - 创建服务接口和实现,使用`@WebService`和`@Path`注解来标记服务接口和资源类。 - 配置CXF的服务器端点,...

    CXF文档介绍

    尽管目前仍然是Apache的一个孵化项目,但CXF因其丰富的功能和易用性而在开发社区中备受青睐。 CXF的主要功能包括对多种Web Services标准的支持,如SOAP、Basic Profile、WS-Addressing、WS-Policy、WS-...

Global site tag (gtag.js) - Google Analytics