use of java.net.CookieStore in project camel by apache.
the class CxfRsProducer method saveCookies.
private void saveCookies(Exchange exchange, Client client, CookieHandler cookieHandler) {
if (cookieHandler != null) {
CookieStore cookieStore = cookieHandler.getCookieStore(exchange);
for (NewCookie newCookie : client.getResponse().getCookies().values()) {
HttpCookie cookie = new HttpCookie(newCookie.getName(), newCookie.getValue());
cookie.setComment(newCookie.getComment());
cookie.setDomain(newCookie.getDomain());
cookie.setHttpOnly(newCookie.isHttpOnly());
cookie.setMaxAge(newCookie.getMaxAge());
cookie.setPath(newCookie.getPath());
cookie.setSecure(newCookie.isSecure());
cookie.setVersion(newCookie.getVersion());
cookieStore.add(client.getCurrentURI(), cookie);
}
}
}
use of java.net.CookieStore in project jetty.project by eclipse.
the class HttpConnection method normalizeRequest.
protected void normalizeRequest(Request request) {
HttpVersion version = request.getVersion();
HttpFields headers = request.getHeaders();
ContentProvider content = request.getContent();
ProxyConfiguration.Proxy proxy = destination.getProxy();
// Make sure the path is there
String path = request.getPath();
if (path.trim().length() == 0) {
path = "/";
request.path(path);
}
URI uri = request.getURI();
if (proxy instanceof HttpProxy && !HttpClient.isSchemeSecure(request.getScheme()) && uri != null) {
path = uri.toString();
request.path(path);
}
// If we are HTTP 1.1, add the Host header
if (version.getVersion() <= 11) {
if (!headers.containsKey(HttpHeader.HOST.asString()))
headers.put(getHttpDestination().getHostField());
}
// Add content headers
if (content != null) {
if (!headers.containsKey(HttpHeader.CONTENT_TYPE.asString())) {
String contentType = null;
if (content instanceof ContentProvider.Typed)
contentType = ((ContentProvider.Typed) content).getContentType();
if (contentType != null)
headers.put(HttpHeader.CONTENT_TYPE, contentType);
else
headers.put(HttpHeader.CONTENT_TYPE, "application/octet-stream");
}
long contentLength = content.getLength();
if (contentLength >= 0) {
if (!headers.containsKey(HttpHeader.CONTENT_LENGTH.asString()))
headers.put(HttpHeader.CONTENT_LENGTH, String.valueOf(contentLength));
}
}
// Cookies
CookieStore cookieStore = getHttpClient().getCookieStore();
if (cookieStore != null) {
StringBuilder cookies = null;
if (uri != null)
cookies = convertCookies(cookieStore.get(uri), null);
cookies = convertCookies(request.getCookies(), cookies);
if (cookies != null)
request.header(HttpHeader.COOKIE.asString(), cookies.toString());
}
// Authentication
applyAuthentication(request, proxy != null ? proxy.getURI() : null);
applyAuthentication(request, uri);
}
use of java.net.CookieStore in project LuaViewSDK by alibaba.
the class CookieManager method updateNetResponseCookies.
/**
* write net cookies
*
* @param cookiesHeader
*/
private static void updateNetResponseCookies(List<String> cookiesHeader) {
//write net cookie
final CookieStore cookieStore = getCookieManager().getCookieStore();
if (cookieStore != null && cookiesHeader != null) {
HttpCookie cookieStr = null;
for (String cookieHeader : cookiesHeader) {
if (cookieHeader != null) {
List<HttpCookie> cookies = HttpCookie.parse(cookieHeader);
if (cookies != null && cookies.size() > 0) {
cookieStr = cookies.get(0);
LogUtil.d(TAG, "write-net", cookieStr);
cookieStore.add(null, cookieStr);
}
}
}
}
}
use of java.net.CookieStore in project LuaViewSDK by alibaba.
the class CookieManager method clearNetCookies.
/**
* clear net cookies
*/
public static void clearNetCookies() {
java.net.CookieManager cookieManager = getCookieManager();
CookieStore cookieStore = cookieManager.getCookieStore();
if (cookieStore != null) {
cookieStore.removeAll();
}
}
use of java.net.CookieStore in project LuaViewSDK by alibaba.
the class CookieManager method updateWebkitResponseCookies.
/**
* @param cookiesHeader
*/
private static String updateWebkitResponseCookies(List<String> cookiesHeader, String requestUrl) {
//write webkit cookie
final CookieStore cookieStore = getCookieManager().getCookieStore();
if (cookieStore != null && cookiesHeader != null) {
StringBuffer cookie = new StringBuffer();
for (String cookieHeader : cookiesHeader) {
cookie.append(cookieHeader).append(";");
}
android.webkit.CookieManager cookieManager = android.webkit.CookieManager.getInstance();
if (cookieManager != null && cookie.length() > 0) {
String cookieStr = cookie.toString();
LogUtil.d(TAG, "write-webkit", cookieStr);
cookieManager.setCookie(requestUrl, cookieStr);
}
}
return null;
}
Aggregations