小编Zuc*_*cca的帖子

如果HTTP PUT不存在,应该创建一个资源吗?

假设有人PUT对我的Endint 执行请求:

/resources/{id}
Run Code Online (Sandbox Code Playgroud)

但是我的PostgreSQL数据库中没有存储具有给定ID的资源。

根据RFC 2616,如果我能够执行以下操作,则应创建资源:

PUT方法请求将封闭的实体存储在提供的Request-URI下。如果Request-URI引用了已经存在的资源,则应将封闭的实体视为驻留在原始服务器上的实体的修改版本。如果Request-URI没有指向现有资源,并且请求用户代理能够将该URI定义为新资源,则原始服务器可以使用该URI创建资源。

可以使用提供的ID创建资源吗?由于在数据库插入上手动分配ID并不是最佳实践。

如果404无法创建资源,是否应该返回错误?

rest http put

3
推荐指数
1
解决办法
1696
查看次数

Jersey:如何注册MultiPartConfigProvider类

我正在尝试使用泽西加载多个文件,但它需要我一些我找不到的配置.这是依赖,我不得不添加它,因为泽西无法解析"multipart/related"类型:

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-multipart</artifactId>
    <version>2.7</version>
 </dependency>
Run Code Online (Sandbox Code Playgroud)

这是我使用multipart的API:

    @PUT
    @Consumes("multipart/related")
    @Path("/{id}/user/{userId}")
    public Response loadFile(@PathParam("id") int id, @PathParam("userId") int userId, MultiPart files) throws Exception{
        int resultado = tool.loadFile(id, userId, files);
        switch (resultado){
        case 401:   return Response.status(401).entity("No existe el experimento con id: "+id).build();
        case 402:   return Response.status(402).entity("El tipo de uno de los archivos no se encuentra en los tipos de entregables del experimento").build();
        case 403:   return Response.status(403).entity("El usuario: "+userId+" no participa en el experimento").build();
        case 405:   return Response.status(405).entity("Debe ingresar un comentario").build();
        case 406: …
Run Code Online (Sandbox Code Playgroud)

exception multipart jersey-2.0

1
推荐指数
1
解决办法
2937
查看次数

标签 统计

exception ×1

http ×1

jersey-2.0 ×1

multipart ×1

put ×1

rest ×1