Skip to content

Commit

Permalink
TCK Changes for URI and hasEntity checks
Browse files Browse the repository at this point in the history
Signed-off-by: Andy McCright <[email protected]>
  • Loading branch information
andymc12 committed Sep 18, 2020
1 parent e62f626 commit 88104ed
Show file tree
Hide file tree
Showing 2 changed files with 169 additions and 26 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import javax.ws.rs.core.UriInfo;

import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.io.DelegatingInputStream;
import org.apache.cxf.jaxrs.utils.ExceptionUtils;
import org.apache.cxf.jaxrs.utils.HttpUtils;
import org.apache.cxf.message.Message;
Expand Down Expand Up @@ -68,12 +69,21 @@ public UriInfo getUriInfo() {

@Override
public boolean hasEntity() {
InputStream is = getEntityStream();
if (is == null) {
return false;
}
// Is Content-Length is explicitly set to 0 ?
if (HttpUtils.isPayloadEmpty(getHeaders())) {
return false;
}

if (is instanceof DelegatingInputStream) {
((DelegatingInputStream) is).cacheInput();
}

try {
return !IOUtils.isEmpty(getEntityStream());
return !IOUtils.isEmpty(is);
} catch (IOException ex) {
throw ExceptionUtils.toInternalServerErrorException(ex, null);
}
Expand All @@ -85,6 +95,7 @@ public void setEntityStream(InputStream is) {
m.setContent(InputStream.class, is);
}

@Override
public MultivaluedMap<String, String> getHeaders() {
h = null;
return HttpUtils.getModifiableStringHeaders(m);
Expand Down Expand Up @@ -112,7 +123,8 @@ public void setRequestUri(URI requestUri) throws IllegalStateException {

protected void doSetRequestUri(URI requestUri) throws IllegalStateException {
checkNotPreMatch();
HttpUtils.resetRequestURI(m, requestUri.getRawPath());
// The JAX-RS TCK requires the full uri toString() rather than just the raw path:
HttpUtils.resetRequestURI(m, requestUri.toString());
String query = requestUri.getRawQuery();
if (query != null) {
m.put(Message.QUERY_STRING, query);
Expand Down
Loading

0 comments on commit 88104ed

Please sign in to comment.