Class PythonHttpConversion
java.lang.Object
io.micronaut.context.python.PythonHttpConversion
-
Method Summary
Modifier and TypeMethodDescriptionstatic <T> HttpResponse<T> convertHttpResponse(HttpResponse<?> response, Class<T> bodyType) Convert a response body to the declared Java body type.static <T> @Nullable HttpResponse<T> convertHttpResponse(org.graalvm.polyglot.Value value, Class<T> bodyType) Convert a GraalPy-createdHttpResponseand its response body to the declared Java body type.static <T> @Nullable Publisher<T> convertPublisher(org.graalvm.polyglot.Value value, PolyglotValueConverter<T> converter) Convert a GraalPy publisher with a generated item converter.static <T,P> @Nullable P convertPublisher(org.graalvm.polyglot.Value value, PolyglotValueConverter<T> converter, Class<P> targetType) Convert a GraalPy publisher with a generated item converter to the reactive type a method declares.static <T> @Nullable Publisher<T> convertPublisher(org.graalvm.polyglot.Value value, Class<T> itemType) Convert a GraalPy Value representing a publisher to a typed Java publisher.static <T,P> @Nullable P convertPublisher(org.graalvm.polyglot.Value value, Class<T> itemType, Class<P> targetType) Convert a GraalPy value representing a publisher to the reactive type a method declares: the items are converted to the declared item type and the publisher is then adapted to the declared type (Mono,Flux, aCompletionStageor any reactive type the conversion service knows), so a Python body may return aFluxwhere the Java signature saysMono, or aMonowhere it saysCompletableFuture.static <T> Publisher<T> convertPublisher(Publisher<?> publisher, PolyglotValueConverter<T> converter) Convert publisher items with a generated wrapper converter.static <T> Publisher<T> convertPublisher(Publisher<?> publisher, Class<T> itemType) Convert each item emitted by a Python-returned publisher to the declared Java item type.static <P> @Nullable PconvertReactive(@Nullable Object source, Class<P> targetType) Adapt a reactive value (aPublisheror aCompletionStage) to the reactive type a method declares.static <P> @Nullable PconvertReactiveValue(org.graalvm.polyglot.Value value, Class<P> targetType) Convert the value a Python method returned to the reactive type its signature declares: a hostPublisherorCompletionStageof another type (a ReactorMonoreturned by a method implementing aCompletableFuturedeclaration without a return annotation) is adapted as byconvertReactive(Object, Class); any other value is converted as byPythonConversion.convertValue(Value, Class).
-
Method Details
-
convertHttpResponse
public static <T> @Nullable HttpResponse<T> convertHttpResponse(org.graalvm.polyglot.Value value, Class<T> bodyType) Convert a GraalPy-createdHttpResponseand its response body to the declared Java body type.- Type Parameters:
T- The response body type- Parameters:
value- The source polyglot responsebodyType- The declared response body type- Returns:
- The converted response, or
nullwhen the value is not anHttpResponse
-
convertPublisher
Convert each item emitted by a Python-returned publisher to the declared Java item type.- Type Parameters:
T- The item type- Parameters:
publisher- The source publisheritemType- The declared publisher item type- Returns:
- The converted publisher
-
convertPublisher
public static <T> Publisher<T> convertPublisher(Publisher<?> publisher, PolyglotValueConverter<T> converter) Convert publisher items with a generated wrapper converter. A generated converter preserves the concrete Python wrapper type after the publisher crosses the reactive boundary.- Type Parameters:
T- The item type- Parameters:
publisher- The source publisherconverter- The generated item converter- Returns:
- The converted publisher
-
convertPublisher
public static <T> @Nullable Publisher<T> convertPublisher(org.graalvm.polyglot.Value value, Class<T> itemType) Convert a GraalPy Value representing a publisher to a typed Java publisher.- Type Parameters:
T- The item type- Parameters:
value- The source polyglot publisheritemType- The declared publisher item type- Returns:
- The converted publisher
-
convertPublisher
public static <T> @Nullable Publisher<T> convertPublisher(org.graalvm.polyglot.Value value, PolyglotValueConverter<T> converter) Convert a GraalPy publisher with a generated item converter.- Type Parameters:
T- The item type- Parameters:
value- The source polyglot publisherconverter- The generated item converter- Returns:
- The converted publisher
-
convertPublisher
public static <T,P> @Nullable P convertPublisher(org.graalvm.polyglot.Value value, Class<T> itemType, Class<P> targetType) Convert a GraalPy value representing a publisher to the reactive type a method declares: the items are converted to the declared item type and the publisher is then adapted to the declared type (Mono,Flux, aCompletionStageor any reactive type the conversion service knows), so a Python body may return aFluxwhere the Java signature saysMono, or aMonowhere it saysCompletableFuture.- Type Parameters:
T- The item typeP- The reactive type- Parameters:
value- The source polyglot publisheritemType- The declared publisher item typetargetType- The declared reactive return type- Returns:
- The converted publisher, or
nullforNone
-
convertPublisher
public static <T,P> @Nullable P convertPublisher(org.graalvm.polyglot.Value value, PolyglotValueConverter<T> converter, Class<P> targetType) Convert a GraalPy publisher with a generated item converter to the reactive type a method declares.- Type Parameters:
T- The item typeP- The reactive type- Parameters:
value- The source polyglot publisherconverter- The generated item convertertargetType- The declared reactive return type- Returns:
- The converted publisher, or
nullforNone - See Also:
-
convertReactiveValue
public static <P> @Nullable P convertReactiveValue(org.graalvm.polyglot.Value value, Class<P> targetType) Convert the value a Python method returned to the reactive type its signature declares: a hostPublisherorCompletionStageof another type (a ReactorMonoreturned by a method implementing aCompletableFuturedeclaration without a return annotation) is adapted as byconvertReactive(Object, Class); any other value is converted as byPythonConversion.convertValue(Value, Class).- Type Parameters:
P- The reactive type- Parameters:
value- The polyglot value the Python method returnedtargetType- The declared reactive return type- Returns:
- The converted value, or
nullforNone - Throws:
IllegalArgumentException- When a reactive value cannot be adapted to the declared type
-
convertReactive
Adapt a reactive value (aPublisheror aCompletionStage) to the reactive type a method declares. A value that already is of the declared type is returned as is; a publisher is otherwise wrapped asMono.from/Flux.fromwhen Reactor is present, completed into a future when aCompletionStageis declared, and converted through the sharedConversionServicefor any other reactive type; a stage is adapted through the publisher it completes.- Type Parameters:
P- The reactive type- Parameters:
source- The publisher or completion stagetargetType- The declared reactive return type- Returns:
- The adapted value, or
nullfor anullsource - Throws:
IllegalArgumentException- When the value cannot be adapted to the declared type
-
convertHttpResponse
Convert a response body to the declared Java body type.- Type Parameters:
T- The response body type- Parameters:
response- The source responsebodyType- The declared response body type- Returns:
- The converted response
-