本文整理汇总了Java中org.apache.http.util.Args.check方法的典型用法代码示例。如果您正苦于以下问题:Java Args.check方法的具体用法?Java Args.check怎么用?Java Args.check使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.http.util.Args
的用法示例。
在下文中一共展示了Args.check方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: updateCacheEntry
import org.apache.http.util.Args; //导入方法依赖的package包/类
/**
* Update the entry with the new information from the response. Should only be used for
* 304 responses.
*
* @param requestId
* @param entry The cache Entry to be updated
* @param requestDate When the request was performed
* @param responseDate When the response was gotten
* @param response The HttpResponse from the backend server call
* @return HttpCacheEntry an updated version of the cache entry
* @throws java.io.IOException if something bad happens while trying to read the body from the original entry
*/
public HttpCacheEntry updateCacheEntry(
final String requestId,
final HttpCacheEntry entry,
final Date requestDate,
final Date responseDate,
final HttpResponse response) throws IOException {
Args.check(response.getStatusLine().getStatusCode() == HttpStatus.SC_NOT_MODIFIED,
"Response must have 304 status code");
final Header[] mergedHeaders = mergeHeaders(entry, response);
Resource resource = null;
if (entry.getResource() != null) {
resource = resourceFactory.copy(requestId, entry.getResource());
}
return new HttpCacheEntry(
requestDate,
responseDate,
entry.getStatusLine(),
mergedHeaders,
resource,
entry.getRequestMethod());
}
示例2: HttpRoute
import org.apache.http.util.Args; //导入方法依赖的package包/类
private HttpRoute(final HttpHost target, final InetAddress local, final List<HttpHost> proxies,
final boolean secure, final TunnelType tunnelled, final LayerType layered) {
Args.notNull(target, "Target host");
this.targetHost = normalize(target);
this.localAddress = local;
if (proxies != null && !proxies.isEmpty()) {
this.proxyChain = new ArrayList<HttpHost>(proxies);
} else {
this.proxyChain = null;
}
if (tunnelled == TunnelType.TUNNELLED) {
Args.check(this.proxyChain != null, "Proxy required if tunnelled");
}
this.secure = secure;
this.tunnelled = tunnelled != null ? tunnelled : TunnelType.PLAIN;
this.layered = layered != null ? layered : LayerType.PLAIN;
}
示例3: Scheme
import org.apache.http.util.Args; //导入方法依赖的package包/类
/**
* Creates a new scheme.
* Whether the created scheme allows for layered connections
* depends on the class of {@code factory}.
*
* @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) {
Args.notNull(name, "Scheme name");
Args.check(port > 0 && port <= 0xffff, "Port is invalid");
Args.notNull(factory, "Socket factory");
this.name = name.toLowerCase(Locale.ENGLISH);
this.defaultPort = port;
if (factory instanceof SchemeLayeredSocketFactory) {
this.layered = true;
this.socketFactory = factory;
} else if (factory instanceof LayeredSchemeSocketFactory) {
this.layered = true;
this.socketFactory = new SchemeLayeredSocketFactoryAdaptor2((LayeredSchemeSocketFactory) factory);
} else {
this.layered = false;
this.socketFactory = factory;
}
}
示例4: getReason
import org.apache.http.util.Args; //导入方法依赖的package包/类
/**
* Obtains the reason phrase for a status code.
*
* @param status the status code, in the range 100-599
* @param loc ignored
*
* @return the reason phrase, or <code>null</code>
*/
public String getReason(final int status, final Locale loc) {
Args.check(status >= 100 && status < 600, "Unknown category for status code " + status);
final int category = status / 100;
final int subcode = status - 100*category;
String reason = null;
if (REASON_PHRASES[category].length > subcode) {
reason = REASON_PHRASES[category][subcode];
}
return reason;
}
示例5: getAvailableActions
import org.apache.http.util.Args; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*
* @throws IllegalArgumentException {@inheritDoc}
*/
@Override
public RestRootEntity<TaskActions> getAvailableActions(@Nonnull List<String> tkiids) {
tkiids = Args.notNull(tkiids, "Task ids (tkiids)");
Args.check(!tkiids.isEmpty(), "At least one tkiid must be specified for available actions retrieving");
URI uri = new SafeUriBuilder(rootUri).addPath(ACTIONS)
.addParameter(TASK_ID_LIST, Joiner.on(DEFAULT_SEPARATOR).join(tkiids)).build();
return makeGet(httpClient, httpContext, uri, new TypeToken<RestRootEntity<TaskActions>>() {});
}
示例6: getHopTarget
import org.apache.http.util.Args; //导入方法依赖的package包/类
@Override
public final HttpHost getHopTarget(final int hop) {
Args.notNegative(hop, "Hop index");
final int hopcount = getHopCount();
Args.check(hop < hopcount, "Hop index exceeds tracked route length");
if (hop < hopcount - 1) {
return this.proxyChain.get(hop);
} else {
return this.targetHost;
}
}
示例7: getHopTarget
import org.apache.http.util.Args; //导入方法依赖的package包/类
@Override
public final HttpHost getHopTarget(final int hop) {
Args.notNegative(hop, "Hop index");
final int hopcount = getHopCount();
Args.check(hop < hopcount, "Hop index exceeds tracked route length");
HttpHost result = null;
if (hop < hopcount-1) {
result = this.proxyChain[hop];
} else {
result = this.targetHost;
}
return result;
}
示例8: doSendResponse
import org.apache.http.util.Args; //导入方法依赖的package包/类
@Override
public void doSendResponse(RestResponse response) {
status = response.status().getStatus();
byte[] bytes = response.content().toBytes();
long length = bytes.length;
Args.check(length <= Integer.MAX_VALUE, "HTTP entity too large to be buffered in memory");
if(length < 0) {
length = 4096;
}
InputStream instream = new ByteArrayInputStream(bytes);
InputStreamReader reader = new InputStreamReader(instream, Consts.UTF_8);
CharArrayBuffer buffer = new CharArrayBuffer((int)length);
char[] tmp = new char[1024];
int l;
try {
while ((l = reader.read(tmp)) != -1) {
buffer.append(tmp, 0, l);
}
content = buffer.toString();
} catch (IOException e) {
status = RestStatus.INTERNAL_SERVER_ERROR.getStatus();
content = "IOException: " + e.getMessage();
} finally {
try {
reader.close();
instream.close();
} catch (IOException e1) {
content = "IOException: " + e1.getMessage();
} finally {
count.countDown();
}
}
}
示例9: normalizeSyntax
import org.apache.http.util.Args; //导入方法依赖的package包/类
/**
* Removes dot segments according to RFC 3986, section 5.2.4 and
* Syntax-Based Normalization according to RFC 3986, section 6.2.2.
*
* @param uri the original URI
* @return the URI without dot segments
*/
private static URI normalizeSyntax(final URI uri) {
if (uri.isOpaque() || uri.getAuthority() == null) {
// opaque and file: URIs
return uri;
}
Args.check(uri.isAbsolute(), "Base URI must be absolute");
final String path = uri.getPath() == null ? "" : uri.getPath();
final String[] inputSegments = path.split("/");
final Stack<String> outputSegments = new Stack<String>();
for (final String inputSegment : inputSegments) {
if ((inputSegment.length() == 0)
|| (".".equals(inputSegment))) {
// Do nothing
} else if ("..".equals(inputSegment)) {
if (!outputSegments.isEmpty()) {
outputSegments.pop();
}
} else {
outputSegments.push(inputSegment);
}
}
final StringBuilder outputBuffer = new StringBuilder();
for (final String outputSegment : outputSegments) {
outputBuffer.append('/').append(outputSegment);
}
if (path.lastIndexOf('/') == path.length() - 1) {
// path.endsWith("/") || path.equals("")
outputBuffer.append('/');
}
try {
final String scheme = uri.getScheme().toLowerCase(Locale.ENGLISH);
final String auth = uri.getAuthority().toLowerCase(Locale.ENGLISH);
final URI ref = new URI(scheme, auth, outputBuffer.toString(),
null, null);
if (uri.getQuery() == null && uri.getFragment() == null) {
return ref;
}
final StringBuilder normalized = new StringBuilder(
ref.toASCIIString());
if (uri.getQuery() != null) {
// query string passed through unchanged
normalized.append('?').append(uri.getRawQuery());
}
if (uri.getFragment() != null) {
// fragment passed through unchanged
normalized.append('#').append(uri.getRawFragment());
}
return URI.create(normalized.toString());
} catch (final URISyntaxException e) {
throw new IllegalArgumentException(e);
}
}
示例10: releaseConnection
import org.apache.http.util.Args; //导入方法依赖的package包/类
@Override
public void releaseConnection(
final ManagedClientConnection conn, final long keepalive, final TimeUnit tunit) {
Args.check(conn instanceof ManagedClientConnectionImpl, "Connection class mismatch, " +
"connection not obtained from this manager");
final ManagedClientConnectionImpl managedConn = (ManagedClientConnectionImpl) conn;
Asserts.check(managedConn.getManager() == this, "Connection not obtained from this manager");
synchronized (managedConn) {
final HttpPoolEntry entry = managedConn.detach();
if (entry == null) {
return;
}
try {
if (managedConn.isOpen() && !managedConn.isMarkedReusable()) {
try {
managedConn.shutdown();
} catch (final IOException iox) {
if (this.log.isDebugEnabled()) {
this.log.debug("I/O exception shutting down released connection", iox);
}
}
}
// Only reusable connections can be kept alive
if (managedConn.isMarkedReusable()) {
entry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
if (this.log.isDebugEnabled()) {
final String s;
if (keepalive > 0) {
s = "for " + keepalive + " " + tunit;
} else {
s = "indefinitely";
}
this.log.debug("Connection " + format(entry) + " can be kept alive " + s);
}
}
} finally {
this.pool.release(entry, managedConn.isMarkedReusable());
}
if (this.log.isDebugEnabled()) {
this.log.debug("Connection released: " + format(entry) + formatStats(entry.getRoute()));
}
}
}
示例11: releaseConnection
import org.apache.http.util.Args; //导入方法依赖的package包/类
@Override
public void releaseConnection(final ManagedClientConnection conn, final long keepalive, final TimeUnit tunit) {
Args.check(conn instanceof ManagedClientConnectionImpl, "Connection class mismatch, " +
"connection not obtained from this manager");
final ManagedClientConnectionImpl managedConn = (ManagedClientConnectionImpl) conn;
synchronized (managedConn) {
if (this.log.isDebugEnabled()) {
this.log.debug("Releasing connection " + conn);
}
if (managedConn.getPoolEntry() == null) {
return; // already released
}
final ClientConnectionManager manager = managedConn.getManager();
Asserts.check(manager == this, "Connection not obtained from this manager");
synchronized (this) {
if (this.shutdown) {
shutdownConnection(managedConn);
return;
}
try {
if (managedConn.isOpen() && !managedConn.isMarkedReusable()) {
shutdownConnection(managedConn);
}
if (managedConn.isMarkedReusable()) {
this.poolEntry.updateExpiry(keepalive, tunit != null ? tunit : TimeUnit.MILLISECONDS);
if (this.log.isDebugEnabled()) {
final String s;
if (keepalive > 0) {
s = "for " + keepalive + " " + tunit;
} else {
s = "indefinitely";
}
this.log.debug("Connection can be kept alive " + s);
}
}
} finally {
managedConn.detach();
this.conn = null;
if (this.poolEntry.isClosed()) {
this.poolEntry = null;
}
}
}
}
}
示例12: releaseConnection
import org.apache.http.util.Args; //导入方法依赖的package包/类
@Override
public void releaseConnection(
final ManagedClientConnection conn,
final long validDuration, final TimeUnit timeUnit) {
Args.check(conn instanceof ConnAdapter, "Connection class mismatch, " +
"connection not obtained from this manager");
assertStillUp();
if (log.isDebugEnabled()) {
log.debug("Releasing connection " + conn);
}
final ConnAdapter sca = (ConnAdapter) conn;
synchronized (sca) {
if (sca.poolEntry == null)
{
return; // already released
}
final ClientConnectionManager manager = sca.getManager();
Asserts.check(manager == this, "Connection not obtained from this manager");
try {
// make sure that the response has been read completely
if (sca.isOpen() && (this.alwaysShutDown ||
!sca.isMarkedReusable())
) {
if (log.isDebugEnabled()) {
log.debug
("Released connection open but not reusable.");
}
// make sure this connection will not be re-used
// we might have gotten here because of a shutdown trigger
// shutdown of the adapter also clears the tracked route
sca.shutdown();
}
} catch (final IOException iox) {
if (log.isDebugEnabled()) {
log.debug("Exception shutting down released connection.",
iox);
}
} finally {
sca.detach();
synchronized (this) {
managedConn = null;
lastReleaseTime = System.currentTimeMillis();
if(validDuration > 0) {
connectionExpiresTime = timeUnit.toMillis(validDuration) + lastReleaseTime;
} else {
connectionExpiresTime = Long.MAX_VALUE;
}
}
}
}
}
示例13: releaseConnection
import org.apache.http.util.Args; //导入方法依赖的package包/类
@Override
public void releaseConnection(final ManagedClientConnection conn, final long validDuration, final TimeUnit timeUnit) {
Args.check(conn instanceof BasicPooledConnAdapter, "Connection class mismatch, " +
"connection not obtained from this manager");
final BasicPooledConnAdapter hca = (BasicPooledConnAdapter) conn;
if (hca.getPoolEntry() != null) {
Asserts.check(hca.getManager() == this, "Connection not obtained from this manager");
}
synchronized (hca) {
final BasicPoolEntry entry = (BasicPoolEntry) hca.getPoolEntry();
if (entry == null) {
return;
}
try {
// make sure that the response has been read completely
if (hca.isOpen() && !hca.isMarkedReusable()) {
// In MTHCM, there would be a call to
// SimpleHttpConnectionManager.finishLastResponse(conn);
// Consuming the response is handled outside in 4.0.
// make sure this connection will not be re-used
// Shut down rather than close, we might have gotten here
// because of a shutdown trigger.
// Shutdown of the adapter also clears the tracked route.
hca.shutdown();
}
} catch (final IOException iox) {
if (log.isDebugEnabled()) {
log.debug("Exception shutting down released connection.",
iox);
}
} finally {
final boolean reusable = hca.isMarkedReusable();
if (log.isDebugEnabled()) {
if (reusable) {
log.debug("Released connection is reusable.");
} else {
log.debug("Released connection is not reusable.");
}
}
hca.detach();
pool.freeEntry(entry, reusable, validDuration, timeUnit);
}
}
}
示例14: normalizeSyntax
import org.apache.http.util.Args; //导入方法依赖的package包/类
/**
* Removes dot segments according to RFC 3986, section 5.2.4 and
* Syntax-Based Normalization according to RFC 3986, section 6.2.2.
*
* @param uri the original URI
* @return the URI without dot segments
*/
static URI normalizeSyntax(final URI uri) throws URISyntaxException {
if (uri.isOpaque() || uri.getAuthority() == null) {
// opaque and file: URIs
return uri;
}
Args.check(uri.isAbsolute(), "Base URI must be absolute");
final URIBuilder builder = new URIBuilder(uri);
final String path = builder.getPath();
if (path != null && !path.equals("/")) {
final String[] inputSegments = path.split("/");
final Stack<String> outputSegments = new Stack<String>();
for (final String inputSegment : inputSegments) {
if ((inputSegment.isEmpty()) || (".".equals(inputSegment))) {
// Do nothing
} else if ("..".equals(inputSegment)) {
if (!outputSegments.isEmpty()) {
outputSegments.pop();
}
} else {
outputSegments.push(inputSegment);
}
}
final StringBuilder outputBuffer = new StringBuilder();
for (final String outputSegment : outputSegments) {
outputBuffer.append('/').append(outputSegment);
}
if (path.lastIndexOf('/') == path.length() - 1) {
// path.endsWith("/") || path.equals("")
outputBuffer.append('/');
}
builder.setPath(outputBuffer.toString());
}
if (builder.getScheme() != null) {
builder.setScheme(builder.getScheme().toLowerCase(Locale.ROOT));
}
if (builder.getHost() != null) {
builder.setHost(builder.getHost().toLowerCase(Locale.ROOT));
}
return builder.build();
}
示例15: create
import org.apache.http.util.Args; //导入方法依赖的package包/类
/**
* Creates a new instance of {@link ContentType}.
*
* @param mimeType MIME type. It may not be <code>null</code> or empty. It may not contain
* characters <">, <;>, <,> reserved by the HTTP specification.
* @param charset charset.
* @return content type
*/
public static ContentType create(final String mimeType, final Charset charset) {
final String type = Args.notBlank(mimeType, "MIME type").toLowerCase(Locale.US);
Args.check(valid(type), "MIME type may not contain reserved characters");
return new ContentType(type, charset);
}