Example usage for java.rmi RemoteException RemoteException

List of usage examples for java.rmi RemoteException RemoteException

Introduction

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

Prototype

public RemoteException(String s) 

Source Link

Document

Constructs a RemoteException with the specified detail message.

Usage

From source file:com.amalto.core.delegator.IXtentisWSDelegator.java

@Override
public WSString deleteItemWithReport(WSDeleteItemWithReport wsDeleteItem) throws RemoteException {
    try {/*w w w  .  j  av a2  s.  c o  m*/
        String dataClusterPK = wsDeleteItem.getWsItemPK().getWsDataClusterPK().getPk();
        String concept = wsDeleteItem.getWsItemPK().getConceptName();
        String[] ids = wsDeleteItem.getWsItemPK().getIds();
        ItemPOJOPK pk = new ItemPOJOPK(new DataClusterPOJOPK(dataClusterPK), concept, ids);
        ItemPOJO pojo = Util.getItemCtrl2Local().getItem(pk);
        if (pojo == null) {
            throw new EntityNotFoundException(pk);
        }
        String dataModelPK = pojo.getDataModelName();
        if (UpdateReportPOJO.OPERATION_TYPE_LOGICAL_DELETE.equals(wsDeleteItem.getOperateType())) {
            Util.getItemCtrl2Local().dropItem(pk, "/", wsDeleteItem.getOverride()); //$NON-NLS-1$
            if (wsDeleteItem.getPushToUpdateReport()) {
                pushToUpdateReport(dataClusterPK, dataModelPK, concept, ids,
                        wsDeleteItem.getInvokeBeforeSaving(), wsDeleteItem.getSource(),
                        wsDeleteItem.getOperateType(), wsDeleteItem.getUser());
            }
            // Message status is stored into 'source' property of the function parameter WSDeleteItemWithReport
            // (not an ideal situation but necessary to get around WS API refactor) and returned back to the webui.
            wsDeleteItem.setSource(SUCCESS_KEYWORD);
            return new WSString("logical delete item successful!"); //$NON-NLS-1$
        } else { // Physical delete
            String status = null;
            String message = null;
            if (wsDeleteItem.getInvokeBeforeSaving()) {
                Util.BeforeDeleteResult result = Util.beforeDeleting(dataClusterPK, concept, ids,
                        wsDeleteItem.getOperateType());
                if (result != null) { // There was a before delete process to execute
                    if (ERROR_KEYWORD.equalsIgnoreCase(result.type)) {
                        wsDeleteItem.setSource(ERROR_KEYWORD);
                        if (result.message == null) {
                            return new WSString(
                                    "Could not retrieve the validation process result. An error might have occurred. The record was not deleted."); //$NON-NLS-1$
                        } else {
                            return new WSString(result.message);
                        }
                    } else if (INFO_KEYWORD.equalsIgnoreCase(result.type)) {
                        status = INFO_KEYWORD;
                        message = result.message;
                    } else {
                        status = SUCCESS_KEYWORD;
                        message = result.message;
                    }
                }
            }

            // Now before delete process (if any configured) was called, perform delete.
            ItemPOJOPK deleteItem = Util.getItemCtrl2Local().deleteItem(pk, wsDeleteItem.getOverride());
            if (deleteItem != null) {
                if (!UpdateReportPOJO.DATA_CLUSTER.equals(dataClusterPK)
                        && wsDeleteItem.getPushToUpdateReport()) {
                    pushToUpdateReport(dataClusterPK, dataModelPK, concept, ids,
                            wsDeleteItem.getInvokeBeforeSaving(), wsDeleteItem.getSource(),
                            wsDeleteItem.getOperateType(), wsDeleteItem.getUser());
                }
                if (status == null) { // do not overwrite BeforeDeleting message
                    status = SUCCESS_KEYWORD;
                    message = "physical delete item successful!"; //$NON-NLS-1$
                }
            } else {
                status = FAIL_KEYWORD;
                message = "Unable to delete item"; //$NON-NLS-1$
            }
            wsDeleteItem.setSource(status);
            return new WSString(message);
        }
    } catch (Exception e) {
        throw new RemoteException(e.getLocalizedMessage());
    }
}

From source file:com.amalto.core.delegator.IXtentisWSDelegator.java

@Override
public WSString executeRoutingOrderV2Synchronously(
        WSExecuteRoutingOrderV2Synchronously wsExecuteRoutingOrderSynchronously) throws RemoteException {
    try {//from  w  ww .  ja va  2s .c o m
        RoutingOrder ctrl = Util.getRoutingOrderV2CtrlLocal();
        AbstractRoutingOrderV2POJO ro = ctrl
                .getRoutingOrder(XConverter.WS2POJO(wsExecuteRoutingOrderSynchronously.getRoutingOrderV2PK()));
        return new WSString(ctrl.executeRoutingOrder(ro));
    } catch (Exception e) {
        if (LOGGER.isDebugEnabled()) {
            String err = "ERROR SYSTRACE: " + e.getMessage(); //$NON-NLS-1$
            LOGGER.debug(err, e);
        }
        throw new RemoteException(e.getClass().getName() + ": " + e.getLocalizedMessage()); //$NON-NLS-1$
    }
}

From source file:nl.cyso.vsphere.client.Entry.java

/**
 * @param args/* www.  j  ava 2s.  co  m*/
 */
public static void main(String[] args) {
    // Start out in ROOT ConfigMode
    CommandLine cli = null;

    // Initialize Formatter
    Formatter.setVersionInfo(Version.getVersion());
    ConfigModes.init();

    // Try to parse all ROOT cli options
    cli = Configuration.parseCli("ROOT", args);

    // Load the config if it was specified
    if (cli.hasOption("config")) {
        try {
            Configuration.loadFile(cli.getOptionValue("config"));
        } catch (ConfigurationException e) {
            e.printStackTrace();
            System.exit(-1);
        }
    }

    // Load all options parsed for ROOT ConfigMode
    Configuration.load(cli);

    // Now we know which ConfigMode was selected

    // Display (specific) help
    if (Configuration.get("mode").equals("HELP")) {
        if (Configuration.has("help-type")) {
            ConfigModes.printConfigModeHelp(Configuration.get("help-type").toString());
        } else {
            ConfigModes.printConfigModeHelp("ROOT");
        }
        System.exit(0);
    }

    // From this point on we want a header displayed
    Formatter.printHeader();

    // Display version information
    if (Configuration.get("mode").equals("VERSION")) {
        System.exit(0);
    }

    if (!Configuration.has("username") || !Configuration.has("password") || !Configuration.has("server")) {
        Formatter.usageError("No credentials were set, or server uri was missing", "ROOT", true);
    }

    try {
        String mode = Configuration.getString("mode");
        if (mode.equals("ADDVM")) {
            Configuration.load("ADDVM", args);
            VsphereClient.createVirtualMachine();
        } else if (mode.equals("REMOVEVM") || mode.equals("POWERONVM") || mode.equals("POWEROFFVM")
                || mode.equals("SHUTDOWNVM") || mode.equals("REBOOTVM") || mode.equals("MODIFYVM")) {
            Configuration.load(mode, args);

            Formatter.printInfoLine("Selecting root Virtual Machine folder");

            ManagedObjectReference rootFolder;
            if (Configuration.has("folder") && !Configuration.getString("folder").equals("")) {
                rootFolder = VsphereQuery.findVirtualMachineFolder(Configuration.getString("dc"),
                        Configuration.getString("folder"), 0);
            } else {
                rootFolder = VsphereQuery.getVMRootFolder(Configuration.getString("dc"));
            }

            if (rootFolder == null) {
                Formatter.printErrorLine("Could not select root Virtual Machine folder");
                System.exit(-1);
            }

            Formatter.printInfoLine("Walking folder to find Virtual Machine");

            ManagedObjectReference vm = VsphereQuery.findVirtualMachine(Configuration.getString("fqdn"),
                    rootFolder);

            if (vm == null) {
                Formatter.printErrorLine("Could not find VM");
                System.exit(-1);
            }

            if (mode.equals("REMOVEVM")) {
                Formatter.printInfoLine("Removing Virtual Machine: " + Configuration.getString("fqdn"));
                VsphereClient.deleteVirtualMachine(vm, Configuration.has("confirm"));
            } else if (mode.equals("POWERONVM")) {
                Formatter.printInfoLine("Powering on Virtual Machine: " + Configuration.getString("fqdn"));
                VsphereClient.powerOnVirtualMachine(vm);
            } else if (mode.equals("POWEROFFVM")) {
                Formatter.printInfoLine("Powering off Virtual Machine: " + Configuration.getString("fqdn"));
                VsphereClient.powerOffVirtualMachine(vm, Configuration.has("confirm"));
            } else if (mode.equals("SHUTDOWNVM")) {
                Formatter.printInfoLine(
                        "Requesting shutdown of Virtual Machine: " + Configuration.getString("fqdn"));
                VsphereClient.shutdownVirtualMachine(vm, Configuration.has("confirm"));
            } else if (mode.equals("REBOOTVM")) {
                Formatter.printInfoLine(
                        "Requesting reboot of Virtual Machine: " + Configuration.getString("fqdn"));
                VsphereClient.rebootVirtualMachine(vm, Configuration.has("confirm"));
            } else if (mode.equals("MODIFYVM")) {
                VsphereClient.modifyVirtualMachine(vm, Configuration.has("confirm"));
            }
        } else if (mode.equals("LIST")) {
            Configuration.load("LIST", args);

            ListModeType listType = null;
            try {
                listType = ListModeType.valueOf(Configuration.getString("list-type"));
            } catch (IllegalArgumentException e) {
                Formatter.usageError("Invalid List type selected", "LIST", true);
            }

            if (listType.equals(ListModeType.STORAGEFOLDER) && !Configuration.has("storage")) {
                Formatter.usageError("--storage must be specified when using storagefolder list mode", "LIST",
                        true);
            }

            switch (listType) {
            case FOLDER:
            case VM:
                VsphereClient.VMFolderListMode(listType);
                break;
            case CLUSTER:
            case ESXNODE:
            case NETWORK:
            case STORAGE:
                VsphereClient.ComputeFolderListMode(listType);
                break;
            case STORAGEFOLDER:
                ManagedObjectReference dsref = VsphereQuery.getDatastoreReference(
                        Configuration.getString("storage"), Configuration.getString("dc"));
                if (dsref == null) {
                    Formatter.printErrorLine("Could not find specified datastore");
                    System.exit(-1);
                }
                VsphereClient.DatastoreListMode(dsref);
                break;
            default:
                throw new UnsupportedOperationException("List Mode not yet implemented");
            }
        } else if (mode.equals("UPLOADTODATASTORE")) {
            Configuration.load("UPLOADTODATASTORE", args);

            URL server = new URL(Configuration.getString("server"));
            File file = new File(Configuration.getString("file"));
            String path = String.format("%s/%s", Configuration.getString("path"), file.getName());
            if (path.charAt(0) != '/') {
                path = "/" + path;
            }

            String uri = String.format("%s://%s/folder%s?dcPath=%s&dsName=%s", server.getProtocol(),
                    server.getHost(), path, URLEncoder.encode(Configuration.getString("dc"), "UTF-8"),
                    URLEncoder.encode(Configuration.getString("storage"), "UTF-8"));

            Formatter.printInfoLine("Connecting to Datastore...");
            HttpHelper http = new HttpHelper(new URL(uri), Configuration.getString("username"),
                    Configuration.getString("password"), true);

            Formatter.printInfoLine("Uploading file...");
            int response = http.putFile(file);

            switch (response) {
            case 200:
                Formatter.printInfoLine("File updated!");
                break;
            case 201:
                Formatter.printInfoLine("File created!");
                break;
            default:
                throw new RemoteException("Upload failed, HTTP error code: " + String.valueOf(response));
            }

            Formatter.printInfoLine("Upload finished!");
        } else {
            throw new UnsupportedOperationException("Mode not yet implemented");
        }
    } catch (RemoteException re) {
        Formatter.printError("An error occured on vSphere: ");
        Formatter.printErrorLine(re);
        System.exit(-1);
    } catch (RuntimeException re) {
        Formatter.printError("Failed to execute action: ");
        Formatter.printErrorLine(re);
        Formatter.printStackTrace(re);
        System.exit(-1);
    } catch (Exception e) {
        Formatter.printErrorLine("An unexpected error occurred: ");
        Formatter.printStackTrace(e);
        System.exit(-1);
    } finally {
        VsphereManager.disconnect();
    }
}

From source file:org.globus.examples.services.filebuy.buyer.impl.FileBuyerService.java

public TransferResponse transfer(Transfer params) throws RemoteException {
    /* Retrieve parameters */
    String name = params.getName();
    byte data[] = params.getData();

    // Report code
    int reportCode;

    // Retrieve expected file name from FilePurchase resource
    FilePurchaseResource purchase = getResource();
    String expectedName = purchase.getName();

    // Check if this is the file we're expecting
    if (!expectedName.equals(name)) {
        logger.error("ERROR: Received a transfer request for an unexpected file.");
        throw new RemoteException("ERROR: Received a transfer request for an unexpected file.");
    }/* w w  w.  j ava2 s .  co  m*/

    // Write file to disk
    String filePath = System.getProperty("java.io.tmpdir") + File.separatorChar + "File-" + name;
    try {
        FileOutputStream fos = new FileOutputStream(filePath);
        fos.write(data);
        fos.flush();
        reportCode = 0; // Success
    } catch (IOException e) {
        logger.error("ERROR: Unable to write file to disk.");
        reportCode = -1; // Error
    }

    /*
     * REPORT TRANSFER
     */

    // Retrieve fileOrder EPR from FilePurchase resource. We will use it to
    // confirm that the transfer has been successful.
    EndpointReferenceType fileOrderEPR = purchase.getFileOrderEPR();

    // Get FileBroker portType
    FileBrokerServiceAddressingLocator brokerLocator;
    brokerLocator = new FileBrokerServiceAddressingLocator();
    FileBrokerPortType broker = null;
    try {
        broker = brokerLocator.getFileBrokerPortTypePort(fileOrderEPR);
    } catch (ServiceException e) {
        logger.error("ERROR: Unable to obtain broker portType.");
        throw new RemoteException("ERROR: Unable to obtain broker portType.", e);
    }

    // Setup security options
    ((Stub) broker)._setProperty(Constants.GSI_TRANSPORT, Constants.SIGNATURE);
    ((Stub) broker)._setProperty(Constants.AUTHORIZATION, NoAuthorization.getInstance());

    // Invoke Report operation
    try {
        broker.report(reportCode);
    } catch (RemoteException e) {
        logger.error("ERROR: Unable to invoke Purchase operation in broker.");
        throw new RemoteException("ERROR: Unable to invoke Purchase operation in broker.", e);

    }

    return new TransferResponse();
}

From source file:org.globus.examples.services.filebuy.seller.impl.FilesForSaleFactoryService.java

public AddFileResponse addFile(AddFile params) throws RemoteException {
    FileResourceHome home = null;/*  w w w .j  a va 2  s. c  o m*/
    ResourceKey key = null;

    // Retrieve parameters 
    String name = params.getName();
    String location = params.getLocation();
    float price = params.getPrice();

    logger.debug("addFile invoked with name=" + name + ",location=" + location + ",price=" + price);

    // First of all, we check if the file exceeds the size limit 
    File file = new File(location);
    if (file.length() > MAX_FILE_SIZE) {
        logger.error("ERROR: File size (" + file.length() + ") exceeds size limit.");
        throw new RemoteException("ERROR: File size (" + file.length() + ") exceeds size limit.");
    }

    /*
     * CREATE A FILE RESOURCE
     */

    // We create a new FileResource through the FileResourceHome
    try {
        home = (FileResourceHome) getInstanceResourceHome();
        key = home.create(name, location, price);
    } catch (Exception e) {
        logger.error("ERROR: Couldn't create new File resource");
        throw new RemoteException("ERROR: Couldn't create File EPR", e);
    }
    EndpointReferenceType epr = null;

    // We construct the EPR for the recently created WS-Resource.
    // The File resource will be accessed through an instance service.
    try {
        URL baseURL = ServiceHost.getBaseURL();
        // The instance service path is contained in the configuration
        // object
        FilesForSaleConfiguration config = FilesForSaleConfiguration.getConfObject();
        String instanceService = config.getInstanceServicePath();
        String instanceURI = baseURL.toString() + instanceService;
        // The endpoint reference includes the instance's URI and the
        // resource key
        epr = AddressingUtils.createEndpointReference(instanceURI, key);
    } catch (Exception e) {
        logger.error("ERROR: Couldn't create File EPR");
        throw new RemoteException("ERROR: Couldn't create File EPR", e);
    }

    logger.info("Added new file. NAME=" + name + ", LOCATION=" + location + ", PRICE=" + price);
    logger.info("File has been added by user '" + SecurityManager.getManager().getCaller() + "'");

    /*
     * RETURN ENDPOINT REFERENCE TO NEW WS-RESOURCE
     */

    AddFileResponse response = new AddFileResponse();
    response.setEndpointReference(epr);
    return response;
}

From source file:org.globus.mds.bigindex.impl.GetContentProvider.java

public GetContentResponse getContent(BigIndexContentIDList request)
        throws RemoteException, org.oasis.wsrf.faults.BaseFaultType {
    if (logger.isDebugEnabled()) {
        logger.debug("GetContentProvider GetContent called");
    }//from ww w .j  a va2 s  .c o  m

    if ((request == null) || ((request != null) && (request.getContentID() == null))) {
        throw new RemoteException("Invalid parameter");
    }

    BigIndexResource resource = null;
    try {
        // get the resource            
        resource = (BigIndexResource) ResourceContext.getResourceContext().getResource();
    } catch (Exception e) {
        throw new RemoteException("Error: could not get resource" + e);
    }

    // get db instance
    XindiceIndexDatabase db = resource.getDatabase();
    if (db == null) {
        throw new RemoteException("Error: database instance is null");
    }

    String colURI = db.getDefaultCollectionURI();
    String[] contentList = request.getContentID();
    ArrayList results = new ArrayList(contentList.length);

    for (int i = 0; i < contentList.length; i++) {
        try {
            String doc = (String) db.getDocument(colURI, contentList[i], true);
            BigIndexContent content = new BigIndexContent();

            BigIndexEntry bigEntry = (BigIndexEntry) ObjectDeserializer
                    .deserialize(new InputSource(new StringReader(doc)), BigIndexEntry.class);

            content.setContentID(contentList[i]);
            EntryType entry = bigEntry.getEntry();
            if (entry != null) {
                content.setContent(entry.getContent());
            }
            results.add(content);
        } catch (Exception e) {
            if (logger.isDebugEnabled()) {
                logger.debug("Exception getting a document from the database: " + e);
            }
            continue;
        }
    }

    GetContentResponse response = new GetContentResponse();
    response.setBigIndexContent((BigIndexContent[]) results.toArray(new BigIndexContent[] {}));

    return response;
}

From source file:org.globus.mds.bigindex.impl.QueryProvider.java

public Object query(QueryType request) throws RemoteException {
    if (logger.isDebugEnabled()) {
        logger.info("QueryProvider query called");
    }//from   www. j  av a2  s .c  om

    // get the resource
    BigIndexResource resource = null;
    try {
        resource = (BigIndexResource) ResourceContext.getResourceContext().getResource();
    } catch (Exception e) {
        throw new RemoteException(e.toString());
    }

    // get db instance
    XindiceIndexDatabase db = resource.getDatabase();
    if (db == null) {
        throw new RemoteException("Error: database instance is null");
    }

    List results = null;
    try {
        results = db.query(request.getQueryString(), request.getNamespaces());
    } catch (Exception e) {
        throw new RemoteException(e.toString());
    }

    QueryResponse response = new QueryResponse();
    AnyHelper.setAny(response, results);

    return response;
}

From source file:org.globus.mds.bigindex.impl.QueryRPProvider.java

public QueryResourcePropertiesResponse queryResourceProperties(QueryResourceProperties_Element request)
        throws RemoteException, InvalidResourcePropertyQNameFaultType, ResourceUnknownFaultType,
        InvalidQueryExpressionFaultType, QueryEvaluationErrorFaultType, UnknownQueryExpressionDialectFaultType {

    if (request == null) {
        throw new RemoteException(i18n.getMessage("nullArgument", "request"));
    }//  w  ww .java2 s. c o  m

    BigIndexResource resource = null;
    try {
        resource = (BigIndexResource) ResourceContext.getResourceContext().getResource();
    } catch (NoSuchResourceException e) {
        ResourceUnknownFaultType fault = new ResourceUnknownFaultType();
        FaultHelper faultHelper = new FaultHelper(fault);
        faultHelper.addFaultCause(e);
        throw fault;
    } catch (Exception e) {
        throw new RemoteException(i18n.getMessage("resourceDisoveryFailed"), e);
    }

    QueryExpressionType query = request.getQueryExpression();
    String queryStr;
    try {
        queryStr = this.getQueryString(query);
    } catch (Exception e) {
        throw new RemoteException("Query string parsing error", e);
    }

    if (this.isDatabaseQuery(queryStr)) {
        // get db instance
        XindiceIndexDatabase db = resource.getDatabase();
        if (db == null) {
            throw new RemoteException("Error: database instance is null");
        }

        List results = null;
        try {
            results = db.query(queryStr, null);
        } catch (Exception e) {
            e.printStackTrace();
            throw new RemoteException("Query error", e);
        }

        QueryResourcePropertiesResponse response = new QueryResourcePropertiesResponse();
        AnyHelper.setAny(response, results);

        return response;
    } else {
        return super.queryResourceProperties(request);
    }

}

From source file:org.globus.workspace.remoting.admin.defaults.DefaultRemoteAdminToolsMgmt.java

public String getAllRunningVMs() throws RemoteException {
    try {//w ww.  j a  v a  2s  . c  o  m
        VM[] allRunningVms = manager.getGlobalAll();

        final List<VMTranslation> vmts = new ArrayList<VMTranslation>(allRunningVms.length);
        for (int i = 0; i < allRunningVms.length; i++) {
            vmts.add(translateVM(allRunningVms[i]));
        }
        return gson.toJson(vmts);
    } catch (ManageException e) {
        throw new RemoteException(e.getMessage());
    }
}

From source file:org.globus.workspace.remoting.admin.defaults.DefaultRemoteAdminToolsMgmt.java

public String getVMsByDN(String userDN) throws RemoteException {
    try {/*  w  ww  .j a  va2 s  .c  o m*/
        final _Caller caller = this.reprFactory._newCaller();
        caller.setIdentity(userDN);
        VM[] vms = manager.getAllByCaller(caller);

        if (vms.length == 0)
            return null;

        final List<VMTranslation> vmts = new ArrayList<VMTranslation>(vms.length);
        for (int i = 0; i < vms.length; i++) {
            vmts.add(translateVM(vms[i]));
        }
        return gson.toJson(vmts);
    } catch (ManageException e) {
        throw new RemoteException(e.getMessage());
    }
}