はい、リソースコンテキストは、同じリソースまたは別のリソースのPOST
とGET
の両方のメソッドにアクセスするために使用できます。
@Context
の助けを借りて、メソッドに簡単にアクセスできます。
@Path("a")
class A{
@GET
public Response getMethod(){
return Response.ok().build();
}
@POST
public Response postMethod(ExampleBean exampleBean){
return Response.ok().build();
}
}
あなたは今、次のようにResource B
からResource A
のメソッドにアクセスすることができます。
@Path("b")
class B{
@Context
private javax.ws.rs.container.ResourceContext rc;
@GET
public Response callMethod(){
//Calling GET method
Response response = rc.getResource(A.class).getMethod();
//Initialize Bean or paramter you have to send in the POST method
ExampleBean exampleBean = new ExampleBean();
//Calling POST method
Response response = rc.getResource(A.class).postMethod(exampleBean);
return Response.ok(response).build();
}
}
Aから1つのBのメソッドを呼び出すとしますか?確かに他のメソッド呼び出しと同じようにすることができますが、AにBのインスタンスを置く必要があります。別のURL(B)にHTTP POST呼び出しを行う場合は、httpclient(ジャージーまたはたとえば、httpclientのようなApache)。または単にリダイレクトを行うことができますhttp://stackoverflow.com/questions/20709386/dropwizard-how-to-do-a-server-side-redirect-from-a-view – gaganbm