use of java.net.URL in project camel by apache.
the class AvroHttpConsumerTest method initializeTranceiver.
@Override
protected void initializeTranceiver() throws IOException {
transceiver = new HttpTransceiver(new URL("http://localhost:" + avroPort));
requestor = new SpecificRequestor(KeyValueProtocol.class, transceiver);
transceiverMessageInRoute = new HttpTransceiver(new URL("http://localhost:" + avroPortMessageInRoute));
requestorMessageInRoute = new SpecificRequestor(KeyValueProtocol.class, transceiverMessageInRoute);
transceiverForWrongMessages = new HttpTransceiver(new URL("http://localhost:" + avroPortForWrongMessages));
requestorForWrongMessages = new SpecificRequestor(KeyValueProtocol.class, transceiverForWrongMessages);
reflectTransceiver = new HttpTransceiver(new URL("http://localhost:" + avroPortReflection));
reflectRequestor = new ReflectRequestor(TestReflection.class, reflectTransceiver);
}
use of java.net.URL in project antlrworks by antlr.
the class XJUpdateManager method fetchRemoteUpdateInformation.
public void fetchRemoteUpdateInformation(String urlString, boolean silent) {
updateInfoMap = null;
URL url;
try {
url = new URL(urlString);
} catch (MalformedURLException e) {
if (!silent)
XJAlert.display(getParentContainer(), "Update Manager", "Cannot check the update because:\n" + e);
return;
}
InputStream is;
try {
is = url.openStream();
} catch (IOException e) {
if (!silent)
XJAlert.display(getParentContainer(), "Update Manager", "Cannot check the update because:\n" + e);
return;
}
XMLDecoder decoder = new XMLDecoder(new BufferedInputStream(is));
try {
updateInfoMap = (Map) decoder.readObject();
} catch (Exception e) {
XJAlert.display(getParentContainer(), "Update Manager", "Cannot check the update because:\n" + e);
return;
}
decoder.close();
}
use of java.net.URL in project camel by apache.
the class DefaultPackageScanClassResolver method find.
protected void find(PackageScanFilter test, String packageName, ClassLoader loader, Set<Class<?>> classes) {
if (log.isTraceEnabled()) {
log.trace("Searching for: {} in package: {} using classloader: {}", new Object[] { test, packageName, loader.getClass().getName() });
}
Enumeration<URL> urls;
try {
urls = getResources(loader, packageName);
if (!urls.hasMoreElements()) {
log.trace("No URLs returned by classloader");
}
} catch (IOException ioe) {
log.warn("Cannot read package: " + packageName, ioe);
return;
}
while (urls.hasMoreElements()) {
URL url = null;
try {
url = urls.nextElement();
log.trace("URL from classloader: {}", url);
url = customResourceLocator(url);
String urlPath = url.getFile();
urlPath = URLDecoder.decode(urlPath, "UTF-8");
if (log.isTraceEnabled()) {
log.trace("Decoded urlPath: {} with protocol: {}", urlPath, url.getProtocol());
}
// If it's a file in a directory, trim the stupid file: spec
if (urlPath.startsWith("file:")) {
// to remedy this then create new path without using the URLDecoder
try {
urlPath = new URI(url.getFile()).getPath();
} catch (URISyntaxException e) {
// fallback to use as it was given from the URLDecoder
// this allows us to work on Windows if users have spaces in paths
}
if (urlPath.startsWith("file:")) {
urlPath = urlPath.substring(5);
}
}
// osgi bundles should be skipped
if (url.toString().startsWith("bundle:") || urlPath.startsWith("bundle:")) {
log.trace("Skipping OSGi bundle: {}", url);
continue;
}
// bundle resource should be skipped
if (url.toString().startsWith("bundleresource:") || urlPath.startsWith("bundleresource:")) {
log.trace("Skipping bundleresource: {}", url);
continue;
}
// Else it's in a JAR, grab the path to the jar
if (urlPath.indexOf('!') > 0) {
urlPath = urlPath.substring(0, urlPath.indexOf('!'));
}
log.trace("Scanning for classes in: {} matching criteria: {}", urlPath, test);
File file = new File(urlPath);
if (file.isDirectory()) {
log.trace("Loading from directory using file: {}", file);
loadImplementationsInDirectory(test, packageName, file, classes);
} else {
InputStream stream;
if (urlPath.startsWith("http:") || urlPath.startsWith("https:") || urlPath.startsWith("sonicfs:") || isAcceptableScheme(urlPath)) {
// load resources using http/https, sonicfs and other acceptable scheme
// sonic ESB requires to be loaded using a regular URLConnection
log.trace("Loading from jar using url: {}", urlPath);
URL urlStream = new URL(urlPath);
URLConnection con = urlStream.openConnection();
// disable cache mainly to avoid jar file locking on Windows
con.setUseCaches(false);
stream = con.getInputStream();
} else {
log.trace("Loading from jar using file: {}", file);
stream = new FileInputStream(file);
}
loadImplementationsInJar(test, packageName, stream, urlPath, classes, jarCache);
}
} catch (IOException e) {
// use debug logging to avoid being to noisy in logs
log.debug("Cannot read entries in url: " + url, e);
}
}
}
use of java.net.URL in project camel by apache.
the class AtmosPropertyManager method loadProperties.
private static Properties loadProperties() throws Exception {
URL url = AtmosPropertyManager.class.getResource("/atmos.properties");
InputStream inStream;
try {
inStream = url.openStream();
} catch (IOException e) {
throw new AtmosException("atmos.properties could not be found");
}
properties = new Properties();
try {
properties.load(inStream);
} catch (IOException e) {
throw new AtmosException("atmos.properties can't be read");
}
return properties;
}
use of java.net.URL in project antlrworks by antlr.
the class StatisticsReporter method submitStats.
protected boolean submitStats(String id, String type, String data) {
if (id == null) {
error = "cannot submit stat with a null id";
return false;
}
StringBuilder param = new StringBuilder();
param.append(URL_SEND_STATS);
param.append("ID=");
param.append(id);
param.append("&type=");
param.append(type);
param.append("&data=");
param.append(XJUtils.encodeToURL(data));
URLConnection urc;
URL url;
BufferedReader br;
boolean success = false;
try {
url = new URL(param.toString());
urc = url.openConnection();
br = new BufferedReader(new InputStreamReader(urc.getInputStream()));
success = br.readLine().equalsIgnoreCase("OK");
br.close();
} catch (IOException e) {
error = e.toString();
}
return success;
}
Aggregations