Example usage for org.apache.http.params CoreProtocolPNames USER_AGENT

List of usage examples for org.apache.http.params CoreProtocolPNames USER_AGENT

Introduction

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

Prototype

String USER_AGENT

To view the source code for org.apache.http.params CoreProtocolPNames USER_AGENT.

Click Source Link

Usage

From source file:com.mobicage.rogerthat.plugins.scan.ScanCommunication.java

private Header getUserAgentHeader() {
    final String userAgentHeaderValue = USER_AGENT + " (1." + mMainService.getMajorVersion() + "."
            + mMainService.getMinorVersion() + ")";
    return new BasicHeader(CoreProtocolPNames.USER_AGENT, userAgentHeaderValue);
}

From source file:com.github.ajasmin.telususageandroidwidget.TelusReportFetcher.java

private static void fetchFromTelusSite(final PreferencesData prefs)
        throws NetworkErrorException, InvalidCredentialsException {
    final DefaultHttpClient httpclient = new DefaultHttpClient();
    httpclient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "ajasmin-widget");
    logIn(httpclient, prefs);/*w  ww  .j  a  v  a 2 s.  c  o m*/
    fetchUsageSummaryPage(httpclient, prefs);

    prefs.markAsUpdatedNow();

    // Log out to avoid session limit
    // on background thread to avoid extra delay
    new Thread(new Runnable() {
        @Override
        public void run() {
            try {
                fetchLogOutPage(httpclient);
                Log.i("TelusWebScraper", "Logged out " + prefs.email);
            } catch (IOException e) {
                Log.e("TelusWebScraper", "Couldn't fetch logout page for " + prefs.email, e);
            }
        }
    }).run();
}

From source file:mobi.jenkinsci.ci.client.AbstractSecureHttpClient.java

public AbstractSecureHttpClient(final JenkinsConfig config, HttpClient httpClient, String url,
        HttpCredentials credentials, String customUserAgentExtention) {
    this.config = config;
    this.wrappedDefaultHttpClient = httpClient;
    if (customUserAgentExtention != null) {
        wrappedDefaultHttpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT,
                customUserAgentExtention);
    }//from   w w w.  ja  v  a  2s.com
    this.credentials = credentials;
    this.fullUrl = url;

    this.port = UrlParser.getPort(url);
    this.protocol = UrlParser.getProtocol(url);
    this.domainName = UrlParser.getDomainName(url);
    this.queryPath = UrlParser.getQueryPath(url);

    if (credentials.getPassword() == null || credentials.getPassword().length() == 0) {

        performAuthentication = false;
    }
}

From source file:de.taxilof.UulmLoginAgent.java

/**
 * perform the Login & necessary Checks
 *//*from  www. j a v  a2s . co m*/
public void login() {
    // setting up my http client
    DefaultHttpClient client = new DefaultHttpClient();
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT,
            "Mozilla/5.0 (Linux; U; Android; uulmLogin " + context.getString(R.string.app_version) + ")");
    // disable redirects in client, used from isLoggedIn method
    client.setRedirectHandler(new RedirectHandler() {
        public URI getLocationURI(HttpResponse arg0, HttpContext arg1) throws ProtocolException {
            return null;
        }

        public boolean isRedirectRequested(HttpResponse arg0, HttpContext arg1) {
            return false;
        }
    });

    // get IP
    String ipAddress = getIp();
    if (ipAddress == null) {
        Log.d("uulmLogin", "Could not get IP Address, aborting.");
        return;
    }
    Log.d("uulmLogin", "Got IP: " + ipAddress + ", continuing.");

    // check if IP prefix is wrong
    if (!(ipAddress.startsWith(context.getString(R.string.ip_prefix)))) {
        Log.d("uulmLogin", "Wrong IP Prefix.");
        return;
    }

    // check the SSID
    String ssid = getSsid();
    if (!(context.getString(R.string.ssid).equals(ssid))) {
        Log.d("uulmLogin", "Wrong SSID, aborting.");
        return;
    }

    // check if we are already logged in
    if (isLoggedIn(client, 5)) {
        Log.d("uulmLogin", "Already logged in, aborting.");
        return;
    }

    // try to login via GET Request
    try {
        // login
        HttpGet get = new HttpGet(String.format("%s?username=%s&password=%s&login=Anmelden",
                context.getString(R.string.capo_uri), username, URLEncoder.encode(password)));
        @SuppressWarnings("unused")
        HttpResponse response = client.execute(get);
        Log.d("uulmLogin", "Login done, HttpResponse:" + HttpHelper.request(response));
    } catch (SSLException ex) {
        Log.w("uulmLogin", "SSL Error while sending Login Request: " + ex.toString());
        if (notifyFailure)
            notify("Login to Welcome failed", "SSL Error: could not verify Host", true);
        return;
    } catch (Exception e) {
        Log.w("uulmLogin", "Error while sending Login Request: " + e.toString());
        if (notifyFailure)
            notify("Login to Welcome failed", "Error while sending Login Request.", true);
        return;
    }

    // should be logged in now, but we check it now, just to be sure
    if (isLoggedIn(client, 2)) {
        if (notifySuccess)
            notify("Login to welcome successful.", "Your IP: " + ipAddress, false);
        Log.d("uulmLogin", "Login successful.");
    } else {
        if (notifyFailure)
            notify("Login to welcome failed.", "Maybe wrong Username/Password?", true);
        Log.w("uulmLogin", "Login failed, wrong user/pass?");
    }
}

From source file:com.woopra.tracking.android.WoopraPing.java

public void ping() {
    //// w w  w  .j  a  va 2  s  .  com
    HttpClient pingHttpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(pingUrl);
    httpGet.setHeader(CoreProtocolPNames.USER_AGENT, clientInfo.getUserAgent());
    try {
        Log.d(TAG, "Sending ping request:" + pingUrl);
        HttpResponse response = pingHttpClient.execute(httpGet);
        Log.d(TAG, "Response:" + EntityUtils.toString(response.getEntity()));
    } catch (Exception e) {
        Log.e(TAG, "Got error!", e);
    }
}

From source file:org.wheelmap.android.net.request.RequestProcessor.java

public void setUserAgent(String userAgent) {
    mRequestFactory.getHttpClient().getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent);
}

From source file:org.epop.dataprovider.HTMLPage.java

private void getCode(URI uri) throws ClientProtocolException, IOException, ParserConfigurationException {

    // HttpGet httpget = new HttpGet(uri);
    // HttpClient httpclient = new DefaultHttpClient();
    // ResponseHandler<String> responseHandler = new BasicResponseHandler();
    // this.rawCode = httpclient.execute(httpget, responseHandler);
    ///*  w w w .  ja  v  a 2s .  co m*/
    // TagNode tagNode = new HtmlCleaner().clean(this.rawCode);
    // return new DomSerializer(new CleanerProperties()).createDOM(tagNode);

    HttpGet request = new HttpGet(uri);

    HttpContext HTTP_CONTEXT = new BasicHttpContext();
    HTTP_CONTEXT.setAttribute(CoreProtocolPNames.USER_AGENT,
            "Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.13) Gecko/20101206 Ubuntu/10.10 (maverick) Firefox/3.6.13");
    request.setHeader("Referer", "http://www.google.com");
    request.setHeader("User-Agent", "Mozilla/5.0 (X11; U; Linux i686) Gecko/20071127 Firefox/2.0.0.11");

    HttpClient httpClient = new DefaultHttpClient();
    HttpResponse response = httpClient.execute(request, HTTP_CONTEXT);

    if (response.getStatusLine().getStatusCode() < 200 || response.getStatusLine().getStatusCode() >= 400) {
        throw new IOException(
                "bad response, error code = " + response.getStatusLine().getStatusCode() + " for " + uri);
    }

    HttpEntity entity = response.getEntity();
    if (entity != null) {
        this.rawCode = EntityUtils.toString(entity);
        EntityUtils.consume(entity);
    }

}

From source file:org.sonatype.nexus.client.rest.jersey.JerseyNexusTestClientUserAgentTest.java

@Test
public void checkUAVersionIsProperlyReadAndSet() throws MalformedURLException {
    final String version = Version
            .readVersion("META-INF/maven/org.sonatype.nexus/nexus-client-core/pom.properties", "foo");
    assertThat("Version read must not return null!", version, notNullValue());
    assertThat("Version read must not return the default (it should succeed in reading the stuff up)!", version,
            not(equalTo("foo")));

    final NexusClientFactory factory = new JerseyNexusClientFactory();
    final NexusClient client = factory.createFor(BaseUrl.baseUrlFrom("https://repository.sonatype.org/"));
    assertThat(client.getNexusStatus(), notNullValue());
    final String userAgent = (String) ((ApacheHttpClient4) ((JerseyNexusClient) client).getClient())
            .getClientHandler().getHttpClient().getParams().getParameter(CoreProtocolPNames.USER_AGENT);
    assertThat("UA must not be null!", userAgent, notNullValue());
    assertThat("UA must not be empty!", userAgent, containsString("Nexus-Client"));
    assertThat("UA should be correct!", userAgent, equalTo("Nexus-Client/" + version));
}

From source file:com.guess.license.plate.Network.ThreadSafeHttpClientFactory.java

private void addUserAgent(HttpClient client) {
    String userAgent = System.getProperty("http.agent");
    client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgent);
}

From source file:uk.ac.ox.oucs.vle.XcriPopulatorInput.java

public void init() {
    // We will have multiple threads using the same httpClient.
    httpClient = new DefaultHttpClient(new ThreadSafeClientConnManager());
    httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, "SES Import")
            .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, connectionTimeout)
            .setIntParameter(CoreConnectionPNames.SO_TIMEOUT, socketTimeout);
}