相关疑难解决方法(0)

限制泽西岛中的路径媒体类型映射

我已经配置了MEDIA_TYPE_MAPPINGS我的 Jersey 应用程序。不幸的是,这会给我的应用程序中的通用上传服务带来一些麻烦。

@PUT
@Path("files/{filename}")
@Produces({ MediaType.APPLICATION_XML, MediaType.APPLICATION_JSON })
public Response uploadFile(
    @PathParam("filename") @NotNull @Size(max = 240) String filename, DataSource dataSource)
Run Code Online (Sandbox Code Playgroud)

如果有人上传,.../files/file.xml扩展名就会被删除。

有没有办法告诉 Jersey 跳过对此资源的过滤?

编辑:在 peeskillet 的回答之后,我的假设得到了证实。我已提交改进请求:https ://java.net/jira/browse/JERSEY-2780

java mapping jersey media-type jersey-2.0

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

Dropwizard和协议缓冲区示例

请注意:尽管这个问题特别提到了Dropwizard,但我相信任何具有Jersey / JAX-RS经验的人都应该能够回答这个问题,因为我认为Dropwizard只是遵循了Jersey / JAX-RS的惯例。


我有一个Dropwizard服务,该服务以JSON 进行改写 /编写,并且效果很好。

我现在想将其切换为读/写二进制数据(以最小化网络带宽)。我看到有Dropwizard-Protobuf库,但是我对在Dropwizard中实现二进制序列化有一些担忧。

首先,这是我当前(以JSON为中心)代码中的重要内容:

// Groovy pseudo-code

// Domain entity/POJO
@JsonIgnoreProperties(ignoreUnknown = true)
@JsonInclude(JsonInclude.Include.NON_NULL)
class Fizz {
    @JsonProperty
    String name

    @JsonProperty
    boolean isBuzz    
}

// The Dropwizard app entry point
class FizzService extends Application<FizzConfiguration> {
    @Override
    void run(FizzConfiguration fizzCfg, Environment env) throws Exception {
        // ... lots of stuff

        env.jersey().register(new FizzService())
    }
}

// JAX-RS resource with a sample GET endpoint
@Path(value = "/fizz")
@Produces(MediaType.APPLICATION_JSON)
class …
Run Code Online (Sandbox Code Playgroud)

jax-rs jersey protocol-buffers binary-serialization dropwizard

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