Skip to content

Commit

Permalink
Fix reading body as int in native mode
Browse files Browse the repository at this point in the history
Fixes: #23732
  • Loading branch information
geoand committed Feb 16, 2022
1 parent f52d0ae commit 9fba53a
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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());
}
}

0 comments on commit 9fba53a

Please sign in to comment.