2013-02-15 45 views
0

我使用JERSEY工作的REST设置。对于不同的实体集,我需要几乎相同的功能。我需要做些什么来克隆这个当前的功能?使用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"); 
} 

.... 

我可以简单地复制这个类,并改变其他东西吗?

回答

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 
} 

这会给你/会/ URL和/ ABC/URL

+0

我建议,这只不过是足够先进的技术反应,但我明白你在说什么。 – jgm 2013-02-15 16:50:23

相关问题