コード例 #1
0
  /**
   * Returns the parent resource. The parent resource is defined in the sense of hierarchical URIs.
   * If the resource URI is not hierarchical, then an exception is thrown.
   *
   * @return The parent resource.
   */
  public ClientResource getParent() throws ResourceException {
    ClientResource result = null;

    if (getReference().isHierarchical()) {
      result = new ClientResource(this);
      result.setReference(getReference().getParentRef());
    } else {
      throw new ResourceException(
          Status.CLIENT_ERROR_BAD_REQUEST, "The resource URI is not hierarchical.");
    }

    return result;
  }
コード例 #2
0
  /**
   * Returns the child resource defined by its URI relatively to the current resource. The child
   * resource is defined in the sense of hierarchical URIs. If the resource URI is not hierarchical,
   * then an exception is thrown.
   *
   * @param relativeRef The URI reference of the child resource relatively to the current resource
   *     seen as the parent resource.
   * @return The child resource.
   * @throws ResourceException
   */
  public ClientResource getChild(Reference relativeRef) throws ResourceException {
    ClientResource result = null;

    if ((relativeRef != null) && relativeRef.isRelative()) {
      result = new ClientResource(this);
      result.setReference(new Reference(getReference().getTargetRef(), relativeRef).getTargetRef());
    } else {
      throw new ResourceException(
          Status.CLIENT_ERROR_BAD_REQUEST, "The child URI is not relative.");
    }

    return result;
  }
コード例 #3
0
ファイル: TestRestCompute.java プロジェクト: nilupa/occi4java
  @Test
  public void testGetCompute() {
    Compute compute = null;
    try {
      compute = new Compute(Architecture.x64, 2, "TestCase", 200, 20, State.active, null);
    } catch (NumberFormatException e) {
      e.printStackTrace();
    } catch (IllegalArgumentException e) {
      e.printStackTrace();
    } catch (URISyntaxException e) {
      e.printStackTrace();
    } catch (NamingException e) {
      e.printStackTrace();
    }
    // test if compute ist not null
    Assert.assertNotNull(compute);
    // connect to api
    clientResource.setReference(
        OcciConfig.getInstance().config.getString("occi.server.location")
            + "compute/"
            + compute.getId());
    clientResource.setHostRef(
        OcciConfig.getInstance().config.getString("occi.server.location")
            + "compute/"
            + compute.getId());
    // create new representation
    Representation representation = null;
    try {
      // send post request
      representation = clientResource.get();
    } catch (Exception ex) {
      System.out.println("Failed to execute GET request: " + ex.getMessage());
    }
    Assert.assertNotNull(representation);
    // get request and print it in debugger
    Request request = Request.getCurrent();
    System.out.println(request.toString() + "\n\n");
    System.out.println("--------------------------------");
    // get current response
    Response response = Response.getCurrent();
    Assert.assertNotNull(response);
    System.out.println("Response: " + response.toString());

    try {
      representation.write(System.out);
    } catch (IOException e) {
      System.out.println(e.getMessage());
    }
    System.out.println("\n--------------------------------");
  }
コード例 #4
0
ファイル: TestRestCompute.java プロジェクト: nilupa/occi4java
  // TODO Die Parameter beim Request werden nicht korrekt übergeben. Keine
  // Ahnung woran es liegt.
  @Test(enabled = false)
  public void testPostCompute() {
    // connect to api
    clientResource.setReference(
        OcciConfig.getInstance().config.getString("occi.server.location") + "compute");
    // Tests if client resource is connected to api
    Assert.assertNotNull(clientResource);
    // try to create a compute resource
    String architecture = "x86";
    String cores = "20";
    String hostname = "Ubuntu";
    String speed = "2000000";
    String memory = "1024";
    String category = "compute";
    // create new request and add all attributes
    Form form = new Form();
    form.add("occi.compute.architecture", architecture);
    form.add("occi.compute.cores", cores);
    form.add("occi.compute.hostname", hostname);
    form.add("occi.compute.speed", speed);
    form.add("occi.compute.memory", memory);
    form.add("category", category);
    System.out.println("\n FORM " + form.toString());
    // create new representation
    Representation representation = null;
    try {
      // send post request
      representation = clientResource.post(form.toString(), MediaType.TEXT_PLAIN);
    } catch (Exception ex) {
      System.out.println("Failed to execute POST request " + ex.getMessage());
    }
    Assert.assertNotNull(representation);
    // get request and print it in debugger
    Request request = Request.getCurrent();
    System.out.println(request.toString() + "\n\n" + form.getMatrixString());
    System.out.println("--------------------------------");
    // get current response
    Response response = Response.getCurrent();
    Assert.assertNotNull(response);
    System.out.println("Response: " + response.toString());

    try {
      representation.write(System.out);
    } catch (IOException e) {
      System.out.println(e.getMessage());
    }
    System.out.println("\n--------------------------------");
  }