use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class Jaxb2CollectionHttpMessageConverterTests method readXmlRootElementExternalEntityEnabled.
@Test
@SuppressWarnings("unchecked")
public void readXmlRootElementExternalEntityEnabled() throws Exception {
Resource external = new ClassPathResource("external.txt", getClass());
String content = "<!DOCTYPE root [" + " <!ELEMENT external ANY >\n" + " <!ENTITY ext SYSTEM \"" + external.getURI() + "\" >]>" + " <list><rootElement><type s=\"1\"/><external>&ext;</external></rootElement></list>";
MockHttpInputMessage inputMessage = new MockHttpInputMessage(content.getBytes("UTF-8"));
Jaxb2CollectionHttpMessageConverter<?> c = new Jaxb2CollectionHttpMessageConverter<Collection<Object>>() {
@Override
protected XMLInputFactory createXmlInputFactory() {
XMLInputFactory inputFactory = XMLInputFactory.newInstance();
inputFactory.setProperty(XMLInputFactory.IS_REPLACING_ENTITY_REFERENCES, true);
return inputFactory;
}
};
Collection<RootElement> result = c.read(rootElementListType, null, inputMessage);
assertEquals(1, result.size());
assertEquals("Foo Bar", result.iterator().next().external);
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class ZeroCopyIntegrationTests method zeroCopy.
@Test
public void zeroCopy() throws Exception {
// Zero-copy only does not support servlet
assumeTrue(server instanceof ReactorHttpServer || server instanceof UndertowHttpServer);
RestTemplate restTemplate = new RestTemplate();
RequestEntity<?> request = RequestEntity.get(new URI("http://localhost:" + port)).build();
ResponseEntity<byte[]> response = restTemplate.exchange(request, byte[].class);
Resource logo = new ClassPathResource("spring.png", ZeroCopyIntegrationTests.class);
assertTrue(response.hasBody());
assertEquals(logo.contentLength(), response.getHeaders().getContentLength());
assertEquals(logo.contentLength(), response.getBody().length);
assertEquals(MediaType.IMAGE_PNG, response.getHeaders().getContentType());
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class AsyncRestTemplateIntegrationTests method multipart.
@Test
public void multipart() throws Exception {
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
parts.add("name 1", "value 1");
parts.add("name 2", "value 2+1");
parts.add("name 2", "value 2+2");
Resource logo = new ClassPathResource("/org/springframework/http/converter/logo.jpg");
parts.add("logo", logo);
HttpEntity<MultiValueMap<String, Object>> requestBody = new HttpEntity<>(parts);
Future<URI> future = template.postForLocation(baseUrl + "/multipart", requestBody);
future.get();
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class RestTemplateIntegrationTests method multipart.
@Test
public void multipart() throws UnsupportedEncodingException {
MultiValueMap<String, Object> parts = new LinkedMultiValueMap<>();
parts.add("name 1", "value 1");
parts.add("name 2", "value 2+1");
parts.add("name 2", "value 2+2");
Resource logo = new ClassPathResource("/org/springframework/http/converter/logo.jpg");
parts.add("logo", logo);
template.postForLocation(baseUrl + "/multipart", parts);
}
use of org.springframework.core.io.ClassPathResource in project spring-framework by spring-projects.
the class CssLinkResourceTransformerTests method transformWithNonCssResource.
@Test
public void transformWithNonCssResource() throws Exception {
MockServerWebExchange exchange = MockServerHttpRequest.get("/static/images/image.png").toExchange();
Resource expected = new ClassPathResource("test/images/image.png", getClass());
StepVerifier.create(this.transformerChain.transform(exchange, expected)).expectNext(expected).expectComplete().verify();
}
Aggregations