Search in sources :

Example 36 with URL

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);
}
Also used : SpecificRequestor(org.apache.avro.ipc.specific.SpecificRequestor) HttpTransceiver(org.apache.avro.ipc.HttpTransceiver) ReflectRequestor(org.apache.avro.ipc.reflect.ReflectRequestor) TestReflection(org.apache.camel.avro.test.TestReflection) URL(java.net.URL) KeyValueProtocol(org.apache.camel.avro.generated.KeyValueProtocol)

Example 37 with URL

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();
}
Also used : MalformedURLException(java.net.MalformedURLException) XMLDecoder(java.beans.XMLDecoder) URL(java.net.URL) MalformedURLException(java.net.MalformedURLException)

Example 38 with URL

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);
        }
    }
}
Also used : JarInputStream(java.util.jar.JarInputStream) FileInputStream(java.io.FileInputStream) InputStream(java.io.InputStream) IOException(java.io.IOException) URISyntaxException(java.net.URISyntaxException) URI(java.net.URI) File(java.io.File) URL(java.net.URL) URLConnection(java.net.URLConnection) FileInputStream(java.io.FileInputStream)

Example 39 with URL

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;
}
Also used : InputStream(java.io.InputStream) IOException(java.io.IOException) Properties(java.util.Properties) URL(java.net.URL)

Example 40 with URL

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;
}
Also used : InputStreamReader(java.io.InputStreamReader) BufferedReader(java.io.BufferedReader) IOException(java.io.IOException) URLConnection(java.net.URLConnection) URL(java.net.URL)

Aggregations

URL (java.net.URL)8112 IOException (java.io.IOException)2006 Test (org.junit.Test)1653 File (java.io.File)1638 MalformedURLException (java.net.MalformedURLException)1165 HttpURLConnection (java.net.HttpURLConnection)1030 InputStream (java.io.InputStream)1028 ArrayList (java.util.ArrayList)633 URLConnection (java.net.URLConnection)515 InputStreamReader (java.io.InputStreamReader)473 URLClassLoader (java.net.URLClassLoader)451 BufferedReader (java.io.BufferedReader)390 HashMap (java.util.HashMap)361 URISyntaxException (java.net.URISyntaxException)286 URI (java.net.URI)269 Map (java.util.Map)259 FileInputStream (java.io.FileInputStream)227 List (java.util.List)205 FileOutputStream (java.io.FileOutputStream)194 OutputStream (java.io.OutputStream)194