とりあえずApache PDFBoxを使ってみる
まずApache PDFBoxをインストール(Gradle)
compile 'org.apache.pdfbox:pdfbox:2.0.5'
とりあえずコードを書いてみる
@Path("/job") public class Resource { @GET @UnitOfWork @Path("/pdf") @Produces(MediaType.TEXT_HTML) public PDDocument pdf() throws Exception { PDDocument document = new PDDocument(); PDPage blankPage = new PDPage(); document.addPage( blankPage ); // Save the newly created document document.save("BlankPage.pdf"); // finally make sure that the document is properly // closed. document.close(); return document; } }
実行したらエラー。
org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=text/html.
調べてみたら、JSONサービスが足りてなかったっぽいので足す。
compile 'org.glassfish.jersey.media:jersey-media-moxy:2.22.2'
もう一回実行したらまたエラー。
ERROR [2017-05-01 11:49:39,487] io.dropwizard.jersey.errors.LoggingExceptionMapper: Error handling a request: d92592dce5a88ddf ! org.glassfish.jersey.message.internal.MessageBodyProviderNotFoundException: MessageBodyWriter not found for media type=text/html, type=class org.apache.pdfbox.pdmodel.PDDocument, genericType=class org.apache.pdfbox.pdmodel.PDDocument. ! at org.glassfish.jersey.message.internal.WriterInterceptorExecutor$TerminalWriterInterceptor.aroundWriteTo(WriterInterceptorExecutor.java:247)
@Produces(MediaType.TEXT_HTML)
から@Produces(MediaType.APPLICATION_JSON)
に変更してみた。
JSONで何かが帰ってきたから成功なのかこれは?
{“allSecurityToBeRemoved”:false,“documentInformation”:{},“resourceCache”:{},“version”:1.4}
BlankPage.pdfというファイルが新たに保存されていたから成功かな…
コンソールからJSONでPOSTする方法
curl -H 'Content-Type:application/json' -X POST -d "{"key":"value", "key":"value"}" http://
エラー
{"code":400,"message":"Unable to process JSON"}
解決方法
curl -H 'Content-Type:application/json' -X POST -d '{"key":"value", "key":"value"}' http://
オプション-d
を" "
から' '
に変更したらうまくいった。
ローカルリポジトリを最新版にして、プッシュするまでの流れ
まずはmasterブランチを最新の状態にする
masterに移動
git checkout master
upstream(fork元)から最新のものを取ってくる
git fetch upstream
fetchしたものをローカルのmasterに反映させる(ローカルのmasterを最新にする)
git rebase upstream/master
最新にしたmasterをプッシュしておく
git push origin master
作業ブランチのコミットを1つにまとめてから最新にする
作業ブランチへ移動
git checkout 作業してるブランチ名
作業中のものを避ける
git stash
masterと差分のコミットを一つにまとめる
git rebase -i master
すると、こんな感じのが出てくる
pick ai9j38h 新機能追加 pick onw832h 修正 pick ji8h84h エラー修正 # Rebase bdd3996..bd66e17 onto bdd3996 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. #
i
を押してINSERTモードにして二つ目以降のコミットのpick
をsquash
へ変更する
pick ai9j38h 新機能追加 squash onw832h 修正 squash ji8h84h エラー修正 # Rebase bdd3996..bd66e17 onto bdd3996 # # Commands: # p, pick = use commit # r, reword = use commit, but edit the commit message # e, edit = use commit, but stop for amending # s, squash = use commit, but meld into previous commit # f, fixup = like "squash", but discard this commit's log message # x, exec = run command (the rest of the line) using shell # # If you remove a line here THAT COMMIT WILL BE LOST. # However, if you remove everything, the rebase will be aborted. #
esc
を押して、:wq
で保存する
作業してるブランチを最新にする
git rebase master 作業してるブランチ名
コンフリクトしたら、奴らと戦う
最新にした作業ブランチをプッシュ
git push origin 作業してるブランチ名