List of usage examples for java.net CookieManager CookieManager
public CookieManager()
From source file:fr.mixit.android.utils.NetworkUtils.java
@TargetApi(Build.VERSION_CODES.GINGERBREAD) static ResponseHttp getInputStreamFromHttpUrlConnection(String url, boolean isPost, String args) { final ResponseHttp myResponse = new ResponseHttp(); HttpURLConnection urlConnection = null; if (cookieManager == null) { cookieManager = new CookieManager(); CookieHandler.setDefault(cookieManager); }//from w w w. j a v a 2 s . c o m try { String urlWithParams = url; if (!isPost && args != null) { urlWithParams = getGetURL(url, args); } final URL urlObject = new URL(urlWithParams); urlConnection = (HttpURLConnection) urlObject.openConnection(); urlConnection.setConnectTimeout(CONNECTION_TIMEOUT); urlConnection.setReadTimeout(SOCKET_TIMEOUT); // if (cookieSession != null) { // cookieManager.getCookieStore().removeAll(); // cookieManager.getCookieStore().addCookie(cookieSession); // } if (isPost) { urlConnection.setDoOutput(true); } // urlConnection.connect(); if (isPost && args != null) { final byte[] params = args.getBytes(HTTP.UTF_8); urlConnection.setFixedLengthStreamingMode(params.length);// or urlConnection.setChunkedStreamingMode(0); final OutputStream out = new BufferedOutputStream(urlConnection.getOutputStream()); out.write(params); } myResponse.status = urlConnection.getResponseCode(); if (DEBUG_MODE) { Log.d(TAG, "Status code : " + myResponse.status); } myResponse.jsonText = getJson(urlConnection.getInputStream()); } catch (final MalformedURLException e) { if (DEBUG_MODE) { Log.e(TAG, "The URL is malformatted", e); } } catch (final IllegalAccessError e) { if (DEBUG_MODE) { Log.e(TAG, "setDoOutput after openning a connection or already done"); } } catch (final UnsupportedEncodingException e) { if (DEBUG_MODE) { Log.e(TAG, "UTF8 unsupported for args", e); } } catch (final IllegalStateException e) { if (DEBUG_MODE) { Log.e(TAG, "I/O Error", e); } } catch (final IllegalArgumentException e) { if (DEBUG_MODE) { Log.e(TAG, "I/O Error", e); } } catch (final IOException e) { if (DEBUG_MODE) { Log.e(TAG, "I/O Error", e); } } finally { if (urlConnection != null) { urlConnection.disconnect(); } } return myResponse; }
From source file:com.dotmarketing.portlets.rules.actionlet.VisitorsTagsActionletFTest.java
/** * Test adding tags to visitor object/* w w w. j av a 2s . c o m*/ * @throws Exception */ @Test public void addTag1() throws Exception { sysuser = userAPI.getSystemUser(); Host host = hostAPI.findDefaultHost(sysuser, false); // setting up the requirements for testing // a new cotent to create the persona linked to the visitor Contentlet personaContentlet = new Contentlet(); personaContentlet.setStructureInode(PersonaAPI.DEFAULT_PERSONAS_STRUCTURE_INODE); personaContentlet.setHost(host.getIdentifier()); personaContentlet.setLanguageId(languageAPI.getDefaultLanguage().getId()); String name = "persona1" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); personaContentlet.setProperty(PersonaAPI.NAME_FIELD, name); personaContentlet.setProperty(PersonaAPI.KEY_TAG_FIELD, name); personaContentlet.setProperty(PersonaAPI.TAGS_FIELD, "persona"); personaContentlet.setProperty(PersonaAPI.DESCRIPTION_FIELD, "test to delete"); personaContentlet = contentletAPI.checkin(personaContentlet, sysuser, false); contentletAPI.publish(personaContentlet, sysuser, false); Persona persona = new Persona(personaContentlet); // 4 test rules // test 1 : using a single tag createTagActionlet("testing"); // test 2 : using a multiple tags createTagActionlet("persona,asia,china,nigeria"); // test 3 : using a new tag (not from the tag manager) createTagActionlet("newtag"); // test 4 : using multiple a new tags (not from the tag manager) createTagActionlet("new2tag,new3tag,new4tag"); // environment setup // FOLDER Folder folder = folderAPI.createFolders("/tags-actionlet-" + System.currentTimeMillis(), host, sysuser, false); // TEMPLATE Template template = templateAPI.find(BLANK_TEMPLATE_INODE, sysuser, false); // PAGE String page = "tags-page-" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); Contentlet pageContentlet = new Contentlet(); pageContentlet.setStructureInode(HTMLPageAssetAPIImpl.DEFAULT_HTMLPAGE_ASSET_STRUCTURE_INODE); pageContentlet.setHost(host.getIdentifier()); pageContentlet.setProperty(HTMLPageAssetAPIImpl.FRIENDLY_NAME_FIELD, page); pageContentlet.setProperty(HTMLPageAssetAPIImpl.URL_FIELD, page); pageContentlet.setProperty(HTMLPageAssetAPIImpl.TITLE_FIELD, page); pageContentlet.setProperty(HTMLPageAssetAPIImpl.CACHE_TTL_FIELD, "0"); pageContentlet.setProperty(HTMLPageAssetAPIImpl.TEMPLATE_FIELD, template.getIdentifier()); pageContentlet.setLanguageId(languageAPI.getDefaultLanguage().getId()); pageContentlet.setFolder(folder.getInode()); pageContentlet = contentletAPI.checkin(pageContentlet, sysuser, false); contentletAPI.publish(pageContentlet, sysuser, false); // Widget to show the tag String title = "personawidget" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); String body = "<p>$visitor.accruedTags</p>"; Contentlet widgetContentlet = new Contentlet(); Structure contentst = StructureFactory.getStructureByVelocityVarName("webPageContent"); Structure widgetst = StructureFactory.getStructureByVelocityVarName("SimpleWidget"); widgetContentlet.setStructureInode(widgetst.getInode()); widgetContentlet.setHost(host.getIdentifier()); widgetContentlet.setProperty("widgetTitle", title); widgetContentlet.setLanguageId(languageAPI.getDefaultLanguage().getId()); widgetContentlet.setProperty("code", body); widgetContentlet.setFolder(folder.getInode()); widgetContentlet = contentletAPI.checkin(widgetContentlet, sysuser, false); contentletAPI.publish(widgetContentlet, sysuser, false); Container container = null; List<Container> containers = containerAPI.findContainersForStructure(contentst.getInode()); for (Container c : containers) { if (c.getTitle().equals("Blank Container")) { container = c; break; } } MultiTree m = new MultiTree(pageContentlet.getIdentifier(), container.getIdentifier(), widgetContentlet.getIdentifier()); MultiTreeFactory.saveMultiTree(m); // login CookieHandler.setDefault(new CookieManager()); URL testUrl = new URL(baseUrl + "/c/portal_public/login?my_account_cmd=auth&my_account_login=admin@dotcms.com&password=admin&my_account_r_m=true"); IOUtils.toString(testUrl.openStream(), "UTF-8"); String url = baseUrl + folder.getPath() + page + "?mainFrame=true&livePage=0com.dotmarketing.htmlpage.language=1&host_id=" + host.getIdentifier() + "&com.dotmarketing.persona.id=" + persona.getIdentifier() + "&previewPage=2"; testUrl = new URL(url); StringBuilder result = new StringBuilder(); InputStreamReader isr = new InputStreamReader(testUrl.openStream()); BufferedReader br = new BufferedReader(isr); int byteRead; while ((byteRead = br.read()) != -1) { result.append((char) byteRead); } br.close(); // testing Assert.assertTrue("Expected tag 'testing' not found", result.toString().contains("testing")); Assert.assertTrue("Expected tag 'persona' not found", result.toString().contains("persona")); Assert.assertTrue("Expected tag 'asia' not found", result.toString().contains("asia")); Assert.assertTrue("Expected tag 'china' not found", result.toString().contains("china")); Assert.assertTrue("Expected tag 'nigeria' not found", result.toString().contains("nigeria")); Assert.assertTrue("Expected tag 'newtag' not found", result.toString().contains("newtag")); Assert.assertTrue("Expected tag 'new2tag' not found", result.toString().contains("new2tag")); Assert.assertTrue("Expected tag 'new3tag' not found", result.toString().contains("new3tag")); Assert.assertTrue("Expected tag 'new4tag' not found", result.toString().contains("new4tag")); Assert.assertFalse("Unexpected tag 'dollar' found", result.toString().contains("dollar")); // clean up contentletAPI.unpublish(personaContentlet, sysuser, false); contentletAPI.unpublish(widgetContentlet, sysuser, false); contentletAPI.unpublish(pageContentlet, sysuser, false); contentletAPI.archive(personaContentlet, sysuser, false); contentletAPI.archive(widgetContentlet, sysuser, false); contentletAPI.archive(pageContentlet, sysuser, false); contentletAPI.delete(personaContentlet, sysuser, false); contentletAPI.delete(widgetContentlet, sysuser, false); contentletAPI.delete(pageContentlet, sysuser, false); folderAPI.delete(folder, sysuser, false); }
From source file:com.dotmarketing.portlets.rules.actionlet.PersonaActionletFTest.java
/** * Test the creation of a persona in the backend and if the persona object * change in the $visitor variable for the preview as persona functionality card584 * @throws Exception// w w w . j a v a2 s. c o m */ @Test public void addPersona() throws Exception { sysuser = userAPI.getSystemUser(); Host host = hostAPI.findDefaultHost(sysuser, false); Host systemHost = hostAPI.findSystemHost(); /* * Create personas for test */ //Create a Persona related to Single host Contentlet persona = new Contentlet(); persona.setStructureInode(PersonaAPI.DEFAULT_PERSONAS_STRUCTURE_INODE); persona.setHost(host.getIdentifier()); persona.setLanguageId(languageAPI.getDefaultLanguage().getId()); String name = "persona1" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); persona.setProperty(PersonaAPI.NAME_FIELD, name); persona.setProperty(PersonaAPI.KEY_TAG_FIELD, name); persona.setProperty(PersonaAPI.TAGS_FIELD, "persona"); persona.setProperty(PersonaAPI.DESCRIPTION_FIELD, "test to delete"); persona = contentletAPI.checkin(persona, sysuser, false); contentletAPI.publish(persona, sysuser, false); Persona personaA = new Persona(persona); boolean isPersonaAIndexed = contentletAPI.isInodeIndexed(persona.getInode(), 500); Assert.assertTrue(isPersonaAIndexed); //Create a Persona related to System Host Contentlet persona2 = new Contentlet(); persona2.setStructureInode(PersonaAPI.DEFAULT_PERSONAS_STRUCTURE_INODE); persona2.setHost(systemHost.getIdentifier()); persona2.setLanguageId(languageAPI.getDefaultLanguage().getId()); String name2 = "persona2" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); persona2.setProperty(PersonaAPI.NAME_FIELD, name2); persona2.setProperty(PersonaAPI.KEY_TAG_FIELD, name2); persona2.setProperty(PersonaAPI.TAGS_FIELD, "persona"); persona2.setProperty(PersonaAPI.DESCRIPTION_FIELD, "test to delete"); persona2 = contentletAPI.checkin(persona2, sysuser, false); contentletAPI.publish(persona2, sysuser, false); Persona personaB = new Persona(persona2); boolean isPersonaBIndexed = contentletAPI.isInodeIndexed(persona2.getInode(), 500); Assert.assertTrue(isPersonaBIndexed); Assert.assertTrue("PersonaA was not created succesfully", UtilMethods.isSet(personaAPI.find(personaA.getIdentifier(), sysuser, false))); Assert.assertTrue("PersonaB was not created succesfully", UtilMethods.isSet(personaAPI.find(personaB.getIdentifier(), sysuser, false))); /* * Test 1: * Create a test page to see if the personas object * in the $visitor variable change */ Folder ftest = folderAPI.createFolders("/personafoldertest" + System.currentTimeMillis(), host, sysuser, false); //adding page String pageStr = "persona-test-page" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); List<Template> templates = templateAPI.findTemplatesAssignedTo(host); Template template = null; for (Template temp : templates) { if (temp.getTitle().equals("Blank")) { template = temp; break; } } Contentlet contentAsset = new Contentlet(); contentAsset.setStructureInode(HTMLPageAssetAPIImpl.DEFAULT_HTMLPAGE_ASSET_STRUCTURE_INODE); contentAsset.setHost(host.getIdentifier()); contentAsset.setProperty(HTMLPageAssetAPIImpl.FRIENDLY_NAME_FIELD, pageStr); contentAsset.setProperty(HTMLPageAssetAPIImpl.URL_FIELD, pageStr); contentAsset.setProperty(HTMLPageAssetAPIImpl.TITLE_FIELD, pageStr); contentAsset.setProperty(HTMLPageAssetAPIImpl.CACHE_TTL_FIELD, "0"); contentAsset.setProperty(HTMLPageAssetAPIImpl.TEMPLATE_FIELD, template.getIdentifier()); contentAsset.setLanguageId(languageAPI.getDefaultLanguage().getId()); contentAsset.setFolder(ftest.getInode()); contentAsset = contentletAPI.checkin(contentAsset, sysuser, false); contentletAPI.publish(contentAsset, sysuser, false); /*Adding simple widget to show the current persona keytag*/ String title = "personawidget" + UtilMethods.dateToHTMLDate(new Date(), "MMddyyyyHHmmss"); String body = "<p>#if(\"$visitor.persona.keyTag\" == \"" + personaA.getKeyTag() + "\")<h1>showing " + personaA.getKeyTag() + "</h1> #elseif(\"$visitor.persona.keyTag\" == \"" + personaB.getKeyTag() + "\") <h1>showing " + personaB.getKeyTag() + "</h1> #else showing default persona #end</p>"; Contentlet contentAsset2 = new Contentlet(); Structure contentst = StructureFactory.getStructureByVelocityVarName("webPageContent"); Structure widgetst = StructureFactory.getStructureByVelocityVarName("SimpleWidget"); contentAsset2.setStructureInode(widgetst.getInode()); contentAsset2.setHost(host.getIdentifier()); contentAsset2.setProperty("widgetTitle", title); contentAsset2.setLanguageId(languageAPI.getDefaultLanguage().getId()); contentAsset2.setProperty("code", body); contentAsset2.setFolder(ftest.getInode()); contentAsset2 = contentletAPI.checkin(contentAsset2, sysuser, false); contentletAPI.publish(contentAsset2, sysuser, false); Container container = null; List<Container> containers = containerAPI.findContainersForStructure(contentst.getInode()); for (Container c : containers) { if (c.getTitle().equals("Blank Container")) { container = c; break; } } /*Relate widget to page*/ MultiTree m = new MultiTree(contentAsset.getIdentifier(), container.getIdentifier(), contentAsset2.getIdentifier()); MultiTreeFactory.saveMultiTree(m); //Call page to see if the persona functionality is working CookieHandler.setDefault(new CookieManager()); URL testUrl = new URL(baseUrl + "/c/portal_public/login?my_account_cmd=auth&my_account_login=admin@dotcms.com&password=admin&my_account_r_m=true"); IOUtils.toString(testUrl.openStream(), "UTF-8"); String urlpersonaA = baseUrl + ftest.getPath() + pageStr + "?mainFrame=true&livePage=0com.dotmarketing.htmlpage.language=1&host_id=" + host.getIdentifier() + "&com.dotmarketing.persona.id=" + personaA.getIdentifier() + "&previewPage=2"; testUrl = new URL(urlpersonaA); StringBuilder result = new StringBuilder(); InputStreamReader isr = new InputStreamReader(testUrl.openStream()); BufferedReader br = new BufferedReader(isr); int byteRead; while ((byteRead = br.read()) != -1) { result.append((char) byteRead); } br.close(); Assert.assertTrue("Error the page is not showing the Persona expected", result.toString().contains("showing " + personaA.getKeyTag())); String urlpersonaB = baseUrl + ftest.getPath() + pageStr + "?mainFrame=true&livePage=0com.dotmarketing.htmlpage.language=1&host_id=" + host.getIdentifier() + "&com.dotmarketing.persona.id=" + personaB.getIdentifier() + "&previewPage=2"; testUrl = new URL(urlpersonaB); result = new StringBuilder(); isr = new InputStreamReader(testUrl.openStream()); br = new BufferedReader(isr); while ((byteRead = br.read()) != -1) { result.append((char) byteRead); } br.close(); Assert.assertTrue("Error the page is not showing the Persona expected", result.toString().contains("showing " + personaB.getKeyTag())); //remove personas, content, page and folder created for this test contentletAPI.unpublish(persona, sysuser, false); contentletAPI.unpublish(persona2, sysuser, false); contentletAPI.unpublish(contentAsset2, sysuser, false); contentletAPI.unpublish(contentAsset, sysuser, false); contentletAPI.archive(persona, sysuser, false); contentletAPI.archive(persona2, sysuser, false); contentletAPI.archive(contentAsset2, sysuser, false); contentletAPI.archive(contentAsset, sysuser, false); contentletAPI.delete(persona, sysuser, false); contentletAPI.delete(persona2, sysuser, false); contentletAPI.delete(contentAsset2, sysuser, false); contentletAPI.delete(contentAsset, sysuser, false); folderAPI.delete(ftest, sysuser, false); }
From source file:com.windigo.http.client.ApacheHttpClient.java
/** * Handle cookies with cookie-handler/* w w w . j a v a 2s. c o m*/ * */ private void setupCookieManager() { CookieManager cookieManager = new CookieManager(); CookieHandler.setDefault(cookieManager); Logger.log("[Request] Setting cookie manager"); }
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; }//w w w . j ava2 s .c o m }
From source file:edgeserver.Descoberta.java
private void publicaGateway(Gateway gateway) throws Exception { // make sure cookies is turn on 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_nome", gateway.getNome())); GatewayParams.add(new BasicNameValuePair("gateway_servidorborda", Integer.toString(this.ServidorBordaID))); GatewayParams.add(new BasicNameValuePair("gateway_uid", (String) gateway.getUid())); String result = http.GetPageContent(this.insertGatewayURI, GatewayParams); //System.out.println(result); String publicType = result.split(":")[0]; String gatewayID = result.split(":")[1]; gateway.setId(Integer.parseInt(gatewayID)); if (null != publicType) switch (publicType) { case "insert": System.out.println("-> Gateway " + gateway.getNome() + "(" + gateway.getId() + ") cadastrado no Servidor de Contexto com sucesso."); break; case "update": System.out.println("-> Gateway " + gateway.getNome() + "(" + gateway.getId() + ") atualizado no Servidor de Contexto com sucesso."); toggleGateway(gateway, "activate"); break; }// w ww. j av a2s .c o m }
From source file:test.be.fedict.eid.applet.ControllerTest.java
@Test public void controllerIdentification() throws Exception { // setup/*from ww w . j av a 2 s.c om*/ 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); // operate controller.run(); // verify LOG.debug("verify..."); SessionHandler sessionHandler = this.servletTester.getContext().getSessionHandler(); SessionManager sessionManager = sessionHandler.getSessionManager(); LOG.debug("session manager type: " + sessionManager.getClass().getName()); HashSessionManager hashSessionManager = (HashSessionManager) sessionManager; LOG.debug("# sessions: " + hashSessionManager.getSessions()); assertEquals(1, hashSessionManager.getSessions()); Map<String, HttpSession> sessionMap = hashSessionManager.getSessionMap(); LOG.debug("session map: " + sessionMap); Entry<String, HttpSession> sessionEntry = sessionMap.entrySet().iterator().next(); HttpSession httpSession = sessionEntry.getValue(); assertNotNull(httpSession.getAttribute("eid")); Identity identity = (Identity) httpSession.getAttribute("eid.identity"); assertNotNull(identity); assertNotNull(identity.name); LOG.debug("name: " + identity.name); LOG.debug("document type: " + identity.getDocumentType()); LOG.debug("duplicate: " + identity.getDuplicate()); assertNull(httpSession.getAttribute("eid.identifier")); assertNull(httpSession.getAttribute("eid.address")); assertNull(httpSession.getAttribute("eid.photo")); }
From source file:edgeserver.Descoberta.java
private void publicaSensor(Gateway gateway, Sensor sensor) throws Exception { // make sure cookies is turn on 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> SensorParams = new ArrayList<>(); SensorParams.add(new BasicNameValuePair("sensor_nome", sensor.getNome())); SensorParams.add(new BasicNameValuePair("sensor_desc", sensor.getDescricao())); SensorParams.add(new BasicNameValuePair("sensor_modelo", sensor.getModelo())); SensorParams.add(new BasicNameValuePair("sensor_precisao", sensor.getPrecisao())); SensorParams.add(new BasicNameValuePair("sensor_tipo", sensor.getTipo())); SensorParams.add(new BasicNameValuePair("sensor_servidorborda", Integer.toString(this.ServidorBordaID))); SensorParams.add(new BasicNameValuePair("sensor_gateway", Integer.toString(gateway.getId()))); String result = http.GetPageContent(this.insertSensorURI, SensorParams); //System.out.println(result); String publicType = result.split(":")[0]; String sensorID = result.split(":")[1]; sensor.setId(Integer.parseInt(sensorID)); if (null != publicType) switch (publicType) { case "insert": System.out.println("-> Sensor " + sensor.getNome() + "(" + sensor.getId() + ") cadastrado no Servidor de Contexto com sucesso."); break; case "update": System.out.println("-> Sensor " + sensor.getNome() + "(" + sensor.getId() + ") atualizado no Servidor de Contexto com sucesso."); break; }// w w w . j av a 2s .co m }
From source file:org.opendatakit.aggregate.odktables.api.perf.AggregateSynchronizer.java
public AggregateSynchronizer(String ctxt, String appName, String odkApiVersion, String aggregateUri, String accessToken) throws InvalidAuthTokenException { this.context = ctxt; this.appName = appName; this.odkClientApiVersion = odkApiVersion; this.aggregateUri = aggregateUri; logger.debug("AggregateUri:" + aggregateUri); this.baseUri = normalizeUri(aggregateUri, "/"); logger.error("baseUri:" + baseUri); // This is technically not correct, as we should really have a global // that we manage for this... If there are two or more service threads // running, we could forget other session cookies. But, by creating a // new cookie manager here, we ensure that we don't have any stale // session cookies at the start of each sync. cm = new CookieManager(); CookieHandler.setDefault(cm); // now everything should work... ClientConfig cc;/*from ww w . ja v a 2 s . co m*/ cc = new ClientConfig(); cc.setLoadWinkApplications(false); cc.applications(new ODKClientApplication()); cc.handlers(new GzipHandler(), new ReAuthSecurityHandler(this)); cc.connectTimeout(CONNECTION_TIMEOUT); cc.readTimeout(2 * CONNECTION_TIMEOUT); cc.followRedirects(true); this.rt = new RestClient(cc); cc = new ClientConfig(); cc.setLoadWinkApplications(false); cc.applications(new ODKClientApplication()); cc.connectTimeout(CONNECTION_TIMEOUT); cc.readTimeout(2 * CONNECTION_TIMEOUT); cc.followRedirects(true); this.tokenRt = new RestClient(cc); this.resources = new HashMap<String, TableResource>(); checkAccessToken(accessToken); this.accessToken = accessToken; }
From source file:org.opendatakit.sync.aggregate.AggregateSynchronizer.java
public AggregateSynchronizer(Context context, String appName, String odkApiVersion, String aggregateUri, String accessToken) throws InvalidAuthTokenException { this.context = context; this.appName = appName; this.log = WebLogger.getLogger(appName); this.odkClientApiVersion = odkApiVersion; this.aggregateUri = aggregateUri; log.e(LOGTAG, "AggregateUri:" + aggregateUri); this.baseUri = normalizeUri(aggregateUri, "/"); log.e(LOGTAG, "baseUri:" + baseUri); // This is technically not correct, as we should really have a global // that we manage for this... If there are two or more service threads // running, we could forget other session cookies. But, by creating a // new cookie manager here, we ensure that we don't have any stale // session cookies at the start of each sync. cm = new CookieManager(); CookieHandler.setDefault(cm); // now everything should work... ClientConfig cc;/* w w w .ja va2s. c om*/ cc = new ClientConfig(); cc.setLoadWinkApplications(false); cc.applications(new ODKClientApplication()); cc.handlers(new GzipHandler(), new ReAuthSecurityHandler(this)); cc.connectTimeout(WebUtils.CONNECTION_TIMEOUT); cc.readTimeout(2 * WebUtils.CONNECTION_TIMEOUT); cc.followRedirects(true); this.rt = new RestClient(cc); cc = new ClientConfig(); cc.setLoadWinkApplications(false); cc.applications(new ODKClientApplication()); cc.connectTimeout(WebUtils.CONNECTION_TIMEOUT); cc.readTimeout(2 * WebUtils.CONNECTION_TIMEOUT); cc.followRedirects(true); this.tokenRt = new RestClient(cc); this.resources = new HashMap<String, TableResource>(); checkAccessToken(accessToken); this.accessToken = accessToken; }