Package javax.ws.rs.client.Invocation

Examples of javax.ws.rs.client.Invocation.Builder


                if (authInfo != null) {
                    HttpBasicAuthFilter besicAuth = new HttpBasicAuthFilter(authInfo.getUser(), authInfo.getPassword() == null ? "" : authInfo.getPassword());
                    target.configuration().register(besicAuth);
                }
                Metrix.event("doRestCommand() - about to prepare request builder");
                Builder request = target.request(acceptedResponseTypes);
                Metrix.event("doRestCommand() - about to add headers");
                if (authToken != null) {
                    /*
                     * If this request is for metadata then we expect to reuse
                     * the auth token.
                     */
                    request = request.header(
                            SecureAdmin.Util.ADMIN_ONE_TIME_AUTH_TOKEN_HEADER_NAME,
                            (isForMetadata ? AuthTokenManager.markTokenForReuse(authToken) : authToken));
                }
                if (commandModel != null && isCommandModelFromCache() && commandModel instanceof CachedCommandModel) {
                    request =  request.header(COMMAND_MODEL_MATCH_HEADER,
                            ((CachedCommandModel) commandModel).getETag());
                    if (logger.isLoggable(Level.FINER)) {
                        logger.log(Level.FINER, "CommandModel ETag: {0}", ((CachedCommandModel) commandModel).getETag());
                    }
                }
                //Headers
                for (Header h : requestHeaders) {
                    request = request.header(h.getName(), h.getValue());
                }
                request = addAdditionalHeaders(request);
                if (logger.isLoggable(Level.FINER)) {
                    request = request.header("X-Indent", "true");
                }
                //Make invocation
                Invocation invoc = null;
                Metrix.event("doRestCommand() - about to prepare invocation");
                if ("POST".equals(method)) {
                    if (outboundPayload != null && outboundPayload.size() > 0) {
                        FormDataMultiPart mp = new FormDataMultiPart();
                        //Copy params there
                        for (Map.Entry<String, List<String>> entry : options.entrySet()) {
                            String key = entry.getKey();
                            for (String val : entry.getValue()) {
                                mp.field(key, val);
                            }
                        }
                        //Copy outbound there
                        outboundPayload.addToMultipart(mp, logger);
                        Entity<FormDataMultiPart> entity = Entity.<FormDataMultiPart>entity(mp, mp.getMediaType());
                        invoc = request.build(method, entity);
                    } else {
                        Entity<ParameterMap> entity = Entity.<ParameterMap>entity(options, MediaType.APPLICATION_FORM_URLENCODED_TYPE);
                        invoc = request.build(method, entity);
                    }
                } else {
                    invoc = request.build(method);
                }
                //todo: set timeout
//                urlConnection.setReadTimeout(readTimeout);
//                if (connectTimeout >= 0)
//                    urlConnection.setConnectTimeout(connectTimeout);
View Full Code Here


                if (authInfo != null) {
                    HttpBasicAuthFilter besicAuth = new HttpBasicAuthFilter(authInfo.getUser(), authInfo.getPassword() == null ? "" : authInfo.getPassword());
                    target.register(besicAuth);
                }
                Metrix.event("doRestCommand() - about to prepare request builder");
                Builder request = target.request(acceptedResponseTypes);
                Metrix.event("doRestCommand() - about to add headers");
                if (authToken != null) {
                    /*
                     * If this request is for metadata then we expect to reuse
                     * the auth token.
                     */
                    request = request.header(
                            SecureAdmin.Util.ADMIN_ONE_TIME_AUTH_TOKEN_HEADER_NAME,
                            (isForMetadata ? AuthTokenManager.markTokenForReuse(authToken) : authToken));
                }
                if (commandModel != null && isCommandModelFromCache() && commandModel instanceof CachedCommandModel) {
                    request =  request.header(COMMAND_MODEL_MATCH_HEADER,
                            ((CachedCommandModel) commandModel).getETag());
                    if (logger.isLoggable(Level.FINER)) {
                        logger.log(Level.FINER, "CommandModel ETag: {0}", ((CachedCommandModel) commandModel).getETag());
                    }
                }
                //Headers
                for (Header h : requestHeaders) {
                    request = request.header(h.getName(), h.getValue());
                }
                request = addAdditionalHeaders(request);
                if (logger.isLoggable(Level.FINER)) {
                    request = request.header("X-Indent", "true");
                }
                //Make invocation
                Invocation invoc = null;
                Metrix.event("doRestCommand() - about to prepare invocation");
                if ("POST".equals(method)) {
                    if (outboundPayload != null && outboundPayload.size() > 0) {
                        FormDataMultiPart mp = new FormDataMultiPart();
                        //Copy params there
                        for (Map.Entry<String, List<String>> entry : options.entrySet()) {
                            String key = entry.getKey();
                            for (String val : entry.getValue()) {
                                mp.field(key, val);
                            }
                        }
                        //Copy outbound there
                        outboundPayload.addToMultipart(mp, logger);
                        Entity<FormDataMultiPart> entity = Entity.<FormDataMultiPart>entity(mp, mp.getMediaType());
                        invoc = request.build(method, entity);
                    } else {
                        Entity<ParameterMap> entity = Entity.<ParameterMap>entity(options, MediaType.APPLICATION_FORM_URLENCODED_TYPE);
                        invoc = request.build(method, entity);
                    }
                } else {
                    invoc = request.build(method);
                }
                //todo: set timeout
//                urlConnection.setReadTimeout(readTimeout);
//                if (connectTimeout >= 0)
//                    urlConnection.setConnectTimeout(connectTimeout);
View Full Code Here

    return sendRequest( method, parameter, configurer );
  }

  private Object sendRequest( Method method, Object[] parameter, RequestConfigurer configurer ) {
    Object result = null;
    Builder request = configurer.configure();
    if( method.isAnnotationPresent( GET.class ) ) {
      result = sendGetRequest( configurer, method, request );
    } if( method.isAnnotationPresent( POST.class ) ) {
      result = sendPostRequest( configurer, method, parameter, request );
    } if( method.isAnnotationPresent( PUT.class ) ) {
View Full Code Here

 
  public Builder configure() {
    WebTarget target = computeTarget();
    target = addQueryParameters( target );
    target = addMatrixParameters( target );
    Builder request = target.request();
    request = addHeaders( request );
    return request;
  }
View Full Code Here

    }
    return null;
  }
 
  private Builder addHeaders( Builder request ) {
    Builder result = request;
    Annotation[][] parameterAnnotations = method.getParameterAnnotations();
    for( int i = 0; i < parameterAnnotations.length; i++ ) {
      Annotation[] annotations = parameterAnnotations[ i ];
      String paramName = extractHeaderParam( annotations );
      if( paramName != null ) {
        result = result.header( paramName, parameter[ i ] );
      }
    }
    result = addAcceptHeader( request );
    return result;
  }
View Full Code Here

    result = addAcceptHeader( request );
    return result;
  }
 
  private Builder addAcceptHeader( Builder request ) {
    Builder result = request;
    MediaType accept = MediaType.WILDCARD_TYPE;
    if( method.isAnnotationPresent( Produces.class ) ) {
      accept = MediaTypes.createFrom( method.getAnnotation( Produces.class ) ).get( 0 );
      result = result.header( HttpHeaders.ACCEPT, accept );
    }
    return result;
  }
View Full Code Here

   }

   @Test(timeout=REQUEST_TIMEOUT)
   public void testConnectionCloseHeader() throws Exception
   {
      Builder requestBuilder = client.target(BASE_URI).path("jaxrs/empty").request();
      requestBuilder.header("Connection", "close");
      Response response = requestBuilder.get();
      Assert.assertEquals(Values.CLOSE, response.getHeaderString("Connection"));
      response.close();
   }
View Full Code Here

      }
      di.setDeploymentName("validate");
      di.setContextPath("/validate");
      server.deploy(di);
      Client client = ClientBuilder.newClient();
      Builder builder = client.target(TestPortProvider.generateURL("/validate/all/a/b/c")).request();
      builder.accept(MediaType.APPLICATION_XML);
      Response response = builder.get();
      Object header = response.getHeaders().getFirst(Validation.VALIDATION_HEADER);
      Assert.assertTrue(header instanceof String);
      Assert.assertTrue(Boolean.valueOf(String.class.cast(header)));
      ViolationReport report = response.readEntity(ViolationReport.class);
      countViolations(report, 1, 1, 1, 1, 0);
View Full Code Here

      }
      di.setDeploymentName("validate");
      di.setContextPath("/validate");
      server.deploy(di);
      Client client = ClientBuilder.newClient();
      Builder builder = client.target(TestPortProvider.generateURL("/validate/all/aa/bbb/cccc")).request();
      builder.accept(MediaType.APPLICATION_XML);
      Response response = builder.get();
      Object header = response.getHeaders().getFirst(Validation.VALIDATION_HEADER);
      Assert.assertTrue(header instanceof String);
      Assert.assertTrue(Boolean.valueOf(String.class.cast(header)));
      ViolationReport report = response.readEntity(ViolationReport.class);
      countViolations(report, 0, 0, 0, 0, 1);
View Full Code Here

      }
      di.setDeploymentName("validate");
      di.setContextPath("/validate");
      server.deploy(di);
      Client client = ClientBuilder.newClient();
      Builder builder = client.target(TestPortProvider.generateURL("/validate/all/a/b/c")).request();
      builder.accept(MediaType.APPLICATION_XML);
      Response response = builder.get();
      Object header = response.getHeaders().getFirst(Validation.VALIDATION_HEADER);
      Assert.assertTrue(header instanceof String);
      Assert.assertTrue(Boolean.valueOf(String.class.cast(header)));
      ViolationReport report = response.readEntity(ViolationReport.class);
      countViolations(report, 1, 1, 1, 1, 0);
View Full Code Here

TOP

Related Classes of javax.ws.rs.client.Invocation.Builder

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.