Package org.apache.http.message

Examples of org.apache.http.message.AbstractHttpMessage


                httpclient.addRequestInterceptor(new PreemptiveAuth(), 0);
                httpContext = localcontext;
            }
        }

        AbstractHttpMessage method = null;

        final HTTPMethod httpMethod = request.getMethod();
        try {
            switch(httpMethod){
                case GET:
                    method = new HttpGet(urlStr);
                    break;
                case POST:
                    method = new HttpPost(urlStr);
                    break;
                case PUT:
                    method = new HttpPut(urlStr);
                    break;
                case DELETE:
                    method = new HttpDelete(urlStr);
                    break;
                case HEAD:
                    method = new HttpHead(urlStr);
                    break;
                case OPTIONS:
                    method = new HttpOptions(urlStr);
                    break;
                case TRACE:
                    method = new HttpTrace(urlStr);
                    break;
            }
            method.setParams(new BasicHttpParams().setParameter(urlStr, url));

            // Get request headers
            MultiValueMap<String, String> header_data = request.getHeaders();
            for (String key : header_data.keySet()) {
                for(String value: header_data.get(key)) {
                    Header header = new BasicHeader(key, value);
                    method.addHeader(header);
                }
            }

            // POST/PUT method specific logic
            if (method instanceof HttpEntityEnclosingRequest) {
View Full Code Here


final class HttpUtil {
    static InputStream getConnectionStream(URL url, Options options) throws IOException{
        if(options != null){
            DefaultHttpClient httpclient = new DefaultHttpClient();
            HttpContext localContext = new BasicHttpContext();
            AbstractHttpMessage method = new HttpGet(url.toString());
            if(options.isHttpAuthEnabled()){
                String username = options.getHttpAuthUsername();
                String password = options.getHttpAuthPassword();
                httpclient.getCredentialsProvider().setCredentials(
                        AuthScope.ANY, new UsernamePasswordCredentials(username, password));
            }
            if(options.isCookiesSet()){
                Map<String, String> cookies = options.getHttpCookies();
                StringBuilder sb = new StringBuilder();
                for(String name: cookies.keySet()){
                    sb.append(name)
                            .append("=")
                            .append(cookies.get(name))
                            .append(";");
                }
                method.addHeader("Cookie", sb.toString());
            }

            HttpResponse http_res = httpclient.execute((HttpUriRequest) method,
                    localContext);
            return new WrappedHttpClientInputStream(http_res, httpclient);
View Full Code Here

TOP

Related Classes of org.apache.http.message.AbstractHttpMessage

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.