当前位置: 首页>>代码示例>>Java>>正文


Java ApacheHttpClient4类代码示例

本文整理汇总了Java中com.sun.jersey.client.apache4.ApacheHttpClient4的典型用法代码示例。如果您正苦于以下问题:Java ApacheHttpClient4类的具体用法?Java ApacheHttpClient4怎么用?Java ApacheHttpClient4使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ApacheHttpClient4类属于com.sun.jersey.client.apache4包,在下文中一共展示了ApacheHttpClient4类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: testCookiePolicy

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
@SuppressWarnings("deprecation")
@Test
public void testCookiePolicy() {
	SpringClientFactory factory = new SpringClientFactory();
	AnnotationConfigApplicationContext parent = new AnnotationConfigApplicationContext();
	addEnvironment(parent, "ribbon.restclient.enabled=true");
	parent.register(RibbonAutoConfiguration.class, ArchaiusAutoConfiguration.class);
	parent.refresh();
	factory.setApplicationContext(parent);
	RestClient client = factory.getClient("foo", RestClient.class);
	ApacheHttpClient4 jerseyClient = (ApacheHttpClient4) client.getJerseyClient();
	assertEquals(CookiePolicy.IGNORE_COOKIES, jerseyClient.getClientHandler()
			.getHttpClient().getParams().getParameter(ClientPNames.COOKIE_POLICY));
	parent.close();
	factory.destroy();
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:17,代码来源:SpringClientFactoryTests.java

示例2: createClient

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
@Before
public void createClient() throws Exception {
  testProperties = new TestProperties();

  String applicationContextPath = getApplicationContextPath();
  APP_BASE_PATH = testProperties.getApplicationPath("/" + applicationContextPath);
  LOGGER.info("Connecting to application "+APP_BASE_PATH);

  ClientConfig clientConfig = new DefaultApacheHttpClient4Config();
  clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
  client = ApacheHttpClient4.create(clientConfig);

  defaultHttpClient = (DefaultHttpClient) client.getClientHandler().getHttpClient();
  HttpParams params = defaultHttpClient.getParams();
  HttpConnectionParams.setConnectionTimeout(params, 3 * 60 * 1000);
  HttpConnectionParams.setSoTimeout(params, 10 * 60 * 1000);
}
 
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:18,代码来源:AbstractWebappIntegrationTest.java

示例3: newApiClient

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
/**
 * @return a new jersey client using a multithreaded http client
 */
public WebResource newApiClient() {
  ClientConfig cc = new DefaultClientConfig();
  cc.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
  cc.getProperties().put(ClientConfig.PROPERTY_READ_TIMEOUT, timeout);
  cc.getProperties().put(ClientConfig.PROPERTY_CONNECT_TIMEOUT, timeout);
  cc.getClasses().add(JacksonJsonProvider.class);
  // use custom configured object mapper ignoring unknown properties
  cc.getClasses().add(ObjectMapperContextResolver.class);

  HttpClient http = HttpUtil.newMultithreadedClient(timeout, maxConnections, maxConnections);
  ApacheHttpClient4Handler hch = new ApacheHttpClient4Handler(http, null, false);
  Client client = new ApacheHttpClient4(hch, cc);

  LOG.info("Connecting to GBIF API: {}", url);
  return client.resource(url);
}
 
开发者ID:gbif,项目名称:occurrence,代码行数:20,代码来源:ApiClientConfiguration.java

示例4: createDefaultJerseyClient

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, MetricRegistry metricRegistry, String serviceName) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:8,代码来源:BlobStoreClientFactory.java

示例5: createDefaultJerseyClient

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:8,代码来源:UserAccessControlClientFactory.java

示例6: createDefaultJerseyClient

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
private static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration) {
    HttpClient httpClient = new HttpClientBuilder().using(configuration).build();
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    // For shading reasons we can't add a Jackson JSON message body provider.  However, our client implementation will
    // handle wrapping all request and response entities using the shaded Jackson so this shouldn't matter.
    return new ApacheHttpClient4(handler, config);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:9,代码来源:BlobStoreClientFactory.java

示例7: createDefaultJerseyClient

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
static ApacheHttpClient4 createDefaultJerseyClient(HttpClientConfiguration configuration, String serviceName, MetricRegistry metricRegistry) {
    HttpClient httpClient = new HttpClientBuilder(metricRegistry).using(configuration).build(serviceName);
    ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(httpClient, null, true);
    ApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getSingletons().add(new JacksonMessageBodyProvider(Jackson.newObjectMapper(), _validatorFactory.getValidator()));
    return new ApacheHttpClient4(handler, config);
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:8,代码来源:QueueClientFactory.java

示例8: providesJerseyClient

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
@Provides
@Singleton
@GeocodeWs
private Client providesJerseyClient() {
  ClientConfig clientConfig = new DefaultClientConfig();
  clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, true);
  return ApacheHttpClient4.create(clientConfig);
}
 
开发者ID:gbif,项目名称:geocode,代码行数:9,代码来源:GeocodeWsClientModule.java

示例9: apacheHttpClientSpecificInitialization

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
@Override
protected Client apacheHttpClientSpecificInitialization() {
	ApacheHttpClient4 apache = (ApacheHttpClient4) super.apacheHttpClientSpecificInitialization();
	apache.getClientHandler().getHttpClient().getParams().setParameter(
			ClientPNames.COOKIE_POLICY, CookiePolicy.IGNORE_COOKIES);
	return apache;
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:8,代码来源:RibbonClientConfiguration.java

示例10: DownloadClient

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
public DownloadClient(HttpAutomationClient httpAutomationClient) {

        ApacheHttpClient4Handler handler = new ApacheHttpClient4Handler(
                httpAutomationClient.http(), new BasicCookieStore(), false);
        client = new ApacheHttpClient4(handler);

        if (httpAutomationClient.getRequestInterceptor() != null) {
            client.addFilter(httpAutomationClient.getRequestInterceptor());
        }
        apiURL = httpAutomationClient.getBaseUrl();
    }
 
开发者ID:tiry,项目名称:nuxeo-mule-connector,代码行数:12,代码来源:DownloadClient.java

示例11: getClient

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
private Client getClient() {

    Client c = ApacheHttpClient4.create( data.config );
    if ( data.basicAuthentication != null ) {
      c.addFilter( data.basicAuthentication );
    }
    return c;
  }
 
开发者ID:pentaho,项目名称:pentaho-kettle,代码行数:9,代码来源:Rest.java

示例12: TestUtil

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
public TestUtil(TestProperties testProperties) {

    this.testProperties = testProperties;

    // create admin user:
    ClientConfig clientConfig = new DefaultApacheHttpClient4Config();
    clientConfig.getFeatures().put(JSONConfiguration.FEATURE_POJO_MAPPING, Boolean.TRUE);
    client = ApacheHttpClient4.create(clientConfig);

    defaultHttpClient = (DefaultHttpClient) client.getClientHandler().getHttpClient();
  }
 
开发者ID:camunda,项目名称:camunda-bpm-platform,代码行数:12,代码来源:TestUtil.java

示例13: buildDefaultClient

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
private Client buildDefaultClient() {
    Client client = new ApacheHttpClient4(buildClientHandler(buildHttpClient()), buildClientConfig());
    client.setExecutorService(determineExecutorService());
    client.addFilter(new GZIPContentEncodingFilter(true));
    return client;
}
 
开发者ID:BrettDuclos,项目名称:Dials,代码行数:7,代码来源:DialsClientBuilder.java

示例14: apacheClient

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
@Bean
public ApacheHttpClient4 apacheClient() {
	return Mockito.mock(ApacheHttpClient4.class);
}
 
开发者ID:spring-cloud,项目名称:spring-cloud-netflix,代码行数:5,代码来源:EurekaClientAutoConfigurationTests.java

示例15: main

import com.sun.jersey.client.apache4.ApacheHttpClient4; //导入依赖的package包/类
public static void main(final String[] args) throws Exception {
    
    //get the command line arguments
    if(args.length < 5) {
        printUseage();
        System.exit(1);
        return;
    }
    final String server = args[0];
    final int port = Integer.parseInt(args[1]);
    
    final String query = args[2];
    final File queryFile;
    if(query.charAt(0) == '@') {
       queryFile = new File(query.substring(1));
       if(!queryFile.exists()) {
           System.err.println("Query file '" + queryFile.getAbsolutePath() + "' does not exist!");
           System.exit(2);
        } 
    } else {
        queryFile = null;
    }
    
    final String path = args[3];
    final String username = args[4];
    final String password;
    if(args.length == 6) {
        password = args[5];
    } else {
        password = "";
    }
    
    //setup authentication
    final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
    credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials(username, password));
    final DefaultApacheHttpClient4Config config = new DefaultApacheHttpClient4Config();
    config.getProperties().put(ApacheHttpClient4Config.PROPERTY_CREDENTIALS_PROVIDER, credentialsProvider);
    
    //setup the Resource for the REST Server API Call
    final Client client = ApacheHttpClient4.create(config);
    final String uri = "http://" + server + ":" + port + "/exist/rest" + path;
    final WebResource resource;
    final ClientResponse response;
    
    logger.info("Starting Query of {}...", uri);
    
    if(queryFile == null) {
        resource = client.resource(uri + "?_query=" + URLEncoder.encode(query, "UTF-8"));
        logger.info("Using HTTP GET to perform the Query...");
        
        //GET the Resource
        response = resource.get(ClientResponse.class);
    } else {
        resource = client.resource(uri);
        logger.info("Using HTTP POST to perform the Query...");
        
        //POST the Resource
        response = resource.type(MediaType.APPLICATION_XML_TYPE).post(ClientResponse.class, createQueryDocument(queryFile));
    }
    
    
    final Status responseStatus = response.getClientResponseStatus();
    if(responseStatus == Status.OK) {
        ConsoleWriter.writeResponseBody(response, "Finished Query OK.");
    } else {
        logger.error("Received HTTP Response: {} {}", responseStatus.getStatusCode(), responseStatus.toString());
        System.exit(3);
    }
}
 
开发者ID:eXist-book,项目名称:book-code,代码行数:70,代码来源:QueryApp.java


注:本文中的com.sun.jersey.client.apache4.ApacheHttpClient4类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。