List of usage examples for java.net SocketTimeoutException getLocalizedMessage
public String getLocalizedMessage()
From source file:org.spinsuite.sync.SyncDataTask.java
/** * Call Web Service And get Response//w ww. j a va 2 s .com * @author Carlos Parada, cparada@erpcya.com, ERPCyA http://www.erpcya.com * @param p_SO_Param * @throws IOException * @throws XmlPullParserException * @return void */ private void callWebService(SoapObject p_SO_Param, MSPSSyncMenu sm) { m_PublicTittle = sm.getName(); m_PublicMsg = sm.getDescription(); m_Progress = -1; publishOnRunning(); soapObject = new CommunicationSoap(m_Current_URL, m_NameSpace, m_MethodValue, SyncValues.IsNetService); soapObject.setM_SoapAction(m_NameSpace + "/" + m_MethodValue); if (p_SO_Param != null) soapObject.addSoapObject(p_SO_Param); soapObject.init_envelope(); if (m_TimeOut == 0) soapObject.initTransport(); else soapObject.initTransport(m_TimeOut); try { soapObject.call(); soapResponse = (SoapObject) soapObject.getM_Envelope().getResponse(); } catch (SocketTimeoutException e) { e.printStackTrace(); m_PublicMsg = e.getLocalizedMessage(); } catch (XmlPullParserException e) { e.printStackTrace(); m_PublicMsg = e.getLocalizedMessage(); } catch (IOException e) { e.printStackTrace(); m_PublicMsg = e.getLocalizedMessage(); } catch (Exception e) { e.printStackTrace(); m_PublicMsg = e.getLocalizedMessage(); } finally { publishOnRunning(); } }
From source file:org.opendatakit.briefcase.util.ServerFetcher.java
public boolean downloadFormAndSubmissionFiles(List<FormStatus> formsToTransfer) { boolean allSuccessful = true; // boolean error = false; int total = formsToTransfer.size(); for (int i = 0; i < total; i++) { FormStatus fs = formsToTransfer.get(i); if (isCancelled()) { fs.setStatusString("aborted. Skipping fetch of form and submissions...", true); EventBus.publish(new FormStatusEvent(fs)); return false; }/*from w w w . j ava2s .c om*/ RemoteFormDefinition fd = (RemoteFormDefinition) fs.getFormDefinition(); fs.setStatusString("Fetching form definition", true); EventBus.publish(new FormStatusEvent(fs)); try { File tmpdl = FileSystemUtils.getTempFormDefinitionFile(); AggregateUtils.commonDownloadFile(serverInfo, tmpdl, fd.getDownloadUrl()); fs.setStatusString("resolving against briefcase form definitions", true); EventBus.publish(new FormStatusEvent(fs)); boolean successful = false; BriefcaseFormDefinition briefcaseLfd; DatabaseUtils formDatabase = null; try { try { briefcaseLfd = BriefcaseFormDefinition.resolveAgainstBriefcaseDefn(tmpdl); if (briefcaseLfd.needsMediaUpdate()) { if (fd.getManifestUrl() != null) { File mediaDir = FileSystemUtils.getMediaDirectory(briefcaseLfd.getFormDirectory()); String error = downloadManifestAndMediaFiles(mediaDir, fs); if (error != null) { allSuccessful = false; fs.setStatusString("Error fetching form definition: " + error, false); EventBus.publish(new FormStatusEvent(fs)); continue; } } } formDatabase = new DatabaseUtils( FileSystemUtils.getFormDatabase(briefcaseLfd.getFormDirectory())); } catch (BadFormDefinition e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString("Error parsing form definition: " + e.getMessage(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } fs.setStatusString("preparing to retrieve instance data", true); EventBus.publish(new FormStatusEvent(fs)); File formInstancesDir = FileSystemUtils .getFormInstancesDirectory(briefcaseLfd.getFormDirectory()); // this will publish events successful = downloadAllSubmissionsForForm(formInstancesDir, formDatabase, briefcaseLfd, fs); } catch (FileSystemException e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString("unable to open form database: " + e.getMessage(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } finally { if (formDatabase != null) { try { formDatabase.close(); } catch (SQLException e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString("unable to close form database: " + e.getMessage(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } } } allSuccessful = allSuccessful && successful; // on success, we haven't actually set a success event (because we don't know we're done) if (successful) { fs.setStatusString("SUCCESS!", true); EventBus.publish(new FormStatusEvent(fs)); } else { fs.setStatusString("FAILED.", true); EventBus.publish(new FormStatusEvent(fs)); } } catch (SocketTimeoutException se) { se.printStackTrace(); allSuccessful = false; fs.setStatusString( "Communications to the server timed out. Detailed message: " + se.getLocalizedMessage() + " while accessing: " + fd.getDownloadUrl() + " A network login screen may be interfering with the transmission to the server.", false); EventBus.publish(new FormStatusEvent(fs)); continue; } catch (IOException e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString( "Unexpected error: " + e.getLocalizedMessage() + " while accessing: " + fd.getDownloadUrl() + " A network login screen may be interfering with the transmission to the server.", false); EventBus.publish(new FormStatusEvent(fs)); continue; } catch (FileSystemException e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString( "Unexpected error: " + e.getLocalizedMessage() + " while accessing: " + fd.getDownloadUrl(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } catch (URISyntaxException e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString( "Unexpected error: " + e.getLocalizedMessage() + " while accessing: " + fd.getDownloadUrl(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } catch (TransmissionException e) { e.printStackTrace(); allSuccessful = false; fs.setStatusString( "Unexpected error: " + e.getLocalizedMessage() + " while accessing: " + fd.getDownloadUrl(), false); EventBus.publish(new FormStatusEvent(fs)); continue; } } return allSuccessful; }
From source file:org.openhab.binding.pulseaudio.internal.PulseaudioClient.java
private String _sendRawRequest(String command) { checkConnection();// w ww.j a v a 2 s.c om String result = ""; try { PrintStream out = new PrintStream(client.getOutputStream(), true); out.print(command + "\r\n"); InputStream instr = client.getInputStream(); try { byte[] buff = new byte[1024]; int ret_read = 0; int lc = 0; do { ret_read = instr.read(buff); lc++; if (ret_read > 0) { String line = new String(buff, 0, ret_read); //System.out.println("'"+line+"'"); if (line.endsWith(">>> ") && lc > 1) { result += line.substring(0, line.length() - 4); break; } result += line.trim(); } } while (ret_read > 0); } catch (SocketTimeoutException e) { // Timeout -> send was has been received so far return result; } catch (IOException e) { System.err.println("Exception while reading socket:" + e.getMessage()); } instr.close(); out.close(); client.close(); return result; } catch (IOException e) { logger.error(e.getLocalizedMessage(), e); } return result; }
From source file:edu.ku.brc.specify.tasks.subpane.lm.LifeMapperPane.java
/** * // w ww . ja v a 2 s . co m */ @SuppressWarnings("unchecked") public void doSearchOccur(final String occurrenceId) { updateMyDataUIState(false); points.clear(); final SimpleGlassPane glassPane = writeSimpleGlassPaneMsg(getLocalizedMessage("LifeMapperTask.PROCESSING"), GLASS_FONT_SIZE); glassPane.setTextYPos((int) ((double) getSize().height * 0.25)); // check the website for the info about the latest version final HttpClient httpClient = new HttpClient(); httpClient.getParams().setParameter("http.useragent", getClass().getName()); //$NON-NLS-1$ httpClient.getParams().setParameter("http.socket.timeout", 15000); if (list.getSelectedIndex() < 0) { return; } UsageTracker.incrUsageCount("LM.OccurSearch"); final String lmURL = String.format( "http://www.lifemapper.org/services/sdm/occurrences/%s/json?format=specify&fillPoints=true", occurrenceId); //System.out.println(lmURL); SwingWorker<String, String> worker = new SwingWorker<String, String>() { @Override protected String doInBackground() throws Exception { GetMethod getMethod = new GetMethod(lmURL); try { httpClient.executeMethod(getMethod); // get the server response //String responseString = getMethod.getResponseBodyAsString(); byte[] bytes = getMethod.getResponseBody(); if (bytes != null && bytes.length > 0) { return new String(bytes, "UTF-8"); } //if (StringUtils.isNotEmpty(responseString)) //{ // System.err.println(responseString); //} return null; } catch (java.net.UnknownHostException uex) { //log.error(uex.getMessage()); } catch (java.net.SocketTimeoutException ex) { UsageTracker.incrUsageCount("LM.OccurSearchErr"); } catch (Exception e) { e.printStackTrace(); UsageTracker.incrUsageCount("LM.OccurSearchErr"); } return null; } @Override protected void done() { super.done(); boolean isError = true; boolean parseError = false; try { String responseString = get(); if (StringUtils.isNotEmpty(responseString) && StringUtils.contains(responseString.toLowerCase(), "{")) { // Need to change this to using regex to strip away unwanted chars StringBuilder sb = new StringBuilder(); String[] lines = StringUtils.split(responseString, '\n'); for (String str : lines) { if (str.indexOf("resname") == -1) { sb.append(str); } } String cleaned = sb.toString(); parseError = false; try { JSONTokener tok = new JSONTokener(cleaned); if (tok != null) { while (tok.more()) { JSONObject obj = (JSONObject) tok.nextValue(); if (obj != null) { JSONArray pointArray = (JSONArray) obj.get("feature"); if (pointArray != null) { Iterator<Object> iter = (Iterator<Object>) pointArray.iterator(); while (iter.hasNext()) { JSONObject pObj = (JSONObject) iter.next(); if (pObj != null) { String lat = null;//(String)pObj.get("lat"); String lon = null;//(String)pObj.get("lon"); String geomwkt = (String) pObj.get("geomwkt"); if (geomwkt != null) { //quel cheapo... geomwkt = geomwkt.replace("POINT", ""); geomwkt = geomwkt.replace("(", ""); geomwkt = geomwkt.replace(")", ""); geomwkt = geomwkt.trim(); String[] geocs = geomwkt.split(" "); if (geocs.length == 2) { lon = geocs[0]; lat = geocs[1]; } } //System.out.println(lat+" "+lon); if (lat != null && lon != null) { LatLonPlacemark plcMark = new LatLonPlacemark(markerImg, Double.parseDouble(lat.trim()), Double.parseDouble(lon.trim())); points.add(plcMark); } } } isError = false; } } } } } catch (net.sf.json.JSONException ex) { System.err.println(ex.getLocalizedMessage()); parseError = true; } boolean hasPnts = points.size() > 0; updateMyDataUIState(hasPnts && StringUtils.isNotEmpty(myDataTF.getText())); if (hasPnts) { imgDisplay.setImage((Image) null); wwPanel.placeMarkers(points, false, true, 0, null, false); imgRequestCnt = 0; imgURL = makeURL(occurSet); getImageFromWeb(imgURL, pointsMapImageListener); } else { isError = false; } } else { UsageTracker.incrUsageCount("LM.OccurSearchErr"); } } catch (InterruptedException e) { e.printStackTrace(); } catch (ExecutionException e) { e.printStackTrace(); } if (isError || parseError) { showErrorMsg(glassPane, "LifeMapperTask.PROC_ERR"); } else { clearSimpleGlassPaneMsg(); } } }; worker.execute(); }