Skip to content

Commit a3ee719

Browse files
committed
Switched to SLF4J (issue 39)
Updated a couple of tests that removes the reliance on test.ipdb.io assuming you have a working BigChainDB Fixed Issue 61 - transaction leaking response objects Fixed Issue 62 - DriverUtils.makeSelfSortingGson now sorts keys
1 parent 735ede3 commit a3ee719

18 files changed

+188
-73
lines changed

build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,13 +24,14 @@ repositories {
2424
}
2525

2626
dependencies {
27-
compile fileTree(dir: 'libs', include: '*.jar')
27+
compile fileTree(dir: 'libs', include: '*.jar')
2828

2929
compile 'net.i2p.crypto:eddsa:0.2.0'
3030
compile 'org.bouncycastle:bcprov-jdk15on:1.58'
31-
compile 'org.json:json:20170516'
3231
compile 'com.google.code.gson:gson:2.7'
3332
compile 'com.squareup.okhttp3:okhttp:3.9.0'
33+
compile 'org.slf4j:slf4j-api:1.7.25'
34+
compile 'org.glassfish.tyrus.bundles:tyrus-standalone-client:1.9'
3435
compile group: 'commons-codec', name: 'commons-codec', version: '1.10'
3536
testCompile 'junit:junit:4.12'
3637
}

pom.xml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,26 @@
7373
<artifactId>gson</artifactId>
7474
<version>2.8.2</version>
7575
</dependency>
76+
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-api -->
77+
<dependency>
78+
<groupId>org.slf4j</groupId>
79+
<artifactId>slf4j-api</artifactId>
80+
<version>1.7.25</version>
81+
</dependency>
82+
<!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core -->
83+
<dependency>
84+
<groupId>org.apache.logging.log4j</groupId>
85+
<artifactId>log4j-core</artifactId>
86+
<version>2.9.1</version>
87+
<scope>test</scope>
88+
</dependency>
89+
<!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->
90+
<dependency>
91+
<groupId>org.slf4j</groupId>
92+
<artifactId>slf4j-log4j12</artifactId>
93+
<version>1.7.25</version>
94+
<scope>test</scope>
95+
</dependency>
7696
<!--
7797
You must install java-crypto-conditions-2.0.0-SNAPSHOT.jar in your local Maven repository with the following
7898

src/main/java/com/authenteq/api/AccountApi.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,33 @@
66
import java.security.spec.InvalidKeySpecException;
77
import java.security.spec.PKCS8EncodedKeySpec;
88
import java.security.spec.X509EncodedKeySpec;
9-
import java.util.logging.Logger;
109

1110
import com.authenteq.model.Account;
1211
import net.i2p.crypto.eddsa.EdDSAPrivateKey;
1312
import net.i2p.crypto.eddsa.EdDSAPublicKey;
1413
import net.i2p.crypto.eddsa.Utils;
14+
import org.slf4j.LoggerFactory;
1515

1616
/**
1717
* The Class AccountApi.
1818
*/
1919
public class AccountApi extends AbstractApi {
20-
21-
22-
private static final Logger LOGGER = Logger.getLogger(AccountApi.class.getName());
20+
21+
private static final org.slf4j.Logger log = LoggerFactory.getLogger( AccountApi.class );
22+
2323
/**
2424
* Creates the account.
2525
*
2626
* @return the account
2727
*/
2828
public static Account createAccount() {
29-
LOGGER.info("createAccount Call");
29+
log.debug( "createAccount Call" );
3030
Account newAccount = new Account();
3131
net.i2p.crypto.eddsa.KeyPairGenerator edDsaKpg = new net.i2p.crypto.eddsa.KeyPairGenerator();
3232
KeyPair keyPair = edDsaKpg.generateKeyPair();
3333
newAccount.setPrivateKey(keyPair.getPrivate());
3434
newAccount.setPublicKey(keyPair.getPublic());
35-
LOGGER.info("createAccount Call : " + newAccount.getPublicKey().toString());
35+
log.debug( "createAccount Call : " + newAccount.getPublicKey().toString() );
3636
return newAccount;
3737
}
3838

@@ -48,7 +48,7 @@ public static Account createAccount() {
4848
* the invalid key spec exception
4949
*/
5050
public static Account loadAccount(String publicKey, String privateKey) throws InvalidKeySpecException {
51-
LOGGER.info("loadAccount Call");
51+
log.debug( "loadAccount Call" );
5252
Account newAccount = new Account();
5353

5454
final X509EncodedKeySpec pubKeySpec = new X509EncodedKeySpec(Utils.hexToBytes(publicKey));
@@ -60,7 +60,7 @@ public static Account loadAccount(String publicKey, String privateKey) throws In
6060
KeyPair keyPair = new KeyPair(pubKey, privKey);
6161
newAccount.setPrivateKey(keyPair.getPrivate());
6262
newAccount.setPublicKey(keyPair.getPublic());
63-
LOGGER.info("loadAccount Call : " + newAccount.getPublicKey().toString());
63+
log.debug( "loadAccount Call : " + newAccount.getPublicKey().toString() );
6464
return newAccount;
6565
}
6666

src/main/java/com/authenteq/api/AssetsApi.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,16 @@
66
import com.authenteq.util.JsonUtils;
77
import com.authenteq.util.NetworkUtils;
88
import okhttp3.Response;
9+
import org.slf4j.LoggerFactory;
10+
911
import java.io.IOException;
10-
import java.util.logging.Logger;
1112

1213
/**
1314
* The Class AssetsApi.
1415
*/
1516
public class AssetsApi {
1617

17-
private static final Logger LOGGER = Logger.getLogger(AssetsApi.class.getName());
18+
private static final org.slf4j.Logger log = LoggerFactory.getLogger( AssetsApi.class );
1819
/**
1920
* Gets the assets.
2021
*
@@ -23,7 +24,7 @@ public class AssetsApi {
2324
* @throws IOException Signals that an I/O exception has occurred.
2425
*/
2526
public static Assets getAssets(String searchKey) throws IOException {
26-
LOGGER.info("getAssets Call :" + searchKey);
27+
log.debug( "getAssets Call :" + searchKey );
2728
Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.ASSETS + "?search="+ searchKey);
2829
String body = response.body().string();
2930
response.close();
@@ -39,11 +40,10 @@ public static Assets getAssets(String searchKey) throws IOException {
3940
* @throws IOException Signals that an I/O exception has occurred.
4041
*/
4142
public static Assets getAssetsWithLimit(String searchKey, String limit) throws IOException {
42-
LOGGER.info("getAssets Call :" + searchKey + " limit " + limit);
43+
log.debug( "getAssets Call :" + searchKey + " limit " + limit );
4344
Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.ASSETS + "?search="+ searchKey+ "&limit=" + limit);
4445
String body = response.body().string();
4546
response.close();
4647
return JsonUtils.fromJson(body, Assets.class);
4748
}
48-
4949
}

src/main/java/com/authenteq/api/BlocksApi.java

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@
88
import com.authenteq.util.NetworkUtils;
99
import com.google.gson.reflect.TypeToken;
1010
import okhttp3.Response;
11+
import org.slf4j.LoggerFactory;
1112

1213
import java.io.IOException;
1314
import java.util.List;
14-
import java.util.logging.Logger;
1515

1616

1717

@@ -20,8 +20,7 @@
2020
*/
2121
public class BlocksApi {
2222

23-
24-
private static final Logger LOGGER = Logger.getLogger(BlocksApi.class.getName());
23+
private static final org.slf4j.Logger log = LoggerFactory.getLogger( BlocksApi.class );
2524

2625
/**
2726
* Gets the block.
@@ -31,7 +30,7 @@ public class BlocksApi {
3130
* @throws IOException Signals that an I/O exception has occurred.
3231
*/
3332
public static Block getBlock(String blockId) throws IOException {
34-
LOGGER.info("getBlock Call :" + blockId);
33+
log.debug( "getBlock Call :" + blockId );
3534
Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.BLOCKS + "/"+ blockId);
3635
String body = response.body().string();
3736
response.close();
@@ -47,7 +46,7 @@ public static Block getBlock(String blockId) throws IOException {
4746
* @throws IOException Signals that an I/O exception has occurred.
4847
*/
4948
public static List<String> getBlocks(String transactionId, BlockStatus status) throws IOException {
50-
LOGGER.info("getBlocks Call :" + transactionId + " status " + status);
49+
log.debug( "getBlocks Call :" + transactionId + " status " + status );
5150
Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.BLOCKS + "?transaction_id="+transactionId+"&status="+status);
5251
String body = response.body().string();
5352
response.close();

src/main/java/com/authenteq/api/OutputsApi.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,16 @@
66
import com.authenteq.util.JsonUtils;
77
import com.authenteq.util.NetworkUtils;
88
import okhttp3.Response;
9+
import org.slf4j.LoggerFactory;
910

1011
import java.io.IOException;
11-
import java.util.logging.Logger;
12-
13-
1412

1513
/**
1614
* The Class OutputsApi.
1715
*/
1816
public class OutputsApi {
1917

20-
private static final Logger LOGGER = Logger.getLogger(OutputsApi.class.getName());
18+
private static final org.slf4j.Logger log = LoggerFactory.getLogger( OutputsApi.class );
2119
/**
2220
* Gets the outputs.
2321
*
@@ -26,7 +24,7 @@ public class OutputsApi {
2624
* @throws IOException Signals that an I/O exception has occurred.
2725
*/
2826
public static Outputs getOutputs(String publicKey) throws IOException {
29-
LOGGER.info("getOutputs Call :" + publicKey);
27+
log.debug( "getOutputs Call :" + publicKey );
3028
Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.OUTPUTS + "?public_key="+ publicKey);
3129
String body = response.body().string();
3230
response.close();
@@ -41,7 +39,7 @@ public static Outputs getOutputs(String publicKey) throws IOException {
4139
* @throws IOException Signals that an I/O exception has occurred.
4240
*/
4341
public static Outputs getSpentOutputs(String publicKey) throws IOException {
44-
LOGGER.info("getSpentOutputs Call :" + publicKey);
42+
log.debug( "getSpentOutputs Call :" + publicKey );
4543
Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.OUTPUTS + "?public_key="+ publicKey+ "&spent=true");
4644
String body = response.body().string();
4745
response.close();

src/main/java/com/authenteq/api/StatusesApi.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -6,17 +6,17 @@
66
import com.authenteq.util.JsonUtils;
77
import com.authenteq.util.NetworkUtils;
88
import okhttp3.Response;
9+
import org.slf4j.LoggerFactory;
910

1011
import java.io.IOException;
11-
import java.util.logging.Logger;
1212

1313
/**
1414
* The Class StatusesApi.
1515
*/
1616
public class StatusesApi {
17-
18-
private static final Logger LOGGER = Logger.getLogger(StatusesApi.class.getName());
19-
17+
18+
private static final org.slf4j.Logger log = LoggerFactory.getLogger( StatusesApi.class );
19+
2020
/**
2121
* Gets the transaction status.
2222
*
@@ -26,11 +26,11 @@ public class StatusesApi {
2626
*/
2727
public static Status getTransactionStatus(String transactionId) throws StatusException, IOException
2828
{
29-
LOGGER.info("getTransactionStatus Call :" + transactionId);
30-
try( Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.STATUSES + "?transaction_id="+ transactionId) ) {
29+
log.debug( "getTransactionStatus Call :" + transactionId );
30+
try( Response response = NetworkUtils.sendGetRequest( BigChainDBGlobals.getBaseUrl() + BigchainDbApi.STATUSES + "?transaction_id=" + transactionId ) ) {
3131
if( response.code() == 200 ) {
32-
String body = response.body().string();
33-
return JsonUtils.fromJson(body, Status.class);
32+
String body = response.body().string();
33+
return JsonUtils.fromJson( body, Status.class );
3434
}
3535
throw new StatusException( response.code(), response.body() != null ? response.body().toString() : "Error in response, body is empty" );
3636
}
@@ -44,11 +44,11 @@ public static Status getTransactionStatus(String transactionId) throws StatusExc
4444
* @throws IOException Signals that an I/O exception has occurred.
4545
*/
4646
public static Status getBlockStatus(String blockId) throws StatusException, IOException {
47-
LOGGER.info("getBlockStatus Call :" + blockId);
48-
try( Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.STATUSES + "?block_id="+ blockId) ) {
47+
log.debug( "getBlockStatus Call :" + blockId );
48+
try( Response response = NetworkUtils.sendGetRequest( BigChainDBGlobals.getBaseUrl() + BigchainDbApi.STATUSES + "?block_id=" + blockId ) ) {
4949
if( response.code() == 200 ) {
50-
String body = response.body().string();
51-
return JsonUtils.fromJson(body, Status.class);
50+
String body = response.body().string();
51+
return JsonUtils.fromJson( body, Status.class );
5252
}
5353
throw new StatusException( response.code(), response.body() != null ? response.body().toString() : "Error in response, body is empty" );
5454
}

src/main/java/com/authenteq/api/TransactionsApi.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,16 +10,17 @@
1010
import com.authenteq.util.NetworkUtils;
1111
import okhttp3.RequestBody;
1212
import okhttp3.Response;
13+
import org.slf4j.Logger;
14+
import org.slf4j.LoggerFactory;
1315

1416
import java.io.IOException;
15-
import java.util.logging.Logger;
1617

1718
/**
1819
* The Class TransactionsApi.
1920
*/
2021
public class TransactionsApi extends AbstractApi {
2122

22-
private static final Logger LOGGER = Logger.getLogger(TransactionsApi.class.getName());
23+
private static final Logger log = LoggerFactory.getLogger( TransactionsApi.class );
2324

2425
/**
2526
* Send transaction.
@@ -30,7 +31,7 @@ public class TransactionsApi extends AbstractApi {
3031
* the callback
3132
*/
3233
public static void sendTransaction(Transaction transaction, final GenericCallback callback) {
33-
LOGGER.info("sendTransaction Call :" + transaction);
34+
log.debug( "sendTransaction Call :" + transaction );
3435
RequestBody body = RequestBody.create(JSON, transaction.toString());
3536
NetworkUtils.sendPostRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.TRANSACTIONS, body, callback);
3637
}
@@ -44,9 +45,10 @@ public static void sendTransaction(Transaction transaction, final GenericCallbac
4445
* Signals that an I/O exception has occurred.
4546
*/
4647
public static void sendTransaction(Transaction transaction) throws IOException {
47-
LOGGER.info("sendTransaction Call :" + transaction);
48+
log.debug( "sendTransaction Call :" + transaction );
4849
RequestBody body = RequestBody.create(JSON, JsonUtils.toJson(transaction));
4950
Response response = NetworkUtils.sendPostRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.TRANSACTIONS, body);
51+
response.close();
5052
}
5153

5254
/**
@@ -59,7 +61,7 @@ public static void sendTransaction(Transaction transaction) throws IOException {
5961
* Signals that an I/O exception has occurred.
6062
*/
6163
public static Transaction getTransactionById(String id) throws IOException {
62-
LOGGER.info("getTransactionById Call :" + id);
64+
log.debug( "getTransactionById Call :" + id );
6365
Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.TRANSACTIONS + "/" + id);
6466
String body = response.body().string();
6567
response.close();
@@ -79,7 +81,7 @@ public static Transaction getTransactionById(String id) throws IOException {
7981
*/
8082
public static Transactions getTransactionsByAssetId(String assetId, Operations operation)
8183
throws IOException {
82-
LOGGER.info("getTransactionsByAssetId Call :" + assetId + " operation " + operation);
84+
log.debug( "getTransactionsByAssetId Call :" + assetId + " operation " + operation );
8385
Response response = NetworkUtils.sendGetRequest(
8486
BigChainDBGlobals.getBaseUrl() + BigchainDbApi.TRANSACTIONS + "?asset_id=" + assetId + "&operation=" + operation);
8587
String body = response.body().string();

src/main/java/com/authenteq/api/VotesApi.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,17 @@
66
import com.authenteq.util.JsonUtils;
77
import com.authenteq.util.NetworkUtils;
88
import okhttp3.Response;
9+
import org.slf4j.LoggerFactory;
910

1011
import java.io.IOException;
11-
import java.util.logging.Logger;
12-
13-
1412

1513
/**
1614
* The Class VotesApi.
1715
*/
1816
public class VotesApi {
1917

20-
private static final Logger LOGGER = Logger.getLogger(VotesApi.class.getName());
21-
18+
private static final org.slf4j.Logger log = LoggerFactory.getLogger( VotesApi.class );
19+
2220
/**
2321
* Gets the votes.
2422
*
@@ -27,7 +25,7 @@ public class VotesApi {
2725
* @throws IOException Signals that an I/O exception has occurred.
2826
*/
2927
public static Votes getVotes(String blockId) throws IOException {
30-
LOGGER.info("getVotes Call :" + blockId);
28+
log.debug( "getVotes Call :" + blockId );
3129
Response response = NetworkUtils.sendGetRequest(BigChainDBGlobals.getBaseUrl() + BigchainDbApi.VOTES + "?block_id=" + blockId);
3230
String body = response.body().string();
3331
response.close();

0 commit comments

Comments
 (0)