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


//      new PasswordValidationCallback(clientSubject, username, pwd);

        // Make REST Request

        Client client2 = RestUtil.initialize(ClientBuilder.newBuilder()).build();
        WebTarget target = client2.target(restURL);
        target.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

    if (tipoConsulta.equals(Consultas.CEP)) {
      if (cep == null) {
        throw new InvalidParameterException("CEP não informado.");
      }

      WebTarget target = client.target(
          APICommons.POSTMON_HOST + APICommons.POSTMON_VER
              + tipoConsulta).path(cep);

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

      Response response = invocationBuilder.get();
      if (response.getStatus() == 200) {
        Gson gson = new Gson();
View Full Code Here

      if (codigo == null) {
        throw new InvalidParameterException(
            "Código de rastreamento não informado");
      }
      if (entidadeRastreio.equals(Consultas.Entidade.ECT)) {
        WebTarget target = client.target(
            APICommons.POSTMON_HOST + APICommons.POSTMON_VER
                + tipoConsulta + entidadeRastreio).path(codigo);

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

        Response response = invocationBuilder.get();
        if (response.getStatus() == 200) {
          Gson gson = new Gson();
View Full Code Here

    public CouchHttpResponse createDatabase(String databaseName) {
        try {
            // Jersey does not allow for null entity on put.
            Entity entity = Entity.entity("", MediaType.WILDCARD_TYPE);

            WebTarget webTarget = newWebTarget(databaseName);
            Response response = webTarget.request(MediaType.APPLICATION_JSON_TYPE)
                .put(entity);

            CouchStatusCode statusCode = CouchStatusCode.findByCode(response.getStatus());
            String eTag = getETag(response);
            byte[] content = response.readEntity(byte[].class);
            CouchMediaType mediaType = CouchMediaType.fromString(response.getMediaType().toString());
            int contentLength = response.getLength();
            return CouchHttpResponse.builder(CouchMethodType.PUT, webTarget.getUri(), statusCode)
                .setDocumentRevision(eTag)
                .setContent(mediaType, contentLength, content)
                .build();
        } catch (Throwable ex) {
            throw CouchHttpException.internalServerError(ex);
View Full Code Here

    }

    @Override
    public CouchHttpResponse deleteDatabase(String databaseName) {
        try {
            WebTarget webTarget = newWebTarget(databaseName);
            Response response = webTarget.request().delete();

            CouchStatusCode statusCode = CouchStatusCode.findByCode(response.getStatus());
            String eTag = getETag(response);
            byte[] content = response.readEntity(byte[].class);
            CouchMediaType mediaType = CouchMediaType.fromString(response.getMediaType().toString());
            int contentLength = response.getLength();
            return CouchHttpResponse.builder(CouchMethodType.DELETE, webTarget.getUri(), statusCode)
                .setDocumentRevision(eTag)
                .setContent(mediaType, contentLength, content)
                .build();
        } catch (Throwable ex) {
            throw CouchHttpException.internalServerError(ex);
View Full Code Here

    }

    @Override
    public CouchHttpResponse head(HttpHeadRequest request) {
        try {
            WebTarget webTarget = newWebTarget(request);
            Response headResponse = webTarget.request().head();

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

            return buildCouchResponse(request, uri, headResponse, request.getDocumentId());
View Full Code Here

    @Override
    public CouchHttpResponse get(HttpGetRequest request) {

        try {
            WebTarget webTarget = newWebTarget(request);
            MediaType acceptType = (request.getAcceptType() != null) ? MediaType.valueOf(request.getAcceptType().getMediaString()) : null;
            Response getResponse = webTarget.request(acceptType).get();

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

            return buildCouchResponse(request, uri, getResponse, request.getDocumentId());
View Full Code Here

            MediaType contentType = MediaType.valueOf(request.getContentType().getMediaString());

            // Jersey does not allow entity value to be null.
            Object content = request.getContent() != null ? request.getContent() : "";
            Entity entity = Entity.entity(content, contentType);
            WebTarget webTarget = newWebTarget(request.getPath());
            for (HttpQueryParam queryParam : request.getQueryParameters()) {
                webTarget = webTarget.queryParam(queryParam.getName(), queryParam.getValue());
            }

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

            Response putResponse = webTarget.request(MediaType.APPLICATION_JSON_TYPE)
                .header("Content-Type", contentType)
                .put(entity);

            return buildCouchResponse(request, uri, putResponse, request.getDocumentId());
        } catch (Throwable ex) {
View Full Code Here

    public CouchHttpResponse post(HttpPostRequest request) {

        try {
            // Jersey does not allow entity value to be null.
            Entity entity = Entity.json(request.getContent());
            WebTarget webTarget = newWebTarget(request.getPath());
            for (HttpQueryParam queryParam : request.getQueryParameters()) {
                webTarget = webTarget.queryParam(queryParam.getName(), queryParam.getValue());
            }

            Response postResponse = webTarget.request(MediaType.APPLICATION_JSON_TYPE)
                .post(entity);

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

            String documentId = UriUtil.lastPathElement(postResponse.getLocation());
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.