Package com.sun.jersey.api.client

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


    /** Creates an entity. */
    public static WebResource createEntity(Client c, WebResource work, String type, String data) throws IOException {
        WebResource entity = work.path(type);
        try {
            entity.post(String.class, data);
            throw new IOException("Could not create " + type + " with data " + data);
        }
        catch (UniformInterfaceException e2) {
            return c.resource(e2.getResponse().getLocation());
        }
View Full Code Here


    /** Creates a new workspace. */
    public static WebResource createWorkspace(String host, Client c) {
        WebResource r = c.resource(host.concat("/client/work/"));
        try {
            r.post(String.class, "");
            fail("We should have been redirected to a new workspace.");
            return null; // to keep the compiler happy, it does not understand what fail() does
        }
        catch (UniformInterfaceException e) {
            assertEquals("Expected a valid redirect after creating a workspace", 302, e.getResponse().getStatus());
View Full Code Here

    public void testCreateAndDestroyRESTSession() throws Exception {
        Client client = createClient();
        try {
            WebResource r = client.resource(HOST.concat("/client/work"));
            try {
                r.post(String.class, "");
                fail("We should have been redirected to a new workspace.");
            }
            catch (UniformInterfaceException e) {
                ClientResponse response = e.getResponse();
                URI location = response.getLocation();
View Full Code Here

            WebResource w1 = createWorkspace(HOST, client);
            deleteResources(gson, w1);
            createBundleArtifact(client, w1, "bar.a1", "bar.b1", "1.0.0", b1);
            createBundleArtifact(client, w1, "bar.a2", "bar.b2", "1.0.0", b2);
            createTarget(client, w1, "bar.t1");
            w1.post();
            w1.delete();

            for (int i = 0; i < nr; i++) {
                WebResource w2 = createWorkspace(HOST, client);
                createAssociationA2F(client, w2, "bar.a1", "feat-1-" + i);
View Full Code Here

                createFeature(client, w2, "feat-2-" + i);
                createAssociationF2D(client, w2, "feat-1-" + i, "dist-" + i);
                createAssociationF2D(client, w2, "feat-2-" + i, "dist-" + i);
                createDistribution(client, w2, "dist-" + i);
                createAssociationD2T(client, w2, "dist-" + i, "bar.t1");
                w2.post();
                w2.delete();
            }
            WebResource t1versions = client.resource(HOST.concat("/deployment/bar.t1/versions"));
            assertEquals("1.0.0\n", t1versions.get(String.class));
        }
View Full Code Here

            assertResources(gson, w2, "feature", 3);
            assertResources(gson, w2, "feature2distribution", 3);
            assertResources(gson, w2, "distribution", 1);
            assertResources(gson, w2, "distribution2target", 1);
            assertResources(gson, w2, "target", 1);
            w2.post();
            w2.delete();

            WebResource t1versions = client.resource(HOST.concat("/deployment/foo.t1/versions"));
            assertEquals("1.0.0\n", t1versions.get(String.class));
        }
View Full Code Here

            createAssociationD2T(client, w1, "d2", "t5");
            createAssociationD2T(client, w1, "d2", "t6");
            createTarget(client, w1, "t4", "test", "one");
            createTarget(client, w1, "t5", "test", "two");
            createTarget(client, w1, "t6", "test", "three");
            w1.post();
            w1.delete();

            WebResource w2 = createWorkspace(HOST, client);
            assertResources(gson, w2, "artifact", 1);
            assertResources(gson, w2, "artifact2feature", 1);
View Full Code Here

      fail("should have been a 404");
    } catch (UniformInterfaceException e) {
      assertThat(e.getResponse().getStatus(), is(404));
    }
   
    final ClientResponse response = r.post(ClientResponse.class, "awesome");
    assertThat(response.getStatus(), is(201));
    assertThat(response.getLocation(), is(r.getURI()));
   
    assertThat(r.get(String.class), is("[Widget name:dingo, description:awesome]"));
   
View Full Code Here

    ClientConfig clientConfig = new DefaultClientConfig();
    clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    client = Client.create(clientConfig);
    WebResource webResource = client.resource("http://localhost:9998/persist");
   
    webResource.post("{\"xyx\" : \"t\"}");
    LOG.info("Done posting to the server");
    String output = webResource.get(String.class);
    LOG.info("All key values " + output);
    Map<String, String> jsonOutput = StageUtils.fromJson(output, Map.class);
    String value = jsonOutput.get("xyx");
View Full Code Here

        WebResource webResource = client.resource(url);
        String response = null;
        switch (method) {
            case POST:
                response = webResource.post(String.class);
                break;
            case PUT:
                response = webResource.put(String.class);
                break;
            case DELETE:
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.