Box API Connection Error Code 400
Hi,
We were unable to connect to box before because of error code 400. After the suggestion from BoX support team, we changed the server time to the Unix Time suggested by Box team.
After configuring we are able to connect to Box successfully but we will get the error code 400 exception after 1 hour. We have to restart our application after every hour to get the connection otherwise we will get 400 exception.
Can you please help us to find what is the issue. Below is the code written by our developer,
package com.edlore.box.util;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.sql.SQLException;
import java.util.ResourceBundle;
import com.box.sdk.BoxDeveloperEditionAPIConnection;
import com.box.sdk.EncryptionAlgorithm;
import com.box.sdk.IAccessTokenCache;
import com.box.sdk.InMemoryLRUAccessTokenCache;
import com.box.sdk.JWTEncryptionPreferences;
public class OurAppBoxAPIConnection {
private static final ResourceBundle resourceBundle = ResourceBundle.getBundle("*****");
private static final int MAX_DEPTH = 1;
private static final int MAX_CACHE_ENTRIES = 100;
private static OurAppBoxAPIConnection OurAppBoxAPIConnection = null;
private static String privateKey = null;
private static JWTEncryptionPreferences encryptionPref = null;
private static IAccessTokenCache accessTokenCache = null;
private static BoxDeveloperEditionAPIConnection api = null;
private OurAppBoxAPIConnection(){
// Default constructor
}
static {
try
{
OurAppBoxAPIConnection = new OurAppBoxAPIConnection();
privateKey = new String(Files.readAllBytes(Paths.get(resourceBundle.getString("PRIVATE_KEY_FILE"))));
encryptionPref = new JWTEncryptionPreferences();
encryptionPref.setPublicKeyID(resourceBundle.getString("PUBLIC_KEY_ID"));
encryptionPref.setPrivateKey(privateKey);
encryptionPref.setPrivateKeyPassword(resourceBundle.getString("PRIVATE_KEY_PASSWORD"));
encryptionPref.setEncryptionAlgorithm(EncryptionAlgorithm.RSA_SHA_256);
accessTokenCache = new InMemoryLRUAccessTokenCache(MAX_CACHE_ENTRIES);
}catch (Exception e) {
e.printStackTrace();
}
}
public static synchronized BoxDeveloperEditionAPIConnection getAppUserConnection()
{
if(api == null)
{
api = BoxDeveloperEditionAPIConnection.getAppUserConnection(resourceBundle.getString("USER_ID"), resourceBundle.getString("CLIENT_ID"),
resourceBundle.getString("CLIENT_SECRET"), encryptionPref, accessTokenCache);
}
if(api.canRefresh())
{
return api;
}
return api;
}
}
Please sign in to leave a comment.
Comments
1 comment