Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use single OkHttp client #202

Merged
merged 1 commit into from
Sep 7, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading