Example usage for java.net URL getClass

List of usage examples for java.net URL getClass

Introduction

In this page you can find the example usage for java.net URL getClass.

Prototype

@HotSpotIntrinsicCandidate
public final native Class<?> getClass();

Source Link

Document

Returns the runtime class of this Object .

Usage

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithArrayTest.java

@Test
public void testConfigurationPropertiesWithURLArray() {
    ConfigurationPropertiesWithArray config = prepareConfigurationPropertiesWithArray();

    URL urlValue = config.urlArray[0];

    URL otherURL = null;/*from  w w  w  . jav  a2  s. c o  m*/

    try {
        otherURL = new URL("http://www.test.com");
    } catch (Exception e) {

    }

    assertEquals(URL.class, urlValue.getClass());
    assertEquals(otherURL, urlValue);
    assertEquals(3, config.urlArray.length);
}

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithArrayTest.java

@Test
public void testConfigurationXMLWithURLArray() {
    ConfigurationXMLWithArray config = prepareConfigurationXMLWithArray();

    URL urlValue = config.urlArray[0];

    URL otherURL = null;/*from  ww w  .  j  a  v a2s.c  o m*/

    try {
        otherURL = new URL("http://www.test.com");
    } catch (Exception e) {

    }

    assertEquals(URL.class, urlValue.getClass());
    assertEquals(otherURL, urlValue);
    assertEquals(3, config.urlArray.length);
}

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithListTest.java

@Test
public void testConfigurationPropertiesWithURLList() {
    ConfigurationPropertiesWithList config = prepareConfigurationPropertiesWithList();

    URL urlValue = config.urlList.get(0);

    URL otherURL = null;/*  w  w  w  .ja va 2s.  c  o  m*/

    try {
        otherURL = new URL("http://www.test.com");
    } catch (Exception e) {

    }

    assertEquals(URL.class, urlValue.getClass());
    assertEquals(otherURL, urlValue);
    assertEquals(3, config.urlList.size());
}

From source file:br.gov.frameworkdemoiselle.internal.configuration.ConfigurationLoaderWithListTest.java

@Test
public void testConfigurationXMLWithURLList() {
    ConfigurationXMLWithList config = prepareConfigurationXMLWithList();

    URL urlValue = config.urlList.get(0);

    URL otherURL = null;//from w w  w  .ja  v a 2  s . c  o m

    try {
        otherURL = new URL("http://www.test.com");
    } catch (Exception e) {

    }

    assertEquals(URL.class, urlValue.getClass());
    assertEquals(otherURL, urlValue);
    assertEquals(3, config.urlList.size());
}

From source file:org.apache.tomcat.util.IntrospectionUtils.java

/**
 * Construct a URLClassLoader. Will compile and work in JDK1.1 too.
 */// w w  w  . j  a va2  s . c o  m
public static ClassLoader getURLClassLoader(URL urls[], ClassLoader parent) {
    try {
        Class urlCL = Class.forName("java.net.URLClassLoader");
        Class paramT[] = new Class[2];
        paramT[0] = urls.getClass();
        paramT[1] = ClassLoader.class;
        Method m = findMethod(urlCL, "newInstance", paramT);
        if (m == null)
            return null;

        ClassLoader cl = (ClassLoader) m.invoke(urlCL, new Object[] { urls, parent });
        return cl;
    } catch (ClassNotFoundException ex) {
        // jdk1.1
        return null;
    } catch (Exception ex) {
        ex.printStackTrace();
        return null;
    }
}

From source file:org.eclipse.ecr.runtime.osgi.OSGiRuntimeService.java

protected File getEclipseBundleFileUsingReflection(Bundle bundle) {
    try {//from  w w w.ja  v  a 2 s  .  co m
        Object proxy = bundle.getClass().getMethod("getLoaderProxy").invoke(bundle);
        Object loader = proxy.getClass().getMethod("getBundleLoader").invoke(proxy);
        URL root = (URL) loader.getClass().getMethod("findResource", String.class).invoke(loader, "/");
        Field field = root.getClass().getDeclaredField("handler");
        field.setAccessible(true);
        Object handler = field.get(root);
        Field entryField = handler.getClass().getSuperclass().getDeclaredField("bundleEntry");
        entryField.setAccessible(true);
        Object entry = entryField.get(handler);
        Field fileField = entry.getClass().getDeclaredField("file");
        fileField.setAccessible(true);
        return (File) fileField.get(entry);
    } catch (Throwable e) {
        log.error("Cannot access to eclipse bundle system files of " + bundle.getSymbolicName());
        return null;
    }
}

From source file:org.kuali.mobility.push.dao.PushDaoImpl.java

@SuppressWarnings("unchecked")
private boolean sendPushToAndroid(Push push, Device device) {

    try {/*from ww  w  . ja v  a2 s .co m*/
        HttpsURLConnection.setDefaultHostnameVerifier(new CustomizedHostnameVerifier());
        URL url = new URL("https://android.apis.google.com/c2dm/send");
        HttpsURLConnection request = (HttpsURLConnection) url.openConnection();

        LOG.info("---- Version: " + url.getClass().getPackage().getSpecificationVersion());
        LOG.info("---- Impl:    " + url.getClass().getPackage().getImplementationVersion());
        String handlers = System.getProperty("java.protocol.handler.pkgs");

        LOG.info(handlers);
        request.setDoOutput(true);
        request.setDoInput(true);

        StringBuilder buf = new StringBuilder();
        buf.append("registration_id").append("=").append((URLEncoder.encode(device.getRegId(), "UTF-8")));
        buf.append("&collapse_key").append("=")
                .append((URLEncoder.encode(push.getPostedTimestamp().toString(), "UTF-8")));
        buf.append("&data.message").append("=").append((URLEncoder.encode(push.getMessage(), "UTF-8")));
        buf.append("&data.title").append("=").append((URLEncoder.encode(push.getTitle(), "UTF-8")));
        buf.append("&data.id").append("=").append((URLEncoder.encode(push.getPushId().toString(), "UTF-8")));
        buf.append("&data.url").append("=").append((URLEncoder.encode(push.getUrl().toString(), "UTF-8")));

        String emer = (push.getEmergency()) ? "YES" : "NO";
        buf.append("&data.emer").append("=").append((URLEncoder.encode(emer, "UTF-8")));

        request.setRequestMethod("POST");
        request.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
        request.setRequestProperty("Content-Length", buf.toString().getBytes().length + "");
        request.setRequestProperty("Authorization", "GoogleLogin auth=" + GoogleAuthToken);

        LOG.info("SEND Android Buffer: " + buf.toString());

        OutputStreamWriter post = new OutputStreamWriter(request.getOutputStream());
        post.write(buf.toString());
        post.flush();

        BufferedReader in = new BufferedReader(new InputStreamReader(request.getInputStream()));
        buf = new StringBuilder();
        String inputLine;
        while ((inputLine = in.readLine()) != null) {
            buf.append(inputLine);
        }
        post.close();
        in.close();

        LOG.info("response from C2DM server:\n" + buf.toString());

    } catch (MalformedURLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    } catch (UnsupportedEncodingException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return false;
    }
    return true;
}

From source file:org.nuxeo.runtime.osgi.OSGiRuntimeService.java

protected File getEclipseBundleFileUsingReflection(Bundle bundle) {
    try {//from   ww  w  .jav  a2  s  .  c  o m
        Object proxy = bundle.getClass().getMethod("getLoaderProxy").invoke(bundle);
        Object loader = proxy.getClass().getMethod("getBundleLoader").invoke(proxy);
        URL root = (URL) loader.getClass().getMethod("findResource", String.class).invoke(loader, "/");
        Field field = root.getClass().getDeclaredField("handler");
        field.setAccessible(true);
        Object handler = field.get(root);
        Field entryField = handler.getClass().getSuperclass().getDeclaredField("bundleEntry");
        entryField.setAccessible(true);
        Object entry = entryField.get(handler);
        Field fileField = entry.getClass().getDeclaredField("file");
        fileField.setAccessible(true);
        return (File) fileField.get(entry);
    } catch (ReflectiveOperationException e) {
        log.error("Cannot access to eclipse bundle system files of " + bundle.getSymbolicName());
        return null;
    }
}