elicpse+maven的webservice应用

使用webservice 在一个服务中调用另外一个服务。

1、准备工作

使用elicpse的maven插件分别建立:

axis2-test

axis2-testServer

其中axis2-test中pom的依赖如下:

<dependencies>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-kernel</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-codegen</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-adb</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-local</artifactId>
<version>1.6.1</version>
</dependency>
<dependency>
<groupId>org.apache.axis2</groupId>
<artifactId>axis2-transport-http</artifactId>
<version>1.6.1</version>
</dependency>
</dependencies>


2、在aix2-test中编写服务器类并使用eclipse插件部署服务器代码。


客户端类OprationClient 调用服务类OprationServiceImpl,服务类定义了一个接口OprationService。

服务类: 

package com.hualom.axis.service;
/**
 * @deprecated(操作接口)
 * @author Administrator
 *
 */
public interface OprationService {
	/**
	 * @deprecated(查询操作)
	 * @param message
	 * @return
	 */
	public String search(String message);
	
	/**
	 * @deprecated(非查询操作)
	 * @param message
	 * @return
	 */
	public String noSearch(String message);
}


package com.hualom.axis.service.impl;

import com.hualom.axis.service.OprationService;

public class OprationServiceImpl implements OprationService {

	public String search(String message) {
		
		return message+"  search finish!";
	}

	public String noSearch(String message) {
		return message+" noSearch finish!";
	}

}

   部署的时候需要导入新版的axis2  http://axis.apache.org/axis2/java/core/download.cgi 并解压。

    在eclipse的菜单栏中选择 window-->preferences-->web service -->axis2 preferences 在axis2 runtime 下的 axis2 runtime location中指定解压目录



右击oprationServiceImpl--->webservice --->create webservice  如下:



在service implemention中出现需要部署的服务类 将服务器的运行状态设置为start service 并且设置 service runtime (web服务器) web service runtime (axis的版本)

对应的web项目。勾选publish the web service 和monitor the service  ---> next --->next直到:


点击 start server 启动刚刚部署的web项目 --->next 直到 finish 此时部署就已经完成了。


3、在axis-test中编写客户端代码并调用服务器程序

package com.hualom.axis.client;

import javax.xml.namespace.QName;

import org.apache.axis2.AxisFault;
import org.apache.axis2.addressing.EndpointReference;
import org.apache.axis2.client.Options;
import org.apache.axis2.rpc.client.RPCServiceClient;

public class OprationClient {
    /** 
     * @param args 
     * @throws AxisFault 
     */  
    public static void main(String[] args) throws AxisFault {  
        // 使用RPC方式调用WebService  
        RPCServiceClient serviceClient = new RPCServiceClient();  
        Options options = serviceClient.getOptions();  
        // 指定调用WebService的URL  
        EndpointReference targetEPR = new EndpointReference("http://localhost:8080/axis2-testServer/services/OprationServiceImpl");  
        options.setTo(targetEPR);  
        // 指定要调用的计算机器中的方法及WSDL文件的命名空间:impl.service.axis.hualom.com 服务类的包名称。  
        QName searchResult = new QName("http://impl.service.axis.hualom.com","search");
        QName noSearchResult = new QName("http://impl.service.axis.hualom.com","noSearch");
        // 设置发送到服务器的内容
        Object[] opAddEntryArgs = new Object[] { "你好 server"};  
        // 指定返回值的类型
        Class[] classes = new Class[] { String.class };
        // 调用服务器开放的接口并且返回结果   如果没有返回值可以直接调用  serviceClient.invokeRobust(opName, opAddEntryArgs)
        System.out.println(serviceClient.invokeBlocking(searchResult,opAddEntryArgs, classes)[0]);  
    }  
}

总结:

服务器访问路径默认

http://localhost:8080/axis2-testServer/services/OprationServiceImpl

实际是http://localhost:8080/axis2-testServer/services+刚才部署的服务类名称OprationServiceImpl

调用服务器的方法需要指定 命名空间:"http://impl.service.axis.hualom.com" 这个空间一般就是服务类包名称倒过来写。


注意:

如果部署服务类的时候出现问题

1、将服务器中部署的项目删除

2、可以为eclipse换一个 工作空间。

  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我会尽可能详细地回答你的问题。 首先,我们需要了解一下这几个工具的作用: - Eclipse:Java开发的集成开发环境(IDE) - Maven:Java项目管理工具,可以自动化构建、依赖管理、打包等操作 - Junit5:Java的单元测试框架,可以方便地编写和执行单元测试 - Pitest:Java的变异测试框架,可以自动生成变异体并运行测试用例,用于评估测试用例的质量。 接下来,我们按照以下步骤来进行参数化测试: 1. 在 Eclipse 中创建 Maven 项目,可以选择使用 Maven 的 Quickstart 模板来创建。 2. 在 pom.xml 文件中添加 Junit5 和 Pitest 的依赖: ```xml <dependency> <groupId>org.junit.jupiter</groupId> <artifactId>junit-jupiter-api</artifactId> <version>5.7.0</version> <scope>test</scope> </dependency> <dependency> <groupId>org.pitest</groupId> <artifactId>pitest-junit5-plugin</artifactId> <version>0.13</version> </dependency> ``` 3. 编写测试类,使用 Junit5 的 ParameterizedTest 注解来标记参数化测试方法,并使用 ValueSource 注解来指定参数值: ```java import org.junit.jupiter.api.Assertions; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; class CalculatorTest { private final Calculator calculator = new Calculator(); @ParameterizedTest @ValueSource(ints = {1, 2, 3}) void testAdd(int value) { int result = calculator.add(value, 2); Assertions.assertEquals(value + 2, result); } } ``` 4. 运行测试,可以使用 Maven 命令 `mvn test` 来执行所有测试用例,也可以使用 Eclipse 的 Junit5 运行器来执行单个测试用例。 5. 运行 Pitest,可以使用 Maven 命令 `mvn org.pitest:pitest-maven:mutationCoverage` 来运行 Pitest。Pitest 会自动生成变异体并运行测试用例,最后生成一个变异测试报告。 以上就是使用 Eclipse+Maven+Junit5+Pitest 进行参数化测试的步骤。希望对你有所帮助!

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值