com.adobe.pdfservices.operation.internal.ExecutionContext Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of pdfservices-sdk Show documentation
Show all versions of pdfservices-sdk Show documentation
Adobe PDF Services SDK allows you to access RESTful APIs to create, convert, and manipulate PDFs within your applications.
Older versions can be found under groupId: com.adobe.documentservices, artifactId: pdftools-sdk
/*
* Copyright 2024 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.pdfservices.operation.internal;
import com.adobe.pdfservices.operation.auth.Credentials;
import com.adobe.pdfservices.operation.config.ClientConfig;
import com.adobe.pdfservices.operation.internal.auth.AuthenticationMethod;
import com.adobe.pdfservices.operation.internal.auth.Authenticator;
import com.adobe.pdfservices.operation.internal.auth.AuthenticatorFactory;
import com.adobe.pdfservices.operation.internal.constants.CustomErrorMessages;
import com.adobe.pdfservices.operation.internal.constants.RequestKey;
import com.adobe.pdfservices.operation.internal.http.HttpRequest;
import com.adobe.pdfservices.operation.internal.http.HttpRequestConfig;
public class ExecutionContext {
private InternalClientConfig clientConfig;
private PlatformServiceRequestContext platformServiceRequestContext;
private Authenticator authenticator;
public ExecutionContext(Credentials credentials) {
this(credentials, null);
}
public ExecutionContext(Credentials credentials, ClientConfig clientConfig) {
if (clientConfig instanceof InternalClientConfig)
this.clientConfig = (InternalClientConfig) clientConfig;
else
this.clientConfig = new InternalClientConfig();
this.clientConfig.validate();
this.authenticator = AuthenticatorFactory.getAuthenticator(credentials, this.clientConfig);
this.platformServiceRequestContext = new PlatformServiceRequestContext(this.clientConfig.getPdfServiceUri());
}
public InternalClientConfig getClientConfig() {
return clientConfig;
}
public HttpRequest getBaseRequestFromRequestContext(RequestKey requestKey) {
HttpRequest baseRequest = platformServiceRequestContext.getBaseRequest(requestKey);
return baseRequest.withAuthenticator(authenticator).withConfig(new HttpRequestConfig(clientConfig));
}
public HttpRequest getUnauthenticatedBaseRequestFromRequestContext(RequestKey requestKey) {
HttpRequest baseRequest = platformServiceRequestContext.getBaseRequest(requestKey);
return baseRequest.withAuthenticationMethod(AuthenticationMethod.UNAUTHENTICATED)
.withConfig(new HttpRequestConfig(clientConfig));
}
public void validate() {
if (this.authenticator == null) {
throw new IllegalStateException(String.format(CustomErrorMessages.GENERIC_CAN_NOT_BE_NULL,
"Authentication"));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy