use of java.io.StringWriter 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 java.io.StringWriter in project camel by apache.
the class LogCustomLoggerTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
sw1 = new StringWriter();
sw2 = new StringWriter();
ConsumingAppender.newAppender(LogCustomLoggerTest.class.getCanonicalName(), "LogCustomLoggerTest", Level.TRACE, event -> sw1.append(event.getLoggerName()));
ConsumingAppender.newAppender("provided.logger1.name", "logger1", Level.TRACE, event -> sw1.append(event.getLoggerName()));
ConsumingAppender.newAppender("provided.logger2.name", "logger2", Level.TRACE, event -> sw1.append(event.getLoggerName()));
ConsumingAppender.newAppender("irrelevant.logger.name", "irrelevant", Level.TRACE, event -> sw1.append(event.getLoggerName()));
ConsumingAppender.newAppender(LogComponent.class.getCanonicalName(), "LogComponent", Level.TRACE, event -> sw2.append(event.getLoggerName()));
}
use of java.io.StringWriter in project camel by apache.
the class LogProcessorWithProvidedLoggerTest method setUp.
@Before
@Override
public void setUp() throws Exception {
super.setUp();
sw = new StringWriter();
ConsumingAppender.newAppender("org.apache.camel.customlogger", "customlogger", Level.TRACE, event -> sw.append(event.getLoggerName() + " " + event.getLevel().toString() + " " + event.getMessage().getFormattedMessage()));
}
use of java.io.StringWriter in project camel by apache.
the class DataFormatConcurrentTest method createPayloads.
/**
* the individual size of one record is:
* fooBarSize = 1 -> 104 bytes
* fooBarSize = 50 -> 2046 bytes
* @return the payloads used for this stress test
* @throws Exception
*/
public ByteArrayInputStream[] createPayloads(int testCount) throws Exception {
Foo foo = new Foo();
for (int x = 0; x < fooBarSize; x++) {
Bar bar = new Bar();
bar.setName("Name: " + x);
bar.setValue("value: " + x);
foo.getBarRefs().add(bar);
}
Marshaller m = JAXBContext.newInstance(Foo.class, Bar.class).createMarshaller();
StringWriter writer = new StringWriter();
m.marshal(foo, writer);
byte[] payload = writer.toString().getBytes();
ByteArrayInputStream[] streams = new ByteArrayInputStream[testCount];
for (int i = 0; i < testCount; i++) {
streams[i] = new ByteArrayInputStream(payload);
}
return streams;
}
use of java.io.StringWriter in project camel by apache.
the class NoClassDefFoundErrorWrapExceptionTest method testNoClassDef.
@Test
public void testNoClassDef() throws Exception {
try {
template.requestBody("activemq:start?transferException=true", "Hello World");
fail("Should throw exception");
} catch (Exception e) {
StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw);
e.printStackTrace(pw);
String s = sw.toString();
assertTrue(s.contains("java.lang.LinkageError"));
assertTrue(s.contains("Cannot do this"));
assertTrue(s.contains("org.apache.camel.component.jms.issues.ProcessorFail.process"));
}
}
Aggregations