Package com.sap.ai.sdk.core.common
Class ClientStreamingHandler<D extends StreamedDelta,R extends ClientError,E extends ClientException>
java.lang.Object
com.sap.ai.sdk.core.common.ClientResponseHandler<D,R,E>
com.sap.ai.sdk.core.common.ClientStreamingHandler<D,R,E>
- Type Parameters:
D- The type of the response.R- The type of the error.E- The type of the exception to throw.
- All Implemented Interfaces:
org.apache.hc.core5.http.io.HttpClientResponseHandler<D>
@Beta
public class ClientStreamingHandler<D extends StreamedDelta,R extends ClientError,E extends ClientException>
extends ClientResponseHandler<D,R,E>
Parse incoming JSON responses and handles any errors. For internal use only.
- Since:
- 1.2.0
-
Constructor Summary
ConstructorsConstructorDescriptionClientStreamingHandler(Class<D> deltaType, Class<? extends R> errorType, ClientExceptionFactory<E, R> exceptionFactory) Creates a new instance of theClientStreamingHandler. -
Method Summary
Modifier and TypeMethodDescriptionhandleStreamingResponse(org.apache.hc.core5.http.ClassicHttpResponse response) Processes aClassicHttpResponseand returns aStreamof deltas corresponding to that response.objectMapper(com.fasterxml.jackson.databind.ObjectMapper jackson) Set theObjectMapperto use for parsing JSON responses.Methods inherited from class com.sap.ai.sdk.core.common.ClientResponseHandler
buildAndThrowException, handleResponse, parseErrorResponseAndThrow
-
Constructor Details
-
ClientStreamingHandler
public ClientStreamingHandler(@Nonnull Class<D> deltaType, @Nonnull Class<? extends R> errorType, @Nonnull ClientExceptionFactory<E, R> exceptionFactory) Creates a new instance of theClientStreamingHandler.- Parameters:
deltaType- The type of the response.errorType- The type of the error.exceptionFactory- The factory to create exceptions.
-
-
Method Details
-
objectMapper
@Nonnull public ClientStreamingHandler<D,R, objectMapperE> (@Nonnull com.fasterxml.jackson.databind.ObjectMapper jackson) Set theObjectMapperto use for parsing JSON responses.- Overrides:
objectMapperin classClientResponseHandler<D extends StreamedDelta,R extends ClientError, E extends ClientException> - Parameters:
jackson- TheObjectMapperto use- Returns:
- the current instance of
ClientStreamingHandlerwith the changed object mapper
-
handleStreamingResponse
@Nonnull public Stream<D> handleStreamingResponse(@Nonnull org.apache.hc.core5.http.ClassicHttpResponse response) throws E Processes aClassicHttpResponseand returns aStreamof deltas corresponding to that response.- Parameters:
response- The response to process- Returns:
- A
Streamof a model class instantiated from the response - Throws:
E- in case of a problem or the connection was aborted
-