This page (revision-1) was last changed on 20-Apr-2024 11:53 by Hiroaki Tateshita

Only authorized users are allowed to rename pages.

Only authorized users are allowed to delete pages.

Page revision history

Version Date Modified Size Author Changes ... Change note
20-Apr-2024 11:53 1 KB Hiroaki Tateshita

Page References

Incoming links Outgoing links

Version management

Difference between version and

At line 1 added 31 lines
[{PageViewPlugin}]
[ServiceMix], [Twitter Account Activity API]
!!!Abstract
|Sometime I have developed web services such as [gnssws|https://github.com/tateshitah/gnssfinder/tree/master/gnssws], [tlews] and [https://github.com/tateshitah/webhook]. I would like to record information related to web service.
!!!Topic
!! How to describe the interface
| It should be referred existing web services such as recruit web service[1].
!! How to make it
*General
| I like [Java], so Jersey which is one of implementation of JAX-RS[2] should be recommended.
*[Tomcat]を使って実装
| check [3]!Servlet3.0以降、[Tomcat]7以降だとweb.xmlの設定がいらなくなるが、その条件として、ResourceConfigクラスを継承したConfigクラスをつくり、Pathを指定しておくのがポイントか。うまくいくと、hostname/application name/ResourceConfigで設定したpath/Pathアノテーションで設定したパス名?**=**...でアクセスできるようになります。最後までインプットしないと404がでるかも。
|まあ、別にWeb.xmlを編集してもいいんだけどね。gnsswsは、そっちでやってます。
*POSTの扱い
|Twitterのwebhookに成功すると。JSONをPostしてきます。POSTアノテーションを指定したメソッドでその処理をするのですが、JSONのようなTextを受け取るときのやり方が意外と探すのに苦労。ここ[4]をみながら、以下のように実装するとできた。
{{{
@POST
public Response postIt(String body){
ResponseBuilder builder=Response.ok();
System.out.println("something posted!"+body);
return builder.build();
}
}}}
*Jerseyを使っていて、JDK11にすると、コンパイルは通るけど実行上は、java.lang.NoClassDefFoundError: javax/activation/DataSourceとか起きて、動きません。原因は、Jerseyの中で使っているJAFとJAXBがJDK11ではなくなっているため。[5]で解決。Jerseyのアップデートでも解決するのだろうか。。
!!!Reference
#[#1]Recruit Co., Ltd., リクルート WEBサービス, [http://webservice.recruit.co.jp]
#[#2]Oracle Corporation, Jersey, [https://jersey.github.io]
#[#3]edgegram, 2015-11-25, Jerseyの設定2(web.xmlとかApplicationクラスとか), [https://edgegram.hatenablog.jp/entry/2015/11/25/194919]
#[#4]Stack Over Flow, 2016-12-16, How do I get the JSON body in Jersey?, [https://stackoverflow.com/questions/41157949/how-do-i-get-the-json-body-in-jersey]
#[#5]YUICHI SAKURABA, 2018年7月4日, 事例から学ぶ、Java SE 11移行、[http://www.javainthebox.com/2018/07/java-se-11.html]