Package com.sun.jersey.api.client

Examples of com.sun.jersey.api.client.Client


        Assert.assertTrue(response.getHeaders().get("Content-Type").toString().equals("[text/plain]"));
    }

    @Test
    public void testCustomerResourceMediaTypeMappingsHTML() throws Exception {
        Client c = new Client();
        WebResource wr = c.resource("http://localhost:" + getJettyPort() + "/customers/1.html");

        // Get customer
        System.out.println("*** GET Customer as TXT **");
        ClientResponse response = wr.get(ClientResponse.class);
        System.out.println("Content-Type: " + response.getHeaders().get("Content-Type"));
View Full Code Here


  public String invokeAPI(String host, String path, String method,
      Map<String, String> queryParams, Object body,
      Map<String, String> headerParams, Map<String, String> formParams,
      String contentType) throws ApiException {
    Client client = getClient(host);

    StringBuilder b = new StringBuilder();

    for (String key : queryParams.keySet()) {
      String value = queryParams.get(key);
      if (value != null) {
        if (b.toString().length() == 0)
          b.append("?");
        else
          b.append("&");
        b.append(escapeString(key)).append("=")
            .append(escapeString(value));
      }
    }
    String querystring = b.toString();

    Builder builder = client.resource(host + path + querystring).accept("application/json");
   
    // add basic header if not present
    String user = null;
    String password = null;
    if (headerParams.containsKey("BASIC"))
    {
      user = headerParams.get("BASIC").split(":")[0];
      password = headerParams.get("BASIC").split(":")[1];
      headerParams.remove("BASIC");
      client.addFilter(new HTTPBasicAuthFilter(user, password));
    }
    else if (!headerParams.containsKey("Authorization")) // add oauth header if not present
    {
      headerParams.put("Authorization", "Bearer " + findSystemDefaultAccessToken());
    }
View Full Code Here

    }
  }

  private Client getClient(String host) {
    if (!hostMap.containsKey(host)) {
      Client client = Client.create();
      if (isDebug)
        client.addFilter(new LoggingFilter());
      hostMap.put(host, client);
    }
    return hostMap.get(host);
  }
View Full Code Here

     * @param tc instance of {@link TestContainer}
     * @param ad instance of {@link AppDescriptor}
     * @return A Client instance.
     */
    protected Client getClient(TestContainer tc, AppDescriptor ad) {
        Client c = tc.getClient();

        if (c != null) {
            return c;
        } else {
            c = getClientFactory().create(ad.getClientConfig());
        }

        //check if logging is required
        boolean enableLogging = System.getProperty("enableLogging") != null;
       
        if (enableLogging) {
                c.addFilter(new LoggingFilter());
        }

        return c;
    }
View Full Code Here

    protected void setUp() throws Exception {
        super.setUp();
       
        threadSelector = Main.startServer();

        Client c = Client.create();
        r = c.resource(Main.BASE_URI);
    }
View Full Code Here

                for(Object providerSingleton : providerSingletons) {
                    clientConfig.getSingletons().add(providerSingleton);
                }
            }

            Client client = (clientConfig == null) ?
                    new Client(new TestResourceClientHandler(baseUri, webApp)) :
                    new Client(new TestResourceClientHandler(baseUri, webApp), clientConfig);

            return client;
        }
View Full Code Here

    }
  }

  protected void buildApiClient() throws NoSuchAlgorithmException, KeyManagementException {

    Client client;

    String pattern;
    String url;

    if (configuration.getApiSSLAuthentication()) {
      pattern = "https://localhost:%s/";
      url = String.format(pattern, configuration.getClientSSLApiPort());

      // Create a trust manager that does not validate certificate chains
      TrustManager[] trustAllCerts = new TrustManager[]{new X509TrustManager() {
        @Override
        public void checkClientTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {

        }

        @Override
        public void checkServerTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException {

        }

        public X509Certificate[] getAcceptedIssuers() {
          return null;
        }


      }};

      //Create SSL context
      SSLContext sc = SSLContext.getInstance("TLS");
      sc.init(null, trustAllCerts, new SecureRandom());

      //Install all trusting cert SSL context for jersey client
      ClientConfig config = new DefaultClientConfig();
      config.getProperties().put(HTTPSProperties.PROPERTY_HTTPS_PROPERTIES, new HTTPSProperties(
        new HostnameVerifier() {
          @Override
          public boolean verify( String s, SSLSession sslSession ) {
            return true;
          }
        },
        sc
      ));

      client = Client.create(config);

    } else {
      client = Client.create();
      pattern = "http://localhost:%s/";
      url = String.format(pattern, configuration.getClientApiPort());
    }

    this.ambariClient = client;
    this.ambariWebResource = client.resource(url);

    //Install auth filters
    ClientFilter csrfFilter = new CsrfProtectionFilter("RequestSchedule");
    ClientFilter tokenFilter = new InternalTokenClientFilter(tokenStorage);
    ambariClient.addFilter(csrfFilter);
View Full Code Here

    this.username = username;
    this.doAs = doAs;
    this.context = context;
    ClientConfig config = new DefaultClientConfig();
    config.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    Client client = Client.create(config);
    this.service = client.resource(api);
  }
View Full Code Here

import com.sun.jersey.client.apache.ApacheHttpClient;

public class HttpClientFactory {

    public Client createClient() {
        Client client = ApacheHttpClient.create();
        client.setFollowRedirects(true);
        client.addFilter(new HTTPBasicAuthFilter("management/admin", "Pyi1bo1r"));
        client.addFilter(new ApplicationKeyFilter());
        return client;
    }
View Full Code Here

        for (Class<?> c : PROVIDERS_CLASSES) {
            config.getClasses().add(c);
        }
        config.getProperties().put(ApacheHttpClientConfig.PROPERTY_READ_TIMEOUT, READ_TIMEOUT_IN_MILLIS);

        Client client = ApacheHttpClient.create(config);
        client.setFollowRedirects(true);
        client.addFilter(new HTTPBasicAuthFilter(platformParameters.getPrincipal(), platformParameters.getPassword()));
       
        return client;
    }
View Full Code Here

TOP

Related Classes of com.sun.jersey.api.client.Client

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.