Skip to content
Permalink
Browse files
[CXF-5558] Updating JSONPInInterceptor to recognize custom callback p…
…arameters

git-svn-id: https://svn.apache.org/repos/asf/cxf/trunk@1567696 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
Sergey Beryozkin committed Feb 12, 2014
1 parent b1a2e7e commit 1903171166dbb50189ee233b14a23948ac846683
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 2 deletions.
@@ -54,7 +54,7 @@ public void handleMessage(Message message) throws Fault {
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 void handleMessage(Message message) throws Fault {

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)) {
@@ -65,6 +65,28 @@ public void testJsonWithPadding() throws Exception {

}

@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();

0 comments on commit 1903171

Please sign in to comment.