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:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateElectrodeLocation.java

/**
 * Method, where electrode location information is pushed to server in order to create user.
 * All heavy lifting is made here.//from   w  w  w.ja va 2  s . c om
 *
 * @param electrodeLocations only one ElectrodeLocation object is accepted
 * @return information about created electrode location
 */
@Override
protected ElectrodeLocation doInBackground(ElectrodeLocation... electrodeLocations) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_ELECTRODE_LOCATIONS;

    setState(RUNNING, R.string.working_ws_create_electrode_location);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    requestHeaders.setContentType(MediaType.APPLICATION_XML);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    ElectrodeLocation location = electrodeLocations[0];

    try {
        Log.d(TAG, url);

        HttpEntity<ElectrodeLocation> entity = new HttpEntity<ElectrodeLocation>(location, requestHeaders);
        // Make the network request
        return restTemplate.postForObject(url, entity, ElectrodeLocation.class);
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return null;
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateExperiment.java

/**
 * Method, where Experiment information is pushed to server in order to create user.
 * All heavy lifting is made here.//from w  w w . j  a v  a2  s  . co  m
 *
 * @param experiments only one Experiment object is accepted
 * @return information about created experiment
 */
@Override
protected Experiment doInBackground(Experiment... experiments) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_EXPERIMENTS + "create";

    setState(RUNNING, R.string.working_ws_create_experiment);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    requestHeaders.setContentType(MediaType.APPLICATION_XML);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    Experiment experiment = experiments[0];

    try {
        Log.d(TAG, url);

        HttpEntity<Experiment> entity = new HttpEntity<Experiment>(experiment, requestHeaders);
        // Make the network request
        return restTemplate.postForObject(url, entity, Experiment.class);
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return null;
}

From source file:net.sourceforge.mavenhippo.ClassPathBeanFinder.java

private String getJcrType(Annotation annotation) {
    Class<? extends Annotation> nodeAnnotClass = getNodeAnnotationClass();
    try {//from   ww  w.  j av a 2s.  co m
        Method method = nodeAnnotClass.getMethod("jcrType");
        return (String) method.invoke(annotation);
    } catch (Exception e) {
        throw new BeanFinderException(e.getLocalizedMessage(), e);
    }
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreatePerson.java

/**
 * Method, where person information is pushed to server in order to create user.
 * All heavy lifting is made here./*from w  ww  .j a  v a  2s  . c  o  m*/
 *
 * @param persons only one Person object is accepted
 * @return information about created user
 */
@Override
protected Person doInBackground(Person... persons) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_USER + "create";

    setState(RUNNING, R.string.working_ws_create_user);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    requestHeaders.setContentType(MediaType.APPLICATION_XML);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    Person person = persons[0];

    try {
        Log.d(TAG, url);

        HttpEntity<Person> entity = new HttpEntity<Person>(person, requestHeaders);
        // Make the network request
        return restTemplate.postForObject(url, entity, Person.class);
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return null;
}

From source file:ru.altruix.commons.android.WebServiceTaskHelper.java

@Override
public HttpResponse doResponse(final String aUrl) {

    // Use our connection and data timeouts as parameters for our
    // DefaultHttpClient
    HttpClient httpclient = new DefaultHttpClient(getHttpParams());

    HttpResponse response = null;/*from   w w  w .  j  a  va2s.c o m*/

    try {
        switch (taskType) {

        case POST_TASK:
            HttpPost httppost = new HttpPost(aUrl);
            // Add parameters
            httppost.setEntity(new UrlEncodedFormEntity(params));

            response = httpclient.execute(httppost);
            break;
        case GET_TASK:
            HttpGet httpget = new HttpGet(aUrl);
            response = httpclient.execute(httpget);
            break;
        }
    } catch (Exception e) {

        Log.e(TAG, e.getLocalizedMessage(), e);

    }

    return response;
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateReservation.java

/**
 * Method, where reservation information is pushed to server in order to create reservation record.
 * All heavy lifting is made here./*www  .ja va  2s  .  c o  m*/
 *
 * @param params only one reservation instance is allowed here - reservation to be created
 * @return object of created reservation if any
 */
@Override
protected Reservation doInBackground(Reservation... params) {

    Reservation data = params[0];
    try {

        setState(RUNNING, R.string.working_ws_create);

        SharedPreferences credentials = getCredentials();
        String username = credentials.getString("username", null);
        String password = credentials.getString("password", null);
        String url = credentials.getString("url", null) + Values.SERVICE_RESERVATION;

        //set HTTP connection
        HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setAuthorization(authHeader);
        requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
        requestHeaders.setContentType(MediaType.APPLICATION_XML);
        HttpEntity<Reservation> entity = new HttpEntity<Reservation>(data, requestHeaders);

        SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
        // Create a new RestTemplate instance
        RestTemplate restTemplate = new RestTemplate(factory);
        restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

        Log.d(TAG, url);
        ResponseEntity<Reservation> dataEntity = restTemplate.postForEntity(url, entity, Reservation.class);
        return dataEntity.getBody();
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage());
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return null;
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.CreateWeather.java

/**
 * Method, where Weather information is pushed to server in order to create user.
 * All heavy lifting is made here.//  w  w w  .j  a  va  2  s  .  c o m
 *
 * @param weathers only one Weather object is accepted
 * @return information about created weather
 */
@Override
protected Weather doInBackground(Weather... weathers) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_WEATHER + "/" + researchGroupId;

    setState(RUNNING, R.string.working_ws_create_weather);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    requestHeaders.setContentType(MediaType.APPLICATION_XML);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    Weather weather = weathers[0];

    try {
        Log.d(TAG, url);

        HttpEntity<Weather> entity = new HttpEntity<Weather>(weather, requestHeaders);
        // Make the network request
        return restTemplate.postForObject(url, entity, Weather.class);
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return null;
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchResearchGroups.java

/**
 * Method, where all research groups are read from server.
 * All heavy lifting is made here.//  w ww .  j  a  va 2s  .co  m
 *
 * @param params omitted here
 * @return list of fetched research groups
 */
@Override
protected List<ResearchGroup> doInBackground(Void... params) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_RESEARCH_GROUPS + qualifier;

    setState(RUNNING, R.string.working_ws_groups);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));
    HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders);

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter());

    try {
        // Make the network request
        Log.d(TAG, url);
        ResponseEntity<ResearchGroupList> response = restTemplate.exchange(url, HttpMethod.GET, entity,
                ResearchGroupList.class);
        ResearchGroupList body = response.getBody();

        if (body != null) {
            return body.getGroups();
        }

    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return Collections.emptyList();
}

From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.UploadDataFile.java

/**
 * Method, where data file information is pushed to server in order to create data file record.
 * All heavy lifting is made here.//from  ww w .j  av a 2  s .c  o  m
 *
 * @param dataFileContents must be three params in order - experiment id, description, path to file
 * @return URI of uploaded file
 */
@Override
protected URI doInBackground(String... dataFileContents) {
    SharedPreferences credentials = getCredentials();
    String username = credentials.getString("username", null);
    String password = credentials.getString("password", null);
    String url = credentials.getString("url", null) + Values.SERVICE_DATAFILE;

    setState(RUNNING, R.string.working_ws_upload_data_file);
    HttpAuthentication authHeader = new HttpBasicAuthentication(username, password);
    HttpHeaders requestHeaders = new HttpHeaders();
    requestHeaders.setAuthorization(authHeader);
    requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML));

    SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory();
    //so files wont buffer in memory
    factory.setBufferRequestBody(false);
    // Create a new RestTemplate instance
    RestTemplate restTemplate = new RestTemplate(factory);
    restTemplate.getMessageConverters().add(new StringHttpMessageConverter());
    restTemplate.getMessageConverters().add(new FormHttpMessageConverter());

    try {
        Log.d(TAG, url);
        FileSystemResource toBeUploadedFile = new FileSystemResource(dataFileContents[2]);
        MultiValueMap<String, Object> form = new LinkedMultiValueMap<String, Object>();
        form.add("experimentId", dataFileContents[0]);
        form.add("description", dataFileContents[1]);
        form.add("file", toBeUploadedFile);

        HttpEntity<Object> entity = new HttpEntity<Object>(form, requestHeaders);
        // Make the network request
        return restTemplate.postForLocation(url, entity);
    } catch (Exception e) {
        Log.e(TAG, e.getLocalizedMessage(), e);
        setState(ERROR, e);
    } finally {
        setState(DONE);
    }
    return null;
}

From source file:com.kylinolap.job.hadoop.invertedindex.InvertedIndexJob.java

@Override
public int run(String[] args) throws Exception {
    Options options = new Options();

    try {//from  ww w.jav a2s.co m
        options.addOption(OPTION_JOB_NAME);
        options.addOption(OPTION_CUBE_NAME);
        options.addOption(OPTION_INPUT_PATH);
        options.addOption(OPTION_INPUT_FORMAT);
        options.addOption(OPTION_INPUT_DELIM);
        options.addOption(OPTION_OUTPUT_PATH);
        parseOptions(options, args);

        job = Job.getInstance(getConf(), getOptionValue(OPTION_JOB_NAME));
        String cubeName = getOptionValue(OPTION_CUBE_NAME);
        Path input = new Path(getOptionValue(OPTION_INPUT_PATH));
        String inputFormat = getOptionValue(OPTION_INPUT_FORMAT);
        String inputDelim = getOptionValue(OPTION_INPUT_DELIM);
        Path output = new Path(getOptionValue(OPTION_OUTPUT_PATH));

        // ----------------------------------------------------------------------------

        System.out.println("Starting: " + job.getJobName());

        setupMapInput(input, inputFormat, inputDelim);
        setupReduceOutput(output);
        attachMetadata(cubeName);

        return waitForCompletion(job);

    } catch (Exception e) {
        printUsage(options);
        log.error(e.getLocalizedMessage(), e);
        return 2;
    }

}