use of org.apache.commons.io.output.WriterOutputStream in project karaf by apache.
the class ShellTableTest method testNoFormat.
@Test
public void testNoFormat() {
ShellTable table = new ShellTable();
table.column(new Col("first"));
table.column(new Col("second"));
table.addRow().addContent("first column", "second column");
StringWriter writer = new StringWriter();
PrintStream out = new PrintStream(new WriterOutputStream(writer));
table.print(out, false);
out.flush();
String expected = "first column\tsecond column\n";
Assert.assertEquals(expected, getString(writer));
}
use of org.apache.commons.io.output.WriterOutputStream in project sling by apache.
the class JSONReporterTest method getJSON.
private static Map<String, Object> getJSON(MetricRegistry registry) throws IOException {
StringWriter sw = new StringWriter();
JSONReporter reporter = JSONReporter.forRegistry(registry).outputTo(new PrintStream(new WriterOutputStream(sw))).build();
reporter.report();
reporter.close();
return new JSONParser(sw.toString()).getParsed();
}
use of org.apache.commons.io.output.WriterOutputStream in project wso2-axis2-transports by wso2.
the class MailUtils method setupLogging.
public static void setupLogging(Session session, Log log, ParameterInclude params) throws AxisFault {
// take care to override it.
if (log.isTraceEnabled()) {
// This is the old behavior: just set debug to true
session.setDebug(true);
}
if (ParamUtils.getOptionalParamBoolean(params, MailConstants.TRANSPORT_MAIL_DEBUG, false)) {
// Redirect debug output to where it belongs, namely to the logs!
session.setDebugOut(new PrintStream(new WriterOutputStream(new LogWriter(log)), true));
// Only enable debug afterwards since the call to setDebug might already cause debug output
session.setDebug(true);
}
}
use of org.apache.commons.io.output.WriterOutputStream in project wso2-axis2-transports by wso2.
the class MqttSender method createMqttMessage.
private MqttMessage createMqttMessage(MessageContext messageContext) {
OMOutputFormat format = BaseUtils.getOMOutputFormat(messageContext);
MessageFormatter messageFormatter;
try {
messageFormatter = MessageProcessorSelector.getMessageFormatter(messageContext);
} catch (AxisFault axisFault) {
throw new AxisMqttException("Unable to get the message formatter to use");
}
OutputStream out;
StringWriter sw = new StringWriter();
try {
out = new WriterOutputStream(sw, format.getCharSetEncoding());
} catch (UnsupportedCharsetException ex) {
throw new AxisMqttException("Unsupported encoding " + format.getCharSetEncoding(), ex);
}
try {
messageFormatter.writeTo(messageContext, format, out, true);
out.close();
} catch (IOException e) {
throw new AxisMqttException("IO Error while creating BytesMessage", e);
}
MqttMessage mqttMessage = new MqttMessage();
mqttMessage.setPayload(sw.toString().getBytes());
return mqttMessage;
}
use of org.apache.commons.io.output.WriterOutputStream in project wso2-axis2-transports by wso2.
the class MSMQSender method createMSMQMessage.
/**
* Generating MSMQ message wrapper in order to communicate with JNI
* @param msgCtx
* @param contentTypeProperty
* @param queuName
* @return
* @throws AxisFault
*/
private Message createMSMQMessage(MessageContext msgCtx, String messageContentType, String queuName) throws AxisFault {
String msgBody = null;
byte[] msgByteBody = null;
String msgType = getProperty(msgCtx, MSMQConstants.MSMQ_MESSAGE_TYPE);
// String msgLable = "L:" + queuName+"["+contentType+"]"; // TODO
// check the first element of the SOAP body, do we have content wrapped
// using the
// default wrapper elements for binary
// (BaseConstants.DEFAULT_BINARY_WRAPPER) or
// text (BaseConstants.DEFAULT_TEXT_WRAPPER) ? If so, do not create SOAP
// messages
// for MSMQ but just get the payload in its native format
String msmqMessageType = guessMessageType(msgCtx);
if (msmqMessageType == null) {
OMOutputFormat format = BaseUtils.getOMOutputFormat(msgCtx);
MessageFormatter messageFormatter = null;
try {
messageFormatter = MessageProcessorSelector.getMessageFormatter(msgCtx);
} catch (AxisFault axisFault) {
handleException("Unable to get the message formatter to use", axisFault);
}
String contentType = messageFormatter != null ? messageFormatter.getContentType(msgCtx, format, msgCtx.getSoapAction()) : "";
boolean useBytesMessage = msgType != null && MSMQConstants.MSMQ_BYTE_MESSAGE.equals(msgType) || contentType.indexOf(HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1;
OutputStream out = null;
StringWriter sw = null;
if (useBytesMessage) {
// TODO: handle MSMQ byte message here
} else {
sw = new StringWriter();
try {
out = new WriterOutputStream(sw, format.getCharSetEncoding());
} catch (UnsupportedCharsetException ex) {
handleException("Unsupported encoding " + format.getCharSetEncoding(), ex);
}
}
try {
if (out != null) {
messageFormatter.writeTo(msgCtx, format, out, true);
out.close();
}
} catch (IOException e) {
handleException("IO Error while creating BytesMessage", e);
}
if (!useBytesMessage) {
msgBody = sw.toString();
}
} else if (MSMQConstants.MSMQ_BYTE_MESSAGE.equals(msmqMessageType)) {
// TODO. handle .net byte messages here.
} else if (MSMQConstants.MSMQ_TEXT_MESSAGE.equals(msmqMessageType)) {
msgBody = msgCtx.getEnvelope().getBody().getFirstChildWithName(BaseConstants.DEFAULT_TEXT_WRAPPER).getText();
}
try {
// Keep message correlation empty will be deciding later on the process
Message message = new Message(msgBody != null ? msgBody : "", "", "");
return message;
} catch (UnsupportedEncodingException e) {
log.error("Unsported message has been received: ", e);
handleEexception("Unsported message has been received: ", e);
}
return null;
}
Aggregations