Search in sources :

Example 11 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project robovm by robovm.

the class BasicHeaderValueParser method parseElements.

// public default constructor
/**
     * Parses elements with the given parser.
     *
     * @param value     the header value to parse
     * @param parser    the parser to use, or <code>null</code> for default
     *
     * @return  array holding the header elements, never <code>null</code>
     */
public static final HeaderElement[] parseElements(final String value, HeaderValueParser parser) throws ParseException {
    if (value == null) {
        throw new IllegalArgumentException("Value to parse may not be null");
    }
    if (parser == null)
        parser = BasicHeaderValueParser.DEFAULT;
    CharArrayBuffer buffer = new CharArrayBuffer(value.length());
    buffer.append(value);
    ParserCursor cursor = new ParserCursor(0, value.length());
    return parser.parseElements(buffer, cursor);
}
Also used : CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Example 12 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project robovm by robovm.

the class BasicHeaderValueParser method parseNameValuePair.

/**
     * Parses a name-value-pair with the given parser.
     *
     * @param value     the NVP to parse
     * @param parser    the parser to use, or <code>null</code> for default
     *
     * @return  the parsed name-value pair
     */
public static final NameValuePair parseNameValuePair(final String value, HeaderValueParser parser) throws ParseException {
    if (value == null) {
        throw new IllegalArgumentException("Value to parse may not be null");
    }
    if (parser == null)
        parser = BasicHeaderValueParser.DEFAULT;
    CharArrayBuffer buffer = new CharArrayBuffer(value.length());
    buffer.append(value);
    ParserCursor cursor = new ParserCursor(0, value.length());
    return parser.parseNameValuePair(buffer, cursor);
}
Also used : CharArrayBuffer(org.apache.http.util.CharArrayBuffer)

Example 13 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project robovm by robovm.

the class BasicLineFormatter method formatHeader.

// non-javadoc, see interface LineFormatter
public CharArrayBuffer formatHeader(CharArrayBuffer buffer, Header header) {
    if (header == null) {
        throw new IllegalArgumentException("Header may not be null");
    }
    CharArrayBuffer result = null;
    if (header instanceof FormattedHeader) {
        // If the header is backed by a buffer, re-use the buffer
        result = ((FormattedHeader) header).getBuffer();
    } else {
        result = initBuffer(buffer);
        doFormatHeader(result, header);
    }
    return result;
}
Also used : CharArrayBuffer(org.apache.http.util.CharArrayBuffer) FormattedHeader(org.apache.http.FormattedHeader)

Example 14 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project robovm by robovm.

the class AbstractAuthenticationHandler method parseChallenges.

protected Map<String, Header> parseChallenges(final Header[] headers) throws MalformedChallengeException {
    Map<String, Header> map = new HashMap<String, Header>(headers.length);
    for (Header header : headers) {
        CharArrayBuffer buffer;
        int pos;
        if (header instanceof FormattedHeader) {
            buffer = ((FormattedHeader) header).getBuffer();
            pos = ((FormattedHeader) header).getValuePos();
        } else {
            String s = header.getValue();
            if (s == null) {
                throw new MalformedChallengeException("Header value is null");
            }
            buffer = new CharArrayBuffer(s.length());
            buffer.append(s);
            pos = 0;
        }
        while (pos < buffer.length() && HTTP.isWhitespace(buffer.charAt(pos))) {
            pos++;
        }
        int beginIndex = pos;
        while (pos < buffer.length() && !HTTP.isWhitespace(buffer.charAt(pos))) {
            pos++;
        }
        int endIndex = pos;
        String s = buffer.substring(beginIndex, endIndex);
        map.put(s.toLowerCase(Locale.ENGLISH), header);
    }
    return map;
}
Also used : Header(org.apache.http.Header) FormattedHeader(org.apache.http.FormattedHeader) HashMap(java.util.HashMap) CharArrayBuffer(org.apache.http.util.CharArrayBuffer) MalformedChallengeException(org.apache.http.auth.MalformedChallengeException) FormattedHeader(org.apache.http.FormattedHeader)

Example 15 with CharArrayBuffer

use of org.apache.http.util.CharArrayBuffer in project robovm by robovm.

the class AuthSchemeBase method processChallenge.

/**
     * Processes the given challenge token. Some authentication schemes
     * may involve multiple challenge-response exchanges. Such schemes must be able 
     * to maintain the state information when dealing with sequential challenges 
     * 
     * @param header the challenge header
     * 
     * @throws MalformedChallengeException is thrown if the authentication challenge
     * is malformed
     */
public void processChallenge(final Header header) throws MalformedChallengeException {
    if (header == null) {
        throw new IllegalArgumentException("Header may not be null");
    }
    String authheader = header.getName();
    if (authheader.equalsIgnoreCase(AUTH.WWW_AUTH)) {
        this.proxy = false;
    } else if (authheader.equalsIgnoreCase(AUTH.PROXY_AUTH)) {
        this.proxy = true;
    } else {
        throw new MalformedChallengeException("Unexpected header name: " + authheader);
    }
    CharArrayBuffer buffer;
    int pos;
    if (header instanceof FormattedHeader) {
        buffer = ((FormattedHeader) header).getBuffer();
        pos = ((FormattedHeader) header).getValuePos();
    } else {
        String s = header.getValue();
        if (s == null) {
            throw new MalformedChallengeException("Header value is null");
        }
        buffer = new CharArrayBuffer(s.length());
        buffer.append(s);
        pos = 0;
    }
    while (pos < buffer.length() && HTTP.isWhitespace(buffer.charAt(pos))) {
        pos++;
    }
    int beginIndex = pos;
    while (pos < buffer.length() && !HTTP.isWhitespace(buffer.charAt(pos))) {
        pos++;
    }
    int endIndex = pos;
    String s = buffer.substring(beginIndex, endIndex);
    if (!s.equalsIgnoreCase(getSchemeName())) {
        throw new MalformedChallengeException("Invalid scheme identifier: " + s);
    }
    parseChallenge(buffer, pos, buffer.length());
}
Also used : CharArrayBuffer(org.apache.http.util.CharArrayBuffer) MalformedChallengeException(org.apache.http.auth.MalformedChallengeException) FormattedHeader(org.apache.http.FormattedHeader)

Aggregations

CharArrayBuffer (org.apache.http.util.CharArrayBuffer)126 BufferedHeader (org.apache.http.message.BufferedHeader)27 FormattedHeader (org.apache.http.FormattedHeader)24 Header (org.apache.http.Header)21 ArrayList (java.util.ArrayList)19 ClientCookie (org.apache.http.cookie.ClientCookie)12 Cookie (org.apache.http.cookie.Cookie)12 ParserCursor (org.apache.http.message.ParserCursor)11 Headers (android.net.http.Headers)6 IOException (java.io.IOException)6 MalformedChallengeException (org.apache.http.auth.MalformedChallengeException)6 MalformedCookieException (org.apache.http.cookie.MalformedCookieException)6 AuthenticationException (org.apache.http.auth.AuthenticationException)5 InvalidCredentialsException (org.apache.http.auth.InvalidCredentialsException)5 BasicNameValuePair (org.apache.http.message.BasicNameValuePair)5 NTCredentials (org.apache.http.auth.NTCredentials)4 HashMap (java.util.HashMap)3 HeaderElement (org.apache.http.HeaderElement)3 NoHttpResponseException (org.apache.http.NoHttpResponseException)3 ParseException (org.apache.http.ParseException)3