Exemplo n.º 1
1
  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();
  }
Exemplo n.º 2
0
  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);
  }
Exemplo n.º 3
0
 /**
  * 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;
 }
Exemplo n.º 4
0
  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();
  }
Exemplo n.º 5
0
 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();
 }
Exemplo n.º 6
0
  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);
  }
Exemplo n.º 7
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);
  }