Axis2基础入门
2016-07-06 23:54
211 查看
最近学习Axis2这个webService。将一些基础但重要的知识简单总结一下。这里是内容是建立在Axis2已经部署在tomcat的情况下(部署过程很简单,在Apache网站上下载axis2的war包然后解压到tomcat/webapps下,此时访问http://localhost:8080/axis2/services/listServices便可知是否正常)
在阅读《Apache Axis2 Web Services 2nd Edition》这本书的时候,在关于如果发布一个WebServices书中提到了两种方法。
方法一:POJO approach
现在我们编写一个简单的POJO类,这个类不包含在任何包下:
接下来的操作就是把这个普通的POJO发布为webServices让其他人可以远程调用。
发布过程:
Compile the Java class, which will produce the HelloWorld.class file.
Go to /webapps/axis2/WEB-INF.
Create a directory named pojo inside the WEB-INF directory.
Then copy the HelloWorld.class into the pojo directory, created in the
previous step.
Start Tomcat.
Go to http://localhost:8080/axis2/services/listServices , where
you will be able to find a service named HelloWorld listed
按照如上的步骤即可通过http://localhost:8080/axis2/services/listServices 这个URL可以看到我们刚刚发布的webServices。注意,这种方法只适合没有包的POJO方法。
通过浏览器访问该webServices:http://localhost:8080/axis2/services/HelloWorld/sayHello?name=Axis2
此时浏览器会打印:
如何对于一个存在包结构的POJO类又该如何发布了?
后面解释这两个注解的含义
现在除了这两个POJO还不够。我们还需要建立一个META-INF的文件夹(如果存在包的话这个文件夹和POJO类的包同级),并在这个文件夹下面创建services.xml
现在需要把两个POJO类的class文件,META-INF文件夹打包成aar文件(jar文件改名即可)然后将aar包放入%tomcat_home%\webapps\axis2\WEB-INF\services目录下。
现在解释上面使用的两个注解的含义:
A .jar file will, more often than not, contain more than one .class file in it. So there
should be a way to identify the service class (or classes) in it. That is why we have
annotated the POJO class with @WebService. Provided this annotation is applied,
Axis2 will identify that class as the service implementation class and expose it as a
web service.
大意为:一般打包jar文件时jar文件中一般存在多个class文件,需要通过标识符表示哪个才是对外发布的。
在阅读《Apache Axis2 Web Services 2nd Edition》这本书的时候,在关于如果发布一个WebServices书中提到了两种方法。
方法一:POJO approach
现在我们编写一个简单的POJO类,这个类不包含在任何包下:
public class HelloWorld { public String sayHello(String name) { return "Hello " + name; } }
接下来的操作就是把这个普通的POJO发布为webServices让其他人可以远程调用。
发布过程:
Compile the Java class, which will produce the HelloWorld.class file.
Go to /webapps/axis2/WEB-INF.
Create a directory named pojo inside the WEB-INF directory.
Then copy the HelloWorld.class into the pojo directory, created in the
previous step.
Start Tomcat.
Go to http://localhost:8080/axis2/services/listServices , where
you will be able to find a service named HelloWorld listed
按照如上的步骤即可通过http://localhost:8080/axis2/services/listServices 这个URL可以看到我们刚刚发布的webServices。注意,这种方法只适合没有包的POJO方法。
通过浏览器访问该webServices:http://localhost:8080/axis2/services/HelloWorld/sayHello?name=Axis2
此时浏览器会打印:
<ns:sayHelloResponse> <return>Hello Axis2</return> </ns:sayHelloResponse>
如何对于一个存在包结构的POJO类又该如何发布了?
package book.sample import javax.jws.WebService; @WebService public class AddressService { @WebMethod public Address getAddress(String name) { Address address = new Address(); address.setStreet("Street"); address.setNumber("Number 15"); return address; } }
后面解释这两个注解的含义
package book.sample public class Address { private String street; private String number; public String getStreet() { return street; } public void setStreet(String street) { this.street = street; } public String getNumber() { return number; } public void setNumber(String number) { this.number = number; } }
现在除了这两个POJO还不够。我们还需要建立一个META-INF的文件夹(如果存在包的话这个文件夹和POJO类的包同级),并在这个文件夹下面创建services.xml
<service name="AddressService"> <description> This is my first service, which says "Address!" </description> <parameter name="ServiceClass">AddressService</parameter> <operation name="getAddress"> <messageReceiver class="org.apache.axis2.rpc.receivers. RPCMessageReceiver"/> </operation> </service>
现在需要把两个POJO类的class文件,META-INF文件夹打包成aar文件(jar文件改名即可)然后将aar包放入%tomcat_home%\webapps\axis2\WEB-INF\services目录下。
现在解释上面使用的两个注解的含义:
A .jar file will, more often than not, contain more than one .class file in it. So there
should be a way to identify the service class (or classes) in it. That is why we have
annotated the POJO class with @WebService. Provided this annotation is applied,
Axis2 will identify that class as the service implementation class and expose it as a
web service.
大意为:一般打包jar文件时jar文件中一般存在多个class文件,需要通过标识符表示哪个才是对外发布的。
相关文章推荐
- Git使用教程
- 李洪强iOS开发之断点续传1
- 二维数组的列排序
- indy httpserver 接收URL包含中文参数乱码的问题
- Logcat 显示
- OpenCV坐标系与操作像素的四种方法
- Hibernate联合主键怎样在xml中配置
- Spring——AOP的相关通知及应用
- 创建httpd启动脚本并加入启动列表开机启动
- 计算机体系结构组成及软硬件工作原理
- Spring注解
- HDU-4651-Partition
- Windows驱动开发之获取系统时间
- 专题四 Problem S
- React Native指南汇集了各类react-native学习资源、开源App和组件
- protobuf vs java
- ubuntu-64bit中数据库MySql安装
- 权限设计与总结——用户,角色,权限
- Asp.NET FormsAuthentication
- 查询方式实例演示