soupUI导出webservice服务端

来源:互联网 发布:linux 聊天工具 编辑:程序博客网 时间:2024/05/18 03:38

一、背景介绍

1、有些医院在某些接口已经实现了和第三方的对接,为了节约成本,他要求后续对接的项目都需要按照之前第三方提供的webservice标准来实现。

2、一般企业源码是不给看的。

二、问题分析

1、如上所述,需要根据对方提供的wsdl文件或webservice路径来构造代码,然后运行代码提供符合他们要求的wsdl标准实现(即webservice)。

2、本次介绍的实现方式主要是通过soupUI直接导出java源码。

3、导出时需要第三方的jar包支持,这个可以在我的资源中下载。这个需要在环境变量中配置路径。


 

4soapUI解析的路径即可以是webservice的路径也可以是路径保下来的wsdl结尾的文件。

三、具体实现

 1. 在官网下载 apache-cxf-2.7.11完成后,配置环境变量(和java 配置环境变量一样)

       新建环境变量CXF_HOME =  你的路径/apache-cxf-2.7.11

       2. Path后面添加 %CXF_HOME%/bin ,保存退出


       3. cmd 一下看是否有此界面,如果有则成功了


       4. 启动 soapui-4.5.2\bin\soapui.bat ,新建 New soapUI project


5. 点ok 后,生成如下图,然后选中项目选择apache cxf 


6. 点击tools,选中cxf路径,ok后,在右边矿 选择输出文件路径,填写包路径,勾选 生成 generates client ,generates server, generatesimplement, 点击generates 


 


7. 这就完成了。其实soapUI也只是用apache-cxf 命令生成。也可以用apache-cxf bin 下生成目录.

 


 

8. 引入jar 包,我这里使用的是 maven 

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

  <dependencies>

    <dependency>

   <groupId>org.apache.cxf</groupId>

   <artifactId>cxf-api</artifactId>

   <version>2.7.11</version>

  </dependency>

  <dependency>

   <groupId>org.apache.cxf</groupId>

   <artifactId>cxf-rt-frontend-jaxws</artifactId>

   <version>2.7.11</version>

  </dependency>

  <dependency>

   <groupId>org.apache.cxf</groupId>

   <artifactId>cxf-rt-bindings-soap</artifactId>

   <version>2.7.11</version>

  </dependency>

  <dependency>

   <groupId>org.apache.cxf</groupId>

   <artifactId>cxf-rt-transports-http</artifactId>

   <version>2.7.11</version>

  </dependency>

  <dependency>

   <groupId>org.apache.cxf</groupId>

   <artifactId>cxf-rt-ws-security</artifactId>

   <version>2.7.11</version>

  </dependency>

 

9. 复制到项目后。新建文件名applicationContext-cxf.xml , 

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

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

<beans xmlns="http://www.springframework.org/schema/beans"  

    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"   

    xmlns:jaxws="http://cxf.apache.org/jaxws"   

    xmlns:context="http://www.springframework.org/schema/context"  

    xsi:schemaLocation="  

        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd  

        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd   

        http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd">  

    <import resource="classpath:META-INF/cxf/cxf.xml" />

    <import resource="classpath:META-INF/cxf/cxf-servlet.xml" />

    <jaxws:endpoint 

      id="sptsmstubws" 

      implementor="com.ishua.tsmsp.service.SptsmstubwsImpl" 

      address="/sptsmstubws" />

</beans>

 

10. 与spring的applicationContext.xml 文件一个目录, 再在applicationContext.xml 里面引用

?

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

<?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:context="http://www.springframework.org/schema/context"

        xmlns:aop="http://www.springframework.org/schema/aop"

        xmlns:tx="http://www.springframework.org/schema/tx"

        xsi:schemaLocation="

        http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd

        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd

        http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd

        http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd

        "

        >

         

    <import resource="applicationContext-cxf.xml"/>

 

11. 在工程里配置web.xml 

?

1

2

3

4

5

6

7

8

9

<!--cxf webservice -->

    <servlet>

      <servlet-name>CXFServlet</servlet-name>

      <servlet-class>org.apache.cxf.transport.servlet.CXFServlet</servlet-class>

    </servlet>

    <servlet-mapping>

      <servlet-name>CXFServlet</servlet-name>

      <url-pattern>/services/*</url-pattern>

    </servlet-mapping>

 

完成上面步骤之前首先你的ssh工程得跑的起来。最少得有spring 支持。我使用的是 spring mvc + mybatis 

按上面来不会有错误.在浏览器输入 http://localhost:8080/tsmweb/services/sptsmstubws?wsdl

路径名称 servlet urlpattern  + applicationContext-cxf.xmladdress

显示如下。成功


 

 

 

四、运行所需要的jar

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

  <dependencies>

    <dependency>

   <groupId>org.apache.cxf</groupId>

   <artifactId>cxf-api</artifactId>

   <version>2.7.11</version>

  </dependency>

  <dependency>

   <groupId>org.apache.cxf</groupId>

   <artifactId>cxf-rt-frontend-jaxws</artifactId>

   <version>2.7.11</version>

  </dependency>

  <dependency>

   <groupId>org.apache.cxf</groupId>

   <artifactId>cxf-rt-bindings-soap</artifactId>

   <version>2.7.11</version>

  </dependency>

  <dependency>

   <groupId>org.apache.cxf</groupId>

   <artifactId>cxf-rt-transports-http</artifactId>

   <version>2.7.11</version>

  </dependency>

  <dependency>

   <groupId>org.apache.cxf</groupId>

   <artifactId>cxf-rt-ws-security</artifactId>

   <version>2.7.11</version>

  </dependency>

 


1 0
原创粉丝点击