Example usage for org.apache.http.client.params ClientPNames ALLOW_CIRCULAR_REDIRECTS

List of usage examples for org.apache.http.client.params ClientPNames ALLOW_CIRCULAR_REDIRECTS

Introduction

In this page you can find the example usage for org.apache.http.client.params ClientPNames ALLOW_CIRCULAR_REDIRECTS.

Prototype

String ALLOW_CIRCULAR_REDIRECTS

To view the source code for org.apache.http.client.params ClientPNames ALLOW_CIRCULAR_REDIRECTS.

Click Source Link

Document

Defines whether circular redirects (redirects to the same location) should be allowed.

Usage

From source file:it.iziozi.iziozi.core.IOApiClient.java

public static void setupClient() {
    client.getHttpClient().getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
}

From source file:com.limewoodmedia.nsdroid.LoadingHelper.java

public static Bitmap loadFlag(String url, Context context) throws ClientProtocolException, IOException {
    if (url == null || url.length() == 0) {
        // No flag to load
        return null;
    }/* www . j av  a2 s  . c om*/
    HttpClient client = new DefaultHttpClient();
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, API.getInstance(context).getUserAgent());
    client.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
    HttpGet get = new HttpGet(url);
    HttpResponse response = client.execute(get);
    InputStream stream = response.getEntity().getContent();
    return BitmapFactory.decodeStream(stream);
}

From source file:com.example.yudiandrean.socioblood.databases.JSONParser.java

public JSONObject getJSONFromUrl(String url, List<NameValuePair> params) {

    // Making HTTP request
    try {//from www  . j  a v  a  2  s  . c  o  m
        // defaultHttpClient
        DefaultHttpClient httpClient = new DefaultHttpClient();
        httpClient.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
        HttpPost httpPost = new HttpPost(url);
        httpPost.setEntity(new UrlEncodedFormEntity(params));

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        is = httpEntity.getContent();

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    try {
        BufferedReader reader = new BufferedReader(new InputStreamReader(is, "iso-8859-1"), 8);
        StringBuilder sb = new StringBuilder();
        String line = null;
        while ((line = reader.readLine()) != null) {
            sb.append(line + "\n");
        }
        is.close();
        json = sb.toString();
        Log.e("JSON", json);
    } catch (Exception e) {
        Log.e("Buffer Error", "Error converting result " + e.toString());
    }

    // try parse the string to a JSON object
    try {
        jObj = new JSONObject(json);
    } catch (JSONException e) {
        Log.e("JSON Parser", "Error parsing data " + e.toString());
    }

    // return JSON String
    return jObj;

}

From source file:info.ajaxplorer.client.http.AjxpHttpClient.java

public AjxpHttpClient(boolean trustSSL) {
    super();/*from  w w w.jav  a2 s.  c o  m*/
    this.trustSelfSignedSSL = trustSSL;
    localContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    this.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);
}

From source file:org.cerberus.util.HTTPSession.java

/**
 * Start a HTTP Session with authorisation
 *
 * @param username/*w  w  w .ja v a 2s.c om*/
 * @param password
 */
public void startSession(String username, String password) {
    // Create your httpclient
    client = new DefaultHttpClient();
    client.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);

    // Then provide the right credentials
    client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT),
            new UsernamePasswordCredentials(username, password));

    // Generate BASIC scheme object and stick it to the execution context
    basicAuth = new BasicScheme();
    context = new BasicHttpContext();
    context.setAttribute("preemptive-auth", basicAuth);

    // Add as the first (because of the zero) request interceptor
    // It will first intercept the request and preemptively initialize the authentication scheme if there is not
    client.addRequestInterceptor(new PreemptiveAuth(), 0);
}

From source file:com.servoy.extensions.plugins.http.HttpClient.java

public HttpClient(IClientPluginAccess plugin) {
    client = new DefaultHttpClient();
    client.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, Boolean.TRUE);
    client.getAuthSchemes().register(AuthPolicy.NTLM, new NTLMSchemeFactory());
    client.getAuthSchemes().register(AuthPolicy.SPNEGO, new NegotiateSchemeFactory());
    this.plugin = plugin;

    try {/*from ww w .  j ava  2 s  . c o  m*/
        final AllowedCertTrustStrategy allowedCertTrustStrategy = new AllowedCertTrustStrategy();
        SSLSocketFactory sf = new SSLSocketFactory(allowedCertTrustStrategy) {
            @Override
            public Socket connectSocket(Socket socket, InetSocketAddress remoteAddress,
                    InetSocketAddress localAddress, HttpParams params)
                    throws IOException, UnknownHostException, ConnectTimeoutException {
                if (socket instanceof SSLSocket) {
                    try {
                        Method s = socket.getClass().getMethod("setHost", String.class);
                        s.invoke(socket, remoteAddress.getHostName());
                    } catch (NoSuchMethodException ex) {
                    } catch (IllegalAccessException ex) {
                    } catch (InvocationTargetException ex) {
                    } catch (IllegalArgumentException ex) {
                    } catch (SecurityException ex) {
                    }
                }
                try {
                    return super.connectSocket(socket, remoteAddress, localAddress, params);
                } catch (SSLPeerUnverifiedException ex) {
                    X509Certificate[] lastCertificates = allowedCertTrustStrategy.getAndClearLastCertificates();
                    if (lastCertificates != null) {
                        // allow for next time
                        if (HttpClient.this.plugin.getApplicationType() == IClientPluginAccess.CLIENT
                                || HttpClient.this.plugin.getApplicationType() == IClientPluginAccess.RUNTIME) {
                            // show dialog
                            CertificateDialog dialog = new CertificateDialog(
                                    ((ISmartRuntimeWindow) HttpClient.this.plugin.getCurrentRuntimeWindow())
                                            .getWindow(),
                                    remoteAddress, lastCertificates);
                            if (dialog.shouldAccept()) {
                                allowedCertTrustStrategy.add(lastCertificates);
                                // try it again now with the new chain.
                                return super.connectSocket(socket, remoteAddress, localAddress, params);
                            }
                        } else {
                            Debug.error("Couldn't connect to " + remoteAddress
                                    + ", please make sure that the ssl certificates of that site are added to the java keystore."
                                    + "Download the keystore in the browser and update the java cacerts file in jre/lib/security: "
                                    + "keytool -import -file downloaded.crt -keystore cacerts");
                        }
                    }
                    throw ex;
                } finally {
                    // always just clear the last request.
                    allowedCertTrustStrategy.getAndClearLastCertificates();
                }

            }
        };
        Scheme https = new Scheme("https", 443, sf); //$NON-NLS-1$
        client.getConnectionManager().getSchemeRegistry().register(https);
    } catch (Exception e) {
        Debug.error("Can't register a https scheme", e); //$NON-NLS-1$
    }
}

From source file:outfox.dict.contest.util.HttpToolKit.java

/**
 * @param maxConnectPerHost/*from  w ww .ja  v  a 2s  . c o  m*/
 * @param maxConnection
 * @param connectTimeOut
 * @param socketTimeOut
 * @param cookiePolicy
 * @param isAutoRetry
 * @param redirect
 */
public HttpToolKit(int maxConnectPerHost, int maxConnection, int connectTimeOut, int socketTimeOut,
        String cookiePolicy, boolean isAutoRetry, boolean redirect) {
    Scheme https = new Scheme("https", 443, SSLSocketFactory.getSocketFactory());
    Scheme http = new Scheme("http", 80, PlainSocketFactory.getSocketFactory());
    SchemeRegistry sr = new SchemeRegistry();
    sr.register(https);
    sr.register(http);

    connectionManager = new PoolingClientConnectionManager(sr, socketTimeOut, TimeUnit.MILLISECONDS);
    connectionManager.setDefaultMaxPerRoute(maxConnectPerHost);
    connectionManager.setMaxTotal(maxConnection);
    HttpParams params = new BasicHttpParams();
    params.setLongParameter(ClientPNames.CONN_MANAGER_TIMEOUT, connectTimeOut);
    params.setParameter(ClientPNames.COOKIE_POLICY, cookiePolicy);
    params.setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, redirect);
    params.setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, false);

    if (isAutoRetry) {
        client = new AutoRetryHttpClient(new DefaultHttpClient(connectionManager, params));
    } else {
        client = new DefaultHttpClient(connectionManager, params);
    }
}

From source file:org.pentaho.reporting.libraries.pensol.vfs.LocalFileModel.java

@Deprecated
public LocalFileModel(final String url, final HttpClient client, final String username, final String password) {
    if (url == null) {
        throw new NullPointerException();
    }/*from   w  w  w  .j  a  va2  s. c  o m*/
    this.url = url;
    this.username = username;
    this.password = password;
    this.client = client;
    this.client.getParams().setParameter(ClientPNames.COOKIE_POLICY, CookiePolicy.BROWSER_COMPATIBILITY);
    this.client.getParams().setParameter(ClientPNames.MAX_REDIRECTS, Integer.valueOf(10));
    this.client.getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, Boolean.TRUE);
    this.client.getParams().setParameter(ClientPNames.REJECT_RELATIVE_REDIRECT, Boolean.FALSE);
    this.context = HttpClientContext.create();
}

From source file:com.abiansoftware.lib.reader.AbianReaderApplication.java

@Override
public void onCreate() {
    s_singleton = this;

    ImageLoader theImageLoader = ImageLoader.getInstance();

    ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
            .threadPoolSize(4).threadPriority(Thread.NORM_PRIORITY - 1).memoryCacheSize(2 * 1024 * 1024)
            .denyCacheImageMultipleSizesInMemory()
            //.enableLogging()
            .build();/*from w ww  . j a va  2  s . c o m*/

    theImageLoader.init(config);

    s_asyncHttpClient = new AsyncHttpClient();
    s_asyncHttpClient.getHttpClient().getParams().setParameter(ClientPNames.ALLOW_CIRCULAR_REDIRECTS, true);

    m_data = new AbianReaderData();
    m_dataFetcher = new AbianReaderDataFetcher();

    WindowManager theWindowManager = (WindowManager) getSystemService(Context.WINDOW_SERVICE);
    Display theDefaultDisplay = theWindowManager.getDefaultDisplay();

    DisplayMetrics theDisplayMetrics = new DisplayMetrics();
    theDefaultDisplay.getMetrics(theDisplayMetrics);
    s_width = theDisplayMetrics.widthPixels;
    s_height = theDisplayMetrics.heightPixels;

    m_handlerVector = new Vector<Handler>();
    m_adapterVector = new Vector<BaseAdapter>();

    m_bSplashScreenHasBeenShown = false;

    m_readUrlArrayList = null;

    loadReadUrlList();

    super.onCreate();
}

From source file:com.mongolduu.android.ng.misc.RedirectHandler.java

public URI getLocationURI(final HttpResponse response, final HttpContext context) throws ProtocolException {
    if (response == null) {
        throw new IllegalArgumentException("HTTP response may not be null");
    }/*from  ww w .  j  av a2s .  c  om*/
    // get the location header to find out where to redirect to
    Header locationHeader = response.getFirstHeader("location");
    if (locationHeader == null) {
        // got a redirect response, but no location header
        throw new ProtocolException(
                "Received redirect response " + response.getStatusLine() + " but no location header");
    }
    // HERE IS THE MODIFIED LINE OF CODE
    String location = locationHeader.getValue().replaceAll(" ", "%20");

    URI uri;
    try {
        uri = new URI(location);
    } catch (URISyntaxException ex) {
        throw new ProtocolException("Invalid redirect URI: " + location, ex);
    }

    HttpParams params = response.getParams();
    // rfc2616 demands the location value be a complete URI
    // Location = "Location" ":" absoluteURI
    if (!uri.isAbsolute()) {
        if (params.isParameterTrue(ClientPNames.REJECT_RELATIVE_REDIRECT)) {
            throw new ProtocolException("Relative redirect location '" + uri + "' not allowed");
        }
        // Adjust location URI
        HttpHost target = (HttpHost) context.getAttribute(ExecutionContext.HTTP_TARGET_HOST);
        if (target == null) {
            throw new IllegalStateException("Target host not available " + "in the HTTP context");
        }

        HttpRequest request = (HttpRequest) context.getAttribute(ExecutionContext.HTTP_REQUEST);

        try {
            URI requestURI = new URI(request.getRequestLine().getUri());
            URI absoluteRequestURI = URIUtils.rewriteURI(requestURI, target, true);
            uri = URIUtils.resolve(absoluteRequestURI, uri);
        } catch (URISyntaxException ex) {
            throw new ProtocolException(ex.getMessage(), ex);
        }
    }

    if (params.isParameterFalse(ClientPNames.ALLOW_CIRCULAR_REDIRECTS)) {

        RedirectLocations redirectLocations = (RedirectLocations) context.getAttribute(REDIRECT_LOCATIONS);

        if (redirectLocations == null) {
            redirectLocations = new RedirectLocations();
            context.setAttribute(REDIRECT_LOCATIONS, redirectLocations);
        }

        URI redirectURI;
        if (uri.getFragment() != null) {
            try {
                HttpHost target = new HttpHost(uri.getHost(), uri.getPort(), uri.getScheme());
                redirectURI = URIUtils.rewriteURI(uri, target, true);
            } catch (URISyntaxException ex) {
                throw new ProtocolException(ex.getMessage(), ex);
            }
        } else {
            redirectURI = uri;
        }

        if (redirectLocations.contains(redirectURI)) {
            throw new CircularRedirectException("Circular redirect to '" + redirectURI + "'");
        } else {
            redirectLocations.add(redirectURI);
        }
    }

    return uri;
}