當前位置: 首頁>>代碼示例>>Java>>正文


Java HttpResponse.getLastHeader方法代碼示例

本文整理匯總了Java中org.apache.http.HttpResponse.getLastHeader方法的典型用法代碼示例。如果您正苦於以下問題:Java HttpResponse.getLastHeader方法的具體用法?Java HttpResponse.getLastHeader怎麽用?Java HttpResponse.getLastHeader使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.apache.http.HttpResponse的用法示例。


在下文中一共展示了HttpResponse.getLastHeader方法的5個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: doResponseRedirectOrNotModifiedLogic

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
protected boolean doResponseRedirectOrNotModifiedLogic(HttpServletRequest servletRequest, HttpServletResponse servletResponse,
        HttpResponse proxyResponse, int statusCode) throws ServletException, IOException {
    // Check if the proxy response is a redirect
    // The following code is adapted from org.tigris.noodle.filters.CheckForRedirect
    if (statusCode >= HttpServletResponse.SC_MULTIPLE_CHOICES /* 300 */
            && statusCode < HttpServletResponse.SC_NOT_MODIFIED /* 304 */) {
        Header locationHeader = proxyResponse.getLastHeader(HttpHeaders.LOCATION);
        if (locationHeader == null) {
            throw new ServletException(
                    "Received status code: " + statusCode + " but no " + HttpHeaders.LOCATION + " header was found in the response");
        }
        // Modify the redirect to go to this proxy servlet rather that the proxied host
        String locStr = rewriteUrlFromResponse(servletRequest, locationHeader.getValue());

        servletResponse.sendRedirect(locStr);
        return true;
    }
    // 304 needs special handling. See:
    // http://www.ics.uci.edu/pub/ietf/http/rfc1945.html#Code304
    // We get a 304 whenever passed an 'If-Modified-Since'
    // header and the data on disk has not changed; server
    // responds w/ a 304 saying I'm not going to send the
    // body because the file has not changed.
    if (statusCode == HttpServletResponse.SC_NOT_MODIFIED) {
        servletResponse.setIntHeader(HttpHeaders.CONTENT_LENGTH, 0);
        servletResponse.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return true;
    }
    return false;
}
 
開發者ID:bluecreator,項目名稱:http-agent,代碼行數:31,代碼來源:AgentServlet.java

示例2: registerClients

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
public void registerClients() throws Exception
{
	// Create OAuth client-credentials clients
	final List<OAuthClient> oauthClients = getOAuthClients();
	for( OAuthClient clientInfo : oauthClients )
	{
		ObjectNode oauthclient = mapper.createObjectNode();
		oauthclient.put("name", clientInfo.getName());
		oauthclient.put("clientId", clientInfo.getClientId());
		String secret = clientInfo.getSecret();
		if( Check.isEmpty(secret) )
		{
			secret = UUID.randomUUID().toString();
			clientInfo.setSecret(secret);
		}
		oauthclient.put("clientSecret", secret);
		oauthclient.put("userId", clientInfo.getUserId());
		String redirectUrl = clientInfo.getUrl();
		if( Check.isEmpty(redirectUrl) )
		{
			redirectUrl = "default";
			clientInfo.setUrl(redirectUrl);
		}
		oauthclient.put("redirectUrl", redirectUrl);
		clients.add(clientInfo);
		HttpResponse postResponse = postEntity(oauthclient.toString(), context.getBaseUrl() + "api/oauth",
			adminToken, true);
		Header postHeader = postResponse.getLastHeader("Location");
		if( postHeader == null )
		{
			throw new RuntimeException("POST response did not contain 'Location' in header (code: "
				+ postResponse.getStatusLine().getStatusCode() + ')');
		}
		String clientUri = postHeader.getValue();
		JsonNode entity = getEntity(clientUri, adminToken);
		clientInfo.setUuid(entity.get("uuid").asText());
	}
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:39,代碼來源:AbstractRestApiTest.java

示例3: getLocation

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
private String getLocation(HttpResponse response)
{
	Header lastHeader = response.getLastHeader("Location");
	if( lastHeader != null )
	{
		return lastHeader.getValue();
	}
	return null;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:10,代碼來源:OAuthTest.java

示例4: checkAccountLocked

import org.apache.http.HttpResponse; //導入方法依賴的package包/類
private static void checkAccountLocked(HttpResponse response) {
    Header header = response.getLastHeader("X-Authentication-Denied-Reason");
    if (header != null) {
        String info = Objects.toString(header.getValue(), "").trim();
        throw new AccessControlException("Your account seems to be locked" + (info.isEmpty() ? "" : ": " + info));
    }
}
 
開發者ID:pascalgn,項目名稱:jiracli,代碼行數:8,代碼來源:HttpClient.java

示例5: doEnd

import org.apache.http.HttpResponse; //導入方法依賴的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];

        responseState = e.toString();
    }
    else {
        HttpResponse response = (HttpResponse) args[0];

        Header sheader = response.getLastHeader("Server");

        if (sheader != null) {
            server = sheader.getValue();
        }

        responseState = response.getStatusLine().getStatusCode() + "";

        rc = 1;
    }

    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_TYPE, "apache.http.Client");
    params.put(CaptureConstants.INFO_CLIENT_APPID, this.applicationId);
    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,
            ApacheHttpClientAdapter.class, args);
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:59,代碼來源:ApacheHttpClientIT.java


注:本文中的org.apache.http.HttpResponse.getLastHeader方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。