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
019import java.net.http.*;
020
021/**
022 * Fluent builder for {@link JavaHttpTransport}.
023 *
024 * <p>
025 * Obtain an instance via {@link JavaHttpTransport#builder()}.
026 *
027 * <h5 class='section'>See Also:</h5><ul>
028 *    <li class='link'><a class="doclink" href="https://juneau.apache.org/docs/topics/NextGenRestClient">Next-Generation REST Client</a>
029 * </ul>
030 *
031 * @since 9.2.1
032 */
033@SuppressWarnings({
034   "resource" // Not owned here; lifecycle is managed by the surrounding context
035})
036public final class JavaHttpTransportBuilder {
037
038   HttpClient httpClient;
039
040   JavaHttpTransportBuilder() {}
041
042   /**
043    * Sets the underlying {@link HttpClient} to use.
044    *
045    * <p>
046    * If not set, a default client is created via {@link HttpClient#newHttpClient()}.
047    *
048    * @param value The client to use. Can be <jk>null</jk> (a default client is created via {@link HttpClient#newHttpClient()}).
049    * @return This object.
050    */
051   public JavaHttpTransportBuilder httpClient(HttpClient value) {
052      httpClient = value;
053      return this;
054   }
055
056   /**
057    * Builds and returns the {@link JavaHttpTransport}.
058    *
059    * @return A new instance. Never <jk>null</jk>.
060    */
061   public JavaHttpTransport build() {
062      return new JavaHttpTransport(this);
063   }
064}