title: How to configure Jsonp and CXF with Interceptors
body: <p>I am developing a restful WS and I want to give the option to the users to take data back from my WS in the form of XML or Json and also to be able to choose a callback function if they want Jsonp. This is what I have until now and the part with the Interceptors is based on <a href="http://cxf.apache.org/docs/jax-rs-data-bindings.html#JAX-RSDataBindings-JSONWithPadding%28JSONP%29" rel="nofollow">CXF - JAX-RS : Data Bindings</a>. </p>
  
  <p>My Rest Service:</p>
  
  <pre><code>@GET
  @Consumes({ MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
  @Produces({ "application/x-javascript", MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML })
  public Response getServers(@Context ServletContext context,
          @Context Request request,
          @QueryParam("format") String format,
          @QueryParam("callback") String callback) {
  
  some code where server object is created....
  
      if(format.equals("json"){
  
          if(callback!= null){
              response = Response.status(Status.OK).type("application/x-javascript")
                          .entity(server).build();
          }else{
              response = Response.status(Status.OK).type("application/json")
                          .entity(server).build();
          }
  
      } else {
      response = Response.status(Status.OK).type("application/xml")
                          .entity(server).build();
      }
      return response;
  }
  </code></pre>
  
  <p>My Server object:</p>
  
  <pre><code>@XmlRootElement (name="Server")
  public class Server implements Serializable {
  
      private String name=null;
      private String hardware = null;
  
      public Server(){
  
      }
  
      public String getName() {
          return name;
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public String getHardware() {
          return hardware;
      }
  
      public void setHardware(String hardware) {
          this.hardware = hardware;
      }
  
  }
  </code></pre>
  
  <p>My beans.xml in the WEB-INF:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jaxrs="http://cxf.apache.org/jaxrs"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="
  http://www.springframework.org/schema/beans 
  http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
  http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd
  http://cxf.apache.org/jaxrs
  http://cxf.apache.org/schemas/jaxrs.xsd"&gt;
  
    &lt;import resource="classpath:META-INF/cxf/cxf.xml" /&gt;
  
    &lt;context:property-placeholder/&gt;
    &lt;context:annotation-config/&gt;
    &lt;bean class="org.springframework.web.context.support.ServletContextPropertyPlaceholderConfigurer"/&gt;
    &lt;bean class="org.springframework.beans.factory.config.PreferencesPlaceholderConfigurer"/&gt;
  
     &lt;jaxrs:server id="services" address="/"&gt;
      &lt;jaxrs:serviceBeans&gt;
        &lt;bean class="com.ba.serversws_cxf.resources.MyResource" /&gt;
      &lt;/jaxrs:serviceBeans&gt;
  
      &lt;jaxrs:inInterceptors&gt;
         &lt;bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpInInterceptor"&gt;
          &lt;property name="callbackParam" value="callback"/&gt;
         &lt;/bean&gt;
      &lt;/jaxrs:inInterceptors&gt;
      &lt;jaxrs:outInterceptors&gt;
         &lt;bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPreStreamInterceptor"&gt;
              &lt;property name="mediaType" value="application/x+javascript"/&gt;
         &lt;/bean&gt;
         &lt;bean class="org.apache.cxf.jaxrs.provider.jsonp.JsonpPostStreamInterceptor"/&gt;
      &lt;/jaxrs:outInterceptors&gt;
  
      &lt;jaxrs:providers&gt;
          &lt;bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider"/&gt;
      &lt;/jaxrs:providers&gt;
      &lt;/jaxrs:server&gt;
  
  &lt;/beans&gt;
  </code></pre>
  
  <p>The error that I get when I set the query parameter "callback" is: </p>
  
  <pre><code>org.apache.cxf.jaxrs.interceptor.JAXRSOutInterceptor writeResponseErrorMessage
  WARNING: No message body writer has been found for response class Server.
  </code></pre>
  
  <p>It works fine for other other two cases. </p>
  
  <p>I have searched to find a solution but still nothing. </p>
  
  <p>Any ideas?</p>
  
  <p>Thanks</p>