Search in sources :

Example 11 with LoadingByteArrayOutputStream

use of org.apache.cxf.helpers.LoadingByteArrayOutputStream in project cxf by apache.

the class CachedOutputStream method getInputStream.

public InputStream getInputStream() throws IOException {
    flush();
    if (inmem) {
        if (currentStream instanceof LoadingByteArrayOutputStream) {
            return ((LoadingByteArrayOutputStream) currentStream).createInputStream();
        } else if (currentStream instanceof ByteArrayOutputStream) {
            return new ByteArrayInputStream(((ByteArrayOutputStream) currentStream).toByteArray());
        } else {
            return null;
        }
    }
    try {
        InputStream fileInputStream = new TransferableFileInputStream(tempFile);
        streamList.add(fileInputStream);
        if (cipherTransformation != null) {
            fileInputStream = new CipherInputStream(fileInputStream, ciphers.getDecryptor()) {

                boolean closed;

                public void close() throws IOException {
                    if (!closed) {
                        super.close();
                        closed = true;
                    }
                }
            };
        }
        return fileInputStream;
    } catch (FileNotFoundException e) {
        throw new IOException("Cached file was deleted, " + e.toString());
    }
}
Also used : LoadingByteArrayOutputStream(org.apache.cxf.helpers.LoadingByteArrayOutputStream) CipherInputStream(javax.crypto.CipherInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) CipherInputStream(javax.crypto.CipherInputStream) ByteArrayInputStream(java.io.ByteArrayInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) FileNotFoundException(java.io.FileNotFoundException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) LoadingByteArrayOutputStream(org.apache.cxf.helpers.LoadingByteArrayOutputStream) IOException(java.io.IOException)

Example 12 with LoadingByteArrayOutputStream

use of org.apache.cxf.helpers.LoadingByteArrayOutputStream in project cxf by apache.

the class CachedOutputStream method maybeDeleteTempFile.

private boolean maybeDeleteTempFile(Object stream) {
    boolean postClosedInvoked = false;
    streamList.remove(stream);
    if (!inmem && tempFile != null && streamList.isEmpty() && allowDeleteOfFile) {
        if (currentStream != null) {
            try {
                currentStream.close();
                postClose();
            } catch (Exception e) {
            // ignore
            }
            postClosedInvoked = true;
        }
        deleteTempFile();
        currentStream = new LoadingByteArrayOutputStream(1024);
        inmem = true;
    }
    return postClosedInvoked;
}
Also used : LoadingByteArrayOutputStream(org.apache.cxf.helpers.LoadingByteArrayOutputStream) GeneralSecurityException(java.security.GeneralSecurityException) IOException(java.io.IOException) FileNotFoundException(java.io.FileNotFoundException)

Example 13 with LoadingByteArrayOutputStream

use of org.apache.cxf.helpers.LoadingByteArrayOutputStream in project cxf by apache.

the class TransportURIResolver method resolve.

public InputSource resolve(String curUri, String baseUri) {
    // Spaces must be encoded or URI.resolve() will choke
    curUri = curUri.replace(" ", "%20");
    InputSource is = null;
    URI base;
    try {
        if (baseUri == null) {
            base = new URI(curUri);
        } else {
            base = new URI(baseUri);
            base = base.resolve(curUri);
        }
    } catch (URISyntaxException use) {
        // ignore
        base = null;
        LOG.log(Level.FINEST, "Could not resolve curUri " + curUri, use);
    }
    try {
        if (base == null || DEFAULT_URI_RESOLVER_HANDLES.contains(base.getScheme())) {
            is = super.resolve(curUri, baseUri);
        }
    } catch (Exception ex) {
        // nothing
        LOG.log(Level.FINEST, "Default URI handlers could not resolve " + baseUri + " " + curUri, ex);
    }
    if (is == null && base != null && base.getScheme() != null && !DEFAULT_URI_RESOLVER_HANDLES.contains(base.getScheme())) {
        try {
            ConduitInitiatorManager mgr = bus.getExtension(ConduitInitiatorManager.class);
            ConduitInitiator ci = null;
            if ("http".equals(base.getScheme()) || "https".equals(base.getScheme())) {
                // common case, don't "search"
                ci = mgr.getConduitInitiator("http://cxf.apache.org/transports/http");
            }
            if (ci == null) {
                ci = mgr.getConduitInitiatorForUri(base.toString());
            }
            if (ci != null) {
                EndpointInfo info = new EndpointInfo();
                // set the endpointInfo name which could be used for configuration
                info.setName(new QName("http://cxf.apache.org", "TransportURIResolver"));
                info.setAddress(base.toString());
                final Conduit c = ci.getConduit(info, bus);
                Message message = new MessageImpl();
                Exchange exch = new ExchangeImpl();
                message.setExchange(exch);
                message.put(Message.HTTP_REQUEST_METHOD, "GET");
                c.setMessageObserver(new MessageObserver() {

                    public void onMessage(Message message) {
                        LoadingByteArrayOutputStream bout = new LoadingByteArrayOutputStream();
                        try {
                            IOUtils.copy(message.getContent(InputStream.class), bout);
                            message.getExchange().put(InputStream.class, bout.createInputStream());
                            c.close(message);
                        } catch (IOException e) {
                        // ignore
                        }
                    }
                });
                c.prepare(message);
                c.close(message);
                InputStream ins = exch.get(InputStream.class);
                resourceOpened.addElement(ins);
                InputSource src = new InputSource(ins);
                String u = (String) message.get("transport.retransmit.url");
                if (u == null) {
                    u = base.toString();
                }
                src.setPublicId(u);
                src.setSystemId(u);
                lastestImportUri = u;
                currentResolver.unresolve();
                return src;
            }
        } catch (Exception e) {
            // ignore
            LOG.log(Level.FINEST, "Conduit initiator could not resolve " + baseUri + " " + curUri, e);
        }
    }
    if (is == null && (base == null || base.getScheme() == null || !DEFAULT_URI_RESOLVER_HANDLES.contains(base.getScheme()))) {
        is = super.resolve(curUri, baseUri);
    }
    return is;
}
Also used : InputSource(org.xml.sax.InputSource) Message(org.apache.cxf.message.Message) QName(javax.xml.namespace.QName) InputStream(java.io.InputStream) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URI(java.net.URI) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) Exchange(org.apache.cxf.message.Exchange) EndpointInfo(org.apache.cxf.service.model.EndpointInfo) LoadingByteArrayOutputStream(org.apache.cxf.helpers.LoadingByteArrayOutputStream) MessageImpl(org.apache.cxf.message.MessageImpl) ExchangeImpl(org.apache.cxf.message.ExchangeImpl)

Aggregations

LoadingByteArrayOutputStream (org.apache.cxf.helpers.LoadingByteArrayOutputStream)13 IOException (java.io.IOException)9 InputStream (java.io.InputStream)8 ByteArrayInputStream (java.io.ByteArrayInputStream)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)5 FileInputStream (java.io.FileInputStream)4 CipherInputStream (javax.crypto.CipherInputStream)4 OutputStream (java.io.OutputStream)3 URISyntaxException (java.net.URISyntaxException)3 List (java.util.List)3 StreamSource (javax.xml.transform.stream.StreamSource)3 FileNotFoundException (java.io.FileNotFoundException)2 InputStreamReader (java.io.InputStreamReader)2 Reader (java.io.Reader)2 MalformedURLException (java.net.MalformedURLException)2 URI (java.net.URI)2 URL (java.net.URL)2 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 LinkedHashMap (java.util.LinkedHashMap)2