use of org.apache.camel.BytesSource in project camel by apache.
the class XmlSignatureProcessor method getSchema.
protected Schema getSchema(Message message) throws SAXException, XmlSignatureException, IOException {
String schemaResourceUri = getSchemaResourceUri(message);
if (schemaResourceUri == null || schemaResourceUri.isEmpty()) {
return null;
}
InputStream is = ResourceHelper.resolveResourceAsInputStream(getConfiguration().getCamelContext().getClassResolver(), schemaResourceUri);
if (is == null) {
throw new XmlSignatureException("XML Signature component is wrongly configured: No XML schema found for specified schema resource URI " + schemaResourceUri);
}
byte[] bytes = null;
try {
bytes = IOConverter.toBytes(is);
} finally {
// and make sure to close the input stream after the schema has been loaded
IOHelper.close(is);
}
SchemaFactory schemaFactory = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
schemaFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true);
schemaFactory.setResourceResolver(new DefaultLSResourceResolver(getConfiguration().getCamelContext(), getConfiguration().getSchemaResourceUri()));
LOG.debug("Instantiating schema for validation");
return schemaFactory.newSchema(new BytesSource(bytes));
}
use of org.apache.camel.BytesSource in project camel by apache.
the class StreamCachingInterceptorTest method testNoConversionForOtherXmlSourceTypes.
public void testNoConversionForOtherXmlSourceTypes() throws Exception {
a.expectedMessageCount(3);
send(converter.toDOMSource(MESSAGE));
send(new StringSource(MESSAGE));
send(new BytesSource(MESSAGE.getBytes()));
assertMockEndpointsSatisfied();
for (Exchange exchange : a.getExchanges()) {
assertFalse(exchange.getIn().getHeader(BODY_TYPE, Class.class).toString() + " shouldn't have been converted to StreamCache", exchange.getIn().getBody() instanceof StreamCache);
}
}
use of org.apache.camel.BytesSource in project camel by apache.
the class XmlConverter method toString.
/**
* Converts the given input Source into text
*/
@Converter
public String toString(Source source, Exchange exchange) throws TransformerException {
if (source == null) {
return null;
} else if (source instanceof StringSource) {
return ((StringSource) source).getText();
} else if (source instanceof BytesSource) {
return new String(((BytesSource) source).getData());
} else {
StringWriter buffer = new StringWriter();
if (exchange != null) {
// check the camelContext properties first
Properties properties = ObjectHelper.getCamelPropertiesWithPrefix(OUTPUT_PROPERTIES_PREFIX, exchange.getContext());
if (properties.size() > 0) {
toResult(source, new StreamResult(buffer), properties);
return buffer.toString();
}
}
// using the old way to deal with it
toResult(source, new StreamResult(buffer));
return buffer.toString();
}
}
use of org.apache.camel.BytesSource in project camel by apache.
the class XmlConverterTest method testToBytesSource.
public void testToBytesSource() throws Exception {
XmlConverter conv = new XmlConverter();
BytesSource bs = conv.toBytesSource("<foo>bar</foo>".getBytes());
assertNotNull(bs);
assertEquals("<foo>bar</foo>", new String(bs.getData()));
}
use of org.apache.camel.BytesSource in project camel by apache.
the class BytesSourceTest method testBytesSourceCtr.
public void testBytesSourceCtr() {
BytesSource bs = new BytesSource("foo".getBytes());
assertNotNull(bs.getData());
assertEquals("BytesSource[foo]", bs.toString());
assertNull(bs.getSystemId());
assertNotNull(bs.getInputStream());
assertNotNull(bs.getReader());
}
Aggregations