Skip to content

Commit

Permalink
Handle no-content response in DefaultHttpJsonRequest (eclipse-che#5577)
Browse files Browse the repository at this point in the history
Signed-off-by: Dmytro Nochevnov <dnochevnov@codenvy.com>
  • Loading branch information
dmytro-ndp committed Jul 10, 2017
1 parent ab1ca07 commit b68c3aa
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
import org.eclipse.che.api.core.rest.shared.dto.ServiceError;
import org.eclipse.che.commons.env.EnvironmentContext;
import org.eclipse.che.commons.lang.Pair;
import org.eclipse.che.commons.subject.Subject;
import org.eclipse.che.dto.server.DtoFactory;
import org.eclipse.che.dto.server.JsonArrayImpl;
import org.eclipse.che.dto.server.JsonSerializable;
Expand Down Expand Up @@ -281,7 +280,9 @@ protected DefaultHttpJsonResponse doRequest(int timeout,
UriBuilder.fromUri(url).replaceQuery("token").build(), method, responseCode, str));
}
final String contentType = conn.getContentType();
if (contentType != null && !contentType.startsWith(MediaType.APPLICATION_JSON)) {
if (responseCode != HttpURLConnection.HTTP_NO_CONTENT
&& contentType != null
&& !contentType.startsWith(MediaType.APPLICATION_JSON)) {
throw new IOException(conn.getResponseMessage());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ public void shouldThrowIOExceptionIfServerReturnsTypeDifferentFromApplicationJso
new DefaultHttpJsonRequest(getUrl(ctx) + "/text-plain").useGetMethod().request();
}

@Test
public void shouldThrowIOExceptionIfServerDoesNotReturnContentTypeOnNoContentResponse(ITestContext ctx) throws Exception {
new DefaultHttpJsonRequest(getUrl(ctx) + "/no-content").useDeleteMethod().request();
}

@Test
public void shouldReadJsonObjectBodyAsString(ITestContext ctx) throws Exception {
final DefaultHttpJsonRequest request = new DefaultHttpJsonRequest(getUrl(ctx) + "/application-json");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.eclipse.che.dto.server.DtoFactory;
import org.eclipse.che.dto.server.JsonArrayImpl;

import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.HeaderParam;
import javax.ws.rs.POST;
Expand Down Expand Up @@ -126,4 +127,11 @@ public Response getStringList(@PathParam("value") String value, @QueryParam("que
.header("Link", createLinkHeader(page, "getStringList", singletonMap("query-param", param), value))
.build();
}

@DELETE
@Path("no-content")
public Response noContent() {
return Response.noContent()
.build();
}
}

0 comments on commit b68c3aa

Please sign in to comment.