Example #1
0
  public boolean shutdown(int port, boolean ssl) {
    try {
      String protocol = "http" + (ssl ? "s" : "");
      URL url = new URL(protocol, "127.0.0.1", port, "shutdown");
      HttpURLConnection conn = (HttpURLConnection) url.openConnection();
      conn.setRequestMethod("GET");
      conn.setRequestProperty("servicemanager", "shutdown");
      conn.connect();

      StringBuffer sb = new StringBuffer();
      BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
      int n;
      char[] cbuf = new char[1024];
      while ((n = br.read(cbuf, 0, cbuf.length)) != -1) sb.append(cbuf, 0, n);
      br.close();
      String message = sb.toString().replace("<br>", "\n");
      if (message.contains("Goodbye")) {
        cp.appendln("Shutting down the server:");
        String[] lines = message.split("\n");
        for (String line : lines) {
          cp.append("...");
          cp.appendln(line);
        }
        return true;
      }
    } catch (Exception ex) {
    }
    cp.appendln("Unable to shutdown CTP");
    return false;
  }
Example #2
0
  /**
   * Parse a repository document.
   *
   * @param url
   * @throws IOException
   * @throws XmlPullParserException
   * @throws Exception
   */
  void parseDocument(URL url) throws IOException, XmlPullParserException, Exception {
    if (!visited.contains(url)) {
      visited.add(url);
      try {
        System.out.println("Visiting: " + url);
        InputStream in = null;

        if (url.getPath().endsWith(".zip")) {
          ZipInputStream zin = new ZipInputStream(url.openStream());
          ZipEntry entry = zin.getNextEntry();
          while (entry != null) {
            if (entry.getName().equals("repository.xml")) {
              in = zin;
              break;
            }
            entry = zin.getNextEntry();
          }
        } else {
          in = url.openStream();
        }
        Reader reader = new InputStreamReader(in);
        XmlPullParser parser = new KXmlParser();
        parser.setInput(reader);
        parseRepository(parser);
      } catch (MalformedURLException e) {
        System.out.println("Cannot create connection to url");
      }
    }
  }
 protected void addPathFile(final File pathComponent) throws IOException {
   if (!this.pathComponents.contains(pathComponent)) {
     this.pathComponents.addElement(pathComponent);
   }
   if (pathComponent.isDirectory()) {
     return;
   }
   final String absPathPlusTimeAndLength =
       pathComponent.getAbsolutePath()
           + pathComponent.lastModified()
           + "-"
           + pathComponent.length();
   String classpath = AntClassLoader.pathMap.get(absPathPlusTimeAndLength);
   if (classpath == null) {
     JarFile jarFile = null;
     try {
       jarFile = new JarFile(pathComponent);
       final Manifest manifest = jarFile.getManifest();
       if (manifest == null) {
         return;
       }
       classpath = manifest.getMainAttributes().getValue(Attributes.Name.CLASS_PATH);
     } finally {
       if (jarFile != null) {
         jarFile.close();
       }
     }
     if (classpath == null) {
       classpath = "";
     }
     AntClassLoader.pathMap.put(absPathPlusTimeAndLength, classpath);
   }
   if (!"".equals(classpath)) {
     final URL baseURL = AntClassLoader.FILE_UTILS.getFileURL(pathComponent);
     final StringTokenizer st = new StringTokenizer(classpath);
     while (st.hasMoreTokens()) {
       final String classpathElement = st.nextToken();
       final URL libraryURL = new URL(baseURL, classpathElement);
       if (!libraryURL.getProtocol().equals("file")) {
         this.log(
             "Skipping jar library "
                 + classpathElement
                 + " since only relative URLs are supported by this"
                 + " loader",
             3);
       } else {
         final String decodedPath = Locator.decodeUri(libraryURL.getFile());
         final File libraryFile = new File(decodedPath);
         if (!libraryFile.exists() || this.isInPath(libraryFile)) {
           continue;
         }
         this.addPathFile(libraryFile);
       }
     }
   }
 }
Example #4
0
 private void doImportFromURL(HttpServletRequest req, HttpServletResponse resp)
     throws IOException, ServletException {
   URL source = getSourceURL();
   IOUtilities.pipe(
       source.openStream(),
       new FileOutputStream(new File(getStorageDirectory(), FILE_DATA), true),
       true,
       true);
   completeTransfer(req, resp);
 }
  /**
   * Returns a stream to a pack, depending on the installation kind.
   *
   * @param n The pack number.
   * @return The stream.
   * @exception Exception Description of the Exception
   */
  private InputStream getPackAsStream(int n) throws Exception {
    InputStream in = null;

    if (idata.kind.equalsIgnoreCase("standard")
        || idata.kind.equalsIgnoreCase("standard-kunststoff"))
      in = getClass().getResourceAsStream("/packs/pack" + n);
    else if (idata.kind.equalsIgnoreCase("web") || idata.kind.equalsIgnoreCase("web-kunststoff")) {
      URL url = new URL("jar:" + jarLocation + "!/packs/pack" + n);
      JarURLConnection jarConnection = (JarURLConnection) url.openConnection();
      in = jarConnection.getInputStream();
    }
    return in;
  }
  /**
   * Resolve IGFS profiler logs directory.
   *
   * @param igfs IGFS instance to resolve logs dir for.
   * @return {@link Path} to log dir or {@code null} if not found.
   * @throws IgniteCheckedException if failed to resolve.
   */
  public static Path resolveIgfsProfilerLogsDir(IgniteFileSystem igfs)
      throws IgniteCheckedException {
    String logsDir;

    if (igfs instanceof IgfsEx) logsDir = ((IgfsEx) igfs).clientLogDirectory();
    else if (igfs == null)
      throw new IgniteCheckedException(
          "Failed to get profiler log folder (IGFS instance not found)");
    else
      throw new IgniteCheckedException(
          "Failed to get profiler log folder (unexpected IGFS instance type)");

    URL logsDirUrl = U.resolveIgniteUrl(logsDir != null ? logsDir : DFLT_IGFS_LOG_DIR);

    return logsDirUrl != null ? new File(logsDirUrl.getPath()).toPath() : null;
  }
Example #7
0
  /** Create a FILE object to read from the specified filename. */
  public static FILE openFile(String filename) {
    try {
      FILE f = null;
      File file = new File(filename);

      if (file.isAbsolute()) {
        f = open(file);
      } else {
        if (documentBase != null) {
          String docBase = documentBase.toString();
          if (docBase.startsWith("file:/")) {
            docBase = docBase.substring(6);
            file = new File(docBase, filename);

            f = open(file);
          }
        }

        if (f == null && codeBase != null) {
          String cBase = codeBase.toString();
          if (cBase.startsWith("file:/")) {
            cBase = cBase.substring(6);
            file = new File(cBase, filename);

            f = open(file);
          }
        }

        if (f == null) {
          file = new File(filename);

          f = open(file);
        }
      }

      return f;
    } catch (Exception e) {
      setException(e);

      if (debug) {
        System.out.println("openFile: " + e);
      }
      return null;
    }
  }
Example #8
0
 private boolean checkServer(int port, boolean ssl) {
   try {
     URL url = new URL("http://127.0.0.1:" + port);
     HttpURLConnection conn = (HttpURLConnection) url.openConnection();
     conn.setRequestMethod("GET");
     conn.connect();
     int length = conn.getContentLength();
     StringBuffer text = new StringBuffer();
     InputStream is = conn.getInputStream();
     InputStreamReader isr = new InputStreamReader(is);
     int size = 256;
     char[] buf = new char[size];
     int len;
     while ((len = isr.read(buf, 0, size)) != -1) text.append(buf, 0, len);
     isr.close();
     if (programName.equals("ISN")) return !shutdown(port, ssl);
     return true;
   } catch (Exception ex) {
     return false;
   }
 }
  // 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);
  }
Example #10
0
  /** Create a FILE object to read from the specified URL. */
  public static FILE open(URL url) {
    try {
      InputStream urlInputStream = url.openStream();
      // urlConnection.getInputStream();

      // System.out.println("open(URL) urlInputStream " + urlInputStream);

      return new FILE(urlInputStream);
    } catch (Exception e) {
      if (debug) {
        System.out.println("open(URL) exception " + e);
      }
      setException(e);

      return null;
    }
  }