grails (バージョン 0.8) で JAX-RS プラグインを使用しており、単一のデータ ポイントを表すドメイン クラスがあります。
class DataPoint {
static hasOne = [user: User]
int time
int accelerationX
int accelerationY
int accelerationZ
....
}
サーバーへのヒット数を減らすために、これらのコレクションを POST できるようにしたいと考えています (高頻度でサンプリングします)。
その JAX-RS プラグインはドメイン クラス コレクションを入力としてサポートしていないことを知っているので、src/groovy に単一のラッパーを作成しました。
public class DataPoints {
List<DataPoint> data = new ArrayList<>();
public void add(DataPoint dataPoint) {
data.add(dataPoint)
}
public List<DataPoint> getData() {
return data
}
}
生成された Resource クラスを使用しました
@Path('/api/data')
@Consumes(['application/xml', 'application/json'])
@Produces(['application/xml', 'application/json'])
class DataPointCollectionResource {
def dataPointResourceService
@POST
Response create(DataPoints dto) {
created dataPointResourceService.create(dto) //overwritten to take wrapper class
}
@GET
Response readAll() {
DataPoints dataPoints = new DataPoints();
DataPoint.findAll().each {
dataPoints.add(it)
}
ok dataPoints
}
}
ただし、これは機能しません。
私はいくつかのxmlを投稿しようとしました
<dataPoints>
<data>
<dataPoint>
<accelerationX>0</accelerationX>
<accelerationY>0</accelerationY>
<accelerationZ>0</accelerationZ>
<user id="1"/>
</dataPoint>
<dataPoint>
<accelerationX>0</accelerationX>
<accelerationY>0</accelerationY>
<accelerationZ>0</accelerationZ>
<user id="1"/>
</dataPoint>
</data>
</dataPoints>
カールの使用
curl -H "Content-Type: application/xml" -H "Accept: application/xml" --request POST -d <xml data> <path to resource>
私が得たエラーは次のとおりです。
ERROR container.ContainerRequest - A message body reader for Java class
com.wristband.atlas.SensorDataPoints, and Java type class
com.wristband.atlas.SensorDataPoints, and MIME media type application/xml was not found.
The registered message body readers compatible with the MIME media type are:
Resource で GET を実行しようとしても、ほとんど同じ結果が得られます。
どの設定が欠けているのかわからない前にJavaでこれを行ったので、何かが欠けていることはわかっています。
乾杯