use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.
the class SchemaValidationPolicyAbstractInterceptor method loadCustomSchema.
protected void loadCustomSchema(Message message, String customSchemaPath, @SuppressWarnings("rawtypes") Class c) throws IOException {
if (customSchemaPath == null || customSchemaPath.trim().isEmpty()) {
throw new IllegalArgumentException("Path to custom schema is not set or empty");
}
String absoluteSchemaPath = null;
CachedOutputStream cos = new CachedOutputStream();
absoluteSchemaPath = loadResource(customSchemaPath, cos);
InputStream customSchemaStream = cos.getInputStream();
Schema customSchema;
SchemaResourceResolver resourceResolver = null;
try {
if (customSchemaStream == null) {
throw new IllegalArgumentException("Cannot load custom schema from path: " + customSchemaPath);
}
SchemaFactory factory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
resourceResolver = new SchemaResourceResolver(absoluteSchemaPath, customSchemaPath);
factory.setResourceResolver(resourceResolver);
Source src = new StreamSource(customSchemaStream);
customSchema = factory.newSchema(src);
} catch (SAXException e) {
throw new IllegalArgumentException("Cannot create custom schema from path: " + customSchemaPath + "\n" + e.getMessage(), e);
} finally {
try {
cos.close();
if (resourceResolver != null) {
resourceResolver.cleanupCache();
}
} catch (IOException e) {
}
}
message.getExchange().getService().getServiceInfos().get(0).setProperty(Schema.class.getName(), customSchema);
}
use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.
the class InputXSLTUtil method transformXReader.
protected void transformXReader(Message message, XMLStreamReader xReader) {
CachedOutputStream cachedOS = new CachedOutputStream();
try {
StaxUtils.copy(xReader, cachedOS);
InputStream transformedIS = XSLTUtils.transform(getXSLTTemplate(), cachedOS.getInputStream());
XMLStreamReader transformedReader = StaxUtils.createXMLStreamReader(transformedIS);
message.setContent(XMLStreamReader.class, transformedReader);
} catch (XMLStreamException e) {
throw new Fault("STAX_COPY", LOG, e, e.getMessage());
} catch (IOException e) {
throw new Fault("GET_CACHED_INPUT_STREAM", LOG, e, e.getMessage());
} finally {
try {
StaxUtils.close(xReader);
} catch (XMLStreamException e) {
LOG.warning("Cannot close stream after transformation: " + e.getMessage());
}
try {
cachedOS.close();
} catch (IOException e) {
LOG.warning("Cannot close stream after transformation: " + e.getMessage());
}
}
}
use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.
the class OutputXSLTUtil method transformOS.
protected void transformOS(Message message, OutputStream out) {
CachedOutputStream wrapper = new CachedOutputStream();
message.setContent(OutputStream.class, wrapper);
TransformationOutEndingInterceptor si = new TransformationOutEndingInterceptor(getXSLTTemplate(), out);
message.getInterceptorChain().add(si);
}
use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.
the class CompressionOutInterceptor method wrapOriginalOutputStream.
public void wrapOriginalOutputStream(Message message) throws Fault {
// remember the original output stream, we will write compressed
// data to this later
OutputStream os = message.getContent(OutputStream.class);
if (os == null) {
return;
}
// new stream to cache the original os
CachedOutputStream wrapper = new CachedOutputStream();
CachedOutputStreamCallback callback = new CompressionCachedOutputStreamCallback(os, threshold, message);
wrapper.registerCallback(callback);
message.setContent(OutputStream.class, wrapper);
}
use of org.apache.cxf.io.CachedOutputStream in project tesb-rt-se by Talend.
the class MessageScanerOutInterceptor method wrapOriginalOutputStream.
public void wrapOriginalOutputStream(Message message) throws Fault {
// remember the original output stream, we will write compressed
// data to this later
OutputStream os = message.getContent(OutputStream.class);
if (os == null) {
return;
}
// new stream to cache the original os
CachedOutputStream wrapper = new CachedOutputStream();
callback = new CompressionCachedOutputStreamCallback(os, pattern, throwPatternNotMatchedException);
wrapper.registerCallback(callback);
message.setContent(OutputStream.class, wrapper);
}
Aggregations