@@ -0,0 +1,2304 @@
+/**%0A * %0A */%0Apackage com.trendrr.strest.contrib.filters;%0A%0Aimport java.io.UnsupportedEncodingException;%0A%0Aimport org.apache.commons.logging.Log;%0Aimport org.apache.commons.logging.LogFactory;%0Aimport org.jboss.netty.handler.codec.http.HttpHeaders;%0Aimport org.jboss.netty.handler.codec.http.HttpResponse;%0A%0Aimport com.trendrr.strest.ContentTypes;%0Aimport com.trendrr.strest.StrestException;%0Aimport com.trendrr.strest.StrestHttpException;%0Aimport com.trendrr.strest.StrestUtil.HEADERS;%0Aimport com.trendrr.strest.server.ResponseBuilder;%0Aimport com.trendrr.strest.server.StrestController;%0Aimport com.trendrr.strest.server.StrestControllerFilter;%0A%0A%0A/**%0A * %0A * Simple filter to handle jsonp requests.%0A * %0A * %0A * @author Dustin Norlander%0A * @created Apr 12, 2011%0A * %0A */%0Apublic class JsonpFilter implements StrestControllerFilter %7B%0A%0A%09protected Log log = LogFactory.getLog(JsonpFilter.class);%0A%0A%09String jsonpParam = %22jsonp%22;%0A%09%0A%09/* (non-Javadoc)%0A%09 * @see com.trendrr.strest.server.StrestControllerFilter#before(com.trendrr.strest.server.StrestController)%0A%09 */%0A%09@Override%0A%09public void before(StrestController controller) throws StrestException %7B%0A%09%09// TODO Auto-generated method stub%0A%0A%09%7D%0A%0A%09/* (non-Javadoc)%0A%09 * @see com.trendrr.strest.server.StrestControllerFilter#after(com.trendrr.strest.server.StrestController)%0A%09 */%0A%09@Override%0A%09public void after(StrestController controller) throws StrestException %7B%0A%09%09HttpResponse response = controller.getResponse();%0A%09%09if (!ContentTypes.JSON.equals(response.getHeader(HttpHeaders.Names.CONTENT_TYPE))) %7B%0A%09%09%09return;%0A%09%09%7D%0A%09%09String param = controller.getParams().getString(this.jsonpParam);%0A%09%09if (param == null)%0A%09%09%09return;%0A%09%09try %7B%0A%09%09%09String jsonp = param +%22(%22 + new String(response.getContent().array(), %22utf8%22) + %22);%22;%0A%09%09%09ResponseBuilder.instance(response).content(ContentTypes.JAVASCRIPT, jsonp.getBytes(%22utf8%22));%0A%09%09%7D catch (UnsupportedEncodingException e) %7B%0A%09%09%09throw StrestHttpException.INTERNAL_SERVER_ERROR(e.getMessage());%0A%09%09%7D%0A%09%7D%0A%0A%09/* (non-Javadoc)%0A%09 * @see com.trendrr.strest.server.StrestControllerFilter#error(com.trendrr.strest.server.StrestController, org.jboss.netty.handler.codec.http.HttpResponse, java.lang.Exception)%0A%09 */%0A%09@Override%0A%09public void error(StrestController controller, HttpResponse response,%0A%09%09%09Exception exception) %7B%0A%09%09// TODO Auto-generated method stub%0A%0A%09%7D%0A%7D%0A

Add jsonp filter