Skip to content

Commit

Permalink
Merge pull request #202 from oaplatform/single-client
Browse files Browse the repository at this point in the history
use single OkHttp client
  • Loading branch information
alebastrov authored Sep 7, 2023
2 parents 15f4f1d + 93cba07 commit 57cd5e5
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
14 changes: 6 additions & 8 deletions oap-stdlib/src/main/java/oap/http/Client.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,6 @@
import oap.util.Throwables;
import oap.util.function.Try;
import oap.util.function.Try.ThrowingRunnable;
import okhttp3.RequestBody;
import okio.Buffer;
import org.apache.http.Header;
import org.apache.http.HttpResponse;
import org.apache.http.NameValuePair;
Expand Down Expand Up @@ -309,12 +307,12 @@ public Response post( String uri, byte[] content, String contentType, Map<String
.orElseThrow( () -> new RuntimeException( NO_RESPONSE ) );
}

@SneakyThrows
public Response uploadFile( String uri, RequestBody body, Map<String, Object> headers ) {
Buffer sink = new Buffer();
body.writeTo( sink );
return post( uri, sink.readByteArray(), ContentType.MULTIPART_FORM_DATA.getMimeType(), headers );
}
// @SneakyThrows
// public Response uploadFile( String uri, okhttp3.RequestBody body, Map<String, Object> headers ) {
// okio.Buffer sink = new okio.Buffer();
// body.writeTo( sink );
// return post( uri, sink.readByteArray(), ContentType.MULTIPART_FORM_DATA.getMimeType(), headers );
// }

private Optional<Response> getResponse( HttpRequestBase request, long timeout, CompletableFuture<Response> future ) {
try {
Expand Down
13 changes: 6 additions & 7 deletions oap-stdlib/src/main/java/oap/http/testng/HttpAsserts.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@
import oap.util.BiStream;
import oap.util.Pair;
import oap.util.Stream;
import okhttp3.RequestBody;
import org.joda.time.DateTime;

import java.io.InputStream;
Expand Down Expand Up @@ -117,13 +116,13 @@ public static HttpAssertion assertPost( String uri, InputStream content, String
return assertHttpResponse( client.post( uri, content, contentType, headers ) );
}

public static HttpAssertion assertUploadFile( String uri, RequestBody body ) {
return new HttpAssertion( client.uploadFile( uri, body, Map.of() ) );
}
// public static HttpAssertion assertUploadFile( String uri, RequestBody body ) {
// return new HttpAssertion( client.uploadFile( uri, body, Map.of() ) );
// }

public static HttpAssertion assertUploadFile( String uri, RequestBody body, Map<String, Object> headers ) {
return new HttpAssertion( client.uploadFile( uri, body, headers ) );
}
// public static HttpAssertion assertUploadFile( String uri, RequestBody body, Map<String, Object> headers ) {
// return new HttpAssertion( client.uploadFile( uri, body, headers ) );
// }

public static HttpAssertion assertPut( String uri, String content, String contentType ) {
return assertHttpResponse( client.put( uri, content, contentType ) );
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

<properties>

<oap.project.version>18.11.6.1</oap.project.version>
<oap.project.version>18.11.6.2</oap.project.version>

<oap.deps.testng.version>7.8.0</oap.deps.testng.version>
<oap.deps.assertj.version>3.24.2</oap.deps.assertj.version>
Expand Down

0 comments on commit 57cd5e5

Please sign in to comment.