private static <T> void fillExceptionWithData(final SphereRequest<T> sphereRequest, final HttpResponse httpResponse, final SphereException exception, final SphereApiConfig config) { exception.setSphereRequest(sphereRequest); exception.setUnderlyingHttpResponse(httpResponse); exception.setProjectKey(config.getProjectKey()); final List<String> errorMessagesDueToMappingError = asList("SearchPhaseExecutionException", "query_fetch", "RemoteTransportException", "SearchParseException", "search/phase/query+fetch"); Optional.ofNullable(httpResponse.getResponseBody()) .map(bytes -> bytesToString(bytes)) .map(body -> errorMessagesDueToMappingError.stream().anyMatch(errorWord -> body.contains(errorWord)) && body.toLowerCase().contains("product")) .ifPresent(containsTerm -> { if (containsTerm) { exception.addNote(format("Maybe it helps to reindex the products https://admin.sphere.io/%s/developers/danger but this may take a while.", config.getProjectKey())); } }); }
/** * Raw client creation. * See also SphereClientFactory. * * @param config platform project and location * @param httpClient client to execute requests * @param tokenSupplier delivery of access tokens * @return sphere client */ static SphereClient of(final SphereApiConfig config, final HttpClient httpClient, final SphereAccessTokenSupplier tokenSupplier) { return SphereClientImpl.of(config, httpClient, tokenSupplier, CorrelationIdGenerator.of(config.getProjectKey())); }
/** * Raw client creation. * See also SphereClientFactory. * * @param config platform project and location * @param httpClient client to execute requests * @param tokenSupplier delivery of access tokens * @return sphere client */ static SphereClient of(final SphereApiConfig config, final HttpClient httpClient, final SphereAccessTokenSupplier tokenSupplier) { return SphereClientImpl.of(config, httpClient, tokenSupplier, CorrelationIdGenerator.of(config.getProjectKey())); }
public static SphereClient of(final SphereApiConfig config, final HttpClient httpClient, final SphereAccessTokenSupplier tokenSupplier) { return new SphereClientImpl(config, tokenSupplier, httpClient, CorrelationIdGenerator.of(config.getProjectKey())); }
public static SphereClient of(final SphereApiConfig config, final HttpClient httpClient, final SphereAccessTokenSupplier tokenSupplier) { return new SphereClientImpl(config, tokenSupplier, httpClient, CorrelationIdGenerator.of(config.getProjectKey())); }
private static <T> void fillExceptionWithData(final SphereRequest<T> sphereRequest, final HttpResponse httpResponse, final SphereException exception, final SphereApiConfig config) { exception.setSphereRequest(sphereRequest); exception.setUnderlyingHttpResponse(httpResponse); exception.setProjectKey(config.getProjectKey()); }
private static <T> void fillExceptionWithData(final SphereRequest<T> sphereRequest, final HttpResponse httpResponse, final SphereException exception, final SphereApiConfig config, final HttpRequest httpRequest) { exception.setSphereRequest(sphereRequest); exception.setUnderlyingHttpResponse(httpResponse); exception.setProjectKey(config.getProjectKey()); exception.setHttpRequest(httpRequest); }
private static <T> void fillExceptionWithData(final SphereRequest<T> sphereRequest, final HttpResponse httpResponse, final SphereException exception, final SphereApiConfig config, final HttpRequest httpRequest) { exception.setSphereRequest(sphereRequest); exception.setUnderlyingHttpResponse(httpResponse); exception.setProjectKey(config.getProjectKey()); exception.setHttpRequest(httpRequest); }
@Test public void shouldRetrieveCorrelationId() throws ExecutionException, InterruptedException { final CorrelationIdRequestDecorator correlationIdRequestDecorator = new CorrelationIdRequestDecorator(ProjectGet.of()); client().executeBlocking(correlationIdRequestDecorator); assertThat(correlationId.isPresent()).isTrue(); final List<String> correlationIdParts = Arrays.asList(correlationId.get().split("/")); assertThat(correlationIdParts).hasSize(2); assertThat(correlationIdParts.get(0)).isEqualTo(client().getConfig().getProjectKey()); final UUID uuid = UUID.fromString(correlationIdParts.get(1)); assertThat(uuid).isNotNull(); }
private <T> HttpRequest createHttpRequest(final SphereRequest<T> sphereRequest, final String token) { return sphereRequest .httpRequestIntent() .plusHeader("User-Agent", "SPHERE.IO JVM SDK " + BuildInfo.version()) .plusHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token) .prefixPath("/" + config.getProjectKey()) .toHttpRequest(config.getApiUrl()); }
when(sphereApiConfig.getProjectKey()).thenReturn(projectKey); when(sphereApiConfig.getApiUrl()).thenReturn("http://api.commercetools.de"); when(httpClient.getUserAgent()).thenReturn("user-agent");
private <T> HttpRequest createHttpRequest(final SphereRequest<T> sphereRequest, final String token) { return sphereRequest .httpRequestIntent() .plusHeader(HttpHeaders.USER_AGENT, BuildInfo.userAgent()) .plusHeader(HttpHeaders.ACCEPT_ENCODING, "gzip") .plusHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token) .prefixPath("/" + config.getProjectKey()) .toHttpRequest(config.getApiUrl()); }
private <T> HttpRequest createHttpRequest(final SphereRequest<T> sphereRequest, final String token) { final String correlationId = correlationIdGenerator.get(); return sphereRequest .httpRequestIntent() .plusHeader(HttpHeaders.X_CORRELATION_ID, correlationId) .plusHeader(HttpHeaders.USER_AGENT, userAgent) .plusHeader(HttpHeaders.ACCEPT_ENCODING, "gzip") .plusHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token) .prefixPath("/" + config.getProjectKey()) .toHttpRequest(config.getApiUrl()); }
private <T> HttpRequest createHttpRequest(final SphereRequest<T> sphereRequest, final String token) { final String correlationId = correlationIdGenerator.get(); return sphereRequest .httpRequestIntent() .plusHeader(HttpHeaders.X_CORRELATION_ID, correlationId) .plusHeader(HttpHeaders.USER_AGENT, userAgent) .plusHeader(HttpHeaders.ACCEPT_ENCODING, "gzip") .plusHeader(HttpHeaders.AUTHORIZATION, "Bearer " + token) .prefixPath("/" + config.getProjectKey()) .toHttpRequest(config.getApiUrl()); }
public static void withApiClient(final BlockingSphereClient client, final List<SphereScope> scopes, final Consumer<ApiClient> consumer){ final SphereApiConfig config = client.getConfig(); final ApiClientDraft apiClientDraft = ApiClientDraftBuilder.of(GENERATED_CLIENT_NAME, config.getProjectKey(), scopes).build(); withApiClient(client,apiClientDraft,consumer); }