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


Java HeaderIterator.hasNext方法代码示例

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


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

示例1: getAllowedMethods

import org.apache.http.HeaderIterator; //导入方法依赖的package包/类
public Set<String> getAllowedMethods(final HttpResponse response) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }

    HeaderIterator it = response.headerIterator("Allow");
    Set<String> methods = new HashSet<String>();
    while (it.hasNext()) {
        Header header = it.nextHeader();
        HeaderElement[] elements = header.getElements();
        for (HeaderElement element : elements) {
            methods.add(element.getName());
        }
    }
    return methods;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:17,代码来源:HttpOptions.java

示例2: getAllowedMethods

import org.apache.http.HeaderIterator; //导入方法依赖的package包/类
public Set<String> getAllowedMethods(final HttpResponse response) {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }
    
    HeaderIterator it = response.headerIterator("Allow");
    Set<String> methods = new HashSet<String>();
    while (it.hasNext()) {
        Header header = it.nextHeader();
        HeaderElement[] elements = header.getElements();
        for (HeaderElement element : elements) {
            methods.add(element.getName());
        }
    }
    return methods;
}
 
开发者ID:tdopires,项目名称:cJUnit-mc626,代码行数:17,代码来源:HttpOptions.java

示例3: buildResponseStr

import org.apache.http.HeaderIterator; //导入方法依赖的package包/类
/**
 * Render the headers and the response content as a string.
 * This could include more things such as the status code.
 * 
 * @param response
 * @return A string consisting of the HTTP Response headers nicely formatted.
 */
 public String buildResponseStr(CloseableHttpResponse response) {
    StringBuilder sb = new StringBuilder();
    
    HeaderIterator hi = response.headerIterator();
    while (hi.hasNext()) {
        Header header = hi.nextHeader();
        sb.append(header.getName()).append(": ").append(header.getValue()).append("\r\n");                        
    }
    sb.append("\r\n");
    try {
        sb.append(EntityUtils.toString(response.getEntity()));            
    } catch (IOException | IllegalStateException ex) {
        // Don't care
    }
    
    return sb.toString();
}
 
开发者ID:TAXIIProject,项目名称:java-taxii,代码行数:25,代码来源:HttpResponseErrorHandler.java

示例4: getAllowedMethods

import org.apache.http.HeaderIterator; //导入方法依赖的package包/类
public Set<String> getAllowedMethods(final HttpResponse response) {
    Args.notNull(response, "HTTP response");

    final HeaderIterator it = response.headerIterator("Allow");
    final Set<String> methods = new HashSet<String>();
    while (it.hasNext()) {
        final Header header = it.nextHeader();
        final HeaderElement[] elements = header.getElements();
        for (final HeaderElement element : elements) {
            methods.add(element.getName());
        }
    }
    return methods;
}
 
开发者ID:xxonehjh,项目名称:remote-files-sync,代码行数:15,代码来源:HttpOptionsHC4.java

示例5: toString

import org.apache.http.HeaderIterator; //导入方法依赖的package包/类
public static String toString(HttpResponse response) throws ParseException, IOException{
	StringBuilder str = new StringBuilder();
	str.append("statusCode:")
		.append(response.getStatusLine().getStatusCode())
		.append("\n");
	HeaderIterator headerIt = response.headerIterator();
	while(headerIt.hasNext()){
		Header header = headerIt.nextHeader();
		str.append(header).append("\n");
	}
	HttpEntity entity = response.getEntity();
	str.append(EntityUtils.toString(entity));
	return str.toString();
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:15,代码来源:HttpClientUtils.java

示例6: printResponse

import org.apache.http.HeaderIterator; //导入方法依赖的package包/类
static void printResponse(HttpResponse response) throws ParseException, IOException{
	System.out.println("statusCode:"+response.getStatusLine().getStatusCode());
	HeaderIterator headerIt = response.headerIterator();
	while(headerIt.hasNext()){
		Header header = headerIt.nextHeader();
		System.out.println(header);
	}
	HttpEntity entity = response.getEntity();
	System.out.println(EntityUtils.toString(entity));
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:11,代码来源:HttpClientTest.java

示例7: handleResponse

import org.apache.http.HeaderIterator; //导入方法依赖的package包/类
@Override
public ProtocolResponse handleResponse(HttpResponse response)
        throws ClientProtocolException, IOException {
    int status = response.getStatusLine().getStatusCode();
    Metadata metadata = new Metadata();
    HeaderIterator iter = response.headerIterator();
    while (iter.hasNext()) {
        Header header = iter.nextHeader();
        metadata.addValue(header.getName().toLowerCase(Locale.ROOT),
                header.getValue());
    }
    // TODO find a way of limiting by maxContent
    byte[] bytes = EntityUtils.toByteArray(response.getEntity());
    return new ProtocolResponse(bytes, status, metadata);
}
 
开发者ID:zaizi,项目名称:alfresco-apache-storm-demo,代码行数:16,代码来源:HttpProtocol.java

示例8: connect

import org.apache.http.HeaderIterator; //导入方法依赖的package包/类
/**
 * execute the real connect action
 * @param httpRequest
 * @return
 */
public String connect(HttpUriRequest httpRequest){
	BufferedReader reader = null;
	try {
		httpClient = new DefaultHttpClient();
		HttpParams params = httpClient.getParams(); 
		//allow auto redirect
		params.setParameter(ClientPNames.HANDLE_REDIRECTS, allowRedirect);
		//set max redirect count
		params.setParameter(ClientPNames.MAX_REDIRECTS, redirectNum);
		httpClient.setParams(params);
		
		HttpResponse response = httpClient.execute(httpRequest);
		//set-cookie header
		Header cookieHeader = response.getFirstHeader("Set-Cookie");
		responseCookies = (cookieHeader==null)?"":cookieHeader.getValue();
		
		statusCode = response.getStatusLine().getStatusCode();
		//set headers
		HeaderIterator iter = response.headerIterator();
		responseHeaders = new HashMap<String,String>();
		while(iter.hasNext()){
			Header header = iter.nextHeader();
			responseHeaders.put(header.getName(), header.getValue());
		}
					
		//处理编码 handle encoding
		InputStream inputStream = response.getEntity().getContent();
		Header typeHeader = response.getEntity().getContentType();
		Header encodingHeader = response.getEntity().getContentEncoding();
		String encoding = "";
		if(encodingHeader!=null){
			encoding = encodingHeader.getValue().trim();
		}else if(typeHeader != null){
			Pattern pattern = Pattern.compile(".*[cC]harset=([a-zA-z0-9-]+).*");
			Matcher matcher = pattern.matcher(typeHeader.getValue());
			if(matcher.find()){
				encoding = matcher.group(1);
			}else{
				encoding = "UTF-8";
			}
		}else{
			encoding = "UTF-8";
		}
		//System.out.println(encoding);
		reader = new BufferedReader(new InputStreamReader(inputStream,encoding));
		String line = "";
		StringBuilder builder = new StringBuilder();
		while((line=reader.readLine())!=null){
			builder.append(line);
		}
		reader.close();
		responseBody = builder.toString();
		//System.err.println(statusCode);
		//System.out.println(responseBody);
		reset();
		
		return responseBody;
	} catch (IOException e) {
		e.printStackTrace();
		if(reader!=null){
			try {
				reader.close();
			} catch (IOException e1) {
				e1.printStackTrace();
			}
		}
		return null;
	} 
}
 
开发者ID:doomdagger,项目名称:jextractor,代码行数:75,代码来源:JExtractorFetchUrl.java

示例9: handleResponse

import org.apache.http.HeaderIterator; //导入方法依赖的package包/类
@Override
public ProtocolResponse handleResponse(HttpResponse response)
        throws IOException {

    StatusLine statusLine = response.getStatusLine();
    int status = statusLine.getStatusCode();

    StringBuilder verbatim = new StringBuilder();
    if (storeHTTPHeaders) {
        verbatim.append(statusLine.toString()).append("\r\n");
    }

    Metadata metadata = new Metadata();
    HeaderIterator iter = response.headerIterator();
    while (iter.hasNext()) {
        Header header = iter.nextHeader();
        if (storeHTTPHeaders) {
            verbatim.append(header.toString()).append("\r\n");
        }
        metadata.addValue(header.getName().toLowerCase(Locale.ROOT),
                header.getValue());
    }

    MutableBoolean trimmed = new MutableBoolean();

    byte[] bytes = new byte[] {};

    if (!Status.REDIRECTION.equals(Status.fromHTTPCode(status))) {
        bytes = HttpProtocol.toByteArray(response.getEntity(), maxContent,
                trimmed);
        if (trimmed.booleanValue()) {
            metadata.setValue("http.trimmed", "true");
            LOG.warn("HTTP content trimmed to {}", bytes.length);
        }
    }

    if (storeHTTPHeaders) {
        verbatim.append("\r\n");
        metadata.setValue("_response.headers_", verbatim.toString());
    }

    return new ProtocolResponse(bytes, status, metadata);
}
 
开发者ID:DigitalPebble,项目名称:storm-crawler,代码行数:44,代码来源:HttpProtocol.java


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