Skip to content

Commit

Permalink
[sony] Fix IllegalArgumentException on icon channels refresh
Browse files Browse the repository at this point in the history
  • Loading branch information
falkena committed Jul 15, 2024
1 parent 5c9d4c1 commit 199fbf0
Showing 1 changed file with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Objects;
Expand All @@ -27,6 +28,7 @@
import javax.ws.rs.client.Entity;
import javax.ws.rs.client.Invocation.Builder;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.core.Response;

import org.eclipse.jdt.annotation.NonNullByDefault;
Expand Down Expand Up @@ -93,14 +95,18 @@ public void register(final Object obj) {
public HttpResponse sendGetCommand(final String url, final Header... rqstHeaders) {
SonyUtil.validateNotEmpty(url, "url cannot be empty");
try {
final Builder rqst = addHeaders(client.target(url).request(), rqstHeaders);
final Response content = rqst.get();

try {
final HttpResponse httpResponse = new HttpResponse(content);
return httpResponse;
} finally {
content.close();
final Builder request = addHeaders(client.target(url).request(), rqstHeaders);
try (final Response response = request.get()) {
// Sony may report ill-formed content response
final MultivaluedMap<String, Object> metadata = response.getMetadata();
final List<Object> content = metadata.get("Content-Type");
for (int index = 0; index < content.size(); index++) {
if (content.get(index) instanceof String entry) {
content.set(index, entry.replaceAll(".+:", "").trim());
}
}
metadata.put("Content-Type", content);
return new HttpResponse(Response.fromResponse(response).replaceAll(metadata).build());
}
} catch (ProcessingException | IllegalStateException | IOException e) {
logger.debug("Exception in sendGetCommand: {}", e.getMessage());
Expand Down

0 comments on commit 199fbf0

Please sign in to comment.