use of cn.taketoday.web.accept.ContentNegotiationManagerFactoryBean in project today-infrastructure by TAKETODAY.
the class ResourceHttpRequestHandlerTests method getMediaTypeWithFavorPathExtensionOff.
// SPR-14577
@Test
public void getMediaTypeWithFavorPathExtensionOff() throws Exception {
ContentNegotiationManagerFactoryBean factory = new ContentNegotiationManagerFactoryBean();
factory.afterPropertiesSet();
ContentNegotiationManager manager = factory.getObject();
List<Resource> paths = Collections.singletonList(new ClassPathResource("test/", getClass()));
ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
handler.setLocations(paths);
handler.setContentNegotiationManager(manager);
handler.afterPropertiesSet();
this.request.addHeader("Accept", "application/json,text/plain,*/*");
request.setRequestURI("foo.html");
handler.handleRequest(requestContext);
assertThat(this.response.getContentType()).isEqualTo("text/html");
}
use of cn.taketoday.web.accept.ContentNegotiationManagerFactoryBean in project today-infrastructure by TAKETODAY.
the class ReactiveTypeHandlerTests method setup.
@BeforeEach
public void setup() throws Exception {
ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean();
factoryBean.afterPropertiesSet();
ContentNegotiationManager manager = factoryBean.getObject();
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
this.handler = new ReactiveTypeHandler(adapterRegistry, new SyncTaskExecutor(), manager);
resetRequest();
}
use of cn.taketoday.web.accept.ContentNegotiationManagerFactoryBean in project today-framework by TAKETODAY.
the class ReactiveTypeHandlerTests method setup.
@BeforeEach
public void setup() throws Exception {
ContentNegotiationManagerFactoryBean factoryBean = new ContentNegotiationManagerFactoryBean();
factoryBean.afterPropertiesSet();
ContentNegotiationManager manager = factoryBean.getObject();
ReactiveAdapterRegistry adapterRegistry = ReactiveAdapterRegistry.getSharedInstance();
this.handler = new ReactiveTypeHandler(adapterRegistry, new SyncTaskExecutor(), manager);
resetRequest();
}
use of cn.taketoday.web.accept.ContentNegotiationManagerFactoryBean in project today-framework by TAKETODAY.
the class ResourceHttpRequestHandlerTests method getResourceWithRegisteredMediaType.
// SPR-13658
@Test
public void getResourceWithRegisteredMediaType() throws Exception {
ContentNegotiationManagerFactoryBean factory = new ContentNegotiationManagerFactoryBean();
factory.addMediaType("bar", new MediaType("foo", "bar"));
factory.afterPropertiesSet();
ContentNegotiationManager manager = factory.getObject();
List<Resource> paths = Collections.singletonList(new ClassPathResource("test/", getClass()));
ResourceHttpRequestHandler handler = new ResourceHttpRequestHandler();
handler.setLocations(paths);
handler.setContentNegotiationManager(manager);
handler.afterPropertiesSet();
request.setRequestURI("foo.bar");
handler.handleRequest(requestContext);
assertThat(this.response.getContentType()).isEqualTo("foo/bar");
assertThat(this.response.getContentAsString()).isEqualTo("h1 { color:red; }");
}
use of cn.taketoday.web.accept.ContentNegotiationManagerFactoryBean in project today-framework by TAKETODAY.
the class RequestResponseBodyMethodProcessorTests method addContentDispositionHeaderToErrorResponse.
@Test
public void addContentDispositionHeaderToErrorResponse() throws Throwable {
ContentNegotiationManagerFactoryBean factory = new ContentNegotiationManagerFactoryBean();
factory.addMediaType("pdf", new MediaType("application", "pdf"));
factory.afterPropertiesSet();
var processor = new RequestResponseBodyMethodProcessor(Collections.singletonList(new StringHttpMessageConverter()), factory.getObject());
this.servletRequest.setRequestURI("/hello.dataless");
this.servletResponse.setStatus(400);
processor.handleReturnValue(request, handlerMethod, "body");
String header = servletResponse.getHeader("Content-Disposition");
assertThat(header).isEqualTo("inline;filename=f.txt");
}
Aggregations