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


Java Header类代码示例

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


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

示例1: testParse3

import org.apache.commons.httpclient.Header; //导入依赖的package包/类
/**
 * Test parse with quoted text
 */
public void testParse3() throws Exception {
    String headerValue =
        "name=\"Doe, John\";version=1;max-age=600;secure;domain=.apache.org";
    Header header = new Header("set-cookie", headerValue);

    CookieSpec cookiespec = new CookieSpecBase();
    Cookie[] cookies = cookieParse(cookiespec, "www.apache.org", 80, "/", false, header);

    assertEquals(1, cookies.length);

    assertEquals("name", cookies[0].getName());
    assertEquals("Doe, John", cookies[0].getValue());
    assertEquals(null, cookies[0].getComment());
    assertEquals(0, cookies[0].getVersion());
    assertEquals(".apache.org", cookies[0].getDomain());
    assertEquals("/", cookies[0].getPath());
    assertTrue(cookies[0].getSecure());
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:22,代码来源:TestCookieCompatibilitySpec.java

示例2: run

import org.apache.commons.httpclient.Header; //导入依赖的package包/类
@Override
public List<TestResult> run() {
    List<TestResult> results = new ArrayList<TestResult>();

    results.add(doSort("Sort users in ascending order in XML", new Header("Accept", "application/xml"), "ascending", "XML", "/Users", "userName"));
    results.add(doSort("Sort users in descending order in XML", new Header("Accept", "application/xml"), "descending", "XML", "/Users", "userName"));
    results.add(doSort("Sort groups in ascending order in XML", new Header("Accept", "application/xml"), "ascending", "XML", "/Groups", "displayName"));
    results.add(doSort("Sort groups in descending order in XML", new Header("Accept", "application/xml"), "descending", "XML", "/Groups", "displayName"));

    results.add(doSort("Sort users in ascending order in JSON", new Header("Accept", "application/json"), "ascending", "JSON", "/Users", "userName"));
    results.add(doSort("Sort users in descending order in JSON", new Header("Accept", "application/json"), "descending", "JSON", "/Users", "userName"));
    results.add(doSort("Sort groups in ascending order in JSON", new Header("Accept", "application/json"), "ascending", "JSON", "/Groups", "displayName"));
    results.add(doSort("Sort groups in descending order in JSON", new Header("Accept", "application/json"), "descending", "JSON", "/Groups", "displayName"));

    return results;
}
 
开发者ID:wso2-incubator,项目名称:scim2-compliance-test-suite,代码行数:17,代码来源:SortTest.java

示例3: testCustomAuthorizationHeader

import org.apache.commons.httpclient.Header; //导入依赖的package包/类
public void testCustomAuthorizationHeader() throws Exception {
    UsernamePasswordCredentials creds = 
        new UsernamePasswordCredentials("testuser", "testpass");
    
    HttpRequestHandlerChain handlerchain = new HttpRequestHandlerChain();
    handlerchain.appendHandler(new AuthRequestHandler(creds));
    handlerchain.appendHandler(new HttpServiceHandler(new FeedbackService()));

    this.server.setRequestHandler(handlerchain);

    GetMethod httpget = new GetMethod("/test/");
    String authResponse = "Basic " + EncodingUtil.getAsciiString(
            Base64.encodeBase64(EncodingUtil.getAsciiBytes("testuser:testpass")));
    httpget.addRequestHeader(new Header("Authorization", authResponse));
    try {
        this.client.executeMethod(httpget);
    } finally {
        httpget.releaseConnection();
    }
    assertNotNull(httpget.getStatusLine());
    assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:23,代码来源:TestBasicAuth.java

示例4: getResponse

import org.apache.commons.httpclient.Header; //导入依赖的package包/类
public static SimpleResponse getResponse(int statusCode) {
    Integer code = new Integer(statusCode);
    SimpleResponse response = (SimpleResponse)responses.get(code);
    if (response == null) {
        response = new SimpleResponse();
        response.setStatusLine(HttpVersion.HTTP_1_0, statusCode);
        response.setHeader(new Header("Content-Type", "text/plain; charset=US-ASCII"));

        String s = HttpStatus.getStatusText(statusCode);
        if (s == null) {
            s = "Error " + statusCode;
        }
        response.setBodyString(s);
        response.addHeader(new Header("Connection", "close"));
        response.addHeader(new Header("Content-Lenght", Integer.toString(s.length())));
        responses.put(code, response);
    }
    return response;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:20,代码来源:ErrorResponse.java

示例5: setHeaders

import org.apache.commons.httpclient.Header; //导入依赖的package包/类
/**
 * Will write all response headers received in the method to the response.
 * One header, connection, is however omitted since we will only want the
 * client to keep his connection to the proxy not to the backing server.
 * 
 * @param response
 *            The response that will have headers written to it
 */
protected void setHeaders(HttpServletResponse response) {
    Header[] headers = method.getResponseHeaders();

    for (int i = 0; i < headers.length; i++) {
        Header header = headers[i];
        String name = header.getName();
        boolean contentLength = name.equalsIgnoreCase("content-length");
        boolean connection = name.equalsIgnoreCase("connection");

        if (!contentLength && !connection) {
            response.addHeader(name, header.getValue());
        }
    }

    setViaHeader(response);
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:25,代码来源:ResponseHandlerBase.java

示例6: makeBlob

import org.apache.commons.httpclient.Header; //导入依赖的package包/类
protected Document makeBlob(byte[] data){
	Document document = XMLUtils.getDefaultDocumentBuilder().newDocument();
	Element blob = document.createElement("blob");
	document.appendChild(blob);

	Header[] heads = context.getResponseHeaders();

	for (int i = 0; i < heads.length; i++) {
		if (HeaderName.ContentType.is(heads[i].getName()) ||
				HeaderName.ContentLength.is(heads[i].getName()) ) {
			blob.setAttribute(heads[i].getName(), heads[i].getValue());
		}
	}
	blob.setAttribute("Referer", ((HtmlConnector)context.getConnector()).getReferer());

	blob.appendChild(document.createTextNode(Base64.encodeBase64String(data)));

	return document;
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:20,代码来源:HtmlTransaction.java

示例7: appendToOutputDom

import org.apache.commons.httpclient.Header; //导入依赖的package包/类
@Override
protected void appendToOutputDom(NodeList nodeList, Document outputDom) {
	
	Element doc = outputDom.getDocumentElement();
	Element httpHeaders = outputDom.createElement(tagName);
	Element headerElement;
	Header header;
	int length = contextHeaders.length;
	
	for (int i = 0 ; i < length ; i++) {
		if (!isRequestedObjectRunning()) break;
		
		header = contextHeaders[i];
		headerElement = outputDom.createElement("header");
		headerElement.setAttribute("headerName", header.getName());
		headerElement.setAttribute("headerValue", header.getValue());
        httpHeaders.appendChild(headerElement);
		Engine.logBeans.trace("HttpHeader '" + headerElement.getAttribute("headerName") + " : " 
							+ headerElement.getAttribute("headerValue") + "' added to httpHeaders.");
	}
	doc.appendChild(httpHeaders);
	Engine.logBeans.trace("HttpHeaders added to result document.");
}
 
开发者ID:convertigo,项目名称:convertigo-engine,代码行数:24,代码来源:XMLHttpHeaders.java

示例8: getHeaderFieldKey

import org.apache.commons.httpclient.Header; //导入依赖的package包/类
/**
 * Return the header field key
 * @param keyPosition The key position
 * @return The header field key.
 * @see java.net.HttpURLConnection#getHeaderFieldKey(int)
 * @see org.apache.commons.httpclient.HttpMethod#getResponseHeaders()
 */
public String getHeaderFieldKey(int keyPosition) {
    LOG.trace("enter HttpURLConnection.getHeaderFieldKey(int)");

    // Note: HttpClient does not consider the returned Status Line as
    // a response header. However, getHeaderFieldKey(0) is supposed to 
    // return null. Hence the special case below ...
    
    if (keyPosition == 0) {
        return null;
    }

    // Note: HttpClient does not currently keep headers in the same order
    // that they are read from the HTTP server.

    Header[] headers = this.method.getResponseHeaders();
    if (keyPosition < 0 || keyPosition > headers.length) {
        return null;
    }

    return headers[keyPosition - 1].getName();
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:29,代码来源:HttpURLConnection.java

示例9: 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

示例10: testParseSimple

import org.apache.commons.httpclient.Header; //导入依赖的package包/类
public void testParseSimple() throws Exception {
    Header header = new Header("Set-Cookie","cookie-name=cookie-value");
    
    CookieSpec cookiespec = new CookieSpecBase();
    Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/path/path", false, header);
    assertEquals("Found 1 cookie.",1,parsed.length);
    assertEquals("Name","cookie-name",parsed[0].getName());
    assertEquals("Value","cookie-value",parsed[0].getValue());
    assertTrue("Comment",null == parsed[0].getComment());
    assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
    //assertTrue("isToBeDiscarded",parsed[0].isToBeDiscarded());
    assertTrue("isPersistent",!parsed[0].isPersistent());
    assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
    assertEquals("Path","/path",parsed[0].getPath());
    assertTrue("Secure",!parsed[0].getSecure());
    assertEquals("Version",0,parsed[0].getVersion());
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:18,代码来源:TestCookieCompatibilitySpec.java

示例11: testKeepCloverHappy

import org.apache.commons.httpclient.Header; //导入依赖的package包/类
public void testKeepCloverHappy() throws Exception {
    CookieSpec cookiespec = new IgnoreCookiesSpec();
    cookiespec.parseAttribute(null, null);
    cookiespec.parse("host", 80, "/", false, (String)null);
    cookiespec.parse("host", 80, "/", false, (Header)null);
    cookiespec.validate("host", 80, "/", false, (Cookie)null);
    cookiespec.match("host", 80, "/", false, (Cookie)null);
    cookiespec.match("host", 80, "/", false, (Cookie [])null);
    cookiespec.domainMatch(null, null);
    cookiespec.pathMatch(null, null);
    cookiespec.match("host", 80, "/", false, (Cookie [])null);
    cookiespec.formatCookie(null);
    cookiespec.formatCookies(null);
    cookiespec.formatCookieHeader((Cookie)null);
    cookiespec.formatCookieHeader((Cookie [])null);
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:17,代码来源:TestCookieIgnoreSpec.java

示例12: testCookieVersionSupportHeader1

import org.apache.commons.httpclient.Header; //导入依赖的package包/类
public void testCookieVersionSupportHeader1() throws IOException {
    this.server.setHttpService(new CookieVer0Service());
    this.client.getParams().setCookiePolicy(CookiePolicy.RFC_2965);
    GetMethod httpget1 = new GetMethod("/test/");
    try {
        this.client.executeMethod(httpget1);
    } finally {
        httpget1.releaseConnection();
    }
    GetMethod httpget2 = new GetMethod("/test/");
    try {
        this.client.executeMethod(httpget2);
    } finally {
        httpget2.releaseConnection();
    }
    Header cookiesupport = httpget2.getRequestHeader("Cookie2");
    assertNotNull(cookiesupport);
    assertEquals("$Version=\"1\"", cookiesupport.getValue());
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:20,代码来源:TestCookieVersionSupport.java

示例13: testParseNoValue

import org.apache.commons.httpclient.Header; //导入依赖的package包/类
public void testParseNoValue() throws Exception {
    Header header = new Header("Set-Cookie","cookie-name=");

    CookieSpec cookiespec = new CookieSpecBase();
    Cookie[] parsed = cookieParse(cookiespec, "127.0.0.1", 80, "/", false, header);
    assertEquals("Found 1 cookie.",1,parsed.length);
    assertEquals("Name","cookie-name",parsed[0].getName());
    assertEquals("Value", "", parsed[0].getValue());
    assertTrue("Comment",null == parsed[0].getComment());
    assertTrue("ExpiryDate",null == parsed[0].getExpiryDate());
    //assertTrue("isToBeDiscarded",parsed[0].isToBeDiscarded());
    assertTrue("isPersistent",!parsed[0].isPersistent());
    assertEquals("Domain","127.0.0.1",parsed[0].getDomain());
    assertEquals("Path","/",parsed[0].getPath());
    assertTrue("Secure",!parsed[0].getSecure());
    assertEquals("Version",0,parsed[0].getVersion());
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:18,代码来源:TestCookieCompatibilitySpec.java

示例14: 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

示例15: getRequestCharSet

import org.apache.commons.httpclient.Header; //导入依赖的package包/类
/**
 * Returns the request's charset.  The charset is parsed from the request entity's 
 * content type, unless the content type header has been set manually. 
 * 
 * @see RequestEntity#getContentType()
 * 
 * @since 3.0
 */
public String getRequestCharSet() {
    if (getRequestHeader("Content-Type") == null) {
        // check the content type from request entity
        // We can't call getRequestEntity() since it will probably call
        // this method.
        if (this.requestEntity != null) {
            return getContentCharSet(
                new Header("Content-Type", requestEntity.getContentType()));
        } else {
            return super.getRequestCharSet();
        }
    } else {
        return super.getRequestCharSet();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:24,代码来源:EntityEnclosingMethod.java


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