Example usage for java.rmi RemoteException getClass

List of usage examples for java.rmi RemoteException getClass

Introduction

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

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:LNISmokeTest.java

/**
 * Execute command line. See Usage string for options and arguments.
 * //ww w  . j av  a  2 s .  co m
 * @param argv the argv
 * 
 * @throws Exception the exception
 */
public static void main(String[] argv) throws Exception {
    Options options = new Options();

    OptionGroup func = new OptionGroup();
    func.addOption(new Option("c", "copy", true, "copy <Item> to -C <Collection>"));
    func.addOption(new Option("s", "submit", true, "submit <collection> -P <packager> -i <file>"));
    func.addOption(new Option("d", "disseminate", true, "disseminate <item> -P <packager> -o <file>"));
    func.addOption(new Option("f", "propfind", true, "propfind of all properties or -N <propname>"));
    func.addOption(new Option("r", "rpropfind", true, "recursive propfind, only collections"));
    func.addOption(new Option("n", "names", true, "list all property names on resource"));
    func.addOption(new Option("p", "proppatch", true, "set property: <handle> -N <property> -V <newvalue>"));
    func.setRequired(true);
    options.addOptionGroup(func);

    options.addOption("h", "help", false, "show help message");
    options.addOption("e", "endpoint", true, "SOAP endpoint URL (REQUIRED)");
    options.addOption("P", "packager", true, "Packager to use to import/export a package.");
    options.addOption("C", "collection", true, "Target collection of -c copy");
    options.addOption("o", "output", true, "file to create for new package");
    options.addOption("i", "input", true, "file containing package to submit");
    options.addOption("N", "name", true, "name of property to query/set");
    options.addOption("V", "value", true, "new value for property being set");

    try {
        CommandLine line = (new PosixParser()).parse(options, argv);
        if (line.hasOption("h")) {
            usage(options, 0, null);
        }

        // get SOAP client connection, using the endpoint URL
        String endpoint = line.getOptionValue("e");
        if (endpoint == null) {
            usage(options, 2, "Missing the required -e endpoint argument");
        }
        LNISoapServletServiceLocator loc = new LNISoapServletServiceLocator();
        LNISoapServlet lni = loc.getDSpaceLNI(new URL(endpoint));

        // propfind - with optional single-property Name
        if (line.hasOption("f")) {
            String pfXml = (line.hasOption("N"))
                    ? specificPropPrefix + line.getOptionValue("N") + specificPropSuffix
                    : allProp;
            doPropfind(lni, line.getOptionValue("f"), pfXml, 0, null);
        }

        // recursive propfind limited to collection, community objects
        else if (line.hasOption("r")) {
            doPropfind(lni, line.getOptionValue("r"), someProp, -1, "collection,community");
        } else if (line.hasOption("n")) {
            doPropfind(lni, line.getOptionValue("n"), nameProp, 0, null);
        } else if (line.hasOption("p")) {
            if (line.hasOption("N") && line.hasOption("V")) {
                doProppatch(lni, line.getOptionValue("p"), line.getOptionValue("N"), line.getOptionValue("V"));
            } else {
                usage(options, 13, "Missing required args: -N <name> -V <value>n");
            }
        }

        // submit a package
        else if (line.hasOption("s")) {
            if (line.hasOption("P") && line.hasOption("i")) {
                doPut(lni, line.getOptionValue("s"), line.getOptionValue("P"), line.getOptionValue("i"),
                        endpoint);
            } else {
                usage(options, 13, "Missing required args after -s: -P <packager> -i <file>");
            }
        }

        // Disseminate (GET) item as package
        else if (line.hasOption("d")) {
            if (line.hasOption("P") && line.hasOption("o")) {
                doGet(lni, line.getOptionValue("d"), line.getOptionValue("P"), line.getOptionValue("o"),
                        endpoint);
            } else {
                usage(options, 13, "Missing required args after -d: -P <packager> -o <file>");
            }
        }

        // copy from src to dst
        else if (line.hasOption("c")) {
            if (line.hasOption("C")) {
                doCopy(lni, line.getOptionValue("c"), line.getOptionValue("C"));
            } else {
                usage(options, 13, "Missing required args after -c: -C <collection>\n");
            }
        } else {
            usage(options, 14, "Missing command option.\n");
        }

    } catch (ParseException pe) {
        usage(options, 1, "Error in arguments: " + pe.toString());

    } catch (java.rmi.RemoteException de) {
        System.out.println("ERROR, got RemoteException, message=" + de.getMessage());

        de.printStackTrace();

        die(1, "  Exception class=" + de.getClass().getName());
    }
}

From source file:de.tudarmstadt.lt.lm.web.servlet.LanguageModelProviderServlet.java

private boolean connectToLanguageModel(String key) throws Exception {
    try {/*from  w  ww.  j  ava  2s.c  o m*/
        int index = _lm_keys.get(key);
        Registry registry = LocateRegistry.getRegistry(_host, _port);
        StringProviderMXBean lmprvdr = (StringProviderMXBean) registry.lookup(key);
        if (lmprvdr.getModelReady()) {
            _lm_provider.set(index, lmprvdr);
            return true;
        }

    } catch (RemoteException e) {
        LOG.error("Unable to connect to rmi registry on {}:{}. {}: {}.", _host, _port,
                e.getClass().getSimpleName(), e.getMessage());
    } catch (NotBoundException e) {
        LOG.error("Unable to connect to service {}. {}: {}.", key, e.getClass().getSimpleName(),
                e.getMessage());
    }
    return false;
}

From source file:org.jgentleframework.utils.ExceptionUtils.java

/**
 * Convert the given RemoteException that happened during remote access to
 * {@link RemoteAccessException} if the method signature does not support
 * RemoteException. Else, return the original RemoteException.
 * /*from   w w w.  ja va2  s. c o m*/
 * @param method
 *            the invoked method
 * @param ex
 *            the RemoteException that happened
 * @param isConnectFailure
 *            whether the given exception should be considered a connect
 *            failure
 * @param serviceName
 *            the name of the service (for debugging purposes)
 * @return the exception to be thrown to the caller
 */
public static Exception convertRmiAccessException(Method method, RemoteException ex, boolean isConnectFailure,
        String serviceName) {

    if (log.isDebugEnabled()) {
        log.debug("Remote service [" + serviceName + "] threw exception", ex);
    }
    if (ReflectUtils.isDeclaredException(method, ex.getClass())) {
        return ex;
    } else {
        if (isConnectFailure) {
            return new RemoteFailingConnectionException(
                    "Could not connect to remote service [" + serviceName + "]", ex);
        } else {
            return new RemoteAccessException("Could not access remote service [" + serviceName + "]", ex);
        }
    }
}

From source file:org.ms123.common.rpc.JsonRpcServlet.java

protected Map<String, Object> buildResponse(final Map<String, Object> request,
        final RemoteException exception) {
    final Map<String, Object> response = new HashMap<String, Object>(3);
    final Map<String, Object> error = new HashMap<String, Object>(6);
    error.put("origin", ERROR_FROM_METHOD);
    error.put("code", null);
    error.put("message", exception.getMessage());
    error.put("class", exception.getClass().getName());
    final Throwable cause = exception.getCause();
    if (cause != null) {
    }//w  ww.j  a v a  2s.c  o  m
    response.put("id", request.get("id"));
    response.put("error", error);
    response.put("result", null);
    return response;
}

From source file:org.springframework.remoting.rmi.RmiClientInterceptorUtils.java

/**
 * Convert the given RemoteException that happened during remote access
 * to Spring's RemoteAccessException if the method signature does not
 * support RemoteException. Else, return the original RemoteException.
 * @param method the invoked method/*ww w  .  j av a  2s. c  o  m*/
 * @param ex the RemoteException that happened
 * @param isConnectFailure whether the given exception should be considered
 * a connect failure
 * @param serviceName the name of the service (for debugging purposes)
 * @return the exception to be thrown to the caller
 */
public static Exception convertRmiAccessException(Method method, RemoteException ex, boolean isConnectFailure,
        String serviceName) {

    if (logger.isDebugEnabled()) {
        logger.debug("Remote service [" + serviceName + "] threw exception", ex);
    }
    if (ReflectionUtils.declaresException(method, ex.getClass())) {
        return ex;
    } else {
        if (isConnectFailure) {
            return new RemoteConnectFailureException(
                    "Could not connect to remote service [" + serviceName + "]", ex);
        } else {
            return new RemoteAccessException("Could not access remote service [" + serviceName + "]", ex);
        }
    }
}