Example usage for java.lang SecurityException getCause

List of usage examples for java.lang SecurityException getCause

Introduction

In this page you can find the example usage for java.lang SecurityException getCause.

Prototype

public synchronized Throwable getCause() 

Source Link

Document

Returns the cause of this throwable or null if the cause is nonexistent or unknown.

Usage

From source file:org.qxsched.doc.afp.impl.AfpClasses.java

public AfpRecord instantiateSpecific(AfpRecord record, AfpFactory fact) throws AfpException {

    // Get record class
    Class<AfpRecord> cls = getSpecificAfpRecordClass(record);

    // Do nothing if no class
    if (cls == null) {
        LOG.warn("No specific class found for AFP identifier '" + record.getSFIdentifierAbbrev() + "'/"
                + record.getSFIdentifierString());
        return record;
    }//from w  ww  .  j av  a2  s  .  co  m

    // Get constructor
    Constructor<AfpRecord> constr;
    try {
        Class[] prams = { AfpRecord.class, AfpFactory.class };
        constr = cls.getConstructor(prams);
    } catch (SecurityException e) {
        throw new AfpException(e.getMessage(), e);
    } catch (NoSuchMethodException e) {
        LOG.error("No constructor found accepting AfpRecord in class " + cls.getName(), e);
        return record;
    }

    // Instantiate
    try {
        Object[] prams = { record, fact };
        AfpRecord inst = constr.newInstance(prams);
        return inst;
    } catch (IllegalArgumentException e) {
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return record;
    } catch (InstantiationException e) {
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return record;
    } catch (IllegalAccessException e) {
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return record;
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof AfpException) {
            throw (AfpException) cause;
        }
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return record;
    }
}

From source file:org.qxsched.doc.afp.impl.AfpClasses.java

public AfpTriplet instantiateSpecific(AfpTriplet triplet, AfpFactory fact) throws AfpException {

    // Get triplet class
    Class<AfpTriplet> cls = getSpecificAfpTripletClass(triplet);

    // Do nothing if no class
    if (cls == null) {
        LOG.warn("No specific class found for AFP triplet 0x" + Integer.toString(triplet.getTid(), 16));
        return triplet;
    }/*  w ww .j  av  a 2 s  .  co  m*/

    // Get constructor
    Constructor<AfpTriplet> constr;
    try {
        constr = cls.getConstructor(AfpTriplet.class);
    } catch (SecurityException e) {
        throw new AfpException(e.getMessage(), e);
    } catch (NoSuchMethodException e) {
        LOG.error("No constructor found accepting AfpTriplet in class " + cls.getName());
        return triplet;
    }
    if (LOG.isTraceEnabled()) {
        LOG.trace("Constructor found accepting AfpTriplet in class " + cls.getName());
    }

    // Instantiate
    try {
        Object[] prams = { triplet };
        AfpTriplet inst = constr.newInstance(prams);
        return inst;
    } catch (IllegalArgumentException e) {
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return triplet;
    } catch (InstantiationException e) {
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return triplet;
    } catch (IllegalAccessException e) {
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return triplet;
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof AfpException) {
            throw (AfpException) cause;
        }
        LOG.error("Unexpected exception: " + e.getMessage(), e);
        return triplet;
    }
}

From source file:org.apache.hadoop.mapred.ClientServiceDelegate.java

private synchronized Object invoke(String method, Class argClass, Object args) throws IOException {
    Method methodOb = null;/*from  w  w w .j a  v  a2 s  .com*/
    try {
        methodOb = MRClientProtocol.class.getMethod(method, argClass);
    } catch (SecurityException e) {
        throw new YarnRuntimeException(e);
    } catch (NoSuchMethodException e) {
        throw new YarnRuntimeException("Method name mismatch", e);
    }
    maxClientRetry = this.conf.getInt(MRJobConfig.MR_CLIENT_MAX_RETRIES,
            MRJobConfig.DEFAULT_MR_CLIENT_MAX_RETRIES);
    IOException lastException = null;
    while (maxClientRetry > 0) {
        MRClientProtocol MRClientProxy = null;
        try {
            MRClientProxy = getProxy();
            return methodOb.invoke(MRClientProxy, args);
        } catch (InvocationTargetException e) {
            // Will not throw out YarnException anymore
            LOG.debug("Failed to contact AM/History for job " + jobId + " retrying..", e.getTargetException());
            // Force reconnection by setting the proxy to null.
            realProxy = null;
            // HS/AMS shut down

            if (e.getCause() instanceof AuthorizationException) {
                throw new IOException(e.getTargetException());
            }

            // if it's AM shut down, do not decrement maxClientRetry as we wait for
            // AM to be restarted.
            if (!usingAMProxy.get()) {
                maxClientRetry--;
            }
            usingAMProxy.set(false);
            lastException = new IOException(e.getTargetException());
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {
                LOG.warn("ClientServiceDelegate invoke call interrupted", ie);
                throw new YarnRuntimeException(ie);
            }
        } catch (Exception e) {
            LOG.debug("Failed to contact AM/History for job " + jobId + "  Will retry..", e);
            // Force reconnection by setting the proxy to null.
            realProxy = null;
            // RM shutdown
            maxClientRetry--;
            lastException = new IOException(e.getMessage());
            try {
                Thread.sleep(100);
            } catch (InterruptedException ie) {
                LOG.warn("ClientServiceDelegate invoke call interrupted", ie);
                throw new YarnRuntimeException(ie);
            }
        }
    }
    throw lastException;
}

From source file:org.kawanfw.file.api.client.RemoteFile.java

/**
 * Returns an array of strings naming the files and directories in the
 * directory denoted by this abstract pathname.
 * /*from w  ww  .ja  va 2  s  .c om*/
 * <p>
 * If this abstract pathname does not denote a directory, then this method
 * returns <code>null</code>. Otherwise an array of strings is returned, one
 * for each file or directory in the directory. Names denoting the directory
 * itself and the directory's parent directory are not included in the
 * result. Each string is a file name rather than a complete path.
 * 
 * <p>
 * There is no guarantee that the name strings in the resulting array will
 * appear in any specific order; they are not, in particular, guaranteed to
 * appear in alphabetical order.
 * 
 * @return An array of strings naming the files and directories in the
 *         directory denoted by this abstract pathname. The array will be
 *         empty if the directory is empty. Returns <code>null</code> if
 *         this abstract pathname does not denote a directory, or if an I/O
 *         error occurs.
 * @throws SecurityException
 *             If a security manager exists and its <code>
 *             {@link java.lang.SecurityManager#checkRead(java.lang.String)}
 *             </code> method denies read access to the directory
 */
public String[] list() {
    try {
        String[] filenames = remoteFileExecutor.list(this.pathname, null, null);
        return filenames;

    } catch (SecurityException e) {
        throw e;
    } catch (Exception e) {
        if (e instanceof RemoteException) {
            Throwable cause = e.getCause();
            throw new RuntimeException(cause);
        }
        throw new RuntimeException(e);
    }
}

From source file:org.kawanfw.file.api.client.RemoteFile.java

/**
 * Returns an array of abstract pathnames denoting the files in the
 * directory denoted by this abstract pathname.
 * // w w w .  j a v  a2s .c  om
 * <p>
 * If this abstract pathname does not denote a directory, then this method
 * returns <code>null</code>. Otherwise an array of <code>File</code>
 * objects is returned, one for each file or directory in the directory.
 * Pathnames denoting the directory itself and the directory's parent
 * directory are not included in the result. Each resulting abstract
 * pathname is constructed from this abstract pathname using the
 * <code>{@link File#File(java.io.File, java.lang.String)
  File(File,&nbsp;String)}</code> constructor. Therefore if this pathname
 * is absolute then each resulting pathname is absolute; if this pathname is
 * relative then each resulting pathname will be relative to the same
 * directory.
 * 
 * <p>
 * There is no guarantee that the name strings in the resulting array will
 * appear in any specific order; they are not, in particular, guaranteed to
 * appear in alphabetical order.
 * 
 * @return An array of abstract pathnames denoting the files and directories
 *         in the directory denoted by this abstract pathname. The array
 *         will be empty if the directory is empty. Returns
 *         <code>null</code> if this abstract pathname does not denote a
 *         directory, or if an I/O error occurs.
 * @throws SecurityException
 *             If a security manager exists and its <code>
 *             {@link java.lang.SecurityManager#checkRead(java.lang.String)}
 *             </code> method denies read access to the directory
 */
public RemoteFile[] listFiles() {
    try {
        RemoteFile[] remoteFiles = remoteFileExecutor.listFiles(this.pathname, null, null, null);
        return remoteFiles;

    } catch (SecurityException e) {
        throw e;
    } catch (Exception e) {

        if (e instanceof RemoteException) {
            Throwable cause = e.getCause();
            throw new RuntimeException(cause);
        }
        throw new RuntimeException(e);
    }
}

From source file:com.vuze.android.remote.SessionInfo.java

private void openTorrent_perms(Activity activity, Uri uri) {
    try {/*from  ww  w  .j a v  a  2s  .  com*/
        InputStream stream = null;
        if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
            String realPath = PaulBurkeFileUtils.getPath(activity, uri);
            if (realPath != null) {
                String meh = realPath.startsWith("/") ? "file://" + realPath : realPath;
                stream = activity.getContentResolver().openInputStream(Uri.parse(meh));
            }
        }
        if (stream == null) {
            ContentResolver contentResolver = activity.getContentResolver();
            stream = contentResolver.openInputStream(uri);
        }
        openTorrent(activity, uri.toString(), stream);
    } catch (SecurityException e) {
        if (AndroidUtils.DEBUG) {
            e.printStackTrace();
        }
        VuzeEasyTracker.getInstance(activity).logError(e);
        String s = "Security Exception trying to access <b>" + uri + "</b>";
        Toast.makeText(activity, Html.fromHtml(s), Toast.LENGTH_LONG).show();
    } catch (FileNotFoundException e) {
        if (AndroidUtils.DEBUG) {
            e.printStackTrace();
        }
        VuzeEasyTracker.getInstance(activity).logError(e);
        String s = "<b>" + uri + "</b> not found";
        if (e.getCause() != null) {
            s += ". " + e.getCause().getMessage();
        }
        Toast.makeText(activity, Html.fromHtml(s), Toast.LENGTH_LONG).show();
    }
}

From source file:de.stadtrallye.rallyesoft.services.UploadService.java

private void upload(final PictureManager.Picture picture, boolean previewUpload) {
    final int biteSize = 8192 * 4;
    FileInputStream fileInputStream = null;

    picture.uploading();//from   ww w . j av  a 2 s.c o m

    try {
        Uri uri = Uri.parse(picture.getUri());
        Log.d(THIS, "Source: " + picture.getUri());
        initReport(picture, biteSize);
        long fileSize = -1;
        try {
            if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT
                    && picture.getUri().startsWith("content://")) {
                // Check for the freshest data.
                persistUriPermissionApi19(uri);
            }
            AssetFileDescriptor fileDescriptor = getContentResolver().openAssetFileDescriptor(uri, "r");
            fileSize = fileDescriptor.getDeclaredLength();//TODO report as indeterminate progress if length unknown
            fileInputStream = fileDescriptor.createInputStream();
        } catch (SecurityException e) {
            Log.e(THIS, "No access rights... WTF", e);
            return;
        }

        TypedOutput uploadStream;
        RetroAuthCommunicator comm = Server.getCurrentServer().getAuthCommunicator();
        Picture responsePicture;

        final long picSize = fileSize;

        reportUploadBegins(picSize, biteSize);

        final FileInputStream fIn = fileInputStream;

        if (previewUpload) {
            Bitmap img = BitmapFactory.decodeStream(fileInputStream);

            int biggerSide = (img.getWidth() > img.getHeight()) ? img.getWidth() : img.getHeight();
            double factor = PictureSize.Preview.getDimension().height * 1.0 / biggerSide;

            int w = (int) Math.round(img.getWidth() * factor);
            int h = (int) Math.round(img.getHeight() * factor);
            final Bitmap scaled = Bitmap.createScaledBitmap(img, w, h, true);

            Log.i(THIS, "scaled bitmap. it now is " + w + "x" + h);

            uploadStream = new TypedOutput() {
                @Override
                public String fileName() {
                    return picture.getHash();
                }

                @Override
                public String mimeType() {
                    return "image/jpeg";
                }

                @Override
                public long length() {
                    return -1;
                }

                @Override
                public void writeTo(OutputStream out) throws IOException {
                    scaled.compress(Bitmap.CompressFormat.JPEG, 80, out);
                }
            };
            reportUploadIndeterminate(picture);
            responsePicture = comm.uploadPreviewPicture(picture.getHash(), uploadStream);
            picture.uploadedPreview();
        } else {
            uploadStream = new TypedOutput() {
                @Override
                public String fileName() {
                    return picture.getHash();
                }

                @Override
                public String mimeType() {
                    return picture.getMimeType();
                }

                @Override
                public long length() {
                    return picSize;
                }

                @Override
                public void writeTo(OutputStream out) throws IOException {
                    final byte[] buf = new byte[biteSize];
                    int readSize = 0;
                    int i = 0;

                    while (readSize >= 0) {
                        readSize = fIn.read(buf);
                        out.write(buf);
                        i++;
                        reportUploadProgress(picture, i);
                    }
                }
            };

            responsePicture = comm.uploadPicture(picture.getHash(), uploadStream);
            picture.uploaded();
        }

        if (responsePicture != null) {
            if (!responsePicture.pictureHash.equals(picture.getHash())) {
                //TODO picture.serverResponse(responsePicture), possibly rename file / hash, if the server would like to
                Log.w(THIS,
                        "The server responded with a different hash than it was asked for... We should rename our file, but cannot since it is not yet implemented");
            }
        }

        reportUploadComplete(picture);

        Log.i(THIS, "Picture " + picture.pictureID + " successfully uploaded (" + picSize + " bytes)");
        return;
    } catch (RetrofitError e) {
        if (e.isNetworkError()) {
            Log.e(THIS, "Retrofit Network error", e.getCause());
        } else {
            Log.e(THIS, "Server declined", e);
        }
    } catch (FileNotFoundException e) {
        Log.e(THIS, "File was not were it was supposed to be: " + picture.getUri(), e);
        picture.discard();
        return;
    } catch (IOException e) {
        Log.e(THIS, "Upload failed", e);
    } finally {
        if (fileInputStream != null) {
            try {
                fileInputStream.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }
    picture.failed();
    reportUploadFailure(picture);
}