|
16 | 16 | package com.unzer.payment.communication.impl; |
17 | 17 |
|
18 | 18 | import com.unzer.payment.communication.UnzerHttpRequest; |
19 | | -import org.apache.http.HttpEntity; |
20 | | -import org.apache.http.HttpEntityEnclosingRequest; |
21 | | -import org.apache.http.client.methods.*; |
22 | | -import org.apache.http.entity.StringEntity; |
| 19 | +import org.apache.hc.client5.http.classic.methods.*; |
| 20 | +import org.apache.hc.core5.http.ClassicHttpRequest; |
| 21 | +import org.apache.hc.core5.http.ContentType; |
| 22 | +import org.apache.hc.core5.http.io.entity.StringEntity; |
23 | 23 |
|
24 | 24 | import java.net.URI; |
| 25 | +import java.net.URISyntaxException; |
25 | 26 |
|
26 | 27 | /** |
27 | 28 | * Implementation of the {@code UnzerHttpRequest} wrapping an apache |
|
35 | 36 | */ |
36 | 37 | public class HttpClientBasedHttpRequest implements UnzerHttpRequest { |
37 | 38 |
|
38 | | - protected HttpUriRequest request; |
| 39 | + protected ClassicHttpRequest request; |
39 | 40 | protected UnzerHttpMethod method; |
40 | 41 |
|
41 | 42 | /** |
42 | 43 | * Creates a {@code HttpClientBasedHttpRequest} wrapping a |
43 | 44 | * {@code HttpUriRequest} defined by the given {@code UnzerHttpMethod}. |
44 | 45 | * |
45 | | - * @param uri |
46 | | - * - the RUI of the request |
47 | | - * @param method |
48 | | - * - the {@code UnzerHttpMethod} representing one of |
49 | | - * {@code HttpGet}, {@code HttpPost}, {@code HttpPut}, |
50 | | - * {@code HttpDelete} |
| 46 | + * @param uri - the RUI of the request |
| 47 | + * @param method - the {@code UnzerHttpMethod} representing one of |
| 48 | + * {@code HttpGet}, {@code HttpPost}, {@code HttpPut}, |
| 49 | + * {@code HttpDelete} |
51 | 50 | */ |
52 | 51 | public HttpClientBasedHttpRequest(String uri, UnzerHttpMethod method) { |
53 | 52 | this.method = method; |
@@ -77,24 +76,28 @@ public void addHeader(String header, String value) { |
77 | 76 | } |
78 | 77 |
|
79 | 78 | /** |
80 | | - * Returns the wrapped {@code HttpUriRequest} to be passed to the {@code HttpClient} within the {@code HttpClientBasedRestCommunication} implementation. |
81 | | - * @return - the the wrapped {@code HttpUriRequest} |
| 79 | + * Returns the wrapped {@code HttpUriRequest} to be passed to the {@code HttpClient} within the {@code HttpClientBasedRestCommunication} implementation. |
| 80 | + * |
| 81 | + * @return - the the wrapped {@code HttpUriRequest} |
82 | 82 | */ |
83 | | - public HttpUriRequest getRequest() { |
| 83 | + public ClassicHttpRequest getRequest() { |
84 | 84 | return request; |
85 | 85 | } |
86 | 86 |
|
87 | 87 | @Override |
88 | | - public URI getURI() { |
89 | | - return request.getURI(); |
| 88 | + public URI getURI() throws URISyntaxException { |
| 89 | + return request.getUri(); |
90 | 90 | } |
91 | 91 |
|
92 | 92 | @Override |
93 | 93 | public void setContent(String content, String encoding) { |
94 | | - if (request instanceof HttpEntityEnclosingRequest) { |
95 | | - HttpEntity entity = new StringEntity(content, encoding); |
96 | | - ((HttpEntityEnclosingRequest) request).setEntity(entity); |
97 | | - } |
| 94 | + StringEntity entity = new StringEntity( |
| 95 | + content, |
| 96 | + ContentType.APPLICATION_JSON, |
| 97 | + encoding, |
| 98 | + false |
| 99 | + ); |
| 100 | + request.setEntity(entity); |
98 | 101 | } |
99 | 102 |
|
100 | 103 | @Override |
|
0 commit comments