Search in sources :

Example 6 with OutputStream

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);
    }
}
Also used : XMLStreamException(javax.xml.stream.XMLStreamException) XMLStreamWriter(javax.xml.stream.XMLStreamWriter) OutputStream(java.io.OutputStream) Fault(org.apache.cxf.interceptor.Fault) Document(org.w3c.dom.Document) XMLStreamException(javax.xml.stream.XMLStreamException)

Example 7 with OutputStream

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"));
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) IOException(java.io.IOException) URL(java.net.URL) URLConnection(java.net.URLConnection) Test(org.junit.Test)

Example 8 with OutputStream

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;
}
Also used : TransformerFactory(javax.xml.transform.TransformerFactory) Transformer(javax.xml.transform.Transformer) SAXResult(javax.xml.transform.sax.SAXResult) Fop(org.apache.fop.apps.Fop) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Result(javax.xml.transform.Result) SAXResult(javax.xml.transform.sax.SAXResult)

Example 9 with OutputStream

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();
        }
    }
}
Also used : InputStream(java.io.InputStream) OutputStream(java.io.OutputStream) FileOutputStream(java.io.FileOutputStream) FileOutputStream(java.io.FileOutputStream) File(java.io.File) CloudPageBlob(com.microsoft.azure.storage.blob.CloudPageBlob) PageRange(com.microsoft.azure.storage.blob.PageRange)

Example 10 with OutputStream

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));
}
Also used : Exchange(org.apache.camel.Exchange) Processor(org.apache.camel.Processor) OutputStream(java.io.OutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Aggregations

OutputStream (java.io.OutputStream)3717 IOException (java.io.IOException)1470 FileOutputStream (java.io.FileOutputStream)1192 InputStream (java.io.InputStream)1171 File (java.io.File)808 ByteArrayOutputStream (java.io.ByteArrayOutputStream)751 Test (org.junit.Test)681 BufferedOutputStream (java.io.BufferedOutputStream)418 FileInputStream (java.io.FileInputStream)380 Socket (java.net.Socket)362 ByteArrayInputStream (java.io.ByteArrayInputStream)201 OutputStreamWriter (java.io.OutputStreamWriter)201 URL (java.net.URL)193 HttpURLConnection (java.net.HttpURLConnection)162 BufferedInputStream (java.io.BufferedInputStream)151 InputStreamReader (java.io.InputStreamReader)149 FileNotFoundException (java.io.FileNotFoundException)143 Path (org.apache.hadoop.fs.Path)143 Path (java.nio.file.Path)138 BufferedReader (java.io.BufferedReader)133