001/* 002 * Licensed to the Apache Software Foundation (ASF) under one or more 003 * contributor license agreements. See the NOTICE file distributed with 004 * this work for additional information regarding copyright ownership. 005 * The ASF licenses this file to You under the Apache License, Version 2.0 006 * (the "License"); you may not use this file except in compliance with 007 * the License. You may obtain a copy of the License at 008 * 009 * http://www.apache.org/licenses/LICENSE-2.0 010 * 011 * Unless required by applicable law or agreed to in writing, software 012 * distributed under the License is distributed on an "AS IS" BASIS, 013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 014 * See the License for the specific language governing permissions and 015 * limitations under the License. 016 */ 017package org.apache.juneau.rest.client.apachehttpclient45; 018 019import org.apache.juneau.rest.client.*; 020 021/** 022 * {@link HttpTransportProvider} implementation that supplies an {@link ApacheHc45Transport}. 023 * 024 * <p> 025 * Registered via {@code META-INF/services/org.apache.juneau.rest.client.HttpTransportProvider} so that 026 * {@code RestClient} can auto-discover Apache HttpClient 4.5 when this module is on the classpath. 027 * 028 * <h5 class='section'>See Also:</h5><ul> 029 * <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/NextGenRestClient">Next-Generation REST Client</a> 030 * </ul> 031 * 032 * @since 9.2.1 033 */ 034@SuppressWarnings({ 035 "resource" // Provider methods return Closeables owned by the caller; Eclipse JDT @Owning warning is by design. 036}) 037public final class ApacheHc45TransportProvider implements HttpTransportProvider { 038 039 @Override /* HttpTransportProvider */ 040 public int getPriority() { 041 return 50; 042 } 043 044 @Override /* HttpTransportProvider */ 045 public boolean isAvailable() { 046 try { 047 Class.forName("org.apache.http.impl.client.CloseableHttpClient"); 048 return true; 049 } catch (ClassNotFoundException e) { // HTT: HttpClient 4.5 is a compile-time dependency of this module, so it is always on the test classpath 050 return false; // HTT: unreachable while this module's own dependency is present 051 } 052 } 053 054 @Override /* HttpTransportProvider */ 055 public HttpTransport create() { 056 return ApacheHc45Transport.create(); 057 } 058}