Skip to content

Commit d4f362d

Browse files
authored
Merge pull request #203 from digipost/get-path
Hent path uten å hente query params
2 parents f426687 + 48570e3 commit d4f362d

4 files changed

Lines changed: 14 additions & 12 deletions

File tree

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)