Package com.sun.jersey.api.client

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


    }

    protected ClientResponse doDelete(String path, String query) {
        String uri = makeUriString(path, query);

        ClientRequest graphRequest = ClientRequest.create().build(createUri("/" + uri), "DELETE");
        return this.client.handle(graphRequest);
    }
View Full Code Here


    }

    protected ClientResponse doPostOfJson(String path, String query, JSONObject jsonToPost) {
        String uri = makeUriString(path, query);

        ClientRequest graphRequest = ClientRequest.create().type(MediaType.APPLICATION_JSON_TYPE).build(createUri("/" + uri), "POST");
        graphRequest.setEntity(jsonToPost);

        return this.client.handle(graphRequest);
    }
View Full Code Here

    }

    protected ClientResponse doPutOfJson(String path, String query, JSONObject jsonToPost) {
        String uri = makeUriString(path, query);

        ClientRequest graphRequest = ClientRequest.create().type(MediaType.APPLICATION_JSON_TYPE).build(createUri("/" + uri), "PUT");
        graphRequest.setEntity(jsonToPost);

        return this.client.handle(graphRequest);
    }
View Full Code Here

    }

    protected ClientResponse doDeleteOfJson(String path, String query, JSONObject jsonToDelete) {
        String uri = makeUriString(path, query);

        ClientRequest graphRequest = ClientRequest.create().type(MediaType.APPLICATION_JSON_TYPE).build(createUri("/" + uri), "DELETE");
        graphRequest.setEntity(jsonToDelete);

        return this.client.handle(graphRequest);
    }
View Full Code Here

    @Before
    public void setUp() throws Exception {
        // the @Before in the superclass should be called automatically before this...but isn't
        super.setUp();

        ClientRequest request = ClientRequest.create().build(createUri("/"), "GET");
        ClientResponse response = this.client.handle(request);

        JSONObject json = response.getEntity(JSONObject.class);
        JSONArray jsonArray = json.optJSONArray("graphs");

        TinkerGraph testGraph = TinkerGraphFactory.createTinkerGraph();

        this.testGraphs = new ArrayList<GraphTestHolder>();
        for (int ix = 0; ix < jsonArray.length(); ix++) {
            ClientRequest graphRequest = ClientRequest.create().build(createUri("/" + jsonArray.optString(ix)), "GET");
            ClientResponse graphResponse = this.client.handle(graphRequest);

            JSONObject graphJson = graphResponse.getEntity(JSONObject.class);

            final JSONObject featuresJson = graphJson.optJSONObject("features");
View Full Code Here

            super.tearDown();
        }
    }

    protected void postVertex(GraphTestHolder graphHolder, Vertex v) throws JSONException {
        ClientRequest request = ClientRequest.create().type(RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON).build(createUri("/" + graphHolder.getGraphName() + "/vertices"), "POST");
        request.setEntity(typeTheElement(GraphSONUtility.jsonFromElement(v, null, GraphSONMode.NORMAL)));

        ClientResponse response = this.client.handle(request);

        JSONObject jsonObject = response.getEntity(JSONObject.class);
        String id = jsonObject.optJSONObject(Tokens.RESULTS).optString(Tokens._ID);
View Full Code Here

        graphHolder.getVertexIdSet().put(v.getId().toString(), id);

    }

    protected void postEdge(GraphTestHolder graphHolder, Edge e) throws JSONException {
        ClientRequest request = ClientRequest.create().build(createUri("/" + graphHolder.getGraphName() + "/edges"), "POST");

        JSONObject jsonEdge = typeTheElement(GraphSONUtility.jsonFromElement(e, null, GraphSONMode.NORMAL));
        jsonEdge.put(Tokens._IN_V, graphHolder.getVertexIdSet().get(jsonEdge.optString(Tokens._IN_V)));
        jsonEdge.put(Tokens._OUT_V, graphHolder.getVertexIdSet().get(jsonEdge.optString(Tokens._OUT_V)));

        request.setEntity(jsonEdge);
        List<Object> headerValue = new ArrayList<Object>() {{
            add(RexsterMediaType.APPLICATION_REXSTER_TYPED_JSON);
        }};
        request.getHeaders().put("Content-Type", headerValue);

        ClientResponse response = this.client.handle(request);

        JSONObject jsonObject = response.getEntity(JSONObject.class);
        String id = jsonObject.optJSONObject(Tokens.RESULTS).optString(Tokens._ID);
View Full Code Here

    }

    private void tryRestGremlin() throws Exception {
        final String url = getHttpBaseUri() + "graphs/gratefulgraph/tp/gremlin?script=" + URLEncoder.encode("g.e(x)") + "&params.x=";
        for (int ix = 101; ix < 901; ix++) {
            final ClientRequest request = ClientRequest.create().build(URI.create(url + String.valueOf(ix)), "GET");
            final ClientResponse response = httpClient.handle(request);
            final JSONObject json = response.getEntity(JSONObject.class);
            Assert.assertEquals(ix, json.optJSONArray("results").optJSONObject(0).optInt("_id"));
        }
    }
View Full Code Here

    }

    private void tryRestApi() throws Exception {
        final String url = getHttpBaseUri() + "graphs/gratefulgraph/edges/";
        for (int ix = 101; ix < 901; ix++) {
            final ClientRequest request = ClientRequest.create().build(URI.create(url + String.valueOf(ix)), "GET");
            final ClientResponse response = httpClient.handle(request);
            final JSONObject json = response.getEntity(JSONObject.class);
            Assert.assertEquals(ix, json.optJSONObject("results").optInt("_id"));
        }
    }
View Full Code Here

    }

    private void tryRestGremlin() throws Exception {
        final String url = getHttpBaseUri() + "graphs/gratefulgraph/tp/gremlin?script=" + URLEncoder.encode("g.v(x)") + "&params.x=";
        for (int ix = 1; ix < 801; ix++) {
            final ClientRequest request = ClientRequest.create().build(URI.create(url + String.valueOf(ix)), "GET");
            final ClientResponse response = httpClient.handle(request);
            final JSONObject json = response.getEntity(JSONObject.class);
            Assert.assertEquals(ix, json.optJSONArray("results").optJSONObject(0).optInt("_id"));
        }
    }
View Full Code Here

TOP

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

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.