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, Throwable cause) 

Source Link

Document

Constructs a RemoteException with the specified detail message and cause.

Usage

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

@Override
public WSCheckServiceConfigResponse checkServiceConfiguration(WSCheckServiceConfigRequest serviceName)
        throws RemoteException {
    // Kept for backward compatibility
    try {/*  ww w . j av  a2  s .  c om*/
        Service service = PluginRegistry.getInstance()
                .getService(PluginRegistry.SERVICE_PREFIX + serviceName.getJndiName());
        return new WSCheckServiceConfigResponse(service == null ? false : true);
    } catch (Exception e) {
        throw new RemoteException(
                (e.getCause() == null ? e.getLocalizedMessage() : e.getCause().getLocalizedMessage()), e);
    }
}

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

@Override
public WSServicesList getServicesList(WSGetServicesList wsGetServicesList) throws RemoteException {
    try {/*from  ww w .j a va2 s .  c  om*/
        ArrayList<WSServicesListItem> wsList = new ArrayList<WSServicesListItem>();
        Map<String, Service> servicesMap = PluginRegistry.getInstance().getServices();
        for (String key : servicesMap.keySet()) {
            WSServicesListItem item = new WSServicesListItem();
            item.setJndiName(key.replaceAll(PluginRegistry.SERVICE_PREFIX, "")); //$NON-NLS-1$
            wsList.add(item);
        }
        return new WSServicesList(wsList.toArray(new WSServicesListItem[wsList.size()]));
    } catch (Exception e) {
        throw new RemoteException(
                (e.getCause() == null ? e.getLocalizedMessage() : e.getCause().getLocalizedMessage()), e);
    }
}

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

@Override
public WSServiceGetDocument getServiceDocument(WSString serviceName) throws RemoteException {
    try {//from   w  w w.  ja  v  a  2 s.c  o  m
        Service service = PluginRegistry.getInstance()
                .getService(PluginRegistry.SERVICE_PREFIX + serviceName.getValue());
        String desc = service.getDescription(""); //$NON-NLS-1$
        String configuration = service.getConfiguration(""); //$NON-NLS-1$
        String doc = service.getDocumentation(""); //$NON-NLS-1$
        String defaultConf = service.getDefaultConfiguration();
        return new WSServiceGetDocument(desc, configuration, doc, "", defaultConf); //$NON-NLS-1$
    } catch (Exception e) {
        throw new RemoteException(
                (e.getCause() == null ? e.getLocalizedMessage() : e.getCause().getLocalizedMessage()), e);
    }
}

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

private RemoteException handleException(Throwable throwable, String errorMessage) {
    CoreException coreException;/*from   w  w w.  jav  a  2  s  .co  m*/
    if (CoreException.class.isInstance(throwable)) {
        coreException = (CoreException) throwable;
    } else if (ValidateException.class.isInstance(throwable)) {
        coreException = new CoreException(VALIDATE_EXCEPTION_MESSAGE, throwable);
    } else if (SchematronValidateException.class.isInstance(throwable)) {
        coreException = new CoreException(VALIDATE_EXCEPTION_MESSAGE, throwable.getMessage(),
                CoreException.INFO);
    } else if (CVCException.class.isInstance(throwable)) {
        coreException = new CoreException(CVC_EXCEPTION_MESSAGE, throwable);
    } else if (JobNotFoundException.class.isInstance(throwable)) {
        coreException = new CoreException(JOB_NOT_FOUND_EXCEPTION_MESSAGE, throwable);
    } else if (com.amalto.core.jobox.util.JoboxException.class.isInstance(throwable)) {
        coreException = new CoreException(JOBOX_EXCEPTION_MESSAGE, throwable);
    } else if (BeforeSavingErrorException.class.isInstance(throwable)) {
        coreException = new CoreException(SAVE_PROCESS_BEFORE_SAVING_FAILURE_MESSAGE, throwable);
    } else if (BeforeSavingFormatException.class.isInstance(throwable)) {
        coreException = new CoreException(BEFORE_SAVING_FORMAT_ERROR_MESSAGE, throwable);
        coreException.setClient(true);
    } else if (OutputReportMissingException.class.isInstance(throwable)) {
        coreException = new CoreException(OUTPUT_REPORT_MISSING_ERROR_MESSAGE, throwable);
    } else if (RoutingException.class.isInstance(throwable)) {
        coreException = new CoreException(ROUTING_ERROR_MESSAGE, throwable);
    } else if (FullTextQueryCompositeKeyException.class.isInstance(throwable)) {
        coreException = new CoreException(FULLTEXT_QUERY_COMPOSITE_KEY_EXCEPTION_MESSAGE, throwable);
    } else if (SaveException.class.isInstance(throwable)) {
        coreException = new CoreException(SAVE_EXCEPTION_MESSAGE, throwable);
    } else if (MultiRecordsSaveException.class.isInstance(throwable)) {
        coreException = new CoreException(MULTI_RECORDS_SAVE_EXCEPTION_MESSAGE, throwable);
    } else if (UnsupportedFullTextQueryException.class.isInstance(throwable)) {
        coreException = new CoreException(UNSUPPORTED_FULLTEXT_QUERY_EXCEPTION_MESSAGE, throwable);
    } else {
        if (throwable.getCause() != null) {
            return handleException(throwable.getCause(), errorMessage);
        } else {
            coreException = new CoreException(errorMessage, throwable);
        }
    }
    return new RemoteException(StringUtils.EMPTY, coreException);
}

From source file:org.globus.examples.services.filebuy.broker.impl.FileBrokerService.java

private FileOrderResource getResource() throws RemoteException {
    Object resource = null;/*  w  w  w  .j  ava2  s. c o  m*/
    try {
        resource = ResourceContext.getResourceContext().getResource();
    } catch (NoSuchResourceException e) {
        throw new RemoteException("Specified resource does not exist", e);
    } catch (ResourceContextException e) {
        throw new RemoteException("Error during resource lookup", e);
    } catch (Exception e) {
        throw new RemoteException("", e);
    }

    FileOrderResource fileResource = (FileOrderResource) resource;
    return fileResource;
}

From source file:org.globus.examples.services.filebuy.broker.impl.FileBrokerService.java

public FindResponse find(Find params) throws RemoteException {
    /* Retrieve parameters */
    String name = params.getName();
    float maxPrice = params.getMaxPrice();

    logger.debug("find invoked with name=" + name + ",maxPrice=" + maxPrice);

    /* Create response object */
    FindResponse response = new FindResponse();

    /*//  w  ww  .j a v a  2s . co  m
     * QUERY INDEX SERVICE
     */

    // Create index service EPR
    FileBrokerConfiguration conf = null;
    try {
        conf = FileBrokerConfiguration.getConfObject();
    } catch (Exception e) {
        logger.error("ERROR: Unable to obtain FileBroker configuration object (JNDI).");
        throw new RemoteException("ERROR: Unable to obtain FileBroker configuration object (JNDI).", e);
    }
    String indexURI = conf.getIndexURI();
    EndpointReferenceType indexEPR = new EndpointReferenceType();
    try {
        indexEPR.setAddress(new Address(indexURI));
    } catch (Exception e) {
        logger.error("ERROR: Malformed index URI '" + indexURI + "'");
        throw new RemoteException("ERROR: Malformed index URI '" + indexURI + "'", e);
    }

    // Get QueryResourceProperties portType
    WSResourcePropertiesServiceAddressingLocator queryLocator;
    queryLocator = new WSResourcePropertiesServiceAddressingLocator();
    QueryResourceProperties_PortType query = null;
    try {
        query = queryLocator.getQueryResourcePropertiesPort(indexEPR);
    } catch (ServiceException e) {
        logger.error("ERROR: Unable to obtain query portType.");
        throw new RemoteException("ERROR: Unable to obtain query portType.", e);
    }

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

    // The following XPath query retrieves all the files with the specified
    // name
    String xpathQuery = "//*[local-name()='Entry'][./*/*/*[local-name()='Name']/text()='" + name + "']";

    // Create request to QueryResourceProperties
    QueryExpressionType queryExpr = new QueryExpressionType();
    try {
        queryExpr.setDialect(new URI(WSRFConstants.XPATH_1_DIALECT));
    } catch (Exception e) {
        logger.error("ERROR: Malformed URI (WSRFConstants.XPATH_1_DIALECT)");
        throw new RemoteException("ERROR: Malformed URI (WSRFConstants.XPATH_1_DIALECT)", e);
    }
    queryExpr.setValue(xpathQuery);
    QueryResourceProperties_Element queryRequest = new QueryResourceProperties_Element(queryExpr);

    // Invoke QueryResourceProperties
    QueryResourcePropertiesResponse queryResponse = null;
    try {
        queryResponse = query.queryResourceProperties(queryRequest);
    } catch (RemoteException e) {
        logger.error("ERROR: Unable to invoke QueryRP operation.");
        throw new RemoteException("ERROR: Unable to invoke QueryRP operation.", e);
    }
    // The response includes 0 or more entries from the index service.
    MessageElement[] entries = queryResponse.get_any();

    /*
     * FIND THE CHEAPEST FILE
     */

    // If the number of entries is 0, there are no files with that name.
    if (entries == null || entries.length == 0) {
        logger.debug("No file found with name " + name);

        // We return a null EPR to indicate that no file has
        // been found meeting the specified criteria.
        // Ideally, we should throw a custom exception.
        response.setFileOrderEPR(null);

    } else {
        // We know that there is at least one file with the specified name.
        // Now, we find the cheapest file, to then see if it meets the
        // price restriction
        float minPrice = Float.MAX_VALUE;
        EntryType cheapestEntry = null;
        for (int i = 0; i < entries.length; i++) {

            try {
                // Access information contained in the entry. First of all,
                // we need to deserialize the entry...
                EntryType entry = (EntryType) ObjectDeserializer.toObject(entries[i], EntryType.class);

                // ... access its content ...
                AggregatorContent content = (AggregatorContent) entry.getContent();

                // ... then the data ...
                AggregatorData data = content.getAggregatorData();

                /*
                 * Now, because of how the registration is set up, we know
                 * that the price is the second element.
                 * 
                 * From registration.xml:
                 * <agg:ResourcePropertyNames>ffs:Name
                 * </agg:ResourcePropertyNames>
                 * <agg:ResourcePropertyNames>ffs:Price
                 * </agg:ResourcePropertyNames>
                 */
                String price_str = data.get_any()[1].getValue();
                float price = Float.parseFloat(price_str);

                /* Is this the cheapest? */
                if (price < minPrice) {
                    minPrice = price;
                    cheapestEntry = entry;
                }

            } catch (Exception e) {
                logger.error("Error when accessing index service entry.");
                throw new RemoteException("Error when accessing index service entry.", e);
            }
        }

        if (minPrice < maxPrice) {
            // A file matches the specified criteria!

            // Return values
            float price = minPrice;
            EndpointReferenceType fileOrderEPR = null;

            /*
             * CREATE A FILE ORDER RESOURCE, AND ADD THE CHEAPEST FILE TO
             * THE RESOURCE
             */

            // Get EPR of File resource. It will be included in the
            // FileOrder resource we are going to create
            EndpointReferenceType fileEPR = cheapestEntry.getMemberServiceEPR();
            ResourceContext ctx = null;
            FileOrderResourceHome home = null;
            ResourceKey key = null;
            try {
                /* Create new FileOrder resource */
                ctx = ResourceContext.getResourceContext();
                home = (FileOrderResourceHome) ctx.getResourceHome();
                key = home.create(name, fileEPR);
                /* Create FileOrder EPR */
                URL serviceURL = ctx.getServiceURL();
                fileOrderEPR = AddressingUtils.createEndpointReference(serviceURL.toString(), key);
            } catch (Exception e) {
                logger.error("Error when creating FileOrder resource.");
                throw new RemoteException("Error when creating FileOrder resource.", e);
            }

            logger.debug("Found file with price=" + price);

            logger.info("Created new file order for file NAME=" + name + ", PRICE=" + price);
            logger.info(
                    "FileOrder has been created for user '" + SecurityManager.getManager().getCaller() + "'");

            /* Create response object */
            response.setPrice(price);
            response.setFileOrderEPR(fileOrderEPR);

        } else {
            logger.debug("No file with name " + name + " is cheaper than " + maxPrice);

            // We return a null EPR to indicate that no file has
            // been found meeting the specified criteria.
            // Ideally, we should throw a custom exception.
            response.setFileOrderEPR(null);
        }
    }

    return response;
}

From source file:org.globus.examples.services.filebuy.broker.impl.FileBrokerService.java

public PurchaseResponse purchase(Purchase params) throws RemoteException {
    /* Retrieve parameters */
    EndpointReferenceType buyerEPR = params.getBuyerEPR();

    /* Get EPR of file to purchase (contained in FileOrder resource) */
    FileOrderResource fileOrder = getResource();
    EndpointReferenceType fileEPR = fileOrder.getFileEPR();

    logger.info("Going to purchase file " + fileOrder.getName());
    logger.info("Purchase requested by user '" + SecurityManager.getManager().getCaller() + "'");

    /*/*from w  w  w .j  av  a2  s . c  o  m*/
     * INVOKE FILLORDER OPERATION IN THE SELLE
     */

    // Get FIlesForSale portType
    FilesForSaleServiceAddressingLocator filesForSaleLocator;
    filesForSaleLocator = new FilesForSaleServiceAddressingLocator();
    FilesForSalePortType filesForSale = null;
    try {
        filesForSale = filesForSaleLocator.getFilesForSalePortTypePort(fileEPR);
    } catch (ServiceException e) {
        logger.error("ERROR: Unable to obtain FilesForSale portType.");
        throw new RemoteException("ERROR: Unable to obtain FilesForSale portType.", e);
    }

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

    /* Invoke FillOrder operation */

    // Create request to FillOrder operation
    FillOrder fillOrderRequest = new FillOrder();
    fillOrderRequest.setBuyerEPR(buyerEPR);

    // Perform invocation
    try {
        filesForSale.fillOrder(fillOrderRequest);
    } catch (RemoteException e) {
        logger.error("ERROR: Unable to invoke FillOrder operation.");
        throw new RemoteException("ERROR: Unable to invoke FillOrder operation.", e);
    }

    return new PurchaseResponse();
}

From source file:org.globus.examples.services.filebuy.broker.impl.FileBrokerService.java

public ReportResponse report(int reportCode) throws RemoteException {

    logger.info("Received report of transfer of file " + getResource().getName());
    logger.info("Report code: " + reportCode);

    if (reportCode == 0) {
        logger.info("Order completed successfully.");
        ResourceContext ctx = null;/*from  ww  w. ja  v  a  2  s. c om*/
        FileOrderResourceHome home = null;
        ResourceKey key = null;
        try {
            /* Destroy FileOrder resource */
            ctx = ResourceContext.getResourceContext();
            home = (FileOrderResourceHome) ctx.getResourceHome();
            key = ctx.getResourceKey();
            home.remove(key);
        } catch (Exception e) {
            logger.error("Error when destroying FileOrder resource.");
            throw new RemoteException("Error when destroying FileOrder resource.", e);
        }
    } else {
        logger.error("File was not transfered!");
    }
    return new ReportResponse();
}

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

private FilePurchaseResource getResource() throws RemoteException {
    Object resource = null;//from   w  ww .java2s.c  o m
    try {
        resource = ResourceContext.getResourceContext().getResource();
    } catch (NoSuchResourceException e) {
        throw new RemoteException("Specified resource does not exist", e);
    } catch (ResourceContextException e) {
        throw new RemoteException("Error during resource lookup", e);
    } catch (Exception e) {
        throw new RemoteException("", e);
    }

    FilePurchaseResource fileResource = (FilePurchaseResource) resource;
    return fileResource;
}

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

public PurchaseResponse purchase(Purchase params) throws RemoteException {
    /* Use delegated credentials */
    SecurityManager.getManager().setServiceOwnerFromContext();

    /* Retrieve parameters */
    EndpointReferenceType fileOrderEPR = params.getFileOrderEPR();

    // Get name of file to be purchased
    // The name will be saved to make sure that we receive the expected file
    String name;// w  w w.  ja va  2  s.  com
    try {
        name = getFileName(fileOrderEPR);
    } catch (Exception e) {
        logger.error("ERROR: Unable to obtain file's name.");
        throw new RemoteException("ERROR: Unable to obtain file's name.", e);
    }

    // Create a FilePurchase resource. This resource will allow us to keep
    // a copy of the FileOrder EPR and the name of the file, which we will
    // need when the Transfer operation is invoked by the FileTransfer
    // service.
    ResourceContext ctx = null;
    FilePurchaseResourceHome home = null;
    ResourceKey key = null;
    EndpointReferenceType buyerEPR = null;
    try {
        /* Create new FilePurchase resource */
        ctx = ResourceContext.getResourceContext();
        home = (FilePurchaseResourceHome) ctx.getResourceHome();
        key = home.create(name, fileOrderEPR);
        /* Create FilePurchase EPR */
        URL serviceURL = ctx.getServiceURL();
        buyerEPR = AddressingUtils.createEndpointReference(serviceURL.toString(), key);
    } catch (Exception e) {
        logger.error("Error when creating FilePurchase resource.");
        throw new RemoteException("Error when creating FilePurchase resource.", e);
    }

    /*
     * INVOKE THE PURCHASE OPERATION IN THE FILE BROKER
     */

    // 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 Purchase operation */

    // Create request to Purchase operation
    org.globus.examples.stubs.filebuy.FileBroker.Purchase purchaseRequest;
    purchaseRequest = new org.globus.examples.stubs.filebuy.FileBroker.Purchase();
    purchaseRequest.setBuyerEPR(buyerEPR);

    // Perform invocation
    PurchaseResponse findResponse = null;
    try {
        broker.purchase(purchaseRequest);
    } 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 PurchaseResponse();
}