jersey-2.0

ExceptionMapper not working consistently in Jersey 2.x & javax

China☆狼群 提交于 2021-02-20 03:49:51
问题 I am using javax and jersey for my api application (exposing api endpoints) I am trying to catch exceptions coming from fasterXml (on put and post calls) by having a Provider which implements ExceptionMapper. My Problem is that on POST or PUT, whenever I am sending wrong attributes names, sometime my mapper catch the exceptions and sometime it doesn't. For example: Running my application once -> everything is working as expected, catching exceptions. Running my application again (restart) ->

ExceptionMapper not working consistently in Jersey 2.x & javax

妖精的绣舞 提交于 2021-02-20 03:49:38
问题 I am using javax and jersey for my api application (exposing api endpoints) I am trying to catch exceptions coming from fasterXml (on put and post calls) by having a Provider which implements ExceptionMapper. My Problem is that on POST or PUT, whenever I am sending wrong attributes names, sometime my mapper catch the exceptions and sometime it doesn't. For example: Running my application once -> everything is working as expected, catching exceptions. Running my application again (restart) ->

JAX-RS (Jersey 2 implementation) content negotiation with URL extension .xml or .json

妖精的绣舞 提交于 2021-02-19 03:47:07
问题 I've seen a Java RESTFUL webservice, that allowed the content-type to be requested in the URL with an extension at the end, such as .xml .json This is the style of content negotiation I am striving to achieve in my own Web Service. I am aware of the @Produces annotation, and the fact a method can resolve multiple types with the (value = {}) syntax, by adding an Accept header, say with Postman, the Chrome extension. But I'm not sure how to effectively extract out the information in one method,

how to modify query params in a Jersey Filter

一个人想着一个人 提交于 2021-02-10 06:34:45
问题 According to Jersey documentation Filters can be used when you want to modify any request or response parameters like headers So I believe modifying query params is possible but I don't know how and I haven't been able to find anything on Google or stackoverflow... This the functionality I would like to achieve: public class EreturnLookupFilter implements ContainerRequestFilter { private static final Logger logger = Logger.getLogger(UserResource.class.getName()); @Override public void filter

Jersey jdbc @resource not working

浪尽此生 提交于 2021-02-07 09:35:35
问题 I'm trying to have a simple Jersey based jaxrs listener, running on my existing tomcat 7.0.57. Tomcat has a global config in its context.xml for a jdbc datasource, which I want to use. My problem is that I can't get the resource to resolve via the @Resource annotation. Heres a simple test example @Path("/") public class TestJersey { @Resource(name = "jdbc/default") private DataSource dsA; @Resource(name = "java:comp/env/jdbc/default") private DataSource dsB; @Resource(lookup = "java:comp/env

java.lang.AbstractMethodError: javax.ws.rs.core.Response$ResponseBuilder.status

空扰寡人 提交于 2021-02-07 09:32:06
问题 Anyone saw similar error before? I looked into maven dependencies and it looks I am using jersey 2.26 . So, I don't think it is dependency conflict issue. The ResponseBuilder is not recognizing the method status. From other posts, I understand that it is possibly related to jersey conflict. java.lang.AbstractMethodError: javax.ws.rs.core.Response$ResponseBuilder.status(ILjava/lang/String;)Ljavax/ws/rs/core/Response$ResponseBuilder; at javax.ws.rs.core.Response$ResponseBuilder.status(Response

Using Jongo and Jackson 2, how to deserialize a MongoDB ObjectId (represented under String _id in a POJO) to an hexadecimal String representation?

孤街浪徒 提交于 2021-02-07 08:43:47
问题 I use the latest version of MongoDB database and the latest version of the official JAVA MongoDB driver. The dependencies that I use in my pom.xml: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> ... <jersey.container.version>2.13</jersey.container.version> <jackson.version>2.4.3</jackson.version> <genson.version>1.1</genson.version> <jongo.version>1.1</jongo

Using Jongo and Jackson 2, how to deserialize a MongoDB ObjectId (represented under String _id in a POJO) to an hexadecimal String representation?

旧时模样 提交于 2021-02-07 08:43:23
问题 I use the latest version of MongoDB database and the latest version of the official JAVA MongoDB driver. The dependencies that I use in my pom.xml: <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <maven.compiler.source>1.7</maven.compiler.source> <maven.compiler.target>1.7</maven.compiler.target> ... <jersey.container.version>2.13</jersey.container.version> <jackson.version>2.4.3</jackson.version> <genson.version>1.1</genson.version> <jongo.version>1.1</jongo

How to return HTTP 404 instead of HTTP 204 response code for null values in jersey

﹥>﹥吖頭↗ 提交于 2021-01-28 05:04:17
问题 I have a Jersey REST API that returns 204 No content instead of 404 when the entity to be returned back is null . To address this issue, I'm currently planning to throw an exception within the resource method so that it could force Jersey to return 404 like below. if (feature == null) throw new WebApplicationException(404); But I have various REST URIs that suffer from the same problem. Is there a way to address all of them without touching each and every resource method? My resource methods

“Already connected” Exception when running jersey application inside docker container

*爱你&永不变心* 提交于 2021-01-28 04:07:20
问题 I am trying to dockerize a jersey application which acts both as a REST server and client. The application seems to behave differently when running inside a docker container. I am able to perform a request to a non-dockerized service (A). The problem occurs when I try to perform a request on another non-dockerized REST server (B), using, in both cases, JAX-RS client API: // common code - for contacting both A & B services private static final Client client = ClientBuilder.newClient().register