1 /* 2 * ==================================================================== 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * ==================================================================== 20 * 21 * This software consists of voluntary contributions made by many 22 * individuals on behalf of the Apache Software Foundation. For more 23 * information on the Apache Software Foundation, please see 24 * <http://www.apache.org/>. 25 * 26 */ 27 28 package org.apache.hc.client5.http.io; 29 30 import java.io.IOException; 31 32 import org.apache.hc.client5.http.EndpointInfo; 33 import org.apache.hc.core5.annotation.Contract; 34 import org.apache.hc.core5.annotation.Internal; 35 import org.apache.hc.core5.annotation.ThreadingBehavior; 36 import org.apache.hc.core5.http.ClassicHttpRequest; 37 import org.apache.hc.core5.http.ClassicHttpResponse; 38 import org.apache.hc.core5.http.HttpException; 39 import org.apache.hc.core5.http.impl.io.HttpRequestExecutor; 40 import org.apache.hc.core5.http.io.HttpClientConnection; 41 import org.apache.hc.core5.http.protocol.HttpContext; 42 import org.apache.hc.core5.io.ModalCloseable; 43 import org.apache.hc.core5.util.Timeout; 44 45 /** 46 * Client endpoint leased from a connection manager. Client points can be used 47 * to execute HTTP requests. 48 * <p> 49 * Once the endpoint is no longer needed it MUST be released with {@link #close(org.apache.hc.core5.io.CloseMode)} )}. 50 * </p> 51 * 52 * @since 5.0 53 */ 54 @Contract(threading = ThreadingBehavior.SAFE) 55 public abstract class ConnectionEndpoint implements ModalCloseable { 56 57 /** 58 * @deprecated Use {@link #execute(String, ClassicHttpRequest, RequestExecutor, HttpContext)} 59 */ 60 @Deprecated 61 public abstract ClassicHttpResponse execute( 62 String id, 63 ClassicHttpRequest request, 64 HttpRequestExecutor executor, 65 HttpContext context) throws IOException, HttpException; 66 67 /** 68 * Executes HTTP request using the provided request executor. 69 * <p> 70 * Once the endpoint is no longer needed it MUST be released with {@link #close(org.apache.hc.core5.io.CloseMode)}. 71 * </p> 72 * 73 * @param id unique operation ID or {@code null}. 74 * @param request the request message. 75 * @param requestExecutor the request executor. 76 * @param context the execution context. 77 * 78 * @since 5.4 79 */ 80 // In the next major release this method must be made abstract. 81 public ClassicHttpResponse execute( 82 final String id, 83 final ClassicHttpRequest request, 84 final RequestExecutor requestExecutor, 85 final HttpContext context) throws IOException, HttpException { 86 return requestExecutor.execute(request,null, context); 87 } 88 89 /** 90 * Determines if the connection to the remote endpoint is still open and valid. 91 */ 92 public abstract boolean isConnected(); 93 94 /** 95 * Sets the socket timeout value. 96 * 97 * @param timeout timeout value 98 */ 99 public abstract void setSocketTimeout(Timeout timeout); 100 101 /** 102 * Returns information about the endpoint or {@code null} when not connected. 103 * 104 * @since 5.4 105 */ 106 public EndpointInfo getInfo() { 107 return null; 108 } 109 110 /** 111 * @since 5.4 112 */ 113 @Internal 114 public interface RequestExecutor { 115 116 ClassicHttpResponse execute( 117 ClassicHttpRequest request, 118 HttpClientConnection conn, 119 HttpContext context) throws IOException, HttpException; 120 121 } 122 123 }