Skip to content

Commit

Permalink
Fiks feil i generic parsing (#58)
Browse files Browse the repository at this point in the history
* bump parent

* Fiks for generic feil

* Fiks for generic feil

* Ikke ta head^2

* Fjern codeql workflow
  • Loading branch information
zapodot authored Mar 16, 2021
1 parent 31d0aef commit b2a24ac
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 80 deletions.
71 changes: 0 additions & 71 deletions .github/workflows/codeql-analysis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<groupId>no.ks.fiks.pom</groupId>
<artifactId>fiks-ekstern-super-pom</artifactId>
<version>0.0.10</version>
<version>0.0.11</version>
</parent>
<groupId>no.ks.fiks</groupId>
<artifactId>streaming-klient</artifactId>
Expand Down
28 changes: 20 additions & 8 deletions src/main/java/no/ks/fiks/streaming/klient/StreamingKlient.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,34 +48,46 @@ public StreamingKlient(AuthenticationStrategy authenticationStrategy, Long liste
}
}

public <T> KlientResponse<T> sendRequest(MultiPartContentProvider contentProvider, HttpMethod httpMethod, String baseUrl, String path, List<HttpHeader> headers, TypeReference returnType) {
public <T> KlientResponse<T> sendRequest(MultiPartContentProvider contentProvider, HttpMethod httpMethod, String baseUrl, String path, List<HttpHeader> headers, TypeReference<T> returnType) {
InputStreamResponseListener listener = sendRequestReturnResponseListener(contentProvider, httpMethod, baseUrl, path, headers);

try {
Response response = listener.get(listenerTimeout, listenerTimeUnit);
final Response response = awaitResponse(listener);
int status = response.getStatus();
if (isError(status)) {
String content = IOUtils.toString(listener.getInputStream(), StandardCharsets.UTF_8);
throw new KlientHttpException(String.format("HTTP-feil (%d): %s", status, content), status, content);
}
return buildResponse(response, returnType != null ? objectMapper.readValue(listener.getInputStream(), returnType) : null);
} catch (InterruptedException | TimeoutException | ExecutionException | IOException e) {
throw new RuntimeException("Feil under invokering av api", e);
try(final InputStream input = listener.getInputStream()) {
return buildResponse(response, returnType != null ? objectMapper.readValue(input, returnType) : null);
}
} catch (IOException e) {
throw new RuntimeException("Feil under lesing av datastrøm", e);
}
}

public KlientResponse<InputStream> sendDownloadRequest(MultiPartContentProvider contentProvider, HttpMethod httpMethod, String baseUrl, String path, List<HttpHeader> headers) {
InputStreamResponseListener listener = sendRequestReturnResponseListener(contentProvider, httpMethod, baseUrl, path, headers);

try {
Response response = listener.get(listenerTimeout, listenerTimeUnit);
Response response = awaitResponse(listener);
int status = response.getStatus();
if (isError(status)) {
String content = IOUtils.toString(listener.getInputStream(), StandardCharsets.UTF_8);
throw new KlientHttpException(String.format("HTTP-feil (%d): %s", status, content), status, content);
}
return buildResponse(response, listener.getInputStream());
} catch (InterruptedException | TimeoutException | ExecutionException | IOException e) {
try(final InputStream input = listener.getInputStream()) {
return buildResponse(response, input);
}
} catch (IOException e) {
throw new RuntimeException("Feil under lesing av datastrøm", e);
}
}

private Response awaitResponse(InputStreamResponseListener listener) {
try {
return listener.get(listenerTimeout, listenerTimeUnit);
} catch (InterruptedException | TimeoutException | ExecutionException e) {
throw new RuntimeException("Feil under invokering av api", e);
}
}
Expand Down

0 comments on commit b2a24ac

Please sign in to comment.