0

JERSEY を使用して REST をセットアップしています。エンティティの異なるセットに対してほぼ同じ機能が必要です。この現在の機能を複製するにはどうすればよいですか?

@Path("/will")
public class FileResource {

private final BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService();
private final BlobInfoFactory blobInfoFactory = new BlobInfoFactory();

/* step 1. get a unique url */

@GET
@Path("/url")
public Response getCallbackUrl() {
  /* this is /_ah/upload and it redirects to its given path */
  String url = blobstoreService.createUploadUrl("/rest/will");
  return Response.ok(new FileUrl(url), MediaType.APPLICATION_JSON).build();
}

/* step 2. post a file */

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void post(@Context HttpServletRequest req, @Context HttpServletResponse res) throws IOException, URISyntaxException {
  Map<String, BlobKey> blobs = blobstoreService.getUploadedBlobs(req);
  BlobKey blobKey = blobs.get("files[]");
  res.sendRedirect("/rest/will/" + blobKey.getKeyString() + "/meta");
}

....

このクラスを複製して、意志を別のものに変更することはできますか?

4

1 に答える 1

1

ジャージーには魔法のようなものは何もありません。いつものようにスーパークラス化できます。例えば:

public class BaseResource
{

  @GET
  @Path("/url")
  public Response getCallbackUrl() {
    // Default code goes here
  }
}

@Path("/will")
public class WillResource extends BaseResource
{
  // Overrides go here
}

@Path("/abc")
public class AbcResource extends BaseResource
{
  // Overrides go here
}

これにより、/will/url および /abc/url の応答が返されます。

于 2013-02-15T16:07:21.420 に答える