本文整理汇总了Java中org.apache.commons.httpclient.HttpMethod.getResponseHeader方法的典型用法代码示例。如果您正苦于以下问题:Java HttpMethod.getResponseHeader方法的具体用法?Java HttpMethod.getResponseHeader怎么用?Java HttpMethod.getResponseHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.HttpMethod
的用法示例。
在下文中一共展示了HttpMethod.getResponseHeader方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: sendRemoteRequest
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
* Send Request to the repository
*/
protected HttpMethod sendRemoteRequest(Request req) throws AuthenticationException, IOException
{
if (logger.isDebugEnabled())
{
logger.debug("");
logger.debug("* Request: " + req.getMethod() + " " + req.getFullUri() + (req.getBody() == null ? "" : "\n" + new String(req.getBody(), "UTF-8")));
}
HttpMethod method = createMethod(req);
// execute method
executeMethod(method);
// Deal with redirect
if(isRedirect(method))
{
Header locationHeader = method.getResponseHeader("location");
if (locationHeader != null)
{
String redirectLocation = locationHeader.getValue();
method.setURI(new URI(redirectLocation, true));
httpClient.executeMethod(method);
}
}
return method;
}
示例2: getResponseMac
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
* Get the MAC (Message Authentication Code) on the HTTP response
*
* @param res HttpMethod
* @return the MAC
* @throws IOException
*/
protected byte[] getResponseMac(HttpMethod res) throws IOException
{
Header header = res.getResponseHeader(HEADER_MAC);
if(header != null)
{
return Base64.decode(header.getValue());
}
else
{
return null;
}
}
示例3: getResponseTimestamp
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
* Get the timestamp on the HTTP response
*
* @param method HttpMethod
* @return timestamp (ms, in UNIX time)
* @throws IOException
*/
protected Long getResponseTimestamp(HttpMethod method) throws IOException
{
Header header = method.getResponseHeader(HEADER_TIMESTAMP);
if(header != null)
{
return Long.valueOf(header.getValue());
}
else
{
return null;
}
}
示例4: decodeAlgorithmParameters
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
* Decode cipher algorithm parameters from the HTTP method
*
* @param method HttpMethod
* @return decoded algorithm parameters
* @throws IOException
*/
protected AlgorithmParameters decodeAlgorithmParameters(HttpMethod method) throws IOException
{
Header header = method.getResponseHeader(HEADER_ALGORITHM_PARAMETERS);
if(header != null)
{
byte[] algorithmParams = Base64.decode(header.getValue());
AlgorithmParameters algorithmParameters = encryptor.decodeAlgorithmParameters(algorithmParams);
return algorithmParameters;
}
else
{
return null;
}
}
示例5: 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);
}
示例6: getContentType
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
protected String getContentType(final HttpMethod method) {
final Header header = method.getResponseHeader("Content-Type");
if (header != null) {
final String contentType = header.getValue();
if (contentType != null && !contentType.isEmpty()) {
return contentType.toLowerCase(Locale.ENGLISH);
}
}
return EMPTY;
}
示例7: assertResponseHeader
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
private void assertResponseHeader(HttpMethod m, String name, String expectedRegex) {
final Header h = m.getResponseHeader(name);
assertNotNull("Expecting header " + name, h);
final String value = h.getValue();
assertTrue("Expected regexp " + expectedRegex + " for header " + name + ", header value is " + value,
Pattern.matches(expectedRegex, value));
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:8,代码来源:HeadServletTest.java
示例8: assertXReason
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
private void assertXReason(final HttpMethod method) throws IOException {
// expected the X-Reason header
final Header reason = method.getResponseHeader("X-Reason");
assertNotNull(reason);
// expect the response to be the same as the reason (SLING-1831)
assertEquals(reason.getValue(), method.getResponseBodyAsString().trim());
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:9,代码来源:AuthenticationResponseCodeTest.java
示例9: readHTTPImage
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
private static BufferedImage readHTTPImage(URI uri,
HostConfiguration hostConfiguration, HttpClient client,
ConnectionWrapper wrapper) {
List<Proxy> list = ProxySelector.getDefault().select(uri);
for (Proxy p : list)
{
InetSocketAddress addr = (InetSocketAddress) p.address();
if (addr == null)
hostConfiguration.setProxyHost(null);
else
hostConfiguration.setProxy(addr.getHostName(), addr.getPort());
try {
HttpMethod method = new GetMethod(uri.toString());
synchronized (wrapper) {
wrapper.connection = method;
}
int sc = client.executeMethod(hostConfiguration, method);
if (sc != HttpStatus.SC_OK) {
continue;
}
// Check Content Type
Header h = method.getResponseHeader("Content-Type");
if (h == null || !h.getValue().contains("image"))
continue;
return ImageIO.read( method.getResponseBodyAsStream() );
} catch (IOException ex) {
continue;
}
}
return null;
}
示例10: doEnd
import org.apache.commons.httpclient.HttpMethod; //导入方法依赖的package包/类
/**
* for http client
*
* @param args
* @return
*/
public void doEnd(Object[] args) {
Map<String, Object> params = new HashMap<String, Object>();
String server = "";
int rc = -1;
String responseState = "";
if (Throwable.class.isAssignableFrom(args[0].getClass())) {
Throwable e = (Throwable) args[0];
rc = 0;
responseState = e.toString();
}
else {
HttpMethod method = (HttpMethod) args[0];
Header sheader = method.getResponseHeader("Server");
if (sheader != null) {
server = sheader.getValue();
}
rc = 1;
responseState = method.getStatusLine().getStatusCode() + "";
}
if (logger.isDebugable()) {
logger.debug("Invoke END:" + rc + "," + server, null);
}
params.put(CaptureConstants.INFO_CLIENT_TARGETSERVER, server);
params.put(CaptureConstants.INFO_CLIENT_RESPONSECODE, rc);
params.put(CaptureConstants.INFO_CLIENT_APPID, this.applicationId);
params.put(CaptureConstants.INFO_CLIENT_TYPE, "apache.http.Client");
params.put(CaptureConstants.INFO_CLIENT_REQUEST_URL, targetURL);
params.put(CaptureConstants.INFO_CLIENT_RESPONSESTATE, responseState);
UAVServer.instance().runMonitorCaptureOnServerCapPoint(CaptureConstants.CAPPOINT_APP_CLIENT,
Monitor.CapturePhase.DOCAP, params);
if (ivcContextParams != null) {
ivcContextParams.putAll(params);
}
UAVServer.instance().runSupporter("com.creditease.uav.apm.supporters.InvokeChainSupporter", "runCap",
InvokeChainConstants.CHAIN_APP_CLIENT, InvokeChainConstants.CapturePhase.DOCAP, ivcContextParams,
ApacheHttpClient3Adapter.class, args);
}