Java Code Examples for org.springframework.http.converter.json.MappingJacksonValue#setJsonpFunction()
The following examples show how to use
org.springframework.http.converter.json.MappingJacksonValue#setJsonpFunction() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: UserController.java From learning-taotaoMall with MIT License | 6 votes |
@RequestMapping("/token/{token}") public Object getUserByToken(@PathVariable String token, String callback) { TaotaoResult result = null; try { result = userService.getUserByToken(token); } catch (Exception e) { e.printStackTrace(); result = TaotaoResult.build(500, ExceptionUtil.getStackTrace(e)); } //判断是否为jsonp调用 if (StringUtils.isBlank(callback)) { return result; } else { MappingJacksonValue mappingJacksonValue = new MappingJacksonValue(result); mappingJacksonValue.setJsonpFunction(callback); return mappingJacksonValue; } }
Example 2
Source File: MappingJackson2JsonView.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected Object filterAndWrapModel(Map<String, Object> model, HttpServletRequest request) { Object value = super.filterAndWrapModel(model, request); String jsonpParameterValue = getJsonpParameterValue(request); if (jsonpParameterValue != null) { if (value instanceof MappingJacksonValue) { ((MappingJacksonValue) value).setJsonpFunction(jsonpParameterValue); } else { MappingJacksonValue container = new MappingJacksonValue(value); container.setJsonpFunction(jsonpParameterValue); value = container; } } return value; }
Example 3
Source File: AbstractJsonpResponseBodyAdvice.java From lams with GNU General Public License v2.0 | 6 votes |
@Override protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) { HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest(); for (String name : this.jsonpQueryParamNames) { String value = servletRequest.getParameter(name); if (value != null) { if (!isValidJsonpQueryParam(value)) { if (logger.isDebugEnabled()) { logger.debug("Ignoring invalid jsonp parameter value: " + value); } continue; } MediaType contentTypeToUse = getContentType(contentType, request, response); response.getHeaders().setContentType(contentTypeToUse); bodyContainer.setJsonpFunction(value); break; } } }
Example 4
Source File: MappingJackson2JsonView.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override protected Object filterAndWrapModel(Map<String, Object> model, HttpServletRequest request) { Object value = super.filterAndWrapModel(model, request); String jsonpParameterValue = getJsonpParameterValue(request); if (jsonpParameterValue != null) { if (value instanceof MappingJacksonValue) { ((MappingJacksonValue) value).setJsonpFunction(jsonpParameterValue); } else { MappingJacksonValue container = new MappingJacksonValue(value); container.setJsonpFunction(jsonpParameterValue); value = container; } } return value; }
Example 5
Source File: AbstractJsonpResponseBodyAdvice.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override protected void beforeBodyWriteInternal(MappingJacksonValue bodyContainer, MediaType contentType, MethodParameter returnType, ServerHttpRequest request, ServerHttpResponse response) { HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest(); for (String name : this.jsonpQueryParamNames) { String value = servletRequest.getParameter(name); if (value != null) { if (!isValidJsonpQueryParam(value)) { if (logger.isDebugEnabled()) { logger.debug("Ignoring invalid jsonp parameter value: " + value); } continue; } MediaType contentTypeToUse = getContentType(contentType, request, response); response.getHeaders().setContentType(contentTypeToUse); bodyContainer.setJsonpFunction(value); break; } } }
Example 6
Source File: ExtJackson2HttpMessageConverter.java From onetwo with Apache License 2.0 | 6 votes |
protected Object filterAndWrapModel(Object value, HttpOutputMessage outputMessage, HttpServletRequest request) { String jsonpParameterValue = getJsonpParameterValue(request); if (jsonpParameterValue != null) { if (value instanceof MappingJacksonValue) { ((MappingJacksonValue) value).setJsonpFunction(jsonpParameterValue); } else { MappingJacksonValue container = new MappingJacksonValue(value); container.setJsonpFunction(jsonpParameterValue); value = container; } outputMessage.getHeaders().setContentType(MediaType.parseMediaType("application/javascript")); } if (value instanceof Optional) { Optional<?> opt = (Optional<?>) value; value = opt.orElse(null); } return value; }
Example 7
Source File: AliyunOssController.java From zheng with MIT License | 5 votes |
/** * 签名生成 * @param callback 跨域请求 * @return */ @GetMapping("/policy") @ResponseBody //@CrossOrigin(origins = "*", methods = RequestMethod.GET) // 该注解不支持JDK1.7 public Object policy(@RequestParam(required = false) String callback) { JSONObject result = aliyunOssService.policy(); if (StringUtils.isBlank(callback)) { return result; } MappingJacksonValue jsonp = new MappingJacksonValue(result); jsonp.setJsonpFunction(callback); return jsonp; }