use of org.talend.daikon.content.DeletableResource in project data-prep by Talend.
the class CloseableInputStreamComponent method getDeletableResource.
public DeletableResource getDeletableResource() throws IOException {
final DeletableResource deletableResource = Mockito.mock(DeletableResource.class);
when(deletableResource.getInputStream()).thenReturn(getInput());
when(deletableResource.getOutputStream()).thenReturn(getOutput());
return deletableResource;
}
use of org.talend.daikon.content.DeletableResource in project data-prep by Talend.
the class CloseableResourceWatch method closeableWatch.
@Around("within(org.talend..*) && (execution(public java.io.Closeable+ *(..)) || execution(public org.talend.daikon.content.DeletableResource+ *(..)))")
public Object closeableWatch(ProceedingJoinPoint pjp) throws Throwable {
final Object proceed = pjp.proceed();
if (proceed == null) {
LOGGER.warn("Unable to watch null closeable.");
return null;
}
try {
if (proceed instanceof InputStream) {
final CloseableHandler handler = new InputStreamHandler((InputStream) proceed);
addEntry(handler);
return handler;
} else if (proceed instanceof OutputStream) {
final CloseableHandler handler = new OutputStreamHandler((OutputStream) proceed);
addEntry(handler);
return handler;
} else if (proceed instanceof DeletableResource) {
ProxyFactory proxyFactory = new ProxyFactory(proceed);
proxyFactory.addAdvice(new ClosableMethodInterceptor());
return proxyFactory.getProxy();
} else {
LOGGER.warn("No watch for '{}'.", proceed);
return proceed;
}
} catch (Exception e) {
if (!LOGGER.isDebugEnabled()) {
LOGGER.error("Unable to watch resource '{}'.", proceed);
} else {
LOGGER.debug("Unable to watch resource '{}'.", proceed, e);
}
}
return proceed;
}
use of org.talend.daikon.content.DeletableResource in project data-prep by Talend.
the class ResourceLoaderContentCache method evictMatch.
@Timed
@Override
public void evictMatch(ContentCacheKey key) {
try {
final DeletableResource[] resources = resolver.getResources("/cache/" + key.getPrefix() + "**");
final Predicate<String> matcher = key.getMatcher();
stream(resources).filter(r -> matcher.test(r.getFilename())).forEach(r -> {
try {
r.delete();
} catch (IOException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
});
} catch (IOException e) {
throw new TDPException(CommonErrorCodes.UNEXPECTED_EXCEPTION, e);
}
}
use of org.talend.daikon.content.DeletableResource in project data-prep by Talend.
the class DataSetServiceTest method updateRawContentWithDirectoryTraversalFile_TDP_3505.
@Test
public void updateRawContentWithDirectoryTraversalFile_TDP_3505() throws Exception {
// dataSetId is the filename under which the file will be stored on the server
String dataSetIdFlawed = "foobar..\\..\\..\\a";
// create dataset
given().body(IOUtils.toString(this.getClass().getResourceAsStream(TAGADA_CSV), UTF_8)).queryParam("Content-Type", "text/csv").when().post("/datasets").asString();
String body = IOUtils.toString(this.getClass().getResourceAsStream(TAGADA_CSV), UTF_8);
//
given().body(body).when().queryParam("name", //
"toto").put("/datasets/{id}/raw", //
dataSetIdFlawed).then().statusCode(OK.value());
// expectations
DeletableResource resource = resolver.getResource("/store/datasets/content/dataset/" + dataSetIdFlawed);
assertFalse(resource.getFile().exists());
}
Aggregations