Skip to content

Commit

Permalink
Move to core InputStreamByteBody (#770)
Browse files Browse the repository at this point in the history
Update to 4.6.x versions
* Move to core InputStreamByteBody
  • Loading branch information
yawkat authored Aug 19, 2024
1 parent 59b3c87 commit b52f4c2
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 12 deletions.
10 changes: 5 additions & 5 deletions gradle/libs.versions.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[versions]
micronaut = "4.5.4"
micronaut = "4.6.1"
micronaut-docs = "2.0.0"
micronaut-test = "4.0.1"
micronaut-test = "4.4.0"

groovy = "4.0.15"
spock = "2.3-groovy-4.0"
Expand All @@ -14,11 +14,11 @@ bcpkix = "1.70"

managed-jetty = '11.0.22'

micronaut-reactor = "3.4.1"
micronaut-reactor = "3.5.0"
micronaut-security = "4.9.1"
micronaut-serde = "2.10.2"
micronaut-serde = "2.11.0"
micronaut-session = "4.3.0"
micronaut-validation = "4.6.1"
micronaut-validation = "4.7.0"
google-cloud-functions = '1.1.0'
kotlin = "1.9.25"
micronaut-logging = "1.3.0"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,15 @@ import io.micronaut.context.annotation.Requires
import io.micronaut.core.async.annotation.SingleResult
import io.micronaut.http.HttpStatus
import io.micronaut.http.MediaType
import io.micronaut.http.annotation.Consumes
import io.micronaut.http.annotation.Controller
import io.micronaut.http.annotation.Get
import io.micronaut.http.client.annotation.Client
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import io.micronaut.http.client.exceptions.HttpClientResponseException
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import jakarta.inject.Inject
import org.reactivestreams.Publisher
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import spock.lang.PendingFeature
import spock.lang.Specification

@MicronautTest
Expand All @@ -32,7 +30,6 @@ class JettyNotFoundSpec extends Specification {
Flux.from(client.streaming('notthere')).collectList().block() == []
}

@PendingFeature(reason = "https://github.com/micronaut-projects/micronaut-core/pull/9307")
void "test 404 handling with not streaming publisher"() {
when:
def exists = Mono.from(client.mono('1234')).block()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* Copyright 2017-2024 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.servlet.http;

import io.micronaut.core.annotation.Internal;
import io.micronaut.core.io.buffer.ByteBuffer;
import io.micronaut.core.io.buffer.ByteBufferFactory;

/**
* {@link ByteBufferFactory} implementation based on simple byte arrays.
*
* @since 4.10.0
* @author Jonas Konrad
*/
@Internal
public class ByteArrayBufferFactory implements ByteBufferFactory<Void, byte[]> {
public static final ByteArrayBufferFactory INSTANCE = new ByteArrayBufferFactory();

private ByteArrayBufferFactory() {
}

@Override
public Void getNativeAllocator() {
throw new UnsupportedOperationException("No native allocator");
}

@Override
public ByteBuffer<byte[]> buffer() {
return buffer(0);
}

@Override
public ByteBuffer<byte[]> buffer(int initialCapacity) {
return new ByteArrayByteBuffer<>(new byte[initialCapacity]);
}

@Override
public ByteBuffer<byte[]> buffer(int initialCapacity, int maxCapacity) {
return buffer(initialCapacity);
}

@Override
public ByteBuffer<byte[]> copiedBuffer(byte[] bytes) {
return wrap(bytes.clone());
}

@Override
public ByteBuffer<byte[]> copiedBuffer(java.nio.ByteBuffer nioBuffer) {
int pos = nioBuffer.position();
int lim = nioBuffer.limit();
byte[] arr = new byte[lim - pos];
nioBuffer.get(pos, arr, 0, arr.length);
return wrap(arr);
}

@Override
public ByteBuffer<byte[]> wrap(byte[] existing) {
return new ByteArrayByteBuffer<>(existing);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
import io.micronaut.http.MutableHttpResponse;
import io.micronaut.http.annotation.Header;
import io.micronaut.http.annotation.Produces;
import io.micronaut.http.body.DynamicMessageBodyWriter;
import io.micronaut.http.body.MessageBodyHandlerRegistry;
import io.micronaut.http.body.MessageBodyWriter;
import io.micronaut.http.codec.CodecException;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,10 @@
*
* @author Jonas Konrad
* @since 4.9.0
* @deprecated Use {@link io.micronaut.http.body.stream.AvailableByteArrayBody} from core instead
*/
@Internal
@Deprecated(forRemoval = true)
public final class AvailableByteArrayBody extends AbstractServletByteBody implements CloseableAvailableByteBody {
private byte[] array;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,10 @@
*
* @since 4.9.0
* @author Jonas Konrad
* @deprecated Use {@link io.micronaut.http.body.stream.InputStreamByteBody} from core instead
*/
@Internal
@Deprecated(forRemoval = true)
public final class InputStreamByteBody extends AbstractServletByteBody {
private final Context context;
private ExtendedInputStream stream;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,16 @@
import io.micronaut.http.ServerHttpRequest;
import io.micronaut.http.body.ByteBody;
import io.micronaut.http.body.CloseableByteBody;
import io.micronaut.http.body.stream.InputStreamByteBody;
import io.micronaut.http.codec.MediaTypeCodecRegistry;
import io.micronaut.http.cookie.Cookies;
import io.micronaut.servlet.http.BodyBuilder;
import io.micronaut.servlet.http.ByteArrayBufferFactory;
import io.micronaut.servlet.http.ParsedBodyHolder;
import io.micronaut.servlet.http.ServletExchange;
import io.micronaut.servlet.http.ServletHttpRequest;
import io.micronaut.servlet.http.ServletHttpResponse;
import io.micronaut.servlet.http.StreamedServletMessage;
import io.micronaut.servlet.http.body.InputStreamByteBody;
import jakarta.servlet.AsyncContext;
import jakarta.servlet.ReadListener;
import jakarta.servlet.ServletInputStream;
Expand Down Expand Up @@ -135,7 +136,7 @@ protected DefaultServletHttpRequest(ConversionService conversionService,
this.delegate = delegate;
this.codecRegistry = codecRegistry;
long contentLengthLong = delegate.getContentLengthLong();
this.byteBody = InputStreamByteBody.create(new LazyDelegateInputStream(delegate), contentLengthLong < 0 ? OptionalLong.empty() : OptionalLong.of(contentLengthLong), ioExecutor);
this.byteBody = InputStreamByteBody.create(new LazyDelegateInputStream(delegate), contentLengthLong < 0 ? OptionalLong.empty() : OptionalLong.of(contentLengthLong), ioExecutor, ByteArrayBufferFactory.INSTANCE);

String requestURI = delegate.getRequestURI();

Expand Down

0 comments on commit b52f4c2

Please sign in to comment.