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


Java HeaderElement类代码示例

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


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

示例1: getCharset

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
public String getCharset() {
    String charset = null;
    Header contenttype = this.headers.getFirstHeader("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 DEFAULT_CONTENT_CHARSET;
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:19,代码来源:SimpleRequest.java

示例2: getResponseContentAsReader

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
public static Reader getResponseContentAsReader(@NotNull HttpMethod response) throws IOException {
  //if (!response.hasBeenUsed()) {
  //  return new StringReader("");
  //}
  InputStream stream = response.getResponseBodyAsStream();
  String charsetName = null;
  org.apache.commons.httpclient.Header header = response.getResponseHeader(HTTP.CONTENT_TYPE);
  if (header != null) {
    // find out encoding
    for (HeaderElement part : header.getElements()) {
      NameValuePair pair = part.getParameterByName("charset");
      if (pair != null) {
        charsetName = pair.getValue();
      }
    }
  }
  return new InputStreamReader(stream, charsetName == null ? DEFAULT_CHARSET_NAME : charsetName);
}
 
开发者ID:jskierbi,项目名称:intellij-ce-playground,代码行数:19,代码来源:TaskResponseUtil.java

示例3: create

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
public FileContentInfo create(FileContent fileContent) throws FileSystemException
{
    HttpFileObject httpFile = (HttpFileObject) (FileObjectUtils
        .getAbstractFileObject(fileContent.getFile()));

    String contentType = null;
    String contentEncoding = null;

    Header header = httpFile.getHeadMethod().getResponseHeader("content-type");
    if (header != null)
    {
        HeaderElement[] element = header.getElements();
        if (element != null && element.length > 0)
        {
            contentType = element[0].getName();
        }
    }

    contentEncoding = httpFile.getHeadMethod().getResponseCharSet();

    return new DefaultFileContentInfo(contentType, contentEncoding);
}
 
开发者ID:wso2,项目名称:wso2-commons-vfs,代码行数:23,代码来源:HttpFileContentInfoFactory.java

示例4: getContentCharSet

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
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;
}
 
开发者ID:apache,项目名称:flex-blazeds,代码行数:22,代码来源:FlexGetMethod.java

示例5: getContentCharSet

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
/**
 * Returns the character set from the <tt>Content-Type</tt> header.
 * 
 * @param contentheader
 *            The content header.
 * @return String The character set.
 */
protected String getContentCharSet(final Header contentheader)
{
	String charset = null;
	if (contentheader != null)
	{
		final HeaderElement values[] = contentheader.getElements();
		// I expect only one header element to be there
		// No more. no less
		if (values.length == 1)
		{
			final 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();
	}
	return charset;
}
 
开发者ID:openfurther,项目名称:further-open-core,代码行数:33,代码来源:HttpResponseTo.java

示例6: getResponseContentAsReader

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
public static Reader getResponseContentAsReader(@NotNull HttpMethod response) throws IOException
{
	//if (!response.hasBeenUsed()) {
	//  return new StringReader("");
	//}
	InputStream stream = response.getResponseBodyAsStream();
	String charsetName = null;
	org.apache.commons.httpclient.Header header = response.getResponseHeader(HTTP.CONTENT_TYPE);
	if(header != null)
	{
		// find out encoding
		for(HeaderElement part : header.getElements())
		{
			NameValuePair pair = part.getParameterByName("charset");
			if(pair != null)
			{
				charsetName = pair.getValue();
			}
		}
	}
	return new InputStreamReader(stream, charsetName == null ? DEFAULT_CHARSET_NAME : charsetName);
}
 
开发者ID:consulo,项目名称:consulo-tasks,代码行数:23,代码来源:TaskResponseUtil.java

示例7: StringRequestEntity

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
/**
 * Creates a new entity with the given content, content type, and charset.
 *  
 * @param content The content to set.
 * @param contentType The type of the content, or <code>null</code>.  The value retured 
 *   by {@link #getContentType()}.  If this content type contains a charset and the charset
 *   parameter is null, the content's type charset will be used.
 * @param charset The charset of the content, or <code>null</code>.  Used to convert the 
 *   content to bytes.  If the content type does not contain a charset and charset is not null,
 *   then the charset will be appended to the content type.
 */
public StringRequestEntity(String content, String contentType, String charset) 
    throws UnsupportedEncodingException {
    super();
    if (content == null) {
        throw new IllegalArgumentException("The content cannot be null");
    }
    
    this.contentType = contentType;
    this.charset = charset;
    
    // resolve the content type and the charset
    if (contentType != null) {
        HeaderElement[] values = HeaderElement.parseElements(contentType);
        NameValuePair charsetPair = null;
        for (int i = 0; i < values.length; i++) {
            if ((charsetPair = values[i].getParameterByName("charset")) != null) {
                // charset found
                break;
            }
        }
        if (charset == null && charsetPair != null) {
            // use the charset from the content type
            this.charset = charsetPair.getValue();
        } else if (charset != null && charsetPair == null) {
            // append the charset to the content type
            this.contentType = contentType + "; charset=" + charset; 
        }
    }
    if (this.charset != null) {
        this.content = content.getBytes(this.charset);
    } else {
        this.content = content.getBytes();
    }
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:46,代码来源:StringRequestEntity.java

示例8: getCharset

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
public String getCharset() {
    String charset = DEFAULT_CONTENT_CHARSET;
    Header contenttype = this.headers.getFirstHeader("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;
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:15,代码来源:SimpleResponse.java

示例9: getHeaders

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
public Header[] getHeaders(String targetInstanceName, int harvestResultNumber, HarvestResourceDTO resource) throws DigitalAssetStoreException {
	try {
		WCTSoapCall call = new WCTSoapCall(host, port, service, "getHeaders");
		call.regTypes(Header.class, HarvestResourceDTO.class, ArcHarvestResourceDTO.class, HeaderElement.class, ArcHarvestResultDTO.class, HarvestResultDTO.class, NameValuePair.class);
		Header[] headers = (Header[]) call.invoke(targetInstanceName, harvestResultNumber, resource);
           
        return headers;	   
	}
	catch(Exception ex) {
           throw new DigitalAssetStoreException("Failed to get headers for " + targetInstanceName + " " + harvestResultNumber + ": " + ex.getMessage(), ex);
	}
}
 
开发者ID:DIA-NZ,项目名称:webcurator,代码行数:13,代码来源:DigitalAssetStoreSOAPClient.java

示例10: processCookieHeader

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
private String processCookieHeader(HeaderElement element) {
    String cookie = element.getName() + "=" + element.getValue();
    NameValuePair[] parameters =  element.getParameters();
    for (int j = 0; parameters != null && j < parameters.length; j++) {
        NameValuePair parameter = parameters[j];
        cookie = cookie + "; " + parameter.getName() + "=" + parameter.getValue();
    }
    return cookie;
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:10,代码来源:AbstractHTTPSender.java

示例11: create

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
public FileContentInfo create(FileContent fileContent) throws FileSystemException
{
    HttpFileObject httpFile = (HttpFileObject) (FileObjectUtils
        .getAbstractFileObject(fileContent.getFile()));

    String contentType = null;
    String contentEncoding = null;

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

    contentEncoding = httpFile.getHeadMethod().getResponseCharSet();

    return new DefaultFileContentInfo(contentType, contentEncoding);
}
 
开发者ID:pentaho,项目名称:pdi-vfs,代码行数:31,代码来源:HttpFileContentInfoFactory.java

示例12: parse

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
/**
 * @see #parse(String, int, String, boolean, org.apache.commons.httpclient.Header)
 */
public Cookie[] parse(String host, int port, String path,
                      boolean secure, final String header)
        throws MalformedCookieException {
    LOG.trace("enter RFC2965Spec.parse("
              + "String, int, String, boolean, String)");

    // before we do anything, lets check validity of arguments
    if (host == null) {
        throw new IllegalArgumentException(
                "Host of origin may not be null");
    }
    if (host.trim().equals("")) {
        throw new IllegalArgumentException(
                "Host of origin may not be blank");
    }
    if (port < 0) {
        throw new IllegalArgumentException("Invalid port: " + port);
    }
    if (path == null) {
        throw new IllegalArgumentException(
                "Path of origin may not be null.");
    }
    if (header == null) {
        throw new IllegalArgumentException("Header may not be null.");
    }

    if (path.trim().equals("")) {
        path = PATH_DELIM;
    }
    host = getEffectiveHost(host);

    HeaderElement[] headerElements =
            HeaderElement.parseElements(header.toCharArray());

    List cookies = new LinkedList();
    for (int i = 0; i < headerElements.length; i++) {
        HeaderElement headerelement = headerElements[i];
        Cookie2 cookie = null;
        try {
            cookie = new Cookie2(host,
                                headerelement.getName(),
                                headerelement.getValue(),
                                path,
                                null,
                                false,
                                new int[] {port});
        } catch (IllegalArgumentException ex) {
            throw new MalformedCookieException(ex.getMessage());
        }
        NameValuePair[] parameters = headerelement.getParameters();
        // could be null. In case only a header element and no parameters.
        if (parameters != null) {
            // Eliminate duplicate attribues. The first occurence takes precedence
            Map attribmap = new HashMap(parameters.length); 
            for (int j = parameters.length - 1; j >= 0; j--) {
                NameValuePair param = parameters[j];
                attribmap.put(param.getName().toLowerCase(), param);
            }
            for (Iterator it = attribmap.entrySet().iterator(); it.hasNext(); ) {
                Map.Entry entry = (Map.Entry) it.next();
                parseAttribute((NameValuePair) entry.getValue(), cookie);
            }
        }
        cookies.add(cookie);
        // cycle through the parameters
    }
    return (Cookie[]) cookies.toArray(new Cookie[cookies.size()]);
}
 
开发者ID:jenkinsci,项目名称:lib-commons-httpclient,代码行数:72,代码来源:RFC2965Spec.java

示例13: authenticate

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
public String authenticate(String url, String host, Integer port, String realm, String userName, String password) {

        Validate.notEmpty(url, "url must not be empty");
        Validate.notEmpty(host, "host must not be empty");
        Validate.notNull(port, "port must not be empty");
        Validate.notEmpty(userName, "userName must not be empty");
        Validate.notEmpty(password, "password must not be empty");

        try {

            HttpClient client = new HttpClient();

            GetMethod getMethod = new GetMethod(url);

            int status = client.executeMethod(getMethod);
            if (LOG.isDebugEnabled()) LOG.debug("status: {}", status);
            String responseBody = getMethod.getResponseBodyAsString();
            if (LOG.isDebugEnabled()) LOG.debug("responseBody: {}", responseBody);

            Header wwAuthHeader = getMethod.getResponseHeader(WWW_AUTHENTICATE);
            for (HeaderElement element : wwAuthHeader.getElements()) {
                if (LOG.isDebugEnabled()) LOG.debug(element.getName() + " : " + element.getValue());
            }

            UsernamePasswordCredentials upc = new UsernamePasswordCredentials(userName, password);
            AuthScope as = new AuthScope(host, port, realm);
            client.getState().setCredentials(as, upc);
            status = client.executeMethod(getMethod);
            if (LOG.isDebugEnabled()) LOG.debug("status: {}", status);
            responseBody = getMethod.getResponseBodyAsString();
            if (LOG.isDebugEnabled()) LOG.debug("responseBody: {}", responseBody);

            getMethod.releaseConnection();

            return responseBody;

        } catch (Exception e) {
            LOG.error("Error:", e);
        }
        return null;
    }
 
开发者ID:nkasvosve,项目名称:beyondj,代码行数:42,代码来源:HttpDigestAuthClient.java

示例14: obtainHTTPHeaderInformation

import org.apache.commons.httpclient.HeaderElement; //导入依赖的package包/类
/**
 * Collect the HTTP header information and set them in the message context
 *
 * @param method HttpMethodBase from which to get information
 * @param msgContext the MessageContext in which to place the information... OR NOT!
 * @throws AxisFault if problems occur
 */
protected void obtainHTTPHeaderInformation(HttpMethodBase method,
                                           MessageContext msgContext) throws AxisFault {
    // Set RESPONSE properties onto the REQUEST message context.  They will need to be copied off the request context onto
    // the response context elsewhere, for example in the OutInOperationClient.
    Map transportHeaders = new CommonsTransportHeaders(method.getResponseHeaders());
    msgContext.setProperty(MessageContext.TRANSPORT_HEADERS, transportHeaders);
    msgContext.setProperty(HTTPConstants.MC_HTTP_STATUS_CODE, new Integer(method.getStatusCode()));
    Header header = method.getResponseHeader(HTTPConstants.HEADER_CONTENT_TYPE);

    if (header != null) {
        HeaderElement[] headers = header.getElements();
        MessageContext inMessageContext = msgContext.getOperationContext().getMessageContext(
                WSDLConstants.MESSAGE_LABEL_IN_VALUE);

        Object contentType = header.getValue();
        Object charSetEnc = null;

        for (int i = 0; i < headers.length; i++) {
            NameValuePair charsetEnc = headers[i].getParameterByName(
                    HTTPConstants.CHAR_SET_ENCODING);
            if (charsetEnc != null) {
                charSetEnc = charsetEnc.getValue();
            }
        }

        if (inMessageContext != null) {
            inMessageContext
                    .setProperty(Constants.Configuration.CONTENT_TYPE, contentType);
            inMessageContext
                    .setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
        } else {

            // Transport details will be stored in a HashMap so that anybody interested can
            // retrieve them
            HashMap transportInfoMap = new HashMap();
            transportInfoMap.put(Constants.Configuration.CONTENT_TYPE, contentType);
            transportInfoMap.put(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);

            //the HashMap is stored in the outgoing message.
            msgContext.setProperty(Constants.Configuration.TRANSPORT_INFO_MAP,
                                   transportInfoMap);
        }
    }

    String sessionCookie = null;
    // Process old style headers first
    Header[] cookieHeaders = method.getResponseHeaders(HTTPConstants.HEADER_SET_COOKIE);
    String customCoookiId = (String) msgContext.getProperty(Constants.CUSTOM_COOKIE_ID);
    // process all the cookieHeaders, when load balancer is fronted it may require some cookies to function.
    sessionCookie = processCookieHeaders(cookieHeaders);

    // Overwrite old style cookies with new style ones if present
    cookieHeaders = method.getResponseHeaders(HTTPConstants.HEADER_SET_COOKIE2);
    for (int i = 0; i < cookieHeaders.length; i++) {
        HeaderElement[] elements = cookieHeaders[i].getElements();
        for (int e = 0; e < elements.length; e++) {
            HeaderElement element = elements[e];
            if (Constants.SESSION_COOKIE.equalsIgnoreCase(element.getName()) ||
                    Constants.SESSION_COOKIE_JSESSIONID.equalsIgnoreCase(element.getName())) {
                sessionCookie = processCookieHeader(element);
            }
            if(customCoookiId!=null&&customCoookiId.equalsIgnoreCase(element.getName())){
                sessionCookie = processCookieHeader(element);
            }
        }
    }

    if (sessionCookie != null && !sessionCookie.isEmpty()) {
        msgContext.getServiceContext().setProperty(HTTPConstants.COOKIE_STRING, sessionCookie);
    }
}
 
开发者ID:wso2,项目名称:wso2-axis2,代码行数:79,代码来源:AbstractHTTPSender.java


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