Java Code Examples for org.springframework.web.reactive.function.client.WebClientResponseException

The following examples show how to use org.springframework.web.reactive.function.client.WebClientResponseException. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
private Throwable handleException(Throwable ex) {

        if (!(ex instanceof WebClientResponseException)) {
            LOG.warn("Got a unexpected error: {}, will rethrow it", ex.toString());
            return ex;
        }

        WebClientResponseException wcre = (WebClientResponseException)ex;

        switch (wcre.getStatusCode()) {

        case NOT_FOUND:
            return new NotFoundException(getErrorMessage(wcre));

        case UNPROCESSABLE_ENTITY :
            return new InvalidInputException(getErrorMessage(wcre));

        default:
            LOG.warn("Got a unexpected HTTP error: {}, will rethrow it", wcre.getStatusCode());
            LOG.warn("Error body: {}", wcre.getResponseBodyAsString());
            return ex;
        }
    }
 
Example 2
private Throwable handleException(Throwable ex) {

        if (!(ex instanceof WebClientResponseException)) {
            LOG.warn("Got a unexpected error: {}, will rethrow it", ex.toString());
            return ex;
        }

        WebClientResponseException wcre = (WebClientResponseException)ex;

        switch (wcre.getStatusCode()) {

        case NOT_FOUND:
            return new NotFoundException(getErrorMessage(wcre));

        case UNPROCESSABLE_ENTITY :
            return new InvalidInputException(getErrorMessage(wcre));

        default:
            LOG.warn("Got a unexpected HTTP error: {}, will rethrow it", wcre.getStatusCode());
            LOG.warn("Error body: {}", wcre.getResponseBodyAsString());
            return ex;
        }
    }
 
Example 3
private Throwable handleException(Throwable ex) {

        if (!(ex instanceof WebClientResponseException)) {
            LOG.warn("Got a unexpected error: {}, will rethrow it", ex.toString());
            return ex;
        }

        WebClientResponseException wcre = (WebClientResponseException)ex;

        switch (wcre.getStatusCode()) {

        case NOT_FOUND:
            return new NotFoundException(getErrorMessage(wcre));

        case UNPROCESSABLE_ENTITY :
            return new InvalidInputException(getErrorMessage(wcre));

        default:
            LOG.warn("Got a unexpected HTTP error: {}, will rethrow it", wcre.getStatusCode());
            LOG.warn("Error body: {}", wcre.getResponseBodyAsString());
            return ex;
        }
    }
 
Example 4
private Throwable handleException(Throwable ex) {

        if (!(ex instanceof WebClientResponseException)) {
            LOG.warn("Got a unexpected error: {}, will rethrow it", ex.toString());
            return ex;
        }

        WebClientResponseException wcre = (WebClientResponseException)ex;

        switch (wcre.getStatusCode()) {

        case NOT_FOUND:
            return new NotFoundException(getErrorMessage(wcre));

        case UNPROCESSABLE_ENTITY :
            return new InvalidInputException(getErrorMessage(wcre));

        default:
            LOG.warn("Got a unexpected HTTP error: {}, will rethrow it", wcre.getStatusCode());
            LOG.warn("Error body: {}", wcre.getResponseBodyAsString());
            return ex;
        }
    }
 
Example 5
private Throwable handleException(Throwable ex) {

        if (!(ex instanceof WebClientResponseException)) {
            LOG.warn("Got a unexpected error: {}, will rethrow it", ex.toString());
            return ex;
        }

        WebClientResponseException wcre = (WebClientResponseException)ex;

        switch (wcre.getStatusCode()) {

        case NOT_FOUND:
            return new NotFoundException(getErrorMessage(wcre));

        case UNPROCESSABLE_ENTITY :
            return new InvalidInputException(getErrorMessage(wcre));

        default:
            LOG.warn("Got a unexpected HTTP error: {}, will rethrow it", wcre.getStatusCode());
            LOG.warn("Error body: {}", wcre.getResponseBodyAsString());
            return ex;
        }
    }
 
Example 6
private Throwable handleException(Throwable ex) {

        if (!(ex instanceof WebClientResponseException)) {
            LOG.warn("Got a unexpected error: {}, will rethrow it", ex.toString());
            return ex;
        }

        WebClientResponseException wcre = (WebClientResponseException)ex;

        switch (wcre.getStatusCode()) {

        case NOT_FOUND:
            return new NotFoundException(getErrorMessage(wcre));

        case UNPROCESSABLE_ENTITY :
            return new InvalidInputException(getErrorMessage(wcre));

        default:
            LOG.warn("Got a unexpected HTTP error: {}, will rethrow it", wcre.getStatusCode());
            LOG.warn("Error body: {}", wcre.getResponseBodyAsString());
            return ex;
        }
    }
 
Example 7
private Throwable handleException(Throwable ex) {

        if (!(ex instanceof WebClientResponseException)) {
            LOG.warn("Got a unexpected error: {}, will rethrow it", ex.toString());
            return ex;
        }

        WebClientResponseException wcre = (WebClientResponseException)ex;

        switch (wcre.getStatusCode()) {

        case NOT_FOUND:
            return new NotFoundException(getErrorMessage(wcre));

        case UNPROCESSABLE_ENTITY :
            return new InvalidInputException(getErrorMessage(wcre));

        default:
            LOG.warn("Got a unexpected HTTP error: {}, will rethrow it", wcre.getStatusCode());
            LOG.warn("Error body: {}", wcre.getResponseBodyAsString());
            return ex;
        }
    }
 
Example 8
Source Project: spring-cloud-sleuth   Source File: GH1102Tests.java    License: Apache License 2.0 6 votes vote down vote up
@Test
public void should_store_retries_as_separate_spans() throws Exception {
	ScopedSpan foo = this.tracer.startScopedSpan("foo");
	try {
		this.webClient.get().uri("http://localhost:" + this.port + "/test").retrieve()
				.bodyToMono(String.class).retry(1).block();
		BDDAssertions.fail("should throw exception");
	}
	catch (WebClientResponseException ex) {

	}
	finally {
		foo.finish();
	}

	// Default inject format for client spans is B3 multi
	BDDAssertions.then(this.testRetry.getHttpHeaders().get("x-b3-traceid"))
			.hasSize(1);
}
 
Example 9
private Throwable handleException(Throwable ex) {

        if (!(ex instanceof WebClientResponseException)) {
            LOG.warn("Got a unexpected error: {}, will rethrow it", ex.toString());
            return ex;
        }

        WebClientResponseException wcre = (WebClientResponseException)ex;

        switch (wcre.getStatusCode()) {

        case NOT_FOUND:
            return new NotFoundException(getErrorMessage(wcre));

        case UNPROCESSABLE_ENTITY :
            return new InvalidInputException(getErrorMessage(wcre));

        default:
            LOG.warn("Got a unexpected HTTP error: {}, will rethrow it", wcre.getStatusCode());
            LOG.warn("Error body: {}", wcre.getResponseBodyAsString());
            return ex;
        }
    }
 
Example 10
private Throwable handleException(Throwable ex) {

        if (!(ex instanceof WebClientResponseException)) {
            LOG.warn("Got a unexpected error: {}, will rethrow it", ex.toString());
            return ex;
        }

        WebClientResponseException wcre = (WebClientResponseException)ex;

        switch (wcre.getStatusCode()) {

        case NOT_FOUND:
            return new NotFoundException(getErrorMessage(wcre));

        case UNPROCESSABLE_ENTITY :
            return new InvalidInputException(getErrorMessage(wcre));

        default:
            LOG.warn("Got a unexpected HTTP error: {}, will rethrow it", wcre.getStatusCode());
            LOG.warn("Error body: {}", wcre.getResponseBodyAsString());
            return ex;
        }
    }
 
Example 11
private Throwable handleException(Throwable ex) {

        if (!(ex instanceof WebClientResponseException)) {
            LOG.warn("Got a unexpected error: {}, will rethrow it", ex.toString());
            return ex;
        }

        WebClientResponseException wcre = (WebClientResponseException)ex;

        switch (wcre.getStatusCode()) {

        case NOT_FOUND:
            return new NotFoundException(getErrorMessage(wcre));

        case UNPROCESSABLE_ENTITY :
            return new InvalidInputException(getErrorMessage(wcre));

        default:
            LOG.warn("Got a unexpected HTTP error: {}, will rethrow it", wcre.getStatusCode());
            LOG.warn("Error body: {}", wcre.getResponseBodyAsString());
            return ex;
        }
    }
 
Example 12
/**
 * Revoke a {@link VaultToken}.
 * @param token the token to revoke, must not be {@literal null}.
 */
protected Mono<Void> revoke(VaultToken token) {

	return this.webClient.post().uri("auth/token/revoke-self").headers(httpHeaders -> {
		httpHeaders.addAll(VaultHttpHeaders.from(token));
	}).retrieve().bodyToMono(String.class)
			.doOnSubscribe(ignore -> dispatch(new BeforeLoginTokenRevocationEvent(token)))
			.doOnNext(ignore -> dispatch(new AfterLoginTokenRevocationEvent(token)))
			.onErrorResume(WebClientResponseException.class, e -> {

				this.logger.warn(format("Could not revoke token", e));
				dispatch(new LoginTokenRevocationFailedEvent(token, e));

				return Mono.empty();
			}).onErrorResume(Exception.class, e -> {

				this.logger.warn("Could not revoke token", e);
				dispatch(new LoginTokenRevocationFailedEvent(token, e));

				return Mono.empty();
			}).then();
}
 
Example 13
private Throwable handleException(Throwable ex) {

        if (!(ex instanceof WebClientResponseException)) {
            LOG.warn("Got a unexpected error: {}, will rethrow it", ex.toString());
            return ex;
        }

        WebClientResponseException wcre = (WebClientResponseException)ex;

        switch (wcre.getStatusCode()) {

        case NOT_FOUND:
            return new NotFoundException(getErrorMessage(wcre));

        case UNPROCESSABLE_ENTITY :
            return new InvalidInputException(getErrorMessage(wcre));

        default:
            LOG.warn("Got a unexpected HTTP error: {}, will rethrow it", wcre.getStatusCode());
            LOG.warn("Error body: {}", wcre.getResponseBodyAsString());
            return ex;
        }
    }
 
Example 14
Source Project: openapi-generator   Source File: StoreApi.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Returns pet inventories by status
 * Returns a map of status codes to quantities
 * <p><b>200</b> - successful operation
 * @return Map&lt;String, Integer&gt;
 * @throws WebClientResponseException if an error occurs while attempting to invoke the API
 */
public Mono<Map<String, Integer>> getInventory() throws WebClientResponseException {
    Object postBody = null;
    // create path and map variables
    final Map<String, Object> pathParams = new HashMap<String, Object>();

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

    final String[] localVarAccepts = { 
        "application/json"
    };
    final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    final String[] localVarContentTypes = { };
    final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);

    String[] localVarAuthNames = new String[] { "api_key" };

    ParameterizedTypeReference<Map<String, Integer>> localVarReturnType = new ParameterizedTypeReference<Map<String, Integer>>() {};
    return apiClient.invokeAPI("/store/inventory", HttpMethod.GET, pathParams, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
}
 
Example 15
@Test
void shouldNotThrowExceptionsOnRevokeErrors() {

	mockToken(LoginToken.of("login"));

	when(this.responseSpec.bodyToMono((Class) any())).thenReturn(
			Mono.error(new WebClientResponseException("forbidden", 403, "Forbidden", null, null, null)));

	this.sessionManager.renewToken() //
			.as(StepVerifier::create) //
			.expectNextCount(1) //
			.verifyComplete();
	this.sessionManager.destroy();

	verify(this.requestBodyUriSpec).uri("auth/token/revoke-self");
}
 
Example 16
Source Project: openapi-generator   Source File: UserApi.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Create user
 * This can only be done by the logged in user.
 * <p><b>0</b> - successful operation
 * @param body Created user object
 * @throws WebClientResponseException if an error occurs while attempting to invoke the API
 */
public Mono<Void> createUser(User body) throws WebClientResponseException {
    Object postBody = body;
    // verify the required parameter 'body' is set
    if (body == null) {
        throw new WebClientResponseException("Missing the required parameter 'body' when calling createUser", HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST.getReasonPhrase(), null, null, null);
    }
    // create path and map variables
    final Map<String, Object> pathParams = new HashMap<String, Object>();

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

    final String[] localVarAccepts = { };
    final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    final String[] localVarContentTypes = { };
    final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);

    String[] localVarAuthNames = new String[] {  };

    ParameterizedTypeReference<Void> localVarReturnType = new ParameterizedTypeReference<Void>() {};
    return apiClient.invokeAPI("/user", HttpMethod.POST, pathParams, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
}
 
Example 17
Source Project: openapi-generator   Source File: UserApi.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates list of users with given input array
 * 
 * <p><b>0</b> - successful operation
 * @param body List of user object
 * @throws WebClientResponseException if an error occurs while attempting to invoke the API
 */
public Mono<Void> createUsersWithArrayInput(List<User> body) throws WebClientResponseException {
    Object postBody = body;
    // verify the required parameter 'body' is set
    if (body == null) {
        throw new WebClientResponseException("Missing the required parameter 'body' when calling createUsersWithArrayInput", HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST.getReasonPhrase(), null, null, null);
    }
    // create path and map variables
    final Map<String, Object> pathParams = new HashMap<String, Object>();

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

    final String[] localVarAccepts = { };
    final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    final String[] localVarContentTypes = { };
    final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);

    String[] localVarAuthNames = new String[] {  };

    ParameterizedTypeReference<Void> localVarReturnType = new ParameterizedTypeReference<Void>() {};
    return apiClient.invokeAPI("/user/createWithArray", HttpMethod.POST, pathParams, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
}
 
Example 18
Source Project: openapi-generator   Source File: UserApi.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Creates list of users with given input array
 * 
 * <p><b>0</b> - successful operation
 * @param body List of user object
 * @throws WebClientResponseException if an error occurs while attempting to invoke the API
 */
public Mono<Void> createUsersWithListInput(List<User> body) throws WebClientResponseException {
    Object postBody = body;
    // verify the required parameter 'body' is set
    if (body == null) {
        throw new WebClientResponseException("Missing the required parameter 'body' when calling createUsersWithListInput", HttpStatus.BAD_REQUEST.value(), HttpStatus.BAD_REQUEST.getReasonPhrase(), null, null, null);
    }
    // create path and map variables
    final Map<String, Object> pathParams = new HashMap<String, Object>();

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

    final String[] localVarAccepts = { };
    final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    final String[] localVarContentTypes = { };
    final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);

    String[] localVarAuthNames = new String[] {  };

    ParameterizedTypeReference<Void> localVarReturnType = new ParameterizedTypeReference<Void>() {};
    return apiClient.invokeAPI("/user/createWithList", HttpMethod.POST, pathParams, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
}
 
Example 19
Source Project: openapi-generator   Source File: UserApi.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Logs out current logged in user session
 * 
 * <p><b>0</b> - successful operation
 * @throws WebClientResponseException if an error occurs while attempting to invoke the API
 */
public Mono<Void> logoutUser() throws WebClientResponseException {
    Object postBody = null;
    // create path and map variables
    final Map<String, Object> pathParams = new HashMap<String, Object>();

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

    final String[] localVarAccepts = { };
    final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    final String[] localVarContentTypes = { };
    final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);

    String[] localVarAuthNames = new String[] {  };

    ParameterizedTypeReference<Void> localVarReturnType = new ParameterizedTypeReference<Void>() {};
    return apiClient.invokeAPI("/user/logout", HttpMethod.GET, pathParams, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
}
 
Example 20
@Test
@SuppressWarnings("unchecked")
void shouldContinueIfSelfLookupFails() {

	VaultResponse vaultResponse = new VaultResponse();
	vaultResponse.setData(Collections.singletonMap("ttl", 100));

	mockToken(VaultToken.of("login"));

	when(this.responseSpec.bodyToMono((Class) any())).thenReturn(
			Mono.error(new WebClientResponseException("forbidden", 403, "Forbidden", null, null, null)));

	this.sessionManager.getSessionToken() //
			.as(StepVerifier::create) //
			.assertNext(it -> {
				assertThat(it).isExactlyInstanceOf(VaultToken.class);
			}).verifyComplete();
	verify(this.listener).onAuthenticationEvent(any(AfterLoginEvent.class));
	verify(this.errorListener).onAuthenticationError(any());
}
 
Example 21
@Test
public void shouldThrow404WithBody() {
	when(this.clientResponse.body(any())).thenReturn(Flux.fromIterable(Collections.singletonList(this.dataBuffer)));
	when(this.clientResponse.statusCode()).thenReturn(HttpStatus.NOT_FOUND);
	when(this.clientResponse.rawStatusCode()).thenReturn(404);

	WebClientResponseException exception =
			WebClientResponseExceptionCreator.createResponseException(this.clientResponse);

	assertThat(exception).isInstanceOf(WebClientResponseException.NotFound.class);

	verify(this.clientResponse).rawStatusCode();
	verify(this.clientResponse, times(2)).statusCode();
	verify(this.dataBuffer).factory();
	verify(this.dataBufferFactory).join(anyList());
}
 
Example 22
Source Project: openapi-generator   Source File: FakeApi.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 
 * Test serialization of object with outer number type
 * <p><b>200</b> - Output composite
 * @param body Input composite as post body
 * @return OuterComposite
 * @throws WebClientResponseException if an error occurs while attempting to invoke the API
 */
public Mono<OuterComposite> fakeOuterCompositeSerialize(OuterComposite body) throws WebClientResponseException {
    Object postBody = body;
    // create path and map variables
    final Map<String, Object> pathParams = new HashMap<String, Object>();

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

    final String[] localVarAccepts = { 
        "*/*"
    };
    final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    final String[] localVarContentTypes = { };
    final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);

    String[] localVarAuthNames = new String[] {  };

    ParameterizedTypeReference<OuterComposite> localVarReturnType = new ParameterizedTypeReference<OuterComposite>() {};
    return apiClient.invokeAPI("/fake/outer/composite", HttpMethod.POST, pathParams, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
}
 
Example 23
Source Project: openapi-generator   Source File: FakeApi.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 
 * Test serialization of outer number types
 * <p><b>200</b> - Output number
 * @param body Input number as post body
 * @return BigDecimal
 * @throws WebClientResponseException if an error occurs while attempting to invoke the API
 */
public Mono<BigDecimal> fakeOuterNumberSerialize(BigDecimal body) throws WebClientResponseException {
    Object postBody = body;
    // create path and map variables
    final Map<String, Object> pathParams = new HashMap<String, Object>();

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

    final String[] localVarAccepts = { 
        "*/*"
    };
    final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    final String[] localVarContentTypes = { };
    final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);

    String[] localVarAuthNames = new String[] {  };

    ParameterizedTypeReference<BigDecimal> localVarReturnType = new ParameterizedTypeReference<BigDecimal>() {};
    return apiClient.invokeAPI("/fake/outer/number", HttpMethod.POST, pathParams, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
}
 
Example 24
Source Project: openapi-generator   Source File: FakeApi.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * 
 * Test serialization of outer string types
 * <p><b>200</b> - Output string
 * @param body Input string as post body
 * @return String
 * @throws WebClientResponseException if an error occurs while attempting to invoke the API
 */
public Mono<String> fakeOuterStringSerialize(String body) throws WebClientResponseException {
    Object postBody = body;
    // create path and map variables
    final Map<String, Object> pathParams = new HashMap<String, Object>();

    final MultiValueMap<String, String> queryParams = new LinkedMultiValueMap<String, String>();
    final HttpHeaders headerParams = new HttpHeaders();
    final MultiValueMap<String, String> cookieParams = new LinkedMultiValueMap<String, String>();
    final MultiValueMap<String, Object> formParams = new LinkedMultiValueMap<String, Object>();

    final String[] localVarAccepts = { 
        "*/*"
    };
    final List<MediaType> localVarAccept = apiClient.selectHeaderAccept(localVarAccepts);
    final String[] localVarContentTypes = { };
    final MediaType localVarContentType = apiClient.selectHeaderContentType(localVarContentTypes);

    String[] localVarAuthNames = new String[] {  };

    ParameterizedTypeReference<String> localVarReturnType = new ParameterizedTypeReference<String>() {};
    return apiClient.invokeAPI("/fake/outer/string", HttpMethod.POST, pathParams, queryParams, postBody, headerParams, cookieParams, formParams, localVarAccept, localVarContentType, localVarAuthNames, localVarReturnType);
}
 
Example 25
Source Project: blog-tutorials   Source File: UsersClientTest.java    License: MIT License 6 votes vote down vote up
@Test
public void testMultipleResponseCodes() {

  final Dispatcher dispatcher = new Dispatcher() {
    @Override
    public MockResponse dispatch(RecordedRequest request) {
      switch (request.getPath()) {
        case "/users/1":
          return new MockResponse().setResponseCode(200);
        case "/users/2":
          return new MockResponse().setResponseCode(500);
        case "/users/3":
          return new MockResponse().setResponseCode(200).setBody("{\"id\": 1, \"name\":\"duke\"}");
      }
      return new MockResponse().setResponseCode(404);
    }
  };

  mockWebServer.setDispatcher(dispatcher);

  assertThrows(WebClientResponseException.class, () -> usersClient.getUserById(2L));
  assertThrows(WebClientResponseException.class, () -> usersClient.getUserById(4L));
}
 
Example 26
private static Mono<Map<String, Object>> lookupSelf(WebClient webClient, VaultToken token) {

		return webClient.get().uri("auth/token/lookup-self")
				.headers(httpHeaders -> httpHeaders.putAll(VaultHttpHeaders.from(token))).retrieve()
				.bodyToMono(VaultResponse.class).map(it -> {

					Assert.state(it.getData() != null, "Token response is null");
					return it.getRequiredData();
				}).onErrorMap(WebClientResponseException.class, e -> {
					return new VaultTokenLookupException(format("Token self-lookup", e), e);
				});
	}
 
Example 27
@Override
public Mono<Product> getProduct(int productId) {
    String url = productServiceUrl + "/product/" + productId;
    LOG.debug("Will call the getProduct API on URL: {}", url);

    return getWebClient().get().uri(url).retrieve().bodyToMono(Product.class).log().onErrorMap(WebClientResponseException.class, ex -> handleException(ex));
}
 
Example 28
private String getErrorMessage(WebClientResponseException ex) {
    try {
        return mapper.readValue(ex.getResponseBodyAsString(), HttpErrorInfo.class).getMessage();
    } catch (IOException ioex) {
        return ex.getMessage();
    }
}
 
Example 29
@Override
public Mono<Product> getProduct(int productId) {
    String url = productServiceUrl + "/product/" + productId;
    LOG.debug("Will call the getProduct API on URL: {}", url);

    return getWebClient().get().uri(url).retrieve().bodyToMono(Product.class).log().onErrorMap(WebClientResponseException.class, ex -> handleException(ex));
}
 
Example 30
private String getErrorMessage(WebClientResponseException ex) {
    try {
        return mapper.readValue(ex.getResponseBodyAsString(), HttpErrorInfo.class).getMessage();
    } catch (IOException ioex) {
        return ex.getMessage();
    }
}