Example usage for java.rmi AccessException AccessException

List of usage examples for java.rmi AccessException AccessException

Introduction

In this page you can find the example usage for java.rmi AccessException AccessException.

Prototype

public AccessException(String s) 

Source Link

Document

Constructs an AccessException with the specified detail message.

Usage

From source file:de.mpg.mpdl.inge.dataacquisition.DataHandlerBean.java

/**
 * Retrieves the content of a component from different escidoc instances.
 * // w ww. j av  a  2 s  .co  m
 * @param identifier
 * @param url
 * @return content of a component as byte[]
 */
public byte[] retrieveComponentContent(String identifier, String url) {
    String coreservice = "";
    URLConnection contentUrl;
    byte[] input = null;

    String sourceName = this.util.trimSourceName("escidoc", identifier);
    DataSourceVO source = this.sourceHandler.getSourceByName(sourceName);

    if (sourceName.equalsIgnoreCase("escidoc")) {
        try {
            coreservice = PropertyReader.getFrameworkUrl();
        } catch (Exception e) {
            this.logger.error("Framework Access threw an exception.", e);
            return null;
        }
    }
    if (sourceName.equalsIgnoreCase("escidocdev") || sourceName.equalsIgnoreCase("escidocqa")
            || sourceName.equalsIgnoreCase("escidocprod") || sourceName.equalsIgnoreCase("escidoctest")) {
        // escidoc source has only one dummy ft record
        FullTextVO ft = source.getFtFormats().get(0);
        coreservice = ft.getFtUrl().toString();
    }

    try {
        contentUrl = ProxyHelper.openConnection(new URL(coreservice + url));
        HttpURLConnection httpConn = (HttpURLConnection) contentUrl;
        int responseCode = httpConn.getResponseCode();
        switch (responseCode) {
        case 503:
            // request was not processed by source
            this.logger.warn("Component content could not be fetched.");
            throw new RuntimeException("Component content could not be fetched. (503)");
        case 200:
            this.logger.info("Source responded with 200.");
            GetMethod method = new GetMethod(coreservice + url);
            HttpClient client = new HttpClient();
            ProxyHelper.executeMethod(client, method);
            input = method.getResponseBody();
            httpConn.disconnect();
            break;
        case 403:
            throw new AccessException("Access to component content is restricted.");
        default:
            throw new RuntimeException("An error occurred during importing from external system: "
                    + responseCode + ": " + httpConn.getResponseMessage());
        }
    } catch (Exception e) {
        this.logger.error("An error occurred while retrieving the item " + identifier + ".", e);
        throw new RuntimeException(e);
    }

    return input;
}

From source file:de.mpg.escidoc.services.dataacquisition.DataHandlerBean.java

/**
 * Retrieves the content of a component from different escidoc instances.
 * /* w  ww.java  2  s  .  c  om*/
 * @param identifier
 * @param url
 * @return content of a component as byte[]
 */
public byte[] retrieveComponentContent(String identifier, String url) {
    String coreservice = "";
    URLConnection contentUrl;
    byte[] input = null;

    String sourceName = this.util.trimSourceName("escidoc", identifier);
    DataSourceVO source = this.sourceHandler.getSourceByName(sourceName);

    if (sourceName.equalsIgnoreCase("escidoc")) {
        try {
            coreservice = ServiceLocator.getFrameworkUrl();
        } catch (Exception e) {
            this.logger.error("Framework Access threw an exception.", e);
            return null;
        }
    }
    if (sourceName.equalsIgnoreCase("escidocdev") || sourceName.equalsIgnoreCase("escidocqa")
            || sourceName.equalsIgnoreCase("escidocprod") || sourceName.equalsIgnoreCase("escidoctest")) {
        // escidoc source has only one dummy ft record
        FullTextVO ft = source.getFtFormats().get(0);
        coreservice = ft.getFtUrl().toString();
    }

    try {
        contentUrl = ProxyHelper.openConnection(new URL(coreservice + url));
        HttpURLConnection httpConn = (HttpURLConnection) contentUrl;
        int responseCode = httpConn.getResponseCode();
        switch (responseCode) {
        case 503:
            // request was not processed by source
            this.logger.warn("Component content could not be fetched.");
            throw new RuntimeException("Component content could not be fetched. (503)");
        case 200:
            this.logger.info("Source responded with 200.");
            GetMethod method = new GetMethod(coreservice + url);
            HttpClient client = new HttpClient();
            ProxyHelper.executeMethod(client, method);
            input = method.getResponseBody();
            httpConn.disconnect();
            break;
        case 403:
            throw new AccessException("Access to component content is restricted.");
        default:
            throw new RuntimeException("An error occurred during importing from external system: "
                    + responseCode + ": " + httpConn.getResponseMessage());
        }
    } catch (Exception e) {
        this.logger.error("An error occurred while retrieving the item " + identifier + ".", e);
        throw new RuntimeException(e);
    }

    return input;
}

From source file:de.mpg.escidoc.services.dataacquisition.DataHandlerBean.java

/**
 * Fetches a file via http protocol./*from   w w w  .  j av  a 2 s  . c  om*/
 * 
 * @param importSource
 * @param ft
 * @return fetched file as byte[]
 * @throws IdentifierNotRecognisedException
 * @throws RuntimeException
 * @throws AccessException
 */
private byte[] fetchHttpFile(FullTextVO ft)
        throws IdentifierNotRecognisedException, RuntimeException, AccessException {
    URLConnection conn;
    byte[] input = null;

    try {
        conn = ProxyHelper.openConnection(ft.getFtUrl());
        HttpURLConnection httpConn = (HttpURLConnection) conn;
        int responseCode = httpConn.getResponseCode();
        switch (responseCode) {
        case 503:
            // request was not processed by source
            this.logger.warn("Import source " + this.currentSource.getName() + "did not provide file.");
            throw new FormatNotAvailableException(ft.getFtLabel());
        case 302:
            String alternativeLocation = conn.getHeaderField("Location");
            ft.setFtUrl(new URL(alternativeLocation));
            return fetchHttpFile(ft);
        case 200:
            this.logger.info("Source responded with 200.");
            GetMethod method = new GetMethod(ft.getFtUrl().toString());
            HttpClient client = new HttpClient();
            ProxyHelper.executeMethod(client, method);
            input = method.getResponseBody();
            httpConn.disconnect();
            break;
        case 403:
            throw new AccessException("Access to url " + this.currentSource.getName() + " is restricted.");
        default:
            throw new RuntimeException("An error occurred during importing from external system: "
                    + responseCode + ": " + httpConn.getResponseMessage());
        }
    } catch (AccessException e) {
        this.logger.error("Access denied.", e);
        throw new AccessException(this.currentSource.getName());
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return input;
}

From source file:org.crazyt.xgogdownloader.Api.java

@Override
public final String getResponse(String url) throws AccessException {
    String response = "";
    try {//  w w  w  .  j a va2  s.com
        response = IOUtils.toString(new InputStreamReader(new URL(url).openStream()));
    } catch (MalformedURLException e) {
        throw new RuntimeException(e);
    } catch (IOException e) {
        throw new AccessException("access to url denied:" + url);
    }
    return org.apache.commons.lang3.StringEscapeUtils.unescapeJson(response);
}