use of java.net.MalformedURLException in project druid by druid-io.
the class LookupCoordinatorManager method deleteAllOnTier.
void deleteAllOnTier(final String tier, final Collection<String> dropLookups) throws ExecutionException, InterruptedException, IOException {
if (dropLookups.isEmpty()) {
LOG.debug("Nothing to drop");
return;
}
final Collection<URL> urls = getAllHostsAnnounceEndpoint(tier);
final List<ListenableFuture<?>> futures = new ArrayList<>(urls.size());
for (final URL url : urls) {
futures.add(executorService.submit(new Runnable() {
@Override
public void run() {
for (final String drop : dropLookups) {
final URL lookupURL;
try {
lookupURL = new URL(url.getProtocol(), url.getHost(), url.getPort(), String.format("%s/%s", url.getFile(), drop));
} catch (MalformedURLException e) {
throw new ISE(e, "Error creating url for [%s]/[%s]", url, drop);
}
try {
deleteOnHost(lookupURL);
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
LOG.warn("Delete [%s] interrupted", lookupURL);
throw Throwables.propagate(e);
} catch (IOException | ExecutionException e) {
// Don't raise as ExecutionException. Just log and continue
LOG.makeAlert(e, "Error deleting [%s]", lookupURL).emit();
}
}
}
}));
}
final ListenableFuture allFuture = Futures.allAsList(futures);
try {
allFuture.get(lookupCoordinatorManagerConfig.getUpdateAllTimeout().getMillis(), TimeUnit.MILLISECONDS);
} catch (TimeoutException e) {
// This should cause Interrupted exceptions on the offending ones
allFuture.cancel(true);
throw new ExecutionException("Timeout in updating hosts! Attempting to cancel", e);
}
}
use of java.net.MalformedURLException in project checkstyle by checkstyle.
the class CommonUtils method getUriByFilename.
/**
* Resolve the specified filename to a URI.
* @param filename name os the file
* @return resolved header file URI
* @throws CheckstyleException on failure
*/
public static URI getUriByFilename(String filename) throws CheckstyleException {
// figure out if this is a File or a URL
URI uri;
try {
final URL url = new URL(filename);
uri = url.toURI();
} catch (final URISyntaxException | MalformedURLException ignored) {
uri = null;
}
if (uri == null) {
final File file = new File(filename);
if (file.exists()) {
uri = file.toURI();
} else {
// check to see if the file is in the classpath
try {
final URL configUrl = CommonUtils.class.getResource(filename);
if (configUrl == null) {
throw new CheckstyleException(UNABLE_TO_FIND_EXCEPTION_PREFIX + filename);
}
uri = configUrl.toURI();
} catch (final URISyntaxException ex) {
throw new CheckstyleException(UNABLE_TO_FIND_EXCEPTION_PREFIX + filename, ex);
}
}
}
return uri;
}
use of java.net.MalformedURLException in project deeplearning4j by deeplearning4j.
the class ClassPathResource method extractActualUrl.
/**
* Extracts parent Jar URL from original ClassPath entry URL.
*
* @param jarUrl Original URL of the resource
* @return URL of the Jar file, containing requested resource
* @throws MalformedURLException
*/
private URL extractActualUrl(URL jarUrl) throws MalformedURLException {
String urlFile = jarUrl.getFile();
int separatorIndex = urlFile.indexOf("!/");
if (separatorIndex != -1) {
String jarFile = urlFile.substring(0, separatorIndex);
try {
return new URL(jarFile);
} catch (MalformedURLException var5) {
if (!jarFile.startsWith("/")) {
jarFile = "/" + jarFile;
}
return new URL("file:" + jarFile);
}
} else {
return jarUrl;
}
}
use of java.net.MalformedURLException in project openhab1-addons by openhab.
the class HttpTransport method execute.
public String execute(String request, int connectTimeout, int readTimeout) {
if (request != null && !request.trim().equals("")) {
HttpURLConnection connection = null;
StringBuilder response = new StringBuilder();
BufferedReader in = null;
try {
URL url = new URL(this.uri + request);
connection = (HttpURLConnection) url.openConnection();
int responseCode = -1;
if (connection != null) {
connection.setConnectTimeout(connectTimeout);
connection.setReadTimeout(readTimeout);
try {
connection.connect();
responseCode = connection.getResponseCode();
} catch (SocketTimeoutException e) {
logger.warn(e.getMessage() + " : " + request);
return null;
}
if (responseCode == HttpURLConnection.HTTP_OK) {
String inputLine = null;
in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
while ((inputLine = in.readLine()) != null) {
response.append(inputLine);
}
in.close();
} else {
response = null;
}
}
if (response != null) {
return response.toString();
}
} catch (MalformedURLException e) {
logger.error("MalformedURLException by executing jsonRequest: " + request + " ; " + e.getLocalizedMessage());
} catch (IOException e) {
logger.error("IOException by executing jsonRequest: " + request + " ; " + e.getLocalizedMessage());
} finally {
if (connection != null) {
connection.disconnect();
}
}
}
return null;
}
use of java.net.MalformedURLException in project neo4j by neo4j.
the class URLTypeCaster method getList.
@Override
Object[] getList(GraphDatabaseAPI graphDb, ParameterList parameters, String name) throws BadInputException {
URI[] uris = parameters.getUriList(name);
URL[] urls = new URL[uris.length];
try {
for (int i = 0; i < urls.length; i++) {
urls[i] = uris[i].toURL();
}
} catch (MalformedURLException e) {
throw new BadInputException(e);
}
return urls;
}
Aggregations