new connection interfaces, step 1
git-svn-id: https://svn.apache.org/repos/asf/jakarta/httpcomponents/httpclient/trunk@492175 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
fc00950965
commit
661ee70ce0
|
@ -0,0 +1,138 @@
|
|||
/*
|
||||
* $HeadURL$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.http.conn;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
|
||||
import org.apache.http.HttpClientConnection;
|
||||
import org.apache.http.HttpInetConnection;
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.params.HttpParams;
|
||||
|
||||
|
||||
//@@@ merge this interface into HttpCore?
|
||||
public interface UnmanagedClientConnection
|
||||
extends HttpClientConnection, HttpInetConnection {
|
||||
|
||||
/**
|
||||
* Obtains the target host for this connection.
|
||||
* If the connection is to a proxy but not tunnelled, this is
|
||||
* the proxy. If the connection is tunnelled through a proxy,
|
||||
* this is the target of the tunnel.
|
||||
* <br/>
|
||||
* The return value is well-defined only while the connection is open.
|
||||
* It may change even while the connection is open,
|
||||
* because of an {@link #update update}.
|
||||
*
|
||||
* @return the host to which this connection is opened
|
||||
*/
|
||||
HttpHost getTargetHost()
|
||||
;
|
||||
|
||||
/**
|
||||
* Indicates whether this connection is secure.
|
||||
* The return value is well-defined only while the connection is open.
|
||||
* It may change even while the connection is open,
|
||||
* because of an {@link #update update}.
|
||||
*
|
||||
* @return <code>true</code> if this connection is secure,
|
||||
* <code>false</code> otherwise
|
||||
*/
|
||||
boolean isSecure()
|
||||
;
|
||||
|
||||
/**
|
||||
* Obtains the socket for this connection.
|
||||
* The return value is well-defined only while the connection is open.
|
||||
* It may change even while the connection is open,
|
||||
* because of an {@link #update update}.
|
||||
*
|
||||
* @return the socket for communicating with the
|
||||
* {@link #getTargetHost target host}
|
||||
*/
|
||||
Socket getSocket()
|
||||
;
|
||||
|
||||
|
||||
// There is no getParams(). For the moment, we
|
||||
// do not require connections to store parameters.
|
||||
|
||||
|
||||
/**
|
||||
* Opens this connection.
|
||||
* A connection can be openend only while it is closed.
|
||||
* To modify a connection while it is open, use {@link #update update}.
|
||||
*
|
||||
* @param sock the open socket for communicating with the target host
|
||||
* @param target the target host of this connection
|
||||
* @param secure <code>true</code> if this connection is secure, for
|
||||
* example if an <code>SSLSocket</code> is used, or
|
||||
* <code>false</code> if it is not secure
|
||||
* @param params parameters for this connection. The parameters will
|
||||
* be used when creating dependent objects, for example
|
||||
* to determine buffer sizes.
|
||||
*/
|
||||
void open(Socket sock, HttpHost target,
|
||||
boolean secure, HttpParams params)
|
||||
throws IOException
|
||||
;
|
||||
|
||||
|
||||
/**
|
||||
* Updates this connection.
|
||||
* A connection can be updated only while it is open.
|
||||
* Updates are used for example when a tunnel has been established,
|
||||
* or when a TLS/SSL connection has been layered on top of a plain
|
||||
* socket connection.
|
||||
* <br/>
|
||||
* <b>Note:</b> Updating the connection will <i>not</i> close the
|
||||
* previously used socket. It is the caller's responsibility to close
|
||||
* that socket if it is no longer required.
|
||||
*
|
||||
* @param sock the new socket for communicating with the target host,
|
||||
* or <code>null</code> to continue using the old socket.
|
||||
* If <code>null</code> is passed, helper objects that
|
||||
* depend on the socket should be re-used. In that case,
|
||||
* some changes in the parameters will not take effect.
|
||||
* @param target the new target host of this connection
|
||||
* @param secure <code>true</code> if this connection is now secure,
|
||||
* <code>false</code> if it is not secure
|
||||
* @param params new parameters for this connection
|
||||
*/
|
||||
void update(Socket sock, HttpHost target,
|
||||
boolean secure, HttpParams params)
|
||||
throws IOException
|
||||
;
|
||||
|
||||
|
||||
} // interface UnmanagedClientConnection
|
|
@ -0,0 +1,136 @@
|
|||
/*
|
||||
* $HeadURL$
|
||||
* $Revision$
|
||||
* $Date$
|
||||
*
|
||||
* ====================================================================
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
* ====================================================================
|
||||
*
|
||||
* This software consists of voluntary contributions made by many
|
||||
* individuals on behalf of the Apache Software Foundation. For more
|
||||
* information on the Apache Software Foundation, please see
|
||||
* <http://www.apache.org/>.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.apache.http.conn.impl;
|
||||
|
||||
|
||||
import java.io.IOException;
|
||||
import java.net.Socket;
|
||||
|
||||
import org.apache.http.HttpHost;
|
||||
import org.apache.http.params.HttpParams;
|
||||
import org.apache.http.impl.SocketHttpClientConnection;
|
||||
|
||||
import org.apache.http.conn.UnmanagedClientConnection;
|
||||
|
||||
|
||||
/**
|
||||
* Default implementation of a managed client connection.
|
||||
*
|
||||
* @author Roland Weber (rolandw@apache.org)
|
||||
*
|
||||
*
|
||||
* <!-- empty lines to avoid svn diff problems -->
|
||||
* @version $Revision$ $Date$
|
||||
*
|
||||
*/
|
||||
public class DefaultClientConnection extends SocketHttpClientConnection
|
||||
implements UnmanagedClientConnection {
|
||||
|
||||
/** The target host of this connection. */
|
||||
private HttpHost targetHost;
|
||||
|
||||
/** Whether this connection is secure. */
|
||||
private boolean connSecure;
|
||||
|
||||
|
||||
|
||||
// public default constructor
|
||||
|
||||
|
||||
// non-javadoc, see interface UnmanagedClientConnection
|
||||
public final HttpHost getTargetHost() {
|
||||
return this.targetHost;
|
||||
}
|
||||
|
||||
|
||||
// non-javadoc, see interface UnmanagedClientConnection
|
||||
public final boolean isSecure() {
|
||||
return this.connSecure;
|
||||
}
|
||||
|
||||
|
||||
// non-javadoc, see interface UnmanagedClientConnection
|
||||
public final Socket getSocket() {
|
||||
return this.socket; // base class attribute
|
||||
}
|
||||
|
||||
|
||||
// non-javadoc, see interface UnmanagedClientConnection
|
||||
public void open(Socket sock, HttpHost target,
|
||||
boolean secure, HttpParams params)
|
||||
throws IOException {
|
||||
|
||||
assertNotOpen();
|
||||
if (sock == null) {
|
||||
throw new IllegalArgumentException
|
||||
("Socket must not be null.");
|
||||
}
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException
|
||||
("Target host must not be null.");
|
||||
}
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException
|
||||
("Parameters must not be null.");
|
||||
}
|
||||
|
||||
bind(sock, params);
|
||||
targetHost = target;
|
||||
connSecure = secure;
|
||||
|
||||
} // open
|
||||
|
||||
|
||||
// non-javadoc, see interface UnmanagedClientConnection
|
||||
public void update(Socket sock, HttpHost target,
|
||||
boolean secure, HttpParams params)
|
||||
throws IOException {
|
||||
|
||||
assertOpen();
|
||||
if (target == null) {
|
||||
throw new IllegalArgumentException
|
||||
("Target host must not be null.");
|
||||
}
|
||||
if (params == null) {
|
||||
throw new IllegalArgumentException
|
||||
("Parameters must not be null.");
|
||||
}
|
||||
|
||||
if (sock != null)
|
||||
bind(sock, params);
|
||||
targetHost = target;
|
||||
connSecure = secure;
|
||||
|
||||
} // update
|
||||
|
||||
|
||||
} // class DefaultClientConnection
|
Loading…
Reference in New Issue