0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Proxyサーバ経由のBox接続(box-java-sdk使用)の開発環境

Posted at

はじめに

プロキシサーバ経由でBoxにファイルアップロードする環境をローカルPCに構築しようとした。
Boxへのファイルアップロードは、box-java-sdkを用いたJavのクライアントプログラム。
プロキシは、goproxyを使用した。

goproxyは以下のとおりに構築した。

環境

  • Windowss 10
  • CentOS 9 Stream(docker)
  • Java8
  • box-java-sdk 4.1.2
  • go 1.20.4

Proxyサーバ設定

モジュールインストール後、Proxyのコードは一番簡単そうなサンプルをそのまま使用した。

package main

import (
    "github.com/elazarl/goproxy"
    "log"
    "net/http"
)

func main() {
    proxy := goproxy.NewProxyHttpServer()
    proxy.Verbose = true
    log.Fatal(http.ListenAndServe(":8080", proxy))
}

Windowsの設定から手動プロキシを設定後、ブラウザから外部にアクセスしてログが出力されることを確認した。

image.png

Box接続部分のコード

JWT認証を使用。
BoxConfigに読み込んでいるのは、Boxアプリケーションを作成してダウンロードしたjsonファイル。java.net.Proxyを生成してBoxAPIConnectionにセットした。

【Proxyの設定部分】

        	private BoxAPIConnection boxApi;
    		BoxConfig config = BoxConfig.readFrom(reader);
            // リリースした環境では、configのみ渡すとハングアップした。
			//boxApi = BoxDeveloperEditionAPIConnection.getAppEnterpriseConnection(config); 
    		boxApi = new BoxDeveloperEditionAPIConnection(config.getEnterpriseId()
					,DeveloperEditionEntityType.ENTERPRISE
					,config.getClientId()
					,config.getClientSecret()
					,config.getJWTEncryptionPreferences());
	
			Proxy proxy = null;
			try {
				proxy = new Proxy(Proxy.Type.HTTP,
							new InetSocketAddress(InetAddress.getByName("127.0.0.1"), 8080));
					
			} catch (UnknownHostException e) {
				LOG.error("UnKnownHostException: {}", e.getMessage());
				e.printStackTrace();
			}

			boxApi.setProxy(proxy);
     ((BoxDeveloperEditionAPIConnection)boxApi).authenticate();
			LOG.info("BOX Connection ClientID: {}", boxApi.getClientID());

動作確認してみたが、最初のコネクション取得時に一回ログが出るが、それ以降は出力されない。。。

2023/06/16 09:15:46 [001] INFO: Running 0 CONNECT handlers
2023/06/16 09:15:46 [001] INFO: Accepting CONNECT to api.box.com:443
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?