com.salesforce.einsteinbot.sdk.util.WebClientUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of einstein-bot-sdk-java Show documentation
Show all versions of einstein-bot-sdk-java Show documentation
Java SDK to interact with Einstein Bots Runtime.
This SDK is a wrapper around the Einstein Bots Runtime API that provides a few added features out of the box like Auth support, Session management
/*
* Copyright (c) 2022, salesforce.com, inc.
* All rights reserved.
* SPDX-License-Identifier: BSD-3-Clause
* For full license text, see the LICENSE file in the repo root or https://opensource.org/licenses/BSD-3-Clause
*/
package com.salesforce.einsteinbot.sdk.util;
import java.util.function.Function;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.web.reactive.function.client.ClientRequest;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.ExchangeFilterFunction;
import reactor.core.publisher.Mono;
/**
* WebClientUtil - Provides utility methods to work with Spring WebClient
*
* @author relango
*/
public class WebClientUtil {
private static final Logger logger = LoggerFactory.getLogger(WebClientUtil.class);
public static Mono createLoggingRequestProcessor(ClientRequest clientRequest) {
logger.info("Making {} Request to URI {} with Headers : {}", clientRequest.method(),
clientRequest.url(), clientRequest.headers());
return Mono.just(clientRequest);
}
public static Mono createErrorResponseProcessor(ClientResponse clientResponse,
Function> errorResponseMapper) {
if (clientResponse.statusCode().isError()) {
return errorResponseMapper.apply(clientResponse);
} else {
return Mono.just(clientResponse);
}
}
public static ExchangeFilterFunction createFilter(
Function> requestProcessor,
Function> responseProcessor) {
return ExchangeFilterFunction
.ofRequestProcessor(requestProcessor)
.andThen(
ExchangeFilterFunction.ofResponseProcessor(responseProcessor)
);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy