private void process(final FetchTokenFromSphereMessage m) { if (!isWaitingForToken) { isWaitingForToken = true; final CompletableFuture<Tokens> future = internalTokensSupplier.get(); onSuccess(future, tokens -> tell(new SuccessfulTokenFetchMessage(tokens))); onFailure(future, e -> tell(new FailedTokenFetchMessage(e, m.attempt + 1))); } }
private AutoRefreshSphereAccessTokenSupplierImpl(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { final TokensSupplier internalTokensSupplier = TokensSupplierImpl.of(config, httpClient, closeHttpClient); authActor = new AuthActor(internalTokensSupplier); authActor.tell(new SubscribeMessage(tokenActor)); }
private AutoRefreshSphereAccessTokenSupplierImpl(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { tokensSupplier = TokensSupplierImpl.of(config, httpClient, closeHttpClient); authActor = new AuthActor(tokensSupplier, this::supervisedTokenSupplier, this::requestUpdateTokens, this::requestUpdateFailedStatus); authActor.tell(new AuthActorProtocol.FetchTokenFromSphereMessage()); }
protected synchronized static TestClient client() { if (client == null) { final SphereClientFactory factory = SphereClientFactory.of(); final SphereClientConfig config = SphereClientConfig.of(projectKey(), clientId(), clientSecret(), authUrl(), apiUrl()); final SphereAccessTokenSupplier tokenSupplier = SphereAccessTokenSupplierFactory.of().createSupplierOfOneTimeFetchingToken(config); final SphereClient underlying = factory.createClient(config, tokenSupplier); final SphereClient underlyingWithDeprecationExceptions = DeprecationExceptionSphereClientDecorator.of(underlying); client = new TestClient(underlyingWithDeprecationExceptions); } return client; }
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()); }
/** * Creates a standard client with configurable service URLs. Intended for commercetools staff * developing with a custom SPHERE.IO instance. * * @param config configuration for the client * @return client */ public SphereClient createClient(final SphereClientConfig config) { final HttpClient httpClient = createHttpClient(); final SphereAccessTokenSupplier tokenSupplier = SphereAccessTokenSupplier.ofAutoRefresh(config, httpClient, false); return SphereClient.of(config, httpClient, tokenSupplier); }
/** * Creates a client which relies on an access token and does not refresh it. * * A possible use case is keeping the clientSecret secret and/or instantiate a client which is used for few requests for a limited time. * * @param config the configuration to use the API * @param accessToken the token belonging to the project in {@code config} * @return client */ public SphereClient createClientOfApiConfigAndAccessToken(final SphereApiConfig config, final String accessToken) { return SphereClient.of(config, createHttpClient(), SphereAccessTokenSupplier.ofConstantToken(accessToken)); }
private SphereClient clientWithResponse(final HttpResponse response) { return SphereClient.of(SphereApiConfig.of("test"), new HttpClient() { @Override public CompletionStage<HttpResponse> execute(final HttpRequest httpRequest) { return CompletableFutureUtils.successful(response); } @Override public void close() { } }, SphereAccessTokenSupplier.ofConstantToken("foo")); } }
/** * Creates a standard client with configurable service URLs. Intended for commercetools staff * developing with a custom SPHERE.IO instance. * * @param config configuration for the client * @return client */ public SphereClient createClient(final SphereClientConfig config) { final HttpClient httpClient = defaultHttpClient(); final SphereAccessTokenSupplier tokenSupplier = SphereAccessTokenSupplier.ofAutoRefresh(config, httpClient, false); return SphereClient.of(config, defaultHttpClient(), tokenSupplier); }
/** * 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())); }
@Override public <T> T executeBlocking(final SphereRequest<T> sphereRequest, final long timeout, final TimeUnit unit) { final CompletionStage<T> completionStage = execute(sphereRequest); return blockingWait(completionStage, sphereRequest, timeout, unit); }
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()); }
/** * Creates a standard client with configurable service URLs. Intended for commercetools staff * developing with a custom platform instance. * * @param config configuration for the client * @return client */ default SphereClient createClient(SphereClientConfig config) { final HttpClient httpClient = createHttpClient(); final SphereAccessTokenSupplier tokenSupplier = SphereAccessTokenSupplier.ofAutoRefresh(config, httpClient, false); return SphereClient.of(config, httpClient, tokenSupplier); }
/** * Creates a client which relies on an access token and does not refresh it. * * A possible use case is keeping the clientSecret secret and/or instantiate a client which is used for few requests for a limited time. * * @param config the configuration to use the API * @param accessToken the token belonging to the project in {@code config} * @return client */ default SphereClient createClientOfApiConfigAndAccessToken(SphereApiConfig config, String accessToken) { return SphereClient.of(config, createHttpClient(), SphereAccessTokenSupplier.ofConstantToken(accessToken)); }
private AutoRefreshSphereAccessTokenSupplierImpl(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { tokensSupplier = TokensSupplierImpl.of(config, httpClient, closeHttpClient); authActor = new AuthActor(tokensSupplier, this::supervisedTokenSupplier, this::requestUpdateTokens, this::requestUpdateFailedStatus); authActor.tell(new AuthActorProtocol.FetchTokenFromSphereMessage()); }
private AutoRefreshSphereAccessTokenSupplierImpl(final SphereAuthConfig config, final HttpClient httpClient, final boolean closeHttpClient) { final TokensSupplier internalTokensSupplier = TokensSupplierImpl.of(config, httpClient, closeHttpClient); authActor = new AuthActor(internalTokensSupplier); authActor.tell(new SubscribeMessage(tokenActor)); }
/** * 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())); }
/** * Creates a standard client with configurable service URLs. Intended for commercetools staff * developing with a custom platform instance. * * @param config configuration for the client * @return client */ default SphereClient createClient(SphereClientConfig config) { final HttpClient httpClient = createHttpClient(); final SphereAccessTokenSupplier tokenSupplier = SphereAccessTokenSupplier.ofAutoRefresh(config, httpClient, false); return SphereClient.of(config, httpClient, tokenSupplier); }
/** * Creates a client which relies on an access token and does not refresh it. * * A possible use case is keeping the clientSecret secret and/or instantiate a client which is used for few requests for a limited time. * * @param config the configuration to use the API * @param accessToken the token belonging to the project in {@code config} * @return client */ default SphereClient createClientOfApiConfigAndAccessToken(SphereApiConfig config, String accessToken) { return SphereClient.of(config, createHttpClient(), SphereAccessTokenSupplier.ofConstantToken(accessToken)); }