Package com.gargoylesoftware.htmlunit

Examples of com.gargoylesoftware.htmlunit.WebClient$CurrentWindowTracker


   public HtmlPage page;  
  
   @BeforeMethod
   public void setUp() throws Exception{
      URL url = new URL(PAGE_URL);     
      wc = new WebClient(BrowserVersion.FIREFOX_2);     
      page = (HtmlPage) wc.getPage(url)
   }
View Full Code Here


        }
    }

    @Before
    public void prepareWebClient() {
        webClient = new WebClient();
        ((DefaultCredentialsProvider) webClient.getCredentialsProvider()).addCredentials("admin", "admin");
    }
View Full Code Here

        private final int clientNum;
        private final WebClient client;
       
        public Client(int clientNum) {
            this.clientNum = clientNum;
            this.client = new WebClient();
        }
View Full Code Here

        protected String baseURL = "http://localhost:8989/mvc/serv";
        protected WebClient client;

        public BaseClient() {
            client = new WebClient();
        }
View Full Code Here

    }

    @Before
    public void beforeEachTest() {

        client = new WebClient();
    }
View Full Code Here

    protected RequestContentType withContentType(String contentType) {
        return new RequestContentType(contentType);
    }
   
    protected void newWebClient() {
        client = new WebClient();
    }
View Full Code Here

        private final int clientNum;
        private final WebClient client;
       
        public Client(int clientNum) {
            this.clientNum = clientNum;
            this.client = new WebClient();
        }
View Full Code Here

        private final int clientNum;
        private final WebClient client;
       
        public Client(int clientNum) {
            this.clientNum = clientNum;
            this.client = new WebClient();
        }
View Full Code Here

        private final int clientNum;
        private final WebClient client;
       
        public Client(int clientNum) {
            this.clientNum = clientNum;
            this.client = new WebClient();
        }
View Full Code Here

    public void authenticate(IAuthFlowListener listener) {

        // TODO run this on an Executor to make it async

        // create HtmlUnit client
        final WebClient webClient = new WebClient(BrowserVersion.FIREFOX_24);
        final WebClientOptions options = webClient.getOptions();
        options.setRedirectEnabled(true);
        options.setJavaScriptEnabled(false);
        options.setThrowExceptionOnFailingStatusCode(true);
        options.setThrowExceptionOnScriptError(true);
        options.setPrintContentOnFailingStatusCode(LOG.isDebugEnabled());
        try {
            // use default SSP to create supported non-SSL protocols list
            final SSLContext sslContext = new SSLContextParameters().createSSLContext();
            options.setSSLClientProtocols(sslContext.createSSLEngine().getEnabledProtocols());
        } catch (GeneralSecurityException e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        } catch (IOException e) {
            throw ObjectHelper.wrapRuntimeCamelException(e);
        }

        // add HTTP proxy if set
        final Map<String, Object> httpParams = configuration.getHttpParams();
        if (httpParams != null && httpParams.get(ConnRoutePNames.DEFAULT_PROXY) != null) {
            final HttpHost proxyHost = (HttpHost) httpParams.get(ConnRoutePNames.DEFAULT_PROXY);
            final Boolean socksProxy = (Boolean) httpParams.get("http.route.socks-proxy");
            final ProxyConfig proxyConfig = new ProxyConfig(proxyHost.getHostName(), proxyHost.getPort(),
                socksProxy != null ? socksProxy : false);
            options.setProxyConfig(proxyConfig);
        }

        // authorize application on user's behalf
        try {
            final String csrfId = String.valueOf(new SecureRandom().nextLong());

            OAuthWebViewData viewData = new OAuthWebViewData(boxClient.getOAuthDataController());
            viewData.setOptionalState(String.valueOf(csrfId));
            final HtmlPage authPage = webClient.getPage(viewData.buildUrl().toString());

            // submit login credentials
            final HtmlForm loginForm = authPage.getFormByName("login_form");
            final HtmlTextInput login = loginForm.getInputByName("login");
            login.setText(configuration.getUserName());
            final HtmlPasswordInput password = loginForm.getInputByName("password");
            password.setText(configuration.getUserPassword());
            final HtmlSubmitInput submitInput = loginForm.getInputByName("login_submit");

            // submit consent
            final HtmlPage consentPage = submitInput.click();
            final HtmlForm consentForm = consentPage.getFormByName("consent_form");
            final HtmlButton consentAccept = consentForm.getButtonByName("consent_accept");

            // disable redirect to avoid loading redirect URL
            webClient.getOptions().setRedirectEnabled(false);

            // validate CSRF and get authorization code
            String redirectQuery;
            try {
                final Page redirectPage = consentAccept.click();
View Full Code Here

TOP

Related Classes of com.gargoylesoftware.htmlunit.WebClient$CurrentWindowTracker

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.