Example usage for org.apache.http.protocol HTTP ISO_8859_1

List of usage examples for org.apache.http.protocol HTTP ISO_8859_1

Introduction

In this page you can find the example usage for org.apache.http.protocol HTTP ISO_8859_1.

Prototype

String ISO_8859_1

To view the source code for org.apache.http.protocol HTTP ISO_8859_1.

Click Source Link

Usage

From source file:org.apache.droids.examples.cli.SimpleRuntime.java

public static void main(String[] args) throws Exception {

    if (args.length < 1) {
        System.out.println("Please specify a URL to crawl");
        System.exit(-1);/*from  ww  w . j  av a 2 s  .  co  m*/
    }
    String targetURL = args[0];

    // Create parser factory. Support basic HTML markup only
    ParserFactory parserFactory = new ParserFactory();
    TikaDocumentParser tikaParser = new TikaDocumentParser();
    parserFactory.getMap().put("text/html", tikaParser);

    // Create protocol factory. Support HTTP/S only.
    ProtocolFactory protocolFactory = new ProtocolFactory();

    // Create and configure HTTP client
    HttpParams params = new BasicHttpParams();
    HttpProtocolParamBean hppb = new HttpProtocolParamBean(params);
    HttpConnectionParamBean hcpb = new HttpConnectionParamBean(params);
    ConnManagerParamBean cmpb = new ConnManagerParamBean(params);

    // Set protocol parametes
    hppb.setVersion(HttpVersion.HTTP_1_1);
    hppb.setContentCharset(HTTP.ISO_8859_1);
    hppb.setUseExpectContinue(true);
    // Set connection parameters
    hcpb.setStaleCheckingEnabled(false);
    // Set connection manager parameters
    ConnPerRouteBean connPerRouteBean = new ConnPerRouteBean();
    connPerRouteBean.setDefaultMaxPerRoute(2);
    cmpb.setConnectionsPerRoute(connPerRouteBean);

    DroidsHttpClient httpclient = new DroidsHttpClient(params);

    HttpProtocol httpProtocol = new HttpProtocol(httpclient);
    protocolFactory.getMap().put("http", httpProtocol);
    protocolFactory.getMap().put("https", httpProtocol);

    // Create URL filter factory.
    URLFiltersFactory filtersFactory = new URLFiltersFactory();
    RegexURLFilter defaultURLFilter = new RegexURLFilter();
    defaultURLFilter.setFile("classpath:/regex-urlfilter.txt");
    filtersFactory.getMap().put("default", defaultURLFilter);

    // Create handler factory. Provide sysout handler only.
    HandlerFactory handlerFactory = new HandlerFactory();
    SysoutHandler defaultHandler = new SysoutHandler();
    handlerFactory.getMap().put("default", defaultHandler);

    // Create droid factory. Leave it empty for now.
    DroidFactory<Link> droidFactory = new DroidFactory<Link>();

    // Create default droid
    SimpleDelayTimer simpleDelayTimer = new SimpleDelayTimer();
    simpleDelayTimer.setDelayMillis(100);

    Queue<Link> simpleQueue = new LinkedList<Link>();

    SequentialTaskMaster<Link> taskMaster = new SequentialTaskMaster<Link>();
    taskMaster.setDelayTimer(simpleDelayTimer);
    taskMaster.setExceptionHandler(new DefaultTaskExceptionHandler());

    CrawlingDroid helloCrawler = new SysoutCrawlingDroid(simpleQueue, taskMaster);
    helloCrawler.setFiltersFactory(filtersFactory);
    helloCrawler.setParserFactory(parserFactory);
    helloCrawler.setProtocolFactory(protocolFactory);

    Collection<String> initialLocations = new ArrayList<String>();
    initialLocations.add(targetURL);
    helloCrawler.setInitialLocations(initialLocations);

    // Initialize and start the crawler
    helloCrawler.init();
    helloCrawler.start();

    // Await termination
    helloCrawler.getTaskMaster().awaitTermination(0, TimeUnit.MILLISECONDS);
    // Shut down the HTTP connection manager
    httpclient.getConnectionManager().shutdown();
}

From source file:org.apache.droids.protocol.http.HttpContentEntity.java

public HttpContentEntity(HttpEntity entity, long maxlen) throws IOException {
    super();//from   w  ww  .  ja  v a  2 s  . c o m
    if (entity.isRepeatable()) {
        this.entity = entity;
    } else {
        this.entity = new DroidHttpEntity(entity, maxlen);
    }

    String mimeType = null;
    String charset = null;
    Header header = entity.getContentType();
    if (header != null) {
        HeaderElement[] helems = header.getElements();
        if (helems != null && helems.length > 0) {
            HeaderElement helem = helems[0];
            mimeType = helem.getName();
            NameValuePair nvp = helem.getParameterByName("charset");
            if (nvp != null) {
                charset = nvp.getValue();
            }
        }
    }
    if (mimeType != null) {
        this.mimeType = mimeType.toLowerCase(Locale.ENGLISH);
    } else {
        this.mimeType = "binary/octet-stream";
    }
    if (charset != null) {
        this.charset = charset;
    } else {
        if (this.mimeType.startsWith("text/")) {
            this.charset = HTTP.ISO_8859_1;
        } else {
            this.charset = null;
        }
    }
}

From source file:com.liato.bankdroid.banking.banks.Nordnet.java

@Override
protected LoginPackage preLogin() throws BankException, ClientProtocolException, IOException {
    urlopen = new Urllib(context, CertificateReader.getCertificates(context, R.raw.cert_nordnet));
    urlopen.setContentCharset(HTTP.ISO_8859_1);
    response = urlopen.open("https://www.nordnet.se/mux/login/startSE.html");

    Document d = Jsoup.parse(response);
    Element e = d.getElementById("input1");
    if (e == null || "".equals(e.attr("name"))) {
        throw new BankException(res.getText(R.string.unable_to_find).toString() + " username field.");
    }/*  w  w  w  .j  a  v  a2  s  . co m*/
    String loginFieldName = e.attr("name");
    e = d.getElementById("pContHidden");
    if (e == null || "".equals(e.attr("name"))) {
        throw new BankException(res.getText(R.string.unable_to_find).toString() + " password field.");
    }
    String loginFieldPassword = e.attr("name");

    List<NameValuePair> postData = new ArrayList<NameValuePair>();
    postData.add(new BasicNameValuePair("checksum", ""));
    postData.add(new BasicNameValuePair("referer", ""));
    postData.add(new BasicNameValuePair("encryption", "0"));
    postData.add(new BasicNameValuePair(loginFieldName, username));
    postData.add(new BasicNameValuePair(loginFieldPassword, password));

    return new LoginPackage(urlopen, postData, response, "https://www.nordnet.se/mux/login/login.html");
}

From source file:com.liato.bankdroid.banking.banks.Nordnetdirekt.java

@Override
protected LoginPackage preLogin() throws BankException, ClientProtocolException, IOException {
    urlopen = new Urllib(context, CertificateReader.getCertificates(context, R.raw.cert_nordnetdirekt));
    urlopen.setContentCharset(HTTP.ISO_8859_1);
    response = urlopen.open("https://www.nordnetdirekt.se/mux/oinloggad/startsida/index.html");

    List<NameValuePair> postData = new ArrayList<NameValuePair>();
    postData.add(new BasicNameValuePair("a4", "sv"));
    postData.add(new BasicNameValuePair("a3", "ADSE"));
    postData.add(new BasicNameValuePair("usa", "7"));
    postData.add(new BasicNameValuePair("a1", username));
    postData.add(new BasicNameValuePair("a2", password));
    postData.add(new BasicNameValuePair("nyckel", extras));
    return new LoginPackage(urlopen, postData, response,
            "https://www.nordnetdirekt.se/mux/inloggad/lib/login.html");
}

From source file:com.liato.bankdroid.banking.banks.Volvofinans.java

@Override
protected LoginPackage preLogin() throws BankException, ClientProtocolException, IOException {
    urlopen = new Urllib(true);
    urlopen.setContentCharset(HTTP.ISO_8859_1);
    List<NameValuePair> postData = new ArrayList<NameValuePair>();
    postData.add(new BasicNameValuePair("username", username));
    postData.add(new BasicNameValuePair("password", password));
    postData.add(new BasicNameValuePair("TARGET",
            "https://inloggad.volvofinans.se/privat/inloggning/redirect.html"));
    postData.add(new BasicNameValuePair("REFERER",
            "https://inloggad.volvofinans.se/privat/inloggning/forenklad.html"));
    return new LoginPackage(urlopen, postData, null, "https://secure.volvofinans.se/neas/KodAuth");
}

From source file:com.liato.bankdroid.banking.banks.MobilbankenBase.java

@Override
protected LoginPackage preLogin() throws BankException, ClientProtocolException, IOException {
    urlopen = new Urllib(context, CertificateReader.getCertificates(context, R.raw.cert_mobilbanken));
    urlopen.setAllowCircularRedirects(true);
    urlopen.setContentCharset(HTTP.ISO_8859_1);
    String postUrl = String.format("https://mobil-banken.se/%s/login.html", targetId);
    response = urlopen.open(postUrl);//from   w w w.ja v  a  2 s  .  c  o m
    Matcher matcher = reMsisdn.matcher(response);
    if (!matcher.find()) {
        throw new BankException(res.getText(R.string.unable_to_find).toString() + " msisdn.");
    }
    String msisdn = matcher.group(1);
    matcher = reTimestamp.matcher(response);
    if (!matcher.find()) {
        throw new BankException(res.getText(R.string.unable_to_find).toString() + " timestamp.");
    }
    String timestamp = matcher.group(1);

    List<NameValuePair> postData = new ArrayList<NameValuePair>();
    postData.add(new BasicNameValuePair("msisdn", msisdn));
    postData.add(new BasicNameValuePair("user" + timestamp, username));
    postData.add(new BasicNameValuePair("password" + timestamp, password));
    return new LoginPackage(urlopen, postData, response, postUrl);
}

From source file:com.liato.bankdroid.banking.banks.SEB.java

@Override
protected LoginPackage preLogin() throws BankException, ClientProtocolException, IOException {
    urlopen = new Urllib(true);
    urlopen.setContentCharset(HTTP.ISO_8859_1);
    urlopen.addHeader("Referer", "https://m.seb.se/");
    urlopen.setKeepAliveTimeout(5);/*  w  w w. j  a  v a  2s  . co m*/
    //response = urlopen.open("https://m.seb.se/cgi-bin/pts3/mpo/9000/mpo9001.aspx?P1=logon.htm");
    List<NameValuePair> postData = new ArrayList<NameValuePair>();
    postData.add(new BasicNameValuePair("A1", username));
    postData.add(new BasicNameValuePair("A2", password));
    postData.add(new BasicNameValuePair("A3", "4"));
    return new LoginPackage(urlopen, postData, response,
            "https://m.seb.se/cgi-bin/pts3/mps/1000/mps1001bm.aspx");
}

From source file:com.liato.bankdroid.banking.banks.AmericanExpress.java

@Override
protected LoginPackage preLogin() throws BankException, ClientProtocolException, IOException {
    urlopen = new Urllib(context, CertificateReader.getCertificates(context, R.raw.cert_americanexpress,
            R.raw.cert_americanexpress2, R.raw.cert_americanexpress_global));
    urlopen.setAllowCircularRedirects(true);
    urlopen.setContentCharset(HTTP.ISO_8859_1);
    response = urlopen.open("https://www.americanexpress.com/home/se/home_c.shtml");
    List<NameValuePair> postData = new ArrayList<NameValuePair>();

    postData.add(new BasicNameValuePair("request_type", "LogLogonHandler"));
    postData.add(new BasicNameValuePair("DestPage",
            "https://global.americanexpress.com/myca/intl/acctsumm/emea/accountSummary.do?request_type=&Face=sv_SE"));
    postData.add(new BasicNameValuePair("Face", "sv_SE"));
    postData.add(new BasicNameValuePair("brandname", ""));
    postData.add(new BasicNameValuePair("TARGET",
            "https://global.americanexpress.com/myca/intl/acctsumm/emea/accountSummary.do?request_type=&Face=sv_SE"));
    postData.add(new BasicNameValuePair("CHECKBOXSTATUS", "1"));
    postData.add(new BasicNameValuePair("Logon", "Continue..."));
    postData.add(new BasicNameValuePair("devicePrint",
            "version%3D1%26pm%5Ffpua%3Dmozilla%2F5%2E0%20%28windows%3B%20u%3B%20windows%20nt%206%2E1%3B%20en%2Dus%3B%20rv%3A1%2E9%2E2%2E7%29%20gecko%2F20100713%20firefox%2F3%2E6%2E7%20%28%20%2Enet%20clr%203%2E5%2E30729%3B%20%2Enet4%2E0c%29%7C5%2E0%20%28Windows%3B%20en%2DUS%29%7CWin32%26pm%5Ffpsc%3D24%7C1680%7C1050%7C988%26pm%5Ffpsw%3Dswf%7Cdef%7Cqt1%7Cqt2%7Cqt3%7Cqt4%7Cqt5%7Cqt6%26pm%5Ffptz%3D1%26pm%5Ffpln%3Dlang%3Den%2DUS%7Csyslang%3D%7Cuserlang%3D%26pm%5Ffpjv%3D1%26pm%5Ffpco%3D1"));
    postData.add(new BasicNameValuePair("REMEMBERME", "on"));
    postData.add(new BasicNameValuePair("manage", "option1"));
    postData.add(new BasicNameValuePair("UserID", username));
    postData.add(new BasicNameValuePair("USERID", username));
    postData.add(new BasicNameValuePair("Password", password));
    postData.add(new BasicNameValuePair("PWD", password));

    return new LoginPackage(urlopen, postData, response,
            "https://global.americanexpress.com/myca/logon/emea/action?request_type=LogLogonHandler&Face=sv_SE");
}

From source file:com.mockey.model.RequestFromClient.java

/**
 * Initialization will extract Headers, Body, Parameters, and Cookies from
 * the raw HTTP request. Note: This class will <i>_ignore_</i> some header
 * information. See <code>HEADERS_TO_IGNORE</code>
 * /* ww w. ja v a 2s  .  c om*/
 * @param rawRequest
 */
public RequestFromClient(HttpServletRequest rawRequest) {
    try {
        rawRequest.setCharacterEncoding(HTTP.ISO_8859_1); // "UTF-8");

    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
    this.method = rawRequest.getMethod();

    parseRequestHeaders(rawRequest);
    parseRequestBody(rawRequest);
    parseParameters(rawRequest);
    parseCookies(rawRequest);
}