RESTful Java client with RESTEasy client framework

This tutorial show you how to create a RESTful Java client with RESTEasy client framework, to perform “GET” and “POST” requests to REST service that created in last “Jackson + JAX-RS” tutorial. 1. RESTEasy Client Framework RESTEasy client framework is included in RESTEasy core module, so, you just need to declares the “resteasy-jaxrs.jar” in your …

Read more

Illegal to inject a message body into a singleton into public org.codehaus.jackson.jaxrs.JacksonJsonProvider

Problem Using Jackson as JSON provider in RESTEasy. <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jaxrs</artifactId> <version>2.2.1.GA</version> </dependency> <dependency> <groupId>org.jboss.resteasy</groupId> <artifactId>resteasy-jackson-provider</artifactId> <version>2.2.1.GA</version> </dependency> With RESTEasy auto scanning enabled. <context-param> <param-name>resteasy.scan</param-name> <param-value>true</param-value> </context-param> When starting up, it hits following errors and failed to start up any of the RESTEasy services. SEVERE: Exception sending context initialized event to listener instance of class …

Read more

XML example with RESTEasy + JAXB

RESTEasy, is required JAXB to support XML file. In this tutorial, we show you how to create an “user” object, convert it into XML file, and return it back to the client. 1. RESTEasy + JAXB To use JAXB in RESTEasy, you need to include the “resteasy-jaxb-provider.jar” dependency. File : pom.xml <repositories> <repository> <id>JBoss repository</id> …

Read more

RESTEasy – Could not find MessageBodyWriter for response object of type:xx of media type: application/xml

Problem Developing RESTEasy + JAXB provider to support XML, when return it back to client, it prompts following error message : org.jboss.resteasy.core.NoMessageBodyWriterFoundFailure: Could not find MessageBodyWriter for response object of type: com.mkyong.rest.User of media type: application/xml at org.jboss.resteasy.core.ServerResponse.writeTo(ServerResponse.java:216) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:500) at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119) //… Solution To use JAXB in RESTEasy, you need to include “resteasy-jaxb-provider.jar“. <repositories> …

Read more

File upload example in RESTEasy

Not many complete file upload example in JAX-RS, especially RESTEasy. Here, we show you two complete RESTEasy examples to handle file upload from HTML form. Normal way to handle uploaded file via MultipartFormDataInput Map uploaded file to a POJO class via @MultipartForm 1. RESTEasy Multipart Dependency In RESTEasy, you need “resteasy-multipart-provider.jar” to handle multipart file …

Read more

RESTEasy – Could not find message body reader for type: multipart/form-data

Note Tested with Eclipse 3.6, Maven 3 and RESTEasy 2.2.1.GA Question Developing file upload feature with RESTEasy, see following RESTEasy multipart file upload example : public class FileUploadForm { private byte[] data; @FormParam("file") public void setData(byte[] data) { this.data = data; } //…code omitted } @Path("/file") public class UploadFileService { @POST @Path("/upload") @Consumes("multipart/form-data") public Response …

Read more

RESTEasy Unable to scan WEB-INF for JAX-RS annotations ?

Question Developing REST service, with file upload function with resteasy, after added resteasy multipart dependency, following strange error message prompt during the application start up? P.S Using resteasy-jaxrs and resteasy-multipart version 2.2.1.GA. SEVERE: Exception sending context initialized event to listener instance of class org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap java.lang.RuntimeException: Unable to scan WEB-INF for JAX-RS annotations, you must manually …

Read more

JAX-RS @QueryParam example

In JAX-RS, you can use @QueryParam annotation to inject URI query parameter into Java method. for example, /users/query?url=mkyong.com In above URI pattern, query parameter is “url=mkyong.com“, and you can get the url value with @QueryParam(“url”). 1. @QueryParam example See a full example of using @QueryParam in JAX-RS. import java.util.List; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.QueryParam; …

Read more

ClassNotFoundException : org.jboss.resteasy.plugins.providers.multipart.MultipartInput

Question Working REST + file upload, using resteasy 2.2.1.GA and Eclipse 3.6. And the reseteasy multipart dependency is declared in maven pom.xml file. In compile mode, class “MultipartInput” is able to compile, but Eclipse prompts following error message during deployment or debugging mode? java.lang.NoClassDefFoundError: org/jboss/resteasy/plugins/providers/multipart/MultipartInput at java.lang.Class.getDeclaredMethods0(Native Method) at java.lang.Class.privateGetDeclaredMethods(Class.java:2427) at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414) Caused by: java.lang.ClassNotFoundException: …

Read more

RESTEasy hello world example

RESTEasy, JBoss project, implementation of the JAX-RS specification. In this tutorial, we show you how to use RESTEasy framework to create a simple REST style web application. Technologies and Tools used in this article: RESTEasy 2.2.1.GA JDK 1.6 Maven 3.0.3 Eclipse 3.6 What’s REST? Read this, this and this to understand what’s REST. 1. Directory …

Read more