Tag: jersey

如何在Jersey中使用自定义validation

我想在泽西中实现validation,这样如果我发送一个已经存在于DataBase中的UserName或Email的重复值,那么它应该抛出一个错误,说UserName / Email已经存在。 我该如何实现这一目标? 我浏览了这个jersey文件 https://jersey.java.net/documentation/latest/bean-validation.html https://github.com/jersey/jersey/tree/2.6/examples/bean-validation-webapp/src 但是我无法理解我必须遵循什么才能进行自定义的Jerseyvalidation。 假设我在创建用户时在Body中发送Json,如: { “name”:”Krdd”, “userName”:”khnfknf”, “password”:”sfastet”, “email”:”xyz@gmail.com”, “createdBy”:”xyz”, “modifiedBy”:”xyz”, “createdAt”:””, “modifiedAt”:””, } 在此先感谢您的帮助。

如何在测试类中为所有测试启动Jersey测试容器(Grizzly)一次?

我正在努力修复其中一个项目中的集成测试。 目前,所有集成测试类都扩展了JerseyTest类。 通过JerseyTest类,我意识到它使用Junit的Before和After注释为每个测试方法启动和停止容器。 为什么这有必要? 如果我们提起容器一次,运行测试并在结束时将其关闭,这还不够吗? 我们也使用Spring,上下文初始化需要时间。 在Junit4之前,我们通过使用布尔标志手动处理它来解决这个限制。 @Before public void setup() { if(!containerStarted) { // start containerStarted = true; } // else do nothing }

jackson2.0与泽西岛1.12

有没有人设法使用jackson2.0与泽西1.12。 知道这将是非常有趣的。 我们必须在整个地方使用jackson1.9.x,因为jersey有jackson如此强烈耦合。 从我所看到的甚至jersey2.0M3仍然使用jackson1.9.2。 所以似乎没有必要等待jersey队在不久的将来做到这一点。

泽西岛的身份validation

我想为我的基于Jersey0的服务器/客户端REST实现身份validation,但我不确定如何布置代码。 基本上对于每个操作我有2个方法 – 从服务器端1个,从客户端1个。 我缩小了算法范围 – 我将使用亚马逊策略和HMAC。 问题是如何在代码中列出这个 – 我应该将身份validation(加密/解密代码)添加到每个方法 – 服务器/客户端还是我应该在两端都有一个“dispatch”方法来执行加密/解密,然后将执行控制转移到一个更专业的版本,这将我有一个中心位置,在客户端或服务器进行身份validation? 我愿意听听你对此的评论吗?

在泽西岛编组通用类型

我需要返回几个结果和结果总数的客户列表。 我必须在具有不同实体的几个地方这样做,所以我希望有一个具有这两个属性的generics类: @XmlRootElement public class QueryResult implements Serializable { private int count; private List result; public QueryResult() { } public void setCount(int count) { this.count = count; } public void setResult(List result) { this.result = result; } public int getCount() { return count; } public List getResult() { return result; } } 和服务: @GET @Produces({MediaType.APPLICATION_JSON, […]

如何从ContainerRequestContext获取路径参数

我想为我的REST API端点应用授权filter,并且filter需要path参数来进行过滤。 这是我的端点和代码: 终点: curl –url ‘localhost:80/reports/resources/org/12345/product/111 ‘ –request GET –header ‘Authorization: ‘ 资源代码: @Path(“/resources”) public class MyResource extends AbstractResource { … @GET @Path(“/org/{orgId}/product/{productId}”) @Produces(MediaType.APPLICATION_JSON) @RoleAuthenticated public Response getResourcesReport(@PathParam(“orgId”) String orgId, @PathParam(“productId”) String productId, @Context HttpHeaders headers){….} 过滤: @PreMatching @RoleAuthenticated public class AuthorizationFilter implements ContainerRequestFilter { @Override public void filter(ContainerRequestContext requestContext) throws IOException { MultivaluedMap […]

Jersey UniformInterfaceException尝试代理REST POST服务

当我尝试执行以这种方式构造的代码时,我一直收到406 HTTP响应。 我已经尝试过多次重构代码和输入,但是我仍然收到这个错误,而且我已经达到了我甚至不知道要调试什么的程度。 exception似乎表明post()方法没有以所需的格式提供@FormParam ,但是你可以看到.accept(MediaType.APPLICATION_FORM_URLENCODED)和@Consumes(MediaType.APPLICATION_FORM_URLENCODED)确实匹配了。 我正在使用Firefox附加的HTTPRequester来传递@FormParam ,并确保我使用适当的Content-Type( application/x-www-form-urlencoded )传递它们。 我已经没有东西要检查了。 有没有人有任何想法? 代理服务 Client client = Client.create(); WebResource service = client.resource(myURL); Form form = new Form(); form.add(“value1”, value1); form.add(“value2”, value2); form.add(“valueN”, valueN); String returnValue = service.accept(MediaType.APPLICATION_FORM_URLENCODED).post(String.class, form); 实际服务 @POST @Produces(MediaType.APPLICATION_XML) @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Path(“/theService”) public String theService( @FormParam(“value1”) String value1, @FormParam(“value2”) String value2, @FormParam(“valueN”) String valueN) { String […]

将列表传递给RESTful Web服务

有没有办法将列表传递给Jersey中的RESTFul Web服务方法? 像@PathParam(“list”)列表一样的东西?

使用jQuery访问基于Jersey的RESTful服务

我正在尝试访问RESTful服务,在Java上创建并使用jQuery在Jersey的帮助下部署。 如果我使用浏览器访问它,我会得到结果,但是从jQuery,我收到一个错误,在页面上看不到任何结果。 带有脚本的页面托管在本地Apache服务器上,并且服务在同一台机器上使用Jersey / Grizzly单独运行。 我可以看到服务正在发送响应并且它有200个代码,但我不断收到来自.ajax的错误,没有任何细节和任何建议有什么问题? 服务: @Path(“/helloworld”) 公共类HelloWorldResource { @GET @Produces public String test(){ System.out.println(“Sending response”); return “test”; } } 主要: public static void main(String[] args) throws IOException { final String baseUri = “http://localhost:9998/”; final Map initParams = new HashMap(); initParams.put(“com.sun.jersey.config.property.packages”, “resources”); System.out.println(“Starting grizly”); SelectorThread threadSelector = GrizzlyWebContainerFactory.create(baseUri, initParams); System.out.println(String.format( “Jersey app started with […]

想要在响应Json的密码上添加@JsonIgnore属性

我想在用户域的密码属性中添加Jackson的@JsonIgnore,这样我必须能够发送带有密码的Json,并将数据保存在数据库中,但作为响应,我不想显示密码。 我该如何实现这一点请帮助我。 我尝试在定义属性的用户的域级别使用它,但它完全忽略了getter和setter方法中的属性。 我试过这个 private String password; @JsonIgnore public String getPassword() { return this.password; }