Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix reading body as int in native mode #23764

Merged
merged 1 commit into from
Feb 17, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,13 @@ public boolean isReadable(Class type, Type genericType, Annotation[] annotations
return !String.class.equals(type) && TypeConverter.isConvertable(type);
}

@SuppressWarnings("unchecked")
public Object readFrom(Class type, Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
return doReadFrom(type, mediaType, entityStream);
}

@SuppressWarnings({ "rawtypes", "unchecked" })
protected Object doReadFrom(Class type, MediaType mediaType, InputStream entityStream) throws IOException {
String input = MessageReaderUtil.readString(entityStream, mediaType);
validateInput(input);
return TypeConverter.getType(type, input);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
package org.jboss.resteasy.reactive.server.providers.serialisers;

import java.io.IOException;
import java.lang.reflect.Type;
import javax.ws.rs.BadRequestException;
import javax.ws.rs.Consumes;
import javax.ws.rs.ProcessingException;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;
import org.jboss.resteasy.reactive.common.providers.serialisers.DefaultTextPlainBodyHandler;
import org.jboss.resteasy.reactive.server.spi.ResteasyReactiveResourceInfo;
import org.jboss.resteasy.reactive.server.spi.ServerMessageBodyReader;
import org.jboss.resteasy.reactive.server.spi.ServerRequestContext;

@Provider
@Consumes("text/plain")
public class ServerDefaultTextPlainBodyHandler extends DefaultTextPlainBodyHandler {
public class ServerDefaultTextPlainBodyHandler extends DefaultTextPlainBodyHandler implements ServerMessageBodyReader<Object> {

@Override
protected void validateInput(String input) throws ProcessingException {
Expand All @@ -19,4 +26,16 @@ protected void validateInput(String input) throws ProcessingException {
throw new BadRequestException(Response.status(Response.Status.BAD_REQUEST).entity("").build());
}
}

@Override
public boolean isReadable(Class<?> type, Type genericType, ResteasyReactiveResourceInfo lazyMethod,
MediaType mediaType) {
return super.isReadable(type, genericType, null, mediaType);
}

@Override
public Object readFrom(Class<Object> type, Type genericType, MediaType mediaType, ServerRequestContext context)
throws WebApplicationException, IOException {
return doReadFrom(type, mediaType, context.getInputStream());
}
}