読者です 読者をやめる 読者になる 読者になる

t.marcusの外部記憶装置

忘備録とかちょっとした考えとかをつらつらと...

Apache HttpClient4.3でSSLの証明書とホスト名のチェックを回避する

Java

Hostsファイルにローカルアドレスを書いて、httpsでしか口が開いていないサーバにリクエストを投げると、

javax.net.ssl.SSLException: hostname in certificate didn't match

↑みたいな例外を投げられて(´A`)ってなるので、
オレオレ証明書javaに登録するか、SSL証明書のチェックを回避して、リクエストするみたいな処理をするかの二通りになる。

前者はググれば結構情報見つかるけど、手順が面倒くさそうなので、後者で…

Apache HttpClient4.2だと下みたいなコードで、SSLの証明書とホスト名のチェックを回避出来たけど、

Apache HttpClient v4.2(org.apache.httpcomponents.httpclient:4.2.5)版

gist01f9c5228913c24d25f1

4.3になってからSSLSocketFactoryとかSchemeRegistryとかSchemeとかが@Deprecatedになったので
以下みたいな書き方をしないとダメっぽい。

Apache HttpClient v4.3(org.apache.httpcomponents.httpclient:4.3.4)版

giste7da2f90fd962cedc780

基本的なことは、4.3のjavadocとかに書いてあるので、それにそって、適宜ポーティングする感じ。
ただ、4.2と比較すると4.3はコード量が多い…

Mac + Eclipse + Subclipseの環境構築 その2

Mac 開発環境

Eclipse4.3に乗り換えてSVNレポジトリが参照できなくなったので、またJavaHL周りの問題かと思いbrew unlinkして再インストールしたところ以下の様なエラーが出たので、忘備録として書いておく

    Incompatible library version
svn: ra_serf was compiled for serf 1.3.3 but loaded an incompatible 1.1.1 library

JavaHL周りの問題かと思って、まずsubversionを再インストールした

# 古いsubversionをunlink
$ brew unlink subversion
Unlinking /usr/local/Cellar/subversion/1.7.8... 67 links removed

# 新しいsubversionをインストール
$ brew install --universal --java subversion
==> Installing dependencies for subversion: sqlite, autoconf, automake, scons
==> Installing subversion dependency: sqlite
==> Downloading http://www.sqlite.org/2013/sqlite-autoconf-3080200.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/sqlite/3.8.2 --enable-dynamic-extensions
==> make install
==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

OS X provides an older sqlite3.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/sqlite/lib
    CPPFLAGS: -I/usr/local/opt/sqlite/include

==> Summary
OK  /usr/local/Cellar/sqlite/3.8.2: 9 files, 3.4M, built in 2.3 minutes
==> Installing subversion dependency: autoconf
==> Downloading http://ftpmirror.gnu.org/autoconf/autoconf-2.69.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/autoconf/2.69
==> make install
OK  /usr/local/Cellar/autoconf/2.69: 69 files, 2.0M, built in 10 seconds
==> Installing subversion dependency: automake
==> Downloading http://ftpmirror.gnu.org/automake/automake-1.14.1.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/automake/1.14.1
==> make install
OK  /usr/local/Cellar/automake/1.14.1: 127 files, 2.5M, built in 11 seconds
==> Installing subversion dependency: scons
==> Downloading http://downloads.sourceforge.net/scons/scons-2.3.0.tar.gz
######################################################################## 100.0%
==> /usr/bin/python setup.py install --prefix=/usr/local/Cellar/scons/2.3.0 --standalone-lib --install-lib=/usr/local/Cellar/scons/2.3
OK  /usr/local/Cellar/scons/2.3.0: 395 files, 4.2M, built in 82 seconds
==> Installing subversion
==> Downloading http://www.apache.org/dyn/closer.cgi?path=subversion/subversion-1.8.5.tar.bz2
==> Best Mirror http://ftp.tsukuba.wide.ad.jp/software/apache/subversion/subversion-1.8.5.tar.bz2

curl: (22) The requested URL returned error: 404
Trying a mirror...
==> Downloading http://archive.apache.org/dist/subversion/subversion-1.8.5.tar.bz2
######################################################################## 100.0%
==> Patching
patching file subversion/bindings/swig/perl/native/Makefile.PL.in
==> Downloading http://serf.googlecode.com/files/serf-1.3.3.tar.bz2
######################################################################## 100.0%
==> scons PREFIX=/usr/local/Cellar/subversion/1.8.5/libexec/serf GSSAPI=/usr CC=/usr/bin/clang CFLAGS=-Os -w -pipe -march=native -mmac
==> scons install
Warning: JAVA_HOME is set. Try unsetting it if JNI headers cannot be found.
==> ./autogen.sh
==> ./configure --prefix=/usr/local/Cellar/subversion/1.8.5 --with-apr=/usr/local/Library/ENV/4.3 --with-zlib=/usr --with-sqlite=/usr/
==> make
==> make install
==> make tools
==> make install-tools
==> make javahl
==> make install-javahl
==> Caveats
svntools have been installed to:
  /usr/local/opt/subversion/libexec

You may need to link the Java bindings into the Java Extensions folder:
  sudo mkdir -p /Library/Java/Extensions
  sudo ln -s /usr/local/lib/libsvnjavahl-1.dylib /Library/Java/Extensions/libsvnjavahl-1.dylib

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
OK  /usr/local/Cellar/subversion/1.8.5: 119 files, 18M, built in 9.8 minutes

Eclipseを起動して、レポジトリを参照してみると冒頭のエラーが出た。

1.3.3向けにコンパイルされているはずなのに、1.1.1のライブラリがロードされた云々と言われているので確認する

$ brew list serf
/usr/local/Cellar/serf/1.1.1/include/serf-1/ (4 files)
/usr/local/Cellar/serf/1.1.1/lib/libserf-1.0.dylib
/usr/local/Cellar/serf/1.1.1/lib/pkgconfig/serf-1.pc
/usr/local/Cellar/serf/1.1.1/lib/ (2 other files)

確かに。

ということで、1.1.1をremove

$ brew remove serf
Uninstalling /usr/local/Cellar/serf/1.1.1...

肝心のserf1.3.3は、subversionのlibexecとして入れられてるので大丈夫?

$ ll /usr/local/Cellar/subversion/1.8.5/libexec/serf/lib/
total 1016
-rwxr-xr-x  1 tmarcus  admin  229684  5  2 17:08 libserf-1.1.3.0.dylib*
-rw-r--r--  1 tmarcus  admin  282360  5  2 17:08 libserf-1.a
lrwxr-xr-x  1 tmarcus  admin      21  5  2 17:08 libserf-1.dylib@ -> libserf-1.1.3.0.dylib
drwxr-xr-x  3 tmarcus  admin     102  5  2 17:08 pkgconfig/

かとおもったが、結局また、JavaHLのライブラリが見つからないと怒られたので、再度、subversionをインストール

$ brew install --universal --java subversion
Error: subversion-1.8.5 already installed
To install this version, first `brew unlink subversion'
[17:45:40 A12649@PC-5861 ~]$ brew unlink subversion
Unlinking /usr/local/Cellar/subversion/1.8.5... 66 symlinks removed
[17:45:52 A12649@PC-5861 ~]$ brew install --universal --java subversion
==> Installing dependencies for subversion: readline, sqlite, scons, openssl
==> Installing subversion dependency: readline
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/readline-6.3.3.mountain_lion.bottle.tar.gz
######################################################################## 100.0%
==> Pouring readline-6.3.3.mountain_lion.bottle.tar.gz
==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.

OS X provides the BSD libedit library, which shadows libreadline.
In order to prevent conflicts when programs look for libreadline we are
defaulting this GNU Readline installation to keg-only.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/readline/lib
    CPPFLAGS: -I/usr/local/opt/readline/include

==> Summary
OK  /usr/local/Cellar/readline/6.3.3: 40 files, 2.1M
==> Installing subversion dependency: sqlite
==> Downloading http://sqlite.org/2014/sqlite-autoconf-3080403.tar.gz
######################################################################## 100.0%
==> ./configure --prefix=/usr/local/Cellar/sqlite/3.8.4.3 --enable-dynamic-extensions
==> make install
==> Caveats
This formula is keg-only, so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

OS X provides an older sqlite3.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/sqlite/lib
    CPPFLAGS: -I/usr/local/opt/sqlite/include

==> Summary
OK  /usr/local/Cellar/sqlite/3.8.4.3: 9 files, 3.4M, built in 2.2 minutes
==> Installing subversion dependency: scons
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/scons-2.3.1.mountain_lion.bottle.3.tar.gz
######################################################################## 100.0%
==> Pouring scons-2.3.1.mountain_lion.bottle.3.tar.gz
OK  /usr/local/Cellar/scons/2.3.1: 205 files, 2.4M
==> Installing subversion dependency: openssl
==> Downloading https://downloads.sf.net/project/machomebrew/Bottles/openssl-1.0.1g.mountain_lion.bottle.tar.gz
######################################################################## 100.0%
==> Pouring openssl-1.0.1g.mountain_lion.bottle.tar.gz
==> Caveats
A CA file has been bootstrapped using certificates from the system
keychain. To add additional certificates, place .pem files in
  /usr/local/etc/openssl/certs

and run
  /usr/local/opt/openssl/bin/c_rehash

This formula is keg-only, so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

The OpenSSL provided by OS X is too old for some software.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/openssl/lib
    CPPFLAGS: -I/usr/local/opt/openssl/include

==> Summary
OK  /usr/local/Cellar/openssl/1.0.1g: 429 files, 15M
==> Installing subversion
==> Downloading http://www.apache.org/dyn/closer.cgi?path=subversion/subversion-1.8.8.tar.bz2
==> Best Mirror http://ftp.jaist.ac.jp/pub/apache/subversion/subversion-1.8.8.tar.bz2
######################################################################## 100.0%
==> Patching
patching file subversion/bindings/swig/perl/native/Makefile.PL.in
Hunk #1 succeeded at 76 (offset 7 lines).
patching file configure.ac
==> Downloading http://serf.googlecode.com/svn/src_releases/serf-1.3.4.tar.bz2
######################################################################## 100.0%
==> /usr/local/opt/scons/bin/scons PREFIX=/usr/local/Cellar/subversion/1.8.8/libexec/serf GSSAPI=/usr CC=/usr/bin/clang CFLAGS=-Os -w
==> /usr/local/opt/scons/bin/scons install
Warning: JAVA_HOME is set. Try unsetting it if JNI headers cannot be found.
==> ./autogen.sh
==> ./configure --prefix=/usr/local/Cellar/subversion/1.8.8 --with-apr=/usr/local/Library/ENV/4.3 --with-zlib=/usr --with-sqlite=/usr/
==> make
==> make install
==> make tools
==> make install-tools
==> make javahl
==> make install-javahl
==> Caveats
svntools have been installed to:
  /usr/local/opt/subversion/libexec

You may need to link the Java bindings into the Java Extensions folder:
  sudo mkdir -p /Library/Java/Extensions
  sudo ln -s /usr/local/lib/libsvnjavahl-1.dylib /Library/Java/Extensions/libsvnjavahl-1.dylib

Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
OK  /usr/local/Cellar/subversion/1.8.8: 119 files, 18M, built in 7.4 minutes

subversion1.8.8が入ったっぽいので、eclipse.iniのパスを1.8.8に書き換える

$ cat /Applications/eclipse43-sr2/Eclipse.app/Contents/MacOS/eclipse.ini | grep java.library.path
-Djava.library.path=.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:/usr/local/Cellar/subversion/1.8.8/lib

上記の手順でちゃんと動きますた。

いい加減Gitに移行したい…

Mac + Eclipse + Subclipseの環境構築

Mac 開発環境

EclipseSubclipseを使うときにSubversion Native Library Not Availableって怒られるので、それの解決方法に関して書いておきます。

基本的にはkawa_xxxさんの記事の通り
http://d.hatena.ne.jp/kawa_xxx/20110930/1317381845

環境

1.Subclipse拡張をインストール
Eclipse Market Placeを開いて「Subclipse」で検索してInstall。

2.subversionライブラリをインストール
ライブラリ見つからないよって怒られるので、brewでインストール

$ brew install --universal --java subversion

3.Eclipsejava.library.pathに追加
kawa_xxxさんの記事では、/usr/local/lib/libsvnjavahl-1.dylibを/Library/Java/Extensionsにシンボリックリンクを張っているが、私の環境ではそれで動かなかった。

[tmarcus@MarcusMBP15 ~]$ brew install --universal --java subversion
==> Installing subversion dependency: neon
==> Downloading http://www.webdav.org/neon/neon-0.29.6.tar.gz
Already downloaded: /Library/Caches/Homebrew/neon-0.29.6.tar.gz
==> ./configure --prefix=/usr/local/Cellar/neon/0.29.6 --enable-shared --disable-static --with-ssl
==> make install
==> Caveats
This formula is keg-only: so it was not symlinked into /usr/local.

Mac OS X already provides this software and installing another version in
parallel can cause all kinds of trouble.

Compiling newer versions of Subversion on 10.6 require this newer neon.

Generally there are no consequences of this for you. If you build your
own software and it requires this formula, you'll need to add to your
build variables:

    LDFLAGS:  -L/usr/local/opt/neon/lib
    CPPFLAGS: -I/usr/local/opt/neon/include

==> Summary
/usr/local/Cellar/neon/0.29.6: 172 files, 1.4M, built in 16 seconds
==> Installing subversion dependency: sqlite
==> Downloading http://sqlite.org/sqlite-autoconf-3071400.tar.gz
Already downloaded: /Library/Caches/Homebrew/sqlite-3.7.14.tar.gz
==> ./configure --prefix=/usr/local/Cellar/sqlite/3.7.14 --enable-dynamic-extensions
==> make install
/usr/local/Cellar/sqlite/3.7.14: 9 files, 3.2M, built in 45 seconds
==> Installing subversion dependency: serf
==> Downloading http://serf.googlecode.com/files/serf-1.1.0.tar.bz2
Already downloaded: /Library/Caches/Homebrew/serf-1.1.0.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/serf/1.1.0 --with-apr=/usr/local/Library/ENV/4.3
==> make install
/usr/local/Cellar/serf/1.1.0: 11 files, 504K, built in 7 seconds
==> Installing subversion
==> Downloading http://www.apache.org/dyn/closer.cgi?path=subversion/subversion-1.7.6.tar.bz2
Already downloaded: /Library/Caches/Homebrew/subversion-1.7.6.tar.bz2
==> ./configure --prefix=/usr/local/Cellar/subversion/1.7.6 --with-ssl --with-zlib=/usr --with-sqlite=/usr/local --with-serf=/usr/lo
==> make
==> make install
==> make javahl
==> make install-javahl
==> Caveats
You may need to link the Java bindings into the Java Extensions folder:
  sudo mkdir -p /Library/Java/Extensions
  sudo ln -s /usr/local/lib/libsvnjavahl-1.dylib /Library/Java/Extensions/libsvnjavahl-1.dylib

==> Caveats
Bash completion has been installed to:
  /usr/local/etc/bash_completion.d
==> Summary
/usr/local/Cellar/subversion/1.7.6: 99 files, 14M, built in 3.1 minutes

brewでのインストール先が違う模様なので(最後の手順も変、、、)、eclipse.iniに直接パスを指定する。
ダイアログに書かれてるパスをメモって、そこにインストールディレクトリを追加して、VMの起動オプションに追加する

ダイアログに書かれてるパス)
java.library.path=.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java

eclipse.iniに追記するオプション)
-Djava.library.path=.:/Library/Java/Extensions:/System/Library/Java/Extensions:/usr/lib/java:/usr/local/Cellar/subversion/1.7.6/lib

私の環境では、これで動きました。