Skip to content

Commit 48570e3

Browse files
committed
Get path without getting query params and fix response handler
`getPath` directly get the path with query params which is not the same as the old behavior. Were doing error handling inside the response handler. This is not needed as correct error handling is done outside
1 parent f426687 commit 48570e3

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

src/main/java/no/digipost/api/client/internal/ApiServiceImpl.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -609,17 +609,12 @@ private CloseableHttpResponse sendDigipostMedia(Object data, String uri) {
609609

610610
private HttpClientResponseHandler<CloseableHttpResponse> responseHandler() {
611611
return response -> {
612-
if (response.getCode() / 100 == 2) {
613612
if (response instanceof CloseableHttpResponse) {
614613
return (CloseableHttpResponse) response;
615614
} else {
616615
throw new DigipostClientException(ErrorCode.GENERAL_ERROR,
617616
"Expected response to be instance of CloseableHttpResponse, but got " + response.getClass().getName());
618617
}
619-
} else {
620-
ErrorMessage errorMessage = unmarshal(jaxbContext, response.getEntity().getContent(), ErrorMessage.class);
621-
throw new DigipostClientException(errorMessage);
622-
}
623618
};
624619
}
625620
}

src/main/java/no/digipost/api/client/internal/http/request/interceptor/ApacheHttpRequestToSign.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,12 @@ public SortedMap<String, String> getHeaders() {
4848

4949
@Override
5050
public String getPath() {
51-
String path = clientRequest.getPath();
52-
return path != null ? path : "";
51+
try {
52+
String path = clientRequest.getUri().getPath();
53+
return path != null ? path : "";
54+
} catch (URISyntaxException e) {
55+
throw new RuntimeException(e.getMessage(), e);
56+
}
5357
}
5458

5559
@Override

src/main/java/no/digipost/api/client/internal/http/response/HttpResponseUtils.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.apache.hc.core5.http.HttpResponse;
2929
import org.apache.hc.core5.http.HttpStatus;
3030
import org.apache.hc.core5.http.io.entity.EntityUtils;
31+
import org.apache.hc.core5.http.message.StatusLine;
3132

3233
import java.io.ByteArrayInputStream;
3334
import java.io.IOException;
@@ -92,10 +93,7 @@ public static void checkResponse(ClassicHttpResponse response, EventLogger event
9293
}
9394

9495
private static ErrorMessage fetchErrorMessageString(final HttpResponse response, final HttpEntity responseEntity) {
95-
String statusLine = response.getVersion() + " " + response.getCode();
96-
if (StringUtils.isNotBlank(response.getReasonPhrase())) {
97-
statusLine += " " + response.getReasonPhrase();
98-
}
96+
StatusLine statusLine = new StatusLine(response);
9997
final ErrorType errorType = ErrorType.fromResponseStatus(response.getCode());
10098
if (responseEntity == null) {
10199
return new ErrorMessage(errorType, "status=" + statusLine + ", body=<empty>");

src/main/java/no/digipost/api/client/internal/http/response/interceptor/ApacheHttpResponseToVerify.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,11 @@ public SortedMap<String, String> getHeaders() {
4949

5050
@Override
5151
public String getPath() {
52-
return (String) context.getAttribute("request-path");
52+
String pathWithQueryParams = (String) context.getAttribute("request-path");
53+
int indexOfQuestionMark = pathWithQueryParams.indexOf('?');
54+
if (indexOfQuestionMark != -1) {
55+
return pathWithQueryParams.substring(0, indexOfQuestionMark);
56+
}
57+
return pathWithQueryParams;
5358
}
5459
}

0 commit comments

Comments
 (0)