From 8d34610fa2bfbd02ab623f73f5f30b2189bb04be Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Tue, 21 Jan 2014 13:09:16 +0100 Subject: [PATCH] support for urls when setting cookies --- .../google/gwt/query/client/plugins/ajax/Ajax.java | 2 -- .../com/google/gwt/query/vm/AjaxTransportJre.java | 5 +---- .../java/com/google/gwt/query/vm/CookieManager.java | 13 ++++++++++--- 3 files changed, 11 insertions(+), 9 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java index f516fc6a..5857de9b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java @@ -212,8 +212,6 @@ public class Ajax extends GQuery { settings.setDataString(dataString); settings.setContentType(contentType); } - - System.out.println(settings.getDataString()); if ("GET".equals(settings.getType()) && settings.getDataString() != null) { url += (url.contains("?") ? "&" : "?") + settings.getDataString(); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java b/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java index 91df6353..f1a73f9a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/vm/AjaxTransportJre.java @@ -26,6 +26,7 @@ import com.google.gwt.user.server.Base64Utils; public class AjaxTransportJre implements AjaxTransport { private static String localDomain = null; + private static CookieManager cookieManager = CookieManager.getInstance(); public static void enableCORS(String domain) { @@ -96,7 +97,6 @@ public class AjaxTransportJre implements AjaxTransport { if (s.getUsername() != null && s.getPassword() != null) { c.setRequestProperty ("Authorization", "Basic " + Base64Utils.toBase64((s.getUsername() + ":" + s.getPassword()).getBytes())); } - System.err.println("SET COOK"); cookieManager.setCookies(c); boolean isCORS = cors && localDomain != null && !s.getUrl().contains(localDomain); @@ -144,7 +144,6 @@ public class AjaxTransportJre implements AjaxTransport { if (isCORS && !localDomain.equals(c.getHeaderField("Access-Control-Allow-Origin"))) { code = 0; } - System.err.println(c.getResponseCode()); BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream())); String inputLine; @@ -155,8 +154,6 @@ public class AjaxTransportJre implements AjaxTransport { in.close(); cookieManager.storeCookies(c); - return new ResponseJre(code, c.getResponseMessage(), response.toString(), c.getHeaderFields()); } - } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/vm/CookieManager.java b/gwtquery-core/src/main/java/com/google/gwt/query/vm/CookieManager.java index e33620b6..1f1241ba 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/vm/CookieManager.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/vm/CookieManager.java @@ -3,7 +3,6 @@ package com.google.gwt.query.vm; import java.io.IOException; import java.net.URL; import java.net.URLConnection; -import java.net.URLEncoder; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; @@ -39,6 +38,10 @@ public class CookieManager { return cookieManager; } + public void clear() { + store.clear(); + } + public void removeDomainCookies(String domain) { store.remove(domain); } @@ -52,7 +55,11 @@ public class CookieManager { } } - public void setDomcainCookieProp(String host, String name, String prop, String value) { + public void setDomcainCookie(String host, String name, String value) { + setDomcainCookieProperty(host, name, name, value); + } + + public void setDomcainCookieProperty(String host, String name, String prop, String value) { String domain = getDomainFromHost(host); Map> domainStore = store.get(domain); if (domainStore == null) { @@ -169,7 +176,6 @@ public class CookieManager { } try { conn.setRequestProperty(COOKIE, cookieStringBuffer.toString()); - System.err.println(">>> SET cookie: " + COOKIE + " " + cookieStringBuffer.toString()); } catch (java.lang.IllegalStateException ise) { IOException ioe = new IOException( @@ -180,6 +186,7 @@ public class CookieManager { } private String getDomainFromHost(String host) { + host = host.toLowerCase().replaceFirst("https?://", "").replaceAll("[/?:].*$", ""); if (host.indexOf(DOT) != host.lastIndexOf(DOT)) { return host.substring(host.indexOf(DOT) + 1); } else { -- 2.39.5