Beispiel #1
0
  /**
   * Used for injecting a test client in unit tests
   *
   * @param authenticationType The type of authentication to use in the request
   * @param client A specific client object to use for the request
   */
  protected JerseyClient(
      final ClientFactory.AuthenticationType authenticationType, final Client client) {
    this.client =
        client
            .register(GZipEncoder.class)
            .register(EncodingFilter.class)
            .register(createMoxyJsonResolver());

    switch (authenticationType) {
      case PREEMPTIVE_BASIC:
        client.register(HttpAuthenticationFeature.basicBuilder().build());
        break;

      case NON_PREEMPTIVE_BASIC:
        client.register(HttpAuthenticationFeature.basicBuilder().nonPreemptive().build());
        break;

      case DIGEST:
        client.register(HttpAuthenticationFeature.digest());
        break;

      case NON_PREEMPTIVE_BASIC_DIGEST:
        client.register(HttpAuthenticationFeature.universalBuilder().build());

      case NONE:
      default:
    }
  }
 private ClientConfig getClientConfig() {
   final ClientConfig cc = new ClientConfig();
   /*2.5-*/
   // cc.register(new HttpDigestAuthFilter("caroline", "zhang"));
   /*2.5+*/
   HttpAuthenticationFeature feature = HttpAuthenticationFeature.digest("caroline", "zhang");
   cc.register(feature);
   return cc;
 }