jax-rs

Use Jackson as JAXB-JSON-processor in JavaEE Application

天涯浪子 提交于 2019-12-20 02:27:27
问题 I've seen many articles and SO-questions about this - but I just don't get it working. My goal is to use Jackson as JSON processor in a JavaEE application. What do I have so far? pom.xml either this one <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-json-jackson</artifactId> <version>2.17</version> </dependency> or this one (which of them is correct in the end?) <dependency> <groupId>com.fasterxml.jackson.jaxrs</groupId> <artifactId>jackson-jaxrs-json

How to deploy a JAX-RS application on a Java SE environment?

我是研究僧i 提交于 2019-12-20 01:40:06
问题 I want to code a RESTful web service with JAX-RS, and I want publish it on localhost like http://localhost:[port] . I read the following in this answer: The Java SE 7 (JSR 336) and the Java SE 8 (JSR 337) specifications don't incorporate the JAX-RS component. However, JAX-RS applications can be published in Java SE environments (using RuntimeDelegate ) and JAX-RS implementations also may support publication via JAX-WS. The RuntimeDelegate is mentioned. How can I use it? If there are good

MessageBody Writer / Reader

二次信任 提交于 2019-12-19 11:41:54
问题 I'm trying to make Jersey supports GSON and for this I have read that I need to implement a Custom MessageBodyWriter and MessageBodyReader . Now my problem is that I couldn't find any clear definition of these 2 interfaces. From the doc : public interface MessageBodyWriter<T> Contract for a provider that supports the conversion of a Java type to a stream. To add a MessageBodyWriter implementation, annotate the implementation class with @Provider. A MessageBodyWriter implementation may be

why Resonse.ok().build() return the Response entity itself?

允我心安 提交于 2019-12-19 11:25:51
问题 I have a simple REST API for which I am just returning Resonse.ok().build(), since the body of the function is asynchronous I was expecting an empty response with a 200 http status code, but instead I got a full description of what seems to be the Response calls as entity. What did I do wrong? Here is the json response that I received from my API call { "context": { "headers": {}, "entity": null, "entityType": null, "entityAnnotations": [], "entityStream": { "committed": false, "closed":

How JAX-RS matches for two or more compatible @Path expressions?

只谈情不闲聊 提交于 2019-12-19 10:42:36
问题 With following two methods, @GET @Path("/{id: \\d+}") public MyEntity readSingleById(@PathParam("id") long id) { } @GET @Path("/{name: .+}") public MyEntity readSingleByName(@PathParam("name") String name) { } Is there any chance that following request matches to readSingleByName not to readSingleById ? GET /1234 HTTP/1.1 If so, what can I do? What is the general rule specified? Sorry I should've checked the spec if anyone say so. 回答1: "Is there any chance that following request matches to

How JAX-RS matches for two or more compatible @Path expressions?

£可爱£侵袭症+ 提交于 2019-12-19 10:42:27
问题 With following two methods, @GET @Path("/{id: \\d+}") public MyEntity readSingleById(@PathParam("id") long id) { } @GET @Path("/{name: .+}") public MyEntity readSingleByName(@PathParam("name") String name) { } Is there any chance that following request matches to readSingleByName not to readSingleById ? GET /1234 HTTP/1.1 If so, what can I do? What is the general rule specified? Sorry I should've checked the spec if anyone say so. 回答1: "Is there any chance that following request matches to

Welcome page in REST with Java (JAX-RS) using Jersey

放肆的年华 提交于 2019-12-19 10:19:21
问题 I am implementing a Restful Web Service using Jersey. I want to show index.jsp as welcome page. <%@page contentType="text/html" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Rest Page</title> </head> <body> <h1>Rest is working!</h1> </body> </html> It works fine when I use this code in my web.xml: <servlet-mapping> <servlet

Best way to denote time (without date) in Swagger spec

匆匆过客 提交于 2019-12-19 10:17:17
问题 What is the best way to represent a time field in a swagger specification, the closest type to denote it looks like date-time but this makes standard deserialisers to expect date field to be passed along with the time... Is there a standard or best practice to just denote time in a swagger spec that works well with the Jackson deserialisers? Is denoting time in milliseconds/seconds and using type string in swagger an acceptable approach? 回答1: Depending on what you're trying to represent, this

@RolesAllowed always rejected (forbidden) on Jersey resource

折月煮酒 提交于 2019-12-19 09:53:27
问题 I am attempting to set up authentication based on roles for a resource I am exposing via Jersey/JAX-RS. This resource exists within a Glassfish instance in which authentication based on roles (specifically, via @RolesAllowed) is currently working as desired. I'm running Jersey within a servlet container: <servlet-class> com.sun.jersey.spi.container.servlet.ServletContainer </servlet-class> And am enforcing basic auth on my resource; that requirement is being enforced as expected. I have also

@RolesAllowed always rejected (forbidden) on Jersey resource

扶醉桌前 提交于 2019-12-19 09:52:14
问题 I am attempting to set up authentication based on roles for a resource I am exposing via Jersey/JAX-RS. This resource exists within a Glassfish instance in which authentication based on roles (specifically, via @RolesAllowed) is currently working as desired. I'm running Jersey within a servlet container: <servlet-class> com.sun.jersey.spi.container.servlet.ServletContainer </servlet-class> And am enforcing basic auth on my resource; that requirement is being enforced as expected. I have also