List of usage examples for java.io IOException getLocalizedMessage
public String getLocalizedMessage()
From source file:ca.phon.plugins.praat.export.TextGridExportWizard.java
public Session getSession() { Session retVal = this.session; if (retVal == null) { final List<SessionPath> selectedSessions = sessionSelector.getSelectedSessions(); if (selectedSessions.size() > 0) { final SessionPath loc = selectedSessions.get(0); try { retVal = getProject().openSession(loc.getCorpus(), loc.getSession()); } catch (IOException e) { LOGGER.log(Level.SEVERE, e.getLocalizedMessage(), e); }//from ww w .jav a 2 s .c o m } } return retVal; }
From source file:com.jaspersoft.jasperserver.rest.services.RESTResource.java
/** * The PUT service is used to create a new resource in the repository... * * @param req//w w w .j av a 2 s . c om * @param resp * @throws ServiceException */ @Override protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { HttpServletRequest mreq = restUtils.extractAttachments(runReportService, req); String resourceDescriptorXml = null; // get the resource descriptor... if (mreq instanceof MultipartHttpServletRequest) { resourceDescriptorXml = mreq.getParameter(restUtils.REQUEST_PARAMENTER_RD); } else { try { resourceDescriptorXml = IOUtils.toString(req.getInputStream()); } catch (IOException ex) { throw new ServiceException(ServiceException.INTERNAL_SERVER_ERROR, ex.getLocalizedMessage()); } } if (resourceDescriptorXml == null) { restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, "Missing parameter " + restUtils.REQUEST_PARAMENTER_RD + " " + runReportService.getInputAttachments()); return; } // Parse the resource descriptor... InputSource is = new InputSource(new StringReader(resourceDescriptorXml)); Document doc = null; ResourceDescriptor rd = null; try { doc = XMLUtil.getNewDocumentBuilder().parse(is); rd = Unmarshaller.readResourceDescriptor(doc.getDocumentElement()); if (log.isDebugEnabled()) { log.debug("resource descriptor was created successfully for: " + rd.getUriString()); } // we force the rd to be new... rd.setIsNew(true); ResourceDescriptor createdRd = resourcesManagementRemoteService.putResource(rd); Marshaller m = new Marshaller(); String xml = m.writeResourceDescriptor(createdRd); // send the xml... restUtils.setStatusAndBody(HttpServletResponse.SC_CREATED, resp, ""); } catch (SAXException ex) { log.error("Unexpected error during resource descriptor marshaling: " + ex.getMessage(), ex); restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, "Invalid resource descriptor"); } catch (ServiceException ex) { throw ex; } catch (Exception ex) { log.error("Unexpected error during resource save: " + ex.getMessage(), ex); throw new ServiceException(ServiceException.INTERNAL_SERVER_ERROR, ex.getLocalizedMessage()); } }
From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.RemoveRawFileListener.java
@Override public void handleEvent(Event event) { Vector<File> files = this.selectRawFilesUI.getSelectedRemovedFile(); File cmf = ((ClinicalData) this.dataType).getCMF(); File wmf = ((ClinicalData) this.dataType).getWMF(); boolean confirm = this.selectRawFilesUI.confirm( "The column mapping file and the word mapping file will be updated or removed consequently.\nAre you sure to remove these files?"); for (File file : files) { if (file == null) { return; }/*from w w w . j a v a 2s . co m*/ if (((ClinicalData) this.dataType).getRawFiles().size() == files.size()) { if (cmf != null || wmf != null) { if (confirm) { if (cmf != null) { ((ClinicalData) this.dataType).setCMF(null); try { FileUtils.forceDelete(cmf); } catch (IOException e) { // TODO Auto-generated catch block this.selectRawFilesUI.displayMessage("File error: " + e.getLocalizedMessage()); e.printStackTrace(); } } if (wmf != null) { ((ClinicalData) this.dataType).setWMF(null); try { FileUtils.forceDelete(wmf); } catch (IOException e) { // TODO Auto-generated catch block this.selectRawFilesUI.displayMessage("File error: " + e.getLocalizedMessage()); e.printStackTrace(); } } ((ClinicalData) this.dataType).getRawFiles().remove(file); FileUtils.deleteQuietly(file); UsedFilesPart.sendFilesChanged(dataType); } } else { if (confirm) { ((ClinicalData) this.dataType).getRawFiles().remove(file); FileUtils.deleteQuietly(file); UsedFilesPart.sendFilesChanged(dataType); } } } else {//several raw files: update cmf and wmf to remove lines for this raw file if (cmf != null || wmf != null) { if (confirm) { if (cmf != null) { File newCmf = new File(this.dataType.getPath().toString() + File.separator + this.dataType.getStudy().toString() + ".columns.tmp"); try { FileWriter fw = new FileWriter(newCmf); BufferedWriter out = new BufferedWriter(fw); try { BufferedReader br = new BufferedReader(new FileReader(cmf)); String line; while ((line = br.readLine()) != null) { if (line.split("\t", -1)[0].compareTo(file.getName()) != 0) { out.write(line + "\n"); } } br.close(); } catch (Exception e) { this.selectRawFilesUI.displayMessage("File error: " + e.getLocalizedMessage()); e.printStackTrace(); out.close(); } out.close(); String fileName = cmf.getName(); FileUtils.deleteQuietly(cmf); try { File fileDest = new File(this.dataType.getPath() + File.separator + fileName); FileUtils.moveFile(newCmf, fileDest); ((ClinicalData) this.dataType).setCMF(fileDest); } catch (Exception ioe) { this.selectRawFilesUI .displayMessage("File error: " + ioe.getLocalizedMessage()); return; } } catch (Exception e) { this.selectRawFilesUI.displayMessage("Error: " + e.getLocalizedMessage()); e.printStackTrace(); } } if (wmf != null) { File newWmf = new File(this.dataType.getPath().toString() + File.separator + this.dataType.getStudy().toString() + ".words.tmp"); try { FileWriter fw = new FileWriter(newWmf); BufferedWriter out = new BufferedWriter(fw); try { BufferedReader br = new BufferedReader(new FileReader(wmf)); String line; while ((line = br.readLine()) != null) { if (line.split("\t", -1)[0].compareTo(file.getName()) != 0) { out.write(line + "\n"); } } br.close(); } catch (Exception e) { this.selectRawFilesUI.displayMessage("Error: " + e.getLocalizedMessage()); e.printStackTrace(); out.close(); } out.close(); String fileName = wmf.getName(); FileUtils.deleteQuietly(wmf); try { File fileDest = new File(this.dataType.getPath() + File.separator + fileName); FileUtils.moveFile(newWmf, fileDest); ((ClinicalData) this.dataType).setWMF(fileDest); } catch (Exception ioe) { this.selectRawFilesUI .displayMessage("File error: " + ioe.getLocalizedMessage()); return; } } catch (Exception e) { this.selectRawFilesUI.displayMessage("Error: " + e.getLocalizedMessage()); e.printStackTrace(); } } ((ClinicalData) this.dataType).getRawFiles().remove(file); FileUtils.deleteQuietly(file); UsedFilesPart.sendFilesChanged(dataType); } } else { if (confirm) { ((ClinicalData) this.dataType).getRawFiles().remove(file); FileUtils.deleteQuietly(file); UsedFilesPart.sendFilesChanged(dataType); } } } } this.selectRawFilesUI.updateViewer(); WorkPart.updateSteps(); WorkPart.updateFiles(); }
From source file:com.jaspersoft.jasperserver.rest.services.RESTResource.java
/** * POST can be used to modify a resource or to copy/move it. * * @param req/* www .ja v a 2 s . c o m*/ * @param resp * @throws ServiceException */ @Override protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServiceException { String sourceURI = restUtils.extractRepositoryUri(req.getPathInfo()); String destURI = restUtils.getDetinationUri(req); if (destURI != null) { if (req.getParameterMap().containsKey(restUtils.REQUEST_PARAMENTER_COPY_TO)) resourcesManagementRemoteService.copyResource(sourceURI, destURI); else resourcesManagementRemoteService.moveResource(sourceURI, destURI); } else // Modify the resource... { HttpServletRequest mreq = restUtils.extractAttachments(runReportService, req); String resourceDescriptorXml = null; // get the resource descriptor... if (mreq instanceof MultipartHttpServletRequest) resourceDescriptorXml = mreq.getParameter(restUtils.REQUEST_PARAMENTER_RD); else { try { resourceDescriptorXml = IOUtils.toString(req.getInputStream()); } catch (IOException ex) { throw new ServiceException(ServiceException.INTERNAL_SERVER_ERROR, ex.getLocalizedMessage()); } } if (resourceDescriptorXml == null) { String msg = "Missing parameter " + restUtils.REQUEST_PARAMENTER_RD + " " + runReportService.getInputAttachments(); restUtils.setStatusAndBody(HttpServletResponse.SC_BAD_REQUEST, resp, msg); throw new ServiceException(ServiceException.INTERNAL_SERVER_ERROR, msg); } // Parse the resource descriptor... InputSource is = new InputSource(new StringReader(resourceDescriptorXml)); Document doc = null; ResourceDescriptor rd = null; try { doc = XMLUtil.getNewDocumentBuilder().parse(is); rd = Unmarshaller.readResourceDescriptor(doc.getDocumentElement()); // we force the rd to be new... rd.setIsNew(false); if (rd.getUriString() == null || !rd.getUriString().equals(sourceURI)) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, "Request URI and descriptor URI are not equals"); } resourcesManagementRemoteService.updateResource(sourceURI, rd, true); restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, ""); } catch (SAXException ex) { log.error("error parsing...", ex); throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, ex.getMessage()); } catch (ServiceException ex) { log.error("error executing the service...", ex); throw ex; } catch (ParserConfigurationException e) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } catch (IOException e) { throw new ServiceException(HttpServletResponse.SC_BAD_REQUEST, e.getMessage()); } } }
From source file:com.alphabetbloc.accessmrs.services.SyncAdapter.java
/** * Downloads forms from OpenMRS//from www .j a v a2s .c o m * * @param serverForms * forms to download * @return error message or null if successful */ private Form[] downloadNewForms(HttpClient client, Form[] newForms, SyncResult syncResult) { SyncManager.sLoopProgress.set(0); SyncManager.sLoopCount.set(newForms.length); ArrayList<Form> downloadedForms = new ArrayList<Form>(); FileUtils.createFolder(FileUtils.getExternalFormsPath()); for (int i = 0; i < newForms.length; i++) { String formId = newForms[i].getFormId() + ""; try { // download StringBuilder url = (new StringBuilder(NetworkUtils.getFormDownloadUrl())).append("&formId=") .append(formId); if (App.DEBUG) Log.v(TAG, "Will try to download form " + formId + " url=" + url); InputStream is = NetworkUtils.getStream(client, url.toString()); File f = new File(FileUtils.getExternalFormsPath(), formId + FileUtils.XML_EXT); String path = f.getAbsolutePath(); OutputStream os = new FileOutputStream(f); byte buf[] = new byte[1024]; int len; while ((len = is.read(buf)) > 0) { os.write(buf, 0, len); } os.flush(); os.close(); is.close(); newForms[i].setFormId(Integer.valueOf(formId)); newForms[i].setPath(path); downloadedForms.add(newForms[i]); } catch (IOException e) { mTimeoutException = e.getLocalizedMessage(); Log.e(TAG, "Connection Timeout Exception... "); e.printStackTrace(); ++syncResult.stats.numIoExceptions; } catch (Exception e) { ++syncResult.stats.numIoExceptions; e.printStackTrace(); } SyncManager.sLoopProgress.getAndIncrement(); } return downloadedForms.toArray(new Form[downloadedForms.size()]); }
From source file:com.serotonin.modbus4j.ip.listener.TcpListener.java
@Override synchronized public ModbusResponse sendImpl(ModbusRequest request) throws ModbusTransportException { if (!connected) { LOG.debug("No connection in Port: " + ipParameters.getPort()); throw new ModbusTransportException(new Exception("TCP Listener has no active connection!"), request.getSlaveId());//from w w w . ja va2s .com } if (!initialized) { LOG.debug("Listener already terminated " + ipParameters.getPort()); return null; } // Wrap the modbus request in a ip request. OutgoingRequestMessage ipRequest; if (ipParameters.isEncapsulated()) { ipRequest = new EncapMessageRequest(request); StringBuilder sb = new StringBuilder(); for (byte b : Arrays.copyOfRange(ipRequest.getMessageData(), 0, ipRequest.getMessageData().length)) { sb.append(String.format("%02X ", b)); } LOG.debug("Encap Request: " + sb.toString()); } else { ipRequest = new XaMessageRequest(request, getNextTransactionId()); StringBuilder sb = new StringBuilder(); for (byte b : Arrays.copyOfRange(ipRequest.getMessageData(), 0, ipRequest.getMessageData().length)) { sb.append(String.format("%02X ", b)); } LOG.debug("Xa Request: " + sb.toString()); } // Send the request to get the response. IpMessageResponse ipResponse; try { // Send data via handler! handler.conn.DEBUG = true; ipResponse = (IpMessageResponse) handler.conn.send(ipRequest); if (ipResponse == null) { throw new ModbusTransportException(new Exception("No valid response from slave!"), request.getSlaveId()); } StringBuilder sb = new StringBuilder(); for (byte b : Arrays.copyOfRange(ipResponse.getMessageData(), 0, ipResponse.getMessageData().length)) { sb.append(String.format("%02X ", b)); } LOG.debug("Response: " + sb.toString()); return ipResponse.getModbusResponse(); } catch (Exception e) { LOG.debug(e.getLocalizedMessage() + ", Port: " + ipParameters.getPort() + ", retries: " + retries); if (retries < 10 && !e.getLocalizedMessage().contains("Broken")) { retries++; } else { /* * To recover from a Broken Pipe, the only way is to restart serverSocket */ LOG.debug("Restarting Socket, Port: " + ipParameters.getPort() + ", retries: " + retries); // Close the serverSocket first to prevent new messages. try { if (serverSocket != null) serverSocket.close(); } catch (IOException e2) { LOG.debug("Error closing socket" + e2.getLocalizedMessage(), e); getExceptionHandler().receivedException(e2); } // Close all open connections. if (handler != null) { handler.closeConnection(); terminateListener(); } if (!initialized) { LOG.debug("Listener already terminated " + ipParameters.getPort()); return null; } executorService = Executors.newCachedThreadPool(); try { startListener(); } catch (Exception e2) { LOG.warn("Error trying to restart socket" + e2.getLocalizedMessage(), e); throw new ModbusTransportException(e2, request.getSlaveId()); } retries = 0; } LOG.warn("Error sending request, Port: " + ipParameters.getPort() + ", msg: " + e.getMessage()); // Simple send error! throw new ModbusTransportException(e, request.getSlaveId()); } }
From source file:org.zaizi.alfresco.publishing.marklogic.MarkLogicChannelType.java
@Override public void unpublish(final NodeRef nodeToUnpublish, final Map<QName, Serializable> channelProperties) { LOG.info("unpublish() invoked..."); final HttpClient httpclient = new DefaultHttpClient(); try {/* w w w. j a va 2s .c om*/ if (LOG.isDebugEnabled()) { LOG.debug("Unpublishing node: " + nodeToUnpublish); } final URI uriDelete = publishingHelper.getDeleteURIFromNodeRefAndChannelProperties(nodeToUnpublish, channelProperties); final HttpDelete httpDelete = new HttpDelete(uriDelete); final HttpResponse response = httpclient.execute(httpDelete, publishingHelper.getHttpContextFromChannelProperties(channelProperties)); if (LOG.isDebugEnabled()) { LOG.debug("Response Status: " + response.getStatusLine().getStatusCode() + " - Message: " + response.getStatusLine().getReasonPhrase() + " - NodeRef: " + nodeToUnpublish.toString()); } if (response.getStatusLine().getStatusCode() != STATUS_DOCUMENT_DELETED) { throw new AlfrescoRuntimeException(response.getStatusLine().getReasonPhrase()); } } catch (IllegalStateException illegalEx) { if (LOG.isErrorEnabled()) { LOG.error("Exception in Unpublish(): ", illegalEx); } throw new AlfrescoRuntimeException(illegalEx.getLocalizedMessage()); } catch (IOException ioex) { if (LOG.isErrorEnabled()) { LOG.error("Exception in Unpublish(): ", ioex); } throw new AlfrescoRuntimeException(ioex.getLocalizedMessage()); } catch (URISyntaxException uriSynEx) { if (LOG.isErrorEnabled()) { LOG.error("Exception in Unpublish(): ", uriSynEx); } throw new AlfrescoRuntimeException(uriSynEx.getLocalizedMessage()); } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:ch.njol.skript.Updater.java
/** * @param sender Sender to receive messages * @param download Whether to directly download the newest version if one is found * @param isAutomatic/*from w w w . j av a2 s . co m*/ */ static void check(final CommandSender sender, final boolean download, final boolean isAutomatic) { stateLock.writeLock().lock(); try { if (state == UpdateState.CHECK_IN_PROGRESS || state == UpdateState.DOWNLOAD_IN_PROGRESS) return; state = UpdateState.CHECK_IN_PROGRESS; } finally { stateLock.writeLock().unlock(); } if (!isAutomatic || Skript.logNormal()) Skript.info(sender, "" + m_checking); Skript.newThread(new Runnable() { @Override public void run() { infos.clear(); InputStream in = null; try { final URLConnection conn = new URL(filesURL).openConnection(); conn.setRequestProperty("User-Agent", "Skript/v" + Skript.getVersion() + " (by Njol)"); in = conn.getInputStream(); final BufferedReader reader = new BufferedReader(new InputStreamReader(in, conn.getContentEncoding() == null ? "UTF-8" : conn.getContentEncoding())); try { final String line = reader.readLine(); if (line != null) { final JSONArray a = (JSONArray) JSONValue.parse(line); for (final Object o : a) { final Object name = ((JSONObject) o).get("name"); if (!(name instanceof String) || !((String) name).matches("\\d+\\.\\d+(\\.\\d+)?( \\(jar( only)?\\))?"))// not the default version pattern to not match beta/etc. versions continue; final Object url = ((JSONObject) o).get("downloadUrl"); if (!(url instanceof String)) continue; final Version version = new Version(((String) name).contains(" ") ? "" + ((String) name).substring(0, ((String) name).indexOf(' ')) : ((String) name)); if (version.compareTo(Skript.getVersion()) > 0) { infos.add(new VersionInfo((String) name, version, (String) url)); } } } } finally { reader.close(); } if (!infos.isEmpty()) { Collections.sort(infos); latest.set(infos.get(0)); } else { latest.set(null); } getChangelogs(sender); final String message = infos.isEmpty() ? (Skript.getVersion().isStable() ? "" + m_running_latest_version : "" + m_running_latest_version_beta) : "" + m_update_available; if (isAutomatic && !infos.isEmpty()) { Skript.adminBroadcast(message); } else { Skript.info(sender, message); } if (download && !infos.isEmpty()) { stateLock.writeLock().lock(); try { state = UpdateState.DOWNLOAD_IN_PROGRESS; } finally { stateLock.writeLock().unlock(); } download_i(sender, isAutomatic); } else { stateLock.writeLock().lock(); try { state = UpdateState.CHECKED_FOR_UPDATE; } finally { stateLock.writeLock().unlock(); } } } catch (final IOException e) { stateLock.writeLock().lock(); try { state = UpdateState.CHECK_ERROR; error.set(ExceptionUtils.toString(e)); if (sender != null) Skript.error(sender, m_check_error.toString()); } finally { stateLock.writeLock().unlock(); } } catch (final Exception e) { if (sender != null) Skript.error(sender, m_internal_error.toString()); Skript.exception(e, "Unexpected error while checking for a new version of Skript"); stateLock.writeLock().lock(); try { state = UpdateState.CHECK_ERROR; error.set(e.getClass().getSimpleName() + ": " + e.getLocalizedMessage()); } finally { stateLock.writeLock().unlock(); } } finally { if (in != null) { try { in.close(); } catch (final IOException e) { } } } } }, "Skript update thread").start(); }
From source file:com.kylinolap.job.flow.JobFlowListener.java
/** * @param jobInstance/*from ww w. ja v a 2 s. c o m*/ * @param stepId */ private void updateKylinJobStatus(JobInstance jobInstance, int stepId, JobEngineConfig engineConfig) { validate(jobInstance); List<JobStep> steps = jobInstance.getSteps(); Collections.sort(steps); JobStep jobStep = jobInstance.getSteps().get(stepId); long duration = jobStep.getExecEndTime() - jobStep.getExecStartTime(); jobInstance.setDuration(jobInstance.getDuration() + (duration > 0 ? duration : 0) / 1000); jobInstance.setMrWaiting(jobInstance.getMrWaiting() + jobStep.getExecWaitTime()); try { JobDAO.getInstance(engineConfig.getConfig()).updateJobInstance(jobInstance); } catch (IOException e) { e.printStackTrace(); log.error(e.getLocalizedMessage(), e); } }
From source file:com.kylinolap.job.flow.JobFlowListener.java
private void updateKylinJobOnSuccess(JobInstance jobInstance, int stepId, JobEngineConfig engineConfig) { validate(jobInstance);/*from ww w. ja v a 2 s . com*/ List<JobStep> steps = jobInstance.getSteps(); Collections.sort(steps); JobStep jobStep = jobInstance.getSteps().get(stepId); jobInstance.setExecStartTime(steps.get(0).getExecStartTime()); long duration = jobStep.getExecEndTime() - jobStep.getExecStartTime(); jobInstance.setDuration(jobInstance.getDuration() + (duration > 0 ? duration / 1000 : 0)); jobInstance.setMrWaiting(jobInstance.getMrWaiting() + jobStep.getExecWaitTime()); if (jobInstance.getStatus().equals(JobStatusEnum.FINISHED)) { jobInstance.setExecEndTime(steps.get(steps.size() - 1).getExecEndTime()); } try { JobDAO.getInstance(engineConfig.getConfig()).updateJobInstance(jobInstance); } catch (IOException e) { e.printStackTrace(); log.error(e.getLocalizedMessage(), e); } }