Class Jackson2JsonpInterceptor

java.lang.Object
org.jboss.resteasy.plugins.providers.jackson.Jackson2JsonpInterceptor
All Implemented Interfaces:
WriterInterceptor, AsyncWriterInterceptor

@Provider @ConstrainedTo(SERVER) public class Jackson2JsonpInterceptor extends Object implements AsyncWriterInterceptor

JSONP is an alternative to normal AJAX requests. Instead of using a XMLHttpRequest a script tag is added to the DOM. The browser will call the corresponding URL and download the JavaScript. The server creates a response which looks like a method call. The parameter is the body of the request. The name of the method to call is normally passed as query parameter. The method has to be present in the current JavaScript environment.

Jackson JSON processor can produce such an response. This interceptor checks if the media type is a JavaScript one if there is a query parameter with the method name. The default name of this query parameter is "callback". So this interceptor is compatible with jQuery.

It is possible to wrap the generated javascript function call in a try-catch block. You can enable it either by setting the wrapInTryCatch property of the provider instance to true or by setting the resteasy.jsonp.silent context-param to true:

  
  <context-param>
   <param-name>resteasy.jsonp.silent</param-name>
   <param-value>true</param-value>
  </context-param>
  
 
Version:
$Revision: 1 $
Author:
Holger Morch