`

[Tutorial] WSDL to Java with Apache CXF and soapUI

    博客分类:
  • J2EE
阅读更多
转自:http://www.celinio.net/techblog/?p=571

The WSDL2java command generates JAX-WS compliant Java code for the services that are defined in the WSDL document.
This is known as the Top-Down approach (contract first, based on an existing WSDL file).

1) open a DOS window and go to the CXF directory, under the bin sub-directory :
D:\softs\CXF\apache-cxf-2.3.1\bin

2) run the following command :

D:\softs\CXF\apache-cxf-2.3.1\bin>wsdl2java.bat -client -p com.company.auth.service http://localhost:8085/BMI/services/cxfBmi?wsdl




This command will create the folder D:\softs\CXF\apache-cxf-2.3.1\bin\com\company\auth\service

The -client option will generate a client
The -p option is used to specify the name of the package used for the generated classes

The generated classes are :
ComputeBMI.java
ComputeBMIResponse.java
IBMICalculator.java
IBMICalculator_IBMICalculatorImplPort_Client.java (the client)
IBMICalculatorImplService.java
ObjectFactory.java
package-info.java

These classes are fully annotated. For instance if we open IBMICalculator.java, we can see 8 annotations !
package com.company.auth.service;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;
import javax.xml.bind.annotation.XmlSeeAlso;
import javax.xml.ws.RequestWrapper;
import javax.xml.ws.ResponseWrapper;

/**
 * This class was generated by Apache CXF 2.3.1
 * Generated source version: 2.3.1
 *
 */

@WebService(targetNamespace = "http://services.bmi.company.com/", name = "IBMICalculator")
@XmlSeeAlso({ObjectFactory.class})
public interface IBMICalculator {

    @WebResult(name = "return", targetNamespace = "")
    @RequestWrapper(localName = "computeBMI", targetNamespace = "http://services.bmi.company.com/", className = "com.company.auth.service.ComputeBMI")
    @WebMethod
    @ResponseWrapper(localName = "computeBMIResponse", targetNamespace = "http://services.bmi.company.com/", className = "com.company.auth.service.ComputeBMIResponse")
    public double computeBMI(
        @WebParam(name = "weight", targetNamespace = "")
        double weight,
        @WebParam(name = "height", targetNamespace = "")
        double height
    );
}


3) copy the classes in the src folder of your project and modify the client according to your needs

Another way to generate the java code (stubs) is by using soapUI, a tool to test Web Services. It integrates different tools that use different Web Services frameworks.
In the case of Apache CXF framework, you must first set its path in the preferences :



Then in the Tools Menu, choose “Apache CXF Stubs”. This is where you specify the arguments for the WSDL2JAVA command. Check the box “All code” to generate all starting point code, choose an output directory :



The command is then executed and the options are displayed :



Link : https://cwiki.apache.org/CXF20DOC/wsdl-to-java.html
  • 大小: 32.2 KB
  • 大小: 136.3 KB
  • 大小: 32.8 KB
  • 大小: 70.1 KB
分享到:
评论
2 楼 Kevin_jiang2011 2012-06-25  
有些wsdl文件需要用代理才能访问,虽然在proxy setting里面设置了代理服务器和端口,并且能够生成testcase。 但是成cxf 客户端的代码的时候,会报连接超时异常。

请问这个问题怎么解决呢?
1 楼 Kevin_jiang2011 2012-06-25  
有些wsdl文件需要用代理才能访问,虽然在proxy setting里面设置了代理服务器和端口,并且能够生成testcase。 但是成cxf 客户端的代码的时候,会报连接超时异常。

相关推荐

    Frank Kane's Taming Big Data with Apache Spark and Python 【含代码】

    Frank Kane's Taming Big Data with Apache Spark and Python is your companion to learning Apache Spark in a hands-on manner. Frank will start you off by teaching you how to set up Spark on a single ...

    SLAM入门教程 A Tutorial Approach to Simultaneous Localization and Mapping

    《SLAM入门教程:A Tutorial Approach to Simultaneous Localization and Mapping》是一本为初学者设计的教程,旨在帮助读者从零基础开始理解SLAM的基本原理和方法。书名“SLAM for Dummies”暗示了它以通俗易懂的...

    Analog Circuit Design Volume 1 - A tutorial guide to applications and solutions

    Analog Circuit Design Volume 1 - A tutorial guide to applications and solutions password: goCHINAgo!

    Java 8 简明教程 (Java 8 Tutorial中文版)文字pdf版

    Java 8 简明教程 Java 8 Tutorial中文版 “Java并没有没落,人们很快就会发现这一点” 欢迎阅读我编写的Java 8介绍。本教程将带领你一步一步地认识这门语言的新特 性。通过简单明了的代码示例,你将会学习到如何使用...

    Java.7.A.Comprehensive.Tutorial

    Designed as a guidebook for those who want to become a Java developer, Java 7: A Comprehensive Tutorial discusses the essential Java programming topics that you need to master in order teach other ...

    Apache.Maven.Cookbook.1785286129

    If you are a Java developer or a manager who has experience with Apache Maven and want to extend your knowledge, then this is the ideal book for you. Apache Maven Cookbook is for those who want to ...

    A tutorial on support vector regression.Statistics and Computing,2004

    Furthermore, we include a summary of currently used algorithms for training SV machines, covering both the quadratic (or convex) programming part and advanced methods for dealing with large datasets....

    Java.Drawing.with.Apache.Batik.A.Tutorial(Apache.Batik教程)

    Apache batik 是一个开源的java svg 工具包,但是关于它的教程比较少。这是一本比较系统的介绍batik 的电子书,非常难得,不过是英文的,不过不难理解

    Java 3D Tutorial v1.6.2 (Java 3D API v1.2)

    目前为止能找到的最新版本。资料很难得。 Java 3D Tutorial v1.6.2 (Java 3D API v1.2) Getting Started with the Java 3D API A Tutorial for Beginners

    Beginning Cryptography With Java 带源码

    Beginning Cryptography with Java While cryptography can still be a controversial topic in the programming community, Java has weathered that storm and provides a rich set of APIs that allow you, the ...

    enterprise java microservices

    Enterprise Java Microservices is an example-rich tutorial that shows how to design and manage large-scale Java applications as a collection of microservices. Purchase of the print book includes a ...

    Android代码-java8-tutorial

    > You should also read my Java 11 Tutorial (including new language and API features from Java 9, 10 and 11). Welcome to my introduction to Java 8. This tutorial guides you step by step through all new...

    Apache Kylin Tutorial 1.5

    Apache Kylin Tutorial, 官方网站整理而来。 Apache Kylin Tutorial Apache Kylin Tutorial Apache Kylin Tutorial Apache Kylin Tutorial Apache Kylin Tutorial

    Java Tutorial

    A hands-on guide to the Java programming language, The Java™ Tutorial, Fourth Edition is perfect for any developer looking for a proven path to proficiency with Java SE. This popular tutorial "from ...

    Learning.Reactive.Programming.With.Java.8

    The book starts with an explanation of what reactive programming is, why it is so appealing, and how we can integrate it in to Java. It continues by introducing the new Java 8 syntax features, such as...

    Java Tutorial: Creating Web Services

    本文介绍了 Web 服务的基本概念和技术,包括 Web 服务的历史背景、多层架构的优势、SOAP 协议的工作原理、WSDL 的结构和用途、示例 Web 服务的开发流程,以及如何使用 Apache CXF 和不同类型的服务器部署 Web 服务。...

    docs文件 tutorial文件 java jdk所需文件

    本教程将深入探讨"docs文件"和"tutorial文件",这两个在Java学习和开发过程中非常重要的资源。 首先,"docs文件"通常指的是Java API文档。API(Application Programming Interface)是Java的核心组成部分,提供了...

    Java.Persistence.with.Hibernate.2nd.Edition

    We walk through a hands-on tutorial to get you started with your first Hibernate project. We look at Java application design for domain models and at the options for creating object/relational ...

    The Java EE 6 Tutorial Basic Concepts 4th Edition

    Chapter 17: Introduction to Contexts and Dependency Injection for the Java EE Platform 305 Overview of CDI 306 About Beans 307 About Managed Beans 307 Beans as Injectable Objects 308 Using ...

Global site tag (gtag.js) - Google Analytics