Fix HawkbitClient multipart support for return void (#2258)

Signed-off-by: Avgustin Marinov <Avgustin.Marinov@bosch.com>
This commit is contained in:
Avgustin Marinov
2025-01-30 11:06:07 +02:00
committed by GitHub
parent 33e863181a
commit 9418eb42cb

View File

@@ -68,16 +68,15 @@ public class HawkbitClient {
Objects.requireNonNull(tenant.getPassword(), Objects.requireNonNull(tenant.getPassword(),
"Password is not available!")) "Password is not available!"))
.getBytes(StandardCharsets.ISO_8859_1))) .getBytes(StandardCharsets.ISO_8859_1)))
: : template -> {
template -> { if (ObjectUtils.isEmpty(tenant.getGatewayToken())) {
if (ObjectUtils.isEmpty(tenant.getGatewayToken())) {
if (!ObjectUtils.isEmpty(controller.getSecurityToken())) { if (!ObjectUtils.isEmpty(controller.getSecurityToken())) {
template.header(AUTHORIZATION, "TargetToken " + controller.getSecurityToken()); template.header(AUTHORIZATION, "TargetToken " + controller.getSecurityToken());
} // else do not sent authentication } // else do not send authentication
} else { } else {
template.header(AUTHORIZATION, "GatewayToken " + tenant.getGatewayToken()); template.header(AUTHORIZATION, "GatewayToken " + tenant.getGatewayToken());
} }
}; };
private static final ErrorDecoder DEFAULT_ERROR_DECODER_0 = new ErrorDecoder.Default(); private static final ErrorDecoder DEFAULT_ERROR_DECODER_0 = new ErrorDecoder.Default();
public static final ErrorDecoder DEFAULT_ERROR_DECODER = (methodKey, response) -> { public static final ErrorDecoder DEFAULT_ERROR_DECODER = (methodKey, response) -> {
final Exception e = DEFAULT_ERROR_DECODER_0.decode(methodKey, response); final Exception e = DEFAULT_ERROR_DECODER_0.decode(methodKey, response);
@@ -209,12 +208,16 @@ public class HawkbitClient {
out.write(("--" + boundary + "--\r\n").getBytes(StandardCharsets.UTF_8)); out.write(("--" + boundary + "--\r\n").getBytes(StandardCharsets.UTF_8));
} }
return method.getReturnType() == ResponseEntity.class return method.getReturnType() == ResponseEntity.class
? new ResponseEntity<Object>( ? new ResponseEntity<>(
objectMapper.readValue( deserialize(
conn.getInputStream(), conn.getInputStream(),
(Class<?>) ((ParameterizedType) method.getGenericReturnType()).getActualTypeArguments()[0]), (Class<?>) ((ParameterizedType) method.getGenericReturnType()).getActualTypeArguments()[0],
objectMapper),
HttpStatusCode.valueOf(conn.getResponseCode())) HttpStatusCode.valueOf(conn.getResponseCode()))
: objectMapper.readValue(conn.getInputStream(), method.getReturnType()); : deserialize(conn.getInputStream(), method.getReturnType(), objectMapper);
}
private Object deserialize(final InputStream is, final Class<?> type, final ObjectMapper objectMapper) throws IOException {
return type == void.class || type == Void.class ? null : objectMapper.readValue(is, type);
} }
private void writeMultipartFile( private void writeMultipartFile(