ssm中发布Apache CXF WebService

作用:两个异构系统,需要共享数据。--用于两个不同语言系统之间数据调度

1.  将CXF整合到项目中,加入jar包。依赖jar。

 

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

<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/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.xh</groupId>
  <artifactId>PSIM_WS_Maternity</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>war</packaging>

  <name>PSIM_WS_Maternity Maven Webapp</name>
  <!-- FIXME change it to the project's website -->
  <url>http://www.example.com</url>

  <!-- 初始化框架的版本号 -->
  <properties>
    <junit.version>4.12</junit.version>
    <spring.version>4.1.3.RELEASE</spring.version>
    <mybatis.version>3.4.6</mybatis.version>
    <mybatis.spring.version>1.3.0</mybatis.spring.version>
    <mybatis.paginator.version>1.2.15</mybatis.paginator.version>
    <mysql.version>5.1.6</mysql.version>
    <slf4j.version>1.6.4</slf4j.version>
    <jackson.version>2.4.2</jackson.version>
    <druid.version>1.0.9</druid.version>
    <httpclient.version>4.3.5</httpclient.version>
    <jstl.version>1.2</jstl.version>
    <servlet-api.version>3.1.0</servlet-api.version>
    <jsp-api.version>2.0</jsp-api.version>
    <commons-lang3.version>3.3.2</commons-lang3.version>
    <commons-io.version>1.3.2</commons-io.version>
    <commons-net.version>3.3</commons-net.version>
    <pagehelper.version>5.1.8</pagehelper.version>
    <jsqlparser.version>0.9.1</jsqlparser.version>
    <commons-fileupload.version>1.3.1</commons-fileupload.version>
    <jedis.version>2.7.2</jedis.version>
    <cxf.version>3.2.4</cxf.version>
    <fastJson.version>1.2.47</fastJson.version>
  </properties>

  <dependencies>
    <!--初始化文件读取Ini-->
    <dependency>
      <groupId>org.ini4j</groupId>
      <artifactId>ini4j</artifactId>
      <version>0.5.4</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/org.quartz-scheduler/quartz -->
    <!-- job-quartz定时任务JAR包  -->
    <dependency>
      <groupId>com.alibaba</groupId>
      <artifactId>fastjson</artifactId>
      <version>${fastJson.version}</version>
    </dependency>
    <dependency>
      <groupId>org.quartz-scheduler</groupId>
      <artifactId>quartz</artifactId>
      <version>2.3.0</version>
    </dependency>
    <dependency>
      <groupId>org.quartz-scheduler</groupId>
      <artifactId>quartz-jobs</artifactId>
      <version>2.3.0</version>
    </dependency>
    <!-- cxf开发webservice接口与调用 jar包-->
    <dependency>
      <groupId>com.fasterxml.jackson.jaxrs</groupId>
      <artifactId>jackson-jaxrs-json-provider</artifactId>
      <version>2.9.2</version>
    </dependency>

    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-core</artifactId>
      <version>3.2.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-bindings-soap</artifactId>
      <version>3.2.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-databinding-jaxb</artifactId>
      <version>3.2.4</version>
    </dependency>

    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-simple</artifactId>
      <version>3.2.4</version>
    </dependency>

    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-udp</artifactId>
      <version>3.2.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-ws-addr</artifactId>
      <version>3.2.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-wsdl</artifactId>
      <version>3.2.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-ws-policy</artifactId>
      <version>3.2.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxws</artifactId>
      <version>3.2.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
      <version>3.2.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-service-description</artifactId>
      <version>3.2.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-extension-providers</artifactId>
      <version>3.2.4</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http</artifactId>
      <version>3.2.4</version>
    </dependency>
    <dependency>
      <groupId>org.codehaus.jettison</groupId>
      <artifactId>jettison</artifactId>
      <version>1.3.8</version>
    </dependency>
    <dependency>
      <groupId>org.dom4j</groupId>
      <artifactId>dom4j</artifactId>
      <version>2.1.1</version>
    </dependency>

    <!--import javax.jws.WebService;  -->
    <dependency>
      <groupId>org.apache.geronimo.specs</groupId>
      <artifactId>geronimo-ws-metadata_2.0_spec</artifactId>
      <version>1.1.2</version>
    </dependency>

    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-lang3</artifactId>
      <version>${commons-lang3.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.commons</groupId>
      <artifactId>commons-io</artifactId>
      <version>${commons-io.version}</version>
    </dependency>
    <dependency>
      <groupId>commons-net</groupId>
      <artifactId>commons-net</artifactId>
      <version>${commons-net.version}</version>
    </dependency>
    <!-- Jackson Json处理工具包 -->
    <dependency>
      <groupId>com.fasterxml.jackson.core</groupId>
      <artifactId>jackson-databind</artifactId>
      <version>${jackson.version}</version>
    </dependency>
    <!-- httpclient -->
    <dependency>
      <groupId>org.apache.httpcomponents</groupId>
      <artifactId>httpclient</artifactId>
      <version>${httpclient.version}</version>
    </dependency>
    <!-- 单元测试 -->
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>${junit.version}</version>
      <scope>test</scope>
    </dependency>
    <!-- 日志处理 -->
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-log4j12</artifactId>
      <version>${slf4j.version}</version>
    </dependency>
    <!-- Mybatis -->
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>${mybatis.version}</version>
    </dependency>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis-spring</artifactId>
      <version>${mybatis.spring.version}</version>
    </dependency>
    <!--sqlserver-->
    <!-- https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4 -->
    <dependency>
      <groupId>com.microsoft.sqlserver</groupId>
      <artifactId>sqljdbc4</artifactId>
      <version>4.0</version>

    </dependency>


    <!-- https://mvnrepository.com/artifact/com.squareup.okhttp3/okhttp -->
    <dependency>
      <groupId>com.squareup.okhttp3</groupId>
      <artifactId>okhttp</artifactId>
      <version>3.14.2</version>
    </dependency>

    <!-- MySql -->
    <dependency>
      <groupId>mysql</groupId>
      <artifactId>mysql-connector-java</artifactId>
      <version>${mysql.version}</version>
    </dependency>
    <!-- Spring -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-aspects</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <!-- https://mvnrepository.com/artifact/com.oracle/ojdbc6 -->
    <!-- <dependency>
         <groupId>com.oracle</groupId>
         <artifactId>ojdbc6</artifactId>
         <version>12.1.0.1-atlassian-hosted</version>
     </dependency>-->
    <!-- JSP相关 -->
    <dependency>
      <groupId>jstl</groupId>
      <artifactId>jstl</artifactId>
      <version>${jstl.version}</version>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.0.1</version>
      <scope>provided</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>jsp-api</artifactId>
      <version>${jsp-api.version}</version>
      <scope>provided</scope>
    </dependency>
    <!-- 分页插件 -->
    <dependency>
      <groupId>com.github.pagehelper</groupId>
      <artifactId>pagehelper</artifactId>
      <version>${pagehelper.version}</version>
    </dependency>
    <!-- 文件上传组件 -->
    <dependency>
      <groupId>commons-fileupload</groupId>
      <artifactId>commons-fileupload</artifactId>
      <version>${commons-fileupload.version}</version>
    </dependency>
    <!-- Redis客户端 -->
    <dependency>
      <groupId>redis.clients</groupId>
      <artifactId>jedis</artifactId>
      <version>${jedis.version}</version>
    </dependency>
    <!-- SPRING JDBC -->
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-jdbc</artifactId>
      <version>${spring.version}</version>
    </dependency>
    <dependency>
      <groupId>commons-dbcp</groupId>
      <artifactId>commons-dbcp</artifactId>
      <version>1.4</version>
    </dependency>
    <dependency>
      <groupId>commons-pool</groupId>
      <artifactId>commons-pool</artifactId>
      <version>1.5.4</version>
    </dependency>
    <dependency>
      <groupId>org.mybatis</groupId>
      <artifactId>mybatis</artifactId>
      <version>3.2.5</version>
    </dependency>

    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxws</artifactId>
      <version>${cxf.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-frontend-jaxrs</artifactId>
      <version>${cxf.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-service-description</artifactId>
      <version>${cxf.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-transports-http</artifactId>
      <version>${cxf.version}</version>
    </dependency>
    <dependency>
      <groupId>org.apache.cxf</groupId>
      <artifactId>cxf-rt-rs-extension-providers</artifactId>
      <version>${cxf.version}</version>
    </dependency>

  </dependencies>

  <build>
    <finalName>PSIM_WS_Maternity</finalName>
    <resources>
      <resource>
        <directory>src/main/resources</directory>
      </resource>
      <resource>
        <directory>src/main/java</directory>
        <includes>
          <include>**/*.xml</include>
          <include>**/*.properties</include>
        </includes>
      </resource>
    </resources>
    <plugins>
      <plugin>
        <groupId>org.apache.maven.plugins</groupId>
        <artifactId>maven-compiler-plugin</artifactId>
        <version>3.5.1</version>
        <configuration>
          <source>1.8</source>
          <target>1.8</target>
        </configuration>
      </plugin>
      <plugin>
        <groupId>org.apache.tomcat.maven</groupId>
        <artifactId>tomcat7-maven-plugin</artifactId>
        <version>2.2</version>
        <configuration>
          <uriEncoding>UTF-8</uriEncoding>
          <port>8080</port>
          <path>/PSIM_WS_Maternity</path><!-- 应用的部署位置 -->
        </configuration>
      </plugin>
      <!-- generator -->
      <!--<plugin>
        <groupId>org.mybatis.generator</groupId>
        <artifactId>mybatis-generator-maven-plugin</artifactId>
        <version>1.3.2</version>
        <configuration>
          <configurationFile>
            ${basedir}/src/main/resources/generatorConfig.xml
          </configurationFile>
        </configuration>
        <executions>
          <execution>
            <id>Generate MyBatis Files</id>
            <goals>
              <goal>generate</goal>
            </goals>
            &lt;!&ndash;<phase>generate</phase>&ndash;&gt;
            &lt;!&ndash;导致本地mapper重新生成 &ndash;&gt;
            &lt;!&ndash; <phase>deploy</phase> &ndash;&gt;
            <configuration>
              &lt;!&ndash;允许移动生成的文件 &ndash;&gt;
              <verbose>true</verbose>
              &lt;!&ndash; 是否覆盖 &ndash;&gt;
              <overwrite>true</overwrite>
              &lt;!&ndash; 自动生成的配置 &ndash;&gt;
              &lt;!&ndash; <configurationFile>
                 src/main/resources/generatorConfig.xml
              </configurationFile> &ndash;&gt;
            </configuration>
          </execution>
        </executions>
        <dependencies>

          &lt;!&ndash; https://mvnrepository.com/artifact/com.microsoft.sqlserver/sqljdbc4 &ndash;&gt;
          <dependency>
            <groupId>com.microsoft.sqlserver</groupId>
            <artifactId>sqljdbc4</artifactId>
            <version>4.0</version>

          </dependency>

          <dependency>
            <groupId>org.mybatis.generator</groupId>
            <artifactId>mybatis-generator-core</artifactId>
            <version>1.3.5</version>
          </dependency>
          <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.4.6</version>
          </dependency>
        </dependencies>
      </plugin>-->
    </plugins>
  </build>
</project>

 

2.配置cxf.xml核心配置文件

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:p="http://www.springframework.org/schema/p"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:tx="http://www.springframework.org/schema/tx" xmlns:jaxws="http://cxf.apache.org/jaxws"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.1.xsd http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">

    <!-- 引入cxf的一些核心配置 -->
    <import resource="classpath:META-INF/cxf/cxf.xml" />
    <import resource="classpath:META-INF/cxf/cxf-servlet.xml"/>

    <bean id="userSoap" class="com.xh.soap.impl.UserSoapImpl"/>
    <!--<bean id="ticketSoap" class="com.xh.soap.impl.TicketSoapImpl"/>-->
    <bean id="OASoap" class="com.xh.soap.impl.OASoapImpl"/>

    <!-- implementor 指定 WebService 实现类, address 指定访问地址-->
    <jaxws:endpoint id="userSoapService" implementor="#userSoap" address="/NurseService/soap" /><!--访问地址http://localhost:8080/PSIM_WS_Maternity/services/NurseService/soap?wsdl-->
    <!--<jaxws:endpoint id="ticketSoapService" implementor="#ticketSoap" address="/TicketService/soap" ></jaxws:endpoint>-->
    <jaxws:endpoint id="oASoapService" implementor="#OASoap" address="/webservice/conference" /><!--http://localhost:8080/PSIM_WS_Maternity/services/webservice/conference?wsdl-->

    <context:component-scan base-package="com.xh"></context:component-scan>
    <bean id="propertyCongfigurer" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
        <property name="location" value="classpath:jdbc.properties"></property>
    </bean>
    <!-- 配置dbcp数据源 -->
    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="${jdbc.driver}"></property>
        <property name="url" value="${jdbc.url}"></property>
        <property name="username" value="${jdbc.username}"></property>
        <property name="password" value="${jdbc.password}"></property>
        <property name="initialSize" value="${jdbc.initialSize}"></property>
        <property name="maxActive" value="${jdbc.maxActive}"></property>
        <property name="maxIdle" value="${jdbc.maxIdle}"></property>
        <property name="minIdle" value="${jdbc.minIdle}"></property>
        <property name="maxWait" value="${jdbc.maxWait}"></property>
    </bean>
    <!-- 配置SqlSessionFactory这是mybatis工厂 -->
    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource"></property><!-- 注入数据源 -->
        <property name="mapperLocations" value="classpath:com/xh/mapper/*.xml"></property><!--自动扫描dao映射文件  -->
        <!-- <property name="typeAliasesPackage" value="com.xh.pojo"></property> --><!--类型别名  dao映射可以直接返回实体对象-->
    </bean>
    <!-- 配置扫描dao接口 -->
    <bean  class="org.mybatis.spring.mapper.MapperScannerConfigurer" lazy-init="false">
        <property name="basePackage" value="com.xh.mapper"></property><!-- 指定dao接口所在的包 -->
        <property name="sqlSessionFactoryBeanName" value="sqlSessionFactory"></property>
    </bean>
    <!-- 配置事务管理器 -->
    <bean id="transactionMamager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource"></property>
    </bean>
    <tx:annotation-driven transaction-manager="transactionMamager"/>
</beans>

3.发布WebService方法供客户的系统进行调用web.xml

<!DOCTYPE web-app PUBLIC
 "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
 "http://java.sun.com/dtd/web-app_2_3.dtd" >

<web-app>
  <display-name>Archetype Created Web Application</display-name>
  <context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>classpath:applicationContext.xml</param-value>
  </context-param>
  <!-- 加载log4j配置文件 -->
  <context-param>
    <param-name>log4jConfigLocation</param-name>
    <param-value>classpath:log4j.properties</param-value>
  </context-param>
  <filter>
    <filter-name>EncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
      <param-name>encoding</param-name>
      <param-value>utf-8</param-value>
    </init-param>
  </filter>
  <filter-mapping>
    <filter-name>EncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
  </filter-mapping>
  <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  <!-- 日志监听 -->
  <listener>
    <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class>
  </listener>
  <servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath:spring-mvc.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet>
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
  <!-- 定义一个Servlet,主要是处理WebService请求:CXF接口 -->
  <!--
  <servlet >
    <servlet-name>CXFServlet</servlet-name>
    <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>
    <load-on-startup>2</load-on-startup>
  </servlet>
  -->
  <servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
  </servlet-mapping>

  <!--
  <servlet-mapping >
    <servlet-name>CXFServlet</servlet-name>
    <url-pattern>/webservice/*</url-pattern>
  </servlet-mapping>
-->
  <!-- 欢迎页 -->
  <!--<welcome-file-list>-->
  <!--<welcome-file>admin/index.jsp</welcome-file>-->
  <!--</welcome-file-list>-->
</web-app>

4.定义接口和实现类

package com.xh.soap;

import javax.jws.WebMethod;
import javax.jws.WebParam;
import javax.jws.WebResult;
import javax.jws.WebService;

@WebService(name = "NurseService",targetNamespace = "http://NurseService.xh.com")
public interface UserSoap {

    //登录
    @WebMethod(operationName = "login",action = "http://NurseService.xh.com/login")
    @WebResult(name = "loginResult",targetNamespace = "http://NurseService.xh.com")
    public String login(
            @WebParam(name = "Staff_LoginName") String Staff_LoginName,
            @WebParam(name = "Staff_password") String Staff_password
    );

    //读取产房数据
    @WebMethod(operationName = "call_Place",action = "http://NurseService.xh.com/call_Place")
    @WebResult(name = "placeResult",targetNamespace = "http://NurseService.xh.com")
    public String call_Place();

    //读取产房中剩余的可用床数量
    @WebMethod(operationName = "find_AvailableBed",action = "http://NurseService.xh.com/find_AvailableBed")
    @WebResult(name = "findAvailableBedResult",targetNamespace = "http://NurseService.xh.com")
    public String find_AvailableBed();

    //读取床位数据
    @WebMethod(operationName = "call_Bed",action = "http://NurseService.xh.com/call_Bed")
    @WebResult(name = "bedResult",targetNamespace = "http://NurseService.xh.com")
    public String call_Bed(
            @WebParam(name = "Place_NO") String Place_NO
    );

    //新增产妇信息表数据
    @WebMethod(operationName = "add_Maternal",action = "http://NurseService.xh.com/add_Maternal")
    @WebResult(name = "maternalResult",targetNamespace = "http://NurseService.xh.com")
    public String addMaternal(
            @WebParam(name = "Puerpaer_Name") String Puerpaer_Name,
            @WebParam(name = "Puerpaer_Sex") int Puerpaer_Sex,
            @WebParam(name = "Puerpaer_Age") int Puerpaer_Age,
            @WebParam(name = "Bed_ID") int Bed_ID,
            @WebParam(name = "DisplayType_ID") int DisplayType_ID,
            @WebParam(name = "Custom_Type") String Custom_Type,
            @WebParam(name = "Custom_Broadcast") String Custom_Broadcast,
            @WebParam(name = "Puerpaer_Status") int Puerpaer_Status,
            @WebParam(name = "DisplayStatus") int DisplayStatus
    );

    //大屏显示产妇试产进度信息
    /**所需参数:
     *     无
     *
     * 返回参数:
     *      房间编号、特殊标符、床位编号、产妇姓名、产妇进度状态
     * */
    @WebMethod(operationName = "read_Display",action = "http://NurseService.xh.com/read_Display")
    @WebResult(name = "displayResult",targetNamespace = "http://NurseService.xh.com")
    public String read_Display();

    //大屏显示标题和滚动信息
    /**所需参数:
     *     无
     *
     * 返回参数:
     *      大屏显示标题、滚动信息
     * */
    @WebMethod(operationName = "disPlay_Title",action = "http://NurseService.xh.com/disPlay_Title")
    @WebResult(name = "titleResult",targetNamespace = "http://NurseService.xh.com")
    public String disPlay_Title(
            @WebParam(name = "Display_IP") String Display_IP
    );

    //对大屏显示的标题和滚动信息进行修改显示
    /**所需参数:
     *      Display_IP              设备IP
     *      Display_Title           标题
     *      Display_Scroll_Text     滚动信息
     * 返回参数:
     *      result 1 、resultInfo ''
     *
     * */
    @WebMethod(operationName = "updateDisplayTitle",action = "http://NurseService.xh.com/updateDisplayTitle")
    @WebResult(name = "upDpTitleResult",targetNamespace = "http://NurseService.xh.com")
    public String updateDisplayTitle(
            @WebParam(name = "Display_IP") String Display_IP,
            @WebParam(name = "Display_Title") String Display_Title,
            @WebParam(name = "Display_Scroll_Text") String Display_Scroll_Text
    );

    //根据Bed_ID获取相应产妇进度状态信息
    /**所需参数:
     *      Bed_ID      床位ID
     *
     * 返回参数:
     *      房间号、床位号、姓名、状态、自定义状态、自定义呼叫
     * */
    @WebMethod(operationName = "read_Maternal",action = "http://NurseService.xh.com/read_Maternal")
    @WebResult(name = "readMaterResult",targetNamespace = "http://NurseService.xh.com")
    public String read_Maternal(
            @WebParam(name = "Bed_ID") int Bed_ID
    );

    //获取所有状态进度信息
    /**
     * 所需参数:无
     * 返回参数
     *      状态id
     *      状态名字
     * */
    @WebMethod(operationName = "call_DisplayType",action = "http://NurseService.xh.com/call_DisplayType")
    @WebResult(name = "displayTypeResult",targetNamespace = "http://NurseService.xh.com")
    public String call_DisplayType();

    //修改产妇试产进度状态信息
    /**
     * 所需参数:
     *      床位Id
     *      产妇进度状态信息
     *
     * 返回参数: result  1
     * */
    @WebMethod(operationName = "updateMaternal",action = "http://NurseService.xh.com/updateMaternal")
    @WebResult(name = "upMaterResult",targetNamespace = "http://NurseService.xh.com")
    public String updateMaternal(
            @WebParam(name = "Bed_ID") int Bed_ID,
            @WebParam(name = "Display_ID") int Display_ID
    );

    //修改产妇试产自定义进度状态信息 update_Broadcast
    /**
     * 所需参数:
     *      床位Id
     *      产妇自定义进度状态信息
     *
     * 返回参数: result  1
     * */
    @WebMethod(operationName = "update_CustomType",action = "http://NurseService.xh.com/update_CustomType")
    @WebResult(name = "upCustomTypeResult",targetNamespace = "http://NurseService.xh.com")
    public String update_CustomType(
            @WebParam(name = "Bed_ID") int Bed_ID,
            @WebParam(name = "Custom_Type") String Custom_Type
    );

    //修改自定义呼叫信息
    /**
     * 所需参数:
     *      床位Id
     *      自定义呼叫内容
     *
     * 返回参数: result  1
     * */
    @WebMethod(operationName = "update_Broadcast",action = "http://NurseService.xh.com/update_Broadcast")
    @WebResult(name = "upCustomTypeResult",targetNamespace = "http://NurseService.xh.com")
    public String update_Broadcast(
            @WebParam(name = "Bed_ID") int Bed_ID,
            @WebParam(name = "Custom_Broadcast") String Custom_Broadcast
    );

    //查询
    /**
     * 所需参数:
     *      产妇姓名
     *      床位编号
     *      是否出院状态
     *
     * 返回参数:
     *      result  1
     *      resultInfo 调用成功
     *      date:
     *          产房序号,特殊标符、床位ID、床位编号、床位状态、
     *          产妇姓名、试产进度状态、自定义显示状态、自定义呼叫信息
     * */
    @WebMethod(operationName = "findMaternal",action = "http://NurseService.xh.com/findMaternal")
    @WebResult(name = "findMaternalResult",targetNamespace = "http://NurseService.xh.com")
    public String findMaternal(
            @WebParam(name = "Puerpaer_Name") String Puerpaer_Name,
            @WebParam(name = "Bed_Name") String Bed_Name,
            @WebParam(name = "Puerpaer_Status") int Puerpaer_Status
    );

    //修改产妇出院的状态及床位状态
    /**
     * 所需参数:
     *      Bed_ID              床位编号
     *      Puerpaer_Name       产妇姓名
     *
     * 返回参数:
     *      result  1/0    调用成功/调用失败
     *      resultInfo     ''
     *
     * */
    @WebMethod(operationName = "updateStatus",action = "http://NurseService.xh.com/updateStatus")
    @WebResult(name = "upStatusResult",targetNamespace = "http://NurseService.xh.com")
    public String updateStatus(
            @WebParam(name = "Bed_ID") int Bed_ID,
            @WebParam(name = "Puerpaer_Name") String Puerpaer_Name
    );

    //添加房间
    @WebMethod(operationName = "savePlace",action = "http://NurseService.xh.com/savePlace")
    @WebResult(name = "savePlaceResult",targetNamespace = "http://NurseService.xh.com")
    public String savePlace(
            @WebParam(name = "Place_NO") String Place_NO,
            @WebParam(name = "Place_Name") String Place_Name,
            @WebParam(name = "Place_Status") Integer Place_Status
    );
    //添加床位
    @WebMethod(operationName = "saveBed",action = "http://NurseService.xh.com/saveBed")
    @WebResult(name = "saveBedResult",targetNamespace = "http://NurseService.xh.com")
    public String saveBed(
            @WebParam(name = "Bed_Name") String Bed_Name,
            @WebParam(name = "Bed_Status") Integer Bed_Status,
            @WebParam(name = "Place_ID") Integer Place_ID
    );

    //安全退出登录

}

实现类

package com.xh.soap.impl;

import com.alibaba.fastjson.JSONObject;
import com.xh.mapper.PlaceDao;
import com.xh.service.PlaceService;
import com.xh.service.PuerpaerService;
import com.xh.service.UserService;
import com.xh.soap.UserSoap;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.Resource;
import javax.jws.WebService;
import java.util.LinkedHashMap;
import java.util.Map;

@WebService(name = "NurseService",targetNamespace = "http://NurseService.xh.com",endpointInterface = "com.xh.soap.UserSoap",serviceName = "NurseServiceName",portName = "NursePortName")
public class UserSoapImpl implements UserSoap {

    @Resource
    UserService userService;
    @Resource
    PlaceService placeService;
    @Resource
    PuerpaerService puerpaerService;
    @Autowired
    PlaceDao placeDao;
    //实现登录接口
    @Override
    public String login(String Staff_LoginName, String Staff_password) {
        Map<String,Object> map = new LinkedHashMap<>();
        map.put("Staff_LoginName",Staff_LoginName);
        map.put("Staff_password",Staff_password);

        Map<String,Object> loginMap = userService.login(map);

        return JSONObject.toJSONString(loginMap);
    }

    @Override
    public String call_Place() {

        return placeService.call_Place();
    }

    @Override
    public String find_AvailableBed() {

        return placeService.find_AvailableBed();
    }

    @Override
    public String call_Bed(String Place_NO) {
//        List<BedVo> bedList = ;
//        for (int i=0; i<bedList.size();i++){
//            System.out.println(bedList.get(i));
//        }
//        Map<String,Object> map = new LinkedHashMap<>();
//        map.put("resultCode","1");
//        map.put("resultInfo","服务调用成功!");
//        map.put("data",bedList);
      /*  Map<Integer,BedVo> bedMap = new HashMap<Integer, BedVo>();
        for (BedVo bedVo : bedList){
            bedMap.put(bedVo.getBed_ID(),bedVo);
        }*/

        return placeService.call_Bed(Place_NO);
    }

    @Override
    public String addMaternal(String Puerpaer_Name, int Puerpaer_Sex, int Puerpaer_Age, int Bed_ID,
                 int DisplayType_ID, String Custom_Type, String Custom_Broadcast, int Puerpaer_Status,
                 int DisplayStatus)
    {
        Map<String,Object> map = new LinkedHashMap<>();
        map.put("Puerpaer_Name",Puerpaer_Name);
        map.put("Puerpaer_Sex",Puerpaer_Sex);
        map.put("Puerpaer_Age",Puerpaer_Age);
        map.put("Bed_ID",Bed_ID);
        map.put("DisplayType_ID",DisplayType_ID);
        map.put("Custom_Type",Custom_Type);
        map.put("Custom_Broadcast",Custom_Broadcast);
        map.put("Puerpaer_Status",Puerpaer_Status);
        map.put("DisplayStatus",DisplayStatus);

        Map<String,Object> addMap = puerpaerService.addMaternal(map);

        return JSONObject.toJSONString(addMap);
    }

    @Override
    public String read_Display() {

        return puerpaerService.read_Display();
    }

    @Override
    public String read_Maternal(int Bed_ID) {
        Map<String,Object> map = new LinkedHashMap<>();
        map.put("Bed_ID",Bed_ID);

        Map<String,Object> readMaternalMap = puerpaerService.read_Maternal(map);

        return JSONObject.toJSONString(readMaternalMap);
    }

    @Override
    public String disPlay_Title(String Display_IP) {
        Map<String,Object> titleMap = puerpaerService.disPlay_Title(Display_IP);

        return JSONObject.toJSONString(titleMap);
    }

    @Override
    public String updateDisplayTitle(String Display_IP, String Display_Title, String Display_Scroll_Text) {
        Map<String,Object> map = new LinkedHashMap<>();
        map.put("Display_IP",Display_IP);
        map.put("Display_Title",Display_Title);
        map.put("Display_Scroll_Text",Display_Scroll_Text);

        return puerpaerService.updateDisplayTitle(map);
    }

    @Override
    public String call_DisplayType() {

        return userService.call_DisplayType();
    }

    @Override
    public String updateMaternal(int Bed_ID, int Display_ID) {
        Map<String,Object> map = new LinkedHashMap<>();
        map.put("Bed_ID",Bed_ID);
        map.put("Display_ID",Display_ID);

        Map<String,Object> materMap = puerpaerService.updateMaternal(map);

        return JSONObject.toJSONString(materMap);
    }

    @Override
    public String update_CustomType(int Bed_ID, String Custom_Type) {
        Map<String,Object> map = new LinkedHashMap<>();
        map.put("Bed_ID",Bed_ID);
        map.put("Custom_Type",Custom_Type);

        Map<String,Object> customTypeMap = puerpaerService.update_CustomType(map);

        return JSONObject.toJSONString(customTypeMap);
    }

    @Override
    public String update_Broadcast(int Bed_ID, String Custom_Broadcast) {
        Map<String,Object> map = new LinkedHashMap<>();
        map.put("Bed_ID",Bed_ID);
        map.put("Custom_Broadcast",Custom_Broadcast);

        Map<String,Object> broadcastMap = puerpaerService.update_Broadcast(map);

        return JSONObject.toJSONString(broadcastMap);
    }

    @Override
    public String findMaternal(String Puerpaer_Name, String Bed_Name, int Puerpaer_Status) {

        return placeService.findMaternal(Puerpaer_Name,Bed_Name,Puerpaer_Status);
    }

    @Override
    public String updateStatus(int Bed_ID, String Puerpaer_Name) {
        Map<String,Object> map = new LinkedHashMap<>();
        map.put("Bed_ID",Bed_ID);
        map.put("Puerpaer_Name",Puerpaer_Name);

        Map<String,Object> statusMap = puerpaerService.updateStatus(map);

        return JSONObject.toJSONString(statusMap);
    }

    @Override
    public String savePlace(String Place_NO, String Place_Name, Integer Place_Status) {
        Map<String,Object> map1 = new LinkedHashMap<>();
        map1.put("Place_NO",Place_NO);
        map1.put("Place_Name",Place_Name);
        map1.put("Place_Status",Place_Status);
        map1.put("result","0");
        map1.put("resultInfo","服务调用失败!");
        try{
            int i = placeDao.savePlace(map1);
            map1.put("result","1");
            map1.put("resultInfo","服务调用成功!");
            map1.put("data",i);
        }catch (Exception e){
            e.printStackTrace();
            map1.put("resultInfo","服务调用异常!\t"+e.getMessage());
        }

        return JSONObject.toJSONString(map1);
    }

    @Override
    public String saveBed(String Bed_Name, Integer Bed_Status, Integer Place_ID) {
        Map<String,Object> map = new LinkedHashMap<>();
        map.put("Bed_Name",Bed_Name);
        map.put("Bed_Status",Bed_Status);
        map.put("Place_ID",Place_ID);
        map.put("result","0");
        map.put("resultInfo","服务调用失败!");
        try{
            int i = placeDao.saveBed(map);
            map.put("result","1");
            map.put("resultInfo","服务调用成功!");
            map.put("data",i);
        }catch (Exception e){
            e.printStackTrace();
            map.put("resultInfo","服务调用异常!\t"+e.getMessage());
        }

        return JSONObject.toJSONString(map);
    }

}

5.@WebService注解详细说明

 

/**
 *  @WebService注解
 *
 * Web Service 元数据注释(JSR 181)
 *
 *
 * @WebService
 *
 *    1、serviceName: 对外发布的服务名,指定 Web Service 的服务名称:wsdl:service。缺省值为 Java 类的简单名称 + Service。(字符串)
 *
 *    2、endpointInterface: 服务接口全路径, 指定做SEI(Service EndPoint Interface)服务端点接口
 *
 *    3、name:此属性的值包含XML Web Service的名称。在默认情况下,该值是实现XML Web Service的类的名称,wsdl:portType 的名称。缺省值为 Java 类或接口的非限定名称。(字符串
 *
 *    4、portName:  wsdl:portName。缺省值为 WebService.name+Port。
 *
 *    5、targetNamespace:指定你想要的名称空间,认是使用接口实现类的包名的反缀
 *
 *    6、wsdlLocation:指定用于定义 Web Service 的 WSDL 文档的 Web 地址。Web 地址可以是相对路径或绝对路径。(字符串)
 *
 *    注意:实现类上可以不添加Webservice注解
 *
 * 
 * @WebMethod
 *
 *    注释表示作为一项 Web Service 操作的方法,将此注释应用于客户机或服务器服务端点接口(SEI)上的方法,或者应用于 JavaBeans 端点的服务器端点实现类。
 *
 *    要点:
 *
 *        仅支持在使用 @WebService 注释来注释的类上使用 @WebMethod 注释
 *
 *
 *
 *  1、operationName:指定与此方法相匹配的wsdl:operation 的名称。缺省值为 Java 方法的名称。(字符串)
 *
 *  2、action:定义此操作的行为。对于 SOAP 绑定,此值将确定 SOAPAction 头的值。缺省值为 Java 方法的名称。(字符串)
 *
 *  3、exclude:指定是否从 Web Service 中排除某一方法。缺省值为 false。(布尔值)
 *
 *
 *
 *
 * @Oneway
 *
 * 注释将一个方法表示为只有输入消息而没有输出消息的 Web Service 单向操作。
 *
 * 将此注释应用于客户机或服务器服务端点接口(SEI)上的方法,或者应用于 JavaBeans 端点的服务器端点实现类
 *
 *
 *
 * @WebParam
 *
 * 注释用于定制从单个参数至 Web Service 消息部件和 XML 元素的映射。
 *
 * 将此注释应用于客户机或服务器服务端点接口(SEI)上的方法,或者应用于 JavaBeans 端点的服务器端点实现类。
 *
 * 1、name :参数的名称。如果操作是远程过程调用(RPC)类型并且未指定partName 属性,那么这是用于表示参数的 wsdl:part 属性的名称。
 *
 * 如果操作是文档类型或者参数映射至某个头,那么 -name 是用于表示该参数的 XML 元素的局部名称。如果操作是文档类型、
 *
 * 参数类型为 BARE 并且方式为 OUT 或 INOUT,那么必须指定此属性。(字符串)
 *
 * 2、partName:定义用于表示此参数的 wsdl:part属性的名称。仅当操作类型为 RPC 或者操作是文档类型并且参数类型为BARE 时才使用此参数。(字符串)
 *
 * 3、targetNamespace:指定参数的 XML 元素的 XML 名称空间。当属性映射至 XML 元素时,仅应用于文档绑定。缺省值为 Web Service 的 targetNamespace。(字符串)
 *
 * 4、mode:此值表示此方法的参数流的方向。有效值为 IN、INOUT 和 OUT。(字符串)
 *
 * 5、header:指定参数是在消息头还是消息体中。缺省值为 false。(布尔值)
 *
 *
 *
 *
 *
 * @WebResult
 *
 *    注释用于定制从返回值至 WSDL 部件或 XML 元素的映射。将此注释应用于客户机或服务器服务端点接口(SEI)上的方法,或者应用于 JavaBeans 端点的服务器端点实现类。
 *
 *
 *
 * 1、name:当返回值列示在 WSDL 文件中并且在连接上的消息中找到该返回值时,指定该返回值的名称。对于 RPC 绑定,这是用于表示返回值的 wsdl:part属性的名称。对于文档绑定,-name参数是用于表示返回值的 XML 元素的局部名。对于 RPC 和 DOCUMENT/WRAPPED 绑定,缺省值为 return。对于 DOCUMENT/BARE 绑定,缺省值为方法名 + Response。(字符串)
 *
 * 2、targetNamespace:指定返回值的 XML 名称空间。仅当操作类型为 RPC 或者操作是文档类型并且参数类型为 BARE 时才使用此参数。(字符串)
 *
 * 3、header:指定头中是否附带结果。缺省值为false。(布尔值)
 *
 * 4、partName:指定 RPC 或 DOCUMENT/BARE 操作的结果的部件名称。缺省值为@WebResult.name。(字符串)
 *
 *
 *
 * @HandlerChain
 *
 *    注释用于使 Web Service 与外部定义的处理程序链相关联。只能通过对 SEI 或实现类使用 @HandlerChain 注释来配置服务器端的处理程序。
 *
 * 但是可以使用多种方法来配置客户端的处理程序。可以通过对生成的服务类或者 SEI 使用 @HandlerChain 注释来配置客户端的处理程序。此外,可以按程序在服务上注册您自己的 HandlerResolver 接口实现,或者按程序在绑定对象上设置处理程序链。
 *
 *
 *
 *  1、file:指定处理程序链文件所在的位置。文件位置可以是采用外部格式的绝对 java.net.URL,也可以是类文件中的相对路径。(字符串)
 *
 *  2、name:指定配置文件中处理程序链的名称。
 * **/

 

 

 

6.postman调用测试

http://192.168.0.15:8080/services/USService/soap

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns:userLogin xmlns:ns= "http://USService.xh.com">
         <WS_ID>1</WS_ID>
            <Staff_Code >3422</Staff_Code>
            <Staff_Pass>111111</Staff_Pass>
        </ns:userLogin>
    </soap:Body>
</soap:Envelope>

获取产房信息
http://localhost:8080/PSIM_WS_Maternity/services/NurseService/soap

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns:call_Place xmlns:ns= "http://NurseService.xh.com">

        </ns:call_Place>
    </soap:Body>
</soap:Envelope>

<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Body>
        <ns2:call_PlaceResponse xmlns:ns2="http://NurseService.xh.com">
            <ns2:placeResult>{"result":"1","resultInfo":"服务调用成功!","data":[{"available_bed_Count":3,"place_Flag":"3A","place_NO":"3A1号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":3,"place_Flag":"3A","place_NO":"3A2号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":3,"place_Flag":"3A","place_NO":"3A3号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":3,"place_Flag":"3A","place_NO":"3A4号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":3,"place_Flag":"3A","place_NO":"3A5号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":3,"place_Flag":"3A","place_NO":"3A6号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":4,"place_Flag":"3A","place_NO":"3A7号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":4,"place_Flag":"3A","place_NO":"3A8号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":4,"place_Flag":"3A","place_NO":"3A9号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":3,"place_Flag":"3B","place_NO":"3B1号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":3,"place_Flag":"3B","place_NO":"3B2号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":3,"place_Flag":"3B","place_NO":"3B3号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":3,"place_Flag":"3B","place_NO":"3B4号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":3,"place_Flag":"3B","place_NO":"3B5号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":4,"place_Flag":"3B","place_NO":"3B6号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":4,"place_Flag":"3B","place_NO":"3B7号","place_Name":"1号楼3层","place_Status":1,"place_Type":"1"},{"available_bed_Count":2,"place_Flag":"3A","place_NO":"3B8号","place_Name":"1号楼3层","place_Status":1,"place_Type":"1"},{"available_bed_Count":2,"place_Flag":"3A","place_NO":"3B9号","place_Name":"1号楼3层","place_Status":1,"place_Type":"1"},{"available_bed_Count":4,"place_Flag":"3A","place_NO":"3A10号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":4,"place_Flag":"3A","place_NO":"3A11号","place_Name":"1号楼3层","place_Note":"","place_Status":1,"place_Type":"1"},{"available_bed_Count":2,"place_Flag":"3A","place_NO":"3B10号","place_Name":"1号楼3层","place_Status":1,"place_Type":"1"},{"available_bed_Count":1,"place_Flag":"3A","place_NO":"3B11号","place_Name":"1号楼3层","place_Status":1,"place_Type":"1"}]}</ns2:placeResult>
        </ns2:call_PlaceResponse>
    </soap:Body>
</soap:Envelope>

 

posted @ 2021-04-08 14:43  当当小丸子  阅读(177)  评论(0编辑  收藏  举报