Skip to content

Commit

Permalink
Fix some compatibility issues with newer resteasy versions
Browse files Browse the repository at this point in the history
  • Loading branch information
beikov committed Oct 12, 2020
1 parent 43740b7 commit d3bd8d5
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
public class ResponseObjectBuilder implements Builder {

private final List<MessageBodyReader<?>> responseObjectMessageReader;
private Builder delegate;
private final Builder delegate;

public ResponseObjectBuilder(Builder delegate, List<MessageBodyReader<?>> responseObjectMessageReader) {
this.delegate = delegate;
this.responseObjectMessageReader = responseObjectMessageReader;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
public class ResponseObjectInvocation implements Invocation {

private final List<MessageBodyReader<?>> responseObjectMessageReader;
private Invocation delegate;
private final Invocation delegate;

public ResponseObjectInvocation(Invocation delegate, List<MessageBodyReader<?>> responseObjectMessageReader) {
this.delegate = delegate;
Expand Down Expand Up @@ -58,7 +58,11 @@ private <T> T getResponseObject(MessageBodyReader<T> reader, Class<T> responseTy
boolean success = false;
try {
// this wrapping serves as a workaround to prevent the GC from closing the response and with it the underlying inputstream
InputStream responseBody = new ResponseInputStreamWrapper(response.readEntity(InputStream.class), response);
InputStream is = null;
if (response.hasEntity()) {
is = response.readEntity(InputStream.class);
}
InputStream responseBody = new ResponseInputStreamWrapper(is, response);
T result = reader.readFrom(responseType, null, null, null, response.getStringHeaders(), responseBody);
success = true;
return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
public class ResponseObjectWebTarget implements WebTarget {

private final List<MessageBodyReader<?>> responseObjectMessageReader;
private WebTarget delegate;
private final WebTarget delegate;

public ResponseObjectWebTarget(WebTarget delegate, List<MessageBodyReader<?>> responseObjectMessageReader) {
this.delegate = delegate;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,19 @@
package com.blazebit.storage.rest.impl.aop;

import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;
import com.blazebit.storage.rest.api.aop.ResponseObject;
import com.blazebit.storage.rest.model.convert.ResponseObjectAwareMessageBodyWriter;

import javax.enterprise.inject.Vetoed;
import javax.ws.rs.Produces;
import javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.io.OutputStream;
import java.lang.annotation.Annotation;
import java.lang.reflect.Type;

import com.blazebit.storage.rest.api.aop.ResponseObject;
import com.blazebit.storage.rest.model.convert.ResponseObjectAwareMessageBodyWriter;

@Vetoed
@Provider
@Produces(MediaType.WILDCARD)
public class ResponseObjectMessageBodyWriter implements MessageBodyWriter<Object> {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.blazebit.storage.rest.impl.aop;

import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerRequestFilter;
import javax.ws.rs.container.PreMatching;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.Provider;
import java.io.IOException;
import java.util.Collections;

@Provider
@PreMatching
public class ResteasyWorkaroundContainerRequestFilter implements ContainerRequestFilter {

@Override
public void filter(ContainerRequestContext requestContext) throws IOException {
MultivaluedMap<String, String> headers = requestContext.getHeaders();
String accept = headers.getFirst(HttpHeaders.ACCEPT);
if (accept == null || accept.isEmpty()) {
headers.put(HttpHeaders.ACCEPT, Collections.singletonList(MediaType.WILDCARD));
}
}
}

0 comments on commit d3bd8d5

Please sign in to comment.