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

    }


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

    private String pathOrAbsolute( String path ) {
        if ( path.startsWith( "http://" ) ) return path;
        return baseUri + "/" + path;
View Full Code Here

                "ORDER BY sortOrder " +
                "LIMIT 300 " +
                "RETURN n.title as title, n.text as text;";

        String payload = "{\"statements\" : [ {\"statement\" : \"" +query + "\"} ]}";
        ClientResponse response = resource
                .accept( MediaType.APPLICATION_JSON )
                .type( MediaType.APPLICATION_JSON )
                .entity( payload )
                .post( ClientResponse.class );
View Full Code Here

     */
    @Test
    public void testCustomer() throws Exception {
        WebResource webResource = resource().path("customer");

        Customer customer = webResource.accept(MediaType.APPLICATION_XML).get(Customer.class);
        customer.setName("Tom Dooley");
        webResource.type(MediaType.APPLICATION_XML).put(customer);

        Customer updatedCustomer = webResource.accept(MediaType.APPLICATION_XML).get(Customer.class);
        Assert.assertEquals(customer, updatedCustomer);
View Full Code Here

        Customer customer = webResource.accept(MediaType.APPLICATION_XML).get(Customer.class);
        customer.setName("Tom Dooley");
        webResource.type(MediaType.APPLICATION_XML).put(customer);

        Customer updatedCustomer = webResource.accept(MediaType.APPLICATION_XML).get(Customer.class);
        Assert.assertEquals(customer, updatedCustomer);
    }

    @Test
    public void testApplicationWadl() {
View Full Code Here

            queryParams.add("support", "-1");
            queryParams.add("text", text);
            //queryParams.add("text", java.net.URLEncoder.encode(text,"UTF-8"));


            json = webResource.
                    accept( MediaType.APPLICATION_JSON, MediaType.APPLICATION_XML).
                    header("ContentType","application/x-www-form-urlencoded;charset=UTF-8").
                    //type(MediaType.APPLICATION_FORM_URLENCODED).
                    //type(MediaType.APPLICATION_FORM_URLENCODED_TYPE).
                            post(String.class, queryParams);
View Full Code Here

    }

    private ZSession createSession(String expire) {
        WebResource wr = sessionsr.queryParam("op", "create")
            .queryParam("expire", expire);
        Builder b = wr.accept(MediaType.APPLICATION_JSON);

        ClientResponse cr = b.post(ClientResponse.class, null);
        assertEquals(ClientResponse.Status.CREATED, cr
                .getClientResponseStatus());
View Full Code Here

    @Test
    public void testDeleteSession() {
        ZSession session = createSession("30");

        WebResource wr = sessionsr.path(session.id);
        Builder b = wr.accept(MediaType.APPLICATION_JSON);

        assertTrue(ZooKeeperService.isConnected(CONTEXT_PATH, session.id));
        ClientResponse cr = b.delete(ClientResponse.class, null);
        assertEquals(ClientResponse.Status.NO_CONTENT,
                cr.getClientResponseStatus());
View Full Code Here

    public void testSendHeartbeat() throws InterruptedException {
        ZSession session = createSession("2");
       
        Thread.sleep(1000);
        WebResource wr = sessionsr.path(session.id);
        Builder b = wr.accept(MediaType.APPLICATION_JSON);
       
        ClientResponse cr = b.put(ClientResponse.class, null);
        assertEquals(ClientResponse.Status.OK, cr.getClientResponseStatus());
       
        Thread.sleep(1500);
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.