Example usage for java.lang NullPointerException getMessage

List of usage examples for java.lang NullPointerException getMessage

Introduction

In this page you can find the example usage for java.lang NullPointerException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:org.wso2.carbon.apimgt.impl.utils.APIDescriptionGenUtil.java

/**
 * This method gives the allowed request count for a minute
 *
 * @param policy The tier level policy//  w w w.  java2  s . c o  m
 * @return The request count for a minute((maxCount * 60000)/timeDuration)
 * @throws APIManagementException if policy or parsing error occurs
 */
public static long getAllowedCountPerMinute(OMElement policy) throws APIManagementException {
    //Here as the method is about extracting some info from the policy. And it's not concern on compliance to
    // specification. So it just extract the required element.
    OMElement maxCount;
    OMElement timeUnit;
    long requestPerMinute;
    try {
        maxCount = policy.getFirstChildWithName(APIConstants.POLICY_ELEMENT)
                .getFirstChildWithName(APIConstants.THROTTLE_CONTROL_ELEMENT)
                .getFirstChildWithName(APIConstants.POLICY_ELEMENT)
                .getFirstChildWithName(APIConstants.THROTTLE_MAXIMUM_COUNT_ELEMENT);
        timeUnit = policy.getFirstChildWithName(APIConstants.POLICY_ELEMENT)
                .getFirstChildWithName(APIConstants.THROTTLE_CONTROL_ELEMENT)
                .getFirstChildWithName(APIConstants.POLICY_ELEMENT)
                .getFirstChildWithName(APIConstants.THROTTLE_UNIT_TIME_ELEMENT);
        //Here we will assume time unit provided as milli second and do calculation to get requests per minute.
        if (maxCount.getText().isEmpty() || timeUnit.getText().isEmpty()) {
            String errorMessage = APIConstants.THROTTLE_MAXIMUM_COUNT_ELEMENT + "or"
                    + APIConstants.THROTTLE_UNIT_TIME_ELEMENT + " element data found empty in " + "the policy.";
            log.warn(errorMessage);
            throw new APIManagementException(errorMessage);
        }
        return (Long.parseLong(maxCount.getText().trim()) * 60000)
                / (Long.parseLong(timeUnit.getText().trim()));
    } catch (NullPointerException e) {
        String errorMessage = "Policy could not be parsed correctly based on "
                + "http://schemas.xmlsoap.org/ws/2004/09/policy specification";
        log.error(errorMessage, e);
        throw new APIManagementException(errorMessage + e.getMessage());
    }
}

From source file:org.wso2.carbon.apimgt.impl.utils.APIDescriptionGenUtil.java

/**
 * The method to extract the tier attributes from each tier level policy definitions
 * @param policy  Tier level policy/*from  w w  w  .j av a 2 s. co m*/
 * @return Attributes map
 * @throws APIManagementException
 */
public static Map<String, Object> getTierAttributes(OMElement policy) throws APIManagementException {
    Map<String, Object> attributesMap = new HashMap<String, Object>();
    OMElement attributes = null;

    try {
        OMElement tier = policy.getFirstChildWithName(APIConstants.POLICY_ELEMENT)
                .getFirstChildWithName(APIConstants.THROTTLE_CONTROL_ELEMENT)
                .getFirstChildWithName(APIConstants.POLICY_ELEMENT)
                .getFirstChildWithName(APIConstants.POLICY_ELEMENT);
        if (tier != null) {
            attributes = tier.getFirstChildWithName(APIConstants.THROTTLE_ATTRIBUTES_ELEMENT);
        }
        if (attributes == null) {
            return attributesMap;
        } else {
            for (Iterator childElements = attributes.getChildElements(); childElements.hasNext();) {
                OMElement element = (OMElement) childElements.next();
                String displayName = element
                        .getAttributeValue(new QName(APIConstants.THROTTLE_ATTRIBUTE_DISPLAY_NAME));
                String localName = element.getLocalName();
                String attrName = (displayName != null ? displayName : localName); //If displayName not defined,
                // use the attribute name
                String attrValue = element.getText();
                attributesMap.put(attrName, attrValue);
            }
        }
    } catch (NullPointerException e) {
        String errorMessage = "Policy could not be parsed correctly based on "
                + "http://schemas.xmlsoap.org/ws/2004/09/policy specification";
        log.error(errorMessage, e);
        throw new APIManagementException(errorMessage + e.getMessage());
    }
    return attributesMap;
}

From source file:com.brewcrewfoo.performance.util.Helpers.java

public static boolean checkSu() {
    if (!new File("/system/bin/su").exists() && !new File("/system/xbin/su").exists()) {
        Log.e(TAG, " su does not exist!!!");
        return false; // tell caller to bail...
    }//from w ww  .ja  va2s.c om
    try {
        if ((new CMDProcessor().su.runWaitFor("ls /data/app-private")).success()) {
            //if ((new CMDProcessor().su.runWaitFor("su -c id")).success()) {
            Log.i(TAG, " SU exists and we have permission");
            return true;
        } else {
            Log.i(TAG, " SU exists but we dont have permission");
            return false;
        }
    } catch (final NullPointerException e) {
        Log.e(TAG, e.getMessage());
        return false;
    }
}

From source file:finale.year.stage.utility.Util.java

public static boolean fileExists(File f) {
    f = new File("config.txt");
    try {/*www  .  jav a2s. c om*/
        if (f.exists())
            return true;

    } catch (NullPointerException e) {
        Authentification.updateStatus(e.getMessage());
        return false;
    }
    return false;
}

From source file:dentex.youtube.downloader.YTD.java

public static void removeIdUpdateNotification(long id) {
    try {/*from  ww w  . j  a v  a 2s  . c o m*/
        if (id != 0) {
            if (sequence.remove(id)) {
                Utils.logger("d", "ID " + id + " REMOVED from Notification", DEBUG_TAG);
            } else {
                Utils.logger("d", "ID " + id + " Already REMOVED from Notification", DEBUG_TAG);
            }
        } else {
            Utils.logger("w", "ID  not found!", DEBUG_TAG);
        }

        Utils.setNotificationDefaults(mBuilder);

        if (sequence.size() > 0) {
            mBuilder.setContentText(pt1 + " " + sequence.size() + " " + pt2).setOngoing(true);
            mNotificationManager.notify(1, mBuilder.build());
        } else {
            mBuilder.setContentText(ctx.getString(R.string.notification_no_downloads)).setOngoing(false);
            mNotificationManager.notify(1, mBuilder.build());
            Utils.logger("d", "No downloads in progress.", DEBUG_TAG);
        }
    } catch (NullPointerException e) {
        Log.e(DEBUG_TAG, "NPE at removeIdUpdateNotification: " + e.getMessage());
        BugSenseHandler.sendExceptionMessage("NPE at removeIdUpdateNotification", e.getMessage(), e);
    }
}

From source file:com.servioticy.api.commons.data.CouchBase.java

/**
 * @param key//from w w w  .  ja  v a  2s  . c o  m
 * @return JsonNode that represents the stored document
 */
public static JsonNode getJsonNode(String key) {
    ObjectMapper mapper = new ObjectMapper();
    //    JsonNode json = mapper.createObjectNode();
    JsonNode json;
    try {
        json = mapper.readTree((String) cli_so.get(key));
    } catch (NullPointerException e) {
        return null;
    } catch (Exception e) {
        LOG.error(e);
        throw new ServIoTWebApplicationException(Response.Status.INTERNAL_SERVER_ERROR, e.getMessage());
    }

    if (json != null) {
        return json;
    }
    return null;

}

From source file:mx.klozz.xperience.tweaker.helpers.Helpers.java

public static boolean checkSu() {
    if (!new File("/system/bin/su").exists() && !new File("/system/xbin/su").exists()) {
        Log.e(TAG, "SU Does not exist");
        return false;
    }/*from w w  w  . ja  v  a 2s .c  om*/
    try {
        if ((new CMDProcessor().su.runWaitFor("ls /data/app-private")).success()) {
            Log.d(TAG, "SU Exist and We Have Permissions");
            return true;
        } else {
            Log.i(TAG, "SU Exist but We Don't Have Permissions");
            return false;
        }
    } catch (final NullPointerException e) {
        Log.e(TAG, e.getMessage());
        return false;
    }
}

From source file:com.android.settings.util.Helpers2.java

/**
 * Checks to see if Busybox is installed in "/system/"
 *
 * @return If busybox exists/*from   w w w. java 2s. c om*/
 */
public static boolean checkBusybox() {
    if (!new File("/system/bin/busybox").exists() && !new File("/system/xbin/busybox").exists()) {
        Log.e(TAG, "Busybox not in xbin or bin!");
        return false;
    }
    try {
        if (!new CMDProcessor2().su.runWaitFor("busybox mount").success()) {
            Log.e(TAG, " Busybox is there but it is borked! ");
            return false;
        }
    } catch (final NullPointerException e) {
        Log.e(TAG, e.getMessage());
        return false;
    }
    return true;
}

From source file:com.android.settings.util.Helpers2.java

/**
 * Checks device for SuperUser permission
 *
 * @return If SU was granted or denied/*from   w w  w . j ava 2s . com*/
 */
public static boolean checkSu() {
    if (!new File("/system/bin/su").exists() && !new File("/system/xbin/su").exists()) {
        Log.e(TAG, "su does not exist!!!");
        return false; // tell caller to bail...
    }
    try {
        if ((new CMDProcessor2().su.runWaitFor("ls /data/app-private")).success()) {
            Log.i(TAG, " SU exists and we have permission");
            return true;
        } else {
            Log.i(TAG, " SU exists but we dont have permission");
            return false;
        }
    } catch (final NullPointerException e) {
        Log.e(TAG, e.getMessage());
        return false;
    }
}

From source file:org.openmrs.module.fhir.api.util.FHIRObsUtil.java

public static Obs generateOpenMRSObs(Observation observation, List<String> errors) {
    Obs obs = new Obs();
    obs.setComment(observation.getComments());
    if (observation.getSubject() != null) {
        ResourceReferenceDt subjectref = observation.getSubject();
        IdDt id = subjectref.getReference();
        String patientUuid = id.getIdPart();
        org.openmrs.Person person = Context.getPersonService().getPersonByUuid(patientUuid);
        if (person == null) {
            errors.add("There is no person for the given uuid");
        } else {//from w  w w . ja v  a 2 s  .  c om
            obs.setPerson(person);
        }
    } else {
        errors.add("Subject cannot be empty");
    }

    Date dateApplies = observation.getIssued();
    if (dateApplies == null) {
        errors.add("Observation DateTime cannot be empty");
    } else {
        obs.setObsDatetime(dateApplies);
    }

    Date instant = observation.getIssued();
    obs.setDateCreated(instant);

    String conceptCode = null;
    String system = null;
    Concept concept = null;
    List<CodingDt> dts = null;
    try {
        CodeableConceptDt dt = observation.getCode();
        dts = dt.getCoding();
    } catch (NullPointerException e) {
        errors.add("Code cannot be empty");
        log.error("Code cannot be empty " + e.getMessage());
    }

    for (CodingDt cding : dts) {
        conceptCode = cding.getCode();
        system = cding.getSystem();
        if (FHIRConstants.OPENMRS_URI.equals(system)) {
            concept = Context.getConceptService().getConceptByUuid(conceptCode);
        } else {
            String systemName = FHIRConstants.conceptSourceURINameMap.get(system);
            if (systemName != null && !systemName.isEmpty()) {
                concept = Context.getConceptService().getConceptByMapping(conceptCode, systemName);
            }
        }
        if (concept != null) {
            break;
        }
    }
    if (concept == null) {
        errors.add("No matching concept found for the given codings");
    } else {
        obs.setConcept(concept);
    }

    if (concept != null) {
        if (observation.getValue() == null) {
            errors.add("Obs set value cannot be empty");
        } else {
            if (concept.isNumeric()) {
                QuantityDt quantity = (QuantityDt) observation.getValue();
                BigDecimal bd = quantity.getValue();
                double doubleValue = bd.doubleValue();
                obs.setValueNumeric(doubleValue);
            } else if (FHIRConstants.ST_HL7_ABBREVATION
                    .equalsIgnoreCase(concept.getDatatype().getHl7Abbreviation())) {
                StringDt value = (StringDt) observation.getValue();
                try {
                    obs.setValueAsString(value.getValue());
                } catch (ParseException e) {
                    errors.add("Obs set value failed");
                    log.error("Obs set value failed " + e.getMessage());
                }
            } else if (FHIRConstants.BIT_HL7_ABBREVATION
                    .equalsIgnoreCase(concept.getDatatype().getHl7Abbreviation())) {
                CodeableConceptDt codeableConceptDt = (CodeableConceptDt) observation.getValue();
                try {
                    List<CodingDt> codingDts = codeableConceptDt.getCoding();
                    CodingDt codingDt2 = codingDts.get(0);
                    boolean booleanValue = Boolean.parseBoolean(codingDt2.getCode());
                    obs.setValueBoolean(booleanValue);
                } catch (NullPointerException e) {
                    errors.add("Setting valueBoolean failed");
                    log.error("Setting valueBoolean failed " + e.getMessage());
                }
            } else if (FHIRConstants.TS_HL7_ABBREVATION
                    .equalsIgnoreCase(concept.getDatatype().getHl7Abbreviation())) {
                PeriodDt datetime = (PeriodDt) observation.getValue();
                obs.setValueDatetime(datetime.getStart());

            } else if (FHIRConstants.DT_HL7_ABBREVATION
                    .equalsIgnoreCase(concept.getDatatype().getHl7Abbreviation())) {
                PeriodDt datetime = (PeriodDt) observation.getValue();
                obs.setValueDate(datetime.getStart());
            } else if (FHIRConstants.ED_HL7_ABBREVATION
                    .equalsIgnoreCase(concept.getDatatype().getHl7Abbreviation())) {
                AttachmentDt attachmentDt = (AttachmentDt) observation.getValue();
                byte[] byteStream = attachmentDt.getData();
                ComplexData data = new ComplexData("images.JPEG", byteStream);
                obs.setValueComplex(byteStream.toString());
                obs.setComplexData(data);
            }
        }
    }

    if (observation.getEncounter() != null && !observation.getEncounter().isEmpty()) {
        ResourceReferenceDt encounter = observation.getEncounter();
        IdDt ref = encounter.getReference();
        if (ref != null) {
            String encounterUuid = ref.getIdPart();
            obs.setEncounter(Context.getEncounterService().getEncounterByUuid(encounterUuid));
        }
    }
    return obs;
}