- 浏览: 107451 次
- 性别:
- 来自: 北京
文章分类
最新评论
-
坚持唯一:
1、看一下eclipse中的window---Preferen ...
Emulator] Failed to allocate memory: 8 -
pop1030123:
都过期了。
MyEclipse 6.0.1 注册码 -
seasheart:
北京多好啊,为什么不留在那家公司呢?
突然发现我该把实习的经历写出来,等到以后7老8十了.... -
abin7230:
你都还有实习,我都不知学校在那实习的呢
突然发现我该把实习的经历写出来,等到以后7老8十了.... -
huangpengxiao:
关注楼主头像。。。
安装飞信fetion IE主页被yidong139篡改
Introduction
Let's start with the service itself. We'll make it simple so you can see what is going on when we build and deploy the services. A StockQuoteService example seems to be mandatory in instances like this one, so let's use the following (see Code Listing 1).
Code Listing 1: The StockQuoteService class
package samples.quickstart.service.pojo; import java.util.HashMap; public class StockQuoteService { private HashMap map = new HashMap(); public double getPrice(String symbol) { Double price = (Double) map.get(symbol); if(price != null){ return price.doubleValue(); } return 42.00; } public void update(String symbol, double price) { map.put(symbol, new Double(price)); } }
It will be a simple service with two possible calls. One of which is an in/out message, and the other is an in-only service. Ultimately, we'll package the service and deploy it in four different ways.
First, let's look at how this simple Java class corresponds to a service.
Getting Ready
Before we build anything using Axis2, we have to take care of a little housekeeping. First off, you'll need to get your environment ready for working with Axis2. Fortunately, it involves just a few simple steps:
- Download and install Java (Minimum version is JDK1.4). Set the JAVA_HOME environment variable to the pathname of the directory into which you installed the JDK release.
- Download Axis2 and extract it to a target directory.
- Copy the axis2.war file to the webapps directory of your servlet engine.
- Set the AXIS2_HOME environment variable to point to the target directory in step. Note that all of the scripts and build files Axis2 generates depend on this value, so don't skip this step! Linux users can alternatively run the setenv.sh file in the AXIS2_HOME/bin directory to set the AXIS2_HOME environment variable to the pathname of the extracted directory of Axis2.
In most cases, we're also going to need a WSDL file for our service. Axis2's Java2WSDL can be used to bootstrap a WSDL. To generate a WSDL file from a Java class, perform the following steps:
- Create and compile the Java class.
(Windows) %AXIS2_HOME%\bin\java2wsdl -cp . -cn samples.quickstart.service.pojo.StockQuoteService -of StockQuoteService.wsdl (Linux) $AXIS2_HOME/bin/java2wsdl -cp . -cn samples.quickstart.service.pojo.StockQuoteService -of StockQuoteService.wsdl
- Generate the WSDL using the command:
Once you've generated the WSDL file, you can make the changes you need. For example, you might add custom faults or change the name of the generated elements. For example, this StockQuoteService.wsdl is in AXIS2_HOME/samples/quickstartadb/resources/META-INF folder, which we'll be using throughout the rest of this guide, replaces the generic parameters created by the generation process.
Axis2 Services
Before we build anything, it's helpful to understand what the finished product looks like.
The server side of Axis2 can be deployed on any Servlet engine, and has the following structure. Shown in Code Listing 2.
Code Listing 2: The Directory Structure of axis2.war
axis2-web META-INF WEB-INF classes conf axis2.xml lib activation.jar ... xmlSchema.jar modules modules.list addressing.mar ... soapmonitor.mar services services.list aservice.aar ... version.aar web.xml
Starting at the top, axis2-web is a collection of JSPs that make up the Axis2 administration application, through which you can perform any action such as adding services and engaging and dis-engaging modules. The WEB-INF directory contains the actual java classes and other support files to run any services deployed to the services directory.
The main file in all this is axis2.xml, which controls how the application deals with the received messages, determining whether Axis2 needs to apply any of the modules defined in the modules directory.
Services can be deployed as *.aar files, as you can see here, but their contents must be arranged in a specific way. For example, the structure of this service will be as follows:
- StockQuoteService - META-INF - services.xml - lib - samples - quickstart - service - pojo - StockQuoteService.class
Here, the name of the service is StockQuoteService, which is specified in the services.xml file and corresponds to the top-level folder of this service. Compiled Java classes are placed underneath this in their proper place based on the package name. The lib directory holds any service-specific JAR files needed for the service to run (none in this case) besides those already stored with the Axis2 WAR file and the servlet container's common JAR directories. Finally, the META-INF directory contains any additional information about the service that Axis2 needs to execute it properly. The services.xml file defines the service itself and links the Java class to it (See Code Listing 3).
Code Listing 3: The Service Definition File
<service name="StockQuoteService" scope="application"> <description> Stock Quote Sample Service </description> <messageReceivers> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-only" class="org.apache.axis2.rpc.receivers.RPCInOnlyMessageReceiver"/> <messageReceiver mep="http://www.w3.org/2004/08/wsdl/in-out" class="org.apache.axis2.rpc.receivers.RPCMessageReceiver"/> </messageReceivers> <parameter name="ServiceClass"> samples.quickstart.service.pojo.StockQuoteService </parameter> </service>
Here the service is defined, along with the relevant messageReceiver types for the different message exchange patterns.
The META-INF directory is also the location for any custom WSDL files you intend to include for this application.
You can deploy a service by simply taking this hierarchy of files and copying it to the webapps/axis2/WEB-INF/services directory of your servlet engine. (Note the Axis2 WAR file must be installed first in the servlet engine.) This is known as the "exploded" format. You can also compress your documents into an *.aar file, similar to a *.jar file, and place the *.aar file directly in the servlet engine's webapps/axis2/WEB-INF/services directory.
Now that you understand what we're trying to accomplish, we're almost ready to start building.
First, download and unzip the appropriate version of Axis2 Standard Binary Distribution. Make sure that you set the value of the AXIS2_HOME variable to match the location into which you extracted the contents of this release.
Let's look at some different ways to create clients and services.
Creating Services
To generate and deploy the service using the Axis2 Databinding Framework (ADB), execute the following steps.
Generate the skeleton using the WSDL2Java utility by typing the following in the Axis2_HOME/samples/quickstartadb directory:
(Windows) %AXIS2_HOME%\bin\WSDL2Java -uri resources\META-INF\StockQuoteService.wsdl -p samples.quickstart.service.adb -d adb -s -ss -sd -ssi -o build\service (Linux) $AXIS2_HOME/bin/WSDL2Java -uri resources/META-INF/StockQuoteService.wsdl -p samples.quickstart.service.adb -d adb -s -ss -sd -ssi -o build/service
Else, simply type ant generate.service in the Axis2_HOME/samples/quickstartadb directory.
The option -d adb specifies Axis Data Binding (ADB). The -s switch specifies synchronous or blocking calls only. The -ss switch creates the server side code (skeleton and related files). The -sd switch creates a service descriptor (services.xml file). The -ssi switch creates an interface for the service skeleton. The service files should now be located at build/service.
If you generated the code by using WSDL2Java directly, next you have to modify the generated skeleton to implement the service (if you used "ant generate.service", a completed skeleton will be copied over the generated one automatically).
Open the build/service/src/samples/quickstart/adb/service/StockQuoteServiceSkeleton.java file and modify it to add the functionality of your service to the generated methods; shown in Code Listing 6.
Code Listing 6: Defining the Service Skeleton File
package samples.quickstart.service.adb; import samples.quickstart.service.adb.xsd.GetPriceResponse; import samples.quickstart.service.adb.xsd.Update; import samples.quickstart.service.adb.xsd.GetPrice; import java.util.HashMap; public class StockQuoteServiceSkeleton { private static HashMap map; static{ map = new HashMap(); } public void update(Update param0) { map.put(param0.getSymbol(), new Double(param0.getPrice())); } public GetPriceResponse getPrice(GetPrice param1) { Double price = (Double) map.get(param1.getSymbol()); double ret = 42; if(price != null){ ret = price.doubleValue(); } GetPriceResponse res = new GetPriceResponse(); res.set_return(ret); return res; } }
Now you can build the project by typing the following command in the build/service directory:
ant jar.server
If all goes well, you should see the BUILD SUCCESSFUL message in your window, and the StockQuoteService.aar file in the build/service/build/lib directory. Copy this file to the webapps/axis2/WEB-INF/services directory of the servlet engine.
You can check to make sure that the service has been properly deployed by viewing the list of services at,
http://localhost:8080/axis2/services/listServices
You can also check the custom WSDL at,
http://localhost:8080/axis2/services/StockQuoteService?wsdl
and the schema at,
http://localhost:8080/axis2/services/StockQuoteService?xsd
Creating Clients
To build a client using Axis Data Binding (ADB), execute the following steps.
Generate the client databings by typing the following in the Axis2_HOME/samples/quickstartadb directory:
%AXIS2_HOME%\bin\WSDL2Java -uri resources\META-INF\StockQuoteService.wsdl -p samples.quickstart.clients -d adb -s -o build\clientElse, simply type ant generate.client in the Axis2_HOME/samples/quickstartadb directory.
Next take a look at quickstartadb/src/samples/quickstart/clients/ADBClient.java, and see how it's defined in Code Listing 10.
Code Listing 10: The ADBClient Class
package samples.quickstart.clients; import samples.quickstart.service.adb.StockQuoteServiceStub; public class ADBClient{ public static void main(java.lang.String args[]){ try{ StockQuoteServiceStub stub = new StockQuoteServiceStub ("http://localhost:8080/axis2/services/StockQuoteService"); getPrice(stub); update(stub); getPrice(stub); } catch(Exception e){ e.printStackTrace(); System.err.println("\n\n\n"); } } /* fire and forget */ public static void update(StockQuoteServiceStub stub){ try{ StockQuoteServiceStub.Update req = new StockQuoteServiceStub.Update(); req.setSymbol ("ABC"); req.setPrice (42.35); stub.update(req); System.err.println("price updated"); } catch(Exception e){ e.printStackTrace(); System.err.println("\n\n\n"); } } /* two way call/receive */ public static void getPrice(StockQuoteServiceStub stub){ try{ StockQuoteServiceStub.GetPrice req = new StockQuoteServiceStub.GetPrice(); req.setSymbol("ABC"); StockQuoteServiceStub.GetPriceResponse res = stub.getPrice(req); System.err.println(res.get_return()); } catch(Exception e){ e.printStackTrace(); System.err.println("\n\n\n"); } } }This class creates a client stub using the Axis Data Bindings you created. Then it calls the getPrice and update operations on the Web service. The getPrice method operation creates the GetPrice payload and sets the symbol to ABC. It then sends the request and displays the current price. The update method creates an Update payload, setting the symbol to ABC and the price to 42.35.
Now build and run the client by typing ant run.client in the Axis2_HOME/samples/quickstartadb directory.
You should get the following as output:
42 price updated 42.35
发表评论
-
我的android开发经历1
2013-06-14 19:40 677从开始接触android已经2年多了,因为与平常工 ... -
Oracle RAC DB Failover, JNDI remote lookup
2012-10-22 11:34 1579前一段时间production的某一个RAC DB node挂 ... -
我的第一个Android app, android app推广与广告
2012-10-15 23:01 1022学习Android APP开发一个月了,写了自己第一个APP, ... -
TIBCO BW SQL data type
2012-03-15 16:28 833TIBCO BW 里面JDBC query的时候用绑定变量,但 ... -
JSF无法提交(summit只是刷新原页面)
2011-03-24 18:40 894最近使用JSF开发的时候,如果页面有某个element的I ... -
JAVA反射机制作用是什么
2011-03-24 18:34 902一、什么是反射: 反 ... -
JAVA设计模式学习笔记–装饰者模式
2010-03-26 22:59 1286装饰者模式: 1. 装饰者模式动态的将责任附加到对象上,若要 ... -
java.lang.IllegalStateExceptThis loader has been closed and should not be in use
2010-03-26 22:33 2632今天用OC4J重新deploy一个project以后出现了 ... -
理解Java ClassLoader机制
2009-11-10 11:24 978当JVM(Java虚拟机)启动 ... -
专家建议:五种最值得学习的JAVA开发技术
2008-10-15 16:46 756【赛迪网-技术社区整理】Carlos Perez(著名的J ... -
一个Java程序员应该掌握的10项技能
2008-10-15 16:49 843阅读提示: 一个合格 ... -
利用java做一个简单的计算器
2008-10-15 16:53 977两个类。还只是完成+、-、×、÷运算而已。GUI只是用了AWT ... -
SSL简单示例
2008-10-17 10:54 738import java.io.BufferedReader; ... -
about uddi root registry and affiliate registry
2009-01-08 14:10 689V3规范则提出了一个全新的 UDDI体系框架 . V3规 ... -
Effective java 主题:Effective Java Second Edition中文版已出版
2009-03-13 16:11 918本书分为11章共78个条目 ... -
Java连接数据库代码
2009-03-16 10:58 12791、Oracle8/8i/9i数据库(thin模式) Cl ... -
Java的ClassLoader与Package机制(Prohibited package name:XXX)
2009-04-03 16:22 769如遇到这个问题:Prohibi ... -
AXIS2中OMElement和Java对象之间的转换*(详细版)
2009-04-08 17:54 1088AXIOM Axis对象模型(AXIOM)是一个XML ... -
JAVA排序汇总-java排序算法-JAVA算法汇总
2009-04-30 10:23 675package com.softeem.jbs.lesson4 ... -
EXCEL批量转化为TXT-EXCEL转化为TXT-java实现 Excel转txt
2009-05-11 12:49 1171在网上找了个EXCEL转化为TXT的JAVA代码,改了下使得可 ...
相关推荐
axis2 soa webservice axis2 基础的中文!!!!!!
【Axis2基础教程】 Axis2 是一款广泛应用的Web服务引擎,尤其在构建和消费Web服务时扮演着重要角色。Web服务是一种允许不同应用程序之间相互通信的技术,它能够跨越不同的平台和技术栈,实现异构环境下的系统集成。...
学习者需要有一定的Axis2基础和Web服务概念,以便更好地理解和应用这些示例。 标签 "axis2" 明确地指出这个项目与Apache Axis2紧密相关。Axis2是基于SOAP(简单对象访问协议)的,它是用于在不同系统间交换结构化...
**Axis2基础知识** Axis2是Apache软件基金会开发的一个开源Web服务引擎,它是 Axis1 的下一代产品,用于构建和部署Web服务。它基于模块化的设计,使得 Axis2 具有高性能、可扩展性和灵活性。Axis2支持多种协议,如...
1. Axis2基础概念: - Web服务:是一种通过HTTP协议进行通信的应用程序,使得不同系统间能够交换数据和服务。 - SOAP(Simple Object Access Protocol):一种轻量级的消息协议,用于在Web上交换结构化和类型化的...
Axis2 入门及简单例子 Axis2 是一个基于 Java 的 Web 服务框架,它提供了一个灵活、可扩展、可靠的方式来创建、部署和管理 Web 服务。Axis2 是 Apache 软件基金会的一个开源项目,是基于 SOAP 和 WSDL 的 Web 服务...
Apache Axis2 是 Apache Axis SOAP 项目的后继项目。此项目是 Web 服务核心引擎的重要改进,目标是成为 Web 服务和面向服务的体系结构(Service-Oriented Architecture,SOA)的下一代平台。作为一个干净的可扩展的...
1. **Axis2基础**: - Axis2是基于SOAP(Simple Object Access Protocol)的Web服务引擎,它提供了丰富的功能,包括WS-I兼容性、模块化架构、多种消息传输支持等。 - Axis2采用服务组件架构(Service Component ...
**一、Axis2基础概念:** 1. **服务引擎:** Axis2是Web服务的服务引擎,负责处理SOAP消息,执行服务逻辑,并将响应返回给调用者。 2. **模块:** Axis2的模块是可插入的组件,提供特定功能,如安全、MTOM(Message ...
描述中的"Axis2教程.doc"确认了这个文件包含了一个Axis2的入门教程,适合想要学习或了解Axis2基础的人群。 **Axis2基础知识** Axis2是基于Apache Axis1的一个全新设计和实现,它是用Java语言编写的,用于处理SOAP...
#### 二、Axis2基础知识 **1.1 Axis2简介** Axis2是由Apache组织维护的一个开源项目,它是一个基于Java的Web服务引擎,旨在提供高效、灵活且易于使用的Web服务解决方案。相比于其前身Axis1.x,Axis2进行了全面的重...
Axis2是Apache Axis的第二代版本,它在第一代的基础上进行了许多改进和优化,提供了更高效、灵活的Web服务解决方案。Axis2基于模块化设计,允许用户按需选择功能,从而降低了内存占用和提高了性能。它支持多种协议,...
在IT行业中,Axis2是Apache软件基金会开发的一个用于构建Web服务和Web服务客户端的框架,主要基于Java语言。本文将详细讲解如何使用Axis2来发布Web服务以及如何生成客户端代码来调用这些服务。 首先,让我们了解...
#### 二、Axis2基础知识 ##### 1. **用POJO实现0配置的WebService** 在Axis2中,开发者可以利用简单的POJO(Plain Old Java Object)创建无须额外配置的WebService。这种模式极大地简化了开发流程,提高了效率。...
本课程共分为两部分,其中第一部分为Axis2基础知识讲解。在这部分介绍了前面所述的Axis2 知识。第二部分介绍了三个小的项目。这三个项目的功能类似。所不同的是,它们使用了不同的技术来实现。第一个项目使用Java ...
7. **axis2-kernel-1.4.jar**:Axis2内核JAR文件包含了运行Axis2服务的基础组件,如服务加载器和服务处理逻辑。 8. **xercesImpl-2.8.1.jar**:Xerces是Apache的一个XML解析器项目,它实现了XML 1.0和1.1规范,以及...
课程分为两大部分:第一部分是Axis2基础知识的讲解,涵盖上述各项技术要点;第二部分则通过三个实际项目来加深理解。这三个项目都是个人信息管理系统(PIM),但实现技术有所不同,分别是使用Java Swing、Struts ...
7. **HTTP通信** - Apache HttpClient库用于处理HTTP请求和响应,是Axis2进行Web服务调用的基础。 8. **服务部署** - Axis2支持多种部署模型,包括WAR文件部署、目录结构部署等,使得Web服务的发布和更新更加便捷。...