settings.setDataString(dataString); | settings.setDataString(dataString); | ||||
settings.setContentType(contentType); | settings.setContentType(contentType); | ||||
} | } | ||||
System.out.println(settings.getDataString()); | |||||
if ("GET".equals(settings.getType()) && settings.getDataString() != null) { | if ("GET".equals(settings.getType()) && settings.getDataString() != null) { | ||||
url += (url.contains("?") ? "&" : "?") + settings.getDataString(); | url += (url.contains("?") ? "&" : "?") + settings.getDataString(); |
public class AjaxTransportJre implements AjaxTransport { | public class AjaxTransportJre implements AjaxTransport { | ||||
private static String localDomain = null; | private static String localDomain = null; | ||||
private static CookieManager cookieManager = CookieManager.getInstance(); | private static CookieManager cookieManager = CookieManager.getInstance(); | ||||
public static void enableCORS(String domain) { | public static void enableCORS(String domain) { | ||||
if (s.getUsername() != null && s.getPassword() != null) { | if (s.getUsername() != null && s.getPassword() != null) { | ||||
c.setRequestProperty ("Authorization", "Basic " + Base64Utils.toBase64((s.getUsername() + ":" + s.getPassword()).getBytes())); | c.setRequestProperty ("Authorization", "Basic " + Base64Utils.toBase64((s.getUsername() + ":" + s.getPassword()).getBytes())); | ||||
} | } | ||||
System.err.println("SET COOK"); | |||||
cookieManager.setCookies(c); | cookieManager.setCookies(c); | ||||
boolean isCORS = cors && localDomain != null && !s.getUrl().contains(localDomain); | boolean isCORS = cors && localDomain != null && !s.getUrl().contains(localDomain); | ||||
if (isCORS && !localDomain.equals(c.getHeaderField("Access-Control-Allow-Origin"))) { | if (isCORS && !localDomain.equals(c.getHeaderField("Access-Control-Allow-Origin"))) { | ||||
code = 0; | code = 0; | ||||
} | } | ||||
System.err.println(c.getResponseCode()); | |||||
BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream())); | BufferedReader in = new BufferedReader(new InputStreamReader(c.getInputStream())); | ||||
String inputLine; | String inputLine; | ||||
in.close(); | in.close(); | ||||
cookieManager.storeCookies(c); | cookieManager.storeCookies(c); | ||||
return new ResponseJre(code, c.getResponseMessage(), response.toString(), c.getHeaderFields()); | return new ResponseJre(code, c.getResponseMessage(), response.toString(), c.getHeaderFields()); | ||||
} | } | ||||
} | } |
import java.io.IOException; | import java.io.IOException; | ||||
import java.net.URL; | import java.net.URL; | ||||
import java.net.URLConnection; | import java.net.URLConnection; | ||||
import java.net.URLEncoder; | |||||
import java.text.DateFormat; | import java.text.DateFormat; | ||||
import java.text.SimpleDateFormat; | import java.text.SimpleDateFormat; | ||||
import java.util.Date; | import java.util.Date; | ||||
return cookieManager; | return cookieManager; | ||||
} | } | ||||
public void clear() { | |||||
store.clear(); | |||||
} | |||||
public void removeDomainCookies(String domain) { | public void removeDomainCookies(String domain) { | ||||
store.remove(domain); | store.remove(domain); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
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); | String domain = getDomainFromHost(host); | ||||
Map<String, Map<String, String>> domainStore = store.get(domain); | Map<String, Map<String, String>> domainStore = store.get(domain); | ||||
if (domainStore == null) { | if (domainStore == null) { | ||||
} | } | ||||
try { | try { | ||||
conn.setRequestProperty(COOKIE, cookieStringBuffer.toString()); | conn.setRequestProperty(COOKIE, cookieStringBuffer.toString()); | ||||
System.err.println(">>> SET cookie: " + COOKIE + " " + cookieStringBuffer.toString()); | |||||
} catch (java.lang.IllegalStateException ise) { | } catch (java.lang.IllegalStateException ise) { | ||||
IOException ioe = | IOException ioe = | ||||
new IOException( | new IOException( | ||||
} | } | ||||
private String getDomainFromHost(String host) { | private String getDomainFromHost(String host) { | ||||
host = host.toLowerCase().replaceFirst("https?://", "").replaceAll("[/?:].*$", ""); | |||||
if (host.indexOf(DOT) != host.lastIndexOf(DOT)) { | if (host.indexOf(DOT) != host.lastIndexOf(DOT)) { | ||||
return host.substring(host.indexOf(DOT) + 1); | return host.substring(host.indexOf(DOT) + 1); | ||||
} else { | } else { |