Example usage for org.springframework.web.accept PathExtensionContentNegotiationStrategy PathExtensionContentNegotiationStrategy

List of usage examples for org.springframework.web.accept PathExtensionContentNegotiationStrategy PathExtensionContentNegotiationStrategy

Introduction

In this page you can find the example usage for org.springframework.web.accept PathExtensionContentNegotiationStrategy PathExtensionContentNegotiationStrategy.

Prototype

public PathExtensionContentNegotiationStrategy(@Nullable Map<String, MediaType> mediaTypes) 

Source Link

Document

Create an instance with the given map of file extensions and media types.

Usage

From source file:org.elasticsoftware.elasticactors.examples.springweb.config.ApplicationContextConfiguration.java

@Bean
public ContentNegotiatingViewResolver contentNegotiatingViewResolver(ObjectMapper objectMapper) {
    ContentNegotiatingViewResolver viewResolver = new ContentNegotiatingViewResolver();
    viewResolver.setOrder(1);//from  w  ww . ja va  2 s  .  c  om
    viewResolver.setUseNotAcceptableStatusCode(true);

    // set content negotiation manager
    Map<String, MediaType> mediaTypes = new HashMap<>();
    mediaTypes.put("json", MediaType.APPLICATION_JSON);
    PathExtensionContentNegotiationStrategy strategy = new PathExtensionContentNegotiationStrategy(mediaTypes);
    ContentNegotiationManager manager = new ContentNegotiationManager(strategy);
    viewResolver.setContentNegotiationManager(manager);

    // set views
    List<View> views = new ArrayList<>();
    MappingJackson2JsonView view = new MappingJackson2JsonView();
    view.setExtractValueFromSingleKeyModel(true);
    view.setObjectMapper(objectMapper);
    views.add(view);
    viewResolver.setDefaultViews(views);

    return viewResolver;
}

From source file:org.fede.calculator.web.MvcConfig.java

@Bean
public ContentNegotiatingViewResolver cnResolver() {
    ContentNegotiatingViewResolver bean = new ContentNegotiatingViewResolver();
    bean.setOrder(0);/*from   w w w . j a  v  a 2s.  c o  m*/
    bean.setContentNegotiationManager(new ContentNegotiationManager(new PathExtensionContentNegotiationStrategy(
            Collections.singletonMap("json", MediaType.APPLICATION_JSON))));

    MappingJackson2JsonView jacksonView = new MappingJackson2JsonView();
    jacksonView.setExtractValueFromSingleKeyModel(true);

    bean.setDefaultViews(Arrays.asList(new View[] { jacksonView }));
    return bean;
}

From source file:cn.newgxu.lab.core.config.SpringBeans.java

@Bean
public ContentNegotiationManager contentNegotiationManager() {
    Map<String, MediaType> mediaTypes = new HashMap<String, MediaType>(2);
    mediaTypes.put("json", MediaType.APPLICATION_JSON);
    mediaTypes.put("jsonp", MediaType.parseMediaType("application/javascript"));
    PathExtensionContentNegotiationStrategy extension = new PathExtensionContentNegotiationStrategy(mediaTypes);
    HeaderContentNegotiationStrategy header = new HeaderContentNegotiationStrategy();
    ContentNegotiationManager contentNegotiationManager = new ContentNegotiationManager(extension, header);
    return contentNegotiationManager;
}

From source file:org.springframework.web.servlet.resource.ResourceHttpRequestHandler.java

/**
 * Initialize the content negotiation strategy depending on the {@code ContentNegotiationManager}
 * setup and the availability of a {@code ServletContext}.
 * @see ServletPathExtensionContentNegotiationStrategy
 * @see PathExtensionContentNegotiationStrategy
 *//*from  w w  w.ja v a 2  s  . co m*/
protected PathExtensionContentNegotiationStrategy initContentNegotiationStrategy() {
    Map<String, MediaType> mediaTypes = null;
    if (getContentNegotiationManager() != null) {
        PathExtensionContentNegotiationStrategy strategy = getContentNegotiationManager()
                .getStrategy(PathExtensionContentNegotiationStrategy.class);
        if (strategy != null) {
            mediaTypes = new HashMap<>(strategy.getMediaTypes());
        }
    }
    return (getServletContext() != null
            ? new ServletPathExtensionContentNegotiationStrategy(getServletContext(), mediaTypes)
            : new PathExtensionContentNegotiationStrategy(mediaTypes));
}