Search in sources :

Example 1 with CookieStore

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);
        }
    }
}
Also used : CookieStore(java.net.CookieStore) HttpCookie(java.net.HttpCookie) NewCookie(javax.ws.rs.core.NewCookie)

Example 2 with CookieStore

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);
}
Also used : CookieStore(java.net.CookieStore) ContentProvider(org.eclipse.jetty.client.api.ContentProvider) HttpFields(org.eclipse.jetty.http.HttpFields) HttpVersion(org.eclipse.jetty.http.HttpVersion) URI(java.net.URI)

Example 3 with CookieStore

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);
                }
            }
        }
    }
}
Also used : CookieStore(java.net.CookieStore) HttpCookie(java.net.HttpCookie)

Example 4 with CookieStore

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();
    }
}
Also used : CookieStore(java.net.CookieStore)

Example 5 with CookieStore

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;
}
Also used : CookieStore(java.net.CookieStore)

Aggregations

CookieStore (java.net.CookieStore)37 HttpCookie (java.net.HttpCookie)33 CookieManager (java.net.CookieManager)28 URI (java.net.URI)26 RefTag (com.kickstarter.libs.RefTag)2 Project (com.kickstarter.models.Project)2 ArrayList (java.util.ArrayList)2 Test (org.junit.Test)2 Nullable (android.support.annotation.Nullable)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 InputStream (java.io.InputStream)1 Serializable (java.io.Serializable)1 URISyntaxException (java.net.URISyntaxException)1 Map (java.util.Map)1 NewCookie (javax.ws.rs.core.NewCookie)1 Message (org.apache.camel.Message)1 RuntimeCamelException (org.apache.camel.RuntimeCamelException)1 HeaderFilterStrategy (org.apache.camel.spi.HeaderFilterStrategy)1 ContentProvider (org.eclipse.jetty.client.api.ContentProvider)1 HttpFields (org.eclipse.jetty.http.HttpFields)1