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; 018 019/** 020 * {@link HttpTransportProvider} implementation that supplies a {@link JavaHttpTransport}. 021 * 022 * <p> 023 * Registered via {@code META-INF/services/HttpTransportProvider} so that 024 * {@code RestClient} auto-discovers the JDK HTTP client when no higher-priority transport is present. 025 * Since the JDK transport ships in the {@code juneau-rest-client} artifact itself, it is always available 026 * unless overridden by a sibling transport module with a lower priority value. 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" // Not owned here; lifecycle is managed by the surrounding context 036}) 037public final class JavaHttpTransportProvider implements HttpTransportProvider { 038 039 @Override /* HttpTransportProvider */ 040 public int getPriority() { 041 return 80; 042 } 043 044 @Override /* HttpTransportProvider */ 045 public boolean isAvailable() { 046 try { 047 Class.forName("java.net.http.HttpClient"); 048 return true; 049 } catch (ClassNotFoundException e) { 050 return false; 051 } 052 } 053 054 @Override /* HttpTransportProvider */ 055 public HttpTransport create() { 056 return JavaHttpTransport.create(); 057 } 058}