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.dchq.docker.volume.driver.adaptor.LocalVolumeAdaptorImpl.java

@Override
public MountResponse path(PathRequest request) {
    MountResponse response = new MountResponse();
    try {//  ww  w . j  a  v a  2 s  .c om
        File directory = new File(TMP_LOC, request.getName());
        if (directory.isDirectory()) {
            response.setMountpoint(FileUtils.getTempDirectoryPath());
        } else {
            response.setErr(String.format("No volume exists with the name [%s]", request.getName()));
        }
    } catch (Exception e) {
        logger.warn(e.getLocalizedMessage(), e);
        response.setErr(e.getLocalizedMessage());
    }
    return response;
}

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

/**
 * Method, where all weatherList are read from server.
 * All heavy lifting is made here.//from  w w w .  ja  v a 2 s  .c  o  m
 *
 * @param params parameters - omitted here
 * @return list of fetched weather
 */
@Override
protected List<Weather> 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_WEATHER + "/" + researchGroupId;

    setState(RUNNING, R.string.working_ws_weather);
    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<WeatherList> response = restTemplate.exchange(url, HttpMethod.GET, entity,
                WeatherList.class);
        WeatherList body = response.getBody();

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

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

From source file:de.fhg.iais.asc.oai.retriever.MetadataFormatsAndSetNamesRetriever.java

/**
 * The list for available sets is downloaded from the OAI-PMH repository
 * /*from   w ww  . j a  v  a 2  s.com*/
 * @return true if stopped by client
 * @throws DbcException
 */
private boolean listSets(ISetConsumer setConsumer) {
    if (setConsumer == null) {
        LOG.error("No HeaderConsumer defined!");
    }

    SetsList list = null;
    try {
        list = this.server.listSets();
    } catch (Exception e) {
        LOG.error(e.getLocalizedMessage(), e);
        this.ascstate.reportProblem(e.getMessage());
    }

    boolean more = list != null && list.size() > 0;
    while (more) {
        for (se.kb.oai.pmh.Set set : list.asList()) {
            if (setConsumer.consume(set.getName(), set.getSpec())) {
                return true;
            }
            if (list.getResumptionToken() == null) {
                more = false;
            } else {
                try {
                    list = this.server.listSets(list.getResumptionToken());
                } catch (Exception e) {
                    LOG.error(e.getLocalizedMessage(), e);
                    this.ascstate.reportProblem(e.getMessage());
                }
            }
        }
    }
    return false;
}

From source file:org.openehealth.coala.transformer.XMLTransformerTest.java

/**
 * Test if the result is correct, if a XML and XSL is given.
 *//*from w  ww. j  av a  2 s.co m*/
@Test
public void testTransformXmlIntoHtmlByXMLyesXSLyesCorrect() {
    try {
        XmlTransformer xmlTransformer = new XmlTransformer(xsltStream);
        String htmlResult = xmlTransformer.transformXmlIntoHtml(xmlString);

        htmlResult = htmlResult.trim();
        htmlResultExpectedUnix = htmlResultExpectedUnix.trim();
        htmlResultExpectedWinows = htmlResultExpectedWinows.trim();

        assertTrue(htmlResult.equals(htmlResultExpectedUnix) || htmlResult.equals(htmlResultExpectedWinows));
    } catch (Exception e) {
        LOG.error(e.getLocalizedMessage(), e);
        fail(e.getLocalizedMessage());
    }
}

From source file:org.metis.jdbc.PreparedStmntCreator.java

private void bindObjects(PreparedStatement ps) throws SQLException {
    // bind the corresponding objects (if any)
    if (bindObs != null) {
        LOG.debug("setValues: binding this many objects " + bindObs.length);
        for (int i = 0; i < bindObs.length; i++) {
            try {
                ps.setObject(i + 1, bindObs[i]);
            } catch (Exception e) {
                String eStr = "setValues: caught this exception [" + e.getLocalizedMessage()
                        + "], when calling setObject for [" + bindObs[i].toString() + "]";
                LOG.error(eStr);//from  ww w  . j  a v  a  2s.co  m
                throw new SQLException(eStr);
            }
        }
    }
    return;
}

From source file:com.dchq.docker.volume.driver.adaptor.LocalVolumeAdaptorImpl.java

@Override
public GetResponse get(GetRequest request) {
    GetResponse response = new GetResponse();
    try {//from www  .j  a  va 2  s. c  om
        File directory = new File(TMP_LOC, request.getName());
        if (directory.isDirectory()) {
            Volume vol = new Volume();
            vol.setName(request.getName());
            vol.getStatus().put("state", "connected");
            vol.setMountpoint(directory.getAbsolutePath());
            response.setVolume(vol);
        } else {
            response.setErr(String.format("No volume exists with the name [%s]", request.getName()));
        }
    } catch (Exception e) {
        logger.warn(e.getLocalizedMessage(), e);
        response.setErr(e.getLocalizedMessage());
    }
    return response;
}

From source file:com.dchq.docker.volume.driver.adaptor.LocalVolumeAdaptorImpl.java

@Override
public ListResponse list() {
    ListResponse response = new ListResponse();
    try {// w  ww . j  a v  a 2  s  .  co m
        File directory = new File(TMP_LOC);
        File[] fList = directory.listFiles();
        for (File file : fList) {
            if (file.isDirectory()) {
                Volume vol = new Volume();
                vol.setName(file.getName());
                vol.getStatus().put("state", "connected");
                vol.setMountpoint(file.getAbsolutePath());
                response.getVolumes().add(vol);
            }
        }
    } catch (Exception e) {
        logger.warn(e.getLocalizedMessage(), e);
        response.setErr(e.getLocalizedMessage());
    }
    return response;
}

From source file:fr.sanofi.fcl4transmart.controllers.listeners.snpData.SetPlatformListener.java

@Override
public void handleEvent(Event event) {
    Vector<String> values = this.ui.getValues();
    Vector<String> samples = this.ui.getSamples();
    File file = new File(this.dataType.getPath().toString() + File.separator
            + this.dataType.getStudy().toString() + ".subject_mapping.tmp");
    File mappingFile = ((SnpData) this.dataType).getMappingFile();
    if (mappingFile == null) {
        this.ui.displayMessage("Error: no subject to sample mapping file");
    }/*from   w  w w  .ja  v a  2 s  .c o  m*/
    try {
        FileWriter fw = new FileWriter(file);
        BufferedWriter out = new BufferedWriter(fw);

        try {
            BufferedReader br = new BufferedReader(new FileReader(mappingFile));
            String line;
            while ((line = br.readLine()) != null) {
                String[] fields = line.split("\t", -1);
                String sample = fields[3];
                String platform;
                if (samples.contains(sample)) {
                    platform = values.get(samples.indexOf(sample));
                } else {
                    br.close();
                    return;
                }
                out.write(fields[0] + "\t" + fields[1] + "\t" + fields[2] + "\t" + sample + "\t" + platform
                        + "\t" + fields[5] + "\t" + fields[6] + "\t" + fields[7] + "\t" + fields[8] + "\n");
            }
            br.close();
        } catch (Exception e) {
            this.ui.displayMessage("Error: " + e.getLocalizedMessage());
            out.close();
            e.printStackTrace();
        }
        out.close();
        try {
            File fileDest;
            if (mappingFile != null) {
                String fileName = mappingFile.getName();
                mappingFile.delete();
                fileDest = new File(this.dataType.getPath() + File.separator + fileName);
            } else {
                fileDest = new File(this.dataType.getPath() + File.separator
                        + this.dataType.getStudy().toString() + ".subject_mapping");
            }
            FileUtils.moveFile(file, fileDest);
            ((SnpData) this.dataType).setMappingFile(fileDest);
        } catch (IOException ioe) {
            this.ui.displayMessage("File error: " + ioe.getLocalizedMessage());
            return;
        }
    } catch (Exception e) {
        this.ui.displayMessage("Error: " + e.getLocalizedMessage());
        e.printStackTrace();
    }
    this.ui.displayMessage("Subject to sample mapping file updated");
    WorkPart.updateSteps();
    WorkPart.updateFiles();
}

From source file:fyp.project.asyncTask.Http_GetPost.java

public void GET(String url, String val) throws IOException {
    String result = "";
    URL url2 = new URL(url + val);
    HttpURLConnection urlConnection = (HttpURLConnection) url2.openConnection();
    int code = urlConnection.getResponseCode();
    try {/*from w w w .j  av  a2 s. co  m*/
        if (code == 404) {
            webpage_output = null;
        } else {
            InputStream in = new BufferedInputStream(urlConnection.getInputStream());
            result = convertInputStreamToString(in);
            webpage_output = result;

        }
    } catch (Exception e) {
        Log.d("InputStream", e.getLocalizedMessage());
    } finally {
        urlConnection.disconnect();
    }

}

From source file:com.difference.historybook.proxy.ProxyTest.java

@Test
public void testChunkedResponseHandling() throws IOException {
    String fileName = "src/test/resources/__files/response.txt";
    Path path = Paths.get(fileName).toAbsolutePath();
    byte[] body = Files.readAllBytes(path);

    stubFor(get(urlEqualTo("/some/page")).willReturn(
            aResponse().withStatus(200).withHeader("Content-Type", "text/html").withBodyFile("response.txt")));

    Proxy proxy = getProxy().setPort(PROXY_PORT);
    try {/*  w w  w.  ja  v  a  2s.com*/
        proxy.start();

        java.net.Proxy proxyServer = new java.net.Proxy(java.net.Proxy.Type.HTTP,
                new InetSocketAddress("127.0.0.1", PROXY_PORT));
        HttpURLConnection connection = (HttpURLConnection) new URL(
                "http://localhost:" + DUMMY_SERVER_PORT + "/some/page").openConnection(proxyServer);

        // The purpose of this test is to test chunked response handling, but there doesn't seem
        // to be an easy way to force this in WireMock (or any of the other tools I looked at)
        // Having it response with the content of a file seems to result in it switching to 
        // chunked responses, but there isn't a reason this needs to be the case.
        // The following test is really testing to make sure this test is still working
        // and forcing chunked mode responses.
        assertEquals("chunked", connection.getHeaderField("Transfer-Encoding"));

        byte[] fetchedContent = IOUtils.toByteArray(connection.getInputStream());
        assertArrayEquals(body, fetchedContent);

        proxy.stop();
    } catch (Exception e) {
        fail(e.getLocalizedMessage());
    }

}