Setting request timeout for JAX-RS 2.0 Client API

Note: this is a new method available on JAX-RS 2.1 This is a very old post but the below code will work for both jersey and resteasy. ClientBuilder clientBuilder = ClientBuilder.newBuilder(); clientBuilder.connectTimeout(10, TimeUnit.SECONDS); clientBuilder.readTimeout(12, TimeUnit.SECONDS); Client client = clientBuilder.build();

java.lang.AbstractMethodError: javax.ws.rs.core.UriBuilder.uri

You’re using both Jersey 1 & 2 (Jersey 1 is an explicit dependency, Jersey 2 is a transitive dependency of jersey-test-framework-provider-jdk-http) and that’s not possible – so the classloader is picking up the wrong URIBuilder class. The Jersey dependencies in group com.sun.jersey are all Jersey version 1. Jersey version 2 uses the group org.glassfish.jersey. You … Read more

JAX-RS using exception mappers

Is InvalidDataException getting wrapped in a PersistenceException? Maybe you could do something like the following: @Provider public class PersistenceMapper implements ExceptionMapper<PersistenceException> { @Override public Response toResponse(PersistenceException arg0) { if(arg0.getCause() instanceof InvalidDataException) { return Response.status(Response.Status.BAD_REQUEST).build(); } else { … } } }

Can’t find javax.ws.rs package in jdk

These classes (JSR 311: JAX-RS: The JavaTM API for RESTful Web Services) are not part of the JDK. You need to include appropriate JAR file to your CLASSPATH. You can find the API e.g. in maven repository. Also check out apache-cxf, jersey (reference implementation), resteasy from JBoss, restlet and few other JAX-RS implementations.

How to deploy a JAX-RS application?

There are a number of options for deploying into a Java EE 6 container (more specifically a Servlet 3.0 implementation): The simplest is: <?xml version=”1.0″ encoding=”UTF-8″?> <web-app xmlns=”http://java.sun.com/xml/ns/j2ee” xmlns:xsi=”http://www.w3.org/2001/XMLSchema-instance” xsi:schemaLocation=”http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_3_0.xsd” version=”3.0″> <servlet> <servlet-name>javax.ws.rs.core.Application</servlet-name> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>javax.ws.rs.core.Application</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> </web-app> Then all the @Path and @Provider classes found in your web application will be … Read more

AbstractMethodError using UriBuilder on JAX-RS [duplicate]

AbstractMethodError are thrown when an application tries to call an abstract method. uri is an abstract method in UriBuilder, so you need an implementation of this. This method (with String parameter) is from version 2.0 of JAX-RS specification. You’re trying to use JAX-RS 2.0 with Jersey 1.*. Instead, you need to use Jersey 2.* that … Read more

SEVERE: MessageBodyWriter not found for media type=application/json, type=class com.jersey.jaxb.Todo, genericType=class com.jersey.jaxb.Todo

You have jackson-jaxrs-json-provider which is a start.. But… that artifact is still dependent on Jacskon itself, which includes all these artifacts That’s why we use Maven[1] (so we don’t have to worry about this kind of thing :-). So go find these. Then just add the package to the web.xml, and it should work <param-name>jersey.config.server.provider.packages</param-name> … Read more

Send redirect from a JAX-RS service

Yes, you can do this in Jersey or any JAX-RS implementation (including RestEasy) if your return type is a Response (or HttpServletResponse) https://eclipse-ee4j.github.io/jersey.github.io/apidocs/1.19.1/jersey/javax/ws/rs/core/Response.html You can use either of the following: Response.temporaryRedirect(URI) Response.seeOther(URI) “Temporary Redirect” returns a 307 status code while “See Other” returns 303.

Can we have more than one @Path annotation for same REST method [duplicate]

You can’t have mutliple @Path annotations on a single method. It causes a “duplicate annotation” syntax error. However, there’s a number of ways you can effectively map two paths to a method. Regular expressions in @Path annotation The @Path annotation in JAX-RS accepts parameters, whose values can be restricted using regular expressions. This annotation: @Path(“a/{parameter: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)