Skip to content

Commit

Permalink
changed RequestBody.create to put content type arg second - fixes dep…
Browse files Browse the repository at this point in the history
…recation warning (hyperledger#4936)

Signed-off-by: Sally MacFarlane <macfarla.github@gmail.com>
  • Loading branch information
macfarla authored and elenduuche committed Aug 16, 2023
1 parent b2db033 commit 0fff00f
Show file tree
Hide file tree
Showing 10 changed files with 161 additions and 161 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ String send(final String username, final String password) throws IOException {
private Request loginRequest(final String username, final String password) {
final RequestBody requestBody =
RequestBody.create(
JSON, String.format("{\"username\":\"%s\",\"password\":\"%s\"}", username, password));
String.format("{\"username\":\"%s\",\"password\":\"%s\"}", username, password), JSON);
return new Request.Builder().post(requestBody).url(loginUri()).build();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void requestWithUnknownHostIsRejected() throws IOException {
}

private int doRequest(final String hostname) throws IOException {
final RequestBody body = RequestBody.create(GRAPHQL, "{maxPriorityFeePerGas}");
final RequestBody body = RequestBody.create("{maxPriorityFeePerGas}", GRAPHQL);

final Request build =
new Request.Builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private void jsonRPCCall(final URL specFile) throws IOException {
final ObjectNode specNode = (ObjectNode) objectMapper.readTree(json);
final String rawRequestBody = specNode.get("request").toString();

final RequestBody requestBody = RequestBody.create(JSON, rawRequestBody);
final RequestBody requestBody = RequestBody.create(rawRequestBody, JSON);
final Request request = new Request.Builder().post(requestBody).url(baseUrl).build();

try (final Response resp = client.newCall(request).execute()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ public void getPeers() throws Exception {
final String id = "123";
final RequestBody body =
RequestBody.create(
JSON,
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"admin_peers\"}");
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"admin_peers\"}",
JSON);
final Request request = new Request.Builder().post(body).url(baseUrl).build();
LOG.info("Request: " + request);
try (final Response resp = client.newCall(request).execute()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -189,8 +189,8 @@ public void requestWithUnknownHostIsRejected() throws IOException {
private int doRequest(final String hostname) throws IOException {
final RequestBody body =
RequestBody.create(
JSON,
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode("123") + ",\"method\":\"net_version\"}");
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode("123") + ",\"method\":\"net_version\"}",
JSON);

final Request build =
new Request.Builder().post(body).url(baseUrl).addHeader("Host", hostname).build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@ public static void shutdownServer() {
@Test
public void loginWithBadCredentials() throws IOException {
final RequestBody body =
RequestBody.create(JSON, "{\"username\":\"user\",\"password\":\"badpass\"}");
RequestBody.create("{\"username\":\"user\",\"password\":\"badpass\"}", JSON);
final Request request = new Request.Builder().post(body).url(baseUrl + "/login").build();
try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(401);
Expand All @@ -213,7 +213,7 @@ public void loginWithBadCredentials() throws IOException {
@Test
public void loginWithGoodCredentials() throws IOException {
final RequestBody body =
RequestBody.create(JSON, "{\"username\":\"user\",\"password\":\"pegasys\"}");
RequestBody.create("{\"username\":\"user\",\"password\":\"pegasys\"}", JSON);
final Request request = new Request.Builder().post(body).url(baseUrl + "/login").build();
try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200);
Expand Down Expand Up @@ -247,7 +247,7 @@ public void loginWithGoodCredentials() throws IOException {
@Test
public void loginWithGoodCredentialsAndPermissions() throws IOException {
final RequestBody body =
RequestBody.create(JSON, "{\"username\":\"user\",\"password\":\"pegasys\"}");
RequestBody.create("{\"username\":\"user\",\"password\":\"pegasys\"}", JSON);
final Request request = new Request.Builder().post(body).url(baseUrl + "/login").build();
try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200);
Expand Down Expand Up @@ -288,7 +288,7 @@ public void loginWithGoodCredentialsAndPermissions() throws IOException {
public void loginDoesntPopulateJWTPayloadWithPassword()
throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
final RequestBody body =
RequestBody.create(JSON, "{\"username\":\"user\",\"password\":\"pegasys\"}");
RequestBody.create("{\"username\":\"user\",\"password\":\"pegasys\"}", JSON);
final Request request = new Request.Builder().post(body).url(baseUrl + "/login").build();
try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200);
Expand All @@ -315,7 +315,7 @@ public void loginDoesntPopulateJWTPayloadWithPassword()
public void loginPopulatesJWTPayloadWithRequiredValues()
throws IOException, KeyStoreException, CertificateException, NoSuchAlgorithmException {
final RequestBody body =
RequestBody.create(JSON, "{\"username\":\"user\",\"password\":\"pegasys\"}");
RequestBody.create("{\"username\":\"user\",\"password\":\"pegasys\"}", JSON);
final Request request = new Request.Builder().post(body).url(baseUrl + "/login").build();
try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200);
Expand Down Expand Up @@ -348,7 +348,7 @@ public void loginPopulatesJWTPayloadWithRequiredValues()
private String login(final String username, final String password) throws IOException {
final RequestBody loginBody =
RequestBody.create(
JSON, "{\"username\":\"" + username + "\",\"password\":\"" + password + "\"}");
"{\"username\":\"" + username + "\",\"password\":\"" + password + "\"}", JSON);
final Request loginRequest =
new Request.Builder().post(loginBody).url(baseUrl + "/login").build();
final String token;
Expand All @@ -372,7 +372,7 @@ private String login(final String username, final String password) throws IOExce
@Test
public void checkJsonRpcMethodsAvailableWithGoodCredentialsAndPermissions() throws IOException {
final RequestBody body =
RequestBody.create(JSON, "{\"username\":\"user\",\"password\":\"pegasys\"}");
RequestBody.create("{\"username\":\"user\",\"password\":\"pegasys\"}", JSON);
final Request request = new Request.Builder().post(body).url(baseUrl + "/login").build();
try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200);
Expand Down Expand Up @@ -441,7 +441,7 @@ public void checkJsonRpcMethodsAvailableWithGoodCredentialsAndPermissions() thro
public void checkJsonRpcMethodsAvailableWithGoodCredentialsAndAllPermissions()
throws IOException {
final RequestBody body =
RequestBody.create(JSON, "{\"username\":\"adminuser\",\"password\":\"pegasys\"}");
RequestBody.create("{\"username\":\"adminuser\",\"password\":\"pegasys\"}", JSON);
final Request request = new Request.Builder().post(body).url(baseUrl + "/login").build();
try (final Response resp = client.newCall(request).execute()) {
assertThat(resp.code()).isEqualTo(200);
Expand Down Expand Up @@ -524,10 +524,10 @@ public void web3ClientVersionUnsuccessfulBeforeLogin() throws Exception {
final String id = "123";
final RequestBody body =
RequestBody.create(
JSON,
"{\"jsonrpc\":\"2.0\",\"id\":"
+ Json.encode(id)
+ ",\"method\":\"web3_clientVersion\"}");
+ ",\"method\":\"web3_clientVersion\"}",
JSON);

try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(401);
Expand All @@ -540,10 +540,10 @@ public void web3ClientVersionUnsuccessfulWithBadBearer() throws Exception {
final String id = "123";
final RequestBody body =
RequestBody.create(
JSON,
"{\"jsonrpc\":\"2.0\",\"id\":"
+ Json.encode(id)
+ ",\"method\":\"web3_clientVersion\"}");
+ ",\"method\":\"web3_clientVersion\"}",
JSON);

try (final Response resp = client.newCall(buildPostRequest(body, "badtoken")).execute()) {
assertThat(resp.code()).isEqualTo(401);
Expand All @@ -558,10 +558,10 @@ public void web3ClientVersionSuccessfulAfterLogin() throws Exception {
final String id = "123";
final RequestBody web3ClientVersionBody =
RequestBody.create(
JSON,
"{\"jsonrpc\":\"2.0\",\"id\":"
+ Json.encode(id)
+ ",\"method\":\"web3_clientVersion\"}");
+ ",\"method\":\"web3_clientVersion\"}",
JSON);

try (final Response web3ClientVersionResp =
client.newCall(buildPostRequest(web3ClientVersionBody, token)).execute()) {
Expand All @@ -582,8 +582,8 @@ public void noAuthMethodSuccessfulAfterLogin() throws Exception {
final String id = "123";
final RequestBody requestBody =
RequestBody.create(
JSON,
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_services\"}");
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_services\"}",
JSON);

try (final Response response = client.newCall(buildPostRequest(requestBody, token)).execute()) {
assertThat(response.code()).isEqualTo(200);
Expand All @@ -597,8 +597,8 @@ public void noAuthMethodSuccessfulWithNoToken() throws Exception {
final String id = "123";
final RequestBody requestBody =
RequestBody.create(
JSON,
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_services\"}");
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_services\"}",
JSON);

try (final Response response = client.newCall(buildPostRequest(requestBody)).execute()) {
assertThat(response.code()).isEqualTo(200);
Expand All @@ -614,8 +614,8 @@ public void ethSyncingUnauthorisedWithoutPermission() throws Exception {
final String id = "007";
final RequestBody body =
RequestBody.create(
JSON,
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_syncing\"}");
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"eth_syncing\"}",
JSON);

try (final Response resp = client.newCall(buildPostRequest(body, token)).execute()) {
assertThat(resp.code()).isEqualTo(401);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public static Collection<Object[]> data() {

@Test
public void invalidJsonShouldReturnParseError() throws Exception {
final RequestBody body = RequestBody.create(JSON, requestJson);
final RequestBody body = RequestBody.create(requestJson, JSON);

try (final Response resp = client.newCall(buildPostRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(400);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -120,8 +120,8 @@ public void requestWithNetMethodShouldSucceedWhenDefaultApisEnabled() throws Exc
final String id = "123";
final RequestBody body =
RequestBody.create(
JSON,
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}");
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}",
JSON);

try (final Response resp = client.newCall(buildRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(200);
Expand All @@ -134,8 +134,8 @@ public void requestWithNetMethodShouldSucceedWhenNetApiIsEnabled() throws Except
final String id = "123";
final RequestBody body =
RequestBody.create(
JSON,
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}");
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}",
JSON);

try (final Response resp = client.newCall(buildRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(200);
Expand All @@ -149,8 +149,8 @@ public void requestWithNetMethodShouldSuccessWithCode200WhenNetApiIsNotEnabled()
final String id = "123";
final RequestBody body =
RequestBody.create(
JSON,
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}");
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}",
JSON);

try (final Response resp = client.newCall(buildRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(200);
Expand All @@ -168,8 +168,8 @@ public void requestWithNetMethodShouldSucceedWhenNetApiAndOtherIsEnabled() throw
final String id = "123";
final RequestBody body =
RequestBody.create(
JSON,
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}");
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_version\"}",
JSON);

try (final Response resp = client.newCall(buildRequest(body)).execute()) {
assertThat(resp.code()).isEqualTo(200);
Expand Down Expand Up @@ -413,7 +413,7 @@ private void assertNetService(
public RequestBody createNetServicesRequestBody() {
final String id = "123";
return RequestBody.create(
JSON, "{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_services\"}");
"{\"jsonrpc\":\"2.0\",\"id\":" + Json.encode(id) + ",\"method\":\"net_services\"}", JSON);
}

public JsonRpcHttpService getJsonRpcHttpService(final boolean[] enabledNetServices)
Expand Down
Loading

0 comments on commit 0fff00f

Please sign in to comment.