/** * Assumes that there is a "callback" query parameter available in the URI * query string, containing the name of the JavaScript callback method. */ @Override public void afterHandle(Request request, Response response) { // Check the presence of the callback parameter String callback = request.getResourceRef().getQueryAsForm() .getFirstValue("callback"); if (callback != null) { Representation entity = response.getEntity(); if (entity != null && ("text".equals(entity.getMediaType().getMainType()) || MediaType.APPLICATION_JSON .equals(entity.getMediaType()))) { response.setEntity(new JsonpRepresentation(callback, response .getStatus(), response.getEntity())); response.setStatus(Status.SUCCESS_OK); } } }
/** * Assumes that there is a "callback" query parameter available in the URI * query string, containing the name of the JavaScript callback method. */ @Override public void afterHandle(Request request, Response response) { // Check the presence of the callback parameter String callback = request.getResourceRef().getQueryAsForm() .getFirstValue("callback"); if (callback != null) { Representation entity = response.getEntity(); if (entity != null && ("text".equals(entity.getMediaType().getMainType()) || MediaType.APPLICATION_JSON .equals(entity.getMediaType()))) { response.setEntity(new JsonpRepresentation(callback, response .getStatus(), response.getEntity())); response.setStatus(Status.SUCCESS_OK); } } }