コード例 #1
1
ファイル: JStravaV3.java プロジェクト: justinhrobbins/JStrava
  private String getResult(String URL, HashMap optionalParameters) {
    StringBuilder sb = new StringBuilder();
    sb.append(URL);
    try {

      Iterator iterator = optionalParameters.keySet().iterator();

      int index = 0;
      while (iterator.hasNext()) {
        if (index == 0) {
          sb.append("?");
        } else {
          sb.append("&");
        }
        String key = (String) iterator.next();
        sb.append(key);
        sb.append("=");
        sb.append(URLEncoder.encode(optionalParameters.get(key).toString(), "UTF-8"));
        index++;
      }

      URI uri = new URI(String.format(sb.toString()));
      URL url = uri.toURL();

      HttpURLConnection conn = (HttpURLConnection) url.openConnection();

      conn.setRequestMethod("GET");
      conn.setRequestProperty("Accept", "application/json");
      conn.setRequestProperty("Authorization", "Bearer " + getAccessToken());
      if (conn.getResponseCode() != 200) {
        throw new RuntimeException(
            "Failed : HTTP error code : "
                + conn.getResponseCode()
                + " - "
                + conn.getResponseMessage());
      }

      BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));

      String output;
      sb = new StringBuilder();
      while ((output = br.readLine()) != null) {
        sb.append(output);
      }

      conn.disconnect();

    } catch (IOException e) {

      e.printStackTrace();
      return null;
    } catch (URISyntaxException e) {
      e.printStackTrace();
      return null;
    }
    return sb.toString();
  }
コード例 #2
0
ファイル: URIHelper.java プロジェクト: vprise/CodenameOne
 /**
  * Internal use only, for sources known to always be valid.
  *
  * @param source
  * @param failSilently
  * @return
  */
 static String decodeString(String source, boolean failSilently) {
   try {
     return decodeString(source);
   } catch (URISyntaxException e) {
     throw new IllegalArgumentException(e.getMessage());
   }
 }
コード例 #3
0
ファイル: ARMLinuxLoader.java プロジェクト: katsuster/ememu
  public static void bootFromURIWithDT(
      ARMv5 cpu, RAM ramMain, String dtree, String kimage, String initrd, String cmdline) {
    byte[] cmdlb = cmdline.getBytes();
    // +1: need null char at the end of line
    byte[] cmdalign = new byte[(cmdlb.length + 1 + 3) & ~0x3];
    System.arraycopy(cmdlb, 0, cmdalign, 0, cmdlb.length);

    final int addrRAM = 0x00000000;
    final int addrDT = addrRAM + 0x800000;
    int sizeDT = 0;
    final int addrImage = addrRAM + 0x008000;
    int sizeImage = 0;
    final int addrInitrd = addrRAM + 0x00810000;
    int sizeInitrd = 0;
    boolean initrdExist = !initrd.equals("");

    // tentative boot loader for ARM Linux with Device Tree
    try {
      // load Device Tree Blob
      sizeDT = loadURIResource(new URI(dtree), cpu, addrDT);
      // load Image file
      sizeImage = loadURIResource(new URI(kimage), cpu, addrImage);
      // load Initrd/InitramFS file
      if (initrdExist) {
        sizeInitrd = loadURIResource(new URI(initrd), cpu, addrInitrd);
      }
    } catch (URISyntaxException e) {
      e.printStackTrace(System.err);
      return;
    }

    // report address mapping
    System.out.printf(
        "Address mapping:\n"
            + "  RAM       : 0x%08x\n"
            + "  DeviceTree: 0x%08x - 0x%08x\n"
            + "  Kernel    : 0x%08x - 0x%08x\n"
            + "  InitramFS : 0x%08x - 0x%08x\n",
        addrRAM,
        addrDT,
        addrDT + sizeDT - 1,
        addrImage,
        addrImage + sizeImage - 1,
        addrInitrd,
        addrInitrd + sizeInitrd - 1);

    // r0: 0
    cpu.setReg(0, 0);

    // r1: Do not care.
    cpu.setReg(1, 0);

    // r2: Device tree blob pointer.
    cpu.setReg(2, addrDT);

    // pc: entry of stext
    cpu.setPC(addrImage);
    cpu.setJumped(false);
  }
コード例 #4
0
ファイル: FTPFile.java プロジェクト: solitaryreaper/IRODS
 /**
  * Constructs a <tt>file:</tt> URI that represents this abstract pathname.
  *
  * <p>The exact form of the URI is system-dependent. If it can be determined that the file denoted
  * by this abstract pathname is a directory, then the resulting URI will end with a slash.
  *
  * <p>For a given abstract pathname <i>f</i>, it is guaranteed that
  *
  * <blockquote>
  *
  * <tt> new {@link #GeneralFile(java.net.URI) GeneralFile}
  * (</tt><i>&nbsp;f</i><tt>.toURI()).equals(</tt><i>&nbsp;f</i><tt>) </tt>
  *
  * </blockquote>
  *
  * so long as the original abstract pathname, the URI, and the new abstract pathname are all
  * created in (possibly different invocations of) the same Java virtual machine. However, this
  * relationship typically does not hold when a <tt>file:</tt> URI that is created in a virtual
  * machine on one operating system is converted into an abstract pathname in a virtual machine on
  * a different operating system.
  *
  * @return An absolute, hierarchical URI with a scheme equal to <tt>"file"</tt>, a path
  *     representing this abstract pathname, and undefined authority, query, and fragment
  *     components
  * @see #GeneralFile(java.net.URI)
  * @see java.net.URI
  * @see java.net.URI#toURL()
  */
 public URI toURI() {
   try {
     return new URI(toString());
   } catch (URISyntaxException e) {
     if (DEBUG > 0) e.printStackTrace();
   }
   return null;
 }
コード例 #5
0
ファイル: URIHelper.java プロジェクト: vprise/CodenameOne
 /**
  * Since a URI query can contain a single key multiple times, the responding parameter map will
  * contain string values when a key appears only once, and string arrays when they key appears
  * multiple times.
  *
  * @return a map representation of the query portion of the URI.
  */
 public static Hashtable<String, Object> getParameters(URI uri) {
   try {
     return parseQuery(uri.getQuery(), true);
   } catch (URISyntaxException e) {
     // should never get here as URI query will already be validated.
     e.printStackTrace();
     throw new IllegalArgumentException(e.getMessage());
   }
 }
コード例 #6
0
ファイル: Util.java プロジェクト: mickaelistria/rt.equinox.p2
  public static IFileArtifactRepository getAggregatedBundleRepository(
      IProvisioningAgent agent, IProfile profile, int repoFilter) {
    List<IFileArtifactRepository> bundleRepositories = new ArrayList<IFileArtifactRepository>();

    // we check for a shared bundle pool first as it should be preferred over the user bundle pool
    // in a shared install
    IArtifactRepositoryManager manager = getArtifactRepositoryManager(agent);
    if ((repoFilter & AGGREGATE_SHARED_CACHE) != 0) {
      String sharedCache = profile.getProperty(IProfile.PROP_SHARED_CACHE);
      if (sharedCache != null) {
        try {
          URI repoLocation = new File(sharedCache).toURI();
          IArtifactRepository repository = manager.loadRepository(repoLocation, null);
          if (repository != null
              && repository instanceof IFileArtifactRepository
              && !bundleRepositories.contains(repository))
            bundleRepositories.add((IFileArtifactRepository) repository);
        } catch (ProvisionException e) {
          // skip repository if it could not be read
        }
      }
    }

    if ((repoFilter & AGGREGATE_CACHE) != 0) {
      IFileArtifactRepository bundlePool = Util.getBundlePoolRepository(agent, profile);
      if (bundlePool != null) bundleRepositories.add(bundlePool);
    }

    if ((repoFilter & AGGREGATE_CACHE_EXTENSIONS) != 0) {
      List<String> repos = getListProfileProperty(profile, CACHE_EXTENSIONS);
      for (String repo : repos) {
        try {
          URI repoLocation;
          try {
            repoLocation = new URI(repo);
          } catch (URISyntaxException e) {
            // in 1.0 we wrote unencoded URL strings, so try as an unencoded string
            repoLocation = URIUtil.fromString(repo);
          }
          IArtifactRepository repository = manager.loadRepository(repoLocation, null);
          if (repository != null
              && repository instanceof IFileArtifactRepository
              && !bundleRepositories.contains(repository))
            bundleRepositories.add((IFileArtifactRepository) repository);
        } catch (ProvisionException e) {
          // skip repositories that could not be read
        } catch (URISyntaxException e) {
          // unexpected, URLs should be pre-checked
          LogHelper.log(new Status(IStatus.ERROR, Activator.ID, e.getMessage(), e));
        }
      }
    }
    return new AggregatedBundleRepository(agent, bundleRepositories);
  }
コード例 #7
0
    @Override
    public void run() {
      try {
        Thread.sleep(3000);

        String uberdustServerDnsName = config.getString("uberdustcoapserver.dnsName");
        if (uberdustServerDnsName == null) {
          throw new Exception("Property uberdustcoapserver.dnsName not set.");
        }

        int uberdustServerPort = config.getInt("uberdustcoapserver.port", 0);
        if (uberdustServerPort == 0) {
          throw new Exception("Property uberdustcoapserver.port not set.");
        }

        InetSocketAddress uberdustServerSocketAddress =
            new InetSocketAddress(InetAddress.getByName(uberdustServerDnsName), uberdustServerPort);

        String baseURI = config.getString("baseURIHost", "localhost");
        CoapRequest fakeRequest =
            new CoapRequest(
                MsgType.NON, Code.POST, new URI("coap://" + baseURI + ":5683/here_i_am"));

        CoapNodeRegistrationServer registrationServer = CoapNodeRegistrationServer.getInstance();
        if (registrationServer == null) {
          log.error("NULL!");
        }
        registrationServer.receiveCoapRequest(fakeRequest, uberdustServerSocketAddress);
      } catch (InterruptedException e) {
        e.printStackTrace();
      } catch (UnknownHostException e) {
        e.printStackTrace();
      } catch (URISyntaxException e) {
        e
            .printStackTrace(); // To change body of catch statement use File | Settings | File
                                // Templates.
      } catch (InvalidMessageException e) {
        e
            .printStackTrace(); // To change body of catch statement use File | Settings | File
                                // Templates.
      } catch (InvalidOptionException e) {
        e
            .printStackTrace(); // To change body of catch statement use File | Settings | File
                                // Templates.
      } catch (ToManyOptionsException e) {
        e
            .printStackTrace(); // To change body of catch statement use File | Settings | File
                                // Templates.
      } catch (Exception e) {
        e
            .printStackTrace(); // To change body of catch statement use File | Settings | File
                                // Templates.
      }
    }
コード例 #8
0
  public static WMSCapabilities retrieve(URI uri) throws Exception {
    try {
      CapabilitiesRequest request = new CapabilitiesRequest(uri);

      return new WMSCapabilities(request);
    } catch (URISyntaxException e) {
      e.printStackTrace();
    } catch (MalformedURLException e) {
      e.printStackTrace();
    }

    return null;
  }
コード例 #9
0
ファイル: JStravaV3.java プロジェクト: justinhrobbins/JStrava
  private String deleteResult(String URL) {
    StringBuilder sb = new StringBuilder();
    sb.append(URL);
    try {

      URI uri = new URI(String.format(sb.toString()));
      URL url = uri.toURL();

      HttpURLConnection conn = (HttpURLConnection) url.openConnection();

      conn.setRequestMethod("DELETE");
      conn.setRequestProperty("Accept", "application/json");
      conn.setRequestProperty("Authorization", "Bearer " + getAccessToken());
      if (conn.getResponseCode() != 204) {
        throw new RuntimeException(
            "Failed : HTTP error code : "
                + conn.getResponseCode()
                + " - "
                + conn.getResponseMessage());
      }

      BufferedReader br = new BufferedReader(new InputStreamReader((conn.getInputStream())));

      String output;
      sb = new StringBuilder();
      while ((output = br.readLine()) != null) {
        sb.append(output);
      }

      conn.disconnect();

    } catch (IOException e) {

      e.printStackTrace();
      return null;
    } catch (URISyntaxException e) {
      e.printStackTrace();
      return null;
    }
    return sb.toString();
  }
コード例 #10
0
ファイル: URLUtils.java プロジェクト: krogoth/scribe-java
 public static String convertUrlToBaseStringURI(URL url) {
   URI uri = null;
   try {
     uri = url.toURI();
   } catch (URISyntaxException e1) {
     e1.printStackTrace();
   }
   String scheme = uri.getScheme().toLowerCase();
   String host = uri.getHost().toLowerCase();
   int port = uri.getPort();
   if ((scheme.equals(HTTP_PROTOCOL) && port == HTTP_DEFAULT_PORT)
       || (scheme.equals(HTTPS_PROTOCOL) && port == HTTPS_DEFAULT_PORT)) {
     port = -1;
   }
   URI baseUri = null;
   try {
     baseUri = new URI(scheme, null, host, port, uri.getPath(), null, null);
   } catch (URISyntaxException e) {
     e.printStackTrace();
   }
   return baseUri.toString();
 }
コード例 #11
0
ファイル: URI.java プロジェクト: sourcewarehouse/JCGO
  /**
   * Attempts to parse this URI's authority component, if defined, into user-information, host, and
   * port components. The purpose of this method was to disambiguate between some authority
   * sections, which form invalid server-based authories, but valid registry based authorities. In
   * the updated RFC 3986, the authority section is defined differently, with registry-based
   * authorities part of the host section. Thus, this method is now simply an explicit way of
   * parsing any authority section.
   *
   * @return the URI, with the authority section parsed into user information, host and port
   *     components.
   * @throws URISyntaxException if the given string violates RFC 2396
   */
  public URI parseServerAuthority() throws URISyntaxException {
    if (rawAuthority != null) {
      if (AUTHORITY_PATTERN == null) AUTHORITY_PATTERN = Pattern.compile(AUTHORITY_REGEXP);
      Matcher matcher = AUTHORITY_PATTERN.matcher(rawAuthority);

      if (matcher.matches()) {
        rawUserInfo = getURIGroup(matcher, AUTHORITY_USERINFO_GROUP);
        rawHost = getURIGroup(matcher, AUTHORITY_HOST_GROUP);

        String portStr = getURIGroup(matcher, AUTHORITY_PORT_GROUP);

        if (portStr != null)
          try {
            port = Integer.parseInt(portStr);
          } catch (NumberFormatException e) {
            URISyntaxException use =
                new URISyntaxException(string, "doesn't match URI regular expression");
            use.initCause(e);
            throw use;
          }
      } else throw new URISyntaxException(string, "doesn't match URI regular expression");
    }
    return this;
  }
コード例 #12
0
ファイル: ARMLinuxLoader.java プロジェクト: katsuster/ememu
  public static void bootFromURI(
      ARMv5 cpu, RAM ramMain, String kimage, String initrd, String cmdline) {
    byte[] cmdlb = cmdline.getBytes();
    // +1: need null char at the end of line
    byte[] cmdalign = new byte[(cmdlb.length + 1 + 3) & ~0x3];
    System.arraycopy(cmdlb, 0, cmdalign, 0, cmdlb.length);

    final int addrRAM = 0x00000000;
    final int addrAtagsStart = addrRAM + 0x800000;
    int addrAtags = addrAtagsStart;
    final int addrImage = addrRAM + 0x00008000;
    int sizeImage = 0;
    final int addrInitrd = addrRAM + 0x00810000;
    int sizeInitrd = 0;
    boolean initrdExist = !initrd.equals("");

    // tentative boot loader for ARM Linux
    try {
      // load Image file
      sizeImage = loadURIResource(new URI(kimage), cpu, addrImage);
      // load Initrd/InitramFS file
      if (initrdExist) {
        sizeInitrd = loadURIResource(new URI(initrd), cpu, addrInitrd);
      }
    } catch (URISyntaxException e) {
      e.printStackTrace(System.err);
      return;
    }

    // report address mapping
    System.out.printf(
        "Address mapping:\n"
            + "  RAM   : 0x%08x\n"
            + "  Kernel: 0x%08x - 0x%08x\n"
            + "  Initrd: 0x%08x - 0x%08x\n"
            + "  ATAGS : 0x%08x - 0x%08x\n",
        addrRAM,
        addrImage,
        addrImage + sizeImage - 1,
        addrInitrd,
        addrInitrd + sizeInitrd - 1,
        addrAtags,
        addrAtags + 4096 - 1);

    // r0: 0
    cpu.setReg(0, 0);

    // r1: machine type
    // ARM-Versatile PB
    cpu.setReg(1, 0x00000183);
    // ARM-Versatile AB
    // cpu.setReg(1, 0x0000025e);

    // r2: ATAGS pointer.
    cpu.setReg(2, addrAtags);
    {
      // ATAG_CORE, size, tag, [flags, pagesize, rootdev]
      cpu.write32_a32(addrAtags + 0x00, 0x00000005);
      cpu.write32_a32(addrAtags + 0x04, ATAG_CORE);
      // bit 0: read only
      cpu.write32(addrAtags + 0x08, 0x00000001);
      cpu.write32(addrAtags + 0x0c, 0x00001000);
      cpu.write32(addrAtags + 0x10, 0x00000000);
      addrAtags += 0x14;

      // ATAG_MEM, size, tag, size, start
      cpu.write32_a32(addrAtags + 0x00, 0x00000004);
      cpu.write32_a32(addrAtags + 0x04, ATAG_MEM);
      cpu.write32_a32(addrAtags + 0x08, ramMain.getSize());
      cpu.write32_a32(addrAtags + 0x0c, addrRAM);
      addrAtags += 0x10;

      // ATAG_INITRD2, size, tag, size, start
      if (initrdExist) {
        cpu.write32_a32(addrAtags + 0x00, 0x00000004);
        cpu.write32_a32(addrAtags + 0x04, ATAG_INITRD2);
        cpu.write32_a32(addrAtags + 0x08, addrInitrd);
        cpu.write32_a32(addrAtags + 0x0c, sizeInitrd);
        addrAtags += 0x10;
      }

      // ATAG_CMDLINE
      cpu.write32_a32(addrAtags + 0x00, 0x00000002 + cmdalign.length / 4);
      cpu.write32_a32(addrAtags + 0x04, ATAG_CMDLINE);
      for (int i = 0; i < cmdalign.length; i++) {
        cpu.write8_a32(addrAtags + 0x08 + i, cmdalign[i]);
      }
      addrAtags += 0x08 + cmdalign.length;

      // ATAG_SERIAL, size, tag, low, high
      cpu.write32_a32(addrAtags + 0x00, 0x00000004);
      cpu.write32_a32(addrAtags + 0x04, ATAG_SERIAL);
      cpu.write32_a32(addrAtags + 0x08, 0x00000020);
      cpu.write32_a32(addrAtags + 0x0c, 0x00000030);
      addrAtags += 0x10;

      // ATAG_REVISION, size, tag, rev
      cpu.write32_a32(addrAtags + 0x00, 0x00000003);
      cpu.write32_a32(addrAtags + 0x04, ATAG_REVISION);
      cpu.write32_a32(addrAtags + 0x08, 0x00000010);
      addrAtags += 0x0c;

      // ATAG_NONE, size, tag
      // It is unique in that its size field in the header
      // should be set to 0 (not 2).
      cpu.write32_a32(addrAtags + 0x00, 0x00000000);
      cpu.write32_a32(addrAtags + 0x04, ATAG_NONE);
      addrAtags += 0x08;
    }

    // pc: entry of stext
    cpu.setPC(addrImage);
    cpu.setJumped(false);
  }
コード例 #13
0
  private void test_image_picker(WebDriver driver) {
    // Check both files exist
    File f1 = null;
    File f2 = null;
    try {
      ClassLoader cl = ImagePickerTest.class.getClassLoader();
      f1 = new File(cl.getResource("image_picker_1.png").toURI());
      assertTrue(f1.exists());
      f2 = new File(cl.getResource("image_picker_2.png").toURI());
      assertTrue(f2.exists());
    } catch (URISyntaxException e) {
      e.printStackTrace();
    }
    assertNotNull(f1);
    assertNotNull(f2);

    // Login
    CStudioSeleniumUtil.try_login(
        driver, CStudioSeleniumUtil.AUTHOR_USER, CStudioSeleniumUtil.AUTHOR_PASSWORD, true);

    // Navigate to Widget
    CStudioSeleniumUtil.navigate_to_image_picker_widget(driver);

    // Upload right file size
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcAltTextTest-imageButton"));

    // Check popup dialog appears
    WebElement popup = driver.findElement(By.id("cstudio-wcm-popup-div_c"));
    assertTrue(popup.isDisplayed());

    WebElement input =
        driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input"));
    input.sendKeys(f1.getAbsolutePath());

    WebElement upload =
        driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input[2]"));
    upload.click();

    new WebDriverWait(driver, CStudioSeleniumUtil.SHORT_TIMEOUT)
        .until(
            new ExpectedCondition<Boolean>() {
              public Boolean apply(WebDriver d) {
                WebElement e = d.findElement(By.id("xf-4$xf-20$imageSrcAltTextTest$xf-206$$a"));
                return e != null && e.getAttribute("class").contains("xforms-alert-inactive");
              }
            });
    WebElement mark = driver.findElement(By.id("xf-4$xf-20$imageSrcAltTextTest$xf-206$$a"));
    assertTrue(mark.getAttribute("class").contains("xforms-alert-inactive"));

    // Delete uploaded image
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcAltTextTest-deleteButton"));
    WebElement filename =
        driver.findElement(By.id("xf-4$xf-20$imageSrcAltTextTest$xf-206-filename"));
    assertTrue(filename.getText().equals("250W X 130H"));

    // Upload any image
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcTest-imageButton"));

    // Check popup dialog appears
    popup = driver.findElement(By.id("cstudio-wcm-popup-div_c"));
    assertTrue(popup.isDisplayed());

    input = driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input"));
    input.sendKeys(f2.getAbsolutePath());

    upload = driver.findElement(By.xpath("/html/body/div[3]/div/div[2]/div/div/div/form/input[2]"));
    upload.click();

    new WebDriverWait(driver, CStudioSeleniumUtil.SHORT_TIMEOUT)
        .until(
            new ExpectedCondition<Boolean>() {
              public Boolean apply(WebDriver d) {
                WebElement e = d.findElement(By.id("xf-4$xf-20$imageSrcTest$xf-237-filename"));
                return e != null && e.getText().equals("/static-assets/images/image_picker_2.png");
              }
            });

    // Delete uploaded image
    CStudioSeleniumUtil.click_on(driver, By.id("xf-4$xf-20$imageSrcTest-deleteButton"));
    filename = driver.findElement(By.id("xf-4$xf-20$imageSrcTest$xf-237-filename"));
    assertTrue(filename.getText().equals(""));

    // Close driver
    CStudioSeleniumUtil.exit(driver);
  }