Example usage for org.apache.http.protocol HttpContext setAttribute

List of usage examples for org.apache.http.protocol HttpContext setAttribute

Introduction

In this page you can find the example usage for org.apache.http.protocol HttpContext setAttribute.

Prototype

void setAttribute(String str, Object obj);

Source Link

Usage

From source file:com.cybussolutions.wikki.afri_pay.Networking.CheckAmount.java

@Override
protected String doInBackground(String... params) {

    LoginActivity.currentSession.authhttpClient = new DefaultHttpClient();
    HttpContext ctx = new BasicHttpContext();
    ctx.setAttribute(ClientContext.COOKIE_STORE, LoginActivity.currentSession.cookieStore);
    LoginActivity.currentSession.httppost = new HttpPost(
            LoginActivity.currentSession.base_url + "compliance/checkComplianceForTrans/");
    List<BasicNameValuePair> nameValuePairs = new ArrayList<>();
    String id = LoginActivity.currentSession.newProfile.getUserID();
    String sending = LoginActivity.currentSession.newProfile.getCountryID();
    nameValuePairs.add(new BasicNameValuePair("transAmount", params[0]));
    nameValuePairs.add(new BasicNameValuePair("localAmount", params[1]));
    nameValuePairs.add(new BasicNameValuePair("totalAmount", params[2]));
    nameValuePairs.add(new BasicNameValuePair("origenCountry", sending));
    nameValuePairs.add(new BasicNameValuePair("destCountry", params[3]));
    nameValuePairs.add(new BasicNameValuePair("action", "send"));
    nameValuePairs.add(new BasicNameValuePair("originCYY", params[4]));
    nameValuePairs.add(new BasicNameValuePair("destCYY", params[5]));
    nameValuePairs.add(new BasicNameValuePair("customerID", id));

    try {/*ww  w  .  ja  v a2s  .  c  om*/
        LoginActivity.currentSession.httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));
        responsebody = LoginActivity.currentSession.authhttpClient
                .execute(LoginActivity.currentSession.httppost, ctx);
        responseString = new BasicResponseHandler().handleResponse(responsebody);

        if (responseString.equals("1")) {

            return "1";
        }

        else if (responseString.equals("nodocuments%")) {
            String complience;
            complience = "Documents Needed to Proceed this transaction";

            return complience;
        }

        else if (responseString.equals("nodocuments%\n"
                + " Message: Docs Needed Please Go back to manage Documents to Upload missing documents. \n"
                + "Documents Need : Passport OR Driver License - Source of Funds - ")) {

            message = responseString.split("%");

        }

        else {
            message = responseString.split("%");
        }

    } catch (ParseException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "Exception";
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
        return "Exception";
    }
    if (responseString.contains("unable to allocate memory for pool") && responseString == null) {

        return "Exception";
    }
    if (responseString.contains("logout")) {
        return "Exception";
    }
    return message[1];
}

From source file:org.wso2.carbon.registry.notes.test.PublisherNotesTestCase.java

@Test(groups = "wso2.greg", description = "Add Schema without name", dependsOnMethods = "createSOAPService")
public void addNoteTestCase() throws Exception {
    String session_id = authenticateJaggeryAPI();
    String endPoint = "https://localhost:10343/publisher/apis/assets?type=note";

    CookieStore cookieStore = new BasicCookieStore();
    HttpContext httpContext = new BasicHttpContext();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    HttpClient client = new DefaultHttpClient();
    HttpPost post = new HttpPost(endPoint);
    post.setHeader("Cookie", "JSESSIONID=" + session_id);
    List nameValuePairs = new ArrayList(5);
    nameValuePairs.add(new BasicNameValuePair("overview_note", "note_one"));
    nameValuePairs.add(new BasicNameValuePair("overview_resourcepath",
            "/_system/governance/trunk/soapservices/4.5.0/SOAPService1"));
    nameValuePairs.add(new BasicNameValuePair("overview_visibility", "public"));
    nameValuePairs.add(new BasicNameValuePair("overview_note", "admin"));
    nameValuePairs.add(new BasicNameValuePair("overview_status", "open"));

    post.setEntity(new UrlEncodedFormEntity(nameValuePairs));
    HttpResponse response = client.execute(post);
    assertEquals("Created", response.getStatusLine().getReasonPhrase());
}

From source file:net.emphased.vkclient.VkClient.java

protected HttpContext getHttpContext(CookieStore cookieStore) {
    HttpContext result = _httpContextFactory.create();
    result.setAttribute(ClientContext.COOKIE_STORE, cookieStore);
    return result;
}

From source file:io.github.kitarek.elasthttpd.server.consumers.HttpRequestPrimaryConsumer.java

private void consumeRequestsUntilConnectionIsOpen(HttpServerConnection connection) {
    final HttpContext httpContext = create();
    httpContext.setAttribute(HTTP_CONNECTION, connection);
    while (connection.isOpen()) {
        consumeSingleRequest(connection, httpContext);
    }// w ww  . j a v a 2  s.c  o m
}

From source file:org.everit.authentication.http.session.ecm.tests.SessionAuthenticationComponentTest.java

@Test
@TestDuringDevelopment//from  ww w.  jav a 2s . c o m
public void testAccessHelloPage() throws Exception {
    CookieStore cookieStore = new BasicCookieStore();
    HttpContext httpContext = new BasicHttpContext();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    long sessionResourceId = hello(httpContext, authenticationContext.getDefaultResourceId());
    sessionResourceId = hello(httpContext, sessionResourceId);
    sessionResourceId = hello(httpContext, sessionResourceId);
    logoutPost(httpContext);

    sessionResourceId = hello(httpContext, authenticationContext.getDefaultResourceId());
    sessionResourceId = hello(httpContext, sessionResourceId);
    hello(httpContext, sessionResourceId);
    logoutGet(httpContext);

    hello(httpContext, authenticationContext.getDefaultResourceId());
}

From source file:com.grouzen.android.serenity.HttpConnection.java

private HttpResponse execute(HttpUriRequest request) throws ClientProtocolException, IOException {
    HttpResponse response;//ww w  .j  a  v  a 2s  .  c om
    HttpContext localContext = new BasicHttpContext();

    localContext.setAttribute(ClientContext.COOKIE_STORE, mCookies);
    response = mClient.execute(request, localContext);

    return response;
}

From source file:com.androidrocks.bex.zxing.client.android.AndroidHttpClient.java

private AndroidHttpClient(ClientConnectionManager ccm, HttpParams params) {
    this.delegate = new DefaultHttpClient(ccm, params) {
        @Override//from  ww  w  .ja v  a 2 s  . c om
        protected BasicHttpProcessor createHttpProcessor() {
            // Add interceptor to prevent making requests from main thread.
            BasicHttpProcessor processor = super.createHttpProcessor();
            processor.addRequestInterceptor(sThreadCheckInterceptor);
            return processor;
        }

        @Override
        protected HttpContext createHttpContext() {
            // Same as DefaultHttpClient.createHttpContext() minus the
            // cookie store.
            HttpContext context = new BasicHttpContext();
            context.setAttribute(ClientContext.AUTHSCHEME_REGISTRY, getAuthSchemes());
            context.setAttribute(ClientContext.COOKIESPEC_REGISTRY, getCookieSpecs());
            context.setAttribute(ClientContext.CREDS_PROVIDER, getCredentialsProvider());
            return context;
        }
    };
}

From source file:org.everit.osgi.authentication.http.session.tests.SessionAuthenticationTestComponent.java

@Test
public void testAccessHelloPage() throws Exception {
    CookieStore cookieStore = new BasicCookieStore();
    HttpContext httpContext = new BasicHttpContext();
    httpContext.setAttribute(ClientContext.COOKIE_STORE, cookieStore);

    long sessionResourceId = hello(httpContext, authenticationContext.getDefaultResourceId());
    sessionResourceId = hello(httpContext, sessionResourceId);
    sessionResourceId = hello(httpContext, sessionResourceId);
    logoutPost(httpContext);/* w w w  .  j  a v a 2  s.  c  om*/

    sessionResourceId = hello(httpContext, authenticationContext.getDefaultResourceId());
    sessionResourceId = hello(httpContext, sessionResourceId);
    hello(httpContext, sessionResourceId);
    logoutGet(httpContext);

    hello(httpContext, authenticationContext.getDefaultResourceId());
}

From source file:mx.clickfactura.util.TipoCambioUtil.java

public String getTipoCambio(String fecha) throws CustomBadRequestException, CustomNotFoundException, Exception {

    Pattern pattern = Pattern.compile("^\\d{4}\\-\\d{2}\\-\\d{2}$");
    Matcher matcher = null;/*  w  w w  . jav a2 s  .c o m*/

    matcher = pattern.matcher(fecha.trim());

    if (!matcher.matches()) {
        throw new CustomBadRequestException("Fecha invalida, el formato debe ser: yyyy-MM-dd");
    }

    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");

    Calendar cal = new GregorianCalendar();

    cal.setTime(sdf.parse(fecha));

    String dia = (cal.get(Calendar.DATE) < 10) ? "0" + cal.get(Calendar.DATE) : cal.get(Calendar.DATE) + "";
    String mes = ((cal.get(Calendar.MONTH) + 1) < 10) ? "0" + (cal.get(Calendar.MONTH) + 1)
            : (cal.get(Calendar.MONTH) + 1) + "";
    String anio = cal.get(Calendar.YEAR) + "";

    String fechaInicial = dia + "%2F" + mes + "%2F" + anio;

    CloseableHttpClient client = HttpClients.createDefault();
    CookieStore cookies = new BasicCookieStore();
    String[] fechaSeparada = fecha.split("-");
    HttpGet get = new HttpGet("http://www.dof.gob.mx/indicadores_detalle.php?cod_tipo_indicador=158&dfecha="
            + fechaInicial + "&hfecha=" + fechaInicial);

    HttpContext httpContext = new BasicHttpContext();
    httpContext.setAttribute(HttpClientContext.COOKIE_STORE, cookies);
    CloseableHttpResponse response = client.execute(get, httpContext);

    //System.out.println(response.toString());      
    //System.out.println(response.getStatusLine());
    //System.out.println(response.getEntity().getContentLength());
    InputStream in = response.getEntity().getContent();
    Header encoding = response.getEntity().getContentEncoding();

    String body = IOUtils.toString(in, "UTF-8");
    //System.out.println(body);

    Document doc = Jsoup.parse(body, "UTF-8");

    doc = doc.normalise();

    //System.out.println(doc.toString());
    Elements e = doc.select("table");

    Iterator iterator = e.iterator();

    pattern = Pattern.compile("^\\d{2}\\.\\d{6}$");
    matcher = null;

    String tipoCambio = null;

    while (iterator.hasNext()) {
        Element xd = (Element) iterator.next();
        if (xd.getElementsByClass("txt").hasAttr("height")) {
            if (xd.getElementsByClass("txt").text().split(" ").length == 6) {

                String cambio = xd.getElementsByClass("txt").text().split(" ")[5];
                matcher = pattern.matcher(cambio.trim());

                if (matcher.matches()) {
                    tipoCambio = cambio;
                    //System.out.println(tipoCambio);
                    break;
                }

            }

        }

    }

    client.close();
    response.close();

    if (tipoCambio == null || tipoCambio.isEmpty()) {
        throw new CustomNotFoundException("No hay un tipo de cambio para el da: " + fecha);

    }

    return tipoCambio;

}

From source file:org.greencheek.spring.rest.SSLCachingHttpComponentsClientHttpRequest.java

private void setSSLPrinciple(HttpContext context) {
    Principal sslToken = sslTokenCache.get();
    if (sslToken != null && useSSLSessionCaching) {
        context.setAttribute(ClientContext.USER_TOKEN, sslToken);
    }//from  w  ww  . j av  a2s. c  om
}