public static void main(String[] args) {

    RMID rmid = null;

    System.out.println("\nRegression test for bug 4510355\n");

    try {
      TestLibrary.suggestSecurityManager("java.lang.SecurityManager");

      /*
       * Install group class file in codebase.
       */
      System.err.println("install class file in codebase");
      URL groupURL = TestLibrary.installClassInCodebase("MyActivationGroupImpl", "group");
      System.err.println("class file installed");

      /*
       * Start rmid.
       */
      RMID.removeLog();
      rmid = RMID.createRMID();
      String execPolicyOption = "-Dsun.rmi.activation.execPolicy=none";
      rmid.addOptions(new String[] {execPolicyOption});
      rmid.start();

      /*
       * Create and register descriptors for custom group and an
       * activatable object in that group.
       */
      System.err.println("register group");

      Properties p = new Properties();
      p.put("java.security.policy", TestParams.defaultGroupPolicy);

      ActivationGroupDesc groupDesc =
          new ActivationGroupDesc(
              "MyActivationGroupImpl", groupURL.toExternalForm(), null, p, null);
      ActivationGroupID groupID = ActivationGroup.getSystem().registerGroup(groupDesc);

      System.err.println("register activatable object");
      ActivationDesc desc = new ActivationDesc(groupID, "DownloadActivationGroup", null, null);
      Ping obj = (Ping) Activatable.register(desc);

      /*
       * Start group (by calling ping).
       */
      System.err.println("ping object (forces download of group's class)");
      obj.ping();
      System.err.println("TEST PASSED: group's class downloaded successfully");
      System.err.println("shutdown object");
      obj.shutdown();
      System.err.println("TEST PASSED");

    } catch (Exception e) {
      TestLibrary.bomb(e);
    } finally {
      rmid.cleanup();
    }
  }
Exemple #2
0
  /** 获取类的class文件位置的URL。这个方法是本类最基础的方法,供其它方法调用。 */
  public URL getClassLocationURL(final Class cls) {
    if (cls == null) {
      throw new IllegalArgumentException("class that input is null");
    }
    URL result = null;
    final String clsAsResource = cls.getName().replace('.', '/').concat(".class");
    final ProtectionDomain pd = cls.getProtectionDomain();
    if (pd != null) {
      final CodeSource cs = pd.getCodeSource();
      if (cs != null) {
        result = cs.getLocation();
      }
      if (result != null) {
        if ("file".equals(result.getProtocol())) {
          try {
            if (result.toExternalForm().endsWith(".jar")
                || result.toExternalForm().endsWith(".zip")) {
              result =
                  new URL(
                      "jar:".concat(result.toExternalForm()).concat("!/").concat(clsAsResource));
            } else if (new File(result.getFile()).isDirectory()) {
              result = new URL(result, clsAsResource);
            }
          } catch (MalformedURLException ignore) {
          }
        }
      }
    }

    if (result == null) {
      final ClassLoader clsLoader = cls.getClassLoader();
      result =
          clsLoader != null
              ? clsLoader.getResource(clsAsResource)
              : ClassLoader.getSystemResource(clsAsResource);
    }
    return result;
  }
  /** {@inheritdoc}. */
  public String resolveURI(final String uri) {
    final String burl = getBaseURL();

    URL ref = null;

    if (uri == null) return burl;
    if (uri.trim().equals("")) return burl; // jar URLs don't resolve this right

    if (uri.startsWith("demo:")) {
      final DemoMarker marker = new DemoMarker();
      String short_url = uri.substring(5);
      if (!short_url.startsWith("/")) {
        short_url = "/" + short_url;
      }
      ref = marker.getClass().getResource(short_url);
      Uu.p("ref = " + ref);
    } else if (uri.startsWith("demoNav:")) {
      final DemoMarker marker = new DemoMarker();
      String short_url = uri.substring("demoNav:".length());
      if (!short_url.startsWith("/")) {
        short_url = "/" + short_url;
      }
      ref = marker.getClass().getResource(short_url);
      Uu.p("Demo navigation URI, ref = " + ref);
    } else if (uri.startsWith("javascript")) {
      Uu.p("Javascript URI, ignoring: " + uri);
    } else if (uri.startsWith("news")) {
      Uu.p("News URI, ignoring: " + uri);
    } else {
      try {
        URL base;
        if (burl == null || burl.length() == 0) {
          base = new File(".").toURL();
        } else {
          base = new URL(burl);
        }
        ref = new URL(base, uri);
      } catch (final MalformedURLException e) {
        Uu.p("URI/URL is malformed: " + burl + " or " + uri);
      }
    }

    if (ref == null) return null;
    else return ref.toExternalForm();
  }
Exemple #4
0
 private static InputSource getConfigSource(Class pAppClass) throws DataNotFoundException {
   URL resource = pAppClass.getResource(CONFIG_FILE_NAME);
   String resourceFileName = resource.toExternalForm();
   File resourceFile = new File(resourceFileName);
   InputStream configResourceStream = pAppClass.getResourceAsStream(CONFIG_FILE_NAME);
   if (null == configResourceStream) {
     throw new DataNotFoundException(
         "unable to find XML configuration file resource: "
             + CONFIG_FILE_NAME
             + " for class: "
             + pAppClass.getName());
   }
   InputSource inputSource = new InputSource(configResourceStream);
   if (!resourceFile.exists()) {
     inputSource.setSystemId(resourceFileName);
   }
   return (inputSource);
 }
  // Goes online to get user authentication from Flickr.
  public void getAuthentication() {
    AuthInterface authInterface = flickr.getAuthInterface();

    try {
      frob = authInterface.getFrob();
    } catch (Exception e) {
      e.printStackTrace();
    }

    try {
      URL authURL = authInterface.buildAuthenticationUrl(Permission.WRITE, frob);

      // open the authentication URL in a browser
      open(authURL.toExternalForm());
    } catch (Exception e) {
      e.printStackTrace();
    }

    println("You have 15 seconds to approve the app!");
    int startedWaiting = millis();
    int waitDuration = 15 * 1000; // wait 10 seconds
    while ((millis() - startedWaiting) < waitDuration) {
      // just wait
    }
    println("Done waiting");

    try {
      auth = authInterface.getToken(frob);
      println("Authentication success");
      // This token can be used until the user revokes it.
      token = auth.getToken();
      // save it for future use
      saveToken(token);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // complete authentication
    authenticateWithToken(token);
  }
 /**
  * (Re)Compiles the given source. This method starts the compilation of a given source, if the
  * source has changed since the class was created. For this isSourceNewer is called.
  *
  * @param source the source pointer for the compilation
  * @param className the name of the class to be generated
  * @param oldClass a possible former class
  * @return the old class if the source wasn't new enough, the new class else
  * @throws CompilationFailedException if the compilation failed
  * @throws IOException if the source is not readable
  * @see #isSourceNewer(URL, Class)
  */
 protected Class recompile(URL source, String className, Class oldClass)
     throws CompilationFailedException, IOException {
   if (source != null) {
     // found a source, compile it if newer
     if ((oldClass != null && isSourceNewer(source, oldClass)) || (oldClass == null)) {
       synchronized (sourceCache) {
         String name = source.toExternalForm();
         sourceCache.remove(name);
         if (isFile(source)) {
           try {
             return parseClass(
                 new GroovyCodeSource(new File(source.toURI()), config.getSourceEncoding()));
           } catch (URISyntaxException e) {
             // do nothing and fall back to the other version
           }
         }
         return parseClass(source.openStream(), name);
       }
     }
   }
   return oldClass;
 }
 /**
  * Set copyright or legal information URL for this track.
  *
  * @param oCopyrightLegalInformationUrl an URL
  */
 public void setCopyrightLegalInformation(URL oCopyrightLegalInformationUrl) {
   m_sURL = oCopyrightLegalInformationUrl.toExternalForm();
 }