@Override protected void cancel() { this.canceled = true; synchronized (this) { if (connection != null) { connection.disconnect(); } } }
@Override protected void realRun() throws SAXException, IOException, OsmTransferException { String urlString = useserver.url + Utils.encodeUrl(searchExpression); try { getProgressMonitor().indeterminateSubTask(tr("Querying name server ...")); URL url = new URL(urlString); synchronized (this) { connection = HttpClient.create(url); connection.connect(); } try (Reader reader = connection.getResponse().getContentReader()) { InputSource inputSource = new InputSource(reader); NameFinderResultParser parser = new NameFinderResultParser(); Utils.parseSafeSAX(inputSource, parser); this.data = parser.getResult(); } } catch (SAXParseException e) { if (!canceled) { // Nominatim sometimes returns garbage, see #5934, #10643 Main.warn(tr("Error occured with query ''{0}'': ''{1}''", urlString, e.getMessage())); GuiHelper.runInEDTAndWait( new Runnable() { @Override public void run() { HelpAwareOptionPane.showOptionDialog( Main.parent, tr("Name server returned invalid data. Please try again."), tr("Bad response"), JOptionPane.WARNING_MESSAGE, null); } }); } } catch (Exception e) { if (!canceled) { OsmTransferException ex = new OsmTransferException(e); ex.setUrl(urlString); lastException = ex; } } }