私はGET POSTメソッドとDELETEメソッドを持つ単純なRESTクライアントを持っています。Java Rest @GETは動作しますが、@ DELETEと@POSTパスはヒットしません。
奇妙なことに、GETメソッドだけが動作し、POSTもDELETEもヒットしないし、応答も「404 Not Found」です。
は、ここに私のRESTサービスとクライアントです:
インタフェース:
public interface MyInterface {
@GET
@Path("/content")
@Produces(MediaType.APPLICATION_JSON)
Response getAirports();
@DELETE
@Path("/content/{id}")
@Produces(MediaType.APPLICATION_JSON)
Response deleteAirport(@PathParam("id") String id);
}
実装:
@Path("/source")
public class SourceService extends AbstractService implements MyInterface {
@Override
public Response getContent() {
DBCollection collection = getDBCollection("content");
DBCursor cursor = collection.find();
String serialize = JSON.serialize(cursor);
return Response.status(Response.Status.OK).entity(serialize).build();
}
@Override
public Response deleteContent(@PathParam("id") Integer id) {
DBCollection collection = getDBCollection("content");
BasicDBObject query = new BasicDBObject();
query.append("id", id);
collection.remove(query);
return Response.status(Response.Status.OK).build();
}
}
クライアント:
// This is working
public void getContent() {
WebTarget path = collect.path("/content");
Response response = path.request().get();
LOGGER.info("collect.ping: " + response.readEntity(String.class) + "\n");
}
// This is not working
public void deleteContent(Integer id) {
WebTarget path = collect.path("/content/"+id);
Response response = path.request(MediaType.APPLICATION_JSON).delete();
System.out.println("object deleted:"+response);
}
私はジャージを要求して試してみましたまたはapa cheクライアントは、しかし、それらのすべては404を返して、今私は絶望的です。
私に指示を与えることを望みます。
問題を少し軽減してみてください。実装がただちにOK応答を返すようにする。 – Chill
@ChillちょうどPathParamを削除しようとするとヒットし、OKを返します。どのようにそのことについて?私は間違った方法でパスパラメータを送信していますか? – neocorp
"airport"などの文字列に変更しようとしています。また、次のようにクライアントにパラメータを渡しています。 public void deleteAirport(String iata){ "iata"あなたのクライアントコードで... –