use of org.springframework.web.servlet.view.json.MappingJackson2JsonView in project cas by apereo.
the class Cas30JsonResponseView method createDelegatedView.
private static MappingJackson2JsonView createDelegatedView() {
final MappingJackson2JsonView view = new MappingJackson2JsonView();
view.setPrettyPrint(true);
view.setDisableCaching(true);
view.getObjectMapper().setSerializationInclusion(JsonInclude.Include.NON_NULL).findAndRegisterModules();
return view;
}
use of org.springframework.web.servlet.view.json.MappingJackson2JsonView in project spring-security-oauth by spring-projects.
the class WebMvcConfig method contentViewResolver.
@Bean
public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);
contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
contentViewResolver.setDefaultViews(Arrays.<View>asList(new MappingJackson2JsonView()));
return contentViewResolver;
}
use of org.springframework.web.servlet.view.json.MappingJackson2JsonView in project spring-security-oauth by spring-projects.
the class WebMvcConfig method contentViewResolver.
@Bean
public ContentNegotiatingViewResolver contentViewResolver() throws Exception {
ContentNegotiationManagerFactoryBean contentNegotiationManager = new ContentNegotiationManagerFactoryBean();
contentNegotiationManager.addMediaType("json", MediaType.APPLICATION_JSON);
InternalResourceViewResolver viewResolver = new InternalResourceViewResolver();
viewResolver.setPrefix("/WEB-INF/jsp/");
viewResolver.setSuffix(".jsp");
MappingJackson2JsonView defaultView = new MappingJackson2JsonView();
defaultView.setExtractValueFromSingleKeyModel(true);
ContentNegotiatingViewResolver contentViewResolver = new ContentNegotiatingViewResolver();
contentViewResolver.setContentNegotiationManager(contentNegotiationManager.getObject());
contentViewResolver.setViewResolvers(Arrays.<ViewResolver>asList(viewResolver));
contentViewResolver.setDefaultViews(Arrays.<View>asList(defaultView));
return contentViewResolver;
}
use of org.springframework.web.servlet.view.json.MappingJackson2JsonView in project Corgi by kevinYin.
the class HandlerMethodExceptionResolver method handleResponseBody.
/**
* 处理异常(ResponseBody)
*
* @param request
* @param response
* @param exception
* @return
*/
private ModelAndView handleResponseBody(HttpServletRequest request, HttpServletResponse response, Exception exception) {
if (exception instanceof IllegalArgumentException) {
String uri = getURI(request);
if (uri.contains("/open/monitor")) {
throw (IllegalArgumentException) exception;
}
}
String message = getThrowableMessage(exception);
Map<String, Object> attributes = new HashMap<>(4);
int code = getErrorCode();
if (StringUtils.isNotEmpty(errorCodeAttr)) {
attributes.put("code", Integer.valueOf(code));
}
if (StringUtils.isNotEmpty(errorMessageAttr)) {
attributes.put("message", message);
}
MappingJackson2JsonView view = new MappingJackson2JsonView();
view.setAttributesMap(attributes);
ModelAndView model = new ModelAndView();
model.setView(view);
return model;
}
use of org.springframework.web.servlet.view.json.MappingJackson2JsonView in project cas by apereo.
the class OAuth20RevocationEndpointController method generateRevocationResponse.
/**
* Generate revocation token response.
*
* @param token the token to revoke
* @param clientId the client who requests the revocation
* @param response the response
* @return the model and view
* @throws Exception the exception
*/
protected ModelAndView generateRevocationResponse(final String token, final String clientId, final HttpServletResponse response) throws Exception {
val registryToken = getConfigurationContext().getTicketRegistry().getTicket(token, OAuth20Token.class);
if (registryToken == null) {
LOGGER.error("Provided token [{}] has not been found in the ticket registry", token);
} else if (isRefreshToken(registryToken) || isAccessToken(registryToken)) {
if (!StringUtils.equals(clientId, registryToken.getClientId())) {
LOGGER.warn("Provided token [{}] has not been issued for the service [{}]", token, clientId);
return OAuth20Utils.writeError(response, OAuth20Constants.INVALID_REQUEST);
}
if (isRefreshToken(registryToken)) {
revokeToken((OAuth20RefreshToken) registryToken);
} else {
revokeToken(registryToken.getId());
}
} else {
LOGGER.error("Provided token [{}] is either not a refresh token or not an access token", token);
return OAuth20Utils.writeError(response, OAuth20Constants.INVALID_REQUEST);
}
val mv = new ModelAndView(new MappingJackson2JsonView());
mv.setStatus(HttpStatus.OK);
return mv;
}
Aggregations