Package com.sun.jersey.api.client

Examples of com.sun.jersey.api.client.ClientResponse


  }

  @Test
  public void get() {
    // First get a non existing resource server
    ClientResponse response = webResource.path("-1").header("Authorization", authorizationBearer(ACCESS_TOKEN)).get(ClientResponse.class);
    assertEquals("Random id should return nothing", 404, response.getStatus());

    // Insert some random one.
    ResourceServer existingResourceServer = putSomeResourceServer();

    // Get it again.
View Full Code Here


    // create a random resourceServer
    ResourceServer existingResourceServer = putSomeResourceServer();

    // Delete it again.
    String id = String.valueOf(existingResourceServer.getId());
    ClientResponse response = webResource.path(id).header("Authorization", authorizationBearer(ACCESS_TOKEN)).delete(ClientResponse.class);

    // Make sure that the response is a 'no content' one
    assertEquals(204, response.getStatus());

    // And make sure it is not found anymore afterwards.
    ClientResponse responseFromGet = webResource.path(id).header("Authorization", authorizationBearer(ACCESS_TOKEN))
        .delete(ClientResponse.class);
    assertEquals(404, responseFromGet.getStatus());
  }
View Full Code Here

    assertEquals(404, responseFromGet.getStatus());
  }

  @Test
  public void stats() {
    final ClientResponse response = webResource.path("stats").header("Authorization", authorizationBearer(ACCESS_TOKEN))
        .get(ClientResponse.class);
    assertEquals(200, response.getStatus());

    StatisticsResponse entity = response.getEntity(StatisticsResponse.class);
    assertTrue(entity.getResourceServers().size() > 0);
    assertNotNull(entity.getResourceServers().get(0).getName());
  }
View Full Code Here

    assertNotNull(entity.getResourceServers().get(0).getName());
  }

  @Test
  public void principal() {
    final ClientResponse response = webResource.path("principal").header("Authorization", authorizationBearer(ACCESS_TOKEN))
            .get(ClientResponse.class);
    assertEquals(200, response.getStatus());

    AuthenticatedPrincipal principal = response.getEntity(AuthenticatedPrincipal.class);
    assertEquals("admin-enduser",principal.getName());
  }
View Full Code Here

        .path("client");
  }

  @Test
  public void getNonExisting() {
    ClientResponse response = webResource
        .path("-1")
        .header("Authorization", authorizationBearer(ACCESS_TOKEN))
        .get(ClientResponse.class);
    assertEquals(404, response.getStatus());
  }
View Full Code Here

  @Test
  public void getAll() {
    putSomeClient();
    putSomeClient();

    ClientResponse response = webResource
        .header("Authorization", authorizationBearer(ACCESS_TOKEN))
        .get(ClientResponse.class);
    assertEquals(200, response.getStatus());
    assertTrue(response.getEntity(Client[].class).length > 1);
  }
View Full Code Here

  @Test
  public void putInvalidScopes() {
    Client c = buildClient();
    c.setScopes(Arrays.asList("invalidScope", "read", "write"));
    ClientResponse clientResponse = webResource
        .header("Authorization", authorizationBearer(ACCESS_TOKEN))
        .put(ClientResponse.class, c);
    assertThat("Server should not accept a client with scopes that are not a subset of the resourceServers scope",
        clientResponse.getStatus(), equalTo(400));
    final ValidationErrorResponse validationErrorResponse = clientResponse.getEntity(ValidationErrorResponse.class);
    assertThat(validationErrorResponse.getViolations().size(), equalTo(1));
    assertThat(validationErrorResponse.getViolations().get(0), containsString("Client should only contain scopes that its resource server defines"));
  }
View Full Code Here

  @Test
  public void delete() {
    Client c = putSomeClient();
    String id = String.valueOf(c.getId());
    ClientResponse deleteResponse = webResource
        .path(id)
        .header("Authorization", authorizationBearer(ACCESS_TOKEN))
        .delete(ClientResponse.class);
    assertEquals(204, deleteResponse.getStatus());

    ClientResponse getResponse = webResource
        .path(id)
        .header("Authorization", authorizationBearer(ACCESS_TOKEN))
        .get(ClientResponse.class);
    assertEquals(404, getResponse.getStatus());
  }
View Full Code Here

      if (verifyTokenResponse != null) {
        return verifyTokenResponse;
      }
    }
    if (verifyTokenResponse == null) {
      ClientResponse res = client.resource(String.format("%s?access_token=%s", authorizationServerUrl, accessToken))
              .header(HttpHeaders.AUTHORIZATION, "Basic " + authorizationValue).accept("application/json")
              .get(ClientResponse.class);
      try {
        String responseString = res.getEntity(String.class);
        int statusCode = res.getClientResponseStatus().getStatusCode();
        LOG.debug("Got verify token response (status: {}): '{}'", statusCode, responseString);
        if (statusCode == HttpServletResponse.SC_OK) {
          verifyTokenResponse = objectMapper.readValue(responseString, VerifyTokenResponse.class);
        }
      } catch (Exception e) {
View Full Code Here

    }

    @Override
    public ClientResponse handle(final ClientRequest clientRequest) throws ClientHandlerException {
        clientRequestInterceptor.handle(new JerseyClientRequestAdapter(clientRequest), serviceName);
        final ClientResponse clientResponse = getNext().handle(clientRequest);
        clientResponseInterceptor.handle(new JerseyClientResponseAdapter(clientResponse));
        return clientResponse;
    }
View Full Code Here

TOP

Related Classes of com.sun.jersey.api.client.ClientResponse

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.