Package com.sun.jersey.api.client

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


  }

  protected Document sendGetRequest(String url) {
    LOGGER.debug("calling: {}", url);
    try {
      WebResource webResource = httpClient.resource(url);
      Document response = webResource.get(Document.class);

      logXmlDocumentToDebug("Got response", response);
      return response;
    } catch (Exception e) {
      if(e instanceof SocketTimeoutException) {
View Full Code Here


  }

  protected ClientResponse sendPutRequest(String url) {
    LOGGER.debug("calling: {}", url);
    try {
      WebResource webResource = httpClient.resource(url);
      ClientResponse response = webResource.put(ClientResponse.class);

      LOGGER.debug("Got response: {}", response);
      return response;
    } catch (Exception e) {
      if(e instanceof SocketTimeoutException) {
View Full Code Here

  }

  protected Document sendPostRequest(String url, Document xml) {
    logXmlDocumentToDebug("submitting", xml);
    try {
      WebResource webResource = httpClient.resource(url);
      Document response = webResource.accept(MediaType.APPLICATION_XML)
          .header("Content-Type", "application/xml")
          .post(Document.class, xml);
      logXmlDocumentToDebug("Got response", response);
      return response;
    } catch (UniformInterfaceException e) {
View Full Code Here

    client = Client.create(clientConfig);
  }

  @Override
  public <T> OpenStackResponse request(OpenStackRequest<T> request) {
    WebResource target = client.resource(request.endpoint()).path(request.path());
    for(Map.Entry<String, List<Object> > entry : request.queryParams().entrySet()) {
      for (Object o : entry.getValue()) {
        target = target.queryParam(entry.getKey(), String.valueOf(o));
      }
    }
    target.addFilter(logger);
    MultivaluedMap<String, Object> headers = new OutBoundHeaders();
    for(Map.Entry<String, List<Object>> h : request.headers().entrySet()) {
      for(Object v : h.getValue()) {
        headers.add(h.getKey(), v);
      }
    }
    if(request.entity() != null && request.entity().getContentType() != null) {
      headers.add("Content-Type", request.entity().getContentType());
    } else {
      headers.add("Content-Type", "application/json");
    }
    try {
      ClientResponse response = null;
      if (request.entity() != null && request.entity().getEntity() != null) {
        response = target.getHeadHandler().handle(new ClientRequestImpl(target.getURI(), request.method().name(), request.entity().getEntity(), headers));
      } else {
        response = target.getHeadHandler().handle(new ClientRequestImpl(target.getURI(), request.method().name(), null, headers));
      }
      return new JerseyResponse(response);
    } catch (UniformInterfaceException e) {
      throw new OpenStackResponseException(e.getResponse().getClientResponseStatus().getReasonPhrase(), e.getResponse().getStatus());
    }
View Full Code Here

    super("mjg");
  }

  @Test
  public void testShow() {
    WebResource webResource = resource();
    String responseMsg = webResource.path("helloworld").get(String.class);
    assertEquals("Hello, World!", responseMsg);
  }
View Full Code Here

     * Test if a WADL document is available at the relative path
     * "application.wadl".
     */
    @Test
    public void testApplicationWadl() {
        WebResource webResource = resource();
        String serviceWadl = webResource.path("application.wadl").
                accept(MediaTypes.WADL).get(String.class);
        assertTrue(serviceWadl.length() > 0);
    }
View Full Code Here

     * a list of properties that contains the "java.class.path"
     * property.
     */
    @Test
    public void testPropertiesResource() throws IOException {
        WebResource webResource = resource();
        String sProperties = webResource.path("properties")
                .accept(MediaType.TEXT_PLAIN)
                .get(String.class);
        Properties properties = new Properties();
        properties.load(new ByteArrayInputStream(sProperties.getBytes()));
        assertNotNull("Properties does not contain 'java.class.path' property",
View Full Code Here

     * Test checks that a GET request on "data" resource gives back a reponse
     * with status "OK".
     */
    @Test
    public void testGetOnDataResource() {
        WebResource webResource = resource();
        ClientResponse response = webResource.path("data")
                .accept(MediaType.TEXT_HTML)
                .get(ClientResponse.class);
        assertEquals("Request for data doesn't give expected response.",
                Response.Status.OK, response.getResponseStatus());
    }
View Full Code Here

    @Test
    public void testPostOnDataResource() {
        Form formData = new Form();
        formData.add("name", "testName");
        formData.add("value", "testValue");
        WebResource webResource = resource();
        ClientResponse response = webResource.path("data")
                .type(MediaType.APPLICATION_FORM_URLENCODED)
                .post(ClientResponse.class, formData);
        assertEquals(Response.Status.OK, response.getResponseStatus());
        String responseMsg = webResource.path("data").type(MediaType.TEXT_HTML).get(String.class);
        assertTrue("Submitted data did not get added to the list...",
                responseMsg.contains("testName") && responseMsg.contains("testValue"));

    }
View Full Code Here

    @Test
    public void signUp() {
        when(userService.createUser(any(CreateUserRequest.class), any(Role.class))).thenReturn(
                new AuthenticatedUserToken(TEST_USER.getUuid().toString(), AUTH_TOKEN.getToken()));
        WebResource webResource = resource();
        CreateUserRequest request = createSignupRequest();
        ClientResponse response = webResource.path("user").entity(request, APPLICATION_JSON).accept(APPLICATION_JSON).post(ClientResponse.class);
        assertThat(response.getStatus(), is(201));
        AuthenticatedUserToken token = response.getEntity(AuthenticatedUserToken.class);
        assertThat(token.getToken(), is(not(nullValue())));
        assertThat(token.getUserId(), is(not(nullValue())));
    }
View Full Code Here

TOP

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

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.