Example usage for java.lang Exception getClass

List of usage examples for java.lang Exception getClass

Introduction

In this page you can find the example usage for java.lang Exception getClass.

Prototype

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

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:com.feilong.tools.net.httpclient3.HttpClientUtil.java

/**
 * HttpMethod./*  w  ww. j  a va  2  s .  com*/
 * 
 * @param httpMethod
 *            httpMethod
 * @param httpClientConfig
 *            the http client config
 * @return the http method response body as string
 * @throws HttpClientException
 *             ?HttpClientUtilException?
 */
private static String getHttpMethodResponseBodyAsString(HttpMethod httpMethod,
        HttpClientConfig httpClientConfig) throws HttpClientException {

    try {
        httpMethod = executeMethod(httpMethod, httpClientConfig);
        //httpMethod.getParams().setContentCharset(charSet);

        // ?getResponseBodybyte?
        // ?getResponseBodyAsStringString?String????String??"?"??
        // ?getResponseBodyAsStream????

        // ?
        String responseBodyAsString = httpMethod.getResponseBodyAsString();

        if (log.isDebugEnabled()) {
            Map<String, Object> map = getHttpMethodResponseAttributeMapForLog(httpMethod, httpClientConfig);
            log.debug("getHttpMethodResponseAttributeMapForLog:{}", JsonUtil.format(map));
        }

        return responseBodyAsString;

    } catch (Exception e) {
        log.error(e.getClass().getName(), e);
        throw new HttpClientException(e);
    } finally {
        // 
        httpMethod.releaseConnection();
    }
}

From source file:com.sunchenbin.store.feilong.core.lang.reflect.FieldUtil.java

/**
 *  (?),key fieldName,value ./*from  w  ww. j  av a 2  s .c  o m*/
 *
 * @param obj
 *            the obj
 * @param excludeFieldNames
 *            ?field names,?nullOrEmpty ?
 * @return the field value map
 * @see #getAllFieldList(Object, String[])
 * @see org.apache.commons.lang3.reflect.MemberUtils#setAccessibleWorkaround(AccessibleObject)
 */
public static Map<String, Object> getAllFieldNameAndValueMap(Object obj, String[] excludeFieldNames) {
    List<Field> fieldList = getAllFieldList(obj, excludeFieldNames);

    if (Validator.isNullOrEmpty(fieldList)) {
        return Collections.emptyMap();
    }
    Map<String, Object> map = new TreeMap<String, Object>();
    for (Field field : fieldList) {
        //XXX see org.apache.commons.lang3.reflect.MemberUtils.setAccessibleWorkaround(AccessibleObject)
        field.setAccessible(true);
        try {
            map.put(field.getName(), field.get(obj));
        } catch (Exception e) {
            LOGGER.error(e.getClass().getName(), e);
            throw new ReflectException(e);
        }
    }
    return map;
}

From source file:com.feilong.tools.net.httpclient3.HttpClientUtil.java

/**
 * ?log.//from   w ww .ja va 2 s .  c o m
 *
 * @param httpMethod
 *            the http method
 * @param httpClientConfig
 *            the http client config
 * @return the http method response attribute map for log
 */
private static Map<String, Object> getHttpMethodResponseAttributeMapForLog(HttpMethod httpMethod,
        HttpClientConfig httpClientConfig) {
    Map<String, Object> map = new LinkedHashMap<String, Object>();

    Object statusCode = null;
    try {
        statusCode = httpMethod.getStatusCode();
    } catch (Exception e) {
        statusCode = e.getClass().getName() + " " + e.getMessage();
    }

    String statusText = null;
    try {
        statusText = httpMethod.getStatusText();
    } catch (Exception e) {
        statusText = e.getClass().getName() + " " + e.getMessage();
    }

    map.put("httpMethod.getRequestHeaders()-->map", NameValuePairUtil.toMap(httpMethod.getRequestHeaders()));

    map.put("httpMethod.getStatusCode()", statusCode);
    map.put("httpMethod.getStatusText()", statusText);
    map.put("httpMethod.getStatusLine()", "" + httpMethod.getStatusLine());

    map.put("httpMethod.getResponseHeaders()-->map", NameValuePairUtil.toMap(httpMethod.getResponseHeaders()));

    map.put("httpMethod.getResponseFooters()", httpMethod.getResponseFooters());
    map.put("httpClientConfig", httpClientConfig);

    return map;
}

From source file:com.clustercontrol.customtrap.util.CustomTrapNotifier.java

/**
 * ?????????/*from   ww  w. ja  v a  2 s .  c om*/
 * 
 * @param customTrap   ???
 * @param monInfo      
 * @param facilityId   ID
 * @param priority      
 * @param agentAddr      Agent
 * @param value         ???
 * @return            ???
 */
private static OutputBasicInfo makeNumMessage(CustomTrap customTrap, MonitorInfo monInfo, String facilityId,
        String agentAddr, int priority, Double value) {
    // Local Variable
    OutputBasicInfo notifyInfo = null;

    notifyInfo = new OutputBasicInfo();
    notifyInfo.setMonitorId(monInfo.getMonitorId());
    notifyInfo.setPluginId(HinemosModuleConstant.MONITOR_CUSTOMTRAP_N);
    notifyInfo.setSubKey(customTrap.getKey());
    notifyInfo.setPriority(priority);
    notifyInfo.setApplication(monInfo.getApplication());
    notifyInfo.setFacilityId(facilityId);

    if (FacilityTreeAttributeConstant.UNREGISTERED_SCOPE.equals(facilityId)) {
        // ?????IP?
        notifyInfo.setScopeText(agentAddr);
    } else {
        // ??]
        try {
            String facilityPath = new RepositoryControllerBean().getFacilityPath(facilityId, null);
            notifyInfo.setScopeText(facilityPath);
        } catch (Exception e) {
            m_log.warn("makeNumMessage() cannot get facility path.(facilityId = " + facilityId + ") : "
                    + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        }
    }

    notifyInfo.setGenerationDate(customTrap.getSampledTime());
    String msg = null;
    if (monInfo.getCustomTrapCheckInfo().getConvertFlg() == ConvertValueConstant.TYPE_DELTA) {
        msg = "DIFF VALUE : " + customTrap.getKey() + "=" + value;
    } else {
        msg = "VALUE : " + customTrap.getKey() + "=" + value;
    }

    notifyInfo.setMessage(msg);
    notifyInfo.setMessageOrg(customTrap.getOrgMsg());
    return notifyInfo;
}

From source file:com.clustercontrol.customtrap.util.CustomTrapNotifier.java

/**
 * ?????????/* w  ww . java  2s.c o m*/
 * 
 * @param customTrap   ???
 * @param monInfo      
 * @param monitorStringValueInfo   
 * @param facilityId   ID
 * @param agentAddr      Agent
 * @param priority      
 * @return            ???
 */
private static OutputBasicInfo makeStringMessage(CustomTrap customTrap, MonitorInfo monInfo,
        MonitorStringValueInfo monitorStringValueInfo, String facilityId, String agentAddr, int priority) {

    OutputBasicInfo output = new OutputBasicInfo();
    output.setMonitorId(monitorStringValueInfo.getMonitorId());
    output.setPluginId(HinemosModuleConstant.MONITOR_CUSTOMTRAP_S);
    output.setFacilityId(facilityId);

    // ????????????
    output.setSubKey(monitorStringValueInfo.getPattern());

    if (FacilityTreeAttributeConstant.UNREGISTERED_SCOPE.equals(facilityId)) {
        // ?????IP?
        output.setScopeText(agentAddr);
    } else {
        // ??]
        try {
            String facilityPath = new RepositoryControllerBean().getFacilityPath(facilityId, null);
            output.setScopeText(facilityPath);
        } catch (Exception e) {
            m_log.warn("makeStringMessage() cannot get facility path.(facilityId = " + facilityId + ") : "
                    + e.getClass().getSimpleName() + ", " + e.getMessage(), e);
        }
    }

    output.setApplication(monInfo.getApplication());

    // ?#[LOG_LINE]??????? ???
    if (monitorStringValueInfo.getMessage() != null) {
        String str = monitorStringValueInfo.getMessage().replace("#[LOG_LINE]", customTrap.getMsg());
        // DB?
        int maxLen = HinemosPropertyUtil.getHinemosPropertyNum("monitor.log.line.max.length", Long.valueOf(256))
                .intValue();
        m_log.info("monitor.log.line.max.length = " + maxLen);
        if (str.length() > maxLen) {
            str = str.substring(0, maxLen);
        }
        output.setMessage(str);
    }

    output.setMessageOrg(customTrap.getOrgMsg());
    output.setPriority(priority);
    output.setGenerationDate(customTrap.getSampledTime());

    return output;
}

From source file:com.bluexml.side.integration.standalone.ApplicationStarter.java

public static Map<String, Object> loadConfiguration(File filePath, String name) {
    Map<String, Object> extractedConfiguration = new HashMap<String, Object>();

    System.out.println("Start Generate with filePath= " + filePath + " & Name: " + name);

    // Create the IFile
    IFile file = null;/*from w  w  w.  ja  v  a  2  s . com*/
    try {
        // IWorkspace ws = ResourcesPlugin.getWorkspace();
        // IProject project= ws.getRoot().getProject("StandAlone");
        // if (!project.exists())
        // project.create(null);
        // if (!project.isOpen())
        // project.open(null);
        // IPath location = new Path(filePath.getAbsolutePath());

        // file = project.getFile(location.lastSegment());

        IWorkspace workspace = ResourcesPlugin.getWorkspace();
        System.out.println("workspace: " + workspace);
        IPath location = Path.fromOSString(filePath.getAbsolutePath());
        System.out.println("location: " + location);
        file = workspace.getRoot().getFileForLocation(location);
        if (file == null)
            file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath.getAbsolutePath()));
        System.out.println("file: " + file);

    } catch (Exception e1) {
        e1.printStackTrace();
    }

    System.out.println("getWorkspace: " + ResourcesPlugin.getWorkspace());
    System.out.println("getRoot: " + ResourcesPlugin.getWorkspace().getRoot().exists() + " -> "
            + ResourcesPlugin.getWorkspace().getRoot());
    System.out.println("getPath: "
            + ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath.getAbsolutePath())));
    if (file == null)
        file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(filePath.getAbsolutePath()));
    if (file == null)
        System.out.println("\tfile is null ");

    System.out.println("\tfile.exists(): " + file.exists());

    URI uri = null;
    System.out.println("\tURI");
    try {

        System.out.println("\tgetRawLocation: " + file.getRawLocation());
        System.out.println("\ttoFile: " + file.getRawLocation().toFile());
        System.out.println("\tpath: " + file.getRawLocation().toFile().getPath());

        String absolutePath = file.getRawLocation().toFile().getAbsolutePath();
        System.out.println("\tabsolutePath: " + absolutePath);

        uri = URI.createFileURI(new File(absolutePath).getAbsolutePath());

        System.out.println("URI: " + uri);

    } catch (Exception e) {
        System.out.println("Exception : " + e.getClass());
    }

    // System.out.println("\tXMI");
    XMIResource resource = new XMIResourceImpl(uri);
    // System.out.println("\tFILE INPUT");

    FileInputStream fi = null;
    try {
        fi = new FileInputStream(file.getRawLocation().toFile());
    } catch (FileNotFoundException e) {
        System.out.println(e.getMessage());
    }

    System.out.println("\tMAP");
    Map<Object, Object> map = new HashMap<Object, Object>();
    map.put(ApplicationPackage.eINSTANCE.getNsURI(), ApplicationPackage.eINSTANCE);
    map.put(XMLResource.OPTION_SCHEMA_LOCATION_IMPLEMENTATION, Boolean.TRUE);

    System.out.println("\tLOAD");
    try {
        resource.load(fi, map);
    } catch (IOException e) {
        System.out.println("Exception  " + e.getMessage());
        e.printStackTrace();
    } catch (Exception e1) {
        System.out.println("Exception  " + e1.getMessage());
        e1.printStackTrace();
    }

    try {
        Application application = (Application) resource.getContents().get(0);
        System.out.println("\tupdateApplicationFile : ");
        ApplicationUtil.updateApplicationFromExtensionPoint(application, file);
        System.out.println("\tapplication: " + application);

        System.out.println("\tstaticParameters: " + ApplicationDialog.staticFieldsName);
        List<Model> models = ApplicationUtil.getModels(application);
        System.out.println("\tmodels: " + models);
        extractedConfiguration.put(MODELS_KEY, models);

        if (name != null) {
            Configuration configuration = application.getConfiguration(name);
            System.out.println("\tconfiguration: " + configuration);
            extractedConfiguration.put(CONFIGURATION_KEY, configuration);
        }

    } catch (java.lang.NullPointerException e) {
        System.out.println("NullPointerException  " + e.getMessage());
        e.printStackTrace();
    } catch (Exception e1) {
        System.out.println("Exception  " + e1.getMessage());
        e1.printStackTrace();
    }
    return extractedConfiguration;
}

From source file:com.amalto.core.objects.DroppedItemPOJO.java

/**
 * find all pks of dropped items/* w  ww  .j  a va 2 s .c  om*/
 */
public static List<DroppedItemPOJOPK> findAllPKs(String regex) throws XtentisException {
    // get XmlServerSLWrapperLocal
    XmlServer server = Util.getXmlServerCtrlLocal();
    if ("".equals(regex) || "*".equals(regex) || ".*".equals(regex)) { //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        regex = null;
    }
    try {
        //retrieve the item
        String[] ids = server.getAllDocumentsUniqueID(MDM_ITEMS_TRASH);
        if (ids == null) {
            return Collections.emptyList();
        }
        //build PKs collection
        List<DroppedItemPOJOPK> list = new ArrayList<DroppedItemPOJOPK>();

        Map<String, ComplexTypeMetadata> conceptMap = new HashMap<String, ComplexTypeMetadata>();
        for (String uid : ids) {
            String[] uidValues = uid.split("\\."); //$NON-NLS-1$
            ItemPOJOPK refItemPOJOPK;
            if (uidValues.length < 3) {
                if (LOGGER.isDebugEnabled()) {
                    LOGGER.debug("Could not read id '" + uid + "'. Skipping it.");
                }
                continue;
            }
            // check xsd key's length
            String uidPrefix = uidValues[0] + "." + uidValues[1] + "."; //$NON-NLS-1$//$NON-NLS-2$
            String[] idArray = Arrays.copyOfRange(uidValues, 2, uidValues.length);
            if (!conceptMap.containsKey(uidPrefix)) {
                MetadataRepository repository = ServerContext.INSTANCE.get().getMetadataRepositoryAdmin()
                        .get(uidValues[0]);
                conceptMap.put(uidPrefix, repository.getComplexType(uidValues[1]));
            }
            if (conceptMap.get(uidPrefix) != null && conceptMap.get(uidPrefix).getKeyFields().size() == 1) {
                idArray = new String[] { StringUtils.removeStart(uid, uidPrefix) };
            }
            refItemPOJOPK = new ItemPOJOPK(new DataClusterPOJOPK(uidValues[0]), uidValues[1], idArray);
            // set revision id as ""
            DroppedItemPOJOPK droppedItemPOJOPK = new DroppedItemPOJOPK(refItemPOJOPK, "/"); //$NON-NLS-1$ //$NON-NLS-2$
            if (regex != null) {
                if (uid.matches(regex)) {
                    list.add(droppedItemPOJOPK);
                }
            } else {
                list.add(droppedItemPOJOPK);
            }
        }
        return list;
    } catch (Exception e) {
        String err = "Unable to find all the identifiers for dropped items " + ": " + e.getClass().getName()
                + ": " + e.getLocalizedMessage();
        LOGGER.error(err, e);
        throw new XtentisException(err, e);
    }
}

From source file:com.sunchenbin.store.feilong.core.bean.BeanUtil.java

/**
 *  {@link BeanUtils#setProperty(Object, String, Object)} ?(<b>?</b>).
 * // ww  w  .  j a v a  2s  .  co  m
 * @param bean
 *            Bean on which setting is to be performed
 * @param propertyName
 *            Property name (can be nested/indexed/mapped/combo)
 * @param value
 *            Value to be set
 * @see org.apache.commons.beanutils.BeanUtils#setProperty(Object, String, Object)
 * 
 * @see org.apache.commons.beanutils.BeanUtilsBean#setProperty(Object, String, Object)
 * 
 * @see org.apache.commons.beanutils.PropertyUtils#setProperty(Object, String, Object)
 * @see com.sunchenbin.store.feilong.core.bean.PropertyUtil#setProperty(Object, String, Object)
 */
public static void setProperty(Object bean, String propertyName, Object value) {
    try {
        // BeanUtils??,???(?)
        BeanUtils.setProperty(bean, propertyName, value);
    } catch (Exception e) {
        LOGGER.error(e.getClass().getName(), e);
        throw new BeanUtilException(e);
    }
}

From source file:com.sunchenbin.store.feilong.core.bean.BeanUtil.java

/**
 * <code>bean</code>?(read method),??/Map.
 * /*  ww  w .  ja va  2 s. c  o m*/
 * <p>
 * ???class,Object??,classjava.lang.Object.
 * </p>
 * <p>
 * <span style="color:red">:<br>
 * ConvertUtils.register(dateTimeConverter, java.util.Date.class)?</span><br>
 * 
 * , {@link BeanUtilsBean#getNestedProperty(Object, String)},  ConvertUtilsBean?? <br>
 *  {@link ConvertUtilsBean#ConvertUtilsBean()}  ?
 * </p>
 *
 * @param bean
 *            Bean whose properties are to be extracted
 * @return Map of property descriptors
 * @see org.apache.commons.beanutils.BeanUtils#describe(Object)
 * @see org.apache.commons.beanutils.PropertyUtils#describe(Object)
 * @see PropertyUtil#describe(Object)
 * @see PropertyDescriptor
 * @see #populate(Object, Map)
 */
public static Map<String, String> describe(Object bean) {
    try {
        //Return the entire set of properties for which the specified bean provides a read method.
        return BeanUtils.describe(bean);
    } catch (Exception e) {
        LOGGER.error(e.getClass().getName(), e);
        throw new BeanUtilException(e);
    }
}

From source file:com.sunchenbin.store.feilong.core.bean.BeanUtil.java

/**
 *  {@link BeanUtils#getProperty(Object, String)} ?.
 *
 * @param bean/*from w  ww.ja  va  2s.com*/
 *            bean
 * @param propertyName
 *            ??
 * @return BeanUtils?
 * @see org.apache.commons.beanutils.BeanUtils#getProperty(Object, String)
 * @see org.apache.commons.beanutils.PropertyUtils#getProperty(Object, String)
 * @see com.sunchenbin.store.feilong.core.bean.PropertyUtil#getProperty(Object, String)
 */
public static String getProperty(Object bean, String propertyName) {
    // Return the value of the specified property of the specified bean,
    // no matter which property reference format is used, as a String.
    try {
        return org.apache.commons.beanutils.BeanUtils.getProperty(bean, propertyName);
    } catch (Exception e) {
        LOGGER.error(e.getClass().getName(), e);
        throw new BeanUtilException(e);
    }
}