Troubles with WADL / generated XSD using Jersey with a contract-first approach

1.14-SNAPSHOT should allow you to do this: public class SampleWadlGeneratorConfig extends WadlGeneratorConfig { @Override public List<WadlGeneratorDescription> configure() { return generator( WadlGeneratorApplicationDoc.class ) .prop( “applicationDocsStream”, “application-doc.xml” ) .generator( WadlGeneratorGrammarsSupport.class ) .prop( “grammarsStream”, “application-grammars.xml” ) .prop(“overrideGrammars”, true) // !!! .generator( WadlGeneratorResourceDocSupport.class ) .prop( “resourceDocStream”, “resourcedoc.xml” ) .descriptions(); } } when overrideGrammars is set to true, Jersey generated … Read more

How can I customize serialization of a list of JAXB objects to JSON?

I found a solution: replace the JAXB JSON serializer with a better behaved JSON serializer like Jackson. The easy way is to use jackson-jaxrs, which has already done it for you. The class is JacksonJsonProvider. All you have to do is edit your project’s web.xml so that Jersey (or another JAX-RS implementation) scans for it. … Read more

org.glassfish.jersey.servlet.ServletContainer ClassNotFoundException

The problem: java.lang.ClassNotFoundException: org.glassfish.jersey.servlet.ServletContainer indicates that you try to use the Jersey 2.x servlet, but you are supplying the Jersey 1.x libs. For Jersey 1.x you have to do it like this: <servlet> <servlet-name>Jersey REST Service</servlet-name> <servlet-class> com.sun.jersey.spi.container.servlet.ServletContainer </servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>sample.hello.resources</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>Jersey REST Service</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> For more information check … Read more

What is the difference between Spring REST service, Jersey REST service and Spring+Jersey solutions?

Jersey is the JAX-RS API example implementation provided by Sun, while Spring REST is of course Spring’s implementation of the same API/JSRs. The major difference is that Spring REST easily integrates into other Spring APIs (if you wish) such as Spring Data Rest. There are a few noteworthy differences between them – you can “embed” … Read more

How to set the connection and read timeout with Jersey 2.x?

The code below works for me in Jersey 2.3.1 (inspiration found here: https://stackoverflow.com/a/19541931/1617124) public static void main(String[] args) { Client client = ClientBuilder.newClient(); client.property(ClientProperties.CONNECT_TIMEOUT, 1000); client.property(ClientProperties.READ_TIMEOUT, 1000); WebTarget target = client.target(“http://1.2.3.4:8080”); try { String responseMsg = target.path(“application.wadl”).request().get(String.class); System.out.println(“responseMsg: ” + responseMsg); } catch (ProcessingException pe) { pe.printStackTrace(); } }

Using the Jersey client to do a POST operation

Not done this yet myself, but a quick bit of Google-Fu reveals a tech tip on blogs.oracle.com with examples of exactly what you ask for. Example taken from the blog post: MultivaluedMap formData = new MultivaluedMapImpl(); formData.add(“name1”, “val1”); formData.add(“name2”, “val2”); ClientResponse response = webResource .type(MediaType.APPLICATION_FORM_URLENCODED_TYPE) .post(ClientResponse.class, formData); That any help?

MULTIPART_FORM_DATA: No injection source found for a parameter of type public javax.ws.rs.core.Response

Get rid of jersey-multipart-1.18.jar. That is for Jersey 1.x. Add these two jersey-media-multipart-2.17 mimepull-1.9.3 For Maven you would use the following dependency (you don’t need to explicitly add the mimepull dependency, as this one will pull it in). <dependency> <groupId>org.glassfish.jersey.media</groupId> <artifactId>jersey-media-multipart</artifactId> <version>2.17</version> <!– Make sure the Jersey version matches the one you are currently using … Read more

Staying DRY with JAX-RS

Here is a workaround I’m using: Define a constructor for the BaseService with ‘id’ and ‘xyz’ as params: // BaseService.java public abstract class BaseService { // JAX-RS injected fields protected final String id; protected final String xyz; public BaseService (String id, String xyz) { this.id = id; this.xyz = xyz; } } Repeat the constructor … Read more