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:org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.rm.defaults.DefaultRun.java

public CreateRequest translateRunInstances(RunInstancesType req, Caller caller)
        throws RemoteException, CannotTranslateException {

    final String ownerID;
    try {// w w  w . j  a v a 2s .c o m
        ownerID = this.container.getOwnerID(caller);
    } catch (CannotTranslateException e) {
        throw new RemoteException(e.getMessage(), e);
    }

    final String imageID = req.getImageId();
    if (imageID == null) {
        throw new RemoteException("Request is missing image ID");
    }

    // currently ignored: groupSet, placement, kernel, ramdiskid,
    // blockDeviceMapping

    final _CustomizationRequest cust;
    final String keyname = req.getKeyName();
    if (keyname != null && this.sshKeys != null) {
        cust = this.repr._newCustomizationRequest();
        final SSHKey key = this.sshKeys.findKey(ownerID, keyname);
        if (key == null) {
            throw new RemoteException("There is no key '" + keyname + "' registered for you to use");
        }
        cust.setContent(key.getPubKeyValue());
        cust.setPathOnVM("/root/.ssh/authorized_keys");
    } else {
        cust = null;
    }

    final CustomizationRequest[] custRequests;
    if (cust != null) {
        custRequests = new CustomizationRequest[1];
        custRequests[0] = cust;
    } else {
        custRequests = null;
    }

    final String raType = req.getInstanceType();
    final ResourceAllocation ra = this.RAs.getMatchingRA(raType, req.getMinCount(), req.getMaxCount(), false);
    final NIC[] nics = this.getNICs(ra.getPublicNetwork(), ra.getPrivateNetwork());
    final RequiredVMM reqVMM = this.RAs.getRequiredVMM();

    String userData = null;
    final UserDataType t_userData = req.getUserData();
    if (t_userData != null) {
        final String base64Encoded = t_userData.getData();
        if (base64Encoded != null) {
            // Remove newlines from the base64 string since they are not
            // supported by the Globus implementation
            final String base64EncodedNoCRLF = base64Encoded.replaceAll("[\r\n]", "");
            if (!Base64.isBase64(base64EncodedNoCRLF)) {
                throw new RemoteException("userdata does not appear to " + "be base64 encoded?");
            }
            final byte[] bytes = Base64.decode(base64EncodedNoCRLF.getBytes());
            userData = new String(bytes);
        }
    }

    final VMFile[] files = this.repository.constructFileRequest(imageID, ra, caller);

    final String clientToken = req.getClientToken();

    String availabilityZone = null;
    if (req.getPlacement() != null) {
        availabilityZone = req.getPlacement().getAvailabilityZone();
    }

    final _CreateRequest creq = this.repr._newCreateRequest();

    DefaultKernel kernel = null;
    String kernelRequestString = req.getKernelId();
    if (kernelRequestString != null) {
        kernel = new DefaultKernel();
        try {
            URI kernelURI = new URI("file://" + kernelRequestString);
            kernel.setKernel(kernelURI);
        } catch (URISyntaxException ueie) {
            throw new RemoteException(ueie.toString());
        }
    }

    creq.setContext(null);
    creq.setCoScheduleDone(false);
    creq.setCoScheduleID(null);
    creq.setCoScheduleMember(false);
    creq.setCustomizationRequests(custRequests);
    creq.setInitialStateRequest(State.STATE_Running);
    creq.setName(imageID);
    creq.setRequestedKernel(kernel); // todo
    creq.setRequestedNics(nics);
    creq.setRequestedRA(ra);
    creq.setRequestedSchedule(null); // ask for default
    creq.setRequiredVMM(reqVMM);
    creq.setShutdownType(CreateRequest.SHUTDOWN_TYPE_TRASH);
    creq.setVMFiles(files);
    creq.setMdUserData(userData);
    creq.setSshKeyName(keyname);
    creq.setClientToken(clientToken);
    creq.setRequestedResourcePool(availabilityZone);

    return creq;
}

From source file:org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.security.ServiceSecurityImpl.java

public CreateKeyPairResponseType createKeyPair(CreateKeyPairType req) throws RemoteException {

    // no use proceeding if these calls fail:
    final Caller caller = this.container.getCaller();
    final String ownerID;
    try {//from   w  ww  .j a  va  2  s.  c om
        ownerID = this.container.getOwnerID(caller);
    } catch (CannotTranslateException e) {
        throw new RemoteException(e.getMessage(), e);
    }

    if (req == null) {
        throw new RemoteException("createKeyPair request is missing");
    }

    final String input = req.getKeyName();
    if (input == null) {
        throw new RemoteException("createKeyPair request does not contain key name");
    }

    final String splitToken;
    try {

        splitToken = this.sshKeys.getSplitToken();

    } catch (DisabledException e) {

        /* If split token method is disabled that means the standard
           "create keypair serverside" method is enabled.  Input field
           is the requested key name. */
        try {
            // *** EARLY RETURN ***
            return this.keyGen.createNewKeyPair(caller, input.trim());
        } catch (DisabledException e1) {
            throw new RuntimeException("Both SSH key implementations are disabled?");
        } catch (KeyGenException e1) {
            throw new RemoteException(e1.getMessage(), e1);
        }
    }

    // this is like an 'else' clause, see createNewKeyPair() call
    return this.splitMethod(splitToken, input, ownerID);
}

From source file:org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.security.ServiceSecurityImpl.java

public ImportKeyPairResponseType importKeyPair(ImportKeyPairType req) throws RemoteException {

    // no use proceeding if these calls fail:
    final Caller caller = this.container.getCaller();
    final String ownerID;
    try {/*from w ww  .  ja va 2s  .  c o m*/
        ownerID = this.container.getOwnerID(caller);
    } catch (CannotTranslateException e) {
        throw new RemoteException(e.getMessage(), e);
    }

    if (req == null) {
        throw new RemoteException("key name is missing");
    }

    final String keyName = req.getKeyName();
    if (keyName == null) {
        throw new RemoteException("createKeyPair request does not contain key name");
    }

    final String publicKeyMaterial = req.getPublicKeyMaterial();
    if (publicKeyMaterial == null) {
        throw new RemoteException("key material is missing");
    }
    if (!Base64.isBase64(publicKeyMaterial)) {
        throw new RemoteException("key material does not appear to " + "be base64 encoded?");
    }
    final byte[] bytes = Base64.decode(publicKeyMaterial.getBytes());
    final String keyMaterial = new String(bytes);

    this.sshKeys.newKey(ownerID, keyName, keyMaterial, FAKE_FINGERPRINT);

    final ImportKeyPairResponseType resp = new ImportKeyPairResponseType(FAKE_FINGERPRINT, keyName, null);

    logger.info("SSH key registered, name='" + keyName + "', owner ID='" + ownerID + "'");

    return resp;
}

From source file:org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.security.ServiceSecurityImpl.java

public DescribeKeyPairsResponseType describeKeyPairs(DescribeKeyPairsType req) throws RemoteException {

    // no use proceeding if these calls fail:
    final Caller caller = this.container.getCaller();
    final String ownerID;
    try {/* ww w  . j  ava 2  s .com*/
        ownerID = this.container.getOwnerID(caller);
    } catch (CannotTranslateException e) {
        throw new RemoteException(e.getMessage(), e);
    }

    if (req == null) {
        throw new RemoteException("describeKeyPairs request is missing");
    }

    final DescribeKeyPairsInfoType pairsInfoType = req.getKeySet();
    final DescribeKeyPairsItemType[] keyPairsItemTypes = pairsInfoType.getItem();

    final String[] filterQuery;
    if (keyPairsItemTypes == null || keyPairsItemTypes.length == 0) {
        filterQuery = null;
    } else {
        filterQuery = new String[keyPairsItemTypes.length];
        for (int i = 0; i < keyPairsItemTypes.length; i++) {
            if (keyPairsItemTypes[i] == null) {
                throw new RemoteException("describeKeyPairs request is invalid, contains empty element?");
            }
            filterQuery[i] = keyPairsItemTypes[i].getKeyName();
            if (filterQuery[i] == null || filterQuery[i].trim().length() == 0) {
                throw new RemoteException("describeKeyPairs request is invalid, contains empty element?");
            }
        }
    }

    if (filterQuery == null) {
        return this.describeAllPairs(ownerID);
    } else {
        return this.describeSomePairs(ownerID, filterQuery);
    }
}

From source file:org.nimbustools.messaging.gt4_0_elastic.v2008_05_05.security.ServiceSecurityImpl.java

public DeleteKeyPairResponseType deleteKeyPair(DeleteKeyPairType req) throws RemoteException {

    // no use proceeding if these calls fail:
    final Caller caller = this.container.getCaller();
    final String ownerID;
    try {// w  w w  . j  ava 2  s.co  m
        ownerID = this.container.getOwnerID(caller);
    } catch (CannotTranslateException e) {
        throw new RemoteException(e.getMessage(), e);
    }

    if (req == null) {
        throw new RemoteException("deleteKeyPair request is missing");
    }

    final String keyToDelete = req.getKeyName();

    final boolean aKeyWasDeleted = this.sshKeys.removeKey(ownerID, keyToDelete);

    final DeleteKeyPairResponseType dkprt = new DeleteKeyPairResponseType();
    dkprt.set_return(aKeyWasDeleted);
    return dkprt;
}

From source file:org.openmrs.module.dss.impl.DssRmiServiceImpl.java

/**
 * @see//  www.j a v a2 s  .  c  om
 * org.openmrs.module.dss.service.DssRmiService#getPatient(java.lang.String,
 * java.lang.String, java.lang.String)
 */
@Override
public Patient getPatient(String username, String password, String mrn) throws RemoteException {
    Context.openSession();
    try {
        log.info("getPatient RMI service method accessed.");
        authenticate(username, password);
        PatientService patientService = Context.getPatientService();
        List<PatientIdentifierType> types = new ArrayList<PatientIdentifierType>();
        types.add(patientService.getPatientIdentifierTypeByName("MRN_OTHER"));
        List<Patient> patients = patientService.getPatients(null, mrn, types, true);
        if (patients.size() > 0) {
            Patient patient = patients.get(0);
            Hibernate.initialize(patient);
            return patient;
        }

        // Patient not found by MRN.  Try spotting a dash.
        int dashIndex = mrn.indexOf("-");
        if (dashIndex < 0) {
            // Place a dash in the next-to-last character position and ask again.
            int length = mrn.length();
            int position = length - 1;
            if (position >= 0) {
                String firstPart = mrn.substring(0, position);
                String lastPart = mrn.substring(position, length);
                String newMrn = firstPart + "-" + lastPart;
                patients = patientService.getPatients(null, newMrn, types, true);
                if (patients.size() > 0) {
                    Patient patient = patients.get(0);
                    Hibernate.initialize(patient);
                    return patient;
                }
            }
        }

        return null;

    } catch (ContextAuthenticationException e) {
        log.error("Unauthorized access attempted on web service method: getPatient", e);
        throw new RemoteException("Unauthorized access attempted on web service method: getPatient", e);

    } catch (Throwable e) {
        log.error("Error retrieving patient", e);
        throw new RemoteException("Error retrieving patient", e);

    } finally {
        Context.closeSession();
    }
}

From source file:org.openmrs.module.dss.impl.DssRmiServiceImpl.java

/**
 * @see//from ww w. j  av  a  2 s.  c  o m
 * org.openmrs.module.dss.service.DssRmiService#getEncounters(java.lang.String,
 * java.lang.String, org.openmrs.Patient, java.util.Date, java.util.Date)
 */
@Override
public List<Encounter> getEncounters(String username, String password, Patient patient, Date fromDate,
        Date toDate) throws RemoteException {
    Context.openSession();
    try {
        log.info("getEncounters RMI service method accessed.");
        authenticate(username, password);
        List<Encounter> encounters = Context.getEncounterService().getEncounters(patient, null, fromDate,
                toDate, null, null, null, false);
        for (Encounter encounter : encounters) {
            initializeEncounter(encounter);
        }

        return encounters;
    } catch (ContextAuthenticationException e) {
        log.error("Unauthorized access attempted on web service method: getEncounters", e);
        throw new RemoteException("Unauthorized access attempted on web service method: getEncounters", e);
    } catch (Throwable e) {
        log.error("Error retrieving encounters", e);
        throw new RemoteException("Error retrieving encounters", e);
    } finally {
        Context.closeSession();
    }
}

From source file:org.openmrs.module.dss.impl.DssRmiServiceImpl.java

/**
 * @see//from ww  w . j  av  a  2 s. c  o m
 * org.openmrs.module.dss.service.DssRmiService#runRule(java.lang.String,
 * java.lang.String, org.openmrs.Patient, java.lang.String,
 * java.lang.Integer, java.lang.String)
 */
@Override
public Result runRule(String username, String password, Patient patient, String ruleName, Integer encounterId,
        String locationName) throws RemoteException {
    Context.openSession();
    try {
        log.info("runRule RMI service method accessed.");
        authenticate(username, password);
        DssService dssService = Context.getService(DssService.class);
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("mode", "PRODUCE");
        if (encounterId != null) {
            parameters.put("encounterId", encounterId);
        }

        if (locationName != null) {
            Integer locationId = findLocationId(locationName);
            if (locationId != null) {
                parameters.put("locationId", locationId);
            }
        }
        Rule rule = new Rule();
        rule.setTokenName(ruleName);
        rule.setParameters(parameters);
        return dssService.runRule(patient, rule);
    } catch (ContextAuthenticationException e) {
        log.error("Unauthorized access attempted on web service method: runRule", e);
        throw new RemoteException("Unauthorized access attempted on web service method: runRule", e);
    } catch (Throwable e) {
        log.error("Error running rule", e);
        throw new RemoteException("Error running rule", e);
    } finally {
        Context.closeSession();
    }
}

From source file:org.openmrs.module.dss.impl.DssRmiServiceImpl.java

/**
 * @see//from  ww w .  ja va  2  s .c o m
 * org.openmrs.module.dss.service.DssRmiService#getRules(java.lang.String,
 * java.lang.String, java.lang.String)
 */
@Override
public List<Rule> getRules(String username, String password, String ruleNameLike) throws RemoteException {
    Context.openSession();
    List<Rule> rules = new ArrayList<Rule>();
    try {
        log.info("getRules RMI service method accessed.");
        authenticate(username, password);
        // Get the tokens first;
        TokenService tokenService = Context.getService(TokenService.class);
        List<String> tokens = null;
        if (ruleNameLike == null || ruleNameLike.trim().length() == 0) {
            tokens = tokenService.getAllTokens();
        } else {
            tokens = tokenService.getTokens(ruleNameLike);
        }

        DssService dssService = Context.getService(DssService.class);
        // Try to find additional metadata for the token.  MLM rules will have it, Java rules will not.
        for (String token : tokens) {
            Rule rule = new Rule();
            rule.setTokenName(token);
            List<Rule> foundRule = dssService.getRules(rule, false, false, null);
            if (foundRule == null || foundRule.size() == 0) {
                Rule newRule = new Rule();
                newRule.setTokenName(token);
                rules.add(newRule);
            } else {
                Rule newRule = foundRule.get(0);
                rules.add(newRule);
            }
        }
    } catch (ContextAuthenticationException e) {
        log.error("Unauthorized access attempted on web service method: getRules", e);
        throw new RemoteException("Unauthorized access attempted on web service method: getRules", e);
    } catch (Throwable e) {
        log.error("Error querying rules", e);
        throw new RemoteException("Error querying rules", e);
    } finally {
        Context.closeSession();
    }

    return rules;
}

From source file:org.openmrs.module.dss.impl.DssRmiServiceImpl.java

/**
 * @see//from  w w  w. j  av a2 s.co m
 * org.openmrs.module.dss.service.DssRmiService#getPhysicianNote(java.lang.String,
 * java.lang.String, org.openmrs.Patient)
 */
@Override
public String getPhysicianNote(String username, String password, Patient patient) throws RemoteException {
    Context.openSession();
    try {
        log.info("getPhysicianNote RMI service method accessed.");
        authenticate(username, password);
        DssService dssService = Context.getService(DssService.class);
        Map<String, Object> parameters = new HashMap<String, Object>();
        parameters.put("mode", "PRODUCE");
        Rule rule = new Rule();
        rule.setTokenName("PhysicianNote");
        rule.setParameters(parameters);
        Result result = dssService.runRule(patient, rule);
        return result.toString();
    } catch (ContextAuthenticationException e) {
        log.error("Unauthorized access attempted on web service method: getPhysicianNote", e);
        throw new RemoteException("Unauthorized access attempted on web service method: getPhysicianNote", e);
    } catch (Throwable e) {
        log.error("Error building physician note", e);
        throw new RemoteException("Error building physician note", e);
    } finally {
        Context.closeSession();
    }
}