List of usage examples for java.net CookieHandler setDefault
public static synchronized void setDefault(CookieHandler cHandler)
From source file:io.jari.geenstijl.API.API.java
/** * ensureCookies sets up cookiemanager and makes sure cookies are set up *//* www. jav a2 s.c om*/ static void ensureCookies() { if (CookieHandler.getDefault() == null) { cookieManager = new CookieManager(null, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cookieManager); } }
From source file:com.google.android.exoplayer2.demo.MediaPlayerFragment.java
@Override public void onViewCreated(View v, Bundle savedInstanceState) { //@Override//from ww w . ja v a2 s . c om //public void onCreate(Bundle savedInstanceState) { super.onViewCreated(v, 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 = v.findViewById(R.id.root); rootView.setOnClickListener(this); debugRootView = (LinearLayout) v.findViewById(R.id.controls_root); debugTextView = (TextView) v.findViewById(R.id.debug_text_view); retryButton = (Button) v.findViewById(R.id.retry_button); retryButton.setOnClickListener(this); centerInfo = (TextView) v.findViewById(R.id.centerInfo); // localTime = (TextView) v.findViewById(R.id.localTime); // battery = (BatteryLevelView) v.findViewById(R.id.battery); simpleExoPlayerView = (SimpleExoPlayerView) v.findViewById(R.id.player_view); simpleExoPlayerView.setControllerVisibilityListener(this); simpleExoPlayerView.requestFocus(); final Intent intent = getActivity().getIntent(); if (intent != null) { Uri extras = intent.getData(); if (extras != null) { CURRENT_PATH = extras.getPath(); Log.d(TAG, "intent.getData() " + CURRENT_PATH); } } updateColor(rootView); }
From source file:org.horaapps.leafpic.activities.PlayerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(org.horaapps.leafpic.R.layout.activity_player); FrameLayout root = (FrameLayout) findViewById(org.horaapps.leafpic.R.id.root); findViewById(R.id.video_frame).setOnClickListener(new View.OnClickListener() { @Override/*from ww w . j a va 2 s. c o m*/ public void onClick(View view) { toggleControlsVisibility(); } }); root.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event); } }); root.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000)); shutterView = findViewById(org.horaapps.leafpic.R.id.shutter); videoFrame = (AspectRatioFrameLayout) findViewById(org.horaapps.leafpic.R.id.video_frame); surfaceView = (SurfaceView) findViewById(org.horaapps.leafpic.R.id.surface_view); surfaceView.getHolder().addCallback(this); mediaController = new CustomMediaController(this, this); mediController_anchor = findViewById(org.horaapps.leafpic.R.id.media_player_anchor); mediaController.setAnchorView(root); //mediaController.setPaddingRelative(0,0,0,Measure.getNavBarHeight(PlayerActivity.this)); toolbar = (Toolbar) findViewById(org.horaapps.leafpic.R.id.toolbar); initUI(); CookieHandler currentHandler = CookieHandler.getDefault(); if (currentHandler != defaultCookieManager) CookieHandler.setDefault(defaultCookieManager); audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this); audioCapabilitiesReceiver.register(); }
From source file:com.windigo.http.client.ApacheHttpClient.java
/** * Handle cookies with cookie-handler// w ww . jav a 2 s .co m * */ private void setupCookieManager() { CookieManager cookieManager = new CookieManager(); CookieHandler.setDefault(cookieManager); Logger.log("[Request] Setting cookie manager"); }
From source file:org.fossasia.phimpme.leafpic.activities.PlayerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_player); FrameLayout root = (FrameLayout) findViewById(R.id.root); findViewById(R.id.video_frame).setOnClickListener(new View.OnClickListener() { @Override/* www . ja v a 2s .co m*/ public void onClick(View view) { toggleControlsVisibility(); } }); root.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event); } }); root.setBackgroundColor(ContextCompat.getColor(getApplicationContext(), R.color.md_black_1000)); shutterView = findViewById(R.id.shutter); videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame); surfaceView = (SurfaceView) findViewById(R.id.surface_view); surfaceView.getHolder().addCallback(this); mediaController = new CustomMediaController(this, this); mediController_anchor = findViewById(R.id.media_player_anchor); mediaController.setAnchorView(root); //mediaController.setPaddingRelative(0,0,0,Measure.getNavBarHeight(PlayerActivity.this)); toolbar = (Toolbar) findViewById(R.id.toolbar); initUI(); CookieHandler currentHandler = CookieHandler.getDefault(); if (currentHandler != defaultCookieManager) CookieHandler.setDefault(defaultCookieManager); audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this); audioCapabilitiesReceiver.register(); }
From source file:com.horaapps.leafpic.PlayerActivity.java
@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_player); FrameLayout root = (FrameLayout) findViewById(R.id.root); root.setOnTouchListener(new OnTouchListener() { @Override//from w ww . j a va 2 s . co m public boolean onTouch(View view, MotionEvent motionEvent) { if (motionEvent.getAction() == MotionEvent.ACTION_DOWN) { toggleControlsVisibility(); } else if (motionEvent.getAction() == MotionEvent.ACTION_UP) { //view.performClick(); } return true; } }); root.setOnKeyListener(new OnKeyListener() { @Override public boolean onKey(View v, int keyCode, KeyEvent event) { return !(keyCode == KeyEvent.KEYCODE_BACK || keyCode == KeyEvent.KEYCODE_ESCAPE || keyCode == KeyEvent.KEYCODE_MENU) && mediaController.dispatchKeyEvent(event); } }); root.setBackgroundColor(R.color.md_black_1000); shutterView = findViewById(R.id.shutter); videoFrame = (AspectRatioFrameLayout) findViewById(R.id.video_frame); surfaceView = (SurfaceView) findViewById(R.id.surface_view); surfaceView.getHolder().addCallback(this); mediaController = new KeyCompatibleMediaController(this); mediController_anchor = findViewById(R.id.media_player_anchor); mediaController.setAnchorView(mediController_anchor); mediaController.setPaddingRelative(0, 0, 0, Measure.getNavBarHeight(PlayerActivity.this)); toolbar = (Toolbar) findViewById(R.id.toolbar); initUI(); CookieHandler currentHandler = CookieHandler.getDefault(); if (currentHandler != defaultCookieManager) CookieHandler.setDefault(defaultCookieManager); audioCapabilitiesReceiver = new AudioCapabilitiesReceiver(this, this); audioCapabilitiesReceiver.register(); }
From source file:edu.stanford.epadd.launcher.Splash.java
private static boolean isURLAlive(String url) throws IOException { try {// w w w . j a v a2 s. c o m // attempt to fetch the page // throws a connect exception if the server is not even running // so catch it and return false // since "index" may auto load default archive, attach it to session, and redirect to "info" page, // we need to maintain the session across the pages. // see "Maintaining the session" at http://stackoverflow.com/questions/2793150/how-to-use-java-net-urlconnection-to-fire-and-handle-http-requests CookieHandler.setDefault(new CookieManager(null, CookiePolicy.ACCEPT_ALL)); out.println("Testing for already running ePADD by probing " + url); HttpURLConnection u = (HttpURLConnection) new URL(url).openConnection(); if (u.getResponseCode() == 200) { u.disconnect(); out.println("ePADD is already running!"); return true; } u.disconnect(); } catch (ConnectException ce) { } out.println("Good, ePADD is not already running"); return false; }
From source file:fr.cls.atoll.motu.api.rest.MotuRequest.java
/** * Executes the request and returns the result as a stream. The stream contains: - the extracted netcdf * file if mode is 'console' - the url the extracted netcdf file if mode is 'url' url - the url of the XML * status file if mode is 'status' (this file contains the status of the request : INPROGRESS or * ERROR+error message or DONE)./*ww w.java2s. c o m*/ * * This function must be used * * @return the result of the request as a stream * * @throws MotuRequestException the motu request exception */ public InputStream executeV2() throws MotuRequestException { if (LOG.isDebugEnabled()) { LOG.debug("executeV2() - entering"); } // First set the default cookie manager. // Must be set before the first http request. // This is essential for cookie session managment with CAS authentication cookieStore.removeAll(); CookieManager cm = new CookieManager(cookieStore, CookiePolicy.ACCEPT_ALL); CookieHandler.setDefault(cm); URL url = null; // Get the authentication mode parameter String authModeString = (String) motuRequestParameters .getParameter(MotuRequestParametersConstant.PARAM_AUTHENTICATION_MODE); AuthenticationMode authMode = null; if (!AssertionUtils.isNullOrEmpty(authModeString)) { authMode = AuthenticationMode.fromValue((String) motuRequestParameters .getParameter(MotuRequestParametersConstant.PARAM_AUTHENTICATION_MODE)); } // Authentication mode is not an extraction criteria, remove it now motuRequestParameters.removeParameter(MotuRequestParametersConstant.PARAM_AUTHENTICATION_MODE); // Get login / password parameters, String login = (String) motuRequestParameters.getParameter(MotuRequestParametersConstant.PARAM_LOGIN); String password = (String) motuRequestParameters.getParameter(MotuRequestParametersConstant.PARAM_PWD); // Login/password are not extraction criteria, remove them now motuRequestParameters.removeParameter(MotuRequestParametersConstant.PARAM_LOGIN); motuRequestParameters.removeParameter(MotuRequestParametersConstant.PARAM_PWD); // String requestParams = null; String targetUrl = getRequestUrl(); // Check is authentication mode is set or not // if not set, guess the authentication mode boolean guessAuthentication = (authMode == null) && (!AssertionUtils.isNullOrEmpty(login)); if (guessAuthentication) { UserBase user = new UserBase(); if (!AssertionUtils.isNullOrEmpty(login)) { user.setLogin(login); if (AssertionUtils.isNullOrEmpty(password)) { password = ""; } user.setPwd(password); } try { RestUtil.checkAuthenticationMode(servletUrl, user); authMode = user.getAuthenticationMode(); } catch (MotuCasException e) { String msg = String.format("Unable to check authentication mode from url '%s'. Reason is:\n %s", servletUrl, e.notifyException()); throw new MotuRequestException(msg, e); } catch (IOException e) { String msg = String.format("Unable to check authentication mode from url '%s'. Reason is:\n %s", servletUrl, e.getMessage()); throw new MotuRequestException(msg, e); } } try { if (authMode == AuthenticationMode.CAS) { // Add CAS ticket to the query parameters // If url is CASified then a CAS ticket is added to the returned url. // If url is not CASified then the original url is returned. // If login or password is null or empty, then the original url is returned. targetUrl = AssertionUtils.addCASTicket(targetUrl, login, password, null); } url = new URL(targetUrl); } catch (MalformedURLException e) { LOG.error("executeV2()", e); throw new MotuRequestException("Invalid url", e); } catch (MotuCasBadRequestException e) { LOG.error("executeV2()", e); throw new MotuRequestException("Invalid url", e); } catch (IOException e) { LOG.error("executeV2()", e); throw new MotuRequestException("Invalid url", e); } LOG.info("URL=" + targetUrl); HttpURLConnection urlConnection = null; try { urlConnection = (HttpURLConnection) url.openConnection(); urlConnection.setConnectTimeout(connectTimeout); if ((authMode == AuthenticationMode.BASIC) && (!AssertionUtils.isNullOrEmpty(login)) && (!AssertionUtils.isNullOrEmpty(password))) { // Set basic authentication StringBuffer stringBuffer = new StringBuffer(); stringBuffer.append(login); stringBuffer.append(":"); stringBuffer.append(password); byte[] encoding = new org.apache.commons.codec.binary.Base64() .encode(stringBuffer.toString().getBytes()); urlConnection.setRequestProperty("Authorization", "Basic " + new String(encoding)); } } catch (IOException ex) { LOG.error("executeV2()", ex); throw new MotuRequestException("Request connection failed", ex); } try { InputStream returnInputStream = urlConnection.getInputStream(); if (LOG.isDebugEnabled()) { LOG.debug("executeV2() - exiting"); } return returnInputStream; } catch (IOException ex) { LOG.error("executeV2()", ex); MotuRequestException motuRequestException; try { motuRequestException = new MotuRequestException("Request failed - errorCode: " + urlConnection.getResponseCode() + ", errorMsg: " + urlConnection.getResponseMessage(), ex); } catch (IOException e) { LOG.error("executeV2()", e); motuRequestException = new MotuRequestException("Request connection failed", ex); } throw motuRequestException; } }
From source file:edgeserver.Descoberta.java
private void toggleGateway(Gateway gateway, String job) throws Exception { CookieHandler.setDefault(new CookieManager()); HTTPClient http = new HTTPClient(); List<NameValuePair> postp = new ArrayList<>(); postp.add(new BasicNameValuePair("login", "huberto")); postp.add(new BasicNameValuePair("password", "99766330")); http.sendPost(this.urlLogin, postp); List<NameValuePair> GatewayParams = new ArrayList<>(); GatewayParams.add(new BasicNameValuePair("gateway_id", Integer.toString(gateway.getId()))); GatewayParams.add(new BasicNameValuePair("job", job)); String result = http.GetPageContent(this.toggleGateway, GatewayParams); if (null != result) switch (result) { case "desativado": System.out.println("-> Gateway " + gateway.getNome() + "(" + gateway.getId() + ") DESATIVADO no Servidor de Contexto"); break; case "ativado": System.out.println("-> Gateway " + gateway.getNome() + "(" + gateway.getId() + ") ATIVADO no Servidor de Contexto"); break; }//from w w w . j av a 2 s . c o m }
From source file:se.leap.bitmaskclient.ProviderAPI.java
private boolean setTokenIfAvailable(JSONObject authentication_step_result) { try {//from w w w.ja v a 2 s .com LeapSRPSession.setToken(authentication_step_result.getString(LeapSRPSession.TOKEN)); CookieHandler.setDefault(null); // we don't need cookies anymore } catch (JSONException e) { // return false; } return true; }