![JAR search and dependency download from the Maven repository](/logo.png)
com.adobe.platform.operation.internal.InternalExecutionContext Maven / Gradle / Ivy
/*
* Copyright 2019 Adobe
* All Rights Reserved.
*
* NOTICE: Adobe permits you to use, modify, and distribute this file in
* accordance with the terms of the Adobe license agreement accompanying
* it. If you have received this file from a source other than Adobe,
* then your use, modification, or distribution of it requires the prior
* written permission of Adobe.
*/
package com.adobe.platform.operation.internal;
import com.adobe.platform.operation.ExecutionContext;
import com.adobe.platform.operation.ClientConfig;
import com.adobe.platform.operation.auth.Credentials;
import com.adobe.platform.operation.auth.ServiceAccountCredentials;
import com.adobe.platform.operation.internal.auth.Authenticator;
import com.adobe.platform.operation.internal.auth.AuthenticatorFactory;
import com.adobe.platform.operation.internal.http.HttpRequest;
import com.adobe.platform.operation.internal.http.HttpRequestConfig;
import com.adobe.platform.operation.internal.cpf.constants.RequestKey;
public class InternalExecutionContext extends ExecutionContext {
private InternalClientConfig clientConfig;
private Authenticator authenticator;
private CPFServiceRequestContext cpfServiceRequestContext;
public InternalExecutionContext(Credentials credentials, ClientConfig clientConfig) {
if (credentials instanceof ServiceAccountCredentials ) {
if (clientConfig instanceof InternalClientConfig)
this.clientConfig = (InternalClientConfig) clientConfig;
else
this.clientConfig = new InternalClientConfig();
this.clientConfig.validate();
this.authenticator = AuthenticatorFactory.getAuthenticator(credentials);
this.cpfServiceRequestContext = new CPFServiceRequestContext(this.clientConfig.getV2PredictUri());
} else {
throw new IllegalArgumentException("Invalid ClientContext provided as argument");
}
}
public InternalClientConfig getClientConfig() {
return clientConfig;
}
public HttpRequest getBaseRequestFromRequestContext(RequestKey requestKey) {
HttpRequest baseRequest = cpfServiceRequestContext.getBaseRequest(requestKey);
HttpRequestConfig requestConfig = new HttpRequestConfig(this.clientConfig.getConnectTimeout(),
this.clientConfig.getSocketTimeout());
return baseRequest.withAuthenticator(authenticator).withConfig(requestConfig);
}
public void validate() {
this.clientConfig.validate();
if (this.authenticator == null) {
throw new IllegalStateException("Authentication not initialized in the provided context");
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy