org.web3j.protocol.exceptions.ClientConnectionException Java Examples
The following examples show how to use
org.web3j.protocol.exceptions.ClientConnectionException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SignerResponse.java From ethsigner with Apache License 2.0 | 6 votes |
public static SignerResponse<JsonRpcErrorResponse> fromError(final ClientConnectionException e) { final String message = e.getMessage(); final String errorBody = message.substring(message.indexOf(":") + 1).trim(); final String[] errorParts = errorBody.split(";", 2); if (errorParts.length == 2) { final String statusCode = errorParts[0]; final HttpResponseStatus status = HttpResponseStatus.valueOf(Integer.parseInt(statusCode)); final String jsonBody = errorParts[1]; JsonRpcErrorResponse jsonRpcResponse = null; if (!jsonBody.isEmpty()) { jsonRpcResponse = Json.decodeValue(jsonBody, JsonRpcErrorResponse.class); } return new SignerResponse<>(jsonRpcResponse, status); } else { throw new RuntimeException("Unable to parse web3j exception message", e); } }
Example #2
Source File: RawJsonRpcRequests.java From ethsigner with Apache License 2.0 | 6 votes |
public SignerResponse<JsonRpcErrorResponse> exceptionalRequest( final String method, final Map<String, String> additionalHeaders) { web3jHttpService.getHeaders().clear(); web3jHttpService.addHeaders(additionalHeaders); web3jHttpService.addHeader( HttpHeaderNames.CONTENT_TYPE.toString(), HttpHeaderValues.APPLICATION_JSON.toString()); final Request<?, ArbitraryResponseType> request = requestFactory.createRequest(method); try { failOnIOException(request::send); fail("Expecting exceptional response "); return null; } catch (final ClientConnectionException e) { LOG.info("ClientConnectionException with message: " + e.getMessage()); return SignerResponse.fromError(e); } }
Example #3
Source File: ClientSideTlsAcceptanceTest.java From ethsigner with Apache License 2.0 | 6 votes |
@Test void ethSignerDoesNotConnectToServerNotSpecifiedInTrustStore(@TempDir Path workDir) throws Exception { final TlsCertificateDefinition serverPresentedCert = TlsCertificateDefinition.loadFromResource("tls/cert1.pfx", "password"); final TlsCertificateDefinition ethSignerCert = TlsCertificateDefinition.loadFromResource("tls/cert2.pfx", "password2"); final TlsCertificateDefinition ethSignerExpectedServerCert = TlsCertificateDefinition.loadFromResource("tls/cert2.pfx", "password2"); final HttpServer web3ProviderHttpServer = serverFactory.create(serverPresentedCert, ethSignerCert, workDir); signer = createAndStartSigner( ethSignerCert, ethSignerExpectedServerCert, web3ProviderHttpServer.actualPort(), 0, workDir); assertThatThrownBy(() -> signer.accounts().balance("0x123456")) .isInstanceOf(ClientConnectionException.class) .hasMessageContaining(String.valueOf(BAD_GATEWAY.code())); // ensure submitting a transaction results in the same behaviour final Transaction transaction = Transaction.createEtherTransaction( signer.accounts().richBenefactor().address(), null, GAS_PRICE, INTRINSIC_GAS, "0x1b00ba00ca00bb00aa00bc00be00ac00ca00da00", Convert.toWei("1.75", Unit.ETHER).toBigIntegerExact()); assertThatThrownBy(() -> signer.transactions().submit(transaction)) .isInstanceOf(ClientConnectionException.class) .hasMessageContaining(String.valueOf(BAD_GATEWAY.code())); }
Example #4
Source File: HttpService.java From etherscan-explorer with GNU General Public License v3.0 | 6 votes |
protected InputStream performGet() throws IOException { Headers headers = buildHeaders(); okhttp3.Request httpRequest; httpRequest = new okhttp3.Request.Builder() .url(url) .headers(headers) .get() .build(); okhttp3.Response response = httpClient.newCall(httpRequest).execute(); if (response.isSuccessful()) { ResponseBody body = response.body(); if (null != body) { return body.byteStream(); } return null; } else { throw new ClientConnectionException( "Invalid response received: " + response.body()); } }
Example #5
Source File: HttpService.java From etherscan-explorer with GNU General Public License v3.0 | 6 votes |
@Override protected InputStream performIO(String request) throws IOException { RequestBody requestBody = RequestBody.create(JSON_MEDIA_TYPE, request); Headers headers = buildHeaders(); okhttp3.Request httpRequest = new okhttp3.Request.Builder() .url(url) .headers(headers) .post(requestBody) .build(); okhttp3.Response response = httpClient.newCall(httpRequest).execute(); if (response.isSuccessful()) { ResponseBody responseBody = response.body(); if (responseBody != null) { return buildInputStream(responseBody); } else { return null; } } else { throw new ClientConnectionException( "Invalid response received: " + response.body()); } }
Example #6
Source File: HttpService.java From web3j with Apache License 2.0 | 6 votes |
@Override protected InputStream performIO(String request) throws IOException { RequestBody requestBody = RequestBody.create(request, JSON_MEDIA_TYPE); Headers headers = buildHeaders(); okhttp3.Request httpRequest = new okhttp3.Request.Builder().url(url).headers(headers).post(requestBody).build(); okhttp3.Response response = httpClient.newCall(httpRequest).execute(); processHeaders(response.headers()); ResponseBody responseBody = response.body(); if (response.isSuccessful()) { if (responseBody != null) { return buildInputStream(responseBody); } else { return null; } } else { int code = response.code(); String text = responseBody == null ? "N/A" : responseBody.string(); throw new ClientConnectionException("Invalid response received: " + code + "; " + text); } }
Example #7
Source File: Contracts.java From ethsigner with Apache License 2.0 | 5 votes |
public SignerResponse<JsonRpcErrorResponse> submitExceptional(final T smartContract) { try { submit(smartContract); fail("Expecting exceptional response "); } catch (final ClientConnectionException e) { LOG.info("ClientConnectionException with message: " + e.getMessage()); return SignerResponse.fromError(e); } return null; }
Example #8
Source File: Transactions.java From ethsigner with Apache License 2.0 | 5 votes |
public SignerResponse<JsonRpcErrorResponse> submitExceptional(final Transaction transaction) { try { failOnIOException(() -> eth.sendTransaction(transaction)); fail("Expecting exceptional response "); } catch (final ClientConnectionException e) { LOG.info("ClientConnectionException with message: " + e.getMessage()); return SignerResponse.fromError(e); } return null; }
Example #9
Source File: ExpectInternalErrorPrivateTransactionReceipt.java From besu with Apache License 2.0 | 5 votes |
@Override public void verify(final PrivacyNode node) { try { node.execute(transactions.getPrivateTransactionReceipt(transactionHash)); } catch (final ClientConnectionException e) { assertThat(e.getMessage()).contains("Internal error"); } }
Example #10
Source File: ExpectJsonRpcError.java From besu with Apache License 2.0 | 5 votes |
@Override public void verify(final Node node) { try { node.execute(transaction); failBecauseExceptionWasNotThrown(ClientConnectionException.class); } catch (final Exception e) { Assertions.assertThat(e) .isInstanceOf(ClientConnectionException.class) .hasMessageContaining("400") .hasMessageContaining(error.getMessage()); } }
Example #11
Source File: PrivCallAcceptanceTest.java From besu with Apache License 2.0 | 5 votes |
@Test public void mustNotSucceedWithWronglyEncodedFunction() { final String privacyGroupId = minerNode.execute( privacyTransactions.createPrivacyGroup( "myGroupName", "my group description", minerNode)); final EventEmitter eventEmitter = minerNode.execute( privateContractTransactions.createSmartContractWithPrivacyGroupId( EventEmitter.class, minerNode.getTransactionSigningKey(), POW_CHAIN_ID, minerNode.getEnclaveKey(), privacyGroupId)); privateContractVerifier .validPrivateContractDeployed( eventEmitter.getContractAddress(), minerNode.getAddress().toString()) .verify(eventEmitter); final Request<Object, EthCall> priv_call = privCall(privacyGroupId, eventEmitter, true, false); assertThatExceptionOfType(ClientConnectionException.class) .isThrownBy(() -> priv_call.send()) .withMessageContaining("Invalid params"); }
Example #12
Source File: HttpService.java From client-sdk-java with Apache License 2.0 | 5 votes |
@Override protected InputStream performIO(String request) throws IOException { RequestBody requestBody = RequestBody.create(JSON_MEDIA_TYPE, request); Headers headers = buildHeaders(); okhttp3.Request httpRequest = new okhttp3.Request.Builder() .url(url) .headers(headers) .post(requestBody) .build(); okhttp3.Response response = httpClient.newCall(httpRequest).execute(); ResponseBody responseBody = response.body(); if (response.isSuccessful()) { if (responseBody != null) { return buildInputStream(responseBody); } else { return null; } } else { int code = response.code(); String text = responseBody == null ? "N/A" : responseBody.string(); throw new ClientConnectionException("Invalid response received: " + code + "; " + text); } }
Example #13
Source File: AWHttpService.java From alpha-wallet-android with MIT License | 5 votes |
private InputStream processNodeResponse(Response response, String request, boolean useSecondaryNode) throws IOException { processHeaders(response.headers()); ResponseBody responseBody = response.body(); if (response.isSuccessful()) { if (responseBody != null) { return buildInputStream(responseBody); } else { return null; } } else if (!useSecondaryNode && secondaryUrl != null) { return trySecondaryNode(request); } else { int code = response.code(); String text = responseBody == null ? "N/A" : responseBody.string(); throw new ClientConnectionException("Invalid response received: " + code + "; " + text); } }
Example #14
Source File: ExpectEthSendRawTransactionException.java From besu with Apache License 2.0 | 4 votes |
@Override public void verify(final Node node) { final Throwable thrown = catchThrowable(() -> node.execute(transaction)); assertThat(thrown).isInstanceOf(ClientConnectionException.class); assertThat(thrown.getMessage()).contains(expectedMessage); }
Example #15
Source File: ExpectEthAccountsException.java From besu with Apache License 2.0 | 4 votes |
@Override public void verify(final Node node) { final Throwable thrown = catchThrowable(() -> node.execute(transaction)); assertThat(thrown).isInstanceOf(ClientConnectionException.class); assertThat(thrown.getMessage()).contains(expectedMessage); }
Example #16
Source File: ExpectEthGetWorkException.java From besu with Apache License 2.0 | 4 votes |
@Override public void verify(final Node node) { final Throwable thrown = catchThrowable(() -> node.execute(transaction)); assertThat(thrown).isInstanceOf(ClientConnectionException.class); assertThat(thrown.getMessage()).contains(expectedMessage); }