下面列出了怎么用org.apache.commons.httpclient.HttpClientError的API类实例代码及写法,或者点击链接到github查看源代码。
/**
* Creates a random cnonce value based on the current time.
*
* @return The cnonce value as String.
* @throws HttpClientError if MD5 algorithm is not supported.
*/
public static String createCnonce() {
LOG.trace("enter DigestScheme.createCnonce()");
String cnonce;
final String digAlg = "MD5";
MessageDigest md5Helper;
try {
md5Helper = MessageDigest.getInstance(digAlg);
} catch (NoSuchAlgorithmException e) {
throw new HttpClientError(
"Unsupported algorithm in HTTP Digest authentication: "
+ digAlg);
}
cnonce = Long.toString(System.currentTimeMillis());
cnonce = encode(md5Helper.digest(EncodingUtil.getAsciiBytes(cnonce)));
return cnonce;
}
private static SSLContext createEasySSLContext()
{
try
{
SSLContext context = SSLContext.getInstance("SSL");
context.init(null,
new TrustManager[]{new EasyX509TrustManager(null)},
null);
return context;
}
catch (Exception e)
{
if (Trace.ssl)
{
Trace.trace(e.getMessage());
}
throw new HttpClientError(e.toString());
}
}
protected SSLContext createEasySSLContext(AppConfiguration appConfiguration) {
try {
String password = appConfiguration.getCaCertsPassphrase();
char[] passphrase = null;
if (password != null) {
passphrase = encryptionService.decrypt(password).toCharArray();
}
KeyStore cacerts = null;
String cacertsFN = appConfiguration.getCaCertsLocation();
if (cacertsFN != null) {
cacerts = KeyStore.getInstance(KeyStore.getDefaultType());
FileInputStream cacertsFile = new FileInputStream(cacertsFN);
cacerts.load(cacertsFile, passphrase);
cacertsFile.close();
}
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[] { new EasyX509TrustManager(cacerts) }, null);
return context;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[] { new EasyX509TrustManager(
null) }, null);
return context;
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new TrustManager[] { new DefaultX509TrustManager(null) }, null);
return context;
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
/**
* Creates a new EasySSLProtocolSocket object.
*
* @return the SSL context
*/
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[] {new EasyX509TrustManager(null)}, null);
return context;
} catch (Exception e) {
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(
null,
new TrustManager[] {new EasyX509TrustManager(null)},
null);
return context;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(
null,
new TrustManager[] {new EasyX509TrustManager(null)},
null);
return context;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
/**
* Converts the specified string to byte array of ASCII characters.
*
* @param data the string to be encoded
* @return The string as a byte array.
*
* @since 3.0
*/
public static byte[] getAsciiBytes(final String data) {
if (data == null) {
throw new IllegalArgumentException("Parameter may not be null");
}
try {
return data.getBytes("US-ASCII");
} catch (UnsupportedEncodingException e) {
throw new HttpClientError("HttpClient requires ASCII support");
}
}
/**
* Converts the byte array of ASCII characters to a string. This method is
* to be used when decoding content of HTTP elements (such as response
* headers)
*
* @param data the byte array to be encoded
* @param offset the index of the first byte to encode
* @param length the number of bytes to encode
* @return The string representation of the byte array
*
* @since 3.0
*/
public static String getAsciiString(final byte[] data, int offset, int length) {
if (data == null) {
throw new IllegalArgumentException("Parameter may not be null");
}
try {
return new String(data, offset, length, "US-ASCII");
} catch (UnsupportedEncodingException e) {
throw new HttpClientError("HttpClient requires ASCII support");
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[] {new EasyX509TrustManager(null)}, null);
return context;
} catch (Exception e) {
// LOG.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[] { new DummyX509TrustManager(null) }, null);
return context;
} catch (Exception e) {
if (LOG.isErrorEnabled()) { LOG.error(e.getMessage(), e); }
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(
null,
new TrustManager[] {new EasyX509TrustManager(null)},
null);
return context;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("TLSv1.3");
context.init(null, new TrustManager[] { new DefaultX509TrustManager(null) }, null);
return context;
} catch (Exception e) {
logger.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null);
return context;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[] { new EasyX509TrustManager(null) }, null);
return context;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new TrustManager[] { new DefaultX509TrustManager(null) }, null);
return context;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("TLS");
context.init(null, new TrustManager[] { new DefaultX509TrustManager(null) }, null);
return context;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(
null,
new TrustManager[] {new EasyX509TrustManager(null)},
null);
return context;
} catch (Exception e) {
log.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(null, new TrustManager[] { new DummyX509TrustManager(null) }, null);
return context;
} catch (Exception e) {
if (LOG.isErrorEnabled()) { LOG.error(e.getMessage(), e); }
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLUtils.getSSLContext();
context.init(null, new TrustManager[] {new EasyX509TrustManager(null)}, null);
return context;
} catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
private static SSLContext createEasySSLContext() {
try {
SSLContext context = SSLContext.getInstance("SSL");
context.init(
null,
new TrustManager[]{new EasyX509TrustManager(null)},
null);
return context;
}
catch (Exception e) {
LOG.error(e.getMessage(), e);
throw new HttpClientError(e.toString());
}
}
/**
* Form-urlencoding routine.
*
* The default encoding for all forms is `application/x-www-form-urlencoded'.
* A form data set is represented in this media type as follows:
*
* The form field names and values are escaped: space characters are replaced
* by `+', and then reserved characters are escaped as per [URL]; that is,
* non-alphanumeric characters are replaced by `%HH', a percent sign and two
* hexadecimal digits representing the ASCII code of the character. Line breaks,
* as in multi-line text field values, are represented as CR LF pairs, i.e. `%0D%0A'.
*
* <p>
* if the given charset is not supported, ISO-8859-1 is used instead.
* </p>
*
* @param pairs the values to be encoded
* @param charset the character set of pairs to be encoded
*
* @return the urlencoded pairs
*
* @since 2.0 final
*/
public static String formUrlEncode(NameValuePair[] pairs, String charset) {
try {
return doFormUrlEncode(pairs, charset);
} catch (UnsupportedEncodingException e) {
LOG.error("Encoding not supported: " + charset);
try {
return doFormUrlEncode(pairs, DEFAULT_CHARSET);
} catch (UnsupportedEncodingException fatal) {
// Should never happen. ISO-8859-1 must be supported on all JVMs
throw new HttpClientError("Encoding not supported: " +
DEFAULT_CHARSET);
}
}
}