001// *************************************************************************************************************************** 002// * Licensed to the Apache Software Foundation (ASF) under one or more contributor license agreements. See the NOTICE file * 003// * distributed with this work for additional information regarding copyright ownership. The ASF licenses this file * 004// * to you under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance * 005// * with the License. You may obtain a copy of the License at * 006// * * 007// * http://www.apache.org/licenses/LICENSE-2.0 * 008// * * 009// * Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an * 010// * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the * 011// * specific language governing permissions and limitations under the License. * 012// *************************************************************************************************************************** 013package org.apache.juneau.rest.client.mock; 014 015import java.io.*; 016import java.util.concurrent.*; 017 018import org.apache.http.*; 019import org.apache.http.conn.*; 020import org.apache.http.conn.routing.*; 021import org.apache.http.protocol.*; 022import org.apache.juneau.utils.*; 023 024/** 025 * An implementation of {@link HttpClientConnectionManager} specifically for use in mocked connections using the {@link MockHttpConnection} class. 026 * 027 * This implementation is NOT thread safe. 028 */ 029public class MockHttpClientConnectionManager implements HttpClientConnectionManager { 030 031 final ConnectionRequest cr; 032 033 /** 034 * Constructor. 035 * 036 * @param c The mocked connection. 037 */ 038 public MockHttpClientConnectionManager(final MockHttpConnection c) { 039 final HttpClientConnection hcc = new MockHttpClientConnection(c); 040 this.cr = new ConnectionRequest() { 041 @Override 042 public boolean cancel() { 043 return false; 044 } 045 @Override 046 public HttpClientConnection get(long timeout, TimeUnit tunit) throws InterruptedException, ExecutionException, ConnectionPoolTimeoutException { 047 return hcc; 048 } 049 }; 050 } 051 052 @Override /* HttpClientConnectionManager */ 053 public ConnectionRequest requestConnection(HttpRoute route, Object state) { 054 return cr; 055 } 056 057 @Override /* HttpClientConnectionManager */ 058 public void releaseConnection(HttpClientConnection conn, Object newState, long validDuration, TimeUnit timeUnit) {} 059 060 @Override /* HttpClientConnectionManager */ 061 public void connect(HttpClientConnection conn, HttpRoute route, int connectTimeout, HttpContext context) throws IOException {} 062 063 @Override /* HttpClientConnectionManager */ 064 public void upgrade(HttpClientConnection conn, HttpRoute route, HttpContext context) throws IOException {} 065 066 @Override /* HttpClientConnectionManager */ 067 public void routeComplete(HttpClientConnection conn, HttpRoute route, HttpContext context) throws IOException {} 068 069 @Override /* HttpClientConnectionManager */ 070 public void closeIdleConnections(long idletime, TimeUnit tunit) {} 071 072 @Override /* HttpClientConnectionManager */ 073 public void closeExpiredConnections() {} 074 075 @Override /* HttpClientConnectionManager */ 076 public void shutdown() {} 077}