final Operation sourceOperation = buildSourceOperation(operation, info);
// lookup the operation we are going to use
final Response sourceResponse = findSourceResponse(sourceOperation, info);
if (sourceResponse == null) {
throw new WFSException(
"Could not locate a response that can generate the desired source format '"
+ info.getSourceFormat() + "' for transformation '" + info.getName() + "'");
}
// prepare the stream connections, so that we can do the transformation on the fly
PipedInputStream pis = new PipedInputStream();
final PipedOutputStream pos = new PipedOutputStream(pis);
// submit the source output format execution, tracking exceptions
Future<Void> future = executor.submit(new Callable<Void>() {
@Override
public Void call() throws Exception {
try {
sourceResponse.write(featureCollection, pos, sourceOperation);
} finally {
// close the stream to make sure the transformation won't keep on waiting
pos.close();
}
return null;
}
});
// run the transformation
TransformerException transformerException = null;
try {
transformer.transform(new StreamSource(pis), new StreamResult(output));
} catch (TransformerException e) {
transformerException = e;
} finally {
pis.close();
}
// now handle exceptions, starting from the source
try {
future.get();
} catch (Exception e) {
throw new WFSException(
"Failed to run the output format generating the source for the XSTL transformation",
e);
}
if (transformerException != null) {
throw new WFSException("Failed to run the the XSTL transformation",
transformerException);
}
}