Example usage for org.apache.http.params BasicHttpParams BasicHttpParams

List of usage examples for org.apache.http.params BasicHttpParams BasicHttpParams

Introduction

In this page you can find the example usage for org.apache.http.params BasicHttpParams BasicHttpParams.

Prototype

public BasicHttpParams() 

Source Link

Usage

From source file:cn.clxy.codes.upload.ApacheHCUploader.java

/**
 * The timeout should be adjusted by network condition.
 * @return//  w  w w .j  a  v  a  2  s  .  co m
 */
private static HttpClient createClient() {

    SchemeRegistry schReg = new SchemeRegistry();
    schReg.register(new Scheme("http", 80, PlainSocketFactory.getSocketFactory()));
    schReg.register(new Scheme("https", 443, SSLSocketFactory.getSocketFactory()));

    PoolingClientConnectionManager ccm = new PoolingClientConnectionManager(schReg);
    ccm.setMaxTotal(Config.MAX_UPLOAD);

    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 10 * 1000);
    HttpConnectionParams.setSoTimeout(params, Config.PART_UPLOAD_TIMEOUT);

    return new DefaultHttpClient(ccm, params);
}

From source file:com.flowzr.budget.holo.export.flowzr.FlowzrSyncTask.java

public FlowzrSyncTask(Context context) {
    this.context = context;

    BasicHttpParams params = new BasicHttpParams();
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    schemeRegistry.register(new Scheme("https", (SocketFactory) sslSocketFactory, 443));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    this.http_client = new DefaultHttpClient(cm, params);
    this.dba = new DatabaseAdapter(context);
}

From source file:org.geomajas.gwt2.example.base.server.mvc.AjaxProxyController.java

@RequestMapping(value = "/")
public final void proxyAjaxCall(@RequestParam(required = true, value = "url") String url,
        HttpServletRequest request, HttpServletResponse response) throws IOException {

    // URL needs to be url decoded
    url = URLDecoder.decode(url, "utf-8");

    HttpClient client = new DefaultHttpClient();
    try {/*from  w w w  .j a va  2s. com*/
        HttpRequestBase proxyRequest;

        // Split this according to the type of request
        if ("GET".equals(request.getMethod())) {
            Enumeration<?> paramNames = request.getParameterNames();
            while (paramNames.hasMoreElements()) {
                String paramName = (String) paramNames.nextElement();
                if (!paramName.equalsIgnoreCase("url")) {
                    url = addParam(url, paramName, request.getParameter(paramName));
                }
            }

            proxyRequest = new HttpGet(url);
        } else if ("POST".equals(request.getMethod())) {
            proxyRequest = new HttpPost(url);

            // Set any eventual parameters that came with our original
            HttpParams params = new BasicHttpParams();
            Enumeration<?> paramNames = request.getParameterNames();
            while (paramNames.hasMoreElements()) {
                String paramName = (String) paramNames.nextElement();
                if (!"url".equalsIgnoreCase("url")) {
                    params.setParameter(paramName, request.getParameter(paramName));
                }
            }
            proxyRequest.setParams(params);
        } else {
            throw new NotImplementedException("This proxy only supports GET and POST methods.");
        }

        // Execute the method
        HttpResponse proxyResponse = client.execute(proxyRequest);

        // Set the content type, as it comes from the server
        Header[] headers = proxyResponse.getAllHeaders();
        for (Header header : headers) {
            if ("Content-Type".equalsIgnoreCase(header.getName())) {
                response.setContentType(header.getValue());
            }
        }

        // Write the body, flush and close
        proxyResponse.getEntity().writeTo(response.getOutputStream());
    } catch (IOException e) {
        e.printStackTrace();
        throw e;
    }
}

From source file:com.cloudant.sync.datastore.SavedHttpAttachment.java

@Override
public InputStream getInputStream() throws IOException {
    if (data == null) {
        HttpRequests requests = new HttpRequests(new BasicHttpParams(), null, null, null);
        if (encoding == Encoding.Gzip) {
            return new GZIPInputStream(requests.getCompressed(attachmentURI));
        } else {//from  w  ww  .j ava  2s . c om
            return requests.get(attachmentURI);
        }
    } else {
        return new ByteArrayInputStream(data);
    }

}

From source file:com.adamrosenfield.wordswithcrosses.versions.DefaultUtil.java

public DefaultUtil() {
    // Set default connect and recv timeouts to 30 seconds
    mHttpParams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(mHttpParams, 30000);
    HttpConnectionParams.setSoTimeout(mHttpParams, 30000);

    mHttpClient = new DefaultHttpClient(mHttpParams);
}

From source file:org.piraso.io.impl.HttpEntrySource.java

private void initReader() {
    alive = false;/*from  www .j a  v  a  2 s .  c  o m*/

    ThreadSafeClientConnManager manager = new ThreadSafeClientConnManager();
    manager.setDefaultMaxPerRoute(2);
    manager.setMaxTotal(2);

    HttpParams params = new BasicHttpParams();

    // set timeout
    HttpConnectionParamBean connParamBean = new HttpConnectionParamBean(params);
    connParamBean.setConnectionTimeout(3000);
    connParamBean.setSoTimeout(1000 * 60 * 120);

    HttpClient client = new DefaultHttpClient(manager, params);
    HttpContext context = new BasicHttpContext();

    this.reader = new HttpPirasoEntryReader(client, context);

    reader.setUri(uri);
    reader.getStartHandler().setPreferences(preferences);

    if (watchedAddr != null) {
        reader.getStartHandler().setWatchedAddr(watchedAddr);
    }
}

From source file:org.transdroid.search.Fenopy.FenopyAdapter.java

@Override
public List<SearchResult> search(Context context, String query, SortOrder order, int maxResults)
        throws Exception {

    if (query == null) {
        return null;
    }// w ww .  j  a v a  2s  .com

    // Build search URL
    String url = String.format(RPC_QUERYURL, URLEncoder.encode(query, "UTF-8"),
            order == SortOrder.BySeeders ? RPC_SORT_SEEDS : RPC_SORT_COMPOSITE, String.valueOf(maxResults));

    // Setup HTTP client
    HttpParams httpparams = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(httpparams, CONNECTION_TIMEOUT);
    HttpConnectionParams.setSoTimeout(httpparams, CONNECTION_TIMEOUT);
    DefaultHttpClient httpclient = new DefaultHttpClient(httpparams);

    // Make request
    HttpResponse response = httpclient.execute(new HttpGet(url));

    // Read JSON response
    InputStream instream = response.getEntity().getContent();
    JSONArray json = new JSONArray(HttpHelper.ConvertStreamToString(instream));
    instream.close();

    // Add search results
    List<SearchResult> results = new ArrayList<SearchResult>();
    for (int i = 0; i < json.length(); i++) {
        JSONObject item = json.getJSONObject(i);
        results.add(new SearchResult(item.getString("name"), item.getString("torrent"), item.getString("page"),
                FileSizeConverter.getSize(item.getLong("size")), null, item.getInt("seeder"),
                item.getInt("leecher")));
    }

    // Return the results list
    return results;

}

From source file:org.apache.hadoop.gateway.dispatch.DefaultDispatchTest.java

@Test
public void testJiraKnox58() throws URISyntaxException, IOException {

    URI uri = new URI("http://unreachable-host");
    BasicHttpParams params = new BasicHttpParams();

    HttpUriRequest outboundRequest = EasyMock.createNiceMock(HttpUriRequest.class);
    EasyMock.expect(outboundRequest.getMethod()).andReturn("GET").anyTimes();
    EasyMock.expect(outboundRequest.getURI()).andReturn(uri).anyTimes();
    EasyMock.expect(outboundRequest.getParams()).andReturn(params).anyTimes();

    HttpServletRequest inboundRequest = EasyMock.createNiceMock(HttpServletRequest.class);

    HttpServletResponse outboundResponse = EasyMock.createNiceMock(HttpServletResponse.class);
    EasyMock.expect(outboundResponse.getOutputStream())
            .andAnswer(new IAnswer<SynchronousServletOutputStreamAdapter>() {
                @Override/*from w  w w  .j a  v a  2s .  c o m*/
                public SynchronousServletOutputStreamAdapter answer() throws Throwable {
                    return new SynchronousServletOutputStreamAdapter() {
                        @Override
                        public void write(int b) throws IOException {
                            throw new IOException("unreachable-host");
                        }
                    };
                }
            });

    EasyMock.replay(outboundRequest, inboundRequest, outboundResponse);

    DefaultDispatch dispatch = new DefaultDispatch();
    dispatch.setHttpClient(new DefaultHttpClient());
    try {
        dispatch.executeRequest(outboundRequest, inboundRequest, outboundResponse);
        fail("Should have thrown IOException");
    } catch (IOException e) {
        assertThat(e.getMessage(), not(containsString("unreachable-host")));
        assertThat(e, not(instanceOf(UnknownHostException.class)));
        assertThat("Message needs meaningful content.", e.getMessage().trim().length(), greaterThan(12));
    }
}

From source file:com.mykola.lexinproject.providers.LexinTranslator.java

public LexinTranslator(TranslationManagerCallback cb) {
    super(cb);// ww  w . java2  s . c o  m
    HttpParams params = new BasicHttpParams();
    HttpConnectionParams.setConnectionTimeout(params, 40 * 1000);
    HttpConnectionParams.setSoTimeout(params, 40 * 1000);
    ConnManagerParams.setMaxTotalConnections(params, 100);
    HttpProtocolParams.setVersion(params, HttpVersion.HTTP_1_1);
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    mHttpClient = new DefaultHttpClient(cm, params);
}

From source file:com.phonty.improved.Balance.java

public Balance(String url, Context _context) {
    context = _context;//  w w  w .  j  av  a2s  . c  om
    APIURL = url;
    httppost = new HttpPost(APIURL);
    BasicHttpParams params = new BasicHttpParams();
    SchemeRegistry schemeRegistry = new SchemeRegistry();
    schemeRegistry.register(new Scheme("http", PlainSocketFactory.getSocketFactory(), 80));
    final SSLSocketFactory sslSocketFactory = SSLSocketFactory.getSocketFactory();
    schemeRegistry.register(new Scheme("https", sslSocketFactory, 4711));
    ClientConnectionManager cm = new ThreadSafeClientConnManager(params, schemeRegistry);
    client = new PhontyHttpClient(cm, params, context);
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "Phonty-Android-Client");
}