Skip to content

Commit

Permalink
Move all System.out.println to slf4j log statements
Browse files Browse the repository at this point in the history
(and fix a few typos)
  • Loading branch information
Jesper Joergensen committed Apr 17, 2016
1 parent f2014cd commit 52c3c08
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 10 deletions.
11 changes: 11 additions & 0 deletions pom.xml
Expand Up @@ -43,11 +43,22 @@
</distributionManagement>

<dependencies>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
<version>1.7.9</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>[2.5.0,2.5.1]</version>
</dependency>
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>1.7.9</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
Expand Down
19 changes: 11 additions & 8 deletions src/main/java/com/force/api/ForceApi.java
Expand Up @@ -10,9 +10,10 @@
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
Expand Down Expand Up @@ -42,6 +43,8 @@ public class ForceApi {

private static final ObjectMapper jsonMapper;

private static final Logger logger = LoggerFactory.getLogger(ForceApi.class);

static {
jsonMapper = new ObjectMapper();
jsonMapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
Expand Down Expand Up @@ -180,8 +183,8 @@ public CreateOrUpdateResult createOrUpdateSObject(String type, String externalId
} else if(res.getResponseCode()==204) {
return CreateOrUpdateResult.UPDATED;
} else {
System.out.println("Code: "+res.getResponseCode());
System.out.println("Message: "+res.getString());
logger.debug("Code: {}",res.getResponseCode());
logger.debug("Message: {}",res.getString());
throw new RuntimeException();
}

Expand Down Expand Up @@ -315,8 +318,8 @@ private final HttpResponse apiRequest(HttpRequest req) {
HttpResponse res = Http.send(req);
if(res.getResponseCode()==401) {
// Perform one attempt to auto renew session if possible
if(autoRenew) {
System.out.println("Session expired. Refreshing session...");
if (autoRenew) {
logger.debug("Session expired. Refreshing session...");
if(session.getRefreshToken()!=null) {
session = Auth.refreshOauthTokenFlow(config, session.getRefreshToken());
} else {
Expand All @@ -334,16 +337,16 @@ private final HttpResponse apiRequest(HttpRequest req) {
}
} else if(req.getExpectedCode()!=-1 && res.getResponseCode()!=req.getExpectedCode()) {
throw new RuntimeException("Unexpected response from Force API. Got response code "+res.getResponseCode()+
". Was expecing "+req.getExpectedCode());
". Was expecting "+req.getExpectedCode());
} else {
return res;
}
}

/**
* Normalizes the JSON response in case it contains responses from
* Relationsip queries. For e.g.
*
* relationship queries. For e.g.
*
* <code>
* Query:
* select Id,Name,(select Id,Email,FirstName from Contacts) from Account
Expand Down
7 changes: 6 additions & 1 deletion src/main/java/com/force/api/http/Http.java
@@ -1,5 +1,8 @@
package com.force.api.http;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.ByteArrayOutputStream;
Expand All @@ -11,6 +14,8 @@


public class Http {

static final Logger logger = LoggerFactory.getLogger(Http.class);

static final byte[] readResponse(InputStream stream) throws IOException {
BufferedInputStream bin = new BufferedInputStream(stream);
Expand Down Expand Up @@ -63,7 +68,7 @@ public static final HttpResponse send(HttpRequest req) {
return new HttpResponse().setStream(conn.getInputStream()).setResponseCode(code);
}
} else {
System.out.println("Bad response code: " + code + " on request:\n" + req);
logger.info("Bad response code: {} on request: {}", code, req);
HttpResponse r = new HttpResponse().setString(
new String(readResponse(conn.getErrorStream()), "UTF-8")).setResponseCode(code);
return r;
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/com/force/api/EndToEndOAuthFlowExample.java
Expand Up @@ -45,7 +45,7 @@ public void endToEndOAuthFlowTest() throws FailingHttpStatusCodeException, Malfo

// --------------------------------------------------------------------
// This part is what you'd normally do somewhere in your web app when
// you want to authenticate an unauthenticate user.
// you want to authenticate an unauthenticated user.

ApiConfig config = new ApiConfig().setClientId(Fixture.get("clientId"))
.setClientSecret(Fixture.get("clientSecret")).setRedirectURI(Fixture.get("redirectURI"));
Expand Down

0 comments on commit 52c3c08

Please sign in to comment.