Java Code Examples for java.net.CookieHandler

The following are top voted examples for showing how to use java.net.CookieHandler. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: boohee_v5.6   File: OkHttpClient.java   Source Code and License 9 votes vote down vote up
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;
}
 
Example 2
Project: LoRaWAN-Smart-Parking   File: OkHttpClient.java   Source Code and License 7 votes vote down vote up
/**
 * 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;
}
 
Example 3
Project: LoRaWAN-Smart-Parking   File: OkHttpClient.java   Source Code and License 7 votes vote down vote up
/**
 * 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;
}
 
Example 4
Project: react-native-videoplayer   File: ReactExoplayerView.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 5
Project: OftenPorter   File: HttpUtil.java   Source Code and License 6 votes vote down vote up
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;
    }
 
Example 6
Project: ExoPlayer-Offline   File: PlayerActivity.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 7
Project: Equella   File: SoapSession.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 8
Project: boohee_v5.6   File: HttpEngine.java   Source Code and License 6 votes vote down vote up
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();
}
 
Example 9
Project: jdk8u-jdk   File: CookieHttpsClientTest.java   Source Code and License 6 votes vote down vote up
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.");
    }
}
 
Example 10
Project: jdk8u-jdk   File: CookieHttpClientTest.java   Source Code and License 6 votes vote down vote up
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.");
    }
}
 
Example 11
Project: openjdk-jdk10   File: CookieHttpClientTest.java   Source Code and License 6 votes vote down vote up
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.");
    }
}
 
Example 12
Project: zabbkit-android   File: GraphFragment.java   Source Code and License 6 votes vote down vote up
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();
        }

    }
}
 
Example 13
Project: openjdk9   File: CookieHttpClientTest.java   Source Code and License 6 votes vote down vote up
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.");
    }
}
 
Example 14
Project: beige-software   File: HttpURLConnectionTest.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 15
Project: smart-mirror-app   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 16
Project: httplite   File: URLite.java   Source Code and License 6 votes vote down vote up
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);
    }
}
 
Example 17
Project: jdk8u_jdk   File: CookieHttpClientTest.java   Source Code and License 6 votes vote down vote up
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.");
    }
}
 
Example 18
Project: lookaside_java-1.8.0-openjdk   File: CookieHttpClientTest.java   Source Code and License 6 votes vote down vote up
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.");
    }
}
 
Example 19
Project: stayawhile-android   File: MainActivity.java   Source Code and License 6 votes vote down vote up
@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");
}
 
Example 20
Project: XKCDownload-deprecated   File: Main.java   Source Code and License 6 votes vote down vote up
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);
    });
}
 
Example 21
Project: cordova-plugin-background-mode   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 22
Project: motu   File: CookieStoreHolder.java   Source Code and License 6 votes vote down vote up
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();
        // }

    }
 
Example 23
Project: JPluf   File: PUserDaoRetrofitTest.java   Source Code and License 6 votes vote down vote up
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);
}
 
Example 24
Project: eid-applet   File: ControllerTest.java   Source Code and License 6 votes vote down vote up
@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...");
}
 
Example 25
Project: Turnierserver   File: ControllerGameManagement.java   Source Code and License 6 votes vote down vote up
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());
}
 
Example 26
Project: hackmxdf-2015   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 27
Project: L.TileLayer.Cordova   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 28
Project: JPluf   File: ContentServiceTest.java   Source Code and License 6 votes vote down vote up
@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);
}
 
Example 29
Project: bluemix-parking-meter   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 30
Project: cordova-android-tv   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 31
Project: transistor   File: PlayerActivity.java   Source Code and License 6 votes vote down vote up
@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();
}
 
Example 32
Project: android-discourse   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 33
Project: wototoplayer   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 34
Project: FXImgurUploader   File: Functions.java   Source Code and License 6 votes vote down vote up
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();
            }
        }
    }
 
Example 35
Project: IoTgo_Android_App   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 36
Project: CanDoVS2015   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 37
Project: CrossWalkAndroidStudio   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 38
Project: krakn   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 39
Project: krakn   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 40
Project: gwt-material-phonegap   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 41
Project: krakn   File: OkHttpClient.java   Source Code and License 6 votes vote down vote up
/**
 * 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;
}
 
Example 42
Project: Android-Client   File: NetworkStore.java   Source Code and License 5 votes vote down vote up
NetworkStore() {

        kwalaCookieStore = new KwalaCookieStore(KwalaApplication.getInstance());
        CookieManager cookieManager = new CookieManager(kwalaCookieStore, CookiePolicy.ACCEPT_ORIGINAL_SERVER);
        CookieHandler.setDefault(cookieManager);

        okHttpClient = new OkHttpClient.Builder()
                .cookieJar(new JavaNetCookieJar(cookieManager))
                .authenticator(authenticator)
                .readTimeout(30, TimeUnit.SECONDS)
                .writeTimeout(30, TimeUnit.SECONDS)
                .build();

        KwalaApplication application = KwalaApplication.getInstance();

        // Initialize the Amazon Cognito credentials provider
        CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(application,
                KwalaConstants.Network.AWS_IDENTITY_POOL_ID,
                Regions.US_EAST_1
        );

        // Initialize Amazon S3 and transfer utility
        s3Client = new AmazonS3Client(credentialsProvider);
        transferUtility = new TransferUtility(s3Client, application);
    }
 
Example 43
Project: vogar   File: TestEnvironment.java   Source Code and License 5 votes vote down vote up
public void reset() {
    // Reset system properties.
    System.setProperties(null);

    // From "L" release onwards, calling System.setProperties(null) clears the java.io.tmpdir,
    // so we set it again. No-op on earlier releases.
    System.setProperty("java.io.tmpdir", tmpDir);

    if (JAVA_RUNTIME_VERSION != null) {
        System.setProperty("java.runtime.version", JAVA_RUNTIME_VERSION);
    }
    if (JAVA_VM_INFO != null) {
        System.setProperty("java.vm.info", JAVA_VM_INFO);
    }
    if (JAVA_VM_VERSION != null) {
        System.setProperty("java.vm.version", JAVA_VM_VERSION);
    }
    if (JAVA_VM_VENDOR != null) {
        System.setProperty("java.vm.vendor", JAVA_VM_VENDOR);
    }
    if (JAVA_VM_NAME != null) {
        System.setProperty("java.vm.name", JAVA_VM_NAME);
    }

    // Require writable java.home and user.dir directories for preferences
    if ("Dalvik".equals(System.getProperty("java.vm.name"))) {
        String javaHome = tmpDir + "/java.home";
        IoUtils.safeMkdirs(new File(javaHome));
        System.setProperty("java.home", javaHome);
    }
    String userHome = System.getProperty("user.home");
    if (userHome.length() == 0) {
        userHome = tmpDir + "/user.home";
        IoUtils.safeMkdirs(new File(userHome));
        System.setProperty("user.home", userHome);
    }

    // Localization
    Locale.setDefault(Locale.US);
    TimeZone.setDefault(TimeZone.getTimeZone("America/Los_Angeles"));

    // Preferences
    // Temporarily silence the java.util.prefs logger, which otherwise emits
    // an unactionable warning. See RI bug 4751540.
    Logger loggerToMute = Logger.getLogger("java.util.prefs");
    boolean usedParentHandlers = loggerToMute.getUseParentHandlers();
    loggerToMute.setUseParentHandlers(false);
    try {
        // resetPreferences(Preferences.systemRoot());
        resetPreferences(Preferences.userRoot());
    } finally {
        loggerToMute.setUseParentHandlers(usedParentHandlers);
    }

    // HttpURLConnection
    Authenticator.setDefault(null);
    CookieHandler.setDefault(null);
    ResponseCache.setDefault(null);
    HttpsURLConnection.setDefaultHostnameVerifier(defaultHostnameVerifier);
    HttpsURLConnection.setDefaultSSLSocketFactory(defaultSSLSocketFactory);

    // Logging
    LogManager.getLogManager().reset();
    Logger.getLogger("").addHandler(new ConsoleHandler());

    // Cleanup to force CloseGuard warnings etc
    System.gc();
    System.runFinalization();
}
 
Example 44
Project: OftenPorter   File: HttpUtil.java   Source Code and License 5 votes vote down vote up
/**
 * 忽略证书验证。
 *
 * @param cookieHandler 为null时,表示使用默认的对象,并且不支持cookie。
 * @return
 */
public static synchronized OkHttpClient getClient(CookieHandler cookieHandler) {

    if (cookieHandler == null) {
        if (defaultClient == null) {
            defaultClient = _getClient(null);
        }
        return defaultClient;
    }
    return _getClient(cookieHandler);
}
 
Example 45
Project: LuaViewPlayground   File: CookieManager.java   Source Code and License 5 votes vote down vote up
private static java.net.CookieManager getCookieManager() {
    if (mCookieManager == null) {
        mCookieManager = new java.net.CookieManager(null, CookiePolicy.ACCEPT_ALL);
        CookieHandler.setDefault(mCookieManager);
    }
    return mCookieManager;
}
 
Example 46
Project: FancyTab   File: VolleySingleton.java   Source Code and License 5 votes vote down vote up
private RequestQueue getRequestQueue() {
    if (mRequestQueue == null) {
        cookieManager = new CookieManager();
        CookieHandler.setDefault(cookieManager);

        mRequestQueue = Volley.newRequestQueue(mCtx.getApplicationContext());
    }
    return mRequestQueue;
}
 
Example 47
Project: faitic-checker   File: Faitic.java   Source Code and License 5 votes vote down vote up
private static void startCookieSession(){

		cookieManager=new CookieManager();
		cookieManager.setCookiePolicy(CookiePolicy.ACCEPT_ORIGINAL_SERVER);
		cookieManager.getCookieStore().removeAll();

		if(android) {
			CookieHandler.setDefault(cookieManager);
		}

	}
 
Example 48
Project: OpenJSharp   File: HttpConfigFeature.java   Source Code and License 5 votes vote down vote up
private static CookieHandler getInternalCookieHandler() {
    try {
        return (CookieHandler)cookieManagerConstructor.newInstance(null, cookiePolicy);
    } catch(Exception e) {
        throw new WebServiceException(e);
    }
}
 
Example 49
Project: LoRaWAN-Smart-Parking   File: HttpEngine.java   Source Code and License 5 votes vote down vote up
/**
 * Populates requestHeaders with defaults and cookies.
 *
 * <p>This client doesn't specify a default {@code Accept} header because it
 * doesn't know what content types the application is interested in.
 */
private void prepareRawRequestHeaders() throws IOException {
  requestHeaders.getHeaders().setRequestLine(getRequestLine());

  if (requestHeaders.getUserAgent() == null) {
    requestHeaders.setUserAgent(getDefaultUserAgent());
  }

  if (requestHeaders.getHost() == null) {
    requestHeaders.setHost(getOriginAddress(policy.getURL()));
  }

  if ((connection == null || connection.getHttpMinorVersion() != 0)
      && requestHeaders.getConnection() == null) {
    requestHeaders.setConnection("Keep-Alive");
  }

  if (requestHeaders.getAcceptEncoding() == null) {
    transparentGzip = true;
    requestHeaders.setAcceptEncoding("gzip");
  }

  if (hasRequestBody() && requestHeaders.getContentType() == null) {
    requestHeaders.setContentType("application/x-www-form-urlencoded");
  }

  long ifModifiedSince = policy.getIfModifiedSince();
  if (ifModifiedSince != 0) {
    requestHeaders.setIfModifiedSince(new Date(ifModifiedSince));
  }

  CookieHandler cookieHandler = client.getCookieHandler();
  if (cookieHandler != null) {
    requestHeaders.addCookies(
        cookieHandler.get(uri, requestHeaders.getHeaders().toMultimap(false)));
  }
}
 
Example 50
Project: LoRaWAN-Smart-Parking   File: HttpEngine.java   Source Code and License 5 votes vote down vote up
/**
 * Populates requestHeaders with defaults and cookies.
 *
 * <p>This client doesn't specify a default {@code Accept} header because it
 * doesn't know what content types the application is interested in.
 */
private void prepareRawRequestHeaders() throws IOException {
  requestHeaders.getHeaders().setRequestLine(getRequestLine());

  if (requestHeaders.getUserAgent() == null) {
    requestHeaders.setUserAgent(getDefaultUserAgent());
  }

  if (requestHeaders.getHost() == null) {
    requestHeaders.setHost(getOriginAddress(policy.getURL()));
  }

  if ((connection == null || connection.getHttpMinorVersion() != 0)
      && requestHeaders.getConnection() == null) {
    requestHeaders.setConnection("Keep-Alive");
  }

  if (requestHeaders.getAcceptEncoding() == null) {
    transparentGzip = true;
    requestHeaders.setAcceptEncoding("gzip");
  }

  if (hasRequestBody() && requestHeaders.getContentType() == null) {
    requestHeaders.setContentType("application/x-www-form-urlencoded");
  }

  long ifModifiedSince = policy.getIfModifiedSince();
  if (ifModifiedSince != 0) {
    requestHeaders.setIfModifiedSince(new Date(ifModifiedSince));
  }

  CookieHandler cookieHandler = client.getCookieHandler();
  if (cookieHandler != null) {
    requestHeaders.addCookies(
        cookieHandler.get(uri, requestHeaders.getHeaders().toMultimap(false)));
  }
}
 
Example 51
Project: jdk8u-jdk   File: HttpOnly.java   Source Code and License 5 votes vote down vote up
void test(String[] args) throws Exception {
    HttpServer server = startHttpServer();
    CookieHandler previousHandler = CookieHandler.getDefault();
    try {
        InetSocketAddress address = server.getAddress();
        URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress()
                          + ":" + address.getPort() + URI_PATH);
        populateCookieStore(uri);
        doClient(uri);
    } finally {
        CookieHandler.setDefault(previousHandler);
        server.stop(0);
    }
}
 
Example 52
Project: jdk8u-jdk   File: HttpOnly.java   Source Code and License 5 votes vote down vote up
void populateCookieStore(URI uri)
        throws IOException {

    CookieManager cm = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cm);
    Map<String,List<String>> header = new HashMap<>();
    List<String> values = new ArrayList<>();
    values.add("JSESSIONID=" + SESSION_ID + "; version=1; Path="
               + URI_PATH +"; HttpOnly");
    values.add("CUSTOMER=WILE_E_COYOTE; version=1; Path=" + URI_PATH);
    header.put("Set-Cookie", values);
    cm.put(uri, header);
}
 
Example 53
Project: openjdk-jdk10   File: CookieHttpsClientTest.java   Source Code and License 5 votes vote down vote up
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.");
    }
}
 
Example 54
Project: openjdk-jdk10   File: HttpOnly.java   Source Code and License 5 votes vote down vote up
void test(String[] args) throws Exception {
    HttpServer server = startHttpServer();
    CookieHandler previousHandler = CookieHandler.getDefault();
    try {
        InetSocketAddress address = server.getAddress();
        URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress()
                          + ":" + address.getPort() + URI_PATH);
        populateCookieStore(uri);
        doClient(uri);
    } finally {
        CookieHandler.setDefault(previousHandler);
        server.stop(0);
    }
}
 
Example 55
Project: openjdk-jdk10   File: HttpOnly.java   Source Code and License 5 votes vote down vote up
void populateCookieStore(URI uri)
        throws IOException {

    CookieManager cm = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
    CookieHandler.setDefault(cm);
    Map<String,List<String>> header = new HashMap<>();
    List<String> values = new ArrayList<>();
    values.add("JSESSIONID=" + SESSION_ID + "; version=1; Path="
               + URI_PATH +"; HttpOnly");
    values.add("CUSTOMER=WILE_E_COYOTE; version=1; Path=" + URI_PATH);
    header.put("Set-Cookie", values);
    cm.put(uri, header);
}
 
Example 56
Project: openjdk-jdk10   File: HttpConfigFeature.java   Source Code and License 5 votes vote down vote up
private static CookieHandler getInternalCookieHandler() {
    try {
        return (CookieHandler)cookieManagerConstructor.newInstance(null, cookiePolicy);
    } catch(Exception e) {
        throw new WebServiceException(e);
    }
}
 
Example 57
Project: TaipeiTechRefined   File: PortalFragment.java   Source Code and License 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    PortalFragment fragment = mActivityRef.get();
    if (fragment == null) {
        return;
    }
    WebView webview = (WebView) fragmentView
            .findViewById(R.id.webview);
    switch (msg.what) {
        case BaseRunnable.REFRESH:
            java.net.CookieStore rawCookieStore = ((java.net.CookieManager)
                    CookieHandler.getDefault()).getCookieStore();
            if (rawCookieStore != null) {
                CookieManager cookieManager = CookieManager.getInstance();
                cookieManager.setAcceptCookie(true);
                try {
                    URI uri = new URI(PORTAL_URL);
                    for (HttpCookie cookie : rawCookieStore.get(uri)) {
                        String cookieString = cookie.getName() + "="
                                + cookie.getValue() + "; domain="
                                + cookie.getDomain();
                        cookieManager.setCookie(PORTAL_URL + "myPortal.do",
                                cookieString);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            webview.loadUrl(PORTAL_URL + "aptreeList.do");
            break;
        case BaseRunnable.ERROR:
            webview.loadUrl(PORTAL_URL);
            break;
    }
    fragment.dismissProgressDialog();
    Toast.makeText(fragment.getContext(), R.string.web_back_hint, Toast.LENGTH_SHORT)
            .show();
}
 
Example 58
Project: TaipeiTechRefined   File: MainApplication.java   Source Code and License 5 votes vote down vote up
@Override
public void onCreate() {
    super.onCreate();
    lang = Locale.getDefault().getLanguage();   //取得當前系統語言 <- 作為課表和學分語言的判斷依據
    CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL));
    singleton = this;
    Model.getInstance();
    Intent check_intent = new Intent(this, ActivityCheckReceiver.class);
    check_intent.putExtra("action", "com.taipeitech.action.ACTIVITY_CHECK");
    sendBroadcast(check_intent);
}
 
Example 59
Project: TaipeiTechRefined   File: PortalActivity.java   Source Code and License 5 votes vote down vote up
@Override
public void handleMessage(Message msg) {
    PortalActivity activity = mActivityRef.get();
    if (activity == null || activity.isFinishing()) {
        return;
    }
    WebView webview = (WebView) activity
            .findViewById(R.id.webview);
    switch (msg.what) {
        case BaseRunnable.REFRESH:
            java.net.CookieStore rawCookieStore = ((java.net.CookieManager)
                    CookieHandler.getDefault()).getCookieStore();
            if (rawCookieStore != null) {
                CookieManager cookieManager = CookieManager.getInstance();
                cookieManager.setAcceptCookie(true);
                try {
                    URI uri = new URI(PORTAL_URL);
                    for (HttpCookie cookie : rawCookieStore.get(uri)) {
                        String cookieString = cookie.getName() + "="
                                + cookie.getValue() + "; domain="
                                + cookie.getDomain();
                        cookieManager.setCookie(PORTAL_URL + "myPortal.do",
                                cookieString);
                    }
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
            webview.loadUrl(PORTAL_URL + "myPortal.do");
            break;
        case BaseRunnable.ERROR:
            webview.loadUrl(PORTAL_URL);
            break;
    }
    activity.dismissProgressDialog();
    Toast.makeText(activity, R.string.web_back_hint, Toast.LENGTH_LONG)
            .show();
}
 
Example 60
Project: openjdk9   File: CookieHttpsClientTest.java   Source Code and License 5 votes vote down vote up
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.");
    }
}