Skip to content
This repository has been archived by the owner on Dec 6, 2024. It is now read-only.

Commit

Permalink
added clarity to BaseB2Response Logging
Browse files Browse the repository at this point in the history
  • Loading branch information
Synapticloop authored and Synapticloop committed Mar 7, 2016
1 parent 5047b8b commit a2a8864
Show file tree
Hide file tree
Showing 12 changed files with 60 additions and 27 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ And now for the dependency
<dependency>
<groupId>synapticloop</groupId>
<artifactId>backblaze-b2-java-api</artifactId>
<version>v1.2.6</version>
<version>v1.2.7</version>
<type>jar</type>
</dependency>
```
Expand Down Expand Up @@ -256,19 +256,19 @@ and then include the dependency:

```
dependencies {
runtime(group: 'synapticloop', name: 'backblaze-b2-java-api', version: 'v1.2.6', ext: 'jar')
runtime(group: 'synapticloop', name: 'backblaze-b2-java-api', version: 'v1.2.7', ext: 'jar')
compile(group: 'synapticloop', name: 'backblaze-b2-java-api', version: 'v1.2.6', ext: 'jar')
compile(group: 'synapticloop', name: 'backblaze-b2-java-api', version: 'v1.2.7', ext: 'jar')
}
```

or, more simply for versions of gradle greater than 2.4

```
dependencies {
runtime 'synapticloop:backblaze-b2-java-api:v1.2.6'
runtime 'synapticloop:backblaze-b2-java-api:v1.2.7'
compile 'synapticloop:backblaze-b2-java-api:v1.2.6'
compile 'synapticloop:backblaze-b2-java-api:v1.2.7'
}
```

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ group = 'synapticloop'
archivesBaseName = 'backblaze-b2-java-api'
description = """A java api for the truly excellent backblaze b2 storage service"""

version = 'v1.2.6'
version = 'v1.2.7'

sourceCompatibility = 1.7
targetCompatibility = 1.7
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public B2AuthorizeAccountResponse(String json) throws B2ApiException {
this.downloadUrl = this.readString(B2ResponseProperties.KEY_DOWNLOAD_URL);
this.minimumPartSize = this.readInt(B2ResponseProperties.KEY_MINIMUM_PART_SIZE);

this.warnOnMissedKeys(LOGGER);
this.warnOnMissedKeys();
}

/**
Expand Down Expand Up @@ -105,6 +105,9 @@ public B2AuthorizeAccountResponse(String json) throws B2ApiException {
*/
public int getMinimumPartSize() {return this.minimumPartSize; }

@Override
protected Logger getLogger() { return LOGGER; }

@Override
public String toString() {
StringBuilder stringBuilder = new StringBuilder();
Expand Down
8 changes: 6 additions & 2 deletions src/main/java/synapticloop/b2/response/B2BucketResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import synapticloop.b2.BucketType;
import synapticloop.b2.exception.B2ApiException;

Expand All @@ -45,7 +46,7 @@ public B2BucketResponse(String json) throws B2ApiException {
this.bucketName = this.readString(B2ResponseProperties.KEY_BUCKET_NAME);
this.bucketType = this.readString(B2ResponseProperties.KEY_BUCKET_TYPE);

this.warnOnMissedKeys(LOGGER);
this.warnOnMissedKeys();
}

/**
Expand All @@ -63,7 +64,7 @@ public B2BucketResponse(final JSONObject response) throws B2ApiException {
this.bucketName = this.readString(B2ResponseProperties.KEY_BUCKET_NAME);
this.bucketType = this.readString(B2ResponseProperties.KEY_BUCKET_TYPE);

this.warnOnMissedKeys(LOGGER);
this.warnOnMissedKeys();
}

/**
Expand Down Expand Up @@ -94,6 +95,9 @@ public B2BucketResponse(final JSONObject response) throws B2ApiException {
*/
public BucketType getBucketType() { return BucketType.valueOf(this.bucketType); }

@Override
protected Logger getLogger() { return LOGGER; }

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("B2BucketResponse{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public B2DeleteFileVersionResponse(String json) throws B2ApiException {
this.fileId = this.readString(B2ResponseProperties.KEY_FILE_ID);
this.fileName = this.readString(B2ResponseProperties.KEY_FILE_NAME);

this.warnOnMissedKeys(LOGGER);
this.warnOnMissedKeys();
}

/**
Expand All @@ -74,6 +74,9 @@ public B2DeleteFileVersionResponse(String json) throws B2ApiException {
*/
public String getFileName() { return this.fileName; }

@Override
protected Logger getLogger() { return LOGGER; }

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("B2DeleteFileVersionResponse{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public B2FileInfoResponse(final JSONObject response) throws B2ApiException {
this.size = this.readInt(B2ResponseProperties.KEY_SIZE);
this.uploadTimestamp = this.readLong(B2ResponseProperties.KEY_UPLOAD_TIMESTAMP);

this.warnOnMissedKeys(LOGGER);
this.warnOnMissedKeys();
}

/**
Expand Down Expand Up @@ -138,6 +138,9 @@ public B2FileInfoResponse(final JSONObject response) throws B2ApiException {
*/
public long getUploadTimestamp() { return this.uploadTimestamp; }

@Override
protected Logger getLogger() { return LOGGER; }

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("B2FileInfoResponse{");
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/synapticloop/b2/response/B2FileResponse.java
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public B2FileResponse(String json) throws B2ApiException {
}
}

this.warnOnMissedKeys(LOGGER);
this.warnOnMissedKeys();
}

/**
Expand Down Expand Up @@ -132,6 +132,9 @@ public B2FileResponse(String json) throws B2ApiException {
*/
public Map<String, String> getFileInfo() { return this.fileInfo; }

@Override
protected Logger getLogger() { return LOGGER; }

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("B2FileResponse{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public B2GetUploadUrlResponse(String json) throws B2ApiException {
this.uploadUrl = this.readString(B2ResponseProperties.KEY_UPLOAD_URL);
this.authorizationToken = this.readString(B2ResponseProperties.KEY_AUTHORIZATION_TOKEN);

this.warnOnMissedKeys(LOGGER);
this.warnOnMissedKeys();
}

/**
Expand All @@ -67,6 +67,9 @@ public B2GetUploadUrlResponse(String json) throws B2ApiException {
*/
public String getAuthorizationToken() { return this.authorizationToken; }

@Override
protected Logger getLogger() { return LOGGER; }

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("B2GetUploadUrlResponse{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public B2HideFileResponse(String json) throws B2ApiException {
this.size = this.readInt(B2ResponseProperties.KEY_SIZE);
this.uploadTimestamp = this.readLong(B2ResponseProperties.KEY_UPLOAD_TIMESTAMP);

this.warnOnMissedKeys(LOGGER);
this.warnOnMissedKeys();
}

public String getFileId() { return this.fileId; }
Expand All @@ -84,6 +84,9 @@ public B2HideFileResponse(String json) throws B2ApiException {

public long getUploadTimestamp() { return this.uploadTimestamp; }

@Override
protected Logger getLogger() { return LOGGER; }

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("B2HideFileResponse{");
Expand All @@ -94,4 +97,5 @@ public String toString() {
sb.append('}');
return sb.toString();
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public B2ListBucketsResponse(final String json) throws B2ApiException {
buckets.add(new B2BucketResponse(optJSONArray.optJSONObject(i)));
}

this.warnOnMissedKeys(LOGGER);
this.warnOnMissedKeys();
}

/**
Expand All @@ -59,6 +59,9 @@ public List<B2BucketResponse> getBuckets() {
return buckets;
}

@Override
protected Logger getLogger() { return LOGGER; }

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("B2ListBucketsResponse{");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public B2ListFilesResponse(String json) throws B2ApiException {
files.add(new B2FileInfoResponse(filesArray.optJSONObject(i)));
}

this.warnOnMissedKeys(LOGGER);
this.warnOnMissedKeys();
}

/**
Expand All @@ -80,6 +80,9 @@ public B2ListFilesResponse(String json) throws B2ApiException {
*/
public List<B2FileInfoResponse> getFiles() { return this.files; }

@Override
protected Logger getLogger() { return LOGGER; }

@Override
public String toString() {
final StringBuilder sb = new StringBuilder("B2ListFilesResponse{");
Expand Down
26 changes: 15 additions & 11 deletions src/main/java/synapticloop/b2/response/BaseB2Response.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,10 @@
import org.json.JSONException;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import synapticloop.b2.exception.B2ApiException;

public abstract class BaseB2Response {
private static final Logger LOGGER = LoggerFactory.getLogger(BaseB2Response.class);

private final JSONObject response;

/**
Expand Down Expand Up @@ -91,7 +88,7 @@ protected String readString(String key) {
protected String readString(JSONObject response, String key) {
final Object value = response.remove(key);
if (null == value || JSONObject.NULL == value) {
LOGGER.warn("No field for key {}", key);
getLogger().warn("No field for key {}", key);
return null;
}
return value.toString();
Expand All @@ -107,7 +104,7 @@ protected String readString(JSONObject response, String key) {
protected int readInt(String key) {
final Object value = response.remove(key);
if (null == value || JSONObject.NULL == value) {
LOGGER.warn("No field for key {}", key);
getLogger().warn("No field for key {}", key);
return -1;
}
return value instanceof Number ? ((Number) value).intValue() : Integer.parseInt(value.toString());
Expand All @@ -123,7 +120,7 @@ protected int readInt(String key) {
protected long readLong(String key) {
final Object value = response.remove(key);
if (null == value || JSONObject.NULL == value) {
LOGGER.warn("No field for key {}", key);
getLogger().warn("No field for key {}", key);
return -1L;
}
return value instanceof Number ? ((Number) value).longValue() : Long.parseLong(value.toString());
Expand Down Expand Up @@ -151,7 +148,7 @@ protected JSONObject readObject(String key) {
protected JSONObject readObject(JSONObject response, String key) {
final Object value = response.remove(key);
if (null == value || JSONObject.NULL == value) {
LOGGER.warn("No field for key {}", key);
getLogger().warn("No field for key {}", key);
return null;
}
return value instanceof JSONObject ? (JSONObject) value : null;
Expand All @@ -167,7 +164,7 @@ protected JSONObject readObject(JSONObject response, String key) {
protected JSONArray readObjects(String key) {
final Object value = response.remove(key);
if (null == value || JSONObject.NULL == value) {
LOGGER.warn("No field for key {}", key);
getLogger().warn("No field for key {}", key);
return null;
}
return value instanceof JSONArray ? (JSONArray) value : null;
Expand All @@ -192,13 +189,20 @@ protected JSONArray readObjects(String key) {
* @param LOGGER The logger to use
*/
@SuppressWarnings("rawtypes")
protected void warnOnMissedKeys(Logger LOGGER) {
if (LOGGER.isWarnEnabled()) {
protected void warnOnMissedKeys() {
if (getLogger().isWarnEnabled()) {
Iterator keys = response.keys();
while (keys.hasNext()) {
String key = (String) keys.next();
LOGGER.warn("Found an unexpected key of '{}' in JSON that is not mapped to a field.", key);
getLogger().warn("Found an unexpected key of '{}' in JSON that is not mapped to a field.", key);
}
}
}

/**
* Get the logger to use for Logging from the base class
*
* @return The logger to use
*/
protected abstract Logger getLogger();
}

0 comments on commit a2a8864

Please sign in to comment.