use of java.io.PrintWriter in project camel by apache.
the class BasicValidationHandler method handle.
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
baseRequest.setHandled(true);
if (expectedMethod != null && !expectedMethod.equals(request.getMethod())) {
response.setStatus(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
return;
}
if (!validateQuery(request)) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return;
}
if (expectedContent != null) {
StringBuilder content = new StringBuilder();
String line = null;
while ((line = request.getReader().readLine()) != null) {
content.append(line);
}
if (!expectedContent.equals(content.toString())) {
response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
return;
}
}
response.setStatus(HttpServletResponse.SC_OK);
if (responseContent != null) {
response.setContentType("text/plain; charset=utf-8");
PrintWriter out = response.getWriter();
out.print(responseContent);
}
}
use of java.io.PrintWriter 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"));
}
}
use of java.io.PrintWriter in project groovy by apache.
the class XmlTemplateEngine method createTemplate.
public Template createTemplate(Reader reader) throws CompilationFailedException, ClassNotFoundException, IOException {
Node root;
try {
root = xmlParser.parse(reader);
} catch (SAXException e) {
throw new RuntimeException("Parsing XML source failed.", e);
}
if (root == null) {
throw new IOException("Parsing XML source failed: root node is null.");
}
StringWriter writer = new StringWriter(1024);
writer.write("/* Generated by XmlTemplateEngine */\n");
new GspPrinter(new PrintWriter(writer), indentation).print(root);
Script script;
try {
script = groovyShell.parse(writer.toString(), "XmlTemplateScript" + counter++ + ".groovy");
} catch (Exception e) {
throw new GroovyRuntimeException("Failed to parse template script (your template may contain an error or be trying to use expressions not currently supported): " + e.getMessage());
}
return new XmlTemplate(script);
}
use of java.io.PrintWriter in project groovy by apache.
the class DomToGroovy method main.
public static void main(String[] args) {
if (args.length < 1) {
System.out.println("Usage: DomToGroovy infilename [outfilename]");
System.exit(1);
}
Document document = null;
try {
document = parse(args[0]);
} catch (Exception e) {
System.out.println("Unable to parse input file '" + args[0] + "': " + e.getMessage());
System.exit(1);
}
PrintWriter writer = null;
if (args.length < 2) {
writer = new PrintWriter(System.out);
} else {
try {
writer = new PrintWriter(new FileWriter(new File(args[1])));
} catch (IOException e) {
System.out.println("Unable to create output file '" + args[1] + "': " + e.getMessage());
System.exit(1);
}
}
DomToGroovy converter = new DomToGroovy(writer);
converter.out.incrementIndent();
writer.println("#!/bin/groovy");
writer.println();
writer.println("// generated from " + args[0]);
writer.println("System.out << new groovy.xml.StreamingMarkupBuilder().bind {");
converter.print(document);
writer.println("}");
writer.close();
}
use of java.io.PrintWriter in project flink by apache.
the class BootstrapTools method writeConfiguration.
/**
* Writes a Flink YAML config file from a Flink Configuration object.
* @param cfg The Flink config
* @param file The File to write to
* @throws IOException
*/
public static void writeConfiguration(Configuration cfg, File file) throws IOException {
try (FileWriter fwrt = new FileWriter(file);
PrintWriter out = new PrintWriter(fwrt)) {
for (String key : cfg.keySet()) {
String value = cfg.getString(key, null);
out.print(key);
out.print(": ");
out.println(value);
}
}
}
Aggregations