Example usage for org.apache.http.entity HttpEntityWrapper HttpEntityWrapper

List of usage examples for org.apache.http.entity HttpEntityWrapper HttpEntityWrapper

Introduction

In this page you can find the example usage for org.apache.http.entity HttpEntityWrapper HttpEntityWrapper.

Prototype

public HttpEntityWrapper(HttpEntity httpEntity) 

Source Link

Usage

From source file:groovyx.net.http.ParserRegistry.java

/**
 * Default parser used to decode a URL-encoded response.
 * @see ContentType#URLENC/*w w w.j  ava  2  s. c om*/
 * @param resp
 * @return
 * @throws IOException
 */
public Map<String, String> parseForm(final HttpResponse resp) throws IOException {
    HttpEntity entity = resp.getEntity();
    /* URLEncodedUtils won't parse the content unless the content-type is
       application/x-www-form-urlencoded.  Since we want to be able to force
       parsing regardless of what the content-type header says, we need to
       'spoof' the content-type if it's not already acceptable. */
    if (!ContentType.URLENC.toString().equals(ParserRegistry.getContentType(resp))) {
        entity = new HttpEntityWrapper(entity) {
            @Override
            public org.apache.http.Header getContentType() {
                String value = ContentType.URLENC.toString();
                String charset = ParserRegistry.getCharset(resp);
                if (charset != null)
                    value += "; charset=" + charset;
                return new BasicHeader("Content-Type", value);
            };
        };
    }
    List<NameValuePair> params = URLEncodedUtils.parse(entity);
    Map<String, String> paramMap = new HashMap<String, String>(params.size());
    for (NameValuePair param : params)
        paramMap.put(param.getName(), param.getValue());
    return paramMap;
}