use of java.io.OutputStream in project camel by apache.
the class RawMessageWSDLGetOutInterceptor method handleMessage.
public void handleMessage(Message message) throws Fault {
Document doc = (Document) message.get(RawMessageWSDLGetInterceptor.DOCUMENT_HOLDER);
if (doc == null) {
return;
}
message.remove(RawMessageWSDLGetInterceptor.DOCUMENT_HOLDER);
OutputStream out = message.getContent(OutputStream.class);
String enc = null;
try {
enc = doc.getXmlEncoding();
} catch (Exception ex) {
//ignore - not dom level 3
}
if (enc == null) {
enc = "utf-8";
}
XMLStreamWriter writer = StaxUtils.createXMLStreamWriter(out, enc);
try {
StaxUtils.writeNode(doc, writer, true);
writer.flush();
} catch (XMLStreamException e) {
throw new Fault(e);
}
}
use of java.io.OutputStream in project camel by apache.
the class CxfCustomizedExceptionTest method testInvokingServiceFromHTTPURL.
@Test
public void testInvokingServiceFromHTTPURL() throws Exception {
URL url = new URL(routerAddress);
URLConnection urlConnection = url.openConnection();
urlConnection.setDoInput(true);
urlConnection.setDoOutput(true);
urlConnection.setUseCaches(false);
urlConnection.setRequestProperty("Content-Type", "application/xml");
// Send POST data
OutputStream out = urlConnection.getOutputStream();
// copy the message out
InputStream is = this.getClass().getResourceAsStream("SimpleSoapRequest.xml");
IOHelper.copy(is, out);
out.flush();
is.close();
// check the response code
try {
urlConnection.getInputStream();
fail("We except an IOException here");
} catch (IOException exception) {
assertTrue(exception.getMessage().contains("500"));
}
}
use of java.io.OutputStream in project camel by apache.
the class FopProducer method transform.
private OutputStream transform(FOUserAgent userAgent, String outputFormat, Source src) throws FOPException, TransformerException {
OutputStream out = new ByteArrayOutputStream();
Fop fop = fopFactory.newFop(outputFormat, userAgent, out);
TransformerFactory factory = TransformerFactory.newInstance();
Transformer transformer = factory.newTransformer();
Result res = new SAXResult(fop.getDefaultHandler());
transformer.transform(src, res);
return out;
}
use of java.io.OutputStream in project camel by apache.
the class BlobServiceUtil method doGetBlob.
private static void doGetBlob(CloudBlob client, Exchange exchange, BlobServiceConfiguration cfg) throws Exception {
BlobServiceUtil.configureCloudBlobForRead(client, cfg);
BlobServiceRequestOptions opts = getRequestOptions(exchange);
LOG.trace("Getting a blob [{}] from exchange [{}]...", cfg.getBlobName(), exchange);
OutputStream os = exchange.getIn().getBody(OutputStream.class);
if (os == null) {
String fileDir = cfg.getFileDir();
if (fileDir != null) {
File file = new File(fileDir, getBlobFileName(cfg));
ExchangeUtil.getMessageForResponse(exchange).setBody(file);
os = new FileOutputStream(file);
}
}
try {
if (os == null) {
// Let the producers like file: deal with it
InputStream blobStream = client.openInputStream(opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext());
exchange.getIn().setBody(blobStream);
exchange.getIn().setHeader(Exchange.FILE_NAME, getBlobFileName(cfg));
} else {
Long blobOffset = cfg.getBlobOffset();
Long blobDataLength = cfg.getDataLength();
if (client instanceof CloudPageBlob) {
PageRange range = exchange.getIn().getHeader(BlobServiceConstants.PAGE_BLOB_RANGE, PageRange.class);
if (range != null) {
blobOffset = range.getStartOffset();
blobDataLength = range.getEndOffset() - range.getStartOffset();
}
}
client.downloadRange(blobOffset, blobDataLength, os, opts.getAccessCond(), opts.getRequestOpts(), opts.getOpContext());
}
} finally {
if (os != null && cfg.isCloseStreamAfterRead()) {
os.close();
}
}
}
use of java.io.OutputStream in project camel by apache.
the class BlobServiceProducerSpringTest method testGetBlockBlob.
@Test
@Ignore
public void testGetBlockBlob() throws Exception {
result.expectedMessageCount(1);
OutputStream os = new ByteArrayOutputStream();
template.send("direct:getBlockBlob", ExchangePattern.InOnly, new Processor() {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setBody(os);
}
});
assertMockEndpointsSatisfied();
assertResultExchange(result.getExchanges().get(0));
}
Aggregations