Anpassad Java (HTTP Client Configuration)
Senast uppdaterad: 20 juli 2024
- Ämnen:
- APIs/SDKs
Skapat för:
- Utvecklare
Om programmet som kör SDK kräver en anpassad HTTP-klient måste TargetClient
konfigureras med ClientConfig.builder().httpClient()
för att funktioner som att konfigurera SSL eller lägga till standardhuvuden till begäranden ska kunna aktiveras:
Grundläggande anpassad HTTP-klientkonfiguration
SDK stöder för närvarande HTTP-klienter som implementerar gränssnittet org.apache.http.client.HttpClient
.
Grundläggande implementering
CloseableHttpClient httpClient = HttpClients.custom().build();
ClientConfig clientConfig = ClientConfig.builder()
.client("acmeclient")
.organizationId("1234567890@AdobeOrg")
.httpClient(httpClient)
.build();
TargetClient targetClient = TargetClient.create(clientConfig);
Anpassad HTTP-klientkonfiguration med SSL-konfiguration
Här är ett exempel på hur du konfigurerar SSL i TargetClient
genom att anpassa HttpClient
som skickas till ClientConfig
. Följande kodfragment använder klasser från paketet org.apache.http.conn.ssl
för SSL-konfiguration.
SSL-implementering
SSLContext context = SSLContextBuilder.create().build();
SSLConnectionSocketFactory sslSocketFactory = new SSLConnectionSocketFactory(context);
CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(sslSocketFactory).build();
ClientConfig clientConfig = ClientConfig.builder()
.client("acmeclient")
.organizationId("1234567890@AdobeOrg")
.httpClient(httpClient)
.build();
TargetClient targetClient = TargetClient.create(clientConfig);
recommendation-more-help
6906415f-169c-422b-89d3-7118e147c4e3