小编mad*_*aka的帖子

如何配置wiremock在达到先前的请求计数后发送不同的响应(相同的url和请求)?

是否可以将wiremock配置为在特定数量的先前响应之后对同一URL和同一请求发送不同的响应?

For example: 
1st request -> 503 response
2nd request -> 503 response
3rd request -> 503 response
4th request -> 200 response
Run Code Online (Sandbox Code Playgroud)

这将模拟启动期间不可用的服务。当它启动并运行时,它会响应 200 状态。

wiremock

9
推荐指数
1
解决办法
6122
查看次数

如何在 Microprofile REST 客户端动态添加 HTTP 标头?

我正在开发使用 microprofile Rest 客户端的应用程序。该 REST 客户端应发送带有各种 http 标头的 REST 请求。某些标头名称会动态更改。我的微配置文件休息客户端应该是通用的,但我没有找到如何实现这种行为。根据文档,您需要通过注释指定实现中的所有标头名称,但这不是通用的。有什么方法可以“破解”它并以编程方式添加 HTTP 标头吗?

提前致谢

 GenericRestClient genericRestClient = null;
 Map<String, Object> appConfig = context.appConfigs();
 String baseUrl = (String) appConfig.get("restClient.baseUrl");
 path = (String) appConfig.get("restClient.path");
 try {
     genericRestClient = RestClientBuilder.newBuilder()
                .baseUri(new URI(baseUrl)).build(GenericRestClient.class);
 }catch(URISyntaxException e){
      logger.error("",e);
      throw e;
 }

Response response = genericRestClient.sendMessage(path, value);
logger.info("Status: "+response.getStatus());
logger.info("Response body: "+response.getEntity().toString());
Run Code Online (Sandbox Code Playgroud)

通用休息客户端代码:

@RegisterRestClient
public interface GenericRestClient {
    @POST
    @Path("{path}")
    @Produces("application/json")
    @Consumes("application/json")
    public Response sendMessage(<here should go any map of custom headers>, @PathParam("path") String pathParam, String jsonBody);
}
Run Code Online (Sandbox Code Playgroud)

java rest-client microprofile

6
推荐指数
1
解决办法
5664
查看次数

标签 统计

java ×1

microprofile ×1

rest-client ×1

wiremock ×1