Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/384.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 使用JERSEY设置重复的REST服务_Java_Jersey - Fatal编程技术网

Java 使用JERSEY设置重复的REST服务

Java 使用JERSEY设置重复的REST服务,java,jersey,Java,Jersey,我有一个工作休息设置使用球衣。对于不同的实体集,我需要几乎相同的功能。要克隆此当前功能,我需要做什么 @Path("/will") public class FileResource { private final BlobstoreService blobstoreService = BlobstoreServiceFactory.getBlobstoreService(); private final BlobInfoFactory blobInfoFactory = new BlobIn

我有一个工作休息设置使用球衣。对于不同的实体集,我需要几乎相同的功能。要克隆此当前功能,我需要做什么

@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");
}

....
@Path(“/will”)
公共类文件资源{
私有最终BlobstoreService BlobstoreService=BlobstoreServiceFactory.getBlobstoreService();
私有最终BlobInfoFactory BlobInfoFactory=新BlobInfoFactory();
/*步骤1.获取唯一的url*/
@得到
@路径(“/url”)
公共响应getCallbackUrl(){
/*这是/_ah/upload,它重定向到给定路径*/
字符串url=blobstoreService.createUploadUrl(“/rest/will”);
返回Response.ok(新文件url(url),MediaType.APPLICATION_JSON.build();
}
/*步骤2.发布文件*/
@职位
@使用(MediaType.MULTIPART\u FORM\u数据)
public void post(@Context-HttpServletRequest-req,@Context-HttpServletResponse-res)抛出IOException、URISyntaxException{
Map blobs=blobstoreService.getUploadedBlobs(req);
BlobKey-BlobKey=blobs.get(“文件[]”);
res.sendRedirect(“/rest/will/”+blobKey.getKeyString()+”/meta”);
}
....

我可以简单地复制这个类并将其更改为其他类吗?

Jersey没有什么神奇之处,您可以像往常一样创建超类。例如:

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的回复,我认为这是一种足够先进的技术,但我理解您的意思。