Package javax.ws.rs.client

Examples of javax.ws.rs.client.WebTarget


            // To avoid deleting database with this call we ensure path is not empty.
            if (ArgUtil.isEmpty(request.getPath())) {
                throw CouchException.badRequest("Attempting to delete with empty path, which would delete the database so we will fail. If you really want to delete the database use the explicit deleteDatabase method.");
            }

            WebTarget webTarget = newWebTarget(request.getPath());
            for (HttpQueryParam queryParam : request.getQueryParameters()) {
                webTarget = webTarget.queryParam(queryParam.getName(), queryParam.getValue());
            }
            Response deleteResponse = webTarget.request().delete();

            URI uri = webTarget.getUri();
            if (log.isDebugEnabled()) {
                log.debug("DELETE url: " + uri.toString());
            }

            // Build our response.
View Full Code Here


        return client.target(absoluteUrl);
    }

    protected WebTarget newWebTarget(HttpReadRequest request) {
        WebTarget webTarget = newWebTarget(request.getPath());
        for (HttpQueryParam queryParam : request.getQueryParameters()) {
            webTarget = webTarget.queryParam(queryParam.getName(), queryParam.getValue());
        }
        return webTarget;
    }
View Full Code Here

        // Make REST Request

        Client client2 = ClientFactory.newClient();
        RestUtil.initialize(client2);
        WebTarget target = client2.target(restURL);
        target.configuration().register(new HttpBasicAuthFilter(username, password));
        MultivaluedMap payLoad = new MultivaluedHashMap();
        payLoad.putSingle("remoteHostName", request.getRemoteHost());

        Response resp = target.request(RESPONSE_TYPE).post(Entity.entity(payLoad, MediaType.APPLICATION_FORM_URLENCODED), Response.class);
        RestResponse restResp = RestResponse.getRestResponse(resp);

        // Check to see if successful..
        if (restResp.isSuccess()) {
            // Username and Password sent in... validate them!
View Full Code Here

        return token;
    }

    public static Response getRequestFromServlet(HttpServletRequest request, String endpoint, Map<String, Object> attrs) {
        String token = (String) request.getSession().getAttribute(AdminConsoleAuthModule.REST_TOKEN);
        WebTarget target = targetWithQueryParams(JERSEY_CLIENT.target(endpoint), attrs);
        Response cr = target
                .request().cookie(new Cookie(REST_TOKEN_COOKIE, token))
                .get(Response.class);

        return cr;
    }
View Full Code Here

        return cr;
    }

    public static void getRestRequestFromServlet(HttpServletRequest request, String endpoint, Map<String, Object> attrs, boolean quiet, boolean throwException) {
        String token = (String) request.getSession().getAttribute(AdminConsoleAuthModule.REST_TOKEN);
        WebTarget target = targetWithQueryParams(JERSEY_CLIENT.target(endpoint), attrs);
        Response cr = target
                .request(RESPONSE_TYPE)
                .cookie(new Cookie(REST_TOKEN_COOKIE, token))
                .get(Response.class);
        RestResponse rr = RestResponse.getRestResponse(cr);
        parseResponse(rr, null, endpoint, attrs, quiet, throwException);
View Full Code Here

    public static RestResponse get(String address, Map<String, Object> payload) {
        if (address.startsWith("/")) {
            address = FacesContext.getCurrentInstance().getExternalContext().getSessionMap().get("REST_URL") + address;
        }
        WebTarget target = targetWithQueryParams(getJerseyClient().target(address), payload);
        Response resp = target
                .request(RESPONSE_TYPE)
                .cookie(new Cookie(REST_TOKEN_COOKIE, getRestToken()))
                .get(Response.class);
        return RestResponse.getRestResponse(resp);
    }
View Full Code Here

                .get(Response.class);
        return RestResponse.getRestResponse(resp);
    }

    public static RestResponse post(String address, Object payload, String contentType) {
        WebTarget target = getJerseyClient().target(address);
        if (contentType == null) {
            contentType = MediaType.APPLICATION_JSON;
        }
        if (payload instanceof Map) {
            payload = buildMultivalueMap((Map<String, Object>) payload);
        }
        Response cr = target.request(RESPONSE_TYPE).header("Content-Type", contentType)
                .cookie(new Cookie(REST_TOKEN_COOKIE, getRestToken()))
                //                .header("Content-type", MediaType.APPLICATION_FORM_URLENCODED)
                .post(Entity.entity(payload, contentType), Response.class);
        RestResponse rr = RestResponse.getRestResponse(cr);
        return rr;
View Full Code Here

        RestResponse rr = RestResponse.getRestResponse(cr);
        return rr;
    }

    public static RestResponse post(String address, Map<String, Object> payload) {
        WebTarget target = getJerseyClient().target(address);
        MultivaluedMap formData = buildMultivalueMap(payload);
        Response cr = target
                //                .header("Content-type", MediaType.APPLICATION_FORM_URLENCODED)
                .request(RESPONSE_TYPE)
                .cookie(new Cookie(REST_TOKEN_COOKIE, getRestToken()))
                .post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED), Response.class);
        RestResponse rr = RestResponse.getRestResponse(cr);
View Full Code Here

        RestResponse rr = RestResponse.getRestResponse(cr);
        return rr;
    }

    public static RestResponse put(String address, Map<String, Object> payload) {
        WebTarget target = getJerseyClient().target(address);
        MultivaluedMap formData = buildMultivalueMap(payload);
        Response cr = target
                //                .header("Content-type", MediaType.APPLICATION_FORM_URLENCODED)
                .request(RESPONSE_TYPE)
                .cookie(new Cookie(REST_TOKEN_COOKIE, getRestToken()))
                .put(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED), Response.class);
        RestResponse rr = RestResponse.getRestResponse(cr);
View Full Code Here

        RestResponse rr = RestResponse.getRestResponse(cr);
        return rr;
    }

    public static RestResponse delete(String address, Map<String, Object> payload) {
        WebTarget target = getJerseyClient().target(address);
        Response cr = targetWithQueryParams(target, payload)
                .request(RESPONSE_TYPE)
                .cookie(new Cookie(REST_TOKEN_COOKIE, getRestToken()))
                .delete(Response.class);
        return RestResponse.getRestResponse(cr);
View Full Code Here

TOP

Related Classes of javax.ws.rs.client.WebTarget

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.