
io.micronaut.http.server.netty.binders.NettyBodyAnnotationBinder Maven / Gradle / Ivy
/*
* 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.server.netty.binders;
import io.micronaut.core.convert.ArgumentConversionContext;
import io.micronaut.core.convert.ConversionContext;
import io.micronaut.core.convert.ConversionError;
import io.micronaut.core.convert.ConversionService;
import io.micronaut.core.convert.value.ConvertibleValues;
import io.micronaut.core.execution.ExecutionFlow;
import io.micronaut.http.HttpRequest;
import io.micronaut.http.MediaType;
import io.micronaut.http.bind.binders.DefaultBodyAnnotationBinder;
import io.micronaut.http.bind.binders.PendingRequestBindingResult;
import io.micronaut.http.body.MessageBodyHandlerRegistry;
import io.micronaut.http.body.MessageBodyReader;
import io.micronaut.http.codec.CodecException;
import io.micronaut.http.server.HttpServerConfiguration;
import io.micronaut.http.server.netty.DefaultHttpContentProcessorResolver;
import io.micronaut.http.server.netty.FormDataHttpContentProcessor;
import io.micronaut.http.server.netty.NettyHttpRequest;
import io.micronaut.http.server.netty.body.ImmediateByteBody;
import java.util.List;
import java.util.Optional;
final class NettyBodyAnnotationBinder extends DefaultBodyAnnotationBinder {
private static final CharSequence ATTR_CONVERTIBLE_BODY = "NettyBodyAnnotationBinder.convertibleBody";
final HttpServerConfiguration httpServerConfiguration;
final MessageBodyHandlerRegistry bodyHandlerRegistry;
NettyBodyAnnotationBinder(ConversionService conversionService,
HttpServerConfiguration httpServerConfiguration,
MessageBodyHandlerRegistry bodyHandlerRegistry) {
super(conversionService);
this.httpServerConfiguration = httpServerConfiguration;
this.bodyHandlerRegistry = bodyHandlerRegistry;
}
@Override
protected BindingResult bindBodyPart(ArgumentConversionContext context, HttpRequest> source, String bodyComponent) {
if (source instanceof NettyHttpRequest> nhr && nhr.isFormOrMultipartData()) {
// skipClaimed=true because for unmatched binding, both this binder and PartUploadAnnotationBinder can be called on the same parameter
return NettyPartUploadAnnotationBinder.bindPart(conversionService, context, nhr, bodyComponent, true);
} else {
return super.bindBodyPart(context, source, bodyComponent);
}
}
@Override
protected BindingResult> bindFullBodyConvertibleValues(HttpRequest> source) {
if (!(source instanceof NettyHttpRequest> nhr)) {
return super.bindFullBodyConvertibleValues(source);
}
Optional
© 2015 - 2025 Weber Informatics LLC | Privacy Policy