code
stringlengths 1
2.01M
| repo_name
stringlengths 3
62
| path
stringlengths 1
267
| language
stringclasses 231
values | license
stringclasses 13
values | size
int64 1
2.01M
|
|---|---|---|---|---|---|
/*
* ====================================================================
*
* 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.ogt.http.auth;
import org.apache.ogt.http.ProtocolException;
import org.apache.ogt.http.annotation.Immutable;
/**
* Signals a failure in authentication process
*
*
* @since 4.0
*/
@Immutable
public class AuthenticationException extends ProtocolException {
private static final long serialVersionUID = -6794031905674764776L;
/**
* Creates a new AuthenticationException with a <tt>null</tt> detail message.
*/
public AuthenticationException() {
super();
}
/**
* Creates a new AuthenticationException with the specified message.
*
* @param message the exception detail message
*/
public AuthenticationException(String message) {
super(message);
}
/**
* Creates a new AuthenticationException with the specified detail message and cause.
*
* @param message the exception detail message
* @param cause the <tt>Throwable</tt> that caused this exception, or <tt>null</tt>
* if the cause is unavailable, unknown, or not a <tt>Throwable</tt>
*/
public AuthenticationException(String message, Throwable cause) {
super(message, cause);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/auth/AuthenticationException.java
|
Java
|
gpl3
| 2,378
|
/*
* ====================================================================
*
* 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.ogt.http.auth;
import java.security.Principal;
/**
* This interface represents a set of credentials consisting of a security
* principal and a secret (password) that can be used to establish user
* identity
*
* @since 4.0
*/
public interface Credentials {
Principal getUserPrincipal();
String getPassword();
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/auth/Credentials.java
|
Java
|
gpl3
| 1,542
|
/*
* ====================================================================
*
* 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.ogt.http.auth;
import java.util.ArrayList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.ogt.http.annotation.ThreadSafe;
import org.apache.ogt.http.params.HttpParams;
/**
* Authentication scheme registry that can be used to obtain the corresponding
* authentication scheme implementation for a given type of authorization challenge.
*
* @since 4.0
*/
@ThreadSafe
public final class AuthSchemeRegistry {
private final ConcurrentHashMap<String,AuthSchemeFactory> registeredSchemes;
public AuthSchemeRegistry() {
super();
this.registeredSchemes = new ConcurrentHashMap<String,AuthSchemeFactory>();
}
/**
* Registers a {@link AuthSchemeFactory} with the given identifier. If a factory with the
* given name already exists it will be overridden. This name is the same one used to
* retrieve the {@link AuthScheme authentication scheme} from {@link #getAuthScheme}.
*
* <p>
* Please note that custom authentication preferences, if used, need to be updated accordingly
* for the new {@link AuthScheme authentication scheme} to take effect.
* </p>
*
* @param name the identifier for this scheme
* @param factory the {@link AuthSchemeFactory} class to register
*
* @see #getAuthScheme
*/
public void register(
final String name,
final AuthSchemeFactory factory) {
if (name == null) {
throw new IllegalArgumentException("Name may not be null");
}
if (factory == null) {
throw new IllegalArgumentException("Authentication scheme factory may not be null");
}
registeredSchemes.put(name.toLowerCase(Locale.ENGLISH), factory);
}
/**
* Unregisters the class implementing an {@link AuthScheme authentication scheme} with
* the given name.
*
* @param name the identifier of the class to unregister
*/
public void unregister(final String name) {
if (name == null) {
throw new IllegalArgumentException("Name may not be null");
}
registeredSchemes.remove(name.toLowerCase(Locale.ENGLISH));
}
/**
* Gets the {@link AuthScheme authentication scheme} with the given name.
*
* @param name the {@link AuthScheme authentication scheme} identifier
* @param params the {@link HttpParams HTTP parameters} for the authentication
* scheme.
*
* @return {@link AuthScheme authentication scheme}
*
* @throws IllegalStateException if a scheme with the given name cannot be found
*/
public AuthScheme getAuthScheme(final String name, final HttpParams params)
throws IllegalStateException {
if (name == null) {
throw new IllegalArgumentException("Name may not be null");
}
AuthSchemeFactory factory = registeredSchemes.get(name.toLowerCase(Locale.ENGLISH));
if (factory != null) {
return factory.newInstance(params);
} else {
throw new IllegalStateException("Unsupported authentication scheme: " + name);
}
}
/**
* Obtains a list containing the names of all registered {@link AuthScheme authentication
* schemes}
*
* @return list of registered scheme names
*/
public List<String> getSchemeNames() {
return new ArrayList<String>(registeredSchemes.keySet());
}
/**
* Populates the internal collection of registered {@link AuthScheme authentication schemes}
* with the content of the map passed as a parameter.
*
* @param map authentication schemes
*/
public void setItems(final Map<String, AuthSchemeFactory> map) {
if (map == null) {
return;
}
registeredSchemes.clear();
registeredSchemes.putAll(map);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/auth/AuthSchemeRegistry.java
|
Java
|
gpl3
| 5,147
|
/*
* ====================================================================
*
* 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.ogt.http.auth;
import org.apache.ogt.http.Header;
import org.apache.ogt.http.HttpRequest;
/**
* This interface represents an abstract challenge-response oriented
* authentication scheme.
* <p>
* An authentication scheme should be able to support the following
* functions:
* <ul>
* <li>Parse and process the challenge sent by the target server
* in response to request for a protected resource
* <li>Provide its textual designation
* <li>Provide its parameters, if available
* <li>Provide the realm this authentication scheme is applicable to,
* if available
* <li>Generate authorization string for the given set of credentials
* and the HTTP request in response to the authorization challenge.
* </ul>
* <p>
* Authentication schemes may be stateful involving a series of
* challenge-response exchanges.
* <p>
* IMPORTANT: implementations of this interface MUST also implement {@link ContextAwareAuthScheme}
* interface in order to remain API compatible with newer versions of HttpClient.
*
* @since 4.0
*/
public interface AuthScheme {
/**
* Processes the given challenge token. Some authentication schemes
* may involve multiple challenge-response exchanges. Such schemes must be able
* to maintain the state information when dealing with sequential challenges
*
* @param header the challenge header
*/
void processChallenge(final Header header) throws MalformedChallengeException;
/**
* Returns textual designation of the given authentication scheme.
*
* @return the name of the given authentication scheme
*/
String getSchemeName();
/**
* Returns authentication parameter with the given name, if available.
*
* @param name The name of the parameter to be returned
*
* @return the parameter with the given name
*/
String getParameter(final String name);
/**
* Returns authentication realm. If the concept of an authentication
* realm is not applicable to the given authentication scheme, returns
* <code>null</code>.
*
* @return the authentication realm
*/
String getRealm();
/**
* Tests if the authentication scheme is provides authorization on a per
* connection basis instead of usual per request basis
*
* @return <tt>true</tt> if the scheme is connection based, <tt>false</tt>
* if the scheme is request based.
*/
boolean isConnectionBased();
/**
* Authentication process may involve a series of challenge-response exchanges.
* This method tests if the authorization process has been completed, either
* successfully or unsuccessfully, that is, all the required authorization
* challenges have been processed in their entirety.
*
* @return <tt>true</tt> if the authentication process has been completed,
* <tt>false</tt> otherwise.
*/
boolean isComplete();
/**
* Produces an authorization string for the given set of {@link Credentials}.
*
* @param credentials The set of credentials to be used for athentication
* @param request The request being authenticated
* @throws AuthenticationException if authorization string cannot
* be generated due to an authentication failure
*
* @return the authorization string
*
* @deprecated Use {@link ContextAwareAuthScheme#authenticate(Credentials, HttpRequest, org.apache.ogt.http.protocol.HttpContext)}
*/
@Deprecated
Header authenticate(Credentials credentials, HttpRequest request)
throws AuthenticationException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/auth/AuthScheme.java
|
Java
|
gpl3
| 4,852
|
/*
* ====================================================================
*
* 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.ogt.http.auth;
import java.util.Locale;
import org.apache.ogt.http.annotation.Immutable;
import org.apache.ogt.http.util.LangUtils;
/**
* The class represents an authentication scope consisting of a host name,
* a port number, a realm name and an authentication scheme name which
* {@link Credentials Credentials} apply to.
*
*
* @since 4.0
*/
@Immutable
public class AuthScope {
/**
* The <tt>null</tt> value represents any host. In the future versions of
* HttpClient the use of this parameter will be discontinued.
*/
public static final String ANY_HOST = null;
/**
* The <tt>-1</tt> value represents any port.
*/
public static final int ANY_PORT = -1;
/**
* The <tt>null</tt> value represents any realm.
*/
public static final String ANY_REALM = null;
/**
* The <tt>null</tt> value represents any authentication scheme.
*/
public static final String ANY_SCHEME = null;
/**
* Default scope matching any host, port, realm and authentication scheme.
* In the future versions of HttpClient the use of this parameter will be
* discontinued.
*/
public static final AuthScope ANY = new AuthScope(ANY_HOST, ANY_PORT, ANY_REALM, ANY_SCHEME);
/** The authentication scheme the credentials apply to. */
private final String scheme;
/** The realm the credentials apply to. */
private final String realm;
/** The host the credentials apply to. */
private final String host;
/** The port the credentials apply to. */
private final int port;
/** Creates a new credentials scope for the given
* <tt>host</tt>, <tt>port</tt>, <tt>realm</tt>, and
* <tt>authentication scheme</tt>.
*
* @param host the host the credentials apply to. May be set
* to <tt>null</tt> if credentials are applicable to
* any host.
* @param port the port the credentials apply to. May be set
* to negative value if credentials are applicable to
* any port.
* @param realm the realm the credentials apply to. May be set
* to <tt>null</tt> if credentials are applicable to
* any realm.
* @param scheme the authentication scheme the credentials apply to.
* May be set to <tt>null</tt> if credentials are applicable to
* any authentication scheme.
*/
public AuthScope(final String host, int port,
final String realm, final String scheme)
{
this.host = (host == null) ? ANY_HOST: host.toLowerCase(Locale.ENGLISH);
this.port = (port < 0) ? ANY_PORT: port;
this.realm = (realm == null) ? ANY_REALM: realm;
this.scheme = (scheme == null) ? ANY_SCHEME: scheme.toUpperCase(Locale.ENGLISH);
}
/** Creates a new credentials scope for the given
* <tt>host</tt>, <tt>port</tt>, <tt>realm</tt>, and any
* authentication scheme.
*
* @param host the host the credentials apply to. May be set
* to <tt>null</tt> if credentials are applicable to
* any host.
* @param port the port the credentials apply to. May be set
* to negative value if credentials are applicable to
* any port.
* @param realm the realm the credentials apply to. May be set
* to <tt>null</tt> if credentials are applicable to
* any realm.
*/
public AuthScope(final String host, int port, final String realm) {
this(host, port, realm, ANY_SCHEME);
}
/** Creates a new credentials scope for the given
* <tt>host</tt>, <tt>port</tt>, any realm name, and any
* authentication scheme.
*
* @param host the host the credentials apply to. May be set
* to <tt>null</tt> if credentials are applicable to
* any host.
* @param port the port the credentials apply to. May be set
* to negative value if credentials are applicable to
* any port.
*/
public AuthScope(final String host, int port) {
this(host, port, ANY_REALM, ANY_SCHEME);
}
/**
* Creates a copy of the given credentials scope.
*/
public AuthScope(final AuthScope authscope) {
super();
if (authscope == null) {
throw new IllegalArgumentException("Scope may not be null");
}
this.host = authscope.getHost();
this.port = authscope.getPort();
this.realm = authscope.getRealm();
this.scheme = authscope.getScheme();
}
/**
* @return the host
*/
public String getHost() {
return this.host;
}
/**
* @return the port
*/
public int getPort() {
return this.port;
}
/**
* @return the realm name
*/
public String getRealm() {
return this.realm;
}
/**
* @return the scheme type
*/
public String getScheme() {
return this.scheme;
}
/**
* Tests if the authentication scopes match.
*
* @return the match factor. Negative value signifies no match.
* Non-negative signifies a match. The greater the returned value
* the closer the match.
*/
public int match(final AuthScope that) {
int factor = 0;
if (LangUtils.equals(this.scheme, that.scheme)) {
factor += 1;
} else {
if (this.scheme != ANY_SCHEME && that.scheme != ANY_SCHEME) {
return -1;
}
}
if (LangUtils.equals(this.realm, that.realm)) {
factor += 2;
} else {
if (this.realm != ANY_REALM && that.realm != ANY_REALM) {
return -1;
}
}
if (this.port == that.port) {
factor += 4;
} else {
if (this.port != ANY_PORT && that.port != ANY_PORT) {
return -1;
}
}
if (LangUtils.equals(this.host, that.host)) {
factor += 8;
} else {
if (this.host != ANY_HOST && that.host != ANY_HOST) {
return -1;
}
}
return factor;
}
/**
* @see java.lang.Object#equals(Object)
*/
@Override
public boolean equals(Object o) {
if (o == null) {
return false;
}
if (o == this) {
return true;
}
if (!(o instanceof AuthScope)) {
return super.equals(o);
}
AuthScope that = (AuthScope) o;
return
LangUtils.equals(this.host, that.host)
&& this.port == that.port
&& LangUtils.equals(this.realm, that.realm)
&& LangUtils.equals(this.scheme, that.scheme);
}
/**
* @see java.lang.Object#toString()
*/
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
if (this.scheme != null) {
buffer.append(this.scheme.toUpperCase(Locale.ENGLISH));
buffer.append(' ');
}
if (this.realm != null) {
buffer.append('\'');
buffer.append(this.realm);
buffer.append('\'');
} else {
buffer.append("<any realm>");
}
if (this.host != null) {
buffer.append('@');
buffer.append(this.host);
if (this.port >= 0) {
buffer.append(':');
buffer.append(this.port);
}
}
return buffer.toString();
}
/**
* @see java.lang.Object#hashCode()
*/
@Override
public int hashCode() {
int hash = LangUtils.HASH_SEED;
hash = LangUtils.hashCode(hash, this.host);
hash = LangUtils.hashCode(hash, this.port);
hash = LangUtils.hashCode(hash, this.realm);
hash = LangUtils.hashCode(hash, this.scheme);
return hash;
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/auth/AuthScope.java
|
Java
|
gpl3
| 9,049
|
/*
* ====================================================================
*
* 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.ogt.http.auth;
import java.io.Serializable;
import java.security.Principal;
import java.util.Locale;
import org.apache.ogt.http.annotation.Immutable;
import org.apache.ogt.http.util.LangUtils;
/**
* Microsoft Windows specific user principal implementation.
*
* @since 4.0
*/
@Immutable
public class NTUserPrincipal implements Principal, Serializable {
private static final long serialVersionUID = -6870169797924406894L;
private final String username;
private final String domain;
private final String ntname;
public NTUserPrincipal(
final String domain,
final String username) {
super();
if (username == null) {
throw new IllegalArgumentException("User name may not be null");
}
this.username = username;
if (domain != null) {
this.domain = domain.toUpperCase(Locale.ENGLISH);
} else {
this.domain = null;
}
if (this.domain != null && this.domain.length() > 0) {
StringBuilder buffer = new StringBuilder();
buffer.append(this.domain);
buffer.append('/');
buffer.append(this.username);
this.ntname = buffer.toString();
} else {
this.ntname = this.username;
}
}
public String getName() {
return this.ntname;
}
public String getDomain() {
return this.domain;
}
public String getUsername() {
return this.username;
}
@Override
public int hashCode() {
int hash = LangUtils.HASH_SEED;
hash = LangUtils.hashCode(hash, this.username);
hash = LangUtils.hashCode(hash, this.domain);
return hash;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof NTUserPrincipal) {
NTUserPrincipal that = (NTUserPrincipal) o;
if (LangUtils.equals(this.username, that.username)
&& LangUtils.equals(this.domain, that.domain)) {
return true;
}
}
return false;
}
@Override
public String toString() {
return this.ntname;
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/auth/NTUserPrincipal.java
|
Java
|
gpl3
| 3,428
|
/*
* ====================================================================
*
* 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.ogt.http.auth;
import org.apache.ogt.http.Header;
import org.apache.ogt.http.HttpRequest;
import org.apache.ogt.http.protocol.HttpContext;
/**
* This interface represents an extended authentication scheme
* that requires access to {@link HttpContext} in order to
* generate an authorization string.
*
* TODO: Fix AuthScheme interface in the next major version
*
* @since 4.1
*/
public interface ContextAwareAuthScheme extends AuthScheme {
/**
* Produces an authorization string for the given set of
* {@link Credentials}.
*
* @param credentials The set of credentials to be used for athentication
* @param request The request being authenticated
* @param context HTTP context
* @throws AuthenticationException if authorization string cannot
* be generated due to an authentication failure
*
* @return the authorization string
*/
Header authenticate(
Credentials credentials,
HttpRequest request,
HttpContext context) throws AuthenticationException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/auth/ContextAwareAuthScheme.java
|
Java
|
gpl3
| 2,279
|
/*
* ====================================================================
* 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.ogt.http.auth;
import org.apache.ogt.http.annotation.Immutable;
/**
* Constants and static helpers related to the HTTP authentication.
*
*
* @since 4.0
*/
@Immutable
public final class AUTH {
/**
* The www authenticate challange header.
*/
public static final String WWW_AUTH = "WWW-Authenticate";
/**
* The www authenticate response header.
*/
public static final String WWW_AUTH_RESP = "Authorization";
/**
* The proxy authenticate challange header.
*/
public static final String PROXY_AUTH = "Proxy-Authenticate";
/**
* The proxy authenticate response header.
*/
public static final String PROXY_AUTH_RESP = "Proxy-Authorization";
private AUTH() {
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/auth/AUTH.java
|
Java
|
gpl3
| 1,952
|
/*
* ====================================================================
*
* 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.ogt.http.auth;
import java.io.Serializable;
import java.security.Principal;
import org.apache.ogt.http.annotation.Immutable;
import org.apache.ogt.http.util.LangUtils;
/**
* Basic user principal used for HTTP authentication
*
* @since 4.0
*/
@Immutable
public final class BasicUserPrincipal implements Principal, Serializable {
private static final long serialVersionUID = -2266305184969850467L;
private final String username;
public BasicUserPrincipal(final String username) {
super();
if (username == null) {
throw new IllegalArgumentException("User name may not be null");
}
this.username = username;
}
public String getName() {
return this.username;
}
@Override
public int hashCode() {
int hash = LangUtils.HASH_SEED;
hash = LangUtils.hashCode(hash, this.username);
return hash;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o instanceof BasicUserPrincipal) {
BasicUserPrincipal that = (BasicUserPrincipal) o;
if (LangUtils.equals(this.username, that.username)) {
return true;
}
}
return false;
}
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append("[principal: ");
buffer.append(this.username);
buffer.append("]");
return buffer.toString();
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/auth/BasicUserPrincipal.java
|
Java
|
gpl3
| 2,715
|
/*
* ====================================================================
*
* 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.ogt.http.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* The field or method to which this annotation is applied can only be accessed
* when holding a particular lock, which may be a built-in (synchronization) lock,
* or may be an explicit java.util.concurrent.Lock.
*
* The argument determines which lock guards the annotated field or method:
* <ul>
* <li>
* <code>this</code> : The intrinsic lock of the object in whose class the field is defined.
* </li>
* <li>
* <code>class-name.this</code> : For inner classes, it may be necessary to disambiguate 'this';
* the <em>class-name.this</em> designation allows you to specify which 'this' reference is intended
* </li>
* <li>
* <code>itself</code> : For reference fields only; the object to which the field refers.
* </li>
* <li>
* <code>field-name</code> : The lock object is referenced by the (instance or static) field
* specified by <em>field-name</em>.
* </li>
* <li>
* <code>class-name.field-name</code> : The lock object is reference by the static field specified
* by <em>class-name.field-name</em>.
* </li>
* <li>
* <code>method-name()</code> : The lock object is returned by calling the named nil-ary method.
* </li>
* <li>
* <code>class-name.class</code> : The Class object for the specified class should be used as the lock object.
* </li>
* <p>
* Based on code developed by Brian Goetz and Tim Peierls and concepts
* published in 'Java Concurrency in Practice' by Brian Goetz, Tim Peierls,
* Joshua Bloch, Joseph Bowbeer, David Holmes and Doug Lea.
*/
@Documented
@Target({ElementType.FIELD, ElementType.METHOD})
@Retention(RetentionPolicy.CLASS) // The original version used RUNTIME
public @interface GuardedBy {
String value();
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/annotation/GuardedBy.java
|
Java
|
gpl3
| 3,119
|
/*
* ====================================================================
*
* 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.ogt.http.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* The class to which this annotation is applied is not thread-safe.
* This annotation primarily exists for clarifying the non-thread-safety of a class
* that might otherwise be assumed to be thread-safe, despite the fact that it is a bad
* idea to assume a class is thread-safe without good reason.
* @see ThreadSafe
* <p>
* Based on code developed by Brian Goetz and Tim Peierls and concepts
* published in 'Java Concurrency in Practice' by Brian Goetz, Tim Peierls,
* Joshua Bloch, Joseph Bowbeer, David Holmes and Doug Lea.
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS) // The original version used RUNTIME
public @interface NotThreadSafe {
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/annotation/NotThreadSafe.java
|
Java
|
gpl3
| 2,125
|
/*
* ====================================================================
*
* 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.ogt.http.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* The class to which this annotation is applied is immutable. This means that
* its state cannot be seen to change by callers, which implies that
* <ul>
* <li> all public fields are final, </li>
* <li> all public final reference fields refer to other immutable objects, and </li>
* <li> constructors and methods do not publish references to any internal state
* which is potentially mutable by the implementation. </li>
* </ul>
* Immutable objects may still have internal mutable state for purposes of performance
* optimization; some state variables may be lazily computed, so long as they are computed
* from immutable state and that callers cannot tell the difference.
* <p>
* Immutable objects are inherently thread-safe; they may be passed between threads or
* published without synchronization.
* <p>
* Based on code developed by Brian Goetz and Tim Peierls and concepts
* published in 'Java Concurrency in Practice' by Brian Goetz, Tim Peierls,
* Joshua Bloch, Joseph Bowbeer, David Holmes and Doug Lea.
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS) // The original version used RUNTIME
public @interface Immutable {
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/annotation/Immutable.java
|
Java
|
gpl3
| 2,620
|
/*
* ====================================================================
*
* 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.ogt.http.annotation;
import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
/**
* The class to which this annotation is applied is thread-safe. This means that
* no sequences of accesses (reads and writes to public fields, calls to public methods)
* may put the object into an invalid state, regardless of the interleaving of those actions
* by the runtime, and without requiring any additional synchronization or coordination on the
* part of the caller.
* @see NotThreadSafe
* <p>
* Based on code developed by Brian Goetz and Tim Peierls and concepts
* published in 'Java Concurrency in Practice' by Brian Goetz, Tim Peierls,
* Joshua Bloch, Joseph Bowbeer, David Holmes and Doug Lea.
*/
@Documented
@Target(ElementType.TYPE)
@Retention(RetentionPolicy.CLASS) // The original version used RUNTIME
public @interface ThreadSafe {
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/annotation/ThreadSafe.java
|
Java
|
gpl3
| 2,204
|
/*
* ====================================================================
*
* 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.ogt.http.conn.params;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.ogt.http.annotation.ThreadSafe;
import org.apache.ogt.http.conn.routing.HttpRoute;
/**
* This class maintains a map of HTTP routes to maximum number of connections allowed
* for those routes. This class can be used by pooling
* {@link org.apache.ogt.http.conn.ClientConnectionManager connection managers} for
* a fine-grained control of connections on a per route basis.
*
* @since 4.0
*/
@ThreadSafe
public final class ConnPerRouteBean implements ConnPerRoute {
/** The default maximum number of connections allowed per host */
public static final int DEFAULT_MAX_CONNECTIONS_PER_ROUTE = 2; // Per RFC 2616 sec 8.1.4
private final ConcurrentHashMap<HttpRoute, Integer> maxPerHostMap;
private volatile int defaultMax;
public ConnPerRouteBean(int defaultMax) {
super();
this.maxPerHostMap = new ConcurrentHashMap<HttpRoute, Integer>();
setDefaultMaxPerRoute(defaultMax);
}
public ConnPerRouteBean() {
this(DEFAULT_MAX_CONNECTIONS_PER_ROUTE);
}
/**
* @deprecated Use {@link #getDefaultMaxPerRoute()} instead
*/
@Deprecated
public int getDefaultMax() {
return this.defaultMax;
}
/**
* @since 4.1
*/
public int getDefaultMaxPerRoute() {
return this.defaultMax;
}
public void setDefaultMaxPerRoute(int max) {
if (max < 1) {
throw new IllegalArgumentException
("The maximum must be greater than 0.");
}
this.defaultMax = max;
}
public void setMaxForRoute(final HttpRoute route, int max) {
if (route == null) {
throw new IllegalArgumentException
("HTTP route may not be null.");
}
if (max < 1) {
throw new IllegalArgumentException
("The maximum must be greater than 0.");
}
this.maxPerHostMap.put(route, Integer.valueOf(max));
}
public int getMaxForRoute(final HttpRoute route) {
if (route == null) {
throw new IllegalArgumentException
("HTTP route may not be null.");
}
Integer max = this.maxPerHostMap.get(route);
if (max != null) {
return max.intValue();
} else {
return this.defaultMax;
}
}
public void setMaxForRoutes(final Map<HttpRoute, Integer> map) {
if (map == null) {
return;
}
this.maxPerHostMap.clear();
this.maxPerHostMap.putAll(map);
}
@Override
public String toString() {
return this.maxPerHostMap.toString();
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/params/ConnPerRouteBean.java
|
Java
|
gpl3
| 3,943
|
<html>
<head>
<!--
/*
* ====================================================================
* 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/>.
*
*/
-->
</head>
<body>
Parameters for configuring HTTP connection and connection management
related classes.
</body>
</html>
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/params/package.html
|
HTML
|
gpl3
| 1,324
|
/*
* ====================================================================
*
* 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.ogt.http.conn.params;
import org.apache.ogt.http.conn.routing.HttpRoute;
/**
* This interface is intended for looking up maximum number of connections
* allowed for a given route. This class can be used by pooling
* {@link org.apache.ogt.http.conn.ClientConnectionManager connection managers} for
* a fine-grained control of connections on a per route basis.
*
* @since 4.0
*/
public interface ConnPerRoute {
int getMaxForRoute(HttpRoute route);
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/params/ConnPerRoute.java
|
Java
|
gpl3
| 1,676
|
/*
* ====================================================================
*
* 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.ogt.http.conn.params;
import java.net.InetAddress;
import org.apache.ogt.http.HttpHost;
import org.apache.ogt.http.annotation.Immutable;
import org.apache.ogt.http.conn.routing.HttpRoute;
import org.apache.ogt.http.params.HttpParams;
/**
* An adaptor for manipulating HTTP routing parameters
* in {@link HttpParams}.
*
* @since 4.0
*/
@Immutable
public class ConnRouteParams implements ConnRoutePNames {
/**
* A special value indicating "no host".
* This relies on a nonsense scheme name to avoid conflicts
* with actual hosts. Note that this is a <i>valid</i> host.
*/
public static final HttpHost NO_HOST =
new HttpHost("127.0.0.255", 0, "no-host"); // Immutable
/**
* A special value indicating "no route".
* This is a route with {@link #NO_HOST} as the target.
*/
public static final HttpRoute NO_ROUTE = new HttpRoute(NO_HOST); // Immutable
/** Disabled default constructor. */
private ConnRouteParams() {
// no body
}
/**
* Obtains the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY}
* parameter value.
* {@link #NO_HOST} will be mapped to <code>null</code>,
* to allow unsetting in a hierarchy.
*
* @param params the parameters in which to look up
*
* @return the default proxy set in the argument parameters, or
* <code>null</code> if not set
*/
public static HttpHost getDefaultProxy(HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
HttpHost proxy = (HttpHost)
params.getParameter(DEFAULT_PROXY);
if ((proxy != null) && NO_HOST.equals(proxy)) {
// value is explicitly unset
proxy = null;
}
return proxy;
}
/**
* Sets the {@link ConnRoutePNames#DEFAULT_PROXY DEFAULT_PROXY}
* parameter value.
*
* @param params the parameters in which to set the value
* @param proxy the value to set, may be <code>null</code>.
* Note that {@link #NO_HOST} will be mapped to
* <code>null</code> by {@link #getDefaultProxy},
* to allow for explicit unsetting in hierarchies.
*/
public static void setDefaultProxy(HttpParams params,
HttpHost proxy) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
params.setParameter(DEFAULT_PROXY, proxy);
}
/**
* Obtains the {@link ConnRoutePNames#FORCED_ROUTE FORCED_ROUTE}
* parameter value.
* {@link #NO_ROUTE} will be mapped to <code>null</code>,
* to allow unsetting in a hierarchy.
*
* @param params the parameters in which to look up
*
* @return the forced route set in the argument parameters, or
* <code>null</code> if not set
*/
public static HttpRoute getForcedRoute(HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
HttpRoute route = (HttpRoute)
params.getParameter(FORCED_ROUTE);
if ((route != null) && NO_ROUTE.equals(route)) {
// value is explicitly unset
route = null;
}
return route;
}
/**
* Sets the {@link ConnRoutePNames#FORCED_ROUTE FORCED_ROUTE}
* parameter value.
*
* @param params the parameters in which to set the value
* @param route the value to set, may be <code>null</code>.
* Note that {@link #NO_ROUTE} will be mapped to
* <code>null</code> by {@link #getForcedRoute},
* to allow for explicit unsetting in hierarchies.
*/
public static void setForcedRoute(HttpParams params,
HttpRoute route) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
params.setParameter(FORCED_ROUTE, route);
}
/**
* Obtains the {@link ConnRoutePNames#LOCAL_ADDRESS LOCAL_ADDRESS}
* parameter value.
* There is no special value that would automatically be mapped to
* <code>null</code>. You can use the wildcard address (0.0.0.0 for IPv4,
* :: for IPv6) to override a specific local address in a hierarchy.
*
* @param params the parameters in which to look up
*
* @return the local address set in the argument parameters, or
* <code>null</code> if not set
*/
public static InetAddress getLocalAddress(HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
InetAddress local = (InetAddress)
params.getParameter(LOCAL_ADDRESS);
// no explicit unsetting
return local;
}
/**
* Sets the {@link ConnRoutePNames#LOCAL_ADDRESS LOCAL_ADDRESS}
* parameter value.
*
* @param params the parameters in which to set the value
* @param local the value to set, may be <code>null</code>
*/
public static void setLocalAddress(HttpParams params,
InetAddress local) {
if (params == null) {
throw new IllegalArgumentException("Parameters must not be null.");
}
params.setParameter(LOCAL_ADDRESS, local);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/params/ConnRouteParams.java
|
Java
|
gpl3
| 6,816
|
/*
* ====================================================================
*
* 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.ogt.http.conn.params;
/**
* Parameter names for connection routing.
*
* @since 4.0
*/
public interface ConnRoutePNames {
/**
* Parameter for the default proxy.
* The default value will be used by some
* {@link org.apache.ogt.http.conn.routing.HttpRoutePlanner HttpRoutePlanner}
* implementations, in particular the default implementation.
* <p>
* This parameter expects a value of type {@link org.apache.ogt.http.HttpHost}.
* </p>
*/
public static final String DEFAULT_PROXY = "http.route.default-proxy";
/**
* Parameter for the local address.
* On machines with multiple network interfaces, this parameter
* can be used to select the network interface from which the
* connection originates.
* It will be interpreted by the standard
* {@link org.apache.ogt.http.conn.routing.HttpRoutePlanner HttpRoutePlanner}
* implementations, in particular the default implementation.
* <p>
* This parameter expects a value of type {@link java.net.InetAddress}.
* </p>
*/
public static final String LOCAL_ADDRESS = "http.route.local-address";
/**
* Parameter for an forced route.
* The forced route will be interpreted by the standard
* {@link org.apache.ogt.http.conn.routing.HttpRoutePlanner HttpRoutePlanner}
* implementations.
* Instead of computing a route, the given forced route will be
* returned, even if it points to the wrong target host.
* <p>
* This parameter expects a value of type
* {@link org.apache.ogt.http.conn.routing.HttpRoute HttpRoute}.
* </p>
*/
public static final String FORCED_ROUTE = "http.route.forced-route";
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/params/ConnRoutePNames.java
|
Java
|
gpl3
| 2,926
|
/*
* ====================================================================
* 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.ogt.http.conn.params;
import java.net.InetAddress;
import org.apache.ogt.http.HttpHost;
import org.apache.ogt.http.annotation.NotThreadSafe;
import org.apache.ogt.http.conn.routing.HttpRoute;
import org.apache.ogt.http.params.HttpAbstractParamBean;
import org.apache.ogt.http.params.HttpParams;
/**
* This is a Java Bean class that can be used to wrap an instance of
* {@link HttpParams} and manipulate connection routing parameters
* using Java Beans conventions.
*
* @since 4.0
*/
@NotThreadSafe
public class ConnRouteParamBean extends HttpAbstractParamBean {
public ConnRouteParamBean (final HttpParams params) {
super(params);
}
/** @see ConnRoutePNames#DEFAULT_PROXY */
public void setDefaultProxy (final HttpHost defaultProxy) {
params.setParameter(ConnRoutePNames.DEFAULT_PROXY, defaultProxy);
}
/** @see ConnRoutePNames#LOCAL_ADDRESS */
public void setLocalAddress (final InetAddress address) {
params.setParameter(ConnRoutePNames.LOCAL_ADDRESS, address);
}
/** @see ConnRoutePNames#FORCED_ROUTE */
public void setForcedRoute (final HttpRoute route) {
params.setParameter(ConnRoutePNames.FORCED_ROUTE, route);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/params/ConnRouteParamBean.java
|
Java
|
gpl3
| 2,417
|
/*
* ====================================================================
* 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.ogt.http.conn.params;
import org.apache.ogt.http.annotation.NotThreadSafe;
import org.apache.ogt.http.params.HttpAbstractParamBean;
import org.apache.ogt.http.params.HttpParams;
/**
* This is a Java Bean class that can be used to wrap an instance of
* {@link HttpParams} and manipulate HTTP client connection parameters
* using Java Beans conventions.
*
* @since 4.0
*/
@NotThreadSafe
public class ConnConnectionParamBean extends HttpAbstractParamBean {
public ConnConnectionParamBean (final HttpParams params) {
super(params);
}
/**
* @see ConnConnectionPNames#MAX_STATUS_LINE_GARBAGE
*/
public void setMaxStatusLineGarbage (final int maxStatusLineGarbage) {
params.setIntParameter(ConnConnectionPNames.MAX_STATUS_LINE_GARBAGE, maxStatusLineGarbage);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/params/ConnConnectionParamBean.java
|
Java
|
gpl3
| 2,018
|
/*
* ====================================================================
*
* 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.ogt.http.conn.params;
import org.apache.ogt.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.ogt.http.params.CoreConnectionPNames;
/**
* Parameter names for connection managers in HttpConn.
*
* @since 4.0
*/
@Deprecated
public interface ConnManagerPNames {
/**
* Defines the timeout in milliseconds used when retrieving an instance of
* {@link org.apache.ogt.http.conn.ManagedClientConnection} from the
* {@link org.apache.ogt.http.conn.ClientConnectionManager}.
* <p>
* This parameter expects a value of type {@link Long}.
* <p>
* @deprecated use {@link CoreConnectionPNames#CONNECTION_TIMEOUT}
*/
@Deprecated
public static final String TIMEOUT = "http.conn-manager.timeout";
/**
* Defines the maximum number of connections per route.
* This limit is interpreted by client connection managers
* and applies to individual manager instances.
* <p>
* This parameter expects a value of type {@link ConnPerRoute}.
* <p>
* @deprecated use {@link ThreadSafeClientConnManager#setMaxForRoute(org.apache.ogt.http.conn.routing.HttpRoute, int)},
* {@link ThreadSafeClientConnManager#getMaxForRoute(org.apache.ogt.http.conn.routing.HttpRoute)}
*/
@Deprecated
public static final String MAX_CONNECTIONS_PER_ROUTE = "http.conn-manager.max-per-route";
/**
* Defines the maximum number of connections in total.
* This limit is interpreted by client connection managers
* and applies to individual manager instances.
* <p>
* This parameter expects a value of type {@link Integer}.
* <p>
* @deprecated use {@link ThreadSafeClientConnManager#setMaxTotal(int)},
* {@link ThreadSafeClientConnManager#getMaxTotal()}
*/
@Deprecated
public static final String MAX_TOTAL_CONNECTIONS = "http.conn-manager.max-total";
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/params/ConnManagerPNames.java
|
Java
|
gpl3
| 3,103
|
/*
* ====================================================================
*
* 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.ogt.http.conn.params;
import org.apache.ogt.http.annotation.Immutable;
import org.apache.ogt.http.conn.routing.HttpRoute;
import org.apache.ogt.http.impl.conn.tsccm.ThreadSafeClientConnManager;
import org.apache.ogt.http.params.HttpConnectionParams;
import org.apache.ogt.http.params.HttpParams;
/**
* An adaptor for manipulating HTTP connection management
* parameters in {@link HttpParams}.
*
* @since 4.0
*
* @see ConnManagerPNames
*/
@Deprecated
@Immutable
public final class ConnManagerParams implements ConnManagerPNames {
/** The default maximum number of connections allowed overall */
public static final int DEFAULT_MAX_TOTAL_CONNECTIONS = 20;
/**
* Returns the timeout in milliseconds used when retrieving a
* {@link org.apache.ogt.http.conn.ManagedClientConnection} from the
* {@link org.apache.ogt.http.conn.ClientConnectionManager}.
*
* @return timeout in milliseconds.
*
* @deprecated use {@link HttpConnectionParams#getConnectionTimeout(HttpParams)}
*/
@Deprecated
public static long getTimeout(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
return params.getLongParameter(TIMEOUT, 0);
}
/**
* Sets the timeout in milliseconds used when retrieving a
* {@link org.apache.ogt.http.conn.ManagedClientConnection} from the
* {@link org.apache.ogt.http.conn.ClientConnectionManager}.
*
* @param timeout the timeout in milliseconds
*
* @deprecated use {@link HttpConnectionParams#setConnectionTimeout(HttpParams, int)}
*/
@Deprecated
public static void setTimeout(final HttpParams params, long timeout) {
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
params.setLongParameter(TIMEOUT, timeout);
}
/** The default maximum number of connections allowed per host */
private static final ConnPerRoute DEFAULT_CONN_PER_ROUTE = new ConnPerRoute() {
public int getMaxForRoute(HttpRoute route) {
return ConnPerRouteBean.DEFAULT_MAX_CONNECTIONS_PER_ROUTE;
}
};
/**
* Sets lookup interface for maximum number of connections allowed per route.
*
* @param params HTTP parameters
* @param connPerRoute lookup interface for maximum number of connections allowed
* per route
*
* @deprecated use {@link ThreadSafeClientConnManager#setMaxForRoute(org.apache.ogt.http.conn.routing.HttpRoute, int)}
*/
@Deprecated
public static void setMaxConnectionsPerRoute(final HttpParams params,
final ConnPerRoute connPerRoute) {
if (params == null) {
throw new IllegalArgumentException
("HTTP parameters must not be null.");
}
params.setParameter(MAX_CONNECTIONS_PER_ROUTE, connPerRoute);
}
/**
* Returns lookup interface for maximum number of connections allowed per route.
*
* @param params HTTP parameters
*
* @return lookup interface for maximum number of connections allowed per route.
*
* @deprecated use {@link ThreadSafeClientConnManager#getMaxForRoute(org.apache.ogt.http.conn.routing.HttpRoute)}
*/
@Deprecated
public static ConnPerRoute getMaxConnectionsPerRoute(final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException
("HTTP parameters must not be null.");
}
ConnPerRoute connPerRoute = (ConnPerRoute) params.getParameter(MAX_CONNECTIONS_PER_ROUTE);
if (connPerRoute == null) {
connPerRoute = DEFAULT_CONN_PER_ROUTE;
}
return connPerRoute;
}
/**
* Sets the maximum number of connections allowed.
*
* @param params HTTP parameters
* @param maxTotalConnections The maximum number of connections allowed.
*
* @deprecated use {@link ThreadSafeClientConnManager#setMaxTotal(int)}
*/
@Deprecated
public static void setMaxTotalConnections(
final HttpParams params,
int maxTotalConnections) {
if (params == null) {
throw new IllegalArgumentException
("HTTP parameters must not be null.");
}
params.setIntParameter(MAX_TOTAL_CONNECTIONS, maxTotalConnections);
}
/**
* Gets the maximum number of connections allowed.
*
* @param params HTTP parameters
*
* @return The maximum number of connections allowed.
*
* @deprecated use {@link ThreadSafeClientConnManager#getMaxTotal()}
*/
@Deprecated
public static int getMaxTotalConnections(
final HttpParams params) {
if (params == null) {
throw new IllegalArgumentException
("HTTP parameters must not be null.");
}
return params.getIntParameter(MAX_TOTAL_CONNECTIONS, DEFAULT_MAX_TOTAL_CONNECTIONS);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/params/ConnManagerParams.java
|
Java
|
gpl3
| 6,300
|
/*
* ====================================================================
*
* 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.ogt.http.conn.params;
/**
* Parameter names for HTTP client connections.
*
* @since 4.0
*/
public interface ConnConnectionPNames {
/**
* Defines the maximum number of ignorable lines before we expect
* a HTTP response's status line.
* <p>
* With HTTP/1.1 persistent connections, the problem arises that
* broken scripts could return a wrong Content-Length
* (there are more bytes sent than specified).
* Unfortunately, in some cases, this cannot be detected after the
* bad response, but only before the next one.
* So HttpClient must be able to skip those surplus lines this way.
* </p>
* <p>
* This parameter expects a value of type {@link Integer}.
* 0 disallows all garbage/empty lines before the status line.
* Use {@link java.lang.Integer#MAX_VALUE} for unlimited number.
* </p>
*/
public static final String MAX_STATUS_LINE_GARBAGE = "http.connection.max-status-line-garbage";
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/params/ConnConnectionPNames.java
|
Java
|
gpl3
| 2,195
|
/*
* ====================================================================
* 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.ogt.http.conn.params;
import org.apache.ogt.http.annotation.NotThreadSafe;
import org.apache.ogt.http.params.HttpAbstractParamBean;
import org.apache.ogt.http.params.HttpParams;
/**
* This is a Java Bean class that can be used to wrap an instance of
* {@link HttpParams} and manipulate connection manager parameters
* using Java Beans conventions.
*
* @since 4.0
*/
@NotThreadSafe
@Deprecated
public class ConnManagerParamBean extends HttpAbstractParamBean {
public ConnManagerParamBean (final HttpParams params) {
super(params);
}
public void setTimeout (final long timeout) {
params.setLongParameter(ConnManagerPNames.TIMEOUT, timeout);
}
/** @see ConnManagerPNames#MAX_TOTAL_CONNECTIONS */
@Deprecated
public void setMaxTotalConnections (final int maxConnections) {
params.setIntParameter(ConnManagerPNames.MAX_TOTAL_CONNECTIONS, maxConnections);
}
/** @see ConnManagerPNames#MAX_CONNECTIONS_PER_ROUTE */
@Deprecated
public void setConnectionsPerRoute(final ConnPerRouteBean connPerRoute) {
params.setParameter(ConnManagerPNames.MAX_CONNECTIONS_PER_ROUTE, connPerRoute);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/params/ConnManagerParamBean.java
|
Java
|
gpl3
| 2,376
|
<html>
<head>
<!--
/*
* ====================================================================
* 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/>.
*
*/
-->
</head>
<body>
The client-side connection management and handling API that provides interfaces
and implementations for opening and managing client side HTTP connections.
<p>
The lowest layer of connection handling is comprised of
{@link org.apache.ogt.http.conn.OperatedClientConnection OperatedClientConnection}
and
{@link org.apache.ogt.http.conn.ClientConnectionOperator ClientConnectionOperator}.
The connection interface extends the core
{@link org.apache.ogt.http.HttpClientConnection HttpClientConnection}
by operations to set and update a socket. An operator encapsulates the logic to
open and layer sockets, typically using a
{@link org.apache.ogt.http.conn.scheme.SocketFactory}. The socket factory for
a protocol {@link org.apache.ogt.http.conn.scheme.Scheme} such as "http" or "https"
can be looked up in a {@link org.apache.ogt.http.conn.scheme.SchemeRegistry}.
Applications without a need for sophisticated connection management can use
this layer directly.
</p>
<p>
On top of that lies the connection management layer. A
{@link org.apache.ogt.http.conn.ClientConnectionManager} internally manages
operated connections, but hands out instances of
{@link org.apache.ogt.http.conn.ManagedClientConnection}.
This interface abstracts from the underlying socket operations and
provides convenient methods for opening and updating sockets in order
to establish a {@link org.apache.ogt.http.conn.routing.HttpRoute route}.
The operator is encapsulated by the connection manager and called
automatically.
</p>
<p>
Connections obtained from a manager have to be returned after use.
This can be {@link org.apache.ogt.http.conn.ConnectionReleaseTrigger triggered}
on various levels, either by releasing the
{@link org.apache.ogt.http.conn.ManagedClientConnection connection} directly,
or by calling a method on
an {@link org.apache.ogt.http.conn.BasicManagedEntity entity} received from
the connection, or by closing the
{@link org.apache.ogt.http.conn.EofSensorInputStream stream} from which
that entity is being read.
</p>
<p>
Connection managers will try to keep returned connections alive in
order to re-use them for subsequent requests along the same route.
The managed connection interface and all triggers for connection release
provide methods to enable or disable this behavior.
</p>
</body>
</html>
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/package.html
|
HTML
|
gpl3
| 3,519
|
/*
* ====================================================================
*
* 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.ogt.http.conn;
import java.io.InputStream;
import java.io.IOException;
/**
* A watcher for {@link EofSensorInputStream}. Each stream will notify its
* watcher at most once.
*
* @since 4.0
*/
public interface EofSensorWatcher {
/**
* Indicates that EOF is detected.
*
* @param wrapped the underlying stream which has reached EOF
*
* @return <code>true</code> if <code>wrapped</code> should be closed,
* <code>false</code> if it should be left alone
*
* @throws IOException
* in case of an IO problem, for example if the watcher itself
* closes the underlying stream. The caller will leave the
* wrapped stream alone, as if <code>false</code> was returned.
*/
boolean eofDetected(InputStream wrapped)
throws IOException;
/**
* Indicates that the {@link EofSensorInputStream stream} is closed.
* This method will be called only if EOF was <i>not</i> detected
* before closing. Otherwise, {@link #eofDetected eofDetected} is called.
*
* @param wrapped the underlying stream which has not reached EOF
*
* @return <code>true</code> if <code>wrapped</code> should be closed,
* <code>false</code> if it should be left alone
*
* @throws IOException
* in case of an IO problem, for example if the watcher itself
* closes the underlying stream. The caller will leave the
* wrapped stream alone, as if <code>false</code> was returned.
*/
boolean streamClosed(InputStream wrapped)
throws IOException;
/**
* Indicates that the {@link EofSensorInputStream stream} is aborted.
* This method will be called only if EOF was <i>not</i> detected
* before aborting. Otherwise, {@link #eofDetected eofDetected} is called.
* <p/>
* This method will also be invoked when an input operation causes an
* IOException to be thrown to make sure the input stream gets shut down.
*
* @param wrapped the underlying stream which has not reached EOF
*
* @return <code>true</code> if <code>wrapped</code> should be closed,
* <code>false</code> if it should be left alone
*
* @throws IOException
* in case of an IO problem, for example if the watcher itself
* closes the underlying stream. The caller will leave the
* wrapped stream alone, as if <code>false</code> was returned.
*/
boolean streamAbort(InputStream wrapped)
throws IOException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/EofSensorWatcher.java
|
Java
|
gpl3
| 3,804
|
/*
* ====================================================================
* 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.ogt.http.conn;
import org.apache.ogt.http.conn.scheme.SchemeRegistry;
import org.apache.ogt.http.params.HttpParams;
/**
* A factory for creating new {@link ClientConnectionManager} instances.
*
*
* @since 4.0
*/
public interface ClientConnectionManagerFactory {
ClientConnectionManager newInstance(
HttpParams params,
SchemeRegistry schemeRegistry);
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ClientConnectionManagerFactory.java
|
Java
|
gpl3
| 1,593
|
/*
* ====================================================================
* 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.ogt.http.conn;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Arrays;
import org.apache.ogt.http.annotation.Immutable;
import org.apache.ogt.http.conn.scheme.SchemeSocketFactory;
import org.apache.ogt.http.conn.scheme.SocketFactory;
import org.apache.ogt.http.params.HttpConnectionParams;
import org.apache.ogt.http.params.HttpParams;
/**
* Socket factory that implements a simple multi-home fail-over on connect failure,
* provided the same hostname resolves to multiple {@link InetAddress}es. Please note
* the {@link #connectSocket(Socket, String, int, InetAddress, int, HttpParams)}
* method cannot be reliably interrupted by closing the socket returned by the
* {@link #createSocket()} method.
*
* @since 4.0
*
* @deprecated Do not use. For multihome support socket factories must implement
* {@link SchemeSocketFactory} interface.
*/
@Deprecated
@Immutable
public final class MultihomePlainSocketFactory implements SocketFactory {
/**
* The factory singleton.
*/
private static final
MultihomePlainSocketFactory DEFAULT_FACTORY = new MultihomePlainSocketFactory();
/**
* Gets the singleton instance of this class.
* @return the one and only plain socket factory
*/
public static MultihomePlainSocketFactory getSocketFactory() {
return DEFAULT_FACTORY;
}
/**
* Restricted default constructor.
*/
private MultihomePlainSocketFactory() {
super();
}
// non-javadoc, see interface org.apache.ogt.http.conn.SocketFactory
public Socket createSocket() {
return new Socket();
}
/**
* Attempts to connects the socket to any of the {@link InetAddress}es the
* given host name resolves to. If connection to all addresses fail, the
* last I/O exception is propagated to the caller.
*
* @param sock socket to connect to any of the given addresses
* @param host Host name to connect to
* @param port the port to connect to
* @param localAddress local address
* @param localPort local port
* @param params HTTP parameters
*
* @throws IOException if an error occurs during the connection
* @throws SocketTimeoutException if timeout expires before connecting
*/
public Socket connectSocket(Socket sock, String host, int port,
InetAddress localAddress, int localPort,
HttpParams params)
throws IOException {
if (host == null) {
throw new IllegalArgumentException("Target host may not be null.");
}
if (params == null) {
throw new IllegalArgumentException("Parameters may not be null.");
}
if (sock == null)
sock = createSocket();
if ((localAddress != null) || (localPort > 0)) {
// we need to bind explicitly
if (localPort < 0)
localPort = 0; // indicates "any"
InetSocketAddress isa =
new InetSocketAddress(localAddress, localPort);
sock.bind(isa);
}
int timeout = HttpConnectionParams.getConnectionTimeout(params);
InetAddress[] inetadrs = InetAddress.getAllByName(host);
List<InetAddress> addresses = new ArrayList<InetAddress>(inetadrs.length);
addresses.addAll(Arrays.asList(inetadrs));
Collections.shuffle(addresses);
IOException lastEx = null;
for (InetAddress remoteAddress: addresses) {
try {
sock.connect(new InetSocketAddress(remoteAddress, port), timeout);
break;
} catch (SocketTimeoutException ex) {
throw new ConnectTimeoutException("Connect to " + remoteAddress + " timed out");
} catch (IOException ex) {
// create new socket
sock = new Socket();
// keep the last exception and retry
lastEx = ex;
}
}
if (lastEx != null) {
throw lastEx;
}
return sock;
} // connectSocket
/**
* Checks whether a socket connection is secure.
* This factory creates plain socket connections
* which are not considered secure.
*
* @param sock the connected socket
*
* @return <code>false</code>
*
* @throws IllegalArgumentException if the argument is invalid
*/
public final boolean isSecure(Socket sock)
throws IllegalArgumentException {
if (sock == null) {
throw new IllegalArgumentException("Socket may not be null.");
}
// This class check assumes that createSocket() calls the constructor
// directly. If it was using javax.net.SocketFactory, we couldn't make
// an assumption about the socket class here.
if (sock.getClass() != Socket.class) {
throw new IllegalArgumentException
("Socket not created by this factory.");
}
// This check is performed last since it calls a method implemented
// by the argument object. getClass() is final in java.lang.Object.
if (sock.isClosed()) {
throw new IllegalArgumentException("Socket is closed.");
}
return false;
} // isSecure
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/MultihomePlainSocketFactory.java
|
Java
|
gpl3
| 6,724
|
<html>
<head>
<!--
/*
* ====================================================================
* 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/>.
*
*/
-->
</head>
<body>
TLS/SSL specific API.
</body>
</html>
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ssl/package.html
|
HTML
|
gpl3
| 1,260
|
/*
* ====================================================================
* 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.ogt.http.conn.ssl;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
/**
* A strategy to establish trustworthiness of certificates without consulting the trust manager
* configured in the actual SSL context. This interface can be used to override the standard
* JSSE certificate verification process.
*
* @since 4.1
*/
public interface TrustStrategy {
/**
* Determines whether the certificate chain can be trusted without consulting the trust manager
* configured in the actual SSL context. This method can be used to override the standard JSSE
* certificate verification process.
* <p>
* Please note that, if this method returns <code>false</code>, the trust manager configured
* in the actual SSL context can still clear the certificate as trusted.
*
* @param chain the peer certificate chain
* @param authType the authentication type based on the client certificate
* @return <code>true</code> if the certificate can be trusted without verification by
* the trust manager, <code>false</code> otherwise.
* @throws CertificateException thrown if the certificate is not trusted or invalid.
*/
boolean isTrusted(X509Certificate[] chain, String authType) throws CertificateException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ssl/TrustStrategy.java
|
Java
|
gpl3
| 2,513
|
/*
* ====================================================================
* 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.ogt.http.conn.ssl;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
/**
* A trust strategy that accepts self-signed certificates as trusted. Verification of all other
* certificates is done by the trust manager configured in the SSL context.
*
* @since 4.1
*/
public class TrustSelfSignedStrategy implements TrustStrategy {
public boolean isTrusted(
final X509Certificate[] chain, final String authType) throws CertificateException {
return chain.length == 1;
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ssl/TrustSelfSignedStrategy.java
|
Java
|
gpl3
| 1,746
|
/*
* ====================================================================
* 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.ogt.http.conn.ssl;
import org.apache.ogt.http.annotation.Immutable;
import org.apache.ogt.http.conn.util.InetAddressUtils;
import java.io.IOException;
import java.io.InputStream;
import java.security.cert.Certificate;
import java.security.cert.CertificateParsingException;
import java.security.cert.X509Certificate;
import java.util.Arrays;
import java.util.Collection;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.StringTokenizer;
import java.util.logging.Logger;
import java.util.logging.Level;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSession;
import javax.net.ssl.SSLSocket;
/**
* Abstract base class for all standard {@link X509HostnameVerifier}
* implementations.
*
* @since 4.0
*/
@Immutable
public abstract class AbstractVerifier implements X509HostnameVerifier {
/**
* This contains a list of 2nd-level domains that aren't allowed to
* have wildcards when combined with country-codes.
* For example: [*.co.uk].
* <p/>
* The [*.co.uk] problem is an interesting one. Should we just hope
* that CA's would never foolishly allow such a certificate to happen?
* Looks like we're the only implementation guarding against this.
* Firefox, Curl, Sun Java 1.4, 5, 6 don't bother with this check.
*/
private final static String[] BAD_COUNTRY_2LDS =
{ "ac", "co", "com", "ed", "edu", "go", "gouv", "gov", "info",
"lg", "ne", "net", "or", "org" };
static {
// Just in case developer forgot to manually sort the array. :-)
Arrays.sort(BAD_COUNTRY_2LDS);
}
public AbstractVerifier() {
super();
}
public final void verify(String host, SSLSocket ssl)
throws IOException {
if(host == null) {
throw new NullPointerException("host to verify is null");
}
SSLSession session = ssl.getSession();
if(session == null) {
// In our experience this only happens under IBM 1.4.x when
// spurious (unrelated) certificates show up in the server'
// chain. Hopefully this will unearth the real problem:
InputStream in = ssl.getInputStream();
in.available();
/*
If you're looking at the 2 lines of code above because
you're running into a problem, you probably have two
options:
#1. Clean up the certificate chain that your server
is presenting (e.g. edit "/etc/apache2/server.crt"
or wherever it is your server's certificate chain
is defined).
OR
#2. Upgrade to an IBM 1.5.x or greater JVM, or switch
to a non-IBM JVM.
*/
// If ssl.getInputStream().available() didn't cause an
// exception, maybe at least now the session is available?
session = ssl.getSession();
if(session == null) {
// If it's still null, probably a startHandshake() will
// unearth the real problem.
ssl.startHandshake();
// Okay, if we still haven't managed to cause an exception,
// might as well go for the NPE. Or maybe we're okay now?
session = ssl.getSession();
}
}
Certificate[] certs = session.getPeerCertificates();
X509Certificate x509 = (X509Certificate) certs[0];
verify(host, x509);
}
public final boolean verify(String host, SSLSession session) {
try {
Certificate[] certs = session.getPeerCertificates();
X509Certificate x509 = (X509Certificate) certs[0];
verify(host, x509);
return true;
}
catch(SSLException e) {
return false;
}
}
public final void verify(String host, X509Certificate cert)
throws SSLException {
String[] cns = getCNs(cert);
String[] subjectAlts = getSubjectAlts(cert, host);
verify(host, cns, subjectAlts);
}
public final void verify(final String host, final String[] cns,
final String[] subjectAlts,
final boolean strictWithSubDomains)
throws SSLException {
// Build the list of names we're going to check. Our DEFAULT and
// STRICT implementations of the HostnameVerifier only use the
// first CN provided. All other CNs are ignored.
// (Firefox, wget, curl, Sun Java 1.4, 5, 6 all work this way).
LinkedList<String> names = new LinkedList<String>();
if(cns != null && cns.length > 0 && cns[0] != null) {
names.add(cns[0]);
}
if(subjectAlts != null) {
for (String subjectAlt : subjectAlts) {
if (subjectAlt != null) {
names.add(subjectAlt);
}
}
}
if(names.isEmpty()) {
String msg = "Certificate for <" + host + "> doesn't contain CN or DNS subjectAlt";
throw new SSLException(msg);
}
// StringBuilder for building the error message.
StringBuilder buf = new StringBuilder();
// We're can be case-insensitive when comparing the host we used to
// establish the socket to the hostname in the certificate.
String hostName = host.trim().toLowerCase(Locale.ENGLISH);
boolean match = false;
for(Iterator<String> it = names.iterator(); it.hasNext();) {
// Don't trim the CN, though!
String cn = it.next();
cn = cn.toLowerCase(Locale.ENGLISH);
// Store CN in StringBuilder in case we need to report an error.
buf.append(" <");
buf.append(cn);
buf.append('>');
if(it.hasNext()) {
buf.append(" OR");
}
// The CN better have at least two dots if it wants wildcard
// action. It also can't be [*.co.uk] or [*.co.jp] or
// [*.org.uk], etc...
boolean doWildcard = cn.startsWith("*.") &&
cn.lastIndexOf('.') >= 0 &&
acceptableCountryWildcard(cn) &&
!isIPAddress(host);
if(doWildcard) {
match = hostName.endsWith(cn.substring(1));
if(match && strictWithSubDomains) {
// If we're in strict mode, then [*.foo.com] is not
// allowed to match [a.b.foo.com]
match = countDots(hostName) == countDots(cn);
}
} else {
match = hostName.equals(cn);
}
if(match) {
break;
}
}
if(!match) {
throw new SSLException("hostname in certificate didn't match: <" + host + "> !=" + buf);
}
}
public static boolean acceptableCountryWildcard(String cn) {
int cnLen = cn.length();
if(cnLen >= 7 && cnLen <= 9) {
// Look for the '.' in the 3rd-last position:
if(cn.charAt(cnLen - 3) == '.') {
// Trim off the [*.] and the [.XX].
String s = cn.substring(2, cnLen - 3);
// And test against the sorted array of bad 2lds:
int x = Arrays.binarySearch(BAD_COUNTRY_2LDS, s);
return x < 0;
}
}
return true;
}
public static String[] getCNs(X509Certificate cert) {
LinkedList<String> cnList = new LinkedList<String>();
/*
Sebastian Hauer's original StrictSSLProtocolSocketFactory used
getName() and had the following comment:
Parses a X.500 distinguished name for the value of the
"Common Name" field. This is done a bit sloppy right
now and should probably be done a bit more according to
<code>RFC 2253</code>.
I've noticed that toString() seems to do a better job than
getName() on these X500Principal objects, so I'm hoping that
addresses Sebastian's concern.
For example, getName() gives me this:
1.2.840.113549.1.9.1=#16166a756c6975736461766965734063756362632e636f6d
whereas toString() gives me this:
EMAILADDRESS=juliusdavies@cucbc.com
Looks like toString() even works with non-ascii domain names!
I tested it with "花子.co.jp" and it worked fine.
*/
String subjectPrincipal = cert.getSubjectX500Principal().toString();
StringTokenizer st = new StringTokenizer(subjectPrincipal, ",");
while(st.hasMoreTokens()) {
String tok = st.nextToken();
int x = tok.indexOf("CN=");
if(x >= 0) {
cnList.add(tok.substring(x + 3));
}
}
if(!cnList.isEmpty()) {
String[] cns = new String[cnList.size()];
cnList.toArray(cns);
return cns;
} else {
return null;
}
}
/**
* Extracts the array of SubjectAlt DNS or IP names from an X509Certificate.
* Returns null if there aren't any.
*
* @param cert X509Certificate
* @param hostname
* @return Array of SubjectALT DNS or IP names stored in the certificate.
*/
private static String[] getSubjectAlts(
final X509Certificate cert, final String hostname) {
int subjectType;
if (isIPAddress(hostname)) {
subjectType = 7;
} else {
subjectType = 2;
}
LinkedList<String> subjectAltList = new LinkedList<String>();
Collection<List<?>> c = null;
try {
c = cert.getSubjectAlternativeNames();
}
catch(CertificateParsingException cpe) {
Logger.getLogger(AbstractVerifier.class.getName())
.log(Level.FINE, "Error parsing certificate.", cpe);
}
if(c != null) {
for (List<?> aC : c) {
List<?> list = aC;
int type = ((Integer) list.get(0)).intValue();
if (type == subjectType) {
String s = (String) list.get(1);
subjectAltList.add(s);
}
}
}
if(!subjectAltList.isEmpty()) {
String[] subjectAlts = new String[subjectAltList.size()];
subjectAltList.toArray(subjectAlts);
return subjectAlts;
} else {
return null;
}
}
/**
* Extracts the array of SubjectAlt DNS names from an X509Certificate.
* Returns null if there aren't any.
* <p/>
* Note: Java doesn't appear able to extract international characters
* from the SubjectAlts. It can only extract international characters
* from the CN field.
* <p/>
* (Or maybe the version of OpenSSL I'm using to test isn't storing the
* international characters correctly in the SubjectAlts?).
*
* @param cert X509Certificate
* @return Array of SubjectALT DNS names stored in the certificate.
*/
public static String[] getDNSSubjectAlts(X509Certificate cert) {
return getSubjectAlts(cert, null);
}
/**
* Counts the number of dots "." in a string.
* @param s string to count dots from
* @return number of dots
*/
public static int countDots(final String s) {
int count = 0;
for(int i = 0; i < s.length(); i++) {
if(s.charAt(i) == '.') {
count++;
}
}
return count;
}
private static boolean isIPAddress(final String hostname) {
return hostname != null &&
(InetAddressUtils.isIPv4Address(hostname) ||
InetAddressUtils.isIPv6Address(hostname));
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ssl/AbstractVerifier.java
|
Java
|
gpl3
| 13,328
|
/*
* ====================================================================
* 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.ogt.http.conn.ssl;
import org.apache.ogt.http.annotation.Immutable;
/**
* The ALLOW_ALL HostnameVerifier essentially turns hostname verification
* off. This implementation is a no-op, and never throws the SSLException.
*
*
* @since 4.0
*/
@Immutable
public class AllowAllHostnameVerifier extends AbstractVerifier {
public final void verify(
final String host,
final String[] cns,
final String[] subjectAlts) {
// Allow everything - so never blowup.
}
@Override
public final String toString() {
return "ALLOW_ALL";
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ssl/AllowAllHostnameVerifier.java
|
Java
|
gpl3
| 1,805
|
/*
* ====================================================================
* 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.ogt.http.conn.ssl;
import javax.net.ssl.SSLException;
import org.apache.ogt.http.annotation.Immutable;
/**
* The Strict HostnameVerifier works the same way as Sun Java 1.4, Sun
* Java 5, Sun Java 6-rc. It's also pretty close to IE6. This
* implementation appears to be compliant with RFC 2818 for dealing with
* wildcards.
* <p/>
* The hostname must match either the first CN, or any of the subject-alts.
* A wildcard can occur in the CN, and in any of the subject-alts. The
* one divergence from IE6 is how we only check the first CN. IE6 allows
* a match against any of the CNs present. We decided to follow in
* Sun Java 1.4's footsteps and only check the first CN. (If you need
* to check all the CN's, feel free to write your own implementation!).
* <p/>
* A wildcard such as "*.foo.com" matches only subdomains in the same
* level, for example "a.foo.com". It does not match deeper subdomains
* such as "a.b.foo.com".
*
*
* @since 4.0
*/
@Immutable
public class StrictHostnameVerifier extends AbstractVerifier {
public final void verify(
final String host,
final String[] cns,
final String[] subjectAlts) throws SSLException {
verify(host, cns, subjectAlts, true);
}
@Override
public final String toString() {
return "STRICT";
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ssl/StrictHostnameVerifier.java
|
Java
|
gpl3
| 2,545
|
/*
* ====================================================================
* 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.ogt.http.conn.ssl;
import javax.net.ssl.SSLException;
import org.apache.ogt.http.annotation.Immutable;
/**
* The HostnameVerifier that works the same way as Curl and Firefox.
* <p/>
* The hostname must match either the first CN, or any of the subject-alts.
* A wildcard can occur in the CN, and in any of the subject-alts.
* <p/>
* The only difference between BROWSER_COMPATIBLE and STRICT is that a wildcard
* (such as "*.foo.com") with BROWSER_COMPATIBLE matches all subdomains,
* including "a.b.foo.com".
*
*
* @since 4.0
*/
@Immutable
public class BrowserCompatHostnameVerifier extends AbstractVerifier {
public final void verify(
final String host,
final String[] cns,
final String[] subjectAlts) throws SSLException {
verify(host, cns, subjectAlts, false);
}
@Override
public final String toString() {
return "BROWSER_COMPATIBLE";
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ssl/BrowserCompatHostnameVerifier.java
|
Java
|
gpl3
| 2,135
|
/*
* ====================================================================
* 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.ogt.http.conn.ssl;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import javax.net.ssl.X509TrustManager;
/**
* @since 4.1
*/
class TrustManagerDecorator implements X509TrustManager {
private final X509TrustManager trustManager;
private final TrustStrategy trustStrategy;
TrustManagerDecorator(final X509TrustManager trustManager, final TrustStrategy trustStrategy) {
super();
this.trustManager = trustManager;
this.trustStrategy = trustStrategy;
}
public void checkClientTrusted(
final X509Certificate[] chain, final String authType) throws CertificateException {
this.trustManager.checkClientTrusted(chain, authType);
}
public void checkServerTrusted(
final X509Certificate[] chain, final String authType) throws CertificateException {
if (!this.trustStrategy.isTrusted(chain, authType)) {
this.trustManager.checkServerTrusted(chain, authType);
}
}
public X509Certificate[] getAcceptedIssuers() {
return this.trustManager.getAcceptedIssuers();
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ssl/TrustManagerDecorator.java
|
Java
|
gpl3
| 2,339
|
/*
* ====================================================================
* 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.ogt.http.conn.ssl;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLException;
import javax.net.ssl.SSLSocket;
import java.io.IOException;
import java.security.cert.X509Certificate;
/**
* Interface for checking if a hostname matches the names stored inside the
* server's X.509 certificate. This interface extends
* {@link javax.net.ssl.HostnameVerifier}, but it is recommended to use
* methods added by X509HostnameVerifier.
*
* @since 4.0
*/
public interface X509HostnameVerifier extends HostnameVerifier {
/**
* Verifies that the host name is an acceptable match with the server's
* authentication scheme based on the given {@link SSLSocket}.
*
* @param host the host.
* @param ssl the SSL socket.
* @throws IOException if an I/O error occurs or the verification process
* fails.
*/
void verify(String host, SSLSocket ssl) throws IOException;
/**
* Verifies that the host name is an acceptable match with the server's
* authentication scheme based on the given {@link X509Certificate}.
*
* @param host the host.
* @param cert the certificate.
* @throws SSLException if the verification process fails.
*/
void verify(String host, X509Certificate cert) throws SSLException;
/**
* Checks to see if the supplied hostname matches any of the supplied CNs
* or "DNS" Subject-Alts. Most implementations only look at the first CN,
* and ignore any additional CNs. Most implementations do look at all of
* the "DNS" Subject-Alts. The CNs or Subject-Alts may contain wildcards
* according to RFC 2818.
*
* @param cns CN fields, in order, as extracted from the X.509
* certificate.
* @param subjectAlts Subject-Alt fields of type 2 ("DNS"), as extracted
* from the X.509 certificate.
* @param host The hostname to verify.
* @throws SSLException if the verification process fails.
*/
void verify(String host, String[] cns, String[] subjectAlts)
throws SSLException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ssl/X509HostnameVerifier.java
|
Java
|
gpl3
| 3,321
|
/*
* ====================================================================
* 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.ogt.http.conn.ssl;
import org.apache.ogt.http.annotation.ThreadSafe;
import org.apache.ogt.http.conn.ConnectTimeoutException;
import org.apache.ogt.http.conn.scheme.HostNameResolver;
import org.apache.ogt.http.conn.scheme.LayeredSchemeSocketFactory;
import org.apache.ogt.http.conn.scheme.LayeredSocketFactory;
import org.apache.ogt.http.params.HttpConnectionParams;
import org.apache.ogt.http.params.HttpParams;
import javax.net.ssl.KeyManager;
import javax.net.ssl.KeyManagerFactory;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.TrustManager;
import javax.net.ssl.TrustManagerFactory;
import javax.net.ssl.X509TrustManager;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import java.security.KeyManagementException;
import java.security.KeyStore;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.SecureRandom;
import java.security.UnrecoverableKeyException;
/**
* Layered socket factory for TLS/SSL connections.
* <p>
* SSLSocketFactory can be used to validate the identity of the HTTPS server against a list of
* trusted certificates and to authenticate to the HTTPS server using a private key.
* <p>
* SSLSocketFactory will enable server authentication when supplied with
* a {@link KeyStore trust-store} file containing one or several trusted certificates. The client
* secure socket will reject the connection during the SSL session handshake if the target HTTPS
* server attempts to authenticate itself with a non-trusted certificate.
* <p>
* Use JDK keytool utility to import a trusted certificate and generate a trust-store file:
* <pre>
* keytool -import -alias "my server cert" -file server.crt -keystore my.truststore
* </pre>
* <p>
* In special cases the standard trust verification process can be bypassed by using a custom
* {@link TrustStrategy}. This interface is primarily intended for allowing self-signed
* certificates to be accepted as trusted without having to add them to the trust-store file.
* <p>
* The following parameters can be used to customize the behavior of this
* class:
* <ul>
* <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#CONNECTION_TIMEOUT}</li>
* <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#SO_TIMEOUT}</li>
* <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#SO_REUSEADDR}</li>
* </ul>
* <p>
* SSLSocketFactory will enable client authentication when supplied with
* a {@link KeyStore key-store} file containing a private key/public certificate
* pair. The client secure socket will use the private key to authenticate
* itself to the target HTTPS server during the SSL session handshake if
* requested to do so by the server.
* The target HTTPS server will in its turn verify the certificate presented
* by the client in order to establish client's authenticity
* <p>
* Use the following sequence of actions to generate a key-store file
* </p>
* <ul>
* <li>
* <p>
* Use JDK keytool utility to generate a new key
* <pre>keytool -genkey -v -alias "my client key" -validity 365 -keystore my.keystore</pre>
* For simplicity use the same password for the key as that of the key-store
* </p>
* </li>
* <li>
* <p>
* Issue a certificate signing request (CSR)
* <pre>keytool -certreq -alias "my client key" -file mycertreq.csr -keystore my.keystore</pre>
* </p>
* </li>
* <li>
* <p>
* Send the certificate request to the trusted Certificate Authority for signature.
* One may choose to act as her own CA and sign the certificate request using a PKI
* tool, such as OpenSSL.
* </p>
* </li>
* <li>
* <p>
* Import the trusted CA root certificate
* <pre>keytool -import -alias "my trusted ca" -file caroot.crt -keystore my.keystore</pre>
* </p>
* </li>
* <li>
* <p>
* Import the PKCS#7 file containg the complete certificate chain
* <pre>keytool -import -alias "my client key" -file mycert.p7 -keystore my.keystore</pre>
* </p>
* </li>
* <li>
* <p>
* Verify the content the resultant keystore file
* <pre>keytool -list -v -keystore my.keystore</pre>
* </p>
* </li>
* </ul>
*
* @since 4.0
*/
@SuppressWarnings("deprecation")
@ThreadSafe
public class SSLSocketFactory implements LayeredSchemeSocketFactory, LayeredSocketFactory {
public static final String TLS = "TLS";
public static final String SSL = "SSL";
public static final String SSLV2 = "SSLv2";
public static final X509HostnameVerifier ALLOW_ALL_HOSTNAME_VERIFIER
= new AllowAllHostnameVerifier();
public static final X509HostnameVerifier BROWSER_COMPATIBLE_HOSTNAME_VERIFIER
= new BrowserCompatHostnameVerifier();
public static final X509HostnameVerifier STRICT_HOSTNAME_VERIFIER
= new StrictHostnameVerifier();
/**
* Gets the default factory, which uses the default JVM settings for secure
* connections.
*
* @return the default factory
*/
public static SSLSocketFactory getSocketFactory() {
return new SSLSocketFactory();
}
private final javax.net.ssl.SSLSocketFactory socketfactory;
private final HostNameResolver nameResolver;
// TODO: make final
private volatile X509HostnameVerifier hostnameVerifier;
private static SSLContext createSSLContext(
String algorithm,
final KeyStore keystore,
final String keystorePassword,
final KeyStore truststore,
final SecureRandom random,
final TrustStrategy trustStrategy)
throws NoSuchAlgorithmException, KeyStoreException, UnrecoverableKeyException, KeyManagementException {
if (algorithm == null) {
algorithm = TLS;
}
KeyManagerFactory kmfactory = KeyManagerFactory.getInstance(
KeyManagerFactory.getDefaultAlgorithm());
kmfactory.init(keystore, keystorePassword != null ? keystorePassword.toCharArray(): null);
KeyManager[] keymanagers = kmfactory.getKeyManagers();
TrustManagerFactory tmfactory = TrustManagerFactory.getInstance(
TrustManagerFactory.getDefaultAlgorithm());
tmfactory.init(truststore);
TrustManager[] trustmanagers = tmfactory.getTrustManagers();
if (trustmanagers != null && trustStrategy != null) {
for (int i = 0; i < trustmanagers.length; i++) {
TrustManager tm = trustmanagers[i];
if (tm instanceof X509TrustManager) {
trustmanagers[i] = new TrustManagerDecorator(
(X509TrustManager) tm, trustStrategy);
}
}
}
SSLContext sslcontext = SSLContext.getInstance(algorithm);
sslcontext.init(keymanagers, trustmanagers, random);
return sslcontext;
}
private static SSLContext createDefaultSSLContext() {
try {
return createSSLContext(TLS, null, null, null, null, null);
} catch (Exception ex) {
throw new IllegalStateException("Failure initializing default SSL context", ex);
}
}
/**
* @deprecated Use {@link #SSLSocketFactory(String, KeyStore, String, KeyStore, SecureRandom, X509HostnameVerifier)}
*/
@Deprecated
public SSLSocketFactory(
final String algorithm,
final KeyStore keystore,
final String keystorePassword,
final KeyStore truststore,
final SecureRandom random,
final HostNameResolver nameResolver)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
this(createSSLContext(
algorithm, keystore, keystorePassword, truststore, random, null),
nameResolver);
}
/**
* @since 4.1
*/
public SSLSocketFactory(
String algorithm,
final KeyStore keystore,
final String keystorePassword,
final KeyStore truststore,
final SecureRandom random,
final X509HostnameVerifier hostnameVerifier)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
this(createSSLContext(
algorithm, keystore, keystorePassword, truststore, random, null),
hostnameVerifier);
}
/**
* @since 4.1
*/
public SSLSocketFactory(
String algorithm,
final KeyStore keystore,
final String keystorePassword,
final KeyStore truststore,
final SecureRandom random,
final TrustStrategy trustStrategy,
final X509HostnameVerifier hostnameVerifier)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
this(createSSLContext(
algorithm, keystore, keystorePassword, truststore, random, trustStrategy),
hostnameVerifier);
}
public SSLSocketFactory(
final KeyStore keystore,
final String keystorePassword,
final KeyStore truststore)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
this(TLS, keystore, keystorePassword, truststore, null, null, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
}
public SSLSocketFactory(
final KeyStore keystore,
final String keystorePassword)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException{
this(TLS, keystore, keystorePassword, null, null, null, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
}
public SSLSocketFactory(
final KeyStore truststore)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
this(TLS, null, null, truststore, null, null, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
}
/**
* @since 4.1
*/
public SSLSocketFactory(
final TrustStrategy trustStrategy,
final X509HostnameVerifier hostnameVerifier)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
this(TLS, null, null, null, null, trustStrategy, hostnameVerifier);
}
/**
* @since 4.1
*/
public SSLSocketFactory(
final TrustStrategy trustStrategy)
throws NoSuchAlgorithmException, KeyManagementException, KeyStoreException, UnrecoverableKeyException {
this(TLS, null, null, null, null, trustStrategy, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
}
public SSLSocketFactory(final SSLContext sslContext) {
this(sslContext, BROWSER_COMPATIBLE_HOSTNAME_VERIFIER);
}
/**
* @deprecated Use {@link #SSLSocketFactory(SSLContext)}
*/
@Deprecated
public SSLSocketFactory(
final SSLContext sslContext, final HostNameResolver nameResolver) {
super();
this.socketfactory = sslContext.getSocketFactory();
this.hostnameVerifier = BROWSER_COMPATIBLE_HOSTNAME_VERIFIER;
this.nameResolver = nameResolver;
}
/**
* @since 4.1
*/
public SSLSocketFactory(
final SSLContext sslContext, final X509HostnameVerifier hostnameVerifier) {
super();
this.socketfactory = sslContext.getSocketFactory();
this.hostnameVerifier = hostnameVerifier;
this.nameResolver = null;
}
private SSLSocketFactory() {
this(createDefaultSSLContext());
}
/**
* @param params Optional parameters. Parameters passed to this method will have no effect.
* This method will create a unconnected instance of {@link Socket} class.
* @since 4.1
*/
public Socket createSocket(final HttpParams params) throws IOException {
return this.socketfactory.createSocket();
}
@Deprecated
public Socket createSocket() throws IOException {
return this.socketfactory.createSocket();
}
/**
* @since 4.1
*/
public Socket connectSocket(
final Socket socket,
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
if (remoteAddress == null) {
throw new IllegalArgumentException("Remote address may not be null");
}
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Socket sock = socket != null ? socket : new Socket();
if (localAddress != null) {
sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
sock.bind(localAddress);
}
int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
int soTimeout = HttpConnectionParams.getSoTimeout(params);
try {
sock.setSoTimeout(soTimeout);
sock.connect(remoteAddress, connTimeout);
} catch (SocketTimeoutException ex) {
throw new ConnectTimeoutException("Connect to " + remoteAddress.getHostName() + "/"
+ remoteAddress.getAddress() + " timed out");
}
SSLSocket sslsock;
// Setup SSL layering if necessary
if (sock instanceof SSLSocket) {
sslsock = (SSLSocket) sock;
} else {
sslsock = (SSLSocket) this.socketfactory.createSocket(
sock, remoteAddress.getHostName(), remoteAddress.getPort(), true);
}
if (this.hostnameVerifier != null) {
try {
this.hostnameVerifier.verify(remoteAddress.getHostName(), sslsock);
// verifyHostName() didn't blowup - good!
} catch (IOException iox) {
// close the socket before re-throwing the exception
try { sslsock.close(); } catch (Exception x) { /*ignore*/ }
throw iox;
}
}
return sslsock;
}
/**
* Checks whether a socket connection is secure.
* This factory creates TLS/SSL socket connections
* which, by default, are considered secure.
* <br/>
* Derived classes may override this method to perform
* runtime checks, for example based on the cypher suite.
*
* @param sock the connected socket
*
* @return <code>true</code>
*
* @throws IllegalArgumentException if the argument is invalid
*/
public boolean isSecure(final Socket sock) throws IllegalArgumentException {
if (sock == null) {
throw new IllegalArgumentException("Socket may not be null");
}
// This instanceof check is in line with createSocket() above.
if (!(sock instanceof SSLSocket)) {
throw new IllegalArgumentException("Socket not created by this factory");
}
// This check is performed last since it calls the argument object.
if (sock.isClosed()) {
throw new IllegalArgumentException("Socket is closed");
}
return true;
}
/**
* @since 4.1
*/
public Socket createLayeredSocket(
final Socket socket,
final String host,
final int port,
final boolean autoClose) throws IOException, UnknownHostException {
SSLSocket sslSocket = (SSLSocket) this.socketfactory.createSocket(
socket,
host,
port,
autoClose
);
if (this.hostnameVerifier != null) {
this.hostnameVerifier.verify(host, sslSocket);
}
// verifyHostName() didn't blowup - good!
return sslSocket;
}
@Deprecated
public void setHostnameVerifier(X509HostnameVerifier hostnameVerifier) {
if ( hostnameVerifier == null ) {
throw new IllegalArgumentException("Hostname verifier may not be null");
}
this.hostnameVerifier = hostnameVerifier;
}
public X509HostnameVerifier getHostnameVerifier() {
return this.hostnameVerifier;
}
/**
* @deprecated Use {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}
*/
@Deprecated
public Socket connectSocket(
final Socket socket,
final String host, int port,
final InetAddress localAddress, int localPort,
final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
InetSocketAddress local = null;
if (localAddress != null || localPort > 0) {
// we need to bind explicitly
if (localPort < 0) {
localPort = 0; // indicates "any"
}
local = new InetSocketAddress(localAddress, localPort);
}
InetAddress remoteAddress;
if (this.nameResolver != null) {
remoteAddress = this.nameResolver.resolve(host);
} else {
remoteAddress = InetAddress.getByName(host);
}
InetSocketAddress remote = new InetSocketAddress(remoteAddress, port);
return connectSocket(socket, remote, local, params);
}
/**
* @deprecated Use {@link #createLayeredSocket(Socket, String, int, boolean)}
*/
@Deprecated
public Socket createSocket(
final Socket socket,
final String host, int port,
boolean autoClose) throws IOException, UnknownHostException {
return createLayeredSocket(socket, host, port, autoClose);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ssl/SSLSocketFactory.java
|
Java
|
gpl3
| 19,280
|
/*
* ====================================================================
* 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.ogt.http.conn.routing;
import org.apache.ogt.http.HttpException;
import org.apache.ogt.http.HttpHost;
import org.apache.ogt.http.HttpRequest;
import org.apache.ogt.http.protocol.HttpContext;
/**
* Encapsulates logic to compute a {@link HttpRoute} to a target host.
* Implementations may for example be based on parameters, or on the
* standard Java system properties.
* <p>
* Implementations of this interface must be thread-safe. Access to shared
* data must be synchronized as methods of this interface may be executed
* from multiple threads.
*
* @since 4.0
*/
public interface HttpRoutePlanner {
/**
* Determines the route for a request.
*
* @param target the target host for the request.
* Implementations may accept <code>null</code>
* if they can still determine a route, for example
* to a default target or by inspecting the request.
* @param request the request to execute
* @param context the context to use for the subsequent execution.
* Implementations may accept <code>null</code>.
*
* @return the route that the request should take
*
* @throws HttpException in case of a problem
*/
public HttpRoute determineRoute(HttpHost target,
HttpRequest request,
HttpContext context) throws HttpException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/routing/HttpRoutePlanner.java
|
Java
|
gpl3
| 2,660
|
<html>
<head>
<!--
/*
* ====================================================================
* 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/>.
*
*/
-->
</head>
<body>
The client-side route representation and tracking API.
<p>
An {@link org.apache.ogt.http.conn.routing.HttpRoute HttpRoute}
is the path along which a request has to be sent to the server.
The route starts at a local network address and may pass
through one or more proxies before reaching the target.
Routes through proxies can be tunnelled, and a layered protocol (TLS/SSL)
might be put on top of the tunnel.
The {@link org.apache.ogt.http.conn.routing.RouteTracker RouteTracker}
helps in tracking the steps for establishing a route, while an
{@link org.apache.ogt.http.conn.routing.HttpRouteDirector HttpRouteDirector}
determines the next step to take.
</p>
<p>
The {@link org.apache.ogt.http.conn.routing.HttpRoutePlanner HttpRoutePlanner}
is responsible for determining a route to a given target host.
Implementations must know about proxies to use, and about exemptions
for hosts that should be contacted directly without a proxy.
</p>
</body>
</html>
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/routing/package.html
|
HTML
|
gpl3
| 2,178
|
/*
* ====================================================================
* 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.ogt.http.conn.routing;
import java.net.InetAddress;
import org.apache.ogt.http.HttpHost;
import org.apache.ogt.http.annotation.Immutable;
import org.apache.ogt.http.util.LangUtils;
/**
* The route for a request.
* Instances of this class are unmodifiable and therefore suitable
* for use as lookup keys.
*
* @since 4.0
*/
@Immutable
public final class HttpRoute implements RouteInfo, Cloneable {
private static final HttpHost[] EMPTY_HTTP_HOST_ARRAY = new HttpHost[]{};
/** The target host to connect to. */
private final HttpHost targetHost;
/**
* The local address to connect from.
* <code>null</code> indicates that the default should be used.
*/
private final InetAddress localAddress;
/** The proxy servers, if any. Never null. */
private final HttpHost[] proxyChain;
/** Whether the the route is tunnelled through the proxy. */
private final TunnelType tunnelled;
/** Whether the route is layered. */
private final LayerType layered;
/** Whether the route is (supposed to be) secure. */
private final boolean secure;
/**
* Internal, fully-specified constructor.
* This constructor does <i>not</i> clone the proxy chain array,
* nor test it for <code>null</code> elements. This conversion and
* check is the responsibility of the public constructors.
* The order of arguments here is different from the similar public
* constructor, as required by Java.
*
* @param local the local address to route from, or
* <code>null</code> for the default
* @param target the host to which to route
* @param proxies the proxy chain to use, or
* <code>null</code> for a direct route
* @param secure <code>true</code> if the route is (to be) secure,
* <code>false</code> otherwise
* @param tunnelled the tunnel type of this route, or
* <code>null</code> for PLAIN
* @param layered the layering type of this route, or
* <code>null</code> for PLAIN
*/
private HttpRoute(InetAddress local,
HttpHost target, HttpHost[] proxies,
boolean secure,
TunnelType tunnelled, LayerType layered) {
if (target == null) {
throw new IllegalArgumentException
("Target host may not be null.");
}
if (proxies == null) {
throw new IllegalArgumentException
("Proxies may not be null.");
}
if ((tunnelled == TunnelType.TUNNELLED) && (proxies.length == 0)) {
throw new IllegalArgumentException
("Proxy required if tunnelled.");
}
// tunnelled is already checked above, that is in line with the default
if (tunnelled == null)
tunnelled = TunnelType.PLAIN;
if (layered == null)
layered = LayerType.PLAIN;
this.targetHost = target;
this.localAddress = local;
this.proxyChain = proxies;
this.secure = secure;
this.tunnelled = tunnelled;
this.layered = layered;
}
/**
* Creates a new route with all attributes specified explicitly.
*
* @param target the host to which to route
* @param local the local address to route from, or
* <code>null</code> for the default
* @param proxies the proxy chain to use, or
* <code>null</code> for a direct route
* @param secure <code>true</code> if the route is (to be) secure,
* <code>false</code> otherwise
* @param tunnelled the tunnel type of this route
* @param layered the layering type of this route
*/
public HttpRoute(HttpHost target, InetAddress local, HttpHost[] proxies,
boolean secure, TunnelType tunnelled, LayerType layered) {
this(local, target, toChain(proxies), secure, tunnelled, layered);
}
/**
* Creates a new route with at most one proxy.
*
* @param target the host to which to route
* @param local the local address to route from, or
* <code>null</code> for the default
* @param proxy the proxy to use, or
* <code>null</code> for a direct route
* @param secure <code>true</code> if the route is (to be) secure,
* <code>false</code> otherwise
* @param tunnelled <code>true</code> if the route is (to be) tunnelled
* via the proxy,
* <code>false</code> otherwise
* @param layered <code>true</code> if the route includes a
* layered protocol,
* <code>false</code> otherwise
*/
public HttpRoute(HttpHost target, InetAddress local, HttpHost proxy,
boolean secure, TunnelType tunnelled, LayerType layered) {
this(local, target, toChain(proxy), secure, tunnelled, layered);
}
/**
* Creates a new direct route.
* That is a route without a proxy.
*
* @param target the host to which to route
* @param local the local address to route from, or
* <code>null</code> for the default
* @param secure <code>true</code> if the route is (to be) secure,
* <code>false</code> otherwise
*/
public HttpRoute(HttpHost target, InetAddress local, boolean secure) {
this(local, target, EMPTY_HTTP_HOST_ARRAY, secure, TunnelType.PLAIN, LayerType.PLAIN);
}
/**
* Creates a new direct insecure route.
*
* @param target the host to which to route
*/
public HttpRoute(HttpHost target) {
this(null, target, EMPTY_HTTP_HOST_ARRAY, false, TunnelType.PLAIN, LayerType.PLAIN);
}
/**
* Creates a new route through a proxy.
* When using this constructor, the <code>proxy</code> MUST be given.
* For convenience, it is assumed that a secure connection will be
* layered over a tunnel through the proxy.
*
* @param target the host to which to route
* @param local the local address to route from, or
* <code>null</code> for the default
* @param proxy the proxy to use
* @param secure <code>true</code> if the route is (to be) secure,
* <code>false</code> otherwise
*/
public HttpRoute(HttpHost target, InetAddress local, HttpHost proxy,
boolean secure) {
this(local, target, toChain(proxy), secure,
secure ? TunnelType.TUNNELLED : TunnelType.PLAIN,
secure ? LayerType.LAYERED : LayerType.PLAIN);
if (proxy == null) {
throw new IllegalArgumentException
("Proxy host may not be null.");
}
}
/**
* Helper to convert a proxy to a proxy chain.
*
* @param proxy the only proxy in the chain, or <code>null</code>
*
* @return a proxy chain array, may be empty (never null)
*/
private static HttpHost[] toChain(HttpHost proxy) {
if (proxy == null)
return EMPTY_HTTP_HOST_ARRAY;
return new HttpHost[]{ proxy };
}
/**
* Helper to duplicate and check a proxy chain.
* <code>null</code> is converted to an empty proxy chain.
*
* @param proxies the proxy chain to duplicate, or <code>null</code>
*
* @return a new proxy chain array, may be empty (never null)
*/
private static HttpHost[] toChain(HttpHost[] proxies) {
if ((proxies == null) || (proxies.length < 1))
return EMPTY_HTTP_HOST_ARRAY;
for (HttpHost proxy : proxies) {
if (proxy == null)
throw new IllegalArgumentException
("Proxy chain may not contain null elements.");
}
// copy the proxy chain, the traditional way
HttpHost[] result = new HttpHost[proxies.length];
System.arraycopy(proxies, 0, result, 0, proxies.length);
return result;
}
// non-JavaDoc, see interface RouteInfo
public final HttpHost getTargetHost() {
return this.targetHost;
}
// non-JavaDoc, see interface RouteInfo
public final InetAddress getLocalAddress() {
return this.localAddress;
}
public final int getHopCount() {
return proxyChain.length+1;
}
public final HttpHost getHopTarget(int hop) {
if (hop < 0)
throw new IllegalArgumentException
("Hop index must not be negative: " + hop);
final int hopcount = getHopCount();
if (hop >= hopcount)
throw new IllegalArgumentException
("Hop index " + hop +
" exceeds route length " + hopcount);
HttpHost result = null;
if (hop < hopcount-1)
result = this.proxyChain[hop];
else
result = this.targetHost;
return result;
}
public final HttpHost getProxyHost() {
return (this.proxyChain.length == 0) ? null : this.proxyChain[0];
}
public final TunnelType getTunnelType() {
return this.tunnelled;
}
public final boolean isTunnelled() {
return (this.tunnelled == TunnelType.TUNNELLED);
}
public final LayerType getLayerType() {
return this.layered;
}
public final boolean isLayered() {
return (this.layered == LayerType.LAYERED);
}
public final boolean isSecure() {
return this.secure;
}
/**
* Compares this route to another.
*
* @param obj the object to compare with
*
* @return <code>true</code> if the argument is the same route,
* <code>false</code>
*/
@Override
public final boolean equals(Object obj) {
if (this == obj) return true;
if (obj instanceof HttpRoute) {
HttpRoute that = (HttpRoute) obj;
return
// Do the cheapest tests first
(this.secure == that.secure) &&
(this.tunnelled == that.tunnelled) &&
(this.layered == that.layered) &&
LangUtils.equals(this.targetHost, that.targetHost) &&
LangUtils.equals(this.localAddress, that.localAddress) &&
LangUtils.equals(this.proxyChain, that.proxyChain);
} else {
return false;
}
}
/**
* Generates a hash code for this route.
*
* @return the hash code
*/
@Override
public final int hashCode() {
int hash = LangUtils.HASH_SEED;
hash = LangUtils.hashCode(hash, this.targetHost);
hash = LangUtils.hashCode(hash, this.localAddress);
for (int i = 0; i < this.proxyChain.length; i++) {
hash = LangUtils.hashCode(hash, this.proxyChain[i]);
}
hash = LangUtils.hashCode(hash, this.secure);
hash = LangUtils.hashCode(hash, this.tunnelled);
hash = LangUtils.hashCode(hash, this.layered);
return hash;
}
/**
* Obtains a description of this route.
*
* @return a human-readable representation of this route
*/
@Override
public final String toString() {
StringBuilder cab = new StringBuilder(50 + getHopCount()*30);
cab.append("HttpRoute[");
if (this.localAddress != null) {
cab.append(this.localAddress);
cab.append("->");
}
cab.append('{');
if (this.tunnelled == TunnelType.TUNNELLED)
cab.append('t');
if (this.layered == LayerType.LAYERED)
cab.append('l');
if (this.secure)
cab.append('s');
cab.append("}->");
for (HttpHost aProxyChain : this.proxyChain) {
cab.append(aProxyChain);
cab.append("->");
}
cab.append(this.targetHost);
cab.append(']');
return cab.toString();
}
// default implementation of clone() is sufficient
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/routing/HttpRoute.java
|
Java
|
gpl3
| 13,548
|
/*
* ====================================================================
* 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.ogt.http.conn.routing;
/**
* Provides directions on establishing a route.
* Implementations of this interface compare a planned route with
* a tracked route and indicate the next step required.
*
* @since 4.0
*/
public interface HttpRouteDirector {
/** Indicates that the route can not be established at all. */
public final static int UNREACHABLE = -1;
/** Indicates that the route is complete. */
public final static int COMPLETE = 0;
/** Step: open connection to target. */
public final static int CONNECT_TARGET = 1;
/** Step: open connection to proxy. */
public final static int CONNECT_PROXY = 2;
/** Step: tunnel through proxy to target. */
public final static int TUNNEL_TARGET = 3;
/** Step: tunnel through proxy to other proxy. */
public final static int TUNNEL_PROXY = 4;
/** Step: layer protocol (over tunnel). */
public final static int LAYER_PROTOCOL = 5;
/**
* Provides the next step.
*
* @param plan the planned route
* @param fact the currently established route, or
* <code>null</code> if nothing is established
*
* @return one of the constants defined in this interface, indicating
* either the next step to perform, or success, or failure.
* 0 is for success, a negative value for failure.
*/
public int nextStep(RouteInfo plan, RouteInfo fact);
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/routing/HttpRouteDirector.java
|
Java
|
gpl3
| 2,649
|
/*
* ====================================================================
* 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.ogt.http.conn.routing;
import java.net.InetAddress;
import org.apache.ogt.http.HttpHost;
import org.apache.ogt.http.annotation.NotThreadSafe;
import org.apache.ogt.http.util.LangUtils;
/**
* Helps tracking the steps in establishing a route.
*
* @since 4.0
*/
@NotThreadSafe
public final class RouteTracker implements RouteInfo, Cloneable {
/** The target host to connect to. */
private final HttpHost targetHost;
/**
* The local address to connect from.
* <code>null</code> indicates that the default should be used.
*/
private final InetAddress localAddress;
// the attributes above are fixed at construction time
// now follow attributes that indicate the established route
/** Whether the first hop of the route is established. */
private boolean connected;
/** The proxy chain, if any. */
private HttpHost[] proxyChain;
/** Whether the the route is tunnelled end-to-end through proxies. */
private TunnelType tunnelled;
/** Whether the route is layered over a tunnel. */
private LayerType layered;
/** Whether the route is secure. */
private boolean secure;
/**
* Creates a new route tracker.
* The target and origin need to be specified at creation time.
*
* @param target the host to which to route
* @param local the local address to route from, or
* <code>null</code> for the default
*/
public RouteTracker(HttpHost target, InetAddress local) {
if (target == null) {
throw new IllegalArgumentException("Target host may not be null.");
}
this.targetHost = target;
this.localAddress = local;
this.tunnelled = TunnelType.PLAIN;
this.layered = LayerType.PLAIN;
}
/**
* Creates a new tracker for the given route.
* Only target and origin are taken from the route,
* everything else remains to be tracked.
*
* @param route the route to track
*/
public RouteTracker(HttpRoute route) {
this(route.getTargetHost(), route.getLocalAddress());
}
/**
* Tracks connecting to the target.
*
* @param secure <code>true</code> if the route is secure,
* <code>false</code> otherwise
*/
public final void connectTarget(boolean secure) {
if (this.connected) {
throw new IllegalStateException("Already connected.");
}
this.connected = true;
this.secure = secure;
}
/**
* Tracks connecting to the first proxy.
*
* @param proxy the proxy connected to
* @param secure <code>true</code> if the route is secure,
* <code>false</code> otherwise
*/
public final void connectProxy(HttpHost proxy, boolean secure) {
if (proxy == null) {
throw new IllegalArgumentException("Proxy host may not be null.");
}
if (this.connected) {
throw new IllegalStateException("Already connected.");
}
this.connected = true;
this.proxyChain = new HttpHost[]{ proxy };
this.secure = secure;
}
/**
* Tracks tunnelling to the target.
*
* @param secure <code>true</code> if the route is secure,
* <code>false</code> otherwise
*/
public final void tunnelTarget(boolean secure) {
if (!this.connected) {
throw new IllegalStateException("No tunnel unless connected.");
}
if (this.proxyChain == null) {
throw new IllegalStateException("No tunnel without proxy.");
}
this.tunnelled = TunnelType.TUNNELLED;
this.secure = secure;
}
/**
* Tracks tunnelling to a proxy in a proxy chain.
* This will extend the tracked proxy chain, but it does not mark
* the route as tunnelled. Only end-to-end tunnels are considered there.
*
* @param proxy the proxy tunnelled to
* @param secure <code>true</code> if the route is secure,
* <code>false</code> otherwise
*/
public final void tunnelProxy(HttpHost proxy, boolean secure) {
if (proxy == null) {
throw new IllegalArgumentException("Proxy host may not be null.");
}
if (!this.connected) {
throw new IllegalStateException("No tunnel unless connected.");
}
if (this.proxyChain == null) {
throw new IllegalStateException("No proxy tunnel without proxy.");
}
// prepare an extended proxy chain
HttpHost[] proxies = new HttpHost[this.proxyChain.length+1];
System.arraycopy(this.proxyChain, 0,
proxies, 0, this.proxyChain.length);
proxies[proxies.length-1] = proxy;
this.proxyChain = proxies;
this.secure = secure;
}
/**
* Tracks layering a protocol.
*
* @param secure <code>true</code> if the route is secure,
* <code>false</code> otherwise
*/
public final void layerProtocol(boolean secure) {
// it is possible to layer a protocol over a direct connection,
// although this case is probably not considered elsewhere
if (!this.connected) {
throw new IllegalStateException
("No layered protocol unless connected.");
}
this.layered = LayerType.LAYERED;
this.secure = secure;
}
public final HttpHost getTargetHost() {
return this.targetHost;
}
public final InetAddress getLocalAddress() {
return this.localAddress;
}
public final int getHopCount() {
int hops = 0;
if (this.connected) {
if (proxyChain == null)
hops = 1;
else
hops = proxyChain.length + 1;
}
return hops;
}
public final HttpHost getHopTarget(int hop) {
if (hop < 0)
throw new IllegalArgumentException
("Hop index must not be negative: " + hop);
final int hopcount = getHopCount();
if (hop >= hopcount) {
throw new IllegalArgumentException
("Hop index " + hop +
" exceeds tracked route length " + hopcount +".");
}
HttpHost result = null;
if (hop < hopcount-1)
result = this.proxyChain[hop];
else
result = this.targetHost;
return result;
}
public final HttpHost getProxyHost() {
return (this.proxyChain == null) ? null : this.proxyChain[0];
}
public final boolean isConnected() {
return this.connected;
}
public final TunnelType getTunnelType() {
return this.tunnelled;
}
public final boolean isTunnelled() {
return (this.tunnelled == TunnelType.TUNNELLED);
}
public final LayerType getLayerType() {
return this.layered;
}
public final boolean isLayered() {
return (this.layered == LayerType.LAYERED);
}
public final boolean isSecure() {
return this.secure;
}
/**
* Obtains the tracked route.
* If a route has been tracked, it is {@link #isConnected connected}.
* If not connected, nothing has been tracked so far.
*
* @return the tracked route, or
* <code>null</code> if nothing has been tracked so far
*/
public final HttpRoute toRoute() {
return !this.connected ?
null : new HttpRoute(this.targetHost, this.localAddress,
this.proxyChain, this.secure,
this.tunnelled, this.layered);
}
/**
* Compares this tracked route to another.
*
* @param o the object to compare with
*
* @return <code>true</code> if the argument is the same tracked route,
* <code>false</code>
*/
@Override
public final boolean equals(Object o) {
if (o == this)
return true;
if (!(o instanceof RouteTracker))
return false;
RouteTracker that = (RouteTracker) o;
return
// Do the cheapest checks first
(this.connected == that.connected) &&
(this.secure == that.secure) &&
(this.tunnelled == that.tunnelled) &&
(this.layered == that.layered) &&
LangUtils.equals(this.targetHost, that.targetHost) &&
LangUtils.equals(this.localAddress, that.localAddress) &&
LangUtils.equals(this.proxyChain, that.proxyChain);
}
/**
* Generates a hash code for this tracked route.
* Route trackers are modifiable and should therefore not be used
* as lookup keys. Use {@link #toRoute toRoute} to obtain an
* unmodifiable representation of the tracked route.
*
* @return the hash code
*/
@Override
public final int hashCode() {
int hash = LangUtils.HASH_SEED;
hash = LangUtils.hashCode(hash, this.targetHost);
hash = LangUtils.hashCode(hash, this.localAddress);
if (this.proxyChain != null) {
for (int i = 0; i < this.proxyChain.length; i++) {
hash = LangUtils.hashCode(hash, this.proxyChain[i]);
}
}
hash = LangUtils.hashCode(hash, this.connected);
hash = LangUtils.hashCode(hash, this.secure);
hash = LangUtils.hashCode(hash, this.tunnelled);
hash = LangUtils.hashCode(hash, this.layered);
return hash;
}
/**
* Obtains a description of the tracked route.
*
* @return a human-readable representation of the tracked route
*/
@Override
public final String toString() {
StringBuilder cab = new StringBuilder(50 + getHopCount()*30);
cab.append("RouteTracker[");
if (this.localAddress != null) {
cab.append(this.localAddress);
cab.append("->");
}
cab.append('{');
if (this.connected)
cab.append('c');
if (this.tunnelled == TunnelType.TUNNELLED)
cab.append('t');
if (this.layered == LayerType.LAYERED)
cab.append('l');
if (this.secure)
cab.append('s');
cab.append("}->");
if (this.proxyChain != null) {
for (int i=0; i<this.proxyChain.length; i++) {
cab.append(this.proxyChain[i]);
cab.append("->");
}
}
cab.append(this.targetHost);
cab.append(']');
return cab.toString();
}
// default implementation of clone() is sufficient
@Override
public Object clone() throws CloneNotSupportedException {
return super.clone();
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/routing/RouteTracker.java
|
Java
|
gpl3
| 12,052
|
/*
* ====================================================================
* 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.ogt.http.conn.routing;
import java.net.InetAddress;
import org.apache.ogt.http.HttpHost;
/**
* Read-only interface for route information.
*
* @since 4.0
*/
public interface RouteInfo {
/**
* The tunnelling type of a route.
* Plain routes are established by connecting to the target or
* the first proxy.
* Tunnelled routes are established by connecting to the first proxy
* and tunnelling through all proxies to the target.
* Routes without a proxy cannot be tunnelled.
*/
public enum TunnelType { PLAIN, TUNNELLED }
/**
* The layering type of a route.
* Plain routes are established by connecting or tunnelling.
* Layered routes are established by layering a protocol such as TLS/SSL
* over an existing connection.
* Protocols can only be layered over a tunnel to the target, or
* or over a direct connection without proxies.
* <br/>
* Layering a protocol
* over a direct connection makes little sense, since the connection
* could be established with the new protocol in the first place.
* But we don't want to exclude that use case.
*/
public enum LayerType { PLAIN, LAYERED }
/**
* Obtains the target host.
*
* @return the target host
*/
HttpHost getTargetHost();
/**
* Obtains the local address to connect from.
*
* @return the local address,
* or <code>null</code>
*/
InetAddress getLocalAddress();
/**
* Obtains the number of hops in this route.
* A direct route has one hop. A route through a proxy has two hops.
* A route through a chain of <i>n</i> proxies has <i>n+1</i> hops.
*
* @return the number of hops in this route
*/
int getHopCount();
/**
* Obtains the target of a hop in this route.
* The target of the last hop is the {@link #getTargetHost target host},
* the target of previous hops is the respective proxy in the chain.
* For a route through exactly one proxy, target of hop 0 is the proxy
* and target of hop 1 is the target host.
*
* @param hop index of the hop for which to get the target,
* 0 for first
*
* @return the target of the given hop
*
* @throws IllegalArgumentException
* if the argument is negative or not less than
* {@link #getHopCount getHopCount()}
*/
HttpHost getHopTarget(int hop);
/**
* Obtains the first proxy host.
*
* @return the first proxy in the proxy chain, or
* <code>null</code> if this route is direct
*/
HttpHost getProxyHost();
/**
* Obtains the tunnel type of this route.
* If there is a proxy chain, only end-to-end tunnels are considered.
*
* @return the tunnelling type
*/
TunnelType getTunnelType();
/**
* Checks whether this route is tunnelled through a proxy.
* If there is a proxy chain, only end-to-end tunnels are considered.
*
* @return <code>true</code> if tunnelled end-to-end through at least
* one proxy,
* <code>false</code> otherwise
*/
boolean isTunnelled();
/**
* Obtains the layering type of this route.
* In the presence of proxies, only layering over an end-to-end tunnel
* is considered.
*
* @return the layering type
*/
LayerType getLayerType();
/**
* Checks whether this route includes a layered protocol.
* In the presence of proxies, only layering over an end-to-end tunnel
* is considered.
*
* @return <code>true</code> if layered,
* <code>false</code> otherwise
*/
boolean isLayered();
/**
* Checks whether this route is secure.
*
* @return <code>true</code> if secure,
* <code>false</code> otherwise
*/
boolean isSecure();
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/routing/RouteInfo.java
|
Java
|
gpl3
| 5,142
|
/*
* ====================================================================
* 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.ogt.http.conn.routing;
import org.apache.ogt.http.annotation.Immutable;
/**
* Basic implementation of an {@link HttpRouteDirector HttpRouteDirector}.
* This implementation is stateless and therefore thread-safe.
*
* @since 4.0
*/
@Immutable
public class BasicRouteDirector implements HttpRouteDirector {
/**
* Provides the next step.
*
* @param plan the planned route
* @param fact the currently established route, or
* <code>null</code> if nothing is established
*
* @return one of the constants defined in this class, indicating
* either the next step to perform, or success, or failure.
* 0 is for success, a negative value for failure.
*/
public int nextStep(RouteInfo plan, RouteInfo fact) {
if (plan == null) {
throw new IllegalArgumentException
("Planned route may not be null.");
}
int step = UNREACHABLE;
if ((fact == null) || (fact.getHopCount() < 1))
step = firstStep(plan);
else if (plan.getHopCount() > 1)
step = proxiedStep(plan, fact);
else
step = directStep(plan, fact);
return step;
} // nextStep
/**
* Determines the first step to establish a route.
*
* @param plan the planned route
*
* @return the first step
*/
protected int firstStep(RouteInfo plan) {
return (plan.getHopCount() > 1) ?
CONNECT_PROXY : CONNECT_TARGET;
}
/**
* Determines the next step to establish a direct connection.
*
* @param plan the planned route
* @param fact the currently established route
*
* @return one of the constants defined in this class, indicating
* either the next step to perform, or success, or failure
*/
protected int directStep(RouteInfo plan, RouteInfo fact) {
if (fact.getHopCount() > 1)
return UNREACHABLE;
if (!plan.getTargetHost().equals(fact.getTargetHost()))
return UNREACHABLE;
// If the security is too low, we could now suggest to layer
// a secure protocol on the direct connection. Layering on direct
// connections has not been supported in HttpClient 3.x, we don't
// consider it here until there is a real-life use case for it.
// Should we tolerate if security is better than planned?
// (plan.isSecure() && !fact.isSecure())
if (plan.isSecure() != fact.isSecure())
return UNREACHABLE;
// Local address has to match only if the plan specifies one.
if ((plan.getLocalAddress() != null) &&
!plan.getLocalAddress().equals(fact.getLocalAddress())
)
return UNREACHABLE;
return COMPLETE;
}
/**
* Determines the next step to establish a connection via proxy.
*
* @param plan the planned route
* @param fact the currently established route
*
* @return one of the constants defined in this class, indicating
* either the next step to perform, or success, or failure
*/
protected int proxiedStep(RouteInfo plan, RouteInfo fact) {
if (fact.getHopCount() <= 1)
return UNREACHABLE;
if (!plan.getTargetHost().equals(fact.getTargetHost()))
return UNREACHABLE;
final int phc = plan.getHopCount();
final int fhc = fact.getHopCount();
if (phc < fhc)
return UNREACHABLE;
for (int i=0; i<fhc-1; i++) {
if (!plan.getHopTarget(i).equals(fact.getHopTarget(i)))
return UNREACHABLE;
}
// now we know that the target matches and proxies so far are the same
if (phc > fhc)
return TUNNEL_PROXY; // need to extend the proxy chain
// proxy chain and target are the same, check tunnelling and layering
if ((fact.isTunnelled() && !plan.isTunnelled()) ||
(fact.isLayered() && !plan.isLayered()))
return UNREACHABLE;
if (plan.isTunnelled() && !fact.isTunnelled())
return TUNNEL_TARGET;
if (plan.isLayered() && !fact.isLayered())
return LAYER_PROTOCOL;
// tunnel and layering are the same, remains to check the security
// Should we tolerate if security is better than planned?
// (plan.isSecure() && !fact.isSecure())
if (plan.isSecure() != fact.isSecure())
return UNREACHABLE;
return COMPLETE;
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/routing/BasicRouteDirector.java
|
Java
|
gpl3
| 5,817
|
/*
* ====================================================================
* 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.ogt.http.conn;
import org.apache.ogt.http.ConnectionReuseStrategy;
import org.apache.ogt.http.HttpResponse;
import org.apache.ogt.http.protocol.HttpContext;
/**
* Interface for deciding how long a connection can remain
* idle before being reused.
* <p>
* Implementations of this interface must be thread-safe. Access to shared
* data must be synchronized as methods of this interface may be executed
* from multiple threads.
*
* @since 4.0
*/
public interface ConnectionKeepAliveStrategy {
/**
* Returns the duration of time which this connection can be safely kept
* idle. If the connection is left idle for longer than this period of time,
* it MUST not reused. A value of 0 or less may be returned to indicate that
* there is no suitable suggestion.
*
* When coupled with a {@link ConnectionReuseStrategy}, if
* {@link ConnectionReuseStrategy#keepAlive(HttpResponse, HttpContext)}
* returns true, this allows you to control how long the reuse will last. If
* keepAlive returns false, this should have no meaningful impact
*
* @param response
* The last response received over the connection.
* @param context
* the context in which the connection is being used.
*
* @return the duration in ms for which it is safe to keep the connection
* idle, or <=0 if no suggested duration.
*/
long getKeepAliveDuration(HttpResponse response, HttpContext context);
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ConnectionKeepAliveStrategy.java
|
Java
|
gpl3
| 2,701
|
/*
* ====================================================================
* 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.ogt.http.conn;
import java.util.concurrent.TimeUnit;
import org.apache.ogt.http.conn.routing.HttpRoute;
import org.apache.ogt.http.conn.scheme.SchemeRegistry;
/**
* Management interface for {@link ManagedClientConnection client connections}.
* The purpose of an HTTP connection manager is to serve as a factory for new
* HTTP connections, manage persistent connections and synchronize access to
* persistent connections making sure that only one thread of execution can
* have access to a connection at a time.
* <p>
* Implementations of this interface must be thread-safe. Access to shared
* data must be synchronized as methods of this interface may be executed
* from multiple threads.
*
* @since 4.0
*/
public interface ClientConnectionManager {
/**
* Obtains the scheme registry used by this manager.
*
* @return the scheme registry, never <code>null</code>
*/
SchemeRegistry getSchemeRegistry();
/**
* Returns a new {@link ClientConnectionRequest}, from which a
* {@link ManagedClientConnection} can be obtained or the request can be
* aborted.
*/
ClientConnectionRequest requestConnection(HttpRoute route, Object state);
/**
* Releases a connection for use by others.
* You may optionally specify how long the connection is valid
* to be reused. Values <= 0 are considered to be valid forever.
* If the connection is not marked as reusable, the connection will
* not be reused regardless of the valid duration.
*
* If the connection has been released before,
* the call will be ignored.
*
* @param conn the connection to release
* @param validDuration the duration of time this connection is valid for reuse
* @param timeUnit the unit of time validDuration is measured in
*
* @see #closeExpiredConnections()
*/
void releaseConnection(ManagedClientConnection conn, long validDuration, TimeUnit timeUnit);
/**
* Closes idle connections in the pool.
* Open connections in the pool that have not been used for the
* timespan given by the argument will be closed.
* Currently allocated connections are not subject to this method.
* Times will be checked with milliseconds precision
*
* All expired connections will also be closed.
*
* @param idletime the idle time of connections to be closed
* @param tunit the unit for the <code>idletime</code>
*
* @see #closeExpiredConnections()
*/
void closeIdleConnections(long idletime, TimeUnit tunit);
/**
* Closes all expired connections in the pool.
* Open connections in the pool that have not been used for
* the timespan defined when the connection was released will be closed.
* Currently allocated connections are not subject to this method.
* Times will be checked with milliseconds precision.
*/
void closeExpiredConnections();
/**
* Shuts down this connection manager and releases allocated resources.
* This includes closing all connections, whether they are currently
* used or not.
*/
void shutdown();
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ClientConnectionManager.java
|
Java
|
gpl3
| 4,377
|
/*
* ====================================================================
*
* 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.ogt.http.conn;
import java.io.IOException;
/**
* Interface for releasing a connection. This can be implemented by various
* "trigger" objects which are associated with a connection, for example
* a {@link EofSensorInputStream stream} or an {@link BasicManagedEntity entity}
* or the {@link ManagedClientConnection connection} itself.
* <p>
* The methods in this interface can safely be called multiple times.
* The first invocation releases the connection, subsequent calls
* are ignored.
*
* @since 4.0
*/
public interface ConnectionReleaseTrigger {
/**
* Releases the connection with the option of keep-alive. This is a
* "graceful" release and may cause IO operations for consuming the
* remainder of a response entity. Use
* {@link #abortConnection abortConnection} for a hard release. The
* connection may be reused as specified by the duration.
*
* @throws IOException
* in case of an IO problem. The connection will be released
* anyway.
*/
void releaseConnection()
throws IOException;
/**
* Releases the connection without the option of keep-alive.
* This is a "hard" release that implies a shutdown of the connection.
* Use {@link #releaseConnection()} for a graceful release.
*
* @throws IOException in case of an IO problem.
* The connection will be released anyway.
*/
void abortConnection()
throws IOException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ConnectionReleaseTrigger.java
|
Java
|
gpl3
| 2,709
|
/*
* ====================================================================
* 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.ogt.http.conn;
import java.util.concurrent.TimeUnit;
/**
* Encapsulates a request for a {@link ManagedClientConnection}.
*
* @since 4.0
*/
public interface ClientConnectionRequest {
/**
* Obtains a connection within a given time.
* This method will block until a connection becomes available,
* the timeout expires, or the connection manager is
* {@link ClientConnectionManager#shutdown() shut down}.
* Timeouts are handled with millisecond precision.
*
* If {@link #abortRequest()} is called while this is blocking or
* before this began, an {@link InterruptedException} will
* be thrown.
*
* @param timeout the timeout, 0 or negative for no timeout
* @param tunit the unit for the <code>timeout</code>,
* may be <code>null</code> only if there is no timeout
*
* @return a connection that can be used to communicate
* along the given route
*
* @throws ConnectionPoolTimeoutException
* in case of a timeout
* @throws InterruptedException
* if the calling thread is interrupted while waiting
*/
ManagedClientConnection getConnection(long timeout, TimeUnit tunit)
throws InterruptedException, ConnectionPoolTimeoutException;
/**
* Aborts the call to {@link #getConnection(long, TimeUnit)},
* causing it to throw an {@link InterruptedException}.
*/
void abortRequest();
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ClientConnectionRequest.java
|
Java
|
gpl3
| 2,680
|
/*
* ====================================================================
* 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.ogt.http.conn;
import java.io.IOException;
import java.net.Socket;
import org.apache.ogt.http.HttpClientConnection;
import org.apache.ogt.http.HttpHost;
import org.apache.ogt.http.HttpInetConnection;
import org.apache.ogt.http.params.HttpParams;
/**
* A client-side connection that relies on outside logic to connect sockets to the
* appropriate hosts. It can be operated directly by an application, or through an
* {@link ClientConnectionOperator operator}.
*
* @since 4.0
*/
public interface OperatedClientConnection 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();
/**
* Signals that this connection is in the process of being open.
* <p>
* By calling this method, the connection can be re-initialized
* with a new Socket instance before {@link #openCompleted} is called.
* This enabled the connection to close that socket if
* {@link org.apache.ogt.http.HttpConnection#shutdown shutdown}
* is called before it is fully open. Closing an unconnected socket
* will interrupt a thread that is blocked on the connect.
* Otherwise, that thread will either time out on the connect,
* or it returns successfully and then opens this connection
* which was just shut down.
* <p>
* This method can be called multiple times if the connection
* is layered over another protocol. <b>Note:</b> This method
* 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.
* <p>
* The caller must invoke {@link #openCompleted} in order to complete
* the process.
*
* @param sock the unconnected socket which is about to
* be connected.
* @param target the target host of this connection
*/
void opening(Socket sock, HttpHost target)
throws IOException;
/**
* Signals that the connection has been successfully open.
* An attempt to call this method on an open connection will cause
* an exception.
*
* @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 openCompleted(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;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/OperatedClientConnection.java
|
Java
|
gpl3
| 6,333
|
/*
* $Revision $
* ====================================================================
*
* 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.ogt.http.conn;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.ogt.http.HttpEntity;
import org.apache.ogt.http.annotation.NotThreadSafe;
import org.apache.ogt.http.entity.HttpEntityWrapper;
import org.apache.ogt.http.util.EntityUtils;
/**
* An entity that releases a {@link ManagedClientConnection connection}.
* A {@link ManagedClientConnection} will
* typically <i>not</i> return a managed entity, but you can replace
* the unmanaged entity in the response with a managed one.
*
* @since 4.0
*/
@NotThreadSafe
public class BasicManagedEntity extends HttpEntityWrapper
implements ConnectionReleaseTrigger, EofSensorWatcher {
/** The connection to release. */
protected ManagedClientConnection managedConn;
/** Whether to keep the connection alive. */
protected final boolean attemptReuse;
/**
* Creates a new managed entity that can release a connection.
*
* @param entity the entity of which to wrap the content.
* Note that the argument entity can no longer be used
* afterwards, since the content will be taken by this
* managed entity.
* @param conn the connection to release
* @param reuse whether the connection should be re-used
*/
public BasicManagedEntity(HttpEntity entity,
ManagedClientConnection conn,
boolean reuse) {
super(entity);
if (conn == null)
throw new IllegalArgumentException
("Connection may not be null.");
this.managedConn = conn;
this.attemptReuse = reuse;
}
@Override
public boolean isRepeatable() {
return false;
}
@Override
public InputStream getContent() throws IOException {
return new EofSensorInputStream(wrappedEntity.getContent(), this);
}
private void ensureConsumed() throws IOException {
if (managedConn == null)
return;
try {
if (attemptReuse) {
// this will not trigger a callback from EofSensorInputStream
EntityUtils.consume(wrappedEntity);
managedConn.markReusable();
}
} finally {
releaseManagedConnection();
}
}
@Deprecated
@Override
public void consumeContent() throws IOException {
ensureConsumed();
}
@Override
public void writeTo(final OutputStream outstream) throws IOException {
super.writeTo(outstream);
ensureConsumed();
}
public void releaseConnection() throws IOException {
ensureConsumed();
}
public void abortConnection() throws IOException {
if (managedConn != null) {
try {
managedConn.abortConnection();
} finally {
managedConn = null;
}
}
}
public boolean eofDetected(InputStream wrapped) throws IOException {
try {
if (attemptReuse && (managedConn != null)) {
// there may be some cleanup required, such as
// reading trailers after the response body:
wrapped.close();
managedConn.markReusable();
}
} finally {
releaseManagedConnection();
}
return false;
}
public boolean streamClosed(InputStream wrapped) throws IOException {
try {
if (attemptReuse && (managedConn != null)) {
// this assumes that closing the stream will
// consume the remainder of the response body:
wrapped.close();
managedConn.markReusable();
}
} finally {
releaseManagedConnection();
}
return false;
}
public boolean streamAbort(InputStream wrapped) throws IOException {
if (managedConn != null) {
managedConn.abortConnection();
}
return false;
}
/**
* Releases the connection gracefully.
* The connection attribute will be nullified.
* Subsequent invocations are no-ops.
*
* @throws IOException in case of an IO problem.
* The connection attribute will be nullified anyway.
*/
protected void releaseManagedConnection()
throws IOException {
if (managedConn != null) {
try {
managedConn.releaseConnection();
} finally {
managedConn = null;
}
}
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/BasicManagedEntity.java
|
Java
|
gpl3
| 5,870
|
/*
* ====================================================================
* 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.ogt.http.conn;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import javax.net.ssl.SSLSession;
import org.apache.ogt.http.HttpClientConnection;
import org.apache.ogt.http.HttpHost;
import org.apache.ogt.http.conn.routing.HttpRoute;
import org.apache.ogt.http.params.HttpParams;
import org.apache.ogt.http.protocol.HttpContext;
/**
* A client-side connection with advanced connection logic.
* Instances are typically obtained from a connection manager.
*
* @since 4.0
*/
public interface ManagedClientConnection extends
HttpClientConnection, HttpRoutedConnection, ConnectionReleaseTrigger {
/**
* 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.
*
* @return <code>true</code> if this connection is secure,
* <code>false</code> otherwise
*/
boolean isSecure();
/**
* Obtains the current route of this connection.
*
* @return the route established so far, or
* <code>null</code> if not connected
*/
HttpRoute getRoute();
/**
* Obtains the SSL session of the underlying connection, if any.
* If this connection is open, and the underlying socket is an
* {@link javax.net.ssl.SSLSocket SSLSocket}, the SSL session of
* that socket is obtained. This is a potentially blocking operation.
* <br/>
* <b>Note:</b> Whether the underlying socket is an SSL socket
* can not necessarily be determined via {@link #isSecure}.
* Plain sockets may be considered secure, for example if they are
* connected to a known host in the same network segment.
* On the other hand, SSL sockets may be considered insecure,
* for example depending on the chosen cipher suite.
*
* @return the underlying SSL session if available,
* <code>null</code> otherwise
*/
SSLSession getSSLSession();
/**
* Opens this connection according to the given route.
*
* @param route the route along which to open. It will be opened to
* the first proxy if present, or directly to the target.
* @param context the context for opening this connection
* @param params the parameters for opening this connection
*
* @throws IOException in case of a problem
*/
void open(HttpRoute route, HttpContext context, HttpParams params)
throws IOException;
/**
* Indicates that a tunnel to the target has been established.
* The route is the one previously passed to {@link #open open}.
* Subsequently, {@link #layerProtocol layerProtocol} can be called
* to layer the TLS/SSL protocol on top of the tunnelled connection.
* <br/>
* <b>Note:</b> In HttpClient 3, a call to the corresponding method
* would automatically trigger the layering of the TLS/SSL protocol.
* This is not the case anymore, you can establish a tunnel without
* layering a new protocol over the connection.
*
* @param secure <code>true</code> if the tunnel should be considered
* secure, <code>false</code> otherwise
* @param params the parameters for tunnelling this connection
*
* @throws IOException in case of a problem
*/
void tunnelTarget(boolean secure, HttpParams params)
throws IOException;
/**
* Indicates that a tunnel to an intermediate proxy has been established.
* This is used exclusively for so-called <i>proxy chains</i>, where
* a request has to pass through multiple proxies before reaching the
* target. In that case, all proxies but the last need to be tunnelled
* when establishing the connection. Tunnelling of the last proxy to the
* target is optional and would be indicated via {@link #tunnelTarget}.
*
* @param next the proxy to which the tunnel was established.
* This is <i>not</i> the proxy <i>through</i> which
* the tunnel was established, but the new end point
* of the tunnel. The tunnel does <i>not</i> yet
* reach to the target, use {@link #tunnelTarget}
* to indicate an end-to-end tunnel.
* @param secure <code>true</code> if the connection should be
* considered secure, <code>false</code> otherwise
* @param params the parameters for tunnelling this connection
*
* @throws IOException in case of a problem
*/
void tunnelProxy(HttpHost next, boolean secure, HttpParams params)
throws IOException;
/**
* Layers a new protocol on top of a {@link #tunnelTarget tunnelled}
* connection. This is typically used to create a TLS/SSL connection
* through a proxy.
* The route is the one previously passed to {@link #open open}.
* It is not guaranteed that the layered connection is
* {@link #isSecure secure}.
*
* @param context the context for layering on top of this connection
* @param params the parameters for layering on top of this connection
*
* @throws IOException in case of a problem
*/
void layerProtocol(HttpContext context, HttpParams params)
throws IOException;
/**
* Marks this connection as being in a reusable communication state.
* The checkpoints for reuseable communication states (in the absence
* of pipelining) are before sending a request and after receiving
* the response in its entirety.
* The connection will automatically clear the checkpoint when
* used for communication. A call to this method indicates that
* the next checkpoint has been reached.
* <br/>
* A reusable communication state is necessary but not sufficient
* for the connection to be reused.
* A {@link #getRoute route} mismatch, the connection being closed,
* or other circumstances might prevent reuse.
*/
void markReusable();
/**
* Marks this connection as not being in a reusable state.
* This can be used immediately before releasing this connection
* to prevent its reuse. Reasons for preventing reuse include
* error conditions and the evaluation of a
* {@link org.apache.ogt.http.ConnectionReuseStrategy reuse strategy}.
* <br/>
* <b>Note:</b>
* It is <i>not</i> necessary to call here before writing to
* or reading from this connection. Communication attempts will
* automatically unmark the state as non-reusable. It can then
* be switched back using {@link #markReusable markReusable}.
*/
void unmarkReusable();
/**
* Indicates whether this connection is in a reusable communication state.
* See {@link #markReusable markReusable} and
* {@link #unmarkReusable unmarkReusable} for details.
*
* @return <code>true</code> if this connection is marked as being in
* a reusable communication state,
* <code>false</code> otherwise
*/
boolean isMarkedReusable();
/**
* Assigns a state object to this connection. Connection managers may make
* use of the connection state when allocating persistent connections.
*
* @param state The state object
*/
void setState(Object state);
/**
* Returns the state object associated with this connection.
*
* @return The state object
*/
Object getState();
/**
* Sets the duration that this connection can remain idle before it is
* reused. The connection should not be used again if this time elapses. The
* idle duration must be reset after each request sent over this connection.
* The elapsed time starts counting when the connection is released, which
* is typically after the headers (and any response body, if present) is
* fully consumed.
*/
void setIdleDuration(long duration, TimeUnit unit);
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ManagedClientConnection.java
|
Java
|
gpl3
| 9,274
|
<html>
<head>
<!--
/*
* ====================================================================
* 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/>.
*
*/
-->
</head>
<body>
A collection of HTTP connection utility classes.
</body>
</html>
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/util/package.html
|
HTML
|
gpl3
| 1,287
|
/*
* ====================================================================
* 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.ogt.http.conn.util;
import java.util.regex.Pattern;
import org.apache.ogt.http.annotation.Immutable;
/**
* A collection of utilities relating to InetAddresses.
*
* @since 4.0
*/
@Immutable
public class InetAddressUtils {
private InetAddressUtils() {
}
private static final Pattern IPV4_PATTERN =
Pattern.compile(
"^(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)(\\.(25[0-5]|2[0-4]\\d|[0-1]?\\d?\\d)){3}$");
private static final Pattern IPV6_STD_PATTERN =
Pattern.compile(
"^(?:[0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$");
private static final Pattern IPV6_HEX_COMPRESSED_PATTERN =
Pattern.compile(
"^((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)::((?:[0-9A-Fa-f]{1,4}(?::[0-9A-Fa-f]{1,4})*)?)$");
public static boolean isIPv4Address(final String input) {
return IPV4_PATTERN.matcher(input).matches();
}
public static boolean isIPv6StdAddress(final String input) {
return IPV6_STD_PATTERN.matcher(input).matches();
}
public static boolean isIPv6HexCompressedAddress(final String input) {
return IPV6_HEX_COMPRESSED_PATTERN.matcher(input).matches();
}
public static boolean isIPv6Address(final String input) {
return isIPv6StdAddress(input) || isIPv6HexCompressedAddress(input);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/util/InetAddressUtils.java
|
Java
|
gpl3
| 2,541
|
/*
* ====================================================================
*
* 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.ogt.http.conn;
import java.net.ConnectException;
import org.apache.ogt.http.HttpHost;
import org.apache.ogt.http.annotation.Immutable;
/**
* A {@link ConnectException} that specifies the {@link HttpHost} that was
* being connected to.
*
* @since 4.0
*/
@Immutable
public class HttpHostConnectException extends ConnectException {
private static final long serialVersionUID = -3194482710275220224L;
private final HttpHost host;
public HttpHostConnectException(final HttpHost host, final ConnectException cause) {
super("Connection to " + host + " refused");
this.host = host;
initCause(cause);
}
public HttpHost getHost() {
return this.host;
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/HttpHostConnectException.java
|
Java
|
gpl3
| 1,927
|
/*
* ====================================================================
* 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.ogt.http.conn;
import org.apache.ogt.http.annotation.Immutable;
/**
* A timeout while waiting for an available connection
* from a connection manager.
*
*
* @since 4.0
*/
@Immutable
public class ConnectionPoolTimeoutException extends ConnectTimeoutException {
private static final long serialVersionUID = -7898874842020245128L;
/**
* Creates a ConnectTimeoutException with a <tt>null</tt> detail message.
*/
public ConnectionPoolTimeoutException() {
super();
}
/**
* Creates a ConnectTimeoutException with the specified detail message.
*
* @param message The exception detail message
*/
public ConnectionPoolTimeoutException(String message) {
super(message);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ConnectionPoolTimeoutException.java
|
Java
|
gpl3
| 1,953
|
/*
* ====================================================================
* 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.ogt.http.conn;
import javax.net.ssl.SSLSession;
import org.apache.ogt.http.HttpInetConnection;
import org.apache.ogt.http.conn.routing.HttpRoute;
/**
* Interface to access routing information of a client side connection.
*
* @since 4.1
*/
public interface HttpRoutedConnection extends HttpInetConnection {
/**
* 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.
*
* @return <code>true</code> if this connection is secure,
* <code>false</code> otherwise
*/
boolean isSecure();
/**
* Obtains the current route of this connection.
*
* @return the route established so far, or
* <code>null</code> if not connected
*/
HttpRoute getRoute();
/**
* Obtains the SSL session of the underlying connection, if any.
* If this connection is open, and the underlying socket is an
* {@link javax.net.ssl.SSLSocket SSLSocket}, the SSL session of
* that socket is obtained. This is a potentially blocking operation.
* <br/>
* <b>Note:</b> Whether the underlying socket is an SSL socket
* can not necessarily be determined via {@link #isSecure}.
* Plain sockets may be considered secure, for example if they are
* connected to a known host in the same network segment.
* On the other hand, SSL sockets may be considered insecure,
* for example depending on the chosen cipher suite.
*
* @return the underlying SSL session if available,
* <code>null</code> otherwise
*/
SSLSession getSSLSession();
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/HttpRoutedConnection.java
|
Java
|
gpl3
| 2,899
|
/*
* $Revision $
* ====================================================================
*
* 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.ogt.http.conn;
import java.io.InputStream;
import java.io.IOException;
import org.apache.ogt.http.annotation.NotThreadSafe;
/**
* Basic implementation of {@link EofSensorWatcher}. The underlying connection
* is released on close or EOF.
*
* @since 4.0
*/
@NotThreadSafe
public class BasicEofSensorWatcher implements EofSensorWatcher {
/** The connection to auto-release. */
protected final ManagedClientConnection managedConn;
/** Whether to keep the connection alive. */
protected final boolean attemptReuse;
/**
* Creates a new watcher for auto-releasing a connection.
*
* @param conn the connection to auto-release
* @param reuse whether the connection should be re-used
*/
public BasicEofSensorWatcher(ManagedClientConnection conn,
boolean reuse) {
if (conn == null)
throw new IllegalArgumentException
("Connection may not be null.");
managedConn = conn;
attemptReuse = reuse;
}
public boolean eofDetected(InputStream wrapped)
throws IOException {
try {
if (attemptReuse) {
// there may be some cleanup required, such as
// reading trailers after the response body:
wrapped.close();
managedConn.markReusable();
}
} finally {
managedConn.releaseConnection();
}
return false;
}
public boolean streamClosed(InputStream wrapped)
throws IOException {
try {
if (attemptReuse) {
// this assumes that closing the stream will
// consume the remainder of the response body:
wrapped.close();
managedConn.markReusable();
}
} finally {
managedConn.releaseConnection();
}
return false;
}
public boolean streamAbort(InputStream wrapped)
throws IOException {
managedConn.abortConnection();
return false;
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/BasicEofSensorWatcher.java
|
Java
|
gpl3
| 3,318
|
/*
* ====================================================================
* 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.ogt.http.conn;
import java.io.InterruptedIOException;
import org.apache.ogt.http.annotation.Immutable;
/**
* A timeout while connecting to an HTTP server or waiting for an
* available connection from an HttpConnectionManager.
*
*
* @since 4.0
*/
@Immutable
public class ConnectTimeoutException extends InterruptedIOException {
private static final long serialVersionUID = -4816682903149535989L;
/**
* Creates a ConnectTimeoutException with a <tt>null</tt> detail message.
*/
public ConnectTimeoutException() {
super();
}
/**
* Creates a ConnectTimeoutException with the specified detail message.
*
* @param message The exception detail message
*/
public ConnectTimeoutException(final String message) {
super(message);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ConnectTimeoutException.java
|
Java
|
gpl3
| 2,013
|
<html>
<head>
<!--
/*
* ====================================================================
* 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/>.
*
*/
-->
</head>
<body>
{@link org.apache.ogt.http.conn.scheme.Scheme} class represents a protocol
scheme such as "http" or "https" and contains a number of protocol properties
such as the default port and the socket factory to be used to creating
{@link java.net.Socket}s for the given protocol
</body>
</html>
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/scheme/package.html
|
HTML
|
gpl3
| 1,510
|
/*
* ====================================================================
* 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.ogt.http.conn.scheme;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import org.apache.ogt.http.HttpHost;
import org.apache.ogt.http.annotation.ThreadSafe;
/**
* A set of supported protocol {@link Scheme}s.
* Schemes are identified by lowercase names.
*
* @since 4.0
*/
@ThreadSafe
public final class SchemeRegistry {
/** The available schemes in this registry. */
private final ConcurrentHashMap<String,Scheme> registeredSchemes;
/**
* Creates a new, empty scheme registry.
*/
public SchemeRegistry() {
super();
registeredSchemes = new ConcurrentHashMap<String,Scheme>();
}
/**
* Obtains a scheme by name.
*
* @param name the name of the scheme to look up (in lowercase)
*
* @return the scheme, never <code>null</code>
*
* @throws IllegalStateException
* if the scheme with the given name is not registered
*/
public final Scheme getScheme(String name) {
Scheme found = get(name);
if (found == null) {
throw new IllegalStateException
("Scheme '"+name+"' not registered.");
}
return found;
}
/**
* Obtains the scheme for a host.
* Convenience method for <code>getScheme(host.getSchemeName())</pre>
*
* @param host the host for which to obtain the scheme
*
* @return the scheme for the given host, never <code>null</code>
*
* @throws IllegalStateException
* if a scheme with the respective name is not registered
*/
public final Scheme getScheme(HttpHost host) {
if (host == null) {
throw new IllegalArgumentException("Host must not be null.");
}
return getScheme(host.getSchemeName());
}
/**
* Obtains a scheme by name, if registered.
*
* @param name the name of the scheme to look up (in lowercase)
*
* @return the scheme, or
* <code>null</code> if there is none by this name
*/
public final Scheme get(String name) {
if (name == null)
throw new IllegalArgumentException("Name must not be null.");
// leave it to the caller to use the correct name - all lowercase
//name = name.toLowerCase();
Scheme found = registeredSchemes.get(name);
return found;
}
/**
* Registers a scheme.
* The scheme can later be retrieved by its name
* using {@link #getScheme(String) getScheme} or {@link #get get}.
*
* @param sch the scheme to register
*
* @return the scheme previously registered with that name, or
* <code>null</code> if none was registered
*/
public final Scheme register(Scheme sch) {
if (sch == null)
throw new IllegalArgumentException("Scheme must not be null.");
Scheme old = registeredSchemes.put(sch.getName(), sch);
return old;
}
/**
* Unregisters a scheme.
*
* @param name the name of the scheme to unregister (in lowercase)
*
* @return the unregistered scheme, or
* <code>null</code> if there was none
*/
public final Scheme unregister(String name) {
if (name == null)
throw new IllegalArgumentException("Name must not be null.");
// leave it to the caller to use the correct name - all lowercase
//name = name.toLowerCase();
Scheme gone = registeredSchemes.remove(name);
return gone;
}
/**
* Obtains the names of the registered schemes.
*
* @return List containing registered scheme names.
*/
public final List<String> getSchemeNames() {
return new ArrayList<String>(registeredSchemes.keySet());
}
/**
* Populates the internal collection of registered {@link Scheme protocol schemes}
* with the content of the map passed as a parameter.
*
* @param map protocol schemes
*/
public void setItems(final Map<String, Scheme> map) {
if (map == null) {
return;
}
registeredSchemes.clear();
registeredSchemes.putAll(map);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/scheme/SchemeRegistry.java
|
Java
|
gpl3
| 5,475
|
/*
* ====================================================================
* 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.ogt.http.conn.scheme;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import org.apache.ogt.http.conn.ConnectTimeoutException;
import org.apache.ogt.http.params.HttpParams;
/**
* A factory for creating, initializing and connecting sockets.
* The factory encapsulates the logic for establishing a socket connection.
*
* @since 4.0
*
* @deprecated use {@link SchemeSocketFactory}
*/
@Deprecated
public interface SocketFactory {
/**
* Creates a new, unconnected socket.
* The socket should subsequently be passed to
* {@link #connectSocket connectSocket}.
*
* @return a new socket
*
* @throws IOException if an I/O error occurs while creating the socket
*/
Socket createSocket()
throws IOException;
/**
* Connects a socket to the given host.
*
* @param sock the socket to connect, as obtained from
* {@link #createSocket createSocket}.
* <code>null</code> indicates that a new socket
* should be created and connected.
* @param host the host to connect to
* @param port the port to connect to on the host
* @param localAddress the local address to bind the socket to, or
* <code>null</code> for any
* @param localPort the port on the local machine,
* 0 or a negative number for any
* @param params additional {@link HttpParams parameters} for connecting
*
* @return the connected socket. The returned object may be different
* from the <code>sock</code> argument if this factory supports
* a layered protocol.
*
* @throws IOException if an I/O error occurs
* @throws UnknownHostException if the IP address of the target host
* can not be determined
* @throws ConnectTimeoutException if the socket cannot be connected
* within the time limit defined in the <code>params</code>
*/
Socket connectSocket(
Socket sock,
String host,
int port,
InetAddress localAddress,
int localPort,
HttpParams params
) throws IOException, UnknownHostException, ConnectTimeoutException;
/**
* Checks whether a socket provides a secure connection.
* The socket must be {@link #connectSocket connected}
* by this factory.
* The factory will <i>not</i> perform I/O operations
* in this method.
* <br/>
* As a rule of thumb, plain sockets are not secure and
* TLS/SSL sockets are secure. However, there may be
* application specific deviations. For example, a plain
* socket to a host in the same intranet ("trusted zone")
* could be considered secure. On the other hand, a
* TLS/SSL socket could be considered insecure based on
* the cipher suite chosen for the connection.
*
* @param sock the connected socket to check
*
* @return <code>true</code> if the connection of the socket
* should be considered secure, or
* <code>false</code> if it should not
*
* @throws IllegalArgumentException
* if the argument is invalid, for example because it is
* not a connected socket or was created by a different
* socket factory.
* Note that socket factories are <i>not</i> required to
* check these conditions, they may simply return a default
* value when called with an invalid socket argument.
*/
boolean isSecure(Socket sock)
throws IllegalArgumentException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/scheme/SocketFactory.java
|
Java
|
gpl3
| 4,880
|
/*
* ====================================================================
* 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.ogt.http.conn.scheme;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import org.apache.ogt.http.conn.ConnectTimeoutException;
import org.apache.ogt.http.params.HttpParams;
@Deprecated
class SchemeSocketFactoryAdaptor implements SchemeSocketFactory {
private final SocketFactory factory;
SchemeSocketFactoryAdaptor(final SocketFactory factory) {
super();
this.factory = factory;
}
public Socket connectSocket(
final Socket sock,
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
String host = remoteAddress.getHostName();
int port = remoteAddress.getPort();
InetAddress local = null;
int localPort = 0;
if (localAddress != null) {
local = localAddress.getAddress();
localPort = localAddress.getPort();
}
return this.factory.connectSocket(sock, host, port, local, localPort, params);
}
public Socket createSocket(final HttpParams params) throws IOException {
return this.factory.createSocket();
}
public boolean isSecure(final Socket sock) throws IllegalArgumentException {
return this.factory.isSecure(sock);
}
public SocketFactory getFactory() {
return this.factory;
}
@Override
public boolean equals(final Object obj) {
if (obj == null) return false;
if (this == obj) return true;
if (obj instanceof SchemeSocketFactoryAdaptor) {
return this.factory.equals(((SchemeSocketFactoryAdaptor)obj).factory);
} else {
return this.factory.equals(obj);
}
}
@Override
public int hashCode() {
return this.factory.hashCode();
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/scheme/SchemeSocketFactoryAdaptor.java
|
Java
|
gpl3
| 3,169
|
/*
* ====================================================================
* 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.ogt.http.conn.scheme;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
@Deprecated
class LayeredSchemeSocketFactoryAdaptor extends SchemeSocketFactoryAdaptor
implements LayeredSchemeSocketFactory {
private final LayeredSocketFactory factory;
LayeredSchemeSocketFactoryAdaptor(final LayeredSocketFactory factory) {
super(factory);
this.factory = factory;
}
public Socket createLayeredSocket(
final Socket socket,
final String target, int port,
boolean autoClose) throws IOException, UnknownHostException {
return this.factory.createSocket(socket, target, port, autoClose);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/scheme/LayeredSchemeSocketFactoryAdaptor.java
|
Java
|
gpl3
| 1,911
|
/*
* ====================================================================
* 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.ogt.http.conn.scheme;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
@Deprecated
class LayeredSocketFactoryAdaptor extends SocketFactoryAdaptor implements LayeredSocketFactory {
private final LayeredSchemeSocketFactory factory;
LayeredSocketFactoryAdaptor(final LayeredSchemeSocketFactory factory) {
super(factory);
this.factory = factory;
}
public Socket createSocket(
final Socket socket,
final String host, int port, boolean autoClose) throws IOException, UnknownHostException {
return this.factory.createLayeredSocket(socket, host, port, autoClose);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/scheme/LayeredSocketFactoryAdaptor.java
|
Java
|
gpl3
| 1,879
|
/*
* ====================================================================
* 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.ogt.http.conn.scheme;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import org.apache.ogt.http.annotation.Immutable;
import org.apache.ogt.http.conn.ConnectTimeoutException;
import org.apache.ogt.http.params.HttpConnectionParams;
import org.apache.ogt.http.params.HttpParams;
/**
* The default class for creating plain (unencrypted) sockets.
* <p>
* The following parameters can be used to customize the behavior of this
* class:
* <ul>
* <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#CONNECTION_TIMEOUT}</li>
* <li>{@link org.apache.ogt.http.params.CoreConnectionPNames#SO_REUSEADDR}</li>
* </ul>
*
* @since 4.0
*/
@SuppressWarnings("deprecation")
@Immutable
public class PlainSocketFactory implements SocketFactory, SchemeSocketFactory {
private final HostNameResolver nameResolver;
/**
* Gets the default factory.
*
* @return the default factory
*/
public static PlainSocketFactory getSocketFactory() {
return new PlainSocketFactory();
}
@Deprecated
public PlainSocketFactory(final HostNameResolver nameResolver) {
super();
this.nameResolver = nameResolver;
}
public PlainSocketFactory() {
super();
this.nameResolver = null;
}
/**
* @param params Optional parameters. Parameters passed to this method will have no effect.
* This method will create a unconnected instance of {@link Socket} class
* using default constructor.
*
* @since 4.1
*/
public Socket createSocket(final HttpParams params) {
return new Socket();
}
public Socket createSocket() {
return new Socket();
}
/**
* @since 4.1
*/
public Socket connectSocket(
final Socket socket,
final InetSocketAddress remoteAddress,
final InetSocketAddress localAddress,
final HttpParams params) throws IOException, ConnectTimeoutException {
if (remoteAddress == null) {
throw new IllegalArgumentException("Remote address may not be null");
}
if (params == null) {
throw new IllegalArgumentException("HTTP parameters may not be null");
}
Socket sock = socket;
if (sock == null) {
sock = createSocket();
}
if (localAddress != null) {
sock.setReuseAddress(HttpConnectionParams.getSoReuseaddr(params));
sock.bind(localAddress);
}
int connTimeout = HttpConnectionParams.getConnectionTimeout(params);
int soTimeout = HttpConnectionParams.getSoTimeout(params);
try {
sock.setSoTimeout(soTimeout);
sock.connect(remoteAddress, connTimeout);
} catch (SocketTimeoutException ex) {
throw new ConnectTimeoutException("Connect to " + remoteAddress.getHostName() + "/"
+ remoteAddress.getAddress() + " timed out");
}
return sock;
}
/**
* Checks whether a socket connection is secure.
* This factory creates plain socket connections
* which are not considered secure.
*
* @param sock the connected socket
*
* @return <code>false</code>
*
* @throws IllegalArgumentException if the argument is invalid
*/
public final boolean isSecure(Socket sock)
throws IllegalArgumentException {
if (sock == null) {
throw new IllegalArgumentException("Socket may not be null.");
}
// This check is performed last since it calls a method implemented
// by the argument object. getClass() is final in java.lang.Object.
if (sock.isClosed()) {
throw new IllegalArgumentException("Socket is closed.");
}
return false;
}
/**
* @deprecated Use {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}
*/
@Deprecated
public Socket connectSocket(
final Socket socket,
final String host, int port,
final InetAddress localAddress, int localPort,
final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
InetSocketAddress local = null;
if (localAddress != null || localPort > 0) {
// we need to bind explicitly
if (localPort < 0) {
localPort = 0; // indicates "any"
}
local = new InetSocketAddress(localAddress, localPort);
}
InetAddress remoteAddress;
if (this.nameResolver != null) {
remoteAddress = this.nameResolver.resolve(host);
} else {
remoteAddress = InetAddress.getByName(host);
}
InetSocketAddress remote = new InetSocketAddress(remoteAddress, port);
return connectSocket(socket, remote, local, params);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/scheme/PlainSocketFactory.java
|
Java
|
gpl3
| 6,268
|
/*
* ====================================================================
* 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.ogt.http.conn.scheme;
import java.util.Locale;
import org.apache.ogt.http.annotation.Immutable;
import org.apache.ogt.http.util.LangUtils;
/**
* Encapsulates specifics of a protocol scheme such as "http" or "https". Schemes are identified
* by lowercase names. Supported schemes are typically collected in a {@link SchemeRegistry
* SchemeRegistry}.
* <p>
* For example, to configure support for "https://" URLs, you could write code like the following:
* <pre>
* Scheme https = new Scheme("https", 443, new MySecureSocketFactory());
* SchemeRegistry.DEFAULT.register(https);
* </pre>
*
* @since 4.0
*/
@Immutable
public final class Scheme {
/** The name of this scheme, in lowercase. (e.g. http, https) */
private final String name;
/** The socket factory for this scheme */
private final SchemeSocketFactory socketFactory;
/** The default port for this scheme */
private final int defaultPort;
/** Indicates whether this scheme allows for layered connections */
private final boolean layered;
/** A string representation, for {@link #toString toString}. */
private String stringRep;
/*
* This is used to cache the result of the toString() method
* Since the method always generates the same value, there's no
* need to synchronize, and it does not affect immutability.
*/
/**
* Creates a new scheme.
* Whether the created scheme allows for layered connections
* depends on the class of <code>factory</code>.
*
* @param name the scheme name, for example "http".
* The name will be converted to lowercase.
* @param port the default port for this scheme
* @param factory the factory for creating sockets for communication
* with this scheme
*
* @since 4.1
*/
public Scheme(final String name, final int port, final SchemeSocketFactory factory) {
if (name == null) {
throw new IllegalArgumentException("Scheme name may not be null");
}
if ((port <= 0) || (port > 0xffff)) {
throw new IllegalArgumentException("Port is invalid: " + port);
}
if (factory == null) {
throw new IllegalArgumentException("Socket factory may not be null");
}
this.name = name.toLowerCase(Locale.ENGLISH);
this.socketFactory = factory;
this.defaultPort = port;
this.layered = factory instanceof LayeredSchemeSocketFactory;
}
/**
* Creates a new scheme.
* Whether the created scheme allows for layered connections
* depends on the class of <code>factory</code>.
*
* @param name the scheme name, for example "http".
* The name will be converted to lowercase.
* @param factory the factory for creating sockets for communication
* with this scheme
* @param port the default port for this scheme
*
* @deprecated Use {@link #Scheme(String, int, SchemeSocketFactory)}
*/
@Deprecated
public Scheme(final String name,
final SocketFactory factory,
final int port) {
if (name == null) {
throw new IllegalArgumentException
("Scheme name may not be null");
}
if (factory == null) {
throw new IllegalArgumentException
("Socket factory may not be null");
}
if ((port <= 0) || (port > 0xffff)) {
throw new IllegalArgumentException
("Port is invalid: " + port);
}
this.name = name.toLowerCase(Locale.ENGLISH);
if (factory instanceof LayeredSocketFactory) {
this.socketFactory = new LayeredSchemeSocketFactoryAdaptor(
(LayeredSocketFactory) factory);
this.layered = true;
} else {
this.socketFactory = new SchemeSocketFactoryAdaptor(factory);
this.layered = false;
}
this.defaultPort = port;
}
/**
* Obtains the default port.
*
* @return the default port for this scheme
*/
public final int getDefaultPort() {
return defaultPort;
}
/**
* Obtains the socket factory.
* If this scheme is {@link #isLayered layered}, the factory implements
* {@link LayeredSocketFactory LayeredSocketFactory}.
*
* @return the socket factory for this scheme
*
* @deprecated Use {@link #getSchemeSocketFactory()}
*/
@Deprecated
public final SocketFactory getSocketFactory() {
if (this.socketFactory instanceof SchemeSocketFactoryAdaptor) {
return ((SchemeSocketFactoryAdaptor) this.socketFactory).getFactory();
} else {
if (this.layered) {
return new LayeredSocketFactoryAdaptor(
(LayeredSchemeSocketFactory) this.socketFactory);
} else {
return new SocketFactoryAdaptor(this.socketFactory);
}
}
}
/**
* Obtains the socket factory.
* If this scheme is {@link #isLayered layered}, the factory implements
* {@link LayeredSocketFactory LayeredSchemeSocketFactory}.
*
* @return the socket factory for this scheme
*
* @since 4.1
*/
public final SchemeSocketFactory getSchemeSocketFactory() {
return this.socketFactory;
}
/**
* Obtains the scheme name.
*
* @return the name of this scheme, in lowercase
*/
public final String getName() {
return name;
}
/**
* Indicates whether this scheme allows for layered connections.
*
* @return <code>true</code> if layered connections are possible,
* <code>false</code> otherwise
*/
public final boolean isLayered() {
return layered;
}
/**
* Resolves the correct port for this scheme.
* Returns the given port if it is valid, the default port otherwise.
*
* @param port the port to be resolved,
* a negative number to obtain the default port
*
* @return the given port or the defaultPort
*/
public final int resolvePort(int port) {
return port <= 0 ? defaultPort : port;
}
/**
* Return a string representation of this object.
*
* @return a human-readable string description of this scheme
*/
@Override
public final String toString() {
if (stringRep == null) {
StringBuilder buffer = new StringBuilder();
buffer.append(this.name);
buffer.append(':');
buffer.append(Integer.toString(this.defaultPort));
stringRep = buffer.toString();
}
return stringRep;
}
@Override
public final boolean equals(Object obj) {
if (this == obj) return true;
if (obj instanceof Scheme) {
Scheme that = (Scheme) obj;
return this.name.equals(that.name)
&& this.defaultPort == that.defaultPort
&& this.layered == that.layered;
} else {
return false;
}
}
@Override
public int hashCode() {
int hash = LangUtils.HASH_SEED;
hash = LangUtils.hashCode(hash, this.defaultPort);
hash = LangUtils.hashCode(hash, this.name);
hash = LangUtils.hashCode(hash, this.layered);
return hash;
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/scheme/Scheme.java
|
Java
|
gpl3
| 8,702
|
/*
* ====================================================================
* 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.ogt.http.conn.scheme;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
/**
* A {@link SocketFactory SocketFactory} for layered sockets (SSL/TLS).
* See there for things to consider when implementing a socket factory.
*
* @since 4.0
*
* @deprecated use {@link SchemeSocketFactory}
*/
@Deprecated
public interface LayeredSocketFactory extends SocketFactory {
/**
* Returns a socket connected to the given host that is layered over an
* existing socket. Used primarily for creating secure sockets through
* proxies.
*
* @param socket the existing socket
* @param host the host name/IP
* @param port the port on the host
* @param autoClose a flag for closing the underling socket when the created
* socket is closed
*
* @return Socket a new socket
*
* @throws IOException if an I/O error occurs while creating the socket
* @throws UnknownHostException if the IP address of the host cannot be
* determined
*/
Socket createSocket(
Socket socket,
String host,
int port,
boolean autoClose
) throws IOException, UnknownHostException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/scheme/LayeredSocketFactory.java
|
Java
|
gpl3
| 2,408
|
/*
* ====================================================================
* 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.ogt.http.conn.scheme;
import java.io.IOException;
import java.net.InetAddress;
/**
* Hostname to IP address resolver.
*
* @since 4.0
*
* @deprecated Do not use
*/
@Deprecated
public interface HostNameResolver {
/**
* Resolves given hostname to its IP address
*
* @param hostname the hostname.
* @return IP address.
* @throws IOException
*/
InetAddress resolve (String hostname) throws IOException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/scheme/HostNameResolver.java
|
Java
|
gpl3
| 1,652
|
/*
* ====================================================================
* 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.ogt.http.conn.scheme;
import java.io.IOException;
import java.net.InetAddress;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import org.apache.ogt.http.conn.ConnectTimeoutException;
import org.apache.ogt.http.params.BasicHttpParams;
import org.apache.ogt.http.params.HttpParams;
@Deprecated
class SocketFactoryAdaptor implements SocketFactory {
private final SchemeSocketFactory factory;
SocketFactoryAdaptor(final SchemeSocketFactory factory) {
super();
this.factory = factory;
}
public Socket createSocket() throws IOException {
HttpParams params = new BasicHttpParams();
return this.factory.createSocket(params);
}
public Socket connectSocket(
final Socket socket,
final String host, int port,
final InetAddress localAddress, int localPort,
final HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException {
InetSocketAddress local = null;
if (localAddress != null || localPort > 0) {
// we need to bind explicitly
if (localPort < 0) {
localPort = 0; // indicates "any"
}
local = new InetSocketAddress(localAddress, localPort);
}
InetAddress remoteAddress = InetAddress.getByName(host);
InetSocketAddress remote = new InetSocketAddress(remoteAddress, port);
return this.factory.connectSocket(socket, remote, local, params);
}
public boolean isSecure(final Socket socket) throws IllegalArgumentException {
return this.factory.isSecure(socket);
}
public SchemeSocketFactory getFactory() {
return this.factory;
}
@Override
public boolean equals(final Object obj) {
if (obj == null) return false;
if (this == obj) return true;
if (obj instanceof SocketFactoryAdaptor) {
return this.factory.equals(((SocketFactoryAdaptor)obj).factory);
} else {
return this.factory.equals(obj);
}
}
@Override
public int hashCode() {
return this.factory.hashCode();
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/scheme/SocketFactoryAdaptor.java
|
Java
|
gpl3
| 3,391
|
/*
* ====================================================================
* 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.ogt.http.conn.scheme;
import java.io.IOException;
import java.net.Socket;
import java.net.UnknownHostException;
/**
* A {@link SocketFactory SocketFactory} for layered sockets (SSL/TLS).
* See there for things to consider when implementing a socket factory.
*
* @since 4.1
*/
public interface LayeredSchemeSocketFactory extends SchemeSocketFactory {
/**
* Returns a socket connected to the given host that is layered over an
* existing socket. Used primarily for creating secure sockets through
* proxies.
*
* @param socket the existing socket
* @param target the name of the target host.
* @param port the port to connect to on the target host
* @param autoClose a flag for closing the underling socket when the created
* socket is closed
*
* @return Socket a new socket
*
* @throws IOException if an I/O error occurs while creating the socket
* @throws UnknownHostException if the IP address of the host cannot be
* determined
*/
Socket createLayeredSocket(
Socket socket,
String target,
int port,
boolean autoClose
) throws IOException, UnknownHostException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/scheme/LayeredSchemeSocketFactory.java
|
Java
|
gpl3
| 2,410
|
/*
* ====================================================================
* 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.ogt.http.conn.scheme;
import java.io.IOException;
import java.net.InetSocketAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import org.apache.ogt.http.conn.ConnectTimeoutException;
import org.apache.ogt.http.params.HttpParams;
/**
* A factory for creating, initializing and connecting sockets. The factory encapsulates the logic
* for establishing a socket connection.
*
* @since 4.1
*/
public interface SchemeSocketFactory {
/**
* Creates a new, unconnected socket. The socket should subsequently be passed to
* {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}.
*
* @param params Optional {@link HttpParams parameters}. In most cases these parameters
* will not be required and will have no effect, as usually socket
* initialization should take place in the
* {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams)}
* method. However, in rare cases one may want to pass additional parameters
* to this method in order to create a customized {@link Socket} instance,
* for instance bound to a SOCKS proxy server.
*
* @return a new socket
*
* @throws IOException if an I/O error occurs while creating the socket
*/
Socket createSocket(HttpParams params) throws IOException;
/**
* Connects a socket to the target host with the given remote address.
*
* @param sock the socket to connect, as obtained from
* {@link #createSocket(HttpParams) createSocket}.
* <code>null</code> indicates that a new socket
* should be created and connected.
* @param remoteAddress the remote address to connect to
* @param localAddress the local address to bind the socket to, or
* <code>null</code> for any
* @param params additional {@link HttpParams parameters} for connecting
*
* @return the connected socket. The returned object may be different
* from the <code>sock</code> argument if this factory supports
* a layered protocol.
*
* @throws IOException if an I/O error occurs
* @throws UnknownHostException if the IP address of the target host
* can not be determined
* @throws ConnectTimeoutException if the socket cannot be connected
* within the time limit defined in the <code>params</code>
*/
Socket connectSocket(
Socket sock,
InetSocketAddress remoteAddress,
InetSocketAddress localAddress,
HttpParams params) throws IOException, UnknownHostException, ConnectTimeoutException;
/**
* Checks whether a socket provides a secure connection. The socket must be
* {@link #connectSocket(Socket, InetSocketAddress, InetSocketAddress, HttpParams) connected}
* by this factory. The factory will <i>not</i> perform I/O operations in this method.
* <p>
* As a rule of thumb, plain sockets are not secure and TLS/SSL sockets are secure. However,
* there may be application specific deviations. For example, a plain socket to a host in the
* same intranet ("trusted zone") could be considered secure. On the other hand, a TLS/SSL
* socket could be considered insecure based on the cipher suite chosen for the connection.
*
* @param sock the connected socket to check
*
* @return <code>true</code> if the connection of the socket
* should be considered secure, or
* <code>false</code> if it should not
*
* @throws IllegalArgumentException
* if the argument is invalid, for example because it is
* not a connected socket or was created by a different
* socket factory.
* Note that socket factories are <i>not</i> required to
* check these conditions, they may simply return a default
* value when called with an invalid socket argument.
*/
boolean isSecure(Socket sock) throws IllegalArgumentException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/scheme/SchemeSocketFactory.java
|
Java
|
gpl3
| 5,378
|
/*
* ====================================================================
* 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.ogt.http.conn;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import org.apache.ogt.http.HttpHost;
import org.apache.ogt.http.conn.scheme.SchemeSocketFactory;
import org.apache.ogt.http.params.HttpParams;
import org.apache.ogt.http.protocol.HttpContext;
/**
* ClientConnectionOperator represents a strategy for creating
* {@link OperatedClientConnection} instances and updating the underlying
* {@link Socket} of those objects. Implementations will most likely make use
* of {@link SchemeSocketFactory}s to create {@link Socket} instances.
* <p>
* The methods in this interface allow the creation of plain and layered
* sockets. Creating a tunnelled connection through a proxy, however,
* is not within the scope of the operator.
* <p>
* Implementations of this interface must be thread-safe. Access to shared
* data must be synchronized as methods of this interface may be executed
* from multiple threads.
*
* @since 4.0
*/
public interface ClientConnectionOperator {
/**
* Creates a new connection that can be operated.
*
* @return a new, unopened connection for use with this operator
*/
OperatedClientConnection createConnection();
/**
* Opens a connection to the given target host.
*
* @param conn the connection to open
* @param target the target host to connect to
* @param local the local address to route from, or
* <code>null</code> for the default
* @param context the context for the connection
* @param params the parameters for the connection
*
* @throws IOException in case of a problem
*/
void openConnection(OperatedClientConnection conn,
HttpHost target,
InetAddress local,
HttpContext context,
HttpParams params)
throws IOException;
/**
* Updates a connection with a layered secure connection.
* The typical use of this method is to update a tunnelled plain
* connection (HTTP) to a secure TLS/SSL connection (HTTPS).
*
* @param conn the open connection to update
* @param target the target host for the updated connection.
* The connection must already be open or tunnelled
* to the host and port, but the scheme of the target
* will be used to create a layered connection.
* @param context the context for the connection
* @param params the parameters for the updated connection
*
* @throws IOException in case of a problem
*/
void updateSecureConnection(OperatedClientConnection conn,
HttpHost target,
HttpContext context,
HttpParams params)
throws IOException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/ClientConnectionOperator.java
|
Java
|
gpl3
| 4,134
|
/*
* ====================================================================
*
* 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.ogt.http.conn;
import java.io.InputStream;
import java.io.IOException;
import org.apache.ogt.http.annotation.NotThreadSafe;
/**
* A stream wrapper that triggers actions on {@link #close close()} and EOF.
* Primarily used to auto-release an underlying
* {@link ManagedClientConnection connection}
* when the response body is consumed or no longer needed.
* <p>
* This class is based on <code>AutoCloseInputStream</code> in HttpClient 3.1,
* but has notable differences. It does not allow mark/reset, distinguishes
* different kinds of event, and does not always close the underlying stream
* on EOF. That decision is left to the {@link EofSensorWatcher watcher}.
*
* @see EofSensorWatcher
*
* @since 4.0
*/
// don't use FilterInputStream as the base class, we'd have to
// override markSupported(), mark(), and reset() to disable them
@NotThreadSafe
public class EofSensorInputStream extends InputStream implements ConnectionReleaseTrigger {
/**
* The wrapped input stream, while accessible.
* The value changes to <code>null</code> when the wrapped stream
* becomes inaccessible.
*/
protected InputStream wrappedStream;
/**
* Indicates whether this stream itself is closed.
* If it isn't, but {@link #wrappedStream wrappedStream}
* is <code>null</code>, we're running in EOF mode.
* All read operations will indicate EOF without accessing
* the underlying stream. After closing this stream, read
* operations will trigger an {@link IOException IOException}.
*
* @see #isReadAllowed isReadAllowed
*/
private boolean selfClosed;
/** The watcher to be notified, if any. */
private final EofSensorWatcher eofWatcher;
/**
* Creates a new EOF sensor.
* If no watcher is passed, the underlying stream will simply be
* closed when EOF is detected or {@link #close close} is called.
* Otherwise, the watcher decides whether the underlying stream
* should be closed before detaching from it.
*
* @param in the wrapped stream
* @param watcher the watcher for events, or <code>null</code> for
* auto-close behavior without notification
*/
public EofSensorInputStream(final InputStream in,
final EofSensorWatcher watcher) {
if (in == null) {
throw new IllegalArgumentException
("Wrapped stream may not be null.");
}
wrappedStream = in;
selfClosed = false;
eofWatcher = watcher;
}
/**
* Checks whether the underlying stream can be read from.
*
* @return <code>true</code> if the underlying stream is accessible,
* <code>false</code> if this stream is in EOF mode and
* detached from the underlying stream
*
* @throws IOException if this stream is already closed
*/
protected boolean isReadAllowed() throws IOException {
if (selfClosed) {
throw new IOException("Attempted read on closed stream.");
}
return (wrappedStream != null);
}
@Override
public int read() throws IOException {
int l = -1;
if (isReadAllowed()) {
try {
l = wrappedStream.read();
checkEOF(l);
} catch (IOException ex) {
checkAbort();
throw ex;
}
}
return l;
}
@Override
public int read(byte[] b, int off, int len) throws IOException {
int l = -1;
if (isReadAllowed()) {
try {
l = wrappedStream.read(b, off, len);
checkEOF(l);
} catch (IOException ex) {
checkAbort();
throw ex;
}
}
return l;
}
@Override
public int read(byte[] b) throws IOException {
int l = -1;
if (isReadAllowed()) {
try {
l = wrappedStream.read(b);
checkEOF(l);
} catch (IOException ex) {
checkAbort();
throw ex;
}
}
return l;
}
@Override
public int available() throws IOException {
int a = 0; // not -1
if (isReadAllowed()) {
try {
a = wrappedStream.available();
// no checkEOF() here, available() can't trigger EOF
} catch (IOException ex) {
checkAbort();
throw ex;
}
}
return a;
}
@Override
public void close() throws IOException {
// tolerate multiple calls to close()
selfClosed = true;
checkClose();
}
/**
* Detects EOF and notifies the watcher.
* This method should only be called while the underlying stream is
* still accessible. Use {@link #isReadAllowed isReadAllowed} to
* check that condition.
* <br/>
* If EOF is detected, the watcher will be notified and this stream
* is detached from the underlying stream. This prevents multiple
* notifications from this stream.
*
* @param eof the result of the calling read operation.
* A negative value indicates that EOF is reached.
*
* @throws IOException
* in case of an IO problem on closing the underlying stream
*/
protected void checkEOF(int eof) throws IOException {
if ((wrappedStream != null) && (eof < 0)) {
try {
boolean scws = true; // should close wrapped stream?
if (eofWatcher != null)
scws = eofWatcher.eofDetected(wrappedStream);
if (scws)
wrappedStream.close();
} finally {
wrappedStream = null;
}
}
}
/**
* Detects stream close and notifies the watcher.
* There's not much to detect since this is called by {@link #close close}.
* The watcher will only be notified if this stream is closed
* for the first time and before EOF has been detected.
* This stream will be detached from the underlying stream to prevent
* multiple notifications to the watcher.
*
* @throws IOException
* in case of an IO problem on closing the underlying stream
*/
protected void checkClose() throws IOException {
if (wrappedStream != null) {
try {
boolean scws = true; // should close wrapped stream?
if (eofWatcher != null)
scws = eofWatcher.streamClosed(wrappedStream);
if (scws)
wrappedStream.close();
} finally {
wrappedStream = null;
}
}
}
/**
* Detects stream abort and notifies the watcher.
* There's not much to detect since this is called by
* {@link #abortConnection abortConnection}.
* The watcher will only be notified if this stream is aborted
* for the first time and before EOF has been detected or the
* stream has been {@link #close closed} gracefully.
* This stream will be detached from the underlying stream to prevent
* multiple notifications to the watcher.
*
* @throws IOException
* in case of an IO problem on closing the underlying stream
*/
protected void checkAbort() throws IOException {
if (wrappedStream != null) {
try {
boolean scws = true; // should close wrapped stream?
if (eofWatcher != null)
scws = eofWatcher.streamAbort(wrappedStream);
if (scws)
wrappedStream.close();
} finally {
wrappedStream = null;
}
}
}
/**
* Same as {@link #close close()}.
*/
public void releaseConnection() throws IOException {
close();
}
/**
* Aborts this stream.
* This is a special version of {@link #close close()} which prevents
* re-use of the underlying connection, if any. Calling this method
* indicates that there should be no attempt to read until the end of
* the stream.
*/
public void abortConnection() throws IOException {
// tolerate multiple calls
selfClosed = true;
checkAbort();
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient/src/main/java/org/apache/ogt/http/conn/EofSensorInputStream.java
|
Java
|
gpl3
| 9,687
|
/*
====================================================================
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/>.
====================================================================
Based on the CSS file for the Spring Reference Documentation.
*/
body {
text-align: justify;
margin-right: 2em;
margin-left: 2em;
}
a:active {
color: #003399;
}
a:visited {
color: #888888;
}
p {
font-family: Verdana, Arial, sans-serif;
}
dt {
font-family: Verdana, Arial, sans-serif;
font-size: 12px;
}
p, dl, dt, dd, blockquote {
color: #000000;
margin-bottom: 3px;
margin-top: 3px;
padding-top: 0px;
}
ol, ul, p {
margin-top: 6px;
margin-bottom: 6px;
}
p, blockquote {
font-size: 90%;
}
p.releaseinfo {
font-size: 100%;
font-weight: bold;
font-family: Verdana, Arial, helvetica, sans-serif;
padding-top: 10px;
}
p.pubdate {
font-size: 120%;
font-weight: bold;
font-family: Verdana, Arial, helvetica, sans-serif;
}
td {
font-size: 80%;
}
td, th, span {
color: #000000;
}
blockquote {
margin-right: 0px;
}
h1, h2, h3, h4, h6, H6 {
color: #000000;
font-weight: 500;
margin-top: 0px;
padding-top: 14px;
font-family: Verdana, Arial, helvetica, sans-serif;
margin-bottom: 0px;
}
h2.title {
font-weight: 800;
margin-bottom: 8px;
}
h2.subtitle {
font-weight: 800;
margin-bottom: 20px;
}
.firstname, .surname {
font-size: 12px;
font-family: Verdana, Arial, helvetica, sans-serif;
}
table {
border-collapse: collapse;
border-spacing: 0;
border: 1px black;
empty-cells: hide;
margin: 10px 0px 30px 50px;
width: 90%;
}
div.table {
margin: 30px 0px 30px 0px;
border: 1px dashed gray;
padding: 10px;
}
div .table-contents table {
border: 1px solid black;
}
div.table > p.title {
padding-left: 10px;
}
td {
padding: 4pt;
font-family: Verdana, Arial, helvetica, sans-serif;
}
div.warning TD {
text-align: justify;
}
h1 {
font-size: 150%;
}
h2 {
font-size: 110%;
}
h3 {
font-size: 100%;
font-weight: bold;
}
h4 {
font-size: 90%;
font-weight: bold;
}
h5 {
font-size: 90%;
font-style: italic;
}
h6 {
font-size: 100%;
font-style: italic;
}
tt {
font-size: 110%;
font-family: "Courier New", Courier, monospace;
color: #000000;
}
.navheader, .navfooter {
border: none;
}
pre {
font-size: 110%;
padding: 5px;
border-style: solid;
border-width: 1px;
border-color: #CCCCCC;
background-color: #f3f5e9;
}
ul, ol, li {
list-style: disc;
}
hr {
width: 100%;
height: 1px;
background-color: #CCCCCC;
border-width: 0px;
padding: 0px;
}
.variablelist {
padding-top: 10px;
padding-bottom: 10px;
margin: 0;
}
.term {
font-weight: bold;
}
.mediaobject {
padding-top: 30px;
padding-bottom: 30px;
}
.legalnotice {
font-family: Verdana, Arial, helvetica, sans-serif;
font-size: 12px;
font-style: italic;
}
.sidebar {
float: right;
margin: 10px 0px 10px 30px;
padding: 10px 20px 20px 20px;
width: 33%;
border: 1px solid black;
background-color: #F4F4F4;
font-size: 14px;
}
.property {
font-family: "Courier New", Courier, monospace;
}
a code {
font-family: Verdana, Arial, monospace;
font-size: 12px;
}
td code {
font-size: 110%;
}
div.note * td,
div.tip * td,
div.warning * td,
div.calloutlist * td {
text-align: justify;
font-size: 100%;
}
.programlisting .interfacename,
.programlisting .literal,
.programlisting .classname {
font-size: 95%;
}
.title .interfacename,
.title .literal,
.title .classname {
font-size: 130%;
}
.programlisting * .lineannotation,
.programlisting * .lineannotation * {
color: blue;
}
.bannerLeft, .bannerRight {
font-size: xx-large;
font-weight: bold;
}
.bannerLeft img, .bannerRight img {
margin: 0px;
}
.bannerLeft img {
float:left;
text-shadow: #7CFC00;
}
.bannerRight img {
float:right;
text-shadow: #7CFC00;
}
.banner {
padding: 0px;
}
.banner img {
border: none;
}
.clear {
clear:both;
visibility: hidden;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/src/docbkx/resources/css/hc-tutorial.css
|
CSS
|
gpl3
| 5,273
|
<?xml version="1.0" encoding="utf-8"?>
<!--
====================================================================
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 />.
====================================================================
Based on the XSL HTML configuration file for the Spring
Reference Documentation.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
<xsl:import href="urn:docbkx:stylesheet"/>
<!--###################################################
HTML Settings
################################################### -->
<xsl:param name="chunk.section.depth">'5'</xsl:param>
<xsl:param name="use.id.as.filename">'1'</xsl:param>
<!-- These extensions are required for table printing and other stuff -->
<xsl:param name="use.extensions">1</xsl:param>
<xsl:param name="tablecolumns.extension">0</xsl:param>
<xsl:param name="callout.extensions">1</xsl:param>
<xsl:param name="graphicsize.extension">0</xsl:param>
<!--###################################################
Table Of Contents
################################################### -->
<!-- Generate the TOCs for named components only -->
<xsl:param name="generate.toc">
book toc
</xsl:param>
<!-- Show only Sections up to level 3 in the TOCs -->
<xsl:param name="toc.section.depth">3</xsl:param>
<!--###################################################
Labels
################################################### -->
<!-- Label Chapters and Sections (numbering) -->
<xsl:param name="chapter.autolabel">1</xsl:param>
<xsl:param name="section.autolabel" select="1"/>
<xsl:param name="section.label.includes.component.label" select="1"/>
<!--###################################################
Callouts
################################################### -->
<!-- Place callout marks at this column in annotated areas -->
<xsl:param name="callout.graphics">1</xsl:param>
<xsl:param name="callout.defaultcolumn">90</xsl:param>
<!--###################################################
Misc
################################################### -->
<!-- Placement of titles -->
<xsl:param name="formal.title.placement">
figure after
example before
equation before
table before
procedure before
</xsl:param>
<xsl:template match="author" mode="titlepage.mode">
<xsl:if test="name(preceding-sibling::*[1]) = 'author'">
<xsl:text>, </xsl:text>
</xsl:if>
<span class="{name(.)}">
<xsl:call-template name="person.name"/>
<xsl:apply-templates mode="titlepage.mode" select="./contrib"/>
<xsl:apply-templates mode="titlepage.mode" select="./affiliation"/>
</span>
</xsl:template>
<xsl:template match="authorgroup" mode="titlepage.mode">
<div class="{name(.)}">
<h2>Authors</h2>
<p/>
<xsl:apply-templates mode="titlepage.mode"/>
</div>
</xsl:template>
<!--###################################################
Headers and Footers
################################################### -->
<xsl:template name="user.header.navigation">
<div class="banner">
<a class="bannerLeft" href="http://www.apache.org/"
title="Apache Software Foundation">
<img style="border:none;" src="images/asf_logo_wide.gif"/>
</a>
<a class="bannerRight" href="http://hc.apache.org/httpcomponents-client-ga/"
title="Apache HttpComponents Client">
<img style="border:none;" src="images/hc_logo.png"/>
</a>
<div class="clear"/>
</div>
</xsl:template>
</xsl:stylesheet>
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/src/docbkx/resources/xsl/html_chunk.xsl
|
XSLT
|
gpl3
| 5,083
|
<?xml version="1.0" encoding="utf-8"?>
<!--
====================================================================
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 />.
====================================================================
Based on the XSL HTML configuration file for the Spring
Reference Documentation.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
<xsl:import href="urn:docbkx:stylesheet"/>
<!--###################################################
HTML Settings
################################################### -->
<xsl:param name="html.stylesheet">html.css</xsl:param>
<!-- These extensions are required for table printing and other stuff -->
<xsl:param name="use.extensions">1</xsl:param>
<xsl:param name="tablecolumns.extension">0</xsl:param>
<xsl:param name="callout.extensions">1</xsl:param>
<xsl:param name="graphicsize.extension">0</xsl:param>
<!--###################################################
Table Of Contents
################################################### -->
<!-- Generate the TOCs for named components only -->
<xsl:param name="generate.toc">
book toc
</xsl:param>
<!-- Show only Sections up to level 3 in the TOCs -->
<xsl:param name="toc.section.depth">3</xsl:param>
<!--###################################################
Labels
################################################### -->
<!-- Label Chapters and Sections (numbering) -->
<xsl:param name="chapter.autolabel">1</xsl:param>
<xsl:param name="section.autolabel" select="1"/>
<xsl:param name="section.label.includes.component.label" select="1"/>
<!--###################################################
Callouts
################################################### -->
<!-- Use images for callouts instead of (1) (2) (3) -->
<xsl:param name="callout.graphics">0</xsl:param>
<!-- Place callout marks at this column in annotated areas -->
<xsl:param name="callout.defaultcolumn">90</xsl:param>
<!--###################################################
Admonitions
################################################### -->
<!-- Use nice graphics for admonitions -->
<xsl:param name="admon.graphics">0</xsl:param>
<!--###################################################
Misc
################################################### -->
<!-- Placement of titles -->
<xsl:param name="formal.title.placement">
figure after
example before
equation before
table before
procedure before
</xsl:param>
<xsl:template match="author" mode="titlepage.mode">
<xsl:if test="name(preceding-sibling::*[1]) = 'author'">
<xsl:text>, </xsl:text>
</xsl:if>
<span class="{name(.)}">
<xsl:call-template name="person.name"/>
<xsl:apply-templates mode="titlepage.mode" select="./contrib"/>
<xsl:apply-templates mode="titlepage.mode" select="./affiliation"/>
</span>
</xsl:template>
<xsl:template match="authorgroup" mode="titlepage.mode">
<div class="{name(.)}">
<h2>Authors</h2>
<p/>
<xsl:apply-templates mode="titlepage.mode"/>
</div>
</xsl:template>
</xsl:stylesheet>
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/src/docbkx/resources/xsl/html.xsl
|
XSLT
|
gpl3
| 4,600
|
<?xml version="1.0" encoding="utf-8"?>
<!--
====================================================================
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 />.
====================================================================
Based on XSL FO (PDF) stylesheet for the Spring reference
documentation.
Thanks are due to Christian Bauer of the Hibernate project
team for writing the original stylesheet upon which this one
is based.
-->
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
xmlns:fo="http://www.w3.org/1999/XSL/Format"
version="1.0">
<xsl:import href="urn:docbkx:stylesheet"/>
<!-- Prevent blank pages in output -->
<xsl:template name="book.titlepage.before.verso">
</xsl:template>
<xsl:template name="book.titlepage.verso">
</xsl:template>
<xsl:template name="book.titlepage.separator">
</xsl:template>
<!--###################################################
Header
################################################### -->
<!-- More space in the center header for long text -->
<xsl:attribute-set name="header.content.properties">
<xsl:attribute name="font-family">
<xsl:value-of select="$body.font.family"/>
</xsl:attribute>
<xsl:attribute name="margin-left">-5em</xsl:attribute>
<xsl:attribute name="margin-right">-5em</xsl:attribute>
</xsl:attribute-set>
<!--###################################################
Custom Footer
################################################### -->
<xsl:template name="footer.content">
<xsl:param name="pageclass" select="''"/>
<xsl:param name="sequence" select="''"/>
<xsl:param name="position" select="''"/>
<xsl:param name="gentext-key" select="''"/>
<xsl:variable name="Version">
<xsl:if test="//releaseinfo">
<xsl:text>HttpClient (</xsl:text>
<xsl:value-of select="//releaseinfo"/>
<xsl:text>)</xsl:text>
</xsl:if>
</xsl:variable>
<xsl:choose>
<xsl:when test="$sequence='blank'">
<xsl:if test="$position = 'center'">
<xsl:value-of select="$Version"/>
</xsl:if>
</xsl:when>
<!-- for double sided printing, print page numbers on alternating sides (of the page) -->
<xsl:when test="$double.sided != 0">
<xsl:choose>
<xsl:when test="$sequence = 'even' and $position='left'">
<fo:page-number/>
</xsl:when>
<xsl:when test="$sequence = 'odd' and $position='right'">
<fo:page-number/>
</xsl:when>
<xsl:when test="$position='center'">
<xsl:value-of select="$Version"/>
</xsl:when>
</xsl:choose>
</xsl:when>
<!-- for single sided printing, print all page numbers on the right (of the page) -->
<xsl:when test="$double.sided = 0">
<xsl:choose>
<xsl:when test="$position='center'">
<xsl:value-of select="$Version"/>
</xsl:when>
<xsl:when test="$position='right'">
<fo:page-number/>
</xsl:when>
</xsl:choose>
</xsl:when>
</xsl:choose>
</xsl:template>
<!--###################################################
Table Of Contents
################################################### -->
<!-- Generate the TOCs for named components only -->
<xsl:param name="generate.toc">
book toc
</xsl:param>
<!-- Show only Sections up to level 3 in the TOCs -->
<xsl:param name="toc.section.depth">2</xsl:param>
<!-- Show titles in bookmarks pane -->
<xsl:param name="fop1.extensions">1</xsl:param>
<!-- Dot and Whitespace as separator in TOC between Label and Title-->
<xsl:param name="autotoc.label.separator" select="'. '"/>
<!--###################################################
Paper & Page Size
################################################### -->
<!-- Paper type, no headers on blank pages, no double sided printing -->
<xsl:param name="paper.type" select="'A4'"/>
<xsl:param name="double.sided">0</xsl:param>
<xsl:param name="headers.on.blank.pages">0</xsl:param>
<xsl:param name="footers.on.blank.pages">0</xsl:param>
<!-- Space between paper border and content (chaotic stuff, don't touch) -->
<xsl:param name="page.margin.top">5mm</xsl:param>
<xsl:param name="region.before.extent">10mm</xsl:param>
<xsl:param name="body.margin.top">10mm</xsl:param>
<xsl:param name="body.margin.bottom">15mm</xsl:param>
<xsl:param name="region.after.extent">10mm</xsl:param>
<xsl:param name="page.margin.bottom">0mm</xsl:param>
<xsl:param name="page.margin.outer">18mm</xsl:param>
<xsl:param name="page.margin.inner">18mm</xsl:param>
<!-- No intendation of Titles -->
<xsl:param name="title.margin.left">0pc</xsl:param>
<!--###################################################
Fonts & Styles
################################################### -->
<!-- Left aligned text and no hyphenation -->
<xsl:param name="alignment">justify</xsl:param>
<xsl:param name="hyphenate">false</xsl:param>
<!-- Default Font size -->
<xsl:param name="body.font.master">11</xsl:param>
<xsl:param name="body.font.small">8</xsl:param>
<!-- Line height in body text -->
<xsl:param name="line-height">1.4</xsl:param>
<!-- Monospaced fonts are smaller than regular text -->
<xsl:attribute-set name="monospace.properties">
<xsl:attribute name="font-family">
<xsl:value-of select="$monospace.font.family"/>
</xsl:attribute>
<xsl:attribute name="font-size">0.8em</xsl:attribute>
</xsl:attribute-set>
<!--###################################################
Tables
################################################### -->
<!-- The table width should be adapted to the paper size -->
<xsl:param name="default.table.width">17.4cm</xsl:param>
<!-- Some padding inside tables -->
<xsl:attribute-set name="table.cell.padding">
<xsl:attribute name="padding-left">4pt</xsl:attribute>
<xsl:attribute name="padding-right">4pt</xsl:attribute>
<xsl:attribute name="padding-top">4pt</xsl:attribute>
<xsl:attribute name="padding-bottom">4pt</xsl:attribute>
</xsl:attribute-set>
<!-- Only hairlines as frame and cell borders in tables -->
<xsl:param name="table.frame.border.thickness">0.1pt</xsl:param>
<xsl:param name="table.cell.border.thickness">0.1pt</xsl:param>
<!--###################################################
Labels
################################################### -->
<!-- Label Chapters and Sections (numbering) -->
<xsl:param name="chapter.autolabel">1</xsl:param>
<xsl:param name="section.autolabel" select="1"/>
<xsl:param name="section.label.includes.component.label" select="1"/>
<!--###################################################
Titles
################################################### -->
<!-- Chapter title size -->
<xsl:attribute-set name="chapter.titlepage.recto.style">
<xsl:attribute name="text-align">left</xsl:attribute>
<xsl:attribute name="font-weight">bold</xsl:attribute>
<xsl:attribute name="font-size">
<xsl:value-of select="$body.font.master * 1.8"/>
<xsl:text>pt</xsl:text>
</xsl:attribute>
</xsl:attribute-set>
<!-- Why is the font-size for chapters hardcoded in the XSL FO templates?
Let's remove it, so this sucker can use our attribute-set only... -->
<xsl:template match="title" mode="chapter.titlepage.recto.auto.mode">
<fo:block xmlns:fo="http://www.w3.org/1999/XSL/Format"
xsl:use-attribute-sets="chapter.titlepage.recto.style">
<xsl:call-template name="component.title">
<xsl:with-param name="node" select="ancestor-or-self::chapter[1]"/>
</xsl:call-template>
</fo:block>
</xsl:template>
<!-- Sections 1, 2 and 3 titles have a small bump factor and padding -->
<xsl:attribute-set name="section.title.level1.properties">
<xsl:attribute name="space-before.optimum">0.8em</xsl:attribute>
<xsl:attribute name="space-before.minimum">0.8em</xsl:attribute>
<xsl:attribute name="space-before.maximum">0.8em</xsl:attribute>
<xsl:attribute name="font-size">
<xsl:value-of select="$body.font.master * 1.5"/>
<xsl:text>pt</xsl:text>
</xsl:attribute>
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="section.title.level2.properties">
<xsl:attribute name="space-before.optimum">0.6em</xsl:attribute>
<xsl:attribute name="space-before.minimum">0.6em</xsl:attribute>
<xsl:attribute name="space-before.maximum">0.6em</xsl:attribute>
<xsl:attribute name="font-size">
<xsl:value-of select="$body.font.master * 1.25"/>
<xsl:text>pt</xsl:text>
</xsl:attribute>
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="section.title.level3.properties">
<xsl:attribute name="space-before.optimum">0.4em</xsl:attribute>
<xsl:attribute name="space-before.minimum">0.4em</xsl:attribute>
<xsl:attribute name="space-before.maximum">0.4em</xsl:attribute>
<xsl:attribute name="font-size">
<xsl:value-of select="$body.font.master * 1.0"/>
<xsl:text>pt</xsl:text>
</xsl:attribute>
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
</xsl:attribute-set>
<!-- Titles of formal objects (tables, examples, ...) -->
<xsl:attribute-set name="formal.title.properties" use-attribute-sets="normal.para.spacing">
<xsl:attribute name="font-weight">bold</xsl:attribute>
<xsl:attribute name="font-size">
<xsl:value-of select="$body.font.master"/>
<xsl:text>pt</xsl:text>
</xsl:attribute>
<xsl:attribute name="hyphenate">false</xsl:attribute>
<xsl:attribute name="space-after.minimum">0.4em</xsl:attribute>
<xsl:attribute name="space-after.optimum">0.6em</xsl:attribute>
<xsl:attribute name="space-after.maximum">0.8em</xsl:attribute>
</xsl:attribute-set>
<!--###################################################
Programlistings
################################################### -->
<!-- Verbatim text formatting (programlistings) -->
<xsl:attribute-set name="monospace.verbatim.properties">
<xsl:attribute name="font-size">
<xsl:value-of select="$body.font.small * 1.0"/>
<xsl:text>pt</xsl:text>
</xsl:attribute>
</xsl:attribute-set>
<xsl:attribute-set name="verbatim.properties">
<xsl:attribute name="space-before.minimum">1em</xsl:attribute>
<xsl:attribute name="space-before.optimum">1em</xsl:attribute>
<xsl:attribute name="space-before.maximum">1em</xsl:attribute>
<xsl:attribute name="border-color">#444444</xsl:attribute>
<xsl:attribute name="border-style">solid</xsl:attribute>
<xsl:attribute name="border-width">0.1pt</xsl:attribute>
<xsl:attribute name="padding-top">0.5em</xsl:attribute>
<xsl:attribute name="padding-left">0.5em</xsl:attribute>
<xsl:attribute name="padding-right">0.5em</xsl:attribute>
<xsl:attribute name="padding-bottom">0.5em</xsl:attribute>
<xsl:attribute name="margin-left">0.5em</xsl:attribute>
<xsl:attribute name="margin-right">0.5em</xsl:attribute>
</xsl:attribute-set>
<!-- Shade (background) programlistings -->
<xsl:param name="shade.verbatim">1</xsl:param>
<xsl:attribute-set name="shade.verbatim.style">
<xsl:attribute name="background-color">#F0F0F0</xsl:attribute>
</xsl:attribute-set>
<!--###################################################
Callouts
################################################### -->
<!-- Use images for callouts instead of (1) (2) (3) -->
<xsl:param name="callout.graphics">0</xsl:param>
<xsl:param name="callout.unicode">1</xsl:param>
<!-- Place callout marks at this column in annotated areas -->
<xsl:param name="callout.defaultcolumn">90</xsl:param>
<!--###################################################
Admonitions
################################################### -->
<!-- Use nice graphics for admonitions -->
<xsl:param name="admon.graphics">'1'</xsl:param>
<!-- <xsl:param name="admon.graphics.path">&admon_gfx_path;</xsl:param> -->
<!--###################################################
Misc
################################################### -->
<!-- Placement of titles -->
<xsl:param name="formal.title.placement">
figure after
example before
equation before
table before
procedure before
</xsl:param>
<!-- Format Variable Lists as Blocks (prevents horizontal overflow) -->
<xsl:param name="variablelist.as.blocks">1</xsl:param>
<!-- The horrible list spacing problems -->
<xsl:attribute-set name="list.block.spacing">
<xsl:attribute name="space-before.optimum">0.8em</xsl:attribute>
<xsl:attribute name="space-before.minimum">0.8em</xsl:attribute>
<xsl:attribute name="space-before.maximum">0.8em</xsl:attribute>
<xsl:attribute name="space-after.optimum">0.1em</xsl:attribute>
<xsl:attribute name="space-after.minimum">0.1em</xsl:attribute>
<xsl:attribute name="space-after.maximum">0.1em</xsl:attribute>
</xsl:attribute-set>
<!--###################################################
colored and hyphenated links
################################################### -->
<xsl:template match="ulink">
<fo:basic-link external-destination="{@url}"
xsl:use-attribute-sets="xref.properties"
text-decoration="underline"
color="blue">
<xsl:choose>
<xsl:when test="count(child::node())=0">
<xsl:value-of select="@url"/>
</xsl:when>
<xsl:otherwise>
<xsl:apply-templates/>
</xsl:otherwise>
</xsl:choose>
</fo:basic-link>
</xsl:template>
</xsl:stylesheet>
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/src/docbkx/resources/xsl/fopdf.xsl
|
XSLT
|
gpl3
| 16,606
|
@import url("../../css/hc-maven.css");
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/src/site/resources/css/site.css
|
CSS
|
gpl3
| 39
|
#====================================================================
# 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/>.
#
import os
import re
import tempfile
import shutil
ignore_pattern = re.compile('^(.svn|target|bin|classes)')
java_pattern = re.compile('^.*\.java')
annot_pattern = re.compile('import org\.apache\.http\.annotation\.')
def process_dir(dir):
files = os.listdir(dir)
for file in files:
f = os.path.join(dir, file)
if os.path.isdir(f):
if not ignore_pattern.match(file):
process_dir(f)
else:
if java_pattern.match(file):
process_source(f)
def process_source(filename):
tmp = tempfile.mkstemp()
tmpfd = tmp[0]
tmpfile = tmp[1]
try:
changed = False
dst = os.fdopen(tmpfd, 'w')
try:
src = open(filename)
try:
for line in src:
if annot_pattern.match(line):
changed = True
line = line.replace('import org.apache.http.annotation.', 'import net.jcip.annotations.')
dst.write(line)
finally:
src.close()
finally:
dst.close();
if changed:
shutil.move(tmpfile, filename)
else:
os.remove(tmpfile)
except:
os.remove(tmpfile)
process_dir('.')
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/jcip-annotations.py
|
Python
|
gpl3
| 2,485
|
@import url("../../../css/hc-maven.css");
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/site/resources/css/site.css
|
CSS
|
gpl3
| 42
|
/*
* ====================================================================
*
* 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.ogt.http.examples.entity.mime;
import java.io.File;
import org.apache.ogt.http.HttpEntity;
import org.apache.ogt.http.HttpResponse;
import org.apache.ogt.http.client.HttpClient;
import org.apache.ogt.http.client.methods.HttpPost;
import org.apache.ogt.http.entity.mime.MultipartEntity;
import org.apache.ogt.http.entity.mime.content.FileBody;
import org.apache.ogt.http.entity.mime.content.StringBody;
import org.apache.ogt.http.impl.client.DefaultHttpClient;
import org.apache.ogt.http.util.EntityUtils;
/**
* Example how to use multipart/form encoded POST request.
*/
public class ClientMultipartFormPost {
public static void main(String[] args) throws Exception {
if (args.length != 1) {
System.out.println("File path not given");
System.exit(1);
}
HttpClient httpclient = new DefaultHttpClient();
try {
HttpPost httppost = new HttpPost("http://localhost:8080" +
"/servlets-examples/servlet/RequestInfoExample");
FileBody bin = new FileBody(new File(args[0]));
StringBody comment = new StringBody("A binary file of some kind");
MultipartEntity reqEntity = new MultipartEntity();
reqEntity.addPart("bin", bin);
reqEntity.addPart("comment", comment);
httppost.setEntity(reqEntity);
System.out.println("executing request " + httppost.getRequestLine());
HttpResponse response = httpclient.execute(httppost);
HttpEntity resEntity = response.getEntity();
System.out.println("----------------------------------------");
System.out.println(response.getStatusLine());
if (resEntity != null) {
System.out.println("Response content length: " + resEntity.getContentLength());
}
EntityUtils.consume(resEntity);
} finally {
try { httpclient.getConnectionManager().shutdown(); } catch (Exception ignore) {}
}
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/examples/org/apache/http/examples/entity/mime/ClientMultipartFormPost.java
|
Java
|
gpl3
| 3,240
|
/*
* ====================================================================
* 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.ogt.http.entity.mime;
import org.apache.ogt.http.entity.mime.content.ContentBody;
/**
* FormBodyPart class represents a content body that can be used as a part of multipart encoded
* entities. This class automatically populates the header with standard fields based on
* the content description of the enclosed body.
*
* @since 4.0
*/
public class FormBodyPart {
private final String name;
private final Header header;
private final ContentBody body;
public FormBodyPart(final String name, final ContentBody body) {
super();
if (name == null) {
throw new IllegalArgumentException("Name may not be null");
}
if (body == null) {
throw new IllegalArgumentException("Body may not be null");
}
this.name = name;
this.body = body;
this.header = new Header();
generateContentDisp(body);
generateContentType(body);
generateTransferEncoding(body);
}
public String getName() {
return this.name;
}
public ContentBody getBody() {
return this.body;
}
public Header getHeader() {
return this.header;
}
public void addField(final String name, final String value) {
if (name == null) {
throw new IllegalArgumentException("Field name may not be null");
}
this.header.addField(new MinimalField(name, value));
}
protected void generateContentDisp(final ContentBody body) {
StringBuilder buffer = new StringBuilder();
buffer.append("form-data; name=\"");
buffer.append(getName());
buffer.append("\"");
if (body.getFilename() != null) {
buffer.append("; filename=\"");
buffer.append(body.getFilename());
buffer.append("\"");
}
addField(MIME.CONTENT_DISPOSITION, buffer.toString());
}
protected void generateContentType(final ContentBody body) {
StringBuilder buffer = new StringBuilder();
buffer.append(body.getMimeType()); // MimeType cannot be null
if (body.getCharset() != null) { // charset may legitimately be null
buffer.append("; charset=");
buffer.append(body.getCharset());
}
addField(MIME.CONTENT_TYPE, buffer.toString());
}
protected void generateTransferEncoding(final ContentBody body) {
addField(MIME.CONTENT_TRANSFER_ENC, body.getTransferEncoding()); // TE cannot be null
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/FormBodyPart.java
|
Java
|
gpl3
| 3,706
|
/*
* ====================================================================
* 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.ogt.http.entity.mime;
/**
*
* @since 4.0
*/
public enum HttpMultipartMode {
/** RFC 822, RFC 2045, RFC 2046 compliant */
STRICT,
/** browser-compatible mode, i.e. only write Content-Disposition; use content charset */
BROWSER_COMPATIBLE
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/HttpMultipartMode.java
|
Java
|
gpl3
| 1,465
|
<html>
<head>
<!--
/*
* ====================================================================
* 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/>.
*
*/
-->
</head>
<body>
Support for MIME multipart encoded entities
</body>
</html>
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/package.html
|
HTML
|
gpl3
| 1,282
|
/*
* ====================================================================
* 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.ogt.http.entity.mime;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.nio.ByteBuffer;
import java.nio.CharBuffer;
import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
import org.apache.ogt.http.entity.mime.content.ContentBody;
import org.apache.ogt.http.util.ByteArrayBuffer;
/**
* HttpMultipart represents a collection of MIME multipart encoded content bodies. This class is
* capable of operating either in the strict (RFC 822, RFC 2045, RFC 2046 compliant) or
* the browser compatible modes.
*
* @since 4.0
*/
public class HttpMultipart {
private static ByteArrayBuffer encode(
final Charset charset, final String string) {
ByteBuffer encoded = charset.encode(CharBuffer.wrap(string));
ByteArrayBuffer bab = new ByteArrayBuffer(encoded.remaining());
bab.append(encoded.array(), encoded.position(), encoded.remaining());
return bab;
}
private static void writeBytes(
final ByteArrayBuffer b, final OutputStream out) throws IOException {
out.write(b.buffer(), 0, b.length());
}
private static void writeBytes(
final String s, final Charset charset, final OutputStream out) throws IOException {
ByteArrayBuffer b = encode(charset, s);
writeBytes(b, out);
}
private static void writeBytes(
final String s, final OutputStream out) throws IOException {
ByteArrayBuffer b = encode(MIME.DEFAULT_CHARSET, s);
writeBytes(b, out);
}
private static void writeField(
final MinimalField field, final OutputStream out) throws IOException {
writeBytes(field.getName(), out);
writeBytes(FIELD_SEP, out);
writeBytes(field.getBody(), out);
writeBytes(CR_LF, out);
}
private static void writeField(
final MinimalField field, final Charset charset, final OutputStream out) throws IOException {
writeBytes(field.getName(), charset, out);
writeBytes(FIELD_SEP, out);
writeBytes(field.getBody(), charset, out);
writeBytes(CR_LF, out);
}
private static final ByteArrayBuffer FIELD_SEP = encode(MIME.DEFAULT_CHARSET, ": ");
private static final ByteArrayBuffer CR_LF = encode(MIME.DEFAULT_CHARSET, "\r\n");
private static final ByteArrayBuffer TWO_DASHES = encode(MIME.DEFAULT_CHARSET, "--");
private final String subType;
private final Charset charset;
private final String boundary;
private final List<FormBodyPart> parts;
private final HttpMultipartMode mode;
/**
* Creates an instance with the specified settings.
*
* @param subType mime subtype - must not be {@code null}
* @param charset the character set to use. May be {@code null}, in which case {@link MIME#DEFAULT_CHARSET} - i.e. US-ASCII - is used.
* @param boundary to use - must not be {@code null}
* @param mode the mode to use
* @throws IllegalArgumentException if charset is null or boundary is null
*/
public HttpMultipart(final String subType, final Charset charset, final String boundary, HttpMultipartMode mode) {
super();
if (subType == null) {
throw new IllegalArgumentException("Multipart subtype may not be null");
}
if (boundary == null) {
throw new IllegalArgumentException("Multipart boundary may not be null");
}
this.subType = subType;
this.charset = charset != null ? charset : MIME.DEFAULT_CHARSET;
this.boundary = boundary;
this.parts = new ArrayList<FormBodyPart>();
this.mode = mode;
}
/**
* Creates an instance with the specified settings.
* Mode is set to {@link HttpMultipartMode#STRICT}
*
* @param subType mime subtype - must not be {@code null}
* @param charset the character set to use. May be {@code null}, in which case {@link MIME#DEFAULT_CHARSET} - i.e. US-ASCII - is used.
* @param boundary to use - must not be {@code null}
* @throws IllegalArgumentException if charset is null or boundary is null
*/
public HttpMultipart(final String subType, final Charset charset, final String boundary) {
this(subType, charset, boundary, HttpMultipartMode.STRICT);
}
public HttpMultipart(final String subType, final String boundary) {
this(subType, null, boundary);
}
public String getSubType() {
return this.subType;
}
public Charset getCharset() {
return this.charset;
}
public HttpMultipartMode getMode() {
return this.mode;
}
public List<FormBodyPart> getBodyParts() {
return this.parts;
}
public void addBodyPart(final FormBodyPart part) {
if (part == null) {
return;
}
this.parts.add(part);
}
public String getBoundary() {
return this.boundary;
}
private void doWriteTo(
final HttpMultipartMode mode,
final OutputStream out,
boolean writeContent) throws IOException {
ByteArrayBuffer boundary = encode(this.charset, getBoundary());
for (FormBodyPart part: this.parts) {
writeBytes(TWO_DASHES, out);
writeBytes(boundary, out);
writeBytes(CR_LF, out);
Header header = part.getHeader();
switch (mode) {
case STRICT:
for (MinimalField field: header) {
writeField(field, out);
}
break;
case BROWSER_COMPATIBLE:
// Only write Content-Disposition
// Use content charset
MinimalField cd = part.getHeader().getField(MIME.CONTENT_DISPOSITION);
writeField(cd, this.charset, out);
String filename = part.getBody().getFilename();
if (filename != null) {
MinimalField ct = part.getHeader().getField(MIME.CONTENT_TYPE);
writeField(ct, this.charset, out);
}
break;
}
writeBytes(CR_LF, out);
if (writeContent) {
part.getBody().writeTo(out);
}
writeBytes(CR_LF, out);
}
writeBytes(TWO_DASHES, out);
writeBytes(boundary, out);
writeBytes(TWO_DASHES, out);
writeBytes(CR_LF, out);
}
/**
* Writes out the content in the multipart/form encoding. This method
* produces slightly different formatting depending on its compatibility
* mode.
*
* @see #getMode()
*/
public void writeTo(final OutputStream out) throws IOException {
doWriteTo(this.mode, out, true);
}
/**
* Determines the total length of the multipart content (content length of
* individual parts plus that of extra elements required to delimit the parts
* from one another). If any of the @{link BodyPart}s contained in this object
* is of a streaming entity of unknown length the total length is also unknown.
* <p/>
* This method buffers only a small amount of data in order to determine the
* total length of the entire entity. The content of individual parts is not
* buffered.
*
* @return total length of the multipart entity if known, <code>-1</code>
* otherwise.
*/
public long getTotalLength() {
long contentLen = 0;
for (FormBodyPart part: this.parts) {
ContentBody body = part.getBody();
long len = body.getContentLength();
if (len >= 0) {
contentLen += len;
} else {
return -1;
}
}
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
doWriteTo(this.mode, out, false);
byte[] extra = out.toByteArray();
return contentLen + extra.length;
} catch (IOException ex) {
// Should never happen
return -1;
}
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/HttpMultipart.java
|
Java
|
gpl3
| 9,326
|
<html>
<head>
<!--
/*
* ====================================================================
* 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/>.
*
*/
-->
</head>
<body>
MIME Multipart content body parts.
</body>
</html>
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/content/package.html
|
HTML
|
gpl3
| 1,273
|
/*
* ====================================================================
* 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.ogt.http.entity.mime.content;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.Reader;
import java.io.UnsupportedEncodingException;
import java.nio.charset.Charset;
import org.apache.ogt.http.entity.mime.MIME;
/**
*
* @since 4.0
*/
public class StringBody extends AbstractContentBody {
private final byte[] content;
private final Charset charset;
/**
* @since 4.1
*/
public static StringBody create(
final String text,
final String mimeType,
final Charset charset) throws IllegalArgumentException {
try {
return new StringBody(text, mimeType, charset);
} catch (UnsupportedEncodingException ex) {
throw new IllegalArgumentException("Charset " + charset + " is not supported", ex);
}
}
/**
* @since 4.1
*/
public static StringBody create(
final String text, final Charset charset) throws IllegalArgumentException {
return create(text, null, charset);
}
/**
* @since 4.1
*/
public static StringBody create(final String text) throws IllegalArgumentException {
return create(text, null, null);
}
/**
* Create a StringBody from the specified text, mime type and character set.
*
* @param text to be used for the body, not {@code null}
* @param mimeType the mime type, not {@code null}
* @param charset the character set, may be {@code null}, in which case the US-ASCII charset is used
* @throws UnsupportedEncodingException
* @throws IllegalArgumentException if the {@code text} parameter is null
*/
public StringBody(
final String text,
final String mimeType,
Charset charset) throws UnsupportedEncodingException {
super(mimeType);
if (text == null) {
throw new IllegalArgumentException("Text may not be null");
}
if (charset == null) {
charset = Charset.forName("US-ASCII");
}
this.content = text.getBytes(charset.name());
this.charset = charset;
}
/**
* Create a StringBody from the specified text and character set.
* The mime type is set to "text/plain".
*
* @param text to be used for the body, not {@code null}
* @param charset the character set, may be {@code null}, in which case the US-ASCII charset is used
* @throws UnsupportedEncodingException
* @throws IllegalArgumentException if the {@code text} parameter is null
*/
public StringBody(final String text, final Charset charset) throws UnsupportedEncodingException {
this(text, "text/plain", charset);
}
/**
* Create a StringBody from the specified text.
* The mime type is set to "text/plain".
* The hosts default charset is used.
*
* @param text to be used for the body, not {@code null}
* @throws UnsupportedEncodingException
* @throws IllegalArgumentException if the {@code text} parameter is null
*/
public StringBody(final String text) throws UnsupportedEncodingException {
this(text, "text/plain", null);
}
public Reader getReader() {
return new InputStreamReader(
new ByteArrayInputStream(this.content),
this.charset);
}
/**
* @deprecated use {@link #writeTo(OutputStream)}
*/
@Deprecated
public void writeTo(final OutputStream out, int mode) throws IOException {
writeTo(out);
}
public void writeTo(final OutputStream out) throws IOException {
if (out == null) {
throw new IllegalArgumentException("Output stream may not be null");
}
InputStream in = new ByteArrayInputStream(this.content);
byte[] tmp = new byte[4096];
int l;
while ((l = in.read(tmp)) != -1) {
out.write(tmp, 0, l);
}
out.flush();
}
public String getTransferEncoding() {
return MIME.ENC_8BIT;
}
public String getCharset() {
return this.charset.name();
}
public long getContentLength() {
return this.content.length;
}
public String getFilename() {
return null;
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/content/StringBody.java
|
Java
|
gpl3
| 5,566
|
/*
* ====================================================================
* 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.ogt.http.entity.mime.content;
/**
* Represents common content properties.
*/
public interface ContentDescriptor {
/**
* Returns the body descriptors MIME type.
* @see #getMediaType()
* @see #getSubType()
* @return The MIME type, which has been parsed from the
* content-type definition. Must not be null, but
* "text/plain", if no content-type was specified.
*/
String getMimeType();
/**
* Gets the defaulted MIME media type for this content.
* For example <code>TEXT</code>, <code>IMAGE</code>, <code>MULTIPART</code>
* @see #getMimeType()
* @return the MIME media type when content-type specified,
* otherwise the correct default (<code>TEXT</code>)
*/
String getMediaType();
/**
* Gets the defaulted MIME sub type for this content.
* @see #getMimeType()
* @return the MIME media type when content-type is specified,
* otherwise the correct default (<code>PLAIN</code>)
*/
String getSubType();
/**
* <p>The body descriptors character set, defaulted appropriately for the MIME type.</p>
* <p>
* For <code>TEXT</code> types, this will be defaulted to <code>us-ascii</code>.
* For other types, when the charset parameter is missing this property will be null.
* </p>
* @return Character set, which has been parsed from the
* content-type definition. Not null for <code>TEXT</code> types, when unset will
* be set to default <code>us-ascii</code>. For other types, when unset,
* null will be returned.
*/
String getCharset();
/**
* Returns the body descriptors transfer encoding.
* @return The transfer encoding. Must not be null, but "7bit",
* if no transfer-encoding was specified.
*/
String getTransferEncoding();
/**
* Returns the body descriptors content-length.
* @return Content length, if known, or -1, to indicate the absence of a
* content-length header.
*/
long getContentLength();
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/content/ContentDescriptor.java
|
Java
|
gpl3
| 3,249
|
/*
* ====================================================================
* 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.ogt.http.entity.mime.content;
import java.io.IOException;
import java.io.OutputStream;
/**
*
* @since 4.0
*/
public interface ContentBody extends ContentDescriptor {
String getFilename();
void writeTo(OutputStream out) throws IOException;
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/content/ContentBody.java
|
Java
|
gpl3
| 1,461
|
/*
* ====================================================================
* 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.ogt.http.entity.mime.content;
/**
*
* @since 4.0
*/
public abstract class AbstractContentBody implements ContentBody {
private final String mimeType;
private final String mediaType;
private final String subType;
public AbstractContentBody(final String mimeType) {
super();
if (mimeType == null) {
throw new IllegalArgumentException("MIME type may not be null");
}
this.mimeType = mimeType;
int i = mimeType.indexOf('/');
if (i != -1) {
this.mediaType = mimeType.substring(0, i);
this.subType = mimeType.substring(i + 1);
} else {
this.mediaType = mimeType;
this.subType = null;
}
}
public String getMimeType() {
return this.mimeType;
}
public String getMediaType() {
return this.mediaType;
}
public String getSubType() {
return this.subType;
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/content/AbstractContentBody.java
|
Java
|
gpl3
| 2,152
|
/*
* ====================================================================
* 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.ogt.http.entity.mime.content;
import java.io.IOException;
import java.io.OutputStream;
import org.apache.ogt.http.entity.mime.MIME;
import org.apache.ogt.http.entity.mime.content.AbstractContentBody;
/**
* Body part that is built using a byte array containing a file.
*
* @since 4.1
*/
public class ByteArrayBody extends AbstractContentBody {
/**
* The contents of the file contained in this part.
*/
private final byte[] data;
/**
* The name of the file contained in this part.
*/
private final String filename;
/**
* Creates a new ByteArrayBody.
*
* @param data The contents of the file contained in this part.
* @param mimeType The mime type of the file contained in this part.
* @param filename The name of the file contained in this part.
*/
public ByteArrayBody(final byte[] data, final String mimeType, final String filename) {
super(mimeType);
if (data == null) {
throw new IllegalArgumentException("byte[] may not be null");
}
this.data = data;
this.filename = filename;
}
/**
* Creates a new ByteArrayBody.
*
* @param data The contents of the file contained in this part.
* @param filename The name of the file contained in this part.
*/
public ByteArrayBody(final byte[] data, final String filename) {
this(data, "application/octet-stream", filename);
}
public String getFilename() {
return filename;
}
public void writeTo(final OutputStream out) throws IOException {
out.write(data);
}
public String getCharset() {
return null;
}
public String getTransferEncoding() {
return MIME.ENC_BINARY;
}
public long getContentLength() {
return data.length;
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/content/ByteArrayBody.java
|
Java
|
gpl3
| 3,038
|
/*
* ====================================================================
* 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.ogt.http.entity.mime.content;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.ogt.http.entity.mime.MIME;
/**
*
* @since 4.0
*/
public class FileBody extends AbstractContentBody {
private final File file;
private final String filename;
private final String charset;
/**
* @since 4.1
*/
public FileBody(final File file,
final String filename,
final String mimeType,
final String charset) {
super(mimeType);
if (file == null) {
throw new IllegalArgumentException("File may not be null");
}
this.file = file;
if (filename != null)
this.filename = filename;
else
this.filename = file.getName();
this.charset = charset;
}
/**
* @since 4.1
*/
public FileBody(final File file,
final String mimeType,
final String charset) {
this(file, null, mimeType, charset);
}
public FileBody(final File file, final String mimeType) {
this(file, mimeType, null);
}
public FileBody(final File file) {
this(file, "application/octet-stream");
}
public InputStream getInputStream() throws IOException {
return new FileInputStream(this.file);
}
/**
* @deprecated use {@link #writeTo(OutputStream)}
*/
@Deprecated
public void writeTo(final OutputStream out, int mode) throws IOException {
writeTo(out);
}
public void writeTo(final OutputStream out) throws IOException {
if (out == null) {
throw new IllegalArgumentException("Output stream may not be null");
}
InputStream in = new FileInputStream(this.file);
try {
byte[] tmp = new byte[4096];
int l;
while ((l = in.read(tmp)) != -1) {
out.write(tmp, 0, l);
}
out.flush();
} finally {
in.close();
}
}
public String getTransferEncoding() {
return MIME.ENC_BINARY;
}
public String getCharset() {
return charset;
}
public long getContentLength() {
return this.file.length();
}
public String getFilename() {
return filename;
}
public File getFile() {
return this.file;
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/content/FileBody.java
|
Java
|
gpl3
| 3,697
|
/*
* ====================================================================
* 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.ogt.http.entity.mime.content;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import org.apache.ogt.http.entity.mime.MIME;
/**
*
* @since 4.0
*/
public class InputStreamBody extends AbstractContentBody {
private final InputStream in;
private final String filename;
public InputStreamBody(final InputStream in, final String mimeType, final String filename) {
super(mimeType);
if (in == null) {
throw new IllegalArgumentException("Input stream may not be null");
}
this.in = in;
this.filename = filename;
}
public InputStreamBody(final InputStream in, final String filename) {
this(in, "application/octet-stream", filename);
}
public InputStream getInputStream() {
return this.in;
}
/**
* @deprecated use {@link #writeTo(OutputStream)}
*/
@Deprecated
public void writeTo(final OutputStream out, int mode) throws IOException {
writeTo(out);
}
public void writeTo(final OutputStream out) throws IOException {
if (out == null) {
throw new IllegalArgumentException("Output stream may not be null");
}
try {
byte[] tmp = new byte[4096];
int l;
while ((l = this.in.read(tmp)) != -1) {
out.write(tmp, 0, l);
}
out.flush();
} finally {
this.in.close();
}
}
public String getTransferEncoding() {
return MIME.ENC_BINARY;
}
public String getCharset() {
return null;
}
public long getContentLength() {
return -1;
}
public String getFilename() {
return this.filename;
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/content/InputStreamBody.java
|
Java
|
gpl3
| 2,961
|
/*
* ====================================================================
* 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.ogt.http.entity.mime;
/**
* Minimal MIME field.
*
* @since 4.0
*/
public class MinimalField {
private final String name;
private final String value;
MinimalField(final String name, final String value) {
super();
this.name = name;
this.value = value;
}
public String getName() {
return this.name;
}
public String getBody() {
return this.value;
}
@Override
public String toString() {
StringBuilder buffer = new StringBuilder();
buffer.append(this.name);
buffer.append(": ");
buffer.append(this.value);
return buffer.toString();
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/MinimalField.java
|
Java
|
gpl3
| 1,869
|
/*
* ====================================================================
* 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.ogt.http.entity.mime;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Locale;
import java.util.Map;
/**
* The header of an entity (see RFC 2045).
*/
public class Header implements Iterable<MinimalField> {
private final List<MinimalField> fields;
private final Map<String, List<MinimalField>> fieldMap;
public Header() {
super();
this.fields = new LinkedList<MinimalField>();
this.fieldMap = new HashMap<String, List<MinimalField>>();
}
public void addField(final MinimalField field) {
if (field == null) {
return;
}
String key = field.getName().toLowerCase(Locale.US);
List<MinimalField> values = this.fieldMap.get(key);
if (values == null) {
values = new LinkedList<MinimalField>();
this.fieldMap.put(key, values);
}
values.add(field);
this.fields.add(field);
}
public List<MinimalField> getFields() {
return new ArrayList<MinimalField>(this.fields);
}
public MinimalField getField(final String name) {
if (name == null) {
return null;
}
String key = name.toLowerCase(Locale.US);
List<MinimalField> list = this.fieldMap.get(key);
if (list != null && !list.isEmpty()) {
return list.get(0);
}
return null;
}
public List<MinimalField> getFields(final String name) {
if (name == null) {
return null;
}
String key = name.toLowerCase(Locale.US);
List<MinimalField> list = this.fieldMap.get(key);
if (list == null || list.isEmpty()) {
return Collections.emptyList();
} else {
return new ArrayList<MinimalField>(list);
}
}
public int removeFields(final String name) {
if (name == null) {
return 0;
}
String key = name.toLowerCase(Locale.US);
List<MinimalField> removed = fieldMap.remove(key);
if (removed == null || removed.isEmpty()) {
return 0;
}
this.fields.removeAll(removed);
return removed.size();
}
public void setField(final MinimalField field) {
if (field == null) {
return;
}
String key = field.getName().toLowerCase(Locale.US);
List<MinimalField> list = fieldMap.get(key);
if (list == null || list.isEmpty()) {
addField(field);
return;
}
list.clear();
list.add(field);
int firstOccurrence = -1;
int index = 0;
for (Iterator<MinimalField> it = this.fields.iterator(); it.hasNext(); index++) {
MinimalField f = it.next();
if (f.getName().equalsIgnoreCase(field.getName())) {
it.remove();
if (firstOccurrence == -1) {
firstOccurrence = index;
}
}
}
this.fields.add(firstOccurrence, field);
}
public Iterator<MinimalField> iterator() {
return Collections.unmodifiableList(fields).iterator();
}
@Override
public String toString() {
return this.fields.toString();
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/Header.java
|
Java
|
gpl3
| 4,554
|
/*
* ====================================================================
* 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.ogt.http.entity.mime;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.nio.charset.Charset;
import java.util.Random;
import org.apache.ogt.http.Header;
import org.apache.ogt.http.HttpEntity;
import org.apache.ogt.http.entity.mime.content.ContentBody;
import org.apache.ogt.http.message.BasicHeader;
import org.apache.ogt.http.protocol.HTTP;
/**
* Multipart/form coded HTTP entity consisting of multiple body parts.
*
* @since 4.0
*/
public class MultipartEntity implements HttpEntity {
/**
* The pool of ASCII chars to be used for generating a multipart boundary.
*/
private final static char[] MULTIPART_CHARS =
"-_1234567890abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"
.toCharArray();
private final HttpMultipart multipart;
private final Header contentType;
// @GuardedBy("dirty") // we always read dirty before accessing length
private long length;
private volatile boolean dirty; // used to decide whether to recalculate length
/**
* Creates an instance using the specified parameters
* @param mode the mode to use, may be {@code null}, in which case {@link HttpMultipartMode#STRICT} is used
* @param boundary the boundary string, may be {@code null}, in which case {@link #generateBoundary()} is invoked to create the string
* @param charset the character set to use, may be {@code null}, in which case {@link MIME#DEFAULT_CHARSET} - i.e. US-ASCII - is used.
*/
public MultipartEntity(
HttpMultipartMode mode,
String boundary,
Charset charset) {
super();
if (boundary == null) {
boundary = generateBoundary();
}
if (mode == null) {
mode = HttpMultipartMode.STRICT;
}
this.multipart = new HttpMultipart("form-data", charset, boundary, mode);
this.contentType = new BasicHeader(
HTTP.CONTENT_TYPE,
generateContentType(boundary, charset));
this.dirty = true;
}
/**
* Creates an instance using the specified {@link HttpMultipartMode} mode.
* Boundary and charset are set to {@code null}.
* @param mode the desired mode
*/
public MultipartEntity(final HttpMultipartMode mode) {
this(mode, null, null);
}
/**
* Creates an instance using mode {@link HttpMultipartMode#STRICT}
*/
public MultipartEntity() {
this(HttpMultipartMode.STRICT, null, null);
}
protected String generateContentType(
final String boundary,
final Charset charset) {
StringBuilder buffer = new StringBuilder();
buffer.append("multipart/form-data; boundary=");
buffer.append(boundary);
if (charset != null) {
buffer.append("; charset=");
buffer.append(charset.name());
}
return buffer.toString();
}
protected String generateBoundary() {
StringBuilder buffer = new StringBuilder();
Random rand = new Random();
int count = rand.nextInt(11) + 30; // a random size from 30 to 40
for (int i = 0; i < count; i++) {
buffer.append(MULTIPART_CHARS[rand.nextInt(MULTIPART_CHARS.length)]);
}
return buffer.toString();
}
public void addPart(final FormBodyPart bodyPart) {
this.multipart.addBodyPart(bodyPart);
this.dirty = true;
}
public void addPart(final String name, final ContentBody contentBody) {
addPart(new FormBodyPart(name, contentBody));
}
public boolean isRepeatable() {
for (FormBodyPart part: this.multipart.getBodyParts()) {
ContentBody body = part.getBody();
if (body.getContentLength() < 0) {
return false;
}
}
return true;
}
public boolean isChunked() {
return !isRepeatable();
}
public boolean isStreaming() {
return !isRepeatable();
}
public long getContentLength() {
if (this.dirty) {
this.length = this.multipart.getTotalLength();
this.dirty = false;
}
return this.length;
}
public Header getContentType() {
return this.contentType;
}
public Header getContentEncoding() {
return null;
}
public void consumeContent()
throws IOException, UnsupportedOperationException{
if (isStreaming()) {
throw new UnsupportedOperationException(
"Streaming entity does not implement #consumeContent()");
}
}
public InputStream getContent() throws IOException, UnsupportedOperationException {
throw new UnsupportedOperationException(
"Multipart form entity does not implement #getContent()");
}
public void writeTo(final OutputStream outstream) throws IOException {
this.multipart.writeTo(outstream);
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/MultipartEntity.java
|
Java
|
gpl3
| 6,206
|
/*
* ====================================================================
* 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.ogt.http.entity.mime;
import java.nio.charset.Charset;
/**
*
* @since 4.0
*/
public final class MIME {
public static final String CONTENT_TYPE = "Content-Type";
public static final String CONTENT_TRANSFER_ENC = "Content-Transfer-Encoding";
public static final String CONTENT_DISPOSITION = "Content-Disposition";
public static final String ENC_8BIT = "8bit";
public static final String ENC_BINARY = "binary";
/** The default character set to be used, i.e. "US-ASCII" */
public static final Charset DEFAULT_CHARSET = Charset.forName("US-ASCII");
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpmime/src/main/java/org/apache/ogt/http/entity/mime/MIME.java
|
Java
|
gpl3
| 1,828
|
/*
* ====================================================================
*
* 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.client.benchmark;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.HttpMethod;
import org.apache.commons.httpclient.HttpMethodRetryHandler;
import org.apache.commons.httpclient.HttpVersion;
import org.apache.commons.httpclient.MultiThreadedHttpConnectionManager;
import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.commons.httpclient.methods.PostMethod;
import org.apache.commons.httpclient.params.HttpMethodParams;
public class TestHttpClient3 implements TestHttpAgent {
private final MultiThreadedHttpConnectionManager mgr;
private final HttpClient httpclient;
public TestHttpClient3() {
super();
this.mgr = new MultiThreadedHttpConnectionManager();
this.httpclient = new HttpClient(this.mgr);
this.httpclient.getParams().setVersion(
HttpVersion.HTTP_1_1);
this.httpclient.getParams().setBooleanParameter(
HttpMethodParams.USE_EXPECT_CONTINUE, false);
this.httpclient.getHttpConnectionManager().getParams()
.setStaleCheckingEnabled(false);
this.httpclient.getParams().setSoTimeout(15000);
HttpMethodRetryHandler retryhandler = new HttpMethodRetryHandler() {
public boolean retryMethod(final HttpMethod httpmethod, final IOException ex, int count) {
return false;
}
};
this.httpclient.getParams().setParameter(HttpMethodParams.RETRY_HANDLER, retryhandler); }
public void init() {
}
public void shutdown() {
this.mgr.shutdown();
}
Stats execute(final URI target, final byte[] content, int n, int c) throws Exception {
this.mgr.getParams().setMaxTotalConnections(2000);
this.mgr.getParams().setDefaultMaxConnectionsPerHost(c);
Stats stats = new Stats(n, c);
WorkerThread[] workers = new WorkerThread[c];
for (int i = 0; i < workers.length; i++) {
workers[i] = new WorkerThread(stats, target, content);
}
for (int i = 0; i < workers.length; i++) {
workers[i].start();
}
for (int i = 0; i < workers.length; i++) {
workers[i].join();
}
return stats;
}
class WorkerThread extends Thread {
private final Stats stats;
private final URI target;
private final byte[] content;
WorkerThread(final Stats stats, final URI target, final byte[] content) {
super();
this.stats = stats;
this.target = target;
this.content = content;
}
@Override
public void run() {
byte[] buffer = new byte[4096];
while (!this.stats.isComplete()) {
HttpMethod httpmethod;
if (this.content == null) {
GetMethod httpget = new GetMethod(target.toASCIIString());
httpmethod = httpget;
} else {
PostMethod httppost = new PostMethod(target.toASCIIString());
httppost.setRequestEntity(new ByteArrayRequestEntity(content));
httpmethod = httppost;
}
long contentLen = 0;
try {
httpclient.executeMethod(httpmethod);
InputStream instream = httpmethod.getResponseBodyAsStream();
if (instream != null) {
int l = 0;
while ((l = instream.read(buffer)) != -1) {
contentLen += l;
}
}
this.stats.success(contentLen);
} catch (IOException ex) {
this.stats.failure(contentLen);
} finally {
httpmethod.releaseConnection();
}
}
}
}
public Stats get(final URI target, int n, int c) throws Exception {
return execute(target, null, n, c);
}
public Stats post(URI target, byte[] content, int n, int c) throws Exception {
return execute(target, content, n, c);
}
public String getClientName() {
return "Apache HttpClient 3.1";
}
public static void main(String[] args) throws Exception {
if (args.length < 2) {
System.out.println("Usage: <target URI> <no of requests> <concurrent connections>");
System.exit(-1);
}
URI targetURI = new URI(args[0]);
int n = Integer.parseInt(args[1]);
int c = 1;
if (args.length > 2) {
c = Integer.parseInt(args[2]);
}
TestHttpClient3 test = new TestHttpClient3();
test.init();
try {
long startTime = System.currentTimeMillis();
Stats stats = test.get(targetURI, n, c);
long finishTime = System.currentTimeMillis();
Stats.printStats(targetURI, startTime, finishTime, stats);
} finally {
test.shutdown();
}
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/TestHttpClient3.java
|
Java
|
gpl3
| 6,452
|
/*
* ====================================================================
*
* 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.client.benchmark;
import java.net.URI;
public class Stats {
private final int expectedCount;
private final int concurrency;
private int successCount = 0;
private int failureCount = 0;
private long contentLen = 0;
private long totalContentLen = 0;
public Stats(int expectedCount, int concurrency) {
super();
this.expectedCount = expectedCount;
this.concurrency = concurrency;
}
public synchronized boolean isComplete() {
return this.successCount + this.failureCount >= this.expectedCount;
}
public synchronized void success(long contentLen) {
if (isComplete()) return;
this.successCount++;
this.contentLen = contentLen;
this.totalContentLen += contentLen;
notifyAll();
}
public synchronized void failure(long contentLen) {
if (isComplete()) return;
this.failureCount++;
this.contentLen = contentLen;
this.totalContentLen += contentLen;
notifyAll();
}
public int getConcurrency() {
return this.concurrency;
}
public synchronized int getSuccessCount() {
return successCount;
}
public synchronized int getFailureCount() {
return failureCount;
}
public void setFailureCount(int failureCount) {
this.failureCount = failureCount;
}
public synchronized long getContentLen() {
return contentLen;
}
public synchronized long getTotalContentLen() {
return totalContentLen;
}
public synchronized void waitFor() throws InterruptedException {
while (!isComplete()) {
wait();
}
}
public static void printStats(
final URI targetURI, long startTime, long finishTime, final Stats stats) {
float totalTimeSec = (float) (finishTime - startTime) / 1000;
float reqsPerSec = (float) stats.getSuccessCount() / totalTimeSec;
float timePerReqMs = (float) (finishTime - startTime) / (float) stats.getSuccessCount();
System.out.print("Document URI:\t\t");
System.out.println(targetURI);
System.out.print("Document Length:\t");
System.out.print(stats.getContentLen());
System.out.println(" bytes");
System.out.println();
System.out.print("Concurrency level:\t");
System.out.println(stats.getConcurrency());
System.out.print("Time taken for tests:\t");
System.out.print(totalTimeSec);
System.out.println(" seconds");
System.out.print("Complete requests:\t");
System.out.println(stats.getSuccessCount());
System.out.print("Failed requests:\t");
System.out.println(stats.getFailureCount());
System.out.print("Content transferred:\t");
System.out.print(stats.getTotalContentLen());
System.out.println(" bytes");
System.out.print("Requests per second:\t");
System.out.print(reqsPerSec);
System.out.println(" [#/sec] (mean)");
System.out.print("Time per request:\t");
System.out.print(timePerReqMs);
System.out.println(" [ms] (mean)");
}
}
|
zzy157-running
|
OpenGPSTracker/external_sources/httpclient-4.1.1/httpclient-benchmark/src/main/java/org/apache/http/client/benchmark/Stats.java
|
Java
|
gpl3
| 4,374
|