org.apache.commons.httpclient.Header.getElements()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(191)

本文整理了Java中org.apache.commons.httpclient.Header.getElements()方法的一些代码示例,展示了Header.getElements()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Header.getElements()方法的具体详情如下:
包路径:org.apache.commons.httpclient.Header
类名称:Header
方法名:getElements

Header.getElements介绍

[英]Returns an array of HeaderElements constructed from my value.
[中]返回由my值构造的HeaderElements数组。

代码示例

代码示例来源:origin: commons-httpclient/commons-httpclient

/**
 * Returns the character set from the <tt>Content-Type</tt> header.
 * 
 * @param contentheader The content header.
 * @return String The character set.
 */
protected String getContentCharSet(Header contentheader) {
  LOG.trace("enter getContentCharSet( Header contentheader )");
  String charset = null;
  if (contentheader != null) {
    HeaderElement values[] = contentheader.getElements();
    // I expect only one header element to be there
    // No more. no less
    if (values.length == 1) {
      NameValuePair param = values[0].getParameterByName("charset");
      if (param != null) {
        // If I get anything "funny" 
        // UnsupportedEncondingException will result
        charset = param.getValue();
      }
    }
  }
  if (charset == null) {
    charset = getParams().getContentCharset();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Default charset used: " + charset);
    }
  }
  return charset;
}

代码示例来源:origin: commons-httpclient/commons-httpclient

HeaderElement[] encodings = transferEncodingHeader.getElements();

代码示例来源:origin: apache/axis2-java

@Override
public Map<String,String> getCookies() {
  Map<String,String> cookies = null;
  for (String name : COOKIE_HEADER_NAMES) {
    for (org.apache.commons.httpclient.Header header : method.getResponseHeaders(name)) {
      for (HeaderElement element : header.getElements()) {
        if (cookies == null) {
          cookies = new HashMap<String,String>();
        }
        cookies.put(element.getName(), element.getValue());
      }
    }
  }
  return cookies;
}

代码示例来源:origin: com.adobe.flex/com.springsource.flex.messaging.services.http

protected String getContentCharSet(Header contentheader)
  {
    String charset = null;
    if (contentheader != null)
    {
      HeaderElement values[] = contentheader.getElements();
      if (values.length == 1)
      {
        NameValuePair param = values[0].getParameterByName("charset");
        if (param != null)
        {
          charset = param.getValue();
        }
      }
    }
    if (charset == null)
    {
      charset = "UTF-8";
    }
    return charset;
  }
}

代码示例来源:origin: com.adobe.flex/com.springsource.flex.messaging.services.http

protected String getContentCharSet(Header contentheader)
  {
    String charset = null;
    if (contentheader != null)
    {
      HeaderElement values[] = contentheader.getElements();
      if (values.length == 1)
      {
        NameValuePair param = values[0].getParameterByName("charset");
        if (param != null)
        {
          charset = param.getValue();
        }
      }
    }
    if (charset == null)
    {
      charset = "UTF-8";
    }
    return charset;
  }
}

代码示例来源:origin: org.mule.transports/mule-transport-http

private String getEncoding(Map<String, Object> headers)
{
  String encoding = DEFAULT_ENCODING;
  Object contentType = headers.get(HttpConstants.HEADER_CONTENT_TYPE);
  if (contentType != null)
  {
    // use HttpClient classes to parse the charset part from the Content-Type
    // header (e.g. "text/html; charset=UTF-16BE")
    Header contentTypeHeader = new Header(HttpConstants.HEADER_CONTENT_TYPE,
                       contentType.toString());
    HeaderElement values[] = contentTypeHeader.getElements();
    if (values.length == 1)
    {
      NameValuePair param = values[0].getParameterByName("charset");
      if (param != null)
      {
        encoding = param.getValue();
      }
    }
  }
  return encoding;
}

代码示例来源:origin: apache/flex-blazeds

protected String getContentCharSet(Header contentheader)
  {
    String charset = null;
    if (contentheader != null)
    {
      HeaderElement values[] = contentheader.getElements();
      if (values.length == 1)
      {
        NameValuePair param = values[0].getParameterByName("charset");
        if (param != null)
        {
          charset = param.getValue();
        }
      }
    }
    if (charset == null)
    {
      charset = "UTF-8";
    }
    return charset;
  }
}

代码示例来源:origin: apache/flex-blazeds

protected String getContentCharSet(Header contentheader)
  {
    String charset = null;
    if (contentheader != null)
    {
      HeaderElement values[] = contentheader.getElements();
      if (values.length == 1)
      {
        NameValuePair param = values[0].getParameterByName("charset");
        if (param != null)
        {
          charset = param.getValue();
        }
      }
    }
    if (charset == null)
    {
      charset = "UTF-8";
    }
    return charset;
  }
}

代码示例来源:origin: franzinc/agraph-java-client

/**
 * Gets the MIME type specified in the response headers of the supplied
 * method, if any. For example, if the response headers contain
 * <tt>Content-Type: application/xml;charset=UTF-8</tt>, this method will
 * return <tt>application/xml</tt> as the MIME type.
 *
 * @param method the method to get the reponse MIME type from
 * @return the response MIME type, or <tt>null</tt> if not available
 */
protected String getResponseMIMEType(HttpMethod method) throws IOException {
  Header[] headers = method.getResponseHeaders("Content-Type");
  for (Header header : headers) {
    HeaderElement[] headerElements = header.getElements();
    for (HeaderElement headerEl : headerElements) {
      String mimeType = headerEl.getName();
      if (mimeType != null) {
        // TODO: logger.debug("response MIME type is {}", mimeType);
        return mimeType;
      }
    }
  }
  return null;
}

代码示例来源:origin: harikrishnan83/rapa

private void insertToCache(HttpMethodBase method, String key, String value) {
  HeaderElement[] cacheControlHeaderElements = method.getResponseHeader(
      "Cache-Control").getElements();
  int maxAge = getMaxAge(cacheControlHeaderElements);
  if (maxAge > 0) {
    Element element = new Element(key, value);
    element.setTimeToLive(maxAge);
    cache.put(element);
  }
}

代码示例来源:origin: org.apache.servicemix.bundles/org.apache.servicemix.bundles.commons-httpclient

/**
 * Returns the character set from the <tt>Content-Type</tt> header.
 * 
 * @param contentheader The content header.
 * @return String The character set.
 */
protected String getContentCharSet(Header contentheader) {
  LOG.trace("enter getContentCharSet( Header contentheader )");
  String charset = null;
  if (contentheader != null) {
    HeaderElement values[] = contentheader.getElements();
    // I expect only one header element to be there
    // No more. no less
    if (values.length == 1) {
      NameValuePair param = values[0].getParameterByName("charset");
      if (param != null) {
        // If I get anything "funny" 
        // UnsupportedEncondingException will result
        charset = param.getValue();
      }
    }
  }
  if (charset == null) {
    charset = getParams().getContentCharset();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Default charset used: " + charset);
    }
  }
  return charset;
}

代码示例来源:origin: org.apache.commons/httpclient

/**
 * Returns the character set from the <tt>Content-Type</tt> header.
 * 
 * @param contentheader The content header.
 * @return String The character set.
 */
protected String getContentCharSet(Header contentheader) {
  LOG.trace("enter getContentCharSet( Header contentheader )");
  String charset = null;
  if (contentheader != null) {
    HeaderElement values[] = contentheader.getElements();
    // I expect only one header element to be there
    // No more. no less
    if (values.length == 1) {
      NameValuePair param = values[0].getParameterByName("charset");
      if (param != null) {
        // If I get anything "funny" 
        // UnsupportedEncondingException will result
        charset = param.getValue();
      }
    }
  }
  if (charset == null) {
    charset = getParams().getContentCharset();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Default charset used: " + charset);
    }
  }
  return charset;
}

代码示例来源:origin: org.apache.commons/com.springsource.org.apache.commons.httpclient

/**
 * Returns the character set from the <tt>Content-Type</tt> header.
 * 
 * @param contentheader The content header.
 * @return String The character set.
 */
protected String getContentCharSet(Header contentheader) {
  LOG.trace("enter getContentCharSet( Header contentheader )");
  String charset = null;
  if (contentheader != null) {
    HeaderElement values[] = contentheader.getElements();
    // I expect only one header element to be there
    // No more. no less
    if (values.length == 1) {
      NameValuePair param = values[0].getParameterByName("charset");
      if (param != null) {
        // If I get anything "funny" 
        // UnsupportedEncondingException will result
        charset = param.getValue();
      }
    }
  }
  if (charset == null) {
    charset = getParams().getContentCharset();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Default charset used: " + charset);
    }
  }
  return charset;
}

代码示例来源:origin: org.zaproxy/zap

/**
 * Returns the character set from the <tt>Content-Type</tt> header.
 * 
 * @param contentheader The content header.
 * @return String The character set.
 */
protected String getContentCharSet(Header contentheader) {
  LOG.trace("enter getContentCharSet( Header contentheader )");
  String charset = null;
  if (contentheader != null) {
    HeaderElement values[] = contentheader.getElements();
    // I expect only one header element to be there
    // No more. no less
    if (values.length == 1) {
      NameValuePair param = values[0].getParameterByName("charset");
      if (param != null) {
        // If I get anything "funny" 
        // UnsupportedEncondingException will result
        charset = param.getValue();
      }
    }
  }
  if (charset == null) {
    charset = getParams().getContentCharset();
    if (LOG.isDebugEnabled()) {
      LOG.debug("Default charset used: " + charset);
    }
  }
  return charset;
}

代码示例来源:origin: org.mule.transports/mule-transport-http

public String getCharset()
{
  String charset = null;
  Header contenttype = this.headers.getFirstHeader(HttpConstants.HEADER_CONTENT_TYPE);
  if (contenttype != null)
  {
    HeaderElement values[] = contenttype.getElements();
    if (values.length == 1)
    {
      NameValuePair param = values[0].getParameterByName("charset");
      if (param != null)
      {
        charset = param.getValue();
      }
    }
  }
  if (charset != null)
  {
    return charset;
  }
  else
  {
    return defaultEncoding;
  }
}

代码示例来源:origin: org.mule.transports/mule-transport-http

public String getCharset()
{
  String charset = getFallbackCharset();
  Header contenttype = this.headers.getFirstHeader(HttpConstants.HEADER_CONTENT_TYPE);
  if (contenttype != null)
  {
    HeaderElement values[] = contenttype.getElements();
    if (values.length == 1)
    {
      NameValuePair param = values[0].getParameterByName("charset");
      if (param != null)
      {
        charset = param.getValue();
      }
    }
  }
  return charset;
}

代码示例来源:origin: org.openrdf.alibaba/alibaba-repository-sparql

private RDFParser getParser(HttpMethod response) {
    for (Header header : response.getResponseHeaders("Content-Type")) {
      for (HeaderElement headerEl : header.getElements()) {
        String mimeType = headerEl.getName();
        if (mimeType != null) {
          RDFFormat format = registry
              .getFileFormatForMIMEType(mimeType);
          RDFParserFactory factory = registry.get(format);
          if (factory != null)
            return factory.getParser();
        }
      }
    }
    throw new UnsupportedQueryResultFormatException(
        "No parser factory available for this graph query result format");
  }
}

代码示例来源:origin: org.apache.commons/commons-vfs2

@Override
  public FileContentInfo create(final FileContent fileContent) throws FileSystemException {
    final HttpFileObject httpFile = (HttpFileObject) FileObjectUtils.getAbstractFileObject(fileContent.getFile());

    String contentType = null;
    String contentEncoding = null;

    HeadMethod headMethod;
    try {
      headMethod = httpFile.getHeadMethod();
    } catch (final IOException e) {
      throw new FileSystemException(e);
    }
    final Header header = headMethod.getResponseHeader("content-type");
    if (header != null) {
      final HeaderElement[] element = header.getElements();
      if (element != null && element.length > 0) {
        contentType = element[0].getName();
      }
    }

    contentEncoding = headMethod.getResponseCharSet();

    return new DefaultFileContentInfo(contentType, contentEncoding);
  }
}

代码示例来源:origin: com.github.abashev/commons-vfs2

@Override
  public FileContentInfo create(final FileContent fileContent) throws FileSystemException {
    final HttpFileObject httpFile = (HttpFileObject) FileObjectUtils.getAbstractFileObject(fileContent.getFile());

    String contentType = null;
    String contentEncoding = null;

    HeadMethod headMethod;
    try {
      headMethod = httpFile.getHeadMethod();
    } catch (final IOException e) {
      throw new FileSystemException(e);
    }
    final Header header = headMethod.getResponseHeader("content-type");
    if (header != null) {
      final HeaderElement[] element = header.getElements();
      if (element != null && element.length > 0) {
        contentType = element[0].getName();
      }
    }

    contentEncoding = headMethod.getResponseCharSet();

    return new DefaultFileContentInfo(contentType, contentEncoding);
  }
}

代码示例来源:origin: apache/commons-vfs

@Override
  public FileContentInfo create(final FileContent fileContent) throws FileSystemException {

    String contentType = null;
    String contentEncoding = null;

    HeadMethod headMethod;
    try (final HttpFileObject<HttpFileSystem> httpFile = (HttpFileObject<HttpFileSystem>) FileObjectUtils
        .getAbstractFileObject(fileContent.getFile())) {
      headMethod = httpFile.getHeadMethod();
    } catch (final IOException e) {
      throw new FileSystemException(e);
    }
    final Header header = headMethod.getResponseHeader("content-type");
    if (header != null) {
      final HeaderElement[] element = header.getElements();
      if (element != null && element.length > 0) {
        contentType = element[0].getName();
      }
    }

    contentEncoding = headMethod.getResponseCharSet();

    return new DefaultFileContentInfo(contentType, contentEncoding);
  }
}

相关文章