Package com.sun.jersey.api.client

Examples of com.sun.jersey.api.client.WebResource.type()


        Form form = new Form();
        form.add("cookie", "myId");
        form.add("service", "大成大樓888");
        form.add("hash", "大成大樓888");

        ClientResponse response = r.type(MediaType.APPLICATION_FORM_URLENCODED).post(ClientResponse.class, form);
        System.out.println(response.getEntity(String.class));



    }
View Full Code Here


        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        ObjectOutputStream oos = new ObjectOutputStream(baos);
        oos.writeObject(cust);
        oos.flush();

        ClientResponse response = wr.type("application/x-java-serialized-object").post(ClientResponse.class, baos.toByteArray());
        Assert.assertEquals(201, response.getStatus()); // 201 = created
        System.out.println("Location: " + response.getHeaders().get("Location"));


        // Get the new customer
View Full Code Here

        baos = new ByteArrayOutputStream();
        oos = new ObjectOutputStream(baos);
        oos.writeObject(cust);
        oos.flush();

        response = wr.type("application/x-java-serialized-object").put(ClientResponse.class, baos.toByteArray());

        Assert.assertEquals(204, response.getStatus()); // 204 = no content

        // Show the update
        System.out.println("**** After Update ***");
 
View Full Code Here

                + "<state>N/A</state>"
                + "<zip>12000</zip>"
                + "<country>Czech Republic</country>"
                + "</customer>";

        ClientResponse response = wr.type(MediaType.APPLICATION_XML).post(ClientResponse.class, newCustomer);

        Assert.assertEquals(201, response.getStatus()); // 201 = created
        System.out.println("Location: " + response.getHeaders().get("Location"));

View Full Code Here

        customer.setState("MA");
        customer.setZip("01711");
        customer.setCountry("USA");

        wr = c.resource(customers.getHref());
        response = wr.type(MediaType.APPLICATION_XML).post(ClientResponse.class, customer);
        Assert.assertEquals(201, response.getStatus());

        Link orders = shoppingLinks.get("orders");

        Order order = new Order();
View Full Code Here

        order.getLineItems().add(item);

        System.out.println();
        System.out.println("** Create an order through this URL: " + orders.getHref());
        wr = c.resource(orders.getHref());
        response = wr.type(MediaType.APPLICATION_XML).post(ClientResponse.class, order);
        Assert.assertEquals(201, response.getStatus());
        String createdOrderUrl = (String) response.getHeaders().getFirst("Location");

        System.out.println();
        System.out.println("** New list of orders");
View Full Code Here

        resource = resource.queryParam("key", apiKey.get().toString());
      }
      boolean threw = true;
      try {
        // TODO(gak): make the json part happen automagically
        resource.type(APPLICATION_JSON_TYPE).post(gson.toJson(ImmutableList.of(trial)));
        // only set the run id if a result has been successfully uploaded
        runId = Optional.of(trial.run().id());
        threw = false;
      } catch (ClientHandlerException e) {
        logUploadFailure(trial, e);
View Full Code Here

    return resource;
  }

  private WebResource jsonResource(String url) {
    WebResource resource = resource(url);
    resource.type(MediaType.APPLICATION_JSON);
    return resource;
  }

  /**
   * Get a complete configuration, with all values
View Full Code Here

  @Test
  public void testRegistration() throws Exception {
    RegistrationResponse response;
    Client client = createTestClient();
    WebResource webResource = client.resource(base_url + "test/register");
    response = webResource.type(MediaType.APPLICATION_JSON)
        .post(RegistrationResponse.class, createDummyJSONRegister());
    Assert.assertEquals(RegistrationStatus.OK, response.getResponseStatus());
  }

  protected Client createTestClient() {
View Full Code Here

  @Test
  public void testHeartbeat() throws Exception {
    HeartBeatResponse response;
    Client client = createTestClient();
    WebResource webResource = client.resource(base_url + "test/heartbeat");
    response = webResource.type(MediaType.APPLICATION_JSON)
        .post(HeartBeatResponse.class, createDummyHeartBeat());
    assertEquals(response.getResponseId(), 0L);
  }

  @Test
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.