Skip to content
This repository has been archived by the owner on Dec 13, 2023. It is now read-only.

Commit

Permalink
handle 204 during GET
Browse files Browse the repository at this point in the history
  • Loading branch information
aravindanr committed Jun 28, 2022
1 parent a99e939 commit 83841ac
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 7 deletions.
3 changes: 2 additions & 1 deletion client/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,9 @@ configurations.all {
}

dependencies {
implementation project(':conductor-common')
compileOnly 'org.jetbrains:annotations:23.0.0'

implementation project(':conductor-common')
implementation "com.sun.jersey:jersey-client:${revJersey}"

implementation "com.netflix.spectator:spectator-api:${revSpectator}"
Expand Down
3 changes: 3 additions & 0 deletions client/dependencies.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@
"org.apache.logging.log4j:log4j-web": {
"locked": "2.17.1"
},
"org.jetbrains:annotations": {
"locked": "23.0.0"
},
"org.slf4j:slf4j-api": {
"locked": "1.7.36"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
import java.nio.charset.StandardCharsets;
import java.util.Collection;
import java.util.Map;
import java.util.Optional;

import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriBuilder;
Expand Down Expand Up @@ -148,17 +149,19 @@ protected String postForString(

protected <T> T getForEntity(
String url, Object[] queryParams, Class<T> responseType, Object... uriVariables) {
InputStream response = getForEntity(url, queryParams, uriVariables);
return convertToType(response, responseType);
return getForEntity(url, queryParams, uriVariables)
.map(inputStream -> convertToType(inputStream, responseType))
.orElse(null);
}

protected <T> T getForEntity(
String url,
Object[] queryParams,
TypeReference<T> responseType,
Object... uriVariables) {
InputStream response = getForEntity(url, queryParams, uriVariables);
return convertToType(response, responseType);
return getForEntity(url, queryParams, uriVariables)
.map(inputStream -> convertToType(inputStream, responseType))
.orElse(null);
}

/**
Expand Down Expand Up @@ -243,10 +246,11 @@ protected boolean isNewerJacksonVersion() {
return version.getMajorVersion() == 2 && version.getMinorVersion() >= 12;
}

private InputStream getForEntity(String url, Object[] queryParams, Object... uriVariables) {
private Optional<InputStream> getForEntity(
String url, Object[] queryParams, Object... uriVariables) {
URI uri = getURIBuilder(getFullUrl(url), queryParams).build(uriVariables);
try {
return requestHandler.get(uri);
return Optional.ofNullable(requestHandler.get(uri));
} catch (RequestHandlerException rhe) {
throw createClientException(rhe);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,19 @@
import java.io.InputStream;
import java.net.URI;

import org.jetbrains.annotations.Nullable;

import com.netflix.conductor.client.exception.RequestHandlerException;

public interface RequestHandler {
void delete(URI uri) throws RequestHandlerException;

@Nullable
InputStream put(URI uri, Object body) throws RequestHandlerException;

@Nullable
InputStream post(URI uri, Object body) throws RequestHandlerException;

@Nullable
InputStream get(URI uri) throws RequestHandlerException;
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import javax.ws.rs.core.MediaType;

import org.jetbrains.annotations.Nullable;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -96,6 +97,7 @@ public void delete(URI uri) {
}

@Override
@Nullable
public InputStream put(URI uri, Object body) {
ClientResponse clientResponse;
try {
Expand All @@ -109,6 +111,7 @@ public InputStream put(URI uri, Object body) {
}

@Override
@Nullable
public InputStream post(URI uri, Object body) {
ClientResponse clientResponse;
try {
Expand All @@ -123,13 +126,27 @@ public InputStream post(URI uri, Object body) {
}

@Override
@Nullable
public InputStream get(URI uri) {
ClientResponse clientResponse;
try {
clientResponse =
client.resource(uri)
.accept(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN)
.get(ClientResponse.class);

// this condition mimics what ClientResponse.getEntity() and ClientBase.getForEntity()
// did before RequestHandler was introduced.
// Previously, ClientBase.getForEntity() called ClientResponse.getEntity()
// which threw a UniformInterfaceException for 204. The
// handleUniformInterfaceException() method did nothing except call close() on
// ClientResponse.
// the same is done below
if (clientResponse.getStatus() == 204) {
clientResponse.close();
return null;
}

if (clientResponse.getStatus() < 300) {
return clientResponse.getEntityInputStream();
} else {
Expand Down

0 comments on commit 83841ac

Please sign in to comment.