您的位置:首页 > 编程语言 > Java开发

webservice之axis2服务端搭建(maven方式创建web项目)

2017-07-31 09:49 826 查看
1.搭建环境

   (1) 操作系统 : windows10

   (2) jdk : 1.7

    (3)IDE:myeclipse10

    (4) 服务器:tomcat7

2. axis2服务端搭建步骤

   (1) 配置maven配置文件pom.xml

       <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.dh</groupId>

  <artifactId>TestAxis2Service</artifactId>

  <packaging>war</packaging>

  <version>0.0.1-SNAPSHOT</version>

  <name>TestAxis2Service</name>

  <url>http://maven.apache.org</url>

  

  <properties>

    

    <!-- <axis2-java2wsdl.version>1.6.2</axis2-java2wsdl.version> -->

    <axis2.version>1.3</axis2.version>

    <commons-logging.version>1.1.1</commons-logging.version>

    <commons-codec.version>1.10</commons-codec.version>

    <commons-httpclient.version>3.1</commons-httpclient.version>

    <wsdl4j.version>1.6.2</wsdl4j.version>

    <XmlSchema.version>1.4.5</XmlSchema.version>

    <axiom.version>1.2.5</axiom.version>

    <httpcore.version>4.4.4</httpcore.version>

    <neethi.version>2.0.4</neethi.version>

    <annogen.version>0.1.0</annogen.version>

    <backport-util-concurrent.version>3.0</backport-util-concurrent.version>

    

  </properties>

  

  <dependencies>

  

  <!-- https://mvnrepository.com/artifact/backport-util-concurrent/backport-util-concurrent -->
<dependency>
   <groupId>backport-util-concurrent</groupId>
   <artifactId>backport-util-concurrent</artifactId>
   <version>${backport-util-concurrent.version}</version>
</dependency>

  
<!-- https://mvnrepository.com/artifact/annogen/annogen -->
<dependency>
   <groupId>annogen</groupId>
   <artifactId>annogen</artifactId>
   <version>${annogen.version}</version>
</dependency>
 
<!-- https://mvnrepository.com/artifact/org.apache.neethi/neethi -->
<dependency>
   <groupId>org.apache.neethi</groupId>
   <artifactId>neethi</artifactId>
   <version>${neethi.version}</version>
</dependency>

  
<!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpcore -->
<dependency>
   <groupId>org.apache.httpcomponents</groupId>
   <artifactId>httpcore</artifactId>
   <version>${httpcore.version}</version>
</dependency>

  
<!-- https://mvnrepository.com/artifact/org.apache.ws.commons.axiom/axiom -->
<dependency>
   <groupId>org.apache.ws.commons.axiom</groupId>
   <artifactId>axiom</artifactId>
   <version>${axiom.version}</version>
</dependency>

<!-- https://mvnrepository.com/artifact/org.apache.ws.commons.schema/XmlSchema -->
<dependency>
   <groupId>org.apache.ws.commons.schema</groupId>
   <artifactId>XmlSchema</artifactId>
   <version>${XmlSchema.version}</version>
</dependency>

  
<!-- https://mvnrepository.com/artifact/wsdl4j/wsdl4j -->
<dependency>
   <groupId>wsdl4j</groupId>
   <artifactId>wsdl4j</artifactId>
   <version>${wsdl4j.version}</version>
</dependency>

  
<!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
<dependency>
   <groupId>commons-httpclient</groupId>
   <artifactId>commons-httpclient</artifactId>
   <version>${commons-httpclient.version}</version>
</dependency>

  
<!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
<dependency>
   <groupId>commons-codec</groupId>
   <artifactId>commons-codec</artifactId>
   <version>${commons-codec.version}</version>
</dependency>
 

  
<!-- https://mvnrepository.com/artifact/commons-logging/commons-logging -->
<dependency>
   <groupId>commons-logging</groupId>
   <artifactId>commons-logging</artifactId>
   <version>${commons-logging.version}</version>
</dependency>

  
<!-- https://mvnrepository.com/artifact/org.apache.axis2/axis2 -->
<dependency>
   <groupId>org.apache.axis2</groupId>
   <artifactId>axis2</artifactId>
   <version>${axis2.version}</version>
</dependency>

    

  </dependencies>

  <build>

    <finalName>TestAxis2Service</finalName>

  </build>

</project>

(2) web.xml配置文件

<?xml version="1.0" encoding="UTF-8"?>

<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
<display-name>testWebservice</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<servlet>
<serv
add3
let-name>AxisServlet</servlet-name>
<servlet-class>org.apache.axis2.transport.http.AxisServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>AxisServlet</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>

</web-app>

(3) 编写接口

在 src/main/java目录下创建目录:com.test.axis2(可自定义),在自定义的包下创建接口:IHelloService 及实现类:HelloServiceImpl

A. IHelloService.java

package com.test.axis2.service;

public interface IHelloService {

void hello(String name);

}

B. HelloServiceImpl.java

package com.test.axis2.service.impl;

import com.test.axis2.service.IHelloService;

public class HelloServiceImpl implements IHelloService {

@Override
public void hello(String name) {
System.out.println("----axis2----hello ---" + name);
}

}

(4) 接口配置文件services.xml

在 WEB-INF 路径下创建  /services/selfdefine/META-INF/services.xml 配置文件,其中 “selfdefine” 为自定义文件夹名

services.xml配置文件:

<?xml version="1.0" encoding="UTF-8"?>

<service name="hello" targetNamespace="http://chnsys.com.cn/rcs_ws/">

    <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>

    <description>

        练习WebService服务

    </description>

    <parameter name="ServiceClass">com.test.axis2.service.impl.HelloServiceImpl</parameter>

    

</service>

(5) 发布到tomcat服务器,访问路径:http://192.168.1.133:8080/TestAxis2Service/services/hello?wsdl ,即可查看接口信息
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  java webservice axis2