本文整理汇总了Java中org.apache.commons.httpclient.HttpMethod.getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.getStatusCode方法的具体用法?Java HttpMethod.getStatusCode怎么用?Java HttpMethod.getStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.HttpMethod
的用法示例。
在下文中一共展示了HttpMethod.getStatusCode方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: SecureHttpMethodResponse
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
public SecureHttpMethodResponse(HttpMethod method, HostConfiguration hostConfig,
EncryptionUtils encryptionUtils) throws AuthenticationException, IOException
{
super(method);
this.hostConfig = hostConfig;
this.encryptionUtils = encryptionUtils;
if(method.getStatusCode() == HttpStatus.SC_OK)
{
this.decryptedBody = encryptionUtils.decryptResponseBody(method);
// authenticate the response
if(!authenticate())
{
throw new AuthenticationException(method);
}
}
}
示例2: isRedirect
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
private boolean isRedirect(HttpMethod method)
{
switch (method.getStatusCode()) {
case HttpStatus.SC_MOVED_TEMPORARILY:
case HttpStatus.SC_MOVED_PERMANENTLY:
case HttpStatus.SC_SEE_OTHER:
case HttpStatus.SC_TEMPORARY_REDIRECT:
if (method.getFollowRedirects()) {
return true;
} else {
return false;
}
default:
return false;
}
}
示例3: SwiftInvalidResponseException
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
public SwiftInvalidResponseException(String message,
String operation,
URI uri,
HttpMethod method) {
super(message);
this.statusCode = method.getStatusCode();
this.operation = operation;
this.uri = uri;
String bodyAsString;
try {
bodyAsString = method.getResponseBodyAsString();
if (bodyAsString == null) {
bodyAsString = "";
}
} catch (IOException e) {
bodyAsString = "";
}
this.body = bodyAsString;
}
示例4: executeRequest
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
* Will create the method and execute it. After this the method is sent to a
* ResponseHandler that is returned.
*
* @param httpRequest
* Request we are receiving from the client
* @param url
* The location we are proxying to
* @return A ResponseHandler that can be used to write the response
* @throws MethodNotAllowedException
* If the method specified by the request isn't handled
* @throws IOException
* When there is a problem with the streams
* @throws HttpException
* The httpclient can throw HttpExcetion when executing the
* method
*/
ResponseHandler executeRequest(HttpServletRequest httpRequest, String url)
throws MethodNotAllowedException, IOException, HttpException {
RequestHandler requestHandler = RequestHandlerFactory
.createRequestMethod(httpRequest.getMethod());
HttpMethod method = requestHandler.process(httpRequest, url);
method.setFollowRedirects(false);
/*
* Why does method.validate() return true when the method has been
* aborted? I mean, if validate returns true the API says that means
* that the method is ready to be executed. TODO I don't like doing type
* casting here, see above.
*/
if (!((HttpMethodBase) method).isAborted()) {
httpClient.executeMethod(method);
if (method.getStatusCode() == 405) {
Header allow = method.getResponseHeader("allow");
String value = allow.getValue();
throw new MethodNotAllowedException(
"Status code 405 from server",
AllowedMethodHandler.processAllowHeader(value));
}
}
return ResponseHandlerFactory.createResponseHandler(method);
}
示例5: sendThankYouRequest
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
void sendThankYouRequest(CoalesceThankYouNotesKey key)
{
boolean success = false;
List requestList = this.removeRequestList(key);
if (done || requestList == null)
{
return;
}
HttpMethod streamedPostMethod = null;
try
{
if (LOGGER.isDebugEnabled())
{
LOGGER.debug("Sending thank you for {}", requestList.size());
}
AuthenticatedUrl url = key.getAuthenticatedUrl();
HttpClient httpClient = FastServletProxyFactory.getHttpClient(url);
httpClient.getState().addCookies(key.getCookies());
OutputStreamWriter writer = new ThankYouStreamWriter(requestList);
streamedPostMethod = FastServletProxyFactory.serverSupportsChunking(url) ? new StreamedPostMethod(url.getPath() + "?thanks", writer) : new BufferedPostMethod(url.getPath() + "?thanks", writer);
httpClient.executeMethod(streamedPostMethod);
int code = streamedPostMethod.getStatusCode();
streamedPostMethod.getResponseBodyAsStream().close();
streamedPostMethod.releaseConnection();
streamedPostMethod = null;
success = code == 200;
}
catch (Exception e)
{
LOGGER.warn("Exception in JRPIP thank you note for URL: {} Retrying.", key.toString(), e);
}
finally
{
if (streamedPostMethod != null)
{
streamedPostMethod.releaseConnection();
}
}
if (!success)
{
this.readList(key, requestList);
}
}