Package com.sun.jersey.api.client

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


  @Private
  @VisibleForTesting
  public ClientResponse doPostingEntities(TimelineEntities entities) {
    WebResource webResource = client.resource(resURI);
    return webResource.accept(MediaType.APPLICATION_JSON)
        .type(MediaType.APPLICATION_JSON)
        .post(ClientResponse.class, entities);
  }

  private static class TimelineAuthenticatedURLConnectionFactory
View Full Code Here


  @Test
  public void testInvalidUri2() throws JSONException, Exception {
    WebResource r = resource();
    String responseStr = "";
    try {
      responseStr = r.accept(MediaType.APPLICATION_JSON).get(String.class);
      fail("should have thrown exception on invalid uri");
    } catch (UniformInterfaceException ue) {
      ClientResponse response = ue.getResponse();
      assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
      WebServicesTestUtils.checkStringMatch(
View Full Code Here

 
  public void getGameList() throws JSONException {
    Client c = Client.create();
    WebResource r = c.resource("http://192.168.1.33:8080/BattleShip/rest/gameserver/games/1");
      
    String result = r.accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
   
    JSONObject gamesJSON = new JSONObject(result);
    JSONArray games = gamesJSON.getJSONArray("game");
    for (int i=0 ; i< games.length();i++) {
      JSONObject game = (JSONObject)games.get(i);
View Full Code Here

  public void createGame() {
   
    Client c = Client.create();
    WebResource r = c.resource("http://localhost:8080/BattleShip/rest/server/creategame/1");
      
    String result = r.accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
    System.out.println(result);
  }
 
  public void joinGame() {
   
View Full Code Here

  public void joinGame() {
   
    Client c = Client.create();
    WebResource r = c.resource("http://localhost:8080/BattleShip/rest/server/join/1903/2");
      
    String result = r.accept(MediaType.APPLICATION_JSON_TYPE).get(String.class);
    System.out.println(result);
  }
 
  public void addShipTest() {
   
View Full Code Here

  @Test
  public void testInvalidUri2() throws JSONException, Exception {
    WebResource r = resource();
    String responseStr = "";
    try {
      responseStr = r.accept(MediaType.APPLICATION_JSON).get(String.class);
      fail("should have thrown exception on invalid uri");
    } catch (UniformInterfaceException ue) {
      ClientResponse response = ue.getResponse();
      assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
      WebServicesTestUtils.checkStringMatch(
View Full Code Here

  @Test
  public void testInvalidUri2() throws JSONException, Exception {
    WebResource r = resource();
    String responseStr = "";
    try {
      responseStr = r.accept(MediaType.APPLICATION_JSON).get(String.class);
      fail("should have thrown exception on invalid uri");
    } catch (UniformInterfaceException ue) {
      ClientResponse response = ue.getResponse();
      assertEquals(Status.NOT_FOUND, response.getClientResponseStatus());
      WebServicesTestUtils.checkStringMatch(
View Full Code Here

    WebResource resource = client.resource(url);

    // Provide filter that will rebuild exception that is sent from server
    resource.addFilter(serverExceptionFilter);

    return resource
      // Sqoop is using JSON for data transfers
      .accept(MediaType.APPLICATION_JSON_TYPE)
      // Transfer client locale to return client specific data
      .acceptLanguage(Locale.getDefault());
  }
View Full Code Here


        // Get XML customer
        System.out.println("*** GET Customer as XML **");
        wr = wr.path("2"); // second customer
        response = wr.accept(MediaType.APPLICATION_XML).get(ClientResponse.class);
        System.out.println("Content-Type: " + response.getHeaders().get("Content-Type"));

        System.out.println(response.getEntity(String.class));

        Assert.assertEquals(200, response.getStatus()); // 200 = ok
View Full Code Here

        Assert.assertEquals(200, response.getStatus()); // 200 = ok


        // Get json
        System.out.println("*** GET Customer as JSON **");
        response = wr.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class);
        System.out.println("Content-Type: " + response.getHeaders().get("Content-Type"));

        System.out.println(response.getEntity(String.class));

        Assert.assertEquals(200, response.getStatus()); // 200 = ok
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.