Package javax.ws.rs.client

Examples of javax.ws.rs.client.WebTarget


        }
    }

    public static void postRestRequestFromServlet(HttpServletRequest request, String endpoint, Map<String, Object> attrs, boolean quiet, boolean throwException) {
        String token = (String) request.getSession().getAttribute(AdminConsoleAuthModule.REST_TOKEN);
        WebTarget target = JERSEY_CLIENT.target(endpoint);
        MultivaluedMap formData = buildMultivalueMap(attrs);
        Response cr = target
                .request(RESPONSE_TYPE)
                .cookie(new Cookie(REST_TOKEN_COOKIE, token))
                .post(Entity.entity(formData, MediaType.APPLICATION_FORM_URLENCODED), Response.class);
        RestResponse rr = RestResponse.getRestResponse(cr);
        parseResponse(rr, null, endpoint, attrs, quiet, throwException);
View Full Code Here


    public <T> T getJsonData(Class<T> clazz, RemoteUrl remoteUrl,
            int retryTimes, int retyrSleepSeconds) throws Exception {

        for (URL url : remoteUrl.getUrls()) {

            WebTarget webtarget = client.target(url.toURI());

            LOGGER.debug("start to query url : "
                    + webtarget.getUri().toString());

            Invocation.Builder builder = webtarget
                    .request(MediaType.APPLICATION_JSON_TYPE);

            // 可重试的下载
            UnreliableInterface unreliableImpl = new RestfulGet(builder);
View Full Code Here

    } else if (resourcePath.startsWith("/")) {
      resourcePath = resourcePath.substring(1);
    }

    String reqPath = getApiPath() + resourcePath;
    WebTarget target = client.target(getEndpoint()).path(reqPath);
    InputStream in = null;
    Entity<?> jsonPayload = null;
    Map<String, String> sigParams = new HashMap<String, String>();

    if (params != null) {
      for (Map.Entry<String, List<String>> param : params.entrySet()) {
        String key = param.getKey();
        List<String> value = param.getValue();
        if (value != null && !value.isEmpty() && value.get(0) != null) {
          target = target.queryParam(key, value.toArray());
          sigParams.put(key, value.get(0));
        }
      }
    }

    Invocation.Builder builder = target.request(MediaType.APPLICATION_JSON);

    if (headers != null) {
      for (Map.Entry<String, String> header : headers.entrySet()) {
        builder.header(header.getKey(), header.getValue());
      }
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

        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

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.