
io.micronaut.http.client.jdk.HttpResponseAdapter Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of micronaut-http-client-jdk Show documentation
Show all versions of micronaut-http-client-jdk Show documentation
Core components supporting the Micronaut Framework
The newest version!
/*
* Copyright 2017-2023 original authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.micronaut.http.client.jdk;
import io.micronaut.core.annotation.Experimental;
import io.micronaut.core.annotation.Internal;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.core.annotation.Nullable;
import io.micronaut.core.convert.ConversionContext;
import io.micronaut.core.convert.ConversionService;
import io.micronaut.core.io.buffer.ByteArrayBufferFactory;
import io.micronaut.core.type.Argument;
import io.micronaut.http.HttpResponse;
import io.micronaut.http.MediaType;
import io.micronaut.http.body.MessageBodyHandlerRegistry;
import io.micronaut.http.body.MessageBodyReader;
import io.micronaut.http.codec.CodecException;
import io.micronaut.http.codec.MediaTypeCodec;
import io.micronaut.http.codec.MediaTypeCodecRegistry;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.util.Optional;
/**
* Adapter from {@link java.net.http.HttpResponse} to {@link HttpResponse}.
* @author Sergio del Amo
* @since 4.0.0
* @param Body Type
*/
@Internal
@Experimental
public class HttpResponseAdapter extends BaseHttpResponseAdapter {
private static final Logger LOG = LoggerFactory.getLogger(HttpResponseAdapter.class);
@NonNull
private final Argument bodyType;
private final MediaTypeCodecRegistry mediaTypeCodecRegistry;
private final MessageBodyHandlerRegistry messageBodyHandlerRegistry;
public HttpResponseAdapter(java.net.http.HttpResponse httpResponse,
@Nullable Argument bodyType,
ConversionService conversionService,
MediaTypeCodecRegistry mediaTypeCodecRegistry,
MessageBodyHandlerRegistry messageBodyHandlerRegistry) {
super(httpResponse, conversionService);
this.bodyType = bodyType;
this.mediaTypeCodecRegistry = mediaTypeCodecRegistry;
this.messageBodyHandlerRegistry = messageBodyHandlerRegistry;
}
@Override
public Optional getBody() {
return getBody(bodyType);
}
@Override
public Optional getBody(Argument type) {
final boolean isOptional = type.getType() == Optional.class;
final Argument
© 2015 - 2025 Weber Informatics LLC | Privacy Policy