LoginSignup
1
1

More than 5 years have passed since last update.

PlayframeworkでFixieを使う

Posted at

流行に乗って、Line botをPlayframework on Herokuで作ったのでメモ。

ここでは、Play WS APIを用い、Fixieのセットアップは済んだものとして進めます。

JVMのシステムパラメータでPROXYを指定する方法

procfileを変更

以下のパラメータを追加する。実際の値は適宜変更のこと。

パラメータ
http.proxyHost xxx.usefixie.com
http.proxyPort 80
http.proxyUser fixie
http.proxyPassword xxxxx

Proxy-Authorizationヘッダをセットする

def example(implicit ws:WSClient) {
    val encodedAuth = new BASE64Encoder().encode(new URL(System.getenv("FIXIE_URL")).getUserInfo.getBytes())

    val request = ws.url(LINE_API_URL).withHeaders("Proxy-Authorization" -> s"Basic $encodedAuth")
    ....
}

これでFixie経由でリクエストが飛ぶようになりますが、これだとすべてのリクエストがFixie経由になってしまいます。

Fixieのtricycleプランは、100MB/月・500リクエスト/月の制限があるので、無駄に使いたくないですね。

同じようにhttp.nonProxyHostsを指定すればいいですが、Line以外全部登録するとかだるい。

WSProxyServerを使う

def example(implicit ws:WSClient) {
    val encodedAuth = new BASE64Encoder().encode(new URL(System.getenv("FIXIE_URL")).getUserInfo.getBytes())

    ws.url(LINE_API_URL)
        .withHeaders("Proxy-Authorization" -> s"Basic $encodedAuth")
        .withProxyServer(
            DefaultWSProxyServer(
                host = "xxx.usefixie.com", 
                port = 80, 
                principal = Some("fixie"), 
                password = Some("xxxxx")
            )
        )

....
}

こうすることで、.withProxyServerしたリクエストのみPROXY経由になります。Procfileのパラメータは消しておきましょう。

1
1
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
1
1