Example usage for java.lang Exception getLocalizedMessage

List of usage examples for java.lang Exception getLocalizedMessage

Introduction

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

Prototype

public String getLocalizedMessage() 

Source Link

Document

Creates a localized description of this throwable.

Usage

From source file:com.ibm.soatf.component.osb.ServiceManager.java

public static boolean changeServiceStatus(String servicetype, boolean status, String serviceURI, String host,
        int port, String username, String password) throws FrameworkExecutionException {

    SessionManagementMBean sm = null;//from ww w  .  jav  a 2 s  .  co  m
    JMXConnector conn = null;
    boolean result = true;
    String statusMsg = "";
    try {
        conn = initConnection(host, port, username, password);
        MBeanServerConnection mbconn = conn.getMBeanServerConnection();
        DomainRuntimeServiceMBean clusterService = (DomainRuntimeServiceMBean) MBeanServerInvocationHandler
                .newProxyInstance(mbconn, new ObjectName(DomainRuntimeServiceMBean.OBJECT_NAME));
        sm = (SessionManagementMBean) clusterService.findService(SessionManagementMBean.NAME,
                SessionManagementMBean.TYPE, null);
        sm.createSession(SESSION_NAME);
        ALSBConfigurationMBean alsbSession = (ALSBConfigurationMBean) clusterService.findService(
                ALSBConfigurationMBean.NAME + "." + SESSION_NAME, ALSBConfigurationMBean.TYPE, null);

        if (servicetype.equals("ProxyService")) {
            Ref ref = constructRef("ProxyService", serviceURI);
            ProxyServiceConfigurationMBean proxyConfigMBean = (ProxyServiceConfigurationMBean) clusterService
                    .findService(ProxyServiceConfigurationMBean.NAME + "." + SESSION_NAME,
                            ProxyServiceConfigurationMBean.TYPE, null);
            if (status) {
                proxyConfigMBean.enableService(ref);
                statusMsg = "Enable the ProxyService : " + serviceURI;
                logger.info(statusMsg);
            } else {
                proxyConfigMBean.disableService(ref);
                statusMsg = "Disable the ProxyService : " + serviceURI;
                logger.info(statusMsg);
            }
        } else if (servicetype.equals("BusinessService")) {
            try {
                Ref ref = constructRef("BusinessService", serviceURI);
                BusinessServiceConfigurationMBean businessConfigMBean = (BusinessServiceConfigurationMBean) clusterService
                        .findService(BusinessServiceConfigurationMBean.NAME + "." + SESSION_NAME,
                                BusinessServiceConfigurationMBean.TYPE, null);
                if (status) {
                    businessConfigMBean.enableService(ref);
                    statusMsg = "Enable the BusinessService : " + serviceURI;
                    logger.info(statusMsg);
                } else {
                    businessConfigMBean.disableService(ref);
                    statusMsg = "Disable the BusinessService : " + serviceURI;
                    logger.info(statusMsg);
                }
            } catch (IllegalArgumentException ex) {
                logger.fatal(ExceptionUtils.getStackTrace(ex));
            }
        }
        sm.activateSession(SESSION_NAME, statusMsg);
        conn.close();
    } catch (Exception ex) {
        if (null != sm) {
            try {
                sm.discardSession(SESSION_NAME);
            } catch (Exception e) {
                logger.debug("Not able to discard the session. " + e.getLocalizedMessage());
                throw new FrameworkExecutionException(e);
            }
        }
        result = false;
        logger.error("Error in MBean Server connection. " + ex.getLocalizedMessage());
        ex.printStackTrace();
    } finally {
        if (null != conn) {
            try {
                conn.close();
            } catch (Exception e) {
                logger.debug("Not able to close the JMX connection. " + e.getLocalizedMessage());
                throw new FrameworkExecutionException(e);

            }
        }
    }

    return result;
}

From source file:com.spoiledmilk.cykelsuperstier.break_rote.STrainData.java

private static boolean hasTrain(int hours, String nightString, String dayString) {
    boolean ret = false;
    int endNight = 24, startNight = 0, endDay = 24, startDay = 0;
    try {/*from  ww w.ja v a  2  s.  c om*/
        String[] splittedNight = nightString.split(" ");
        endNight = Integer.parseInt(splittedNight[0].split("\\.")[0]);
        startNight = Integer.parseInt(splittedNight[1].split("\\.")[0]);
        if (startNight > endNight) {
            int temp = startNight;
            startNight = endNight;
            endNight = temp;
        }
    } catch (Exception e) {
        LOG.e(e.getLocalizedMessage());
    }
    try {
        String[] splittedDay = dayString.split(" ");
        endDay = Integer.parseInt(splittedDay[1].split("\\.")[0]);
        startDay = Integer.parseInt(splittedDay[0].split("\\.")[0]);
        if (startDay > endDay) {
            int temp = startDay;
            startDay = endDay;
            endDay = temp;
        }
    } catch (Exception e) {
        LOG.e(e.getLocalizedMessage());
    }
    if ((hours >= startNight && hours < endNight) || (hours >= startDay && hours < endDay))
        ret = true;
    return ret;
}

From source file:com.lineage.server.model.L1ItemDelay.java

/**
 * /*from w  w  w.  ja v  a2s  .  co  m*/
 * 
 * @param pc
 *            
 * @param item
 *            
 */
public static void onItemUse(final L1PcInstance pc, final L1ItemInstance item) {
    try {
        int delayId = 0;
        int delayTime = 0;
        switch (item.getItem().getType2()) {
        case 0: // ?
            delayId = ((L1EtcItem) item.getItem()).get_delayid();
            delayTime = ((L1EtcItem) item.getItem()).get_delaytime();
            break;

        case 1: // 
            return;

        case 2: // 
            switch (item.getItemId()) {
            case 20077: // ?
            case 120077: // ?? ?
            case 20062: // 

                //  && ???
                if (item.isEquipped() && !pc.isInvisble()) {
                    pc.beginInvisTimer();
                }
                break;

            default: // ?
                return;
            }
            break;
        }

        if ((delayId != 0) && (delayTime != 0)) {
            final ItemDelayTimer timer = new ItemDelayTimer(pc, delayId, delayTime);

            pc.addItemDelay(delayId, timer);
            GeneralThreadPool.getInstance().schedule(timer, delayTime);
        }

    } catch (final Exception e) {
        _log.error(e.getLocalizedMessage(), e);
    }
}

From source file:com.spoiledmilk.ibikecph.util.HttpUtils.java

public static JsonNode getFromServer(String urlString) {
    JsonNode ret = null;/*www . j  a  v  a2s. co m*/
    LOG.d("GET api request, url = " + urlString);
    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, CONNECTON_TIMEOUT);
    HttpConnectionParams.setSoTimeout(myParams, CONNECTON_TIMEOUT);
    HttpClient httpclient = new DefaultHttpClient(myParams);
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Config.USER_AGENT);
    HttpGet httpget = null;
    URL url = null;
    try {

        url = new URL(urlString);
        httpget = new HttpGet(url.toString());
        httpget.setHeader("Content-type", "application/json");
        httpget.setHeader("Accept", ACCEPT);
        httpget.setHeader("LANGUAGE_CODE", IbikeApplication.getLanguageString());
        HttpResponse response = httpclient.execute(httpget);
        String serverResponse = EntityUtils.toString(response.getEntity());
        LOG.d("API response = " + serverResponse);
        ret = Util.stringToJsonNode(serverResponse);
    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null) {
            LOG.e(e.getLocalizedMessage());
        }
    }
    return ret;
}

From source file:com.spoiledmilk.ibikecph.util.HttpUtils.java

public static JsonNode deleteFromServer(String urlString, JSONObject objectToPost) {
    JsonNode ret = null;//from www. jav a2s  .com
    LOG.d("DELETE api request, url = " + urlString);
    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, CONNECTON_TIMEOUT);
    HttpConnectionParams.setSoTimeout(myParams, CONNECTON_TIMEOUT);
    HttpClient httpclient = new DefaultHttpClient(myParams);
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Config.USER_AGENT);
    HTTPDeleteWithBody httpdelete = null;
    URL url = null;
    try {
        url = new URL(urlString);
        httpdelete = new HTTPDeleteWithBody(url.toString());
        httpdelete.setHeader("Content-type", "application/json");
        httpdelete.setHeader("Accept", ACCEPT);
        httpdelete.setHeader("LANGUAGE_CODE", IbikeApplication.getLanguageString());
        StringEntity se = new StringEntity(objectToPost.toString(), HTTP.UTF_8);
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        httpdelete.setEntity(se);
        HttpResponse response = httpclient.execute(httpdelete);
        String serverResponse = EntityUtils.toString(response.getEntity());
        LOG.d("API response = " + serverResponse);
        ret = Util.stringToJsonNode(serverResponse);
    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null)
            LOG.e(e.getLocalizedMessage());
    }
    return ret;
}

From source file:com.spoiledmilk.ibikecph.search.HTTPAutocompleteHandler.java

public static JsonNode performGET(String urlString) {
    JsonNode ret = null;// w  w  w . j a va  2  s. c  om

    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, 20000);
    HttpConnectionParams.setSoTimeout(myParams, 20000);
    HttpClient httpclient = new DefaultHttpClient(myParams);
    HttpGet httpget = null;

    URL url = null;

    try {

        url = new URL(urlString);
        httpget = new HttpGet(url.toString());
        LOG.d("Request " + url.toString());
        httpget.setHeader("Content-type", "application/json");
        HttpResponse response = httpclient.execute(httpget);
        String serverResponse = EntityUtils.toString(response.getEntity());
        LOG.d("Response " + serverResponse);
        ret = Util.stringToJsonNode(serverResponse);

    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null)
            LOG.e(e.getLocalizedMessage());
    }
    return ret;
}

From source file:com.spoiledmilk.ibikecph.util.HttpUtils.java

public static JsonNode postToServer(String urlString, JSONObject objectToPost) {
    JsonNode ret = null;/*w  w  w  .  java2  s. c  o  m*/
    LOG.d("POST api request, url = " + urlString + " object = " + objectToPost.toString());
    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, CONNECTON_TIMEOUT);
    HttpConnectionParams.setSoTimeout(myParams, CONNECTON_TIMEOUT);
    HttpClient httpclient = new DefaultHttpClient(myParams);
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Config.USER_AGENT);
    HttpPost httppost = null;
    URL url = null;
    try {
        url = new URL(urlString);
        httppost = new HttpPost(url.toString());
        httppost.setHeader("Content-type", "application/json");
        httppost.setHeader("Accept", ACCEPT);
        httppost.setHeader("LANGUAGE_CODE", IbikeApplication.getLanguageString());
        StringEntity se = new StringEntity(objectToPost.toString(), HTTP.UTF_8);// , HTTP.UTF_8
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        httppost.setEntity(se);
        HttpResponse response = httpclient.execute(httppost);
        String serverResponse = EntityUtils.toString(response.getEntity());
        LOG.d("API response = " + serverResponse);
        ret = Util.stringToJsonNode(serverResponse);
    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null) {
            LOG.e(e.getLocalizedMessage());
        }
    }
    return ret;
}

From source file:com.spoiledmilk.ibikecph.util.HttpUtils.java

public static JsonNode putToServer(String urlString, JSONObject objectToPost) {
    JsonNode ret = null;/*from  w ww  .j  av a 2  s  .com*/
    LOG.d("PUT api request, url = " + urlString);
    HttpParams myParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(myParams, CONNECTON_TIMEOUT);
    HttpConnectionParams.setSoTimeout(myParams, CONNECTON_TIMEOUT);
    HttpClient httpclient = new DefaultHttpClient(myParams);
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, Config.USER_AGENT);
    HttpPut httput = null;
    URL url = null;
    try {
        url = new URL(urlString);
        httput = new HttpPut(url.toString());
        httput.setHeader("Content-type", "application/json");
        httput.setHeader("Accept", ACCEPT);
        httput.setHeader("LANGUAGE_CODE", IbikeApplication.getLanguageString());
        StringEntity se = new StringEntity(objectToPost.toString(), HTTP.UTF_8);
        se.setContentEncoding(new BasicHeader(HTTP.CONTENT_TYPE, "application/json"));
        httput.setEntity(se);
        HttpResponse response = httpclient.execute(httput);
        String serverResponse = EntityUtils.toString(response.getEntity());
        LOG.d("API response = " + serverResponse);
        ret = Util.stringToJsonNode(serverResponse);
    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null) {
            LOG.e(e.getLocalizedMessage());
        }
    }
    return ret;
}

From source file:Main.java

/**
 * Print the content of the cursor//  w ww .  j av  a2  s.  c  o  m
 *
 * @param cursor, The cursor, which content needs to be printed
 * @param logTag, The log tag
 */
public static void printCursorContent(Cursor cursor, String logTag) {
    if (cursor == null) {
        Log.d(logTag, "Cursor is NULL!");
        return;
    }
    final int columnSpace = 2;
    ArrayList<Integer> columnWidth = new ArrayList<Integer>();
    for (int columnIndex = 0; columnIndex < cursor.getColumnCount(); columnIndex++) {
        String value = cursor.getColumnName(columnIndex);
        int maxWidth = value.length();
        if (cursor.moveToFirst()) {
            do {
                try {
                    value = cursor.getString(columnIndex);
                } catch (Exception e) {
                    value = "BLOB";
                    Log.d(logTag, "Get value from " + cursor.getColumnName(columnIndex) + " failed. Caused by "
                            + e.getLocalizedMessage());
                }
                if (!TextUtils.isEmpty(value) && value.length() > maxWidth) {
                    maxWidth = value.length();
                }
            } while (cursor.moveToNext());
        }
        columnWidth.add(maxWidth + columnSpace);
    }
    ArrayList<ArrayList<String>> tableContent = new ArrayList<ArrayList<String>>();
    for (int columnIndex = 0; columnIndex < cursor.getColumnCount(); columnIndex++) {
        ArrayList<String> columnContent = new ArrayList<String>();
        String value = cursor.getColumnName(columnIndex);
        columnContent.add(appendColumnSpaces(value, columnWidth.get(columnIndex)));
        if (cursor.moveToFirst()) {
            do {
                try {
                    value = cursor.getString(columnIndex);
                } catch (Exception e) {
                    value = "BLOB";
                }
                columnContent.add(appendColumnSpaces(value, columnWidth.get(columnIndex)));
            } while (cursor.moveToNext());
        }
        tableContent.add(columnContent);
    }
    // Including the header
    int maxRowIndex = cursor.getCount() + 1;
    for (int rowIndex = 0; rowIndex < maxRowIndex; rowIndex++) {
        StringBuilder rowValues = new StringBuilder();
        for (int columnIndex = 0; columnIndex < cursor.getColumnCount(); columnIndex++) {
            ArrayList<String> columnValues = tableContent.get(columnIndex);
            rowValues.append(columnValues.get(rowIndex));
        }
        Log.d(logTag, rowValues.toString());
    }
    // set the cursor back the first item
    cursor.moveToFirst();
}

From source file:com.spoiledmilk.ibikecph.search.HTTPAutocompleteHandler.java

public static List<JsonNode> getKortforsyningenPlaces(Location currentLocation, Address address) {
    String urlString;//  w w  w .j  a  v  a 2 s .co  m
    List<JsonNode> list = new ArrayList<JsonNode>();
    if (address.city == null || address.city.equals("")) {
        address.city = address.street;
    }
    try {

        urlString = "http://kortforsyningen.kms.dk/?servicename=RestGeokeys_v2&method=sted&stednavn=" + "*"
                + URLEncoder.encode(address.street, "UTF-8") + "*&geop=" + ""
                + Util.limitDecimalPlaces(currentLocation.getLongitude(), 6) + "," + ""
                + Util.limitDecimalPlaces(currentLocation.getLatitude(), 6)
                + "&georef=EPSG:4326&outgeoref=EPSG:4326&login=ibikecph&password=Spoiledmilk123&hits=10&distinct=true";
        if (address.city != null & !address.city.equals("") && !address.street.equals(address.street)) {
            // urlString = urlString + "&by=" + URLEncoder.encode(address.city.trim(), "UTF-8") + "*";
            // urlString += "&postdist=" + URLEncoder.encode(address.city.trim(), "UTF-8");// + "*";
        }
        JsonNode rootNode = performGET(urlString);
        if (rootNode.has("features")) {
            JsonNode features = rootNode.get("features");
            for (int i = 0; i < features.size(); i++) {
                if (features.get(i).has("properties") && features.get(i).get("properties").has("navn"))
                    list.add(features.get(i));
            }
        }
    } catch (Exception e) {
        if (e != null && e.getLocalizedMessage() != null)
            LOG.e(e.getLocalizedMessage());
    }
    return list;
}