Return-Path: Delivered-To: apmail-cxf-issues-archive@www.apache.org Received: (qmail 43124 invoked from network); 11 Nov 2010 02:44:09 -0000 Received: from unknown (HELO mail.apache.org) (140.211.11.3) by 140.211.11.9 with SMTP; 11 Nov 2010 02:44:09 -0000 Received: (qmail 2385 invoked by uid 500); 11 Nov 2010 02:44:41 -0000 Delivered-To: apmail-cxf-issues-archive@cxf.apache.org Received: (qmail 2279 invoked by uid 500); 11 Nov 2010 02:44:40 -0000 Mailing-List: contact issues-help@cxf.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@cxf.apache.org Delivered-To: mailing list issues@cxf.apache.org Received: (qmail 2264 invoked by uid 99); 11 Nov 2010 02:44:40 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Nov 2010 02:44:40 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.22] (HELO thor.apache.org) (140.211.11.22) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Nov 2010 02:44:37 +0000 Received: from thor (localhost [127.0.0.1]) by thor.apache.org (8.13.8+Sun/8.13.8) with ESMTP id oAB2iFWW023232 for ; Thu, 11 Nov 2010 02:44:15 GMT Message-ID: <29063695.20221289443455492.JavaMail.jira@thor> Date: Wed, 10 Nov 2010 21:44:15 -0500 (EST) From: "Dobes Vandermeer (JIRA)" To: issues@cxf.apache.org Subject: [jira] Issue Comment Edited: (CXF-3005) Add support for jsonp in CXF JAX-RS MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-JIRA-FingerPrint: 30527f35849b9dde25b450d4833f0394 X-Virus-Checked: Checked by ClamAV on apache.org [ https://issues.apache.org/jira/browse/CXF-3005?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=12930896#action_12930896 ] Dobes Vandermeer edited comment on CXF-3005 at 11/10/10 9:42 PM: ----------------------------------------------------------------- Here's a somewhat simpler solution; create a subclass of the JSONProvider that handles JSONP: {code} /** * Add jsonp support to the JSONProvider. * * Basically, check for the appropriate content type * and the parameter specifying the prefix. */ @Produces("application/javascript") static class JsonpProvider extends JSONProvider { @Context HttpServletRequest request; @Override public void writeTo(Object obj, Class cls, Type genericType, Annotation[] anns, MediaType m, MultivaluedMap headers, OutputStream os) throws IOException { String prefix = request.getParameter("_jsonp"); boolean hasPrefix = !isEmpty(prefix); if(hasPrefix) { os.write(prefix.getBytes(HttpUtils.getSetEncoding(m, headers, "UTF-8"))); os.write('('); } super.writeTo(obj, cls, genericType, anns, m, headers, os); if(hasPrefix) { os.write(')'); } } } {code} was (Author: dobes_vandermeer): Here's a somewhat simpler solution; create a subclass of the JSONProvider that handles JSONP: {code} /** * Add jsonp support to the JSONProvider. * * Basically, check for the appropriate content type * and the parameter specifying the prefix. */ @Produces("application/javascript") static class JsonpProvider extends JSONProvider { @Context HttpServletRequest request; @Override protected void marshal(Marshaller ms, Object actualObject, Class actualClass, Type genericType, String enc, OutputStream os, boolean isCollection) throws Exception { String prefix = request.getParameter("_jsonp"); boolean hasPrefix = !isEmpty(prefix); if(hasPrefix) { os.write(prefix.getBytes(enc)); os.write('('); } super.marshal(ms, actualObject, actualClass, genericType, enc, os, isCollection); if(hasPrefix) { os.write(')'); } } } {code} > Add support for jsonp in CXF JAX-RS > ----------------------------------- > > Key: CXF-3005 > URL: https://issues.apache.org/jira/browse/CXF-3005 > Project: CXF > Issue Type: New Feature > Components: JAX-RS > Reporter: Josh Holtzman > Attachments: cxf_jsonp.diff > > > JAX-RS endpoints that produce JSON can be wrapped by a callback to enable JSONP, or JSON with padding. The attached patch adds JSONP interceptors that may be added to a JAXRSServerFactoryBean to support JSONP. > JAXRSServerFactoryBean factory = new JAXRSServerFactoryBean(); > factory.getInInterceptors().add(new JsonpInvokeInterceptor()); > factory.getOutInterceptors().add(new JsonpPreStreamInterceptor()); > factory.getOutInterceptors().add(new JsonpPostStreamInterceptor()); > ... -- This message is automatically generated by JIRA. - You can reply to this email to add a comment to the issue online.