Package com.sun.jersey.api.client

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


  @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

  @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

  @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);
  }

}
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

        try{
            // create a client and then a web resource
            Client client = Client.create();
            WebResource webResource = client.resource(JSonURL);
            // create a response object with the specified accepted Media-Type
            ClientResponse clientResponse = webResource.accept("application/json").get(ClientResponse.class);
            if (clientResponse.getStatus() != 200){
                throw new RuntimeException("Failed to fetch data :: HTTP request status: "+ clientResponse.getStatus());
            }
            // retrieve the json data
            String jsonData = clientResponse.getEntity(String.class);
View Full Code Here

    protected MavenArtifact lookupMetadataForChecksum(String checksum) throws ConverterException {
        final String queryUrl = MAVEN_CENTRAL_SHA_1_QUERY_URL + checksum;

        final Client client = Client.create();
        final WebResource webResource = client.resource(queryUrl);
        final ClientResponse response = webResource.accept("application/json").get(ClientResponse.class);

        if (response.getStatus() != 200) {
          throw new RuntimeException("Failed : HTTP error code : " + response.getStatus());
        }
View Full Code Here

        queryParams.add("media", MEDIA);
        queryParams.add("limit", Integer.toString(LIMIT));
        queryParams.add("output", "json");
        webResource = webResource.queryParams(queryParams);

        ClientResponse response = webResource.accept("text/plain").get(ClientResponse.class);
        logger.info("HTTP response status: "+response.getStatus());

        InputStream is = response.getEntityInputStream();
        Reader reader = new InputStreamReader(is);
        Gson gson = new Gson();
View Full Code Here

        return builder(path, MediaType.APPLICATION_JSON_TYPE);
    }

    private Builder builder(String path, final MediaType accept) {
        WebResource resource = client.resource(uri(pathOrAbsolute(path)));
        return resource.accept(accept);
    }

    private String pathOrAbsolute(String path) {
        if (path.startsWith("http://"))
            return path;
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

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.