当前位置: 首页>>代码示例>>Java>>正文


Java Header.getValue方法代码示例

本文整理汇总了Java中org.apache.commons.httpclient.Header.getValue方法的典型用法代码示例。如果您正苦于以下问题:Java Header.getValue方法的具体用法?Java Header.getValue怎么用?Java Header.getValue使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.commons.httpclient.Header的用法示例。


在下文中一共展示了Header.getValue方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: getPostResponseHeader

import org.apache.commons.httpclient.Header; //导入方法依赖的package包/类
public static String getPostResponseHeader(String url,String argJson,List<UHeader> headerList,String headerName){
  	String info = "";
  	try {
   	HttpClient client = new HttpClient();
	PostMethod method = new PostMethod(url);
	client.getParams().setContentCharset("UTF-8");
	if(headerList.size()>0){
		for(int i = 0;i<headerList.size();i++){
			UHeader header = headerList.get(i);
			method.setRequestHeader(header.getHeaderTitle(),header.getHeaderValue());
		}
	}
	method.getParams().setParameter(
			HttpMethodParams.HTTP_CONTENT_CHARSET, "UTF-8");
	if(argJson != null && !argJson.trim().equals("")) {
		RequestEntity requestEntity = new StringRequestEntity(argJson,"application/json","UTF-8");
		method.setRequestEntity(requestEntity);
	}
	method.releaseConnection();
	Header h =  method.getResponseHeader(headerName);
	info = h.getValue();
} catch (IOException e) {
	e.printStackTrace();
}
  	return info;
  }
 
开发者ID:noseparte,项目名称:Spring-Boot-Server,代码行数:27,代码来源:HttpUtils.java

示例2: runTest

import org.apache.commons.httpclient.Header; //导入方法依赖的package包/类
private void runTest(String acceptHeaderValue, boolean useHttpEquiv, String expectedContentType) throws Exception {
    final String info = (useHttpEquiv ? "Using http-equiv parameter" : "Using Accept header") + ": ";
    final String url = HTTP_BASE_URL + MY_TEST_PATH;
    final PostMethod post = new PostMethod(url);
    post.setFollowRedirects(false);
    
    if(acceptHeaderValue != null) {
        if(useHttpEquiv) {
            post.addParameter(":http-equiv-accept", acceptHeaderValue);
        } else {
            post.addRequestHeader("Accept", acceptHeaderValue);
        }
    }
    
    final int status = httpClient.executeMethod(post) / 100;
    assertEquals(info + "Expected status 20x for POST at " + url, 2, status);
    final Header h = post.getResponseHeader("Content-Type");
    assertNotNull(info + "Expected Content-Type header", h);
    final String ct = h.getValue();
    assertTrue(info + "Expected Content-Type '" + expectedContentType + "' for Accept header=" + acceptHeaderValue
            + " but got '" + ct + "'",
            ct.startsWith(expectedContentType));
}
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:24,代码来源:PostServletOutputContentTypeTest.java

示例3: testRedirectToLoginFormAfterLoginError

import org.apache.commons.httpclient.Header; //导入方法依赖的package包/类
/**
   * Test SLING-2165.  Login Error should redirect back to the referrer
   * login page.
   *
   * @throws Exception
   */
  public void testRedirectToLoginFormAfterLoginError() throws Exception {
  	//login failure
      List<NameValuePair> params = new ArrayList<NameValuePair>();
      params.add(new NameValuePair("j_username", "___bogus___"));
      params.add(new NameValuePair("j_password", "not_a_real_user"));
      final String loginPageUrl = String.format("%s/system/sling/form/login", HTTP_BASE_URL);
PostMethod post = (PostMethod)assertPostStatus(HTTP_BASE_URL + "/j_security_check",
      		HttpServletResponse.SC_MOVED_TEMPORARILY,
      		params,
      		null,
      		loginPageUrl);

      final Header locationHeader = post.getResponseHeader("Location");
      String location = locationHeader.getValue();
      int queryStrStart = location.indexOf('?');
      if (queryStrStart != -1) {
      	location = location.substring(0, queryStrStart);
      }
      assertEquals("Expected to remain on the form/login page", loginPageUrl, location);
  }
 
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:27,代码来源:RedirectOnLoginErrorTest.java

示例4: processResponseHeaders

import org.apache.commons.httpclient.Header; //导入方法依赖的package包/类
/**
 * <p>
 * This implementation will parse the <tt>Allow</tt> header to obtain 
 * the set of methods supported by the resource identified by the Request-URI.
 * </p>
 *
 * @param state the {@link HttpState state} information associated with this method
 * @param conn the {@link HttpConnection connection} used to execute
 *        this HTTP method
 *
 * @see #readResponse
 * @see #readResponseHeaders
 * @since 2.0
 */
protected void processResponseHeaders(HttpState state, HttpConnection conn) {
    LOG.trace("enter OptionsMethod.processResponseHeaders(HttpState, HttpConnection)");

    Header allowHeader = getResponseHeader("allow");
    if (allowHeader != null) {
        String allowHeaderValue = allowHeader.getValue();
        StringTokenizer tokenizer =
            new StringTokenizer(allowHeaderValue, ",");
        while (tokenizer.hasMoreElements()) {
            String methodAllowed =
                tokenizer.nextToken().trim().toUpperCase();
            methodsAllowed.addElement(methodAllowed);
        }
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:30,代码来源:OptionsMethod.java

示例5: doPost

import org.apache.commons.httpclient.Header; //导入方法依赖的package包/类
public String doPost(String url, String charset, String jsonObj) {
    String resStr = null;
    HttpClient htpClient = new HttpClient();
    PostMethod postMethod = new PostMethod(url);
    postMethod.getParams().setParameter(
            HttpMethodParams.HTTP_CONTENT_CHARSET, charset);
    try {
        postMethod.setRequestEntity(new StringRequestEntity(jsonObj,
                "application/json", charset));
        int statusCode = htpClient.executeMethod(postMethod);
        if (statusCode != HttpStatus.SC_OK) {
            // post和put不能自动处理转发 301:永久重定向,告诉客户端以后应从新地址访问 302:Moved
            if (statusCode == HttpStatus.SC_MOVED_PERMANENTLY
                    || statusCode == HttpStatus.SC_MOVED_TEMPORARILY) {
                Header locationHeader = postMethod
                        .getResponseHeader("location");
                String location = null;
                if (locationHeader != null) {
                    location = locationHeader.getValue();
                    log.info("The page was redirected to :" + location);
                } else {
                    log.info("Location field value is null");
                }
            } else {
                log.error("Method failed: " + postMethod.getStatusLine());
            }
            return resStr;
        }
        byte[] responseBody = postMethod.getResponseBody();
        resStr = new String(responseBody, charset);
    } catch (Exception e) {
        e.printStackTrace();
    } finally {
        postMethod.releaseConnection();
    }
    return resStr;
}
 
开发者ID:BriData,项目名称:DBus,代码行数:38,代码来源:HttpRequest.java

示例6: process

import org.apache.commons.httpclient.Header; //导入方法依赖的package包/类
public boolean process(final SimpleRequest request, final SimpleResponse response)
    throws IOException
{
    RequestLine requestLine = request.getRequestLine();
    HttpVersion ver = requestLine.getHttpVersion();
    Header auth = request.getFirstHeader("Authorization");
    if (auth == null) { 
        response.setStatusLine(ver, HttpStatus.SC_BAD_REQUEST);
        response.setBodyString("Authorization header missing");
        return true;
    } else {
        String authstr = auth.getValue();
        
        if (authstr.indexOf("NTLM") != -1) {
            response.setStatusLine(ver, HttpStatus.SC_OK);
            return true;
        } else if (authstr.indexOf("Basic") != -1) {
            response.setStatusLine(ver, HttpStatus.SC_UNAUTHORIZED);
            response.addHeader(new Header("WWW-Authenticate", "Negotiate"));
            response.addHeader(new Header("WWW-Authenticate", "NTLM"));
            response.setBodyString("Authorization required");
            return true;
        } else {
            response.setStatusLine(ver, HttpStatus.SC_BAD_REQUEST);
            response.setBodyString("Unknown auth type: " + authstr);
            return true;
        }
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:30,代码来源:TestNTLMAuth.java

示例7: getContentType

import org.apache.commons.httpclient.Header; //导入方法依赖的package包/类
public String getContentType() {
    Header contenttype = this.headers.getFirstHeader("Content-Type");
    if (contenttype != null) {
        return contenttype.getValue(); 
    } else {
        return "text/plain"; 
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:9,代码来源:SimpleRequest.java

示例8: sendRemoteRequest

import org.apache.commons.httpclient.Header; //导入方法依赖的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;
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:31,代码来源:AbstractHttpClient.java

示例9: getHeader

import org.apache.commons.httpclient.Header; //导入方法依赖的package包/类
public String getHeader(String key) {
  for (Header header: headers) {
    if (header.getName().equalsIgnoreCase(key)) {
      return header.getValue();
    }
  }
  return null;
}
 
开发者ID:fengchen8086,项目名称:ditb,代码行数:9,代码来源:Response.java

示例10: getHeader

import org.apache.commons.httpclient.Header; //导入方法依赖的package包/类
public String getHeader(String name) {
    Header header = request.getRequestHeader(name);
    if (header == null) {
        return null;
    }
    String value = header.getValue();
    return value;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:9,代码来源:HttpMethodAdapter.java

示例11: isGzipResponse

import org.apache.commons.httpclient.Header; //导入方法依赖的package包/类
/**
 * Determine whether the given response is a GZIP response.
 * <p>Default implementation checks whether the HTTP "Content-Encoding"
 * header contains "gzip" (in any casing).
 * @param postMethod the PostMethod to check
 */
protected boolean isGzipResponse(PostMethod postMethod) {
	Header encodingHeader = postMethod.getResponseHeader(HTTP_HEADER_CONTENT_ENCODING);
	if (encodingHeader == null || encodingHeader.getValue() == null) {
		return false;
	}
	return (encodingHeader.getValue().toLowerCase().indexOf(ENCODING_GZIP) != -1);
}
 
开发者ID:ITYug,项目名称:kaltura-ce-sakai-extension,代码行数:14,代码来源:KalturaClientBase.java

示例12: processConditionalRetrievalHeaders

import org.apache.commons.httpclient.Header; //导入方法依赖的package包/类
/**
 * Records the ETag and Last-Modified headers, from the response, if they are present.
 * 
 * @param getMethod GetMethod containing a valid HTTP response
 */
protected void processConditionalRetrievalHeaders(GetMethod getMethod) {
    Header httpHeader = getMethod.getResponseHeader("ETag");
    if (httpHeader != null) {
        cachedMetadataETag = httpHeader.getValue();
    }

    httpHeader = getMethod.getResponseHeader("Last-Modified");
    if (httpHeader != null) {
        cachedMetadataLastModified = httpHeader.getValue();
    }
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:HTTPMetadataProvider.java

示例13: assertResponseHeader

import org.apache.commons.httpclient.Header; //导入方法依赖的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

示例14: postQuery

import org.apache.commons.httpclient.Header; //导入方法依赖的package包/类
protected JSONObject postQuery(HttpClient httpClient, String url, JSONObject body) throws UnsupportedEncodingException,
            IOException, HttpException, URIException, JSONException
{
    PostMethod post = new PostMethod(url);
    if (body.toString().length() > DEFAULT_SAVEPOST_BUFFER)
    {
        post.getParams().setBooleanParameter(HttpMethodParams.USE_EXPECT_CONTINUE, true);
    }
    post.setRequestEntity(new ByteArrayRequestEntity(body.toString().getBytes("UTF-8"), "application/json"));

    try
    {
        httpClient.executeMethod(post);

        if(post.getStatusCode() == HttpStatus.SC_MOVED_PERMANENTLY || post.getStatusCode() == HttpStatus.SC_MOVED_TEMPORARILY)
        {
            Header locationHeader = post.getResponseHeader("location");
            if (locationHeader != null)
            {
                String redirectLocation = locationHeader.getValue();
                post.setURI(new URI(redirectLocation, true));
                httpClient.executeMethod(post);
            }
        }

        if (post.getStatusCode() != HttpServletResponse.SC_OK)
        {
            throw new LuceneQueryParserException("Request failed " + post.getStatusCode() + " " + url.toString());
        }

        Reader reader = new BufferedReader(new InputStreamReader(post.getResponseBodyAsStream(), post.getResponseCharSet()));
        // TODO - replace with streaming-based solution e.g. SimpleJSON ContentHandler
        JSONObject json = new JSONObject(new JSONTokener(reader));

        if (json.has("status"))
        {
            JSONObject status = json.getJSONObject("status");
            if (status.getInt("code") != HttpServletResponse.SC_OK)
            {
                throw new LuceneQueryParserException("SOLR side error: " + status.getString("message"));
            }
        }
        return json;
    }
    finally
    {
        post.releaseConnection();
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:50,代码来源:SolrQueryHTTPClient.java

示例15: getHeader

import org.apache.commons.httpclient.Header; //导入方法依赖的package包/类
public String getHeader(String name)
{
    Header header = method.getResponseHeader(name);
    return (header != null) ? header.getValue() : null;
}
 
开发者ID:Alfresco,项目名称:alfresco-core,代码行数:6,代码来源:HttpMethodResponse.java


注:本文中的org.apache.commons.httpclient.Header.getValue方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。