cxf-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From serg...@apache.org
Subject svn commit: r1567696 - in /cxf/trunk/rt/rs/extensions/providers/src: main/java/org/apache/cxf/jaxrs/provider/jsonp/JsonpInInterceptor.java test/java/org/apache/cxf/jaxrs/provider/jsonp/JsonpInterceptorTest.java
Date Wed, 12 Feb 2014 17:36:05 GMT
Author: sergeyb
Date: Wed Feb 12 17:36:05 2014
New Revision: 1567696

URL: http://svn.apache.org/r1567696
Log:
[CXF-5558] Updating JSONPInInterceptor to recognize custom callback parameters

Modified:
    cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/jsonp/JsonpInInterceptor.java
    cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/jsonp/JsonpInterceptorTest.java

Modified: cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/jsonp/JsonpInInterceptor.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/jsonp/JsonpInInterceptor.java?rev=1567696&r1=1567695&r2=1567696&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/jsonp/JsonpInInterceptor.java
(original)
+++ cxf/trunk/rt/rs/extensions/providers/src/main/java/org/apache/cxf/jaxrs/provider/jsonp/JsonpInInterceptor.java
Wed Feb 12 17:36:05 2014
@@ -54,7 +54,7 @@ public class JsonpInInterceptor extends 
         if (!StringUtils.isEmpty(callbackValue)) {
             if (getAcceptType() != null) {
                 // may be needed to enforce the selection of 
-                // JSON-awarenprovider
+                // JSON-aware provider
                 message.put(Message.ACCEPT_CONTENT_TYPE, getAcceptType());
             }
             message.getExchange().put(CALLBACK_KEY, callbackValue);
@@ -63,7 +63,7 @@ public class JsonpInInterceptor extends 
 
     protected String getCallbackValue(Message message) {
         String theQuery = (String)message.get(Message.QUERY_STRING);
-        String callback = JAXRSUtils.getStructuredParams(theQuery, "&", false, false).getFirst(CALLBACK_PARAM);
+        String callback = JAXRSUtils.getStructuredParams(theQuery, "&", false, false).getFirst(callbackParam);
         if (StringUtils.isEmpty(callback)) {
             String httpAcceptType = (String)message.get(Message.ACCEPT_CONTENT_TYPE);
             if (httpAcceptType != null && mediaType.equals(httpAcceptType)) {

Modified: cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/jsonp/JsonpInterceptorTest.java
URL: http://svn.apache.org/viewvc/cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/jsonp/JsonpInterceptorTest.java?rev=1567696&r1=1567695&r2=1567696&view=diff
==============================================================================
--- cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/jsonp/JsonpInterceptorTest.java
(original)
+++ cxf/trunk/rt/rs/extensions/providers/src/test/java/org/apache/cxf/jaxrs/provider/jsonp/JsonpInterceptorTest.java
Wed Feb 12 17:36:05 2014
@@ -66,6 +66,28 @@ public class JsonpInterceptorTest extend
     }
     
     @Test
+    public void testJsonWithPaddingCustomCallbackParam() throws Exception {
+        Message message = new MessageImpl();
+        message.put(Message.CONTENT_TYPE, MediaType.APPLICATION_JSON);
+        message.setExchange(new ExchangeImpl());
+        message.put(Message.QUERY_STRING, "_customjsonp=myCallback");
+        ByteArrayOutputStream bos = new ByteArrayOutputStream();
+        message.setContent(OutputStream.class, bos);
+        
+        // Process the message
+        try {
+            in.setCallbackParam("_customjsonp");
+            in.handleMessage(message);
+            preStream.handleMessage(message);
+            postStream.handleMessage(message);
+            assertEquals("myCallback();", bos.toString());
+        } finally {
+            in.setCallbackParam("_jsonp");
+        }
+
+    }
+    
+    @Test
     public void testJsonWithDefaultPadding() throws Exception {
         Message message = new MessageImpl();
         message.put(Message.ACCEPT_CONTENT_TYPE, JsonpInInterceptor.JSONP_TYPE);



Mime
View raw message