Skip to content

Commit f1aff4e

Browse files
committed
Executor post request fix
1 parent fffd463 commit f1aff4e

11 files changed

+20
-21
lines changed

src/main/java/io/api/etherscan/core/impl/ProxyApiProvider.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ public Optional<String> txSendRaw(final String hexEncodedTx) throws ApiException
136136
throw new InvalidDataHexException("Data is not encoded in hex format - " + hexEncodedTx);
137137

138138
final String urlParams = ACT_SEND_RAW_TX_PARAM + HEX_PARAM + hexEncodedTx;
139-
final StringProxyTO response = getRequest(urlParams, StringProxyTO.class);
139+
final StringProxyTO response = postRequest(urlParams, "", StringProxyTO.class);
140140
if(response.getError() != null)
141141
throw new EtherScanException("Error occurred with code " + response.getError().getCode()
142142
+ " with message " + response.getError().getMessage());

src/main/java/io/api/etherscan/executor/impl/HttpExecutor.java

+10-10
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,8 @@
1717
import static java.net.HttpURLConnection.HTTP_MOVED_TEMP;
1818

1919
/**
20-
* @see IHttpExecutor
21-
*
2220
* @author GoodforGod
21+
* @see IHttpExecutor
2322
* @since 28.10.2018
2423
*/
2524
public class HttpExecutor implements IHttpExecutor {
@@ -30,7 +29,7 @@ public class HttpExecutor implements IHttpExecutor {
3029
DEFAULT_HEADERS.put("accept-language", "en,ru;q=0.9");
3130
DEFAULT_HEADERS.put("accept-encoding", "gzip, deflate, br");
3231
DEFAULT_HEADERS.put("user-agent", "Mozilla/5.0 (Windows NT 10.0; WOW64) Chrome/68.0.3440.106");
33-
DEFAULT_HEADERS.put("cache-control", "max-age=0");
32+
DEFAULT_HEADERS.put("content-Type", "application/x-www-form-urlencoded");
3433
}
3534

3635
private final Map<String, String> headers;
@@ -82,13 +81,14 @@ public String post(final String urlAsString, final String dataToPost) {
8281
connection.setConnectTimeout(timeout);
8382
headers.forEach(connection::setRequestProperty);
8483

85-
if(!BasicUtils.isEmpty(dataToPost)) {
86-
connection.setDoOutput(true);
87-
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
88-
wr.writeBytes(dataToPost);
89-
wr.flush();
90-
wr.close();
91-
}
84+
final String contentLength = (BasicUtils.isEmpty(dataToPost)) ? "0" : String.valueOf(dataToPost.length());
85+
connection.setRequestProperty("Content-Length", contentLength);
86+
87+
connection.setDoOutput(true);
88+
DataOutputStream wr = new DataOutputStream(connection.getOutputStream());
89+
wr.writeBytes(dataToPost);
90+
wr.flush();
91+
wr.close();
9292

9393
final int status = connection.getResponseCode();
9494
if (status == HTTP_MOVED_TEMP || status == HTTP_MOVED_PERM) {

src/test/java/io/api/etherscan/account/AccountTxInternalByHashTest.java

-1
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ public void correct() {
2424
assertNotNull(txs);
2525
assertEquals(1, txs.size());
2626
assertTxs(txs);
27-
assertNotNull(txs.get(0).getHash());
2827
assertNotNull(txs.get(0).getFrom());
2928
assertNotNull(txs.get(0).getTimeStamp());
3029
assertNotNull(txs.get(0).getGas());

src/test/java/io/api/etherscan/block/BlockApiTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ public class BlockApiTest extends Assert {
1919

2020
@Test
2121
public void correct() {
22-
Optional<UncleBlock> uncles = api.block().uncles(242512);
22+
Optional<UncleBlock> uncles = api.block().uncles(2165403);
2323
assertTrue(uncles.isPresent());
2424
assertFalse(uncles.get().isEmpty());
2525
assertNotNull(uncles.get().getBlockMiner());

src/test/java/io/api/etherscan/proxy/ProxyCodeApiTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @author GoodforGod
1515
* @since 03.11.2018
1616
*/
17-
public class ProxyCodeApiTest extends Assert{
17+
public class ProxyCodeApiTest extends Assert {
1818

1919
private final EtherScanApi api = new EtherScanApi();
2020

src/test/java/io/api/etherscan/proxy/ProxyGasApiTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
* @author GoodforGod
1414
* @since 03.11.2018
1515
*/
16-
public class ProxyGasApiTest extends Assert{
16+
public class ProxyGasApiTest extends Assert {
1717

1818
private final EtherScanApi api = new EtherScanApi();
1919

src/test/java/io/api/etherscan/proxy/ProxyStorageApiTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @author GoodforGod
1515
* @since 03.11.2018
1616
*/
17-
public class ProxyStorageApiTest extends Assert{
17+
public class ProxyStorageApiTest extends Assert {
1818

1919
private final EtherScanApi api = new EtherScanApi();
2020

src/test/java/io/api/etherscan/proxy/ProxyTxApiTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @author GoodforGod
1515
* @since 03.11.2018
1616
*/
17-
public class ProxyTxApiTest extends Assert{
17+
public class ProxyTxApiTest extends Assert {
1818

1919
private final EtherScanApi api = new EtherScanApi();
2020

src/test/java/io/api/etherscan/proxy/ProxyTxCountApiTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
* @author GoodforGod
1212
* @since 03.11.2018
1313
*/
14-
public class ProxyTxCountApiTest extends Assert{
14+
public class ProxyTxCountApiTest extends Assert {
1515

1616
private final EtherScanApi api = new EtherScanApi();
1717

src/test/java/io/api/etherscan/proxy/ProxyTxReceiptApiTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* @author GoodforGod
1515
* @since 03.11.2018
1616
*/
17-
public class ProxyTxReceiptApiTest extends Assert{
17+
public class ProxyTxReceiptApiTest extends Assert {
1818

1919
private final EtherScanApi api = new EtherScanApi();
2020

src/test/java/io/api/etherscan/proxy/ProxyTxSendRawApiTest.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
* @since 03.11.2018
1616
*/
1717
//TODO contact etherscan and ask about methods
18-
public class ProxyTxSendRawApiTest extends Assert{
18+
public class ProxyTxSendRawApiTest extends Assert {
1919

2020
private final EtherScanApi api = new EtherScanApi();
2121

@@ -31,7 +31,7 @@ public void invalidParamWithError() {
3131

3232
@Test(expected = EtherScanException.class)
3333
public void invalidParamEtherScanDataException() {
34-
Optional<String> sendRaw = api.proxy().txSendRaw("0x0");
34+
Optional<String> sendRaw = api.proxy().txSendRaw("0x1");
3535
}
3636

3737
public void correctParamWithEmptyExpectedResult() {

0 commit comments

Comments
 (0)