Failing to connect using getAppEnterpriseConnection


I’m new using’s Java SDK. The application I’m working is trying to use Java to connect to in order to download a file. The application is a Spring Boot project, version 2.5.9, compiled using Java 8.

The code below “fails” in method: BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, tokenCache). The method does not throw an error and never comes back from the call. The thread this process is in Stops.

         try { 
      Reader reader = new FileReader("D:/Box/xxxxxxx_config.json");
      BoxConfig boxConfig = BoxConfig.readFrom(reader);
      IAccessTokenCache tokenCache = new InMemoryLRUAccessTokenCache(100);

      BoxDeveloperEditionAPIConnection api = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(boxConfig, tokenCache);

      BoxFile file = new BoxFile(api, "1081XXXXXXXXX");
      BoxFile.Info info = file.getInfo();

      FileOutputStream stream = new FileOutputStream(info.getName());;

      try {
      } catch (IOException e) {
        System.out.println("Failed to close output stream" + e);
    } catch (BoxAPIException e) {
      System.out.println("Error creating Box enterprise client");
    } catch (IOException e1) {
      System.out.println("Error creating Box enterprise client:" + e1);
    } catch (Exception e2) {
      System.out.println("Error - Run time exception" + e2);

Debugging indicates that the call to new OkHttpClient.Builder(this.httpClient) in method BoxAPIConnection.buildHttpClients() fails.

  private void buildHttpClients() {
      OkHttpClient.Builder httpClientBuilder = new OkHttpClient.Builder();
      if (this.trustManager != null) {
         try {
            SSLContext sslContext = SSLContext.getInstance("SSL");
            sslContext.init((KeyManager[])null, new TrustManager[]{this.trustManager}, new SecureRandom());
            httpClientBuilder.sslSocketFactory(sslContext.getSocketFactory(), this.trustManager);
         } catch (KeyManagementException | NoSuchAlgorithmException var3) {
            throw new RuntimeException(var3);

      OkHttpClient.Builder builder = httpClientBuilder.followSslRedirects(true).followRedirects(true).connectTimeout(Duration.ofMillis((long)this.connectTimeout)).readTimeout(Duration.ofMillis((long)this.readTimeout)).connectionSpecs(Collections.singletonList(ConnectionSpec.MODERN_TLS));
      if (this.hostnameVerifier != null) {

      if (this.proxy != null) {
         if (this.proxyUsername != null && this.proxyPassword != null) {
            builder.proxyAuthenticator((route, response) -> {
               String credential = Credentials.basic(this.proxyUsername, this.proxyPassword);
               return response.request().newBuilder().header("Proxy-Authorization", credential).build();

         if (this.authenticator != null) {

      builder = this.modifyHttpClientBuilder(builder);
      this.httpClient =;
      this.noRedirectsHttpClient = (**new OkHttpClient.Builder(this.httpClient)**).followSslRedirects(false).followRedirects(false).build();

I’ve tried SDK versions 4.0.0, 4.6.1 as well as 4.7.0, with the same result.

Any advice on how to solve this issue would be helpful.

Thanks in advance,


Hi @Bob_B, welcome to the forum.

I’m not versed in Java, let me see if I can get someone from the Java SDK team to help.


I think we’ve may have gotten this solved. We upgrade the Spring Boot version to 2.7.18.

Let me get back to you if that is not the issue.