Package javax.ws.rs.client

Examples of javax.ws.rs.client.Client


    }
    if ( !dataStore.exists( EntitiesDesignDocument.DOCUMENT_ID, true ) ) {
      dataStore.saveDocument( new EntitiesDesignDocument() );
    }

    Client client = ClientBuilder.newBuilder().build();
    WebTarget target = client.target( dataStore.getDatabaseIdentifier().getDatabaseUri() );
    ResteasyWebTarget rtarget = (ResteasyWebTarget) target;

    return rtarget.proxy( DatabaseTestClient.class );
  }
View Full Code Here


    return configuration;
  }

  private static void createServerAdminUser() {
    Client client = ClientBuilder.newClient();
    WebTarget target = client.target( serverUri + "/_config/admins/" + serverAdminUser );
    target.request().put( Entity.text( "\"" + serverAdminPassword + "\"" ) ).close();
  }
View Full Code Here

        System.out.println("URL: " + url);
        System.out.println("MediaType: " + mediaType.toString());

        // Using the JAX-RS client, initiate a request
        // using the url as the target
        Client client = ClientBuilder.newClient();
        Response response = client.target(url)
                .register(JsonObjectProvider.class)
                .request(mediaType)
                .get();

        // Check the HTTP status of the request
View Full Code Here

    @Test
    public void testConcurrency() throws IOException, InterruptedException, Exception {
        final int concurrencyLevel = 40;
        // snippet client creation
        final Client client = AsyncClientBuilder.newBuilder().build();
        // end of snippet
        final CountDownLatch cdl = new CountDownLatch(concurrencyLevel);
        for (int i = 0; i < concurrencyLevel; i++)
            new Fiber<Void>(new SuspendableRunnable() {
                @Override
                public void run() throws SuspendExecution, InterruptedException {
                    // snippet http call
                    String response = client.target("http://localhost:8080").request().get(String.class);
                    // end of snippet
                    assertEquals("testGet", response);
                    System.out.println("done "+cdl.getCount());
                    cdl.countDown();
                }
View Full Code Here

        }
    }

    @Test
    public void testSSE() throws IOException, InterruptedException, DeploymentException, ExecutionException {
        final Client client = ClientBuilder.newBuilder().register(SseFeature.class).build();
        Response resp = client.target("http://localhost:8080/ssechannel").request().get();
        NewCookie session = resp.getCookies().get(JSESSIONID);
        final EventInput eventInput = resp.readEntity(EventInput.class);
        final SettableFuture<String> res = new SettableFuture<>();
        new Thread(new Runnable() {
            @Override
            public void run() {
                while (!eventInput.isClosed() && !res.isDone()) {
                    final InboundEvent inboundEvent = eventInput.read();
                    if (inboundEvent == null)
                        break;
                    res.set(inboundEvent.readData(String.class));
                }
            }
        }).start();
        client.target("http://localhost:8080/ssepublish").request().cookie(session).post(Entity.text("test it"));
        assertEquals("test it", res.get());
    }
View Full Code Here

   }

   @Test
   public void testGetRequest()
   {
      Client client = clientFactory.createClient();
      String response = client.target("http://www.iheartquotes.com/api/v1/random").request(MediaType.TEXT_PLAIN_TYPE)
               .get(String.class);
      Assert.assertNotNull(response);
      Assert.assertFalse(response.isEmpty());

   }
View Full Code Here

  private static void all() {
    System.out.println("-- ALL --");
    System.out.println("--------------------------");

    URI rootURI = UriBuilder.fromUri("http://localhost/chapter15-service-1.0/rs/book").port(8080).build();
    Client client = ClientBuilder.newClient();
    Response response;

    System.out.println("--- GET all books in XML");
    response = client.target(rootURI).request(MediaType.APPLICATION_XML).get();
    System.out.println("\tStatus : " + response.getStatus());
    System.out.println(response.readEntity(String.class));

    System.out.println("--- POST new book");
    Book book = new Book("The Hitchhiker's Guide to the Galaxy", 12.5F, "Science fiction comedy book", "1-84023-742-2", 354, false);
    response = client.target(rootURI).request().post(Entity.entity(book, MediaType.APPLICATION_XML));
    System.out.println("\tStatus : " + response.getStatus());
    URI bookURI = response.getLocation();
    System.out.println("\tLocation : " + bookURI);
    book.setId(response.getLocation().toString().split("/")[6]);

    System.out.println("--- GET the created book in JSon");
    System.out.println(client.target(bookURI).request(MediaType.APPLICATION_JSON).get(String.class));

    System.out.println("-- PUT updated book");
    System.out.println("--------------------------");
    book.setTitle("Updated title");
    response = client.target(rootURI).request().put(Entity.entity(book, MediaType.APPLICATION_XML));
    System.out.println("\tStatus : " + response.getStatus());

    System.out.println("--- GET the created book in XML");
    System.out.println(client.target(bookURI).request(MediaType.APPLICATION_XML).get(String.class));

    System.out.println("--- DELETE the book");
    response = client.target(rootURI).path(book.getId()).request().delete();
    System.out.println("\tStatus : " + response.getStatus());

    System.out.println("--- GET the deted book (404-Not Found)");
    response = client.target(bookURI).request(MediaType.APPLICATION_XML).get();
    System.out.println("\tStatus : " + response.getStatus());
  }
View Full Code Here

  // ======================================

  @Test
  public void shouldCheckForH2G2Verbose() throws URISyntaxException {

    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://localhost:8282/03/book");
    assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.TEXT_PLAIN).get().getStatus());
    URI uri = new URI("http://localhost:8282/03/book");
    target = client.target(uri);
    assertEquals(Response.Status.OK.getStatusCode(), target.request(MediaType.TEXT_PLAIN).get().getStatus());
  }
View Full Code Here

  }

  @Test
  public void shouldCheckForH2G2WithWebTarget() {

    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://localhost:8282/03/book");
    Invocation.Builder builder = target.request(MediaType.TEXT_PLAIN);
    Response response = builder.get();
    String entity = response.readEntity(String.class);

    assertEquals("H2G2", entity);
View Full Code Here

  }

  @Test
  public void shouldCheckForH2G2WithInvocation() {

    Client client = ClientBuilder.newClient();
    WebTarget target = client.target("http://localhost:8282/03/book");
    Invocation invocation = target.request(MediaType.TEXT_PLAIN).buildGet();
    Response response = invocation.invoke();
    String entity = response.readEntity(String.class);

    assertEquals("H2G2", entity);
View Full Code Here

TOP

Related Classes of javax.ws.rs.client.Client

Copyright © 2018 www.massapicom. 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.