@Override public String getMethod() { return wsRequest.getMethod().name(); }
@Override public Map<String, String[]> getParameterMap() { return wsRequest.getParameters() .getKeys() .stream() .collect(Collectors.toMap( identity(), k -> wsRequest.getParameters().getValues(k).toArray(new String[0]))); } }
@Override public String getPath() { return wsRequest.getPath(); }
private Request.Builder prepareOkRequestBuilder(WsRequest getRequest, HttpUrl.Builder urlBuilder) { Request.Builder okHttpRequestBuilder = new Request.Builder() .url(urlBuilder.build()) .header("Accept", getRequest.getMediaType()) .header("Accept-Charset", "UTF-8"); if (systemPassCode != null) { okHttpRequestBuilder.header("X-Sonar-Passcode", systemPassCode); } getRequest.getHeaders().getNames().forEach(name -> okHttpRequestBuilder.header(name, getRequest.getHeaders().getValue(name).get())); return okHttpRequestBuilder; }
private static OkHttpClient prepareOkHttpClient(OkHttpClient okHttpClient, WsRequest wsRequest) { if (!wsRequest.getTimeOutInMs().isPresent()) { return okHttpClient; } return okHttpClient.newBuilder() .readTimeout(wsRequest.getTimeOutInMs().getAsInt(), TimeUnit.MILLISECONDS) .build(); }
@Override public Optional<String> getHeader(String name) { return wsRequest.getHeaders().getValue(name); }
@Override public String getMediaType() { return wsRequest.getMediaType(); }
private Request.Builder prepareOkRequestBuilder(WsRequest getRequest, HttpUrl.Builder urlBuilder) { Request.Builder okHttpRequestBuilder = new Request.Builder() .url(urlBuilder.build()) .header("Accept", getRequest.getMediaType()) .header("Accept-Charset", "UTF-8"); if (systemPassCode != null) { okHttpRequestBuilder.header("X-Sonar-Passcode", systemPassCode); } getRequest.getHeaders().getNames().forEach(name -> okHttpRequestBuilder.header(name, getRequest.getHeaders().getValue(name).get())); return okHttpRequestBuilder; }
private static OkHttpClient prepareOkHttpClient(OkHttpClient okHttpClient, WsRequest wsRequest) { if (!wsRequest.getTimeOutInMs().isPresent()) { return okHttpClient; } return okHttpClient.newBuilder() .readTimeout(wsRequest.getTimeOutInMs().getAsInt(), TimeUnit.MILLISECONDS) .build(); }
@Override public Optional<String> getHeader(String name) { return wsRequest.getHeaders().getValue(name); }
@Override public String getMediaType() { return wsRequest.getMediaType(); }
/** * If an exception is not thrown, the response needs to be closed by either calling close() directly, or closing the * body content's stream/reader. * * @throws IllegalStateException if the request could not be executed due to a connectivity problem or timeout. Because networks can * fail during an exchange, it is possible that the remote server accepted the request before the failure * @throws MessageException if there was a problem with authentication or if a error message was parsed from the response. * @throws HttpException if the response code is not in range [200..300). Consider using {@link #createErrorMessage(HttpException)} to create more relevant messages for the users. */ public WsResponse call(WsRequest request) { Preconditions.checkState(!globalMode.isMediumTest(), "No WS call should be made in medium test mode"); Profiler profiler = Profiler.createIfDebug(LOG).start(); WsResponse response = target.wsConnector().call(request); profiler.stopDebug(format("%s %d %s", request.getMethod(), response.code(), response.requestUrl())); failIfUnauthorized(response); return response; }
@Override public boolean hasParam(String key) { return !wsRequest.getParameters().getValues(key).isEmpty(); }
private HttpUrl.Builder prepareUrlBuilder(WsRequest wsRequest) { String path = wsRequest.getPath(); return baseUrl .resolve(path.startsWith("/") ? path.replaceAll("^(/)+", "") : path) .newBuilder(); }
@Override public String getMethod() { return wsRequest.getMethod().name(); }
@Override public String getParam(String key) { return wsRequest.getParameters().getValue(key); }
@Override public boolean matches(@Nullable WsRequest item) { if (item == null) { return false; } return StringUtils.equals(item.getPath(), path); } }
/** * If an exception is not thrown, the response needs to be closed by either calling close() directly, or closing the * body content's stream/reader. * * @throws IllegalStateException if the request could not be executed due to a connectivity problem or timeout. Because networks can * fail during an exchange, it is possible that the remote server accepted the request before the failure * @throws MessageException if there was a problem with authentication or if a error message was parsed from the response. * @throws HttpException if the response code is not in range [200..300). Consider using {@link #createErrorMessage(HttpException)} to create more relevant messages for the users. */ public WsResponse call(WsRequest request) { Preconditions.checkState(!globalMode.isMediumTest(), "No WS call should be made in medium test mode"); Profiler profiler = Profiler.createIfDebug(LOG).start(); WsResponse response = target.wsConnector().call(request); profiler.stopDebug(format("%s %d %s", request.getMethod(), response.code(), response.requestUrl())); failIfUnauthorized(response); return response; }
@Override public List<String> getMultiParam(String key) { return wsRequest.getParameters().getValues(key); }
@Override public WsResponse call(WsRequest wsRequest) { DefaultLocalRequest localRequest = new DefaultLocalRequest(wsRequest); LocalConnector.LocalResponse localResponse = localConnector.call(localRequest); return new ByteArrayResponse(wsRequest.getPath(), localResponse); }