OkHttpClient copyWithDefaults() { OkHttpClient result = new OkHttpClient(this); if (result.proxySelector == null) { result.proxySelector = ProxySelector.getDefault(); } if (result.cookieHandler == null) { result.cookieHandler = CookieHandler.getDefault(); } if (result.socketFactory == null) { result.socketFactory = SocketFactory.getDefault(); } if (result.sslSocketFactory == null) { result.sslSocketFactory = getDefaultSSLSocketFactory(); } if (result.hostnameVerifier == null) { result.hostnameVerifier = OkHostnameVerifier.INSTANCE; } if (result.certificatePinner == null) { result.certificatePinner = CertificatePinner.DEFAULT; } if (result.authenticator == null) { result.authenticator = AuthenticatorAdapter.INSTANCE; } if (result.connectionPool == null) { result.connectionPool = ConnectionPool.getDefault(); } if (result.protocols == null) { result.protocols = DEFAULT_PROTOCOLS; } if (result.connectionSpecs == null) { result.connectionSpecs = DEFAULT_CONNECTION_SPECS; } if (result.dns == null) { result.dns = Dns.SYSTEM; } return result; }
/** * Returns a shallow copy of this OkHttpClient that uses the system-wide default for * each field that hasn't been explicitly configured. */ private OkHttpClient copyWithDefaults() { OkHttpClient result = new OkHttpClient(this); result.proxy = proxy; result.proxySelector = proxySelector != null ? proxySelector : ProxySelector.getDefault(); result.cookieHandler = cookieHandler != null ? cookieHandler : CookieHandler.getDefault(); result.responseCache = responseCache != null ? responseCache : ResponseCache.getDefault(); result.sslSocketFactory = sslSocketFactory != null ? sslSocketFactory : HttpsURLConnection.getDefaultSSLSocketFactory(); result.hostnameVerifier = hostnameVerifier != null ? hostnameVerifier : OkHostnameVerifier.INSTANCE; result.authenticator = authenticator != null ? authenticator : HttpAuthenticator.SYSTEM_DEFAULT; result.connectionPool = connectionPool != null ? connectionPool : ConnectionPool.getDefault(); result.followProtocolRedirects = followProtocolRedirects; result.transports = transports != null ? transports : DEFAULT_TRANSPORTS; result.connectTimeout = connectTimeout; result.readTimeout = readTimeout; return result; }
private void createViews() { mediaDataSourceFactory = buildDataSourceFactory(true); mainHandler = new Handler(); window = new Timeline.Window(); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } LayoutParams layoutParams = new LayoutParams( LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT); exoPlayerView = new ExoPlayerView(getContext()); exoPlayerView.setLayoutParams(layoutParams); addView(exoPlayerView, 0, layoutParams); }
private static OkHttpClientImpl _getClient(CookieHandler cookieHandler) { OkHttpClientImpl okHttpClient = new OkHttpClientImpl(); //okHttpClient.setConnectTimeout(SET_CONNECTION_TIMEOUT, TimeUnit.MILLISECONDS); //okHttpClient.setReadTimeout(SET_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS); //okHttpClient.setWriteTimeout(SET_SOCKET_TIMEOUT, TimeUnit.MILLISECONDS); if (cookieHandler == null) { CookieManager cookieManager = new CookieManager(); cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_NONE); okHttpClient._setCookieHandler(cookieManager); } else { okHttpClient._setCookieHandler(cookieHandler); } return okHttpClient; }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); shouldAutoPlay = true; clearResumePosition(); mediaDataSourceFactory = buildDataSourceFactory(true); mainHandler = new Handler(); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } setContentView(R.layout.player_activity); View rootView = findViewById(R.id.root); rootView.setOnClickListener(this); debugRootView = (LinearLayout) findViewById(R.id.controls_root); debugTextView = (TextView) findViewById(R.id.debug_text_view); retryButton = (Button) findViewById(R.id.retry_button); retryButton.setOnClickListener(this); simpleExoPlayerView = (SimpleExoPlayerView) findViewById(R.id.player_view); simpleExoPlayerView.setControllerVisibilityListener(this); simpleExoPlayerView.requestFocus(); }
public SoapSession(URL institutionUrl, String username, String password) throws Exception { this.institutionUrl = institutionUrl; encoder = new Base64(-1); CookieHandler.setDefault(new BasicCookieHandler()); final URL endpointUrl = new URL(institutionUrl, "services/SoapService51"); System.setProperty("axis.socketFactory", "com.dytech.edge.importexport.TleDefaultSocketFactory"); System.setProperty("org.apache.commons.logging.Log", "org.apache.commons.logging.impl.SLF4JLog"); System.setProperty("org.apache.commons.logging.LogFactory", "org.apache.commons.logging.impl.SLF4JLogFactory"); final CustomSoapService51Locator locator = new CustomSoapService51Locator(); client = locator.getSoapService51Endpoint(endpointUrl); final PropBagEx userXml = new PropBagEx(client.login(username, password)); userId = userXml.getNode("uuid"); loggedIn = true; final Map<String, List<String>> fakeHeaders = new HashMap<String, List<String>>(); fakeHeaders.put("Set-Cookie", locator.getCookiesForUrl(endpointUrl)); CookieHandler.getDefault().put(endpointUrl.toURI(), fakeHeaders); new KeepAlive().start(); }
private Request networkRequest(Request request) throws IOException { Request.Builder result = request.newBuilder(); if (request.header("Host") == null) { result.header("Host", Util.hostHeader(request.httpUrl())); } if (request.header("Connection") == null) { result.header("Connection", "Keep-Alive"); } if (request.header(AsyncHttpClient.HEADER_ACCEPT_ENCODING) == null) { this.transparentGzip = true; result.header(AsyncHttpClient.HEADER_ACCEPT_ENCODING, AsyncHttpClient.ENCODING_GZIP); } CookieHandler cookieHandler = this.client.getCookieHandler(); if (cookieHandler != null) { OkHeaders.addCookies(result, cookieHandler.get(request.uri(), OkHeaders.toMultimap (result.build().headers(), null))); } if (request.header(Network.USER_AGENT) == null) { result.header(Network.USER_AGENT, Version.userAgent()); } return result.build(); }
void doClientSide() throws Exception { // Wait for server to get started. while (!serverReady) { Thread.sleep(50); } HttpsURLConnection.setDefaultHostnameVerifier(new HostnameVerifier() { public boolean verify(String hostname, SSLSession session) { return true; }}); URL url = new URL("https://localhost:" + serverPort +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
CookieHttpClientTest() throws Exception { /* start the server */ ss = new ServerSocket(0); (new Thread(this)).start(); URL url = new URL("http://localhost:" + ss.getLocalPort() +"/"); // Run without a CookieHandler first InputStream in = url.openConnection().getInputStream(); while (in.read() != -1); // read response body so connection can be reused // Set a CookeHandler and retest using the HttpClient from the KAC CookieManager manager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(manager); in = url.openConnection().getInputStream(); while (in.read() != -1); if (manager.getCookieStore().getCookies().isEmpty()) { throw new RuntimeException("Failed: No cookies in the cookie Handler."); } }
private void initCookies() { CookieManager cookieManager = new CookieManager(); CookieHandler.setDefault(cookieManager); if (cookieManager.getCookieStore().getCookies().size() == 0) { try { String url = SharedPreferencesEditor.getInstance().getString( Constants.PREFS_URL_SHORTCUT); URI uri = new URI(url); HttpCookie cookie = new HttpCookie(Constants.COOKIE_AUTH_NAME, SharedPreferencesEditor.getInstance().getString( Constants.PREFS_AUTH)); cookie.setDomain(uri.getHost()); cookie.setPath(Constants.COOKIE_BASE_PATH); cookie.setVersion(0); cookie.setMaxAge((new Date()).getTime() + Constants.COOKIE_LIFETIME_YEAR); cookieManager.getCookieStore().add(uri, cookie); } catch (URISyntaxException e) { e.printStackTrace(); } } }
public void tstGetPost() throws Exception { String urlSource = "http://localhost:8080/beige-accounting-web/secure/main.jsp"; String urlBase = urlSource.substring(0, urlSource.indexOf("secure") - 1); assertEquals("http://localhost:8080/beige-accounting-web", urlBase); CookieManager cookieManager = new CookieManager(); cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cookieManager); URL url = new URL(urlSource); Map<String, Object> params = new HashMap<String, Object>(); params.put("userName", "admin"); params.put("userPass", "admin"); params.put("authMethod", "form"); params.put("urlBase", urlBase); params.put("authUrl", urlBase + "/secure/j_security_check"); params.put("authUserName", "j_username"); params.put("authUserPass", "j_password"); params.put("urlSource", urlSource); tstAuthGet(url, params, cookieManager); //either Get or Post for test allowed urlSource = "http://localhost:8080/beige-accounting-web/secure/sendEntities"; params.put("urlSource", urlSource); //url = new URL(urlSource); //tstAuthPost(url, params, cookieManager); }
void processCookie(String url, Map<String, List<String>> headers) { if (!isUseCookie()) { return; } try { CookieHandler cookieManager = getCookieHandler(); Map<String, List<String>> singleMap = cookieManager.get(URI.create(url), new HashMap<String, List<String>>(0)); List<String> cookies = singleMap.get("Cookie"); if (cookies != null) { headers.put("Cookie", Collections.singletonList(TextUtils.join(";", cookies))); } } catch (Throwable ex) { LogUtil.e(ex.getMessage(), ex); } }
@Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); android.webkit.CookieManager.getInstance().setAcceptCookie(true); CookieManager cookieManager = new CookieManager(new PersistentCookieStore(getApplicationContext()), CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cookieManager); new APITask(new APICallback() { @Override public void r(String result) { if (result.length() != 0) { Intent queueList = new Intent(MainActivity.this, QueueListActivity.class); startActivity(queueList); } else { setContentView(R.layout.activity_main); Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar); setSupportActionBar(toolbar); } } }).execute("method", "userData"); }
public static void main(String[] args) { AppVars.setAppVars(); Preferences.load(); if (Preferences.useSystemLookAndFeel()) { useSystemLookAndFeel(true); } CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); if (Preferences.useUserProxy()) { ComicUtil.setProxy(Preferences.getProxyAddress(), Preferences.getProxyPort(), Preferences.getProxyUsername(), Preferences.getProxyEncryptedPassword()); } ComicUtil.getNewestComic(); EventQueue.invokeLater(() -> { MainFrame frame = new MainFrame("XKCDownload"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.setVisible(true); frame.setLocationRelativeTo(null); }); }
public static void initCookieManager() { CookieHandler cookieHandler = CookieHandler.getDefault(); if (cookieHandler == null) { // CookieStore cookieStore = CookieStoreHolder.initInMemoryCookieStore(); // CookieManager cm = new CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL); CookieManager cm = new CookieManager(); cm.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cm); } // else { // CookieStoreHolder.initInMemoryCookieStore(); // } }
public PUserDaoRetrofitTest() { CookieManager cookieManager = new CookieManager(); cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cookieManager); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder// .setDateFormat("yyyy-MM-dd HH:mm:ss");// Gson gson = gsonBuilder.create(); RestAdapter restAdapter = new RestAdapter.Builder()// .setConverter(new GsonConverter(gson))// .setErrorHandler(new PErrorHandler())// .setEndpoint(API_URL)// .build(); this.userSerivece = restAdapter.create(IRUserService.class); userDao = new PUserDaoRetrofit(); userDao.setUserService(userSerivece); }
@Test public void controllerKioskMode() throws Exception { // setup Messages messages = new Messages(Locale.getDefault()); Runtime runtime = new TestRuntime(); View view = new TestView(); Controller controller = new Controller(view, runtime, messages); // make sure that the session cookies are passed during conversations CookieManager cookieManager = new CookieManager(); cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cookieManager); this.servletHolder.setInitParameter("Kiosk", "true"); // operate controller.run(); // verify LOG.debug("verify..."); }
public void showOnlineGame(GameOnline game) { WebEngine webEngine = webView.getEngine(); webEngine.setJavaScriptEnabled(true); URI uri = URI.create(MainApp.webConnector.getUrlFromGame(game)); List<String> cookies = new ArrayList<>(); for(Cookie cookie : MainApp.webConnector.cookies.getCookies()) { cookies.add(cookie.getName() + "=" + cookie.getValue()); } Map<String, List<String>> headers = new LinkedHashMap<String, List<String>>(); headers.put("Set-Cookie", cookies); try { CookieHandler.getDefault().put(uri, headers); } catch (IOException e) { e.printStackTrace(); } webEngine.load(uri.toString()); }
@Before public void init() { trash = new ArrayList<PContent>(); CookieManager cookieManager = new CookieManager(); cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cookieManager); GsonBuilder gsonBuilder = new GsonBuilder(); gsonBuilder// .setDateFormat("yyyy-MM-dd HH:mm:ss");// Gson gson = gsonBuilder.create(); RestAdapter restAdapter = new RestAdapter.Builder() // تعیین مبدل داده .setConverter(new GsonConverter(gson)) // تعیین کنترل کننده خطا .setErrorHandler(new PErrorHandler()) // تعیین آدرس سایت مورد نظر .setEndpoint(TestSettings.getApiURL()) // ایجاد یک نمونه .build(); // ایجاد سرویسها this.userService = restAdapter.create(IRUserService.class); this.contentService = restAdapter.create(IContentService.class); }
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); shouldAutoPlay = true; clearResumePosition(); mediaDataSourceFactory = buildDataSourceFactory(true); mainHandler = new Handler(); if (CookieHandler.getDefault() != DEFAULT_COOKIE_MANAGER) { CookieHandler.setDefault(DEFAULT_COOKIE_MANAGER); } setContentView(R.layout.player_activity); View rootView = findViewById(R.id.root); rootView.setOnClickListener(this); debugRootView = findViewById(R.id.controls_root); debugTextView = findViewById(R.id.debug_text_view); retryButton = findViewById(R.id.retry_button); retryButton.setOnClickListener(this); simpleExoPlayerView = findViewById(R.id.player_view); simpleExoPlayerView.setControllerVisibilityListener(this); simpleExoPlayerView.requestFocus(); }
public static void saveCookies() { PrintWriter writer = null; try { CookieManager manager = (CookieManager) CookieHandler.getDefault(); manager.getCookieStore().getCookies(); JSONSerializer cookieSerializer = new JSONSerializer(); String cookieJson = cookieSerializer.exclude("class").serialize(manager.getCookieStore().getCookies()); // System.out.println(cookieJson); writer = new PrintWriter(Locations.HOME + "/cookies.tmp", "UTF-8"); writer.write(cookieJson); } catch (IOException ex) { System.err.println(ex.getMessage()); } finally { if (writer != null) { writer.close(); } } }