Example usage for org.apache.commons.httpclient Cookie getSecure

List of usage examples for org.apache.commons.httpclient Cookie getSecure

Introduction

In this page you can find the example usage for org.apache.commons.httpclient Cookie getSecure.

Prototype

public boolean getSecure() 

Source Link

Usage

From source file:com.twinsoft.convertigo.engine.util.CookiesUtils.java

public static String formatCookie(Cookie cookie) {
    StringBuffer buf = new StringBuffer();
    Date d = cookie.getExpiryDate();
    String[][] datas = {/*ww w . j  a  va  2 s .c  o m*/
            // {"$Version",Integer.toString(cookie.getVersion())},
            { cookie.getName(), cookie.getValue() }, { "$Domain", cookie.getDomain() },
            { "$Path", cookie.getPath() }, { "$Secure", Boolean.toString(cookie.getSecure()) },
            { "$Date", d == null ? "null" : DateFormat.getDateTimeInstance().format(d) } };
    buf.append(datas[0][0] + "=" + datas[0][1]);
    for (int i = 1; i < datas.length; i++) {
        if (datas[i][1] != null)
            buf.append("; " + datas[i][0] + "=" + datas[i][1]);
    }
    return buf.toString();
}

From source file:flex.messaging.services.http.proxy.RequestFilter.java

/**
 * Before calling the endpoint, set up the cookies found in the request.
 * @param context the context//from  w  ww.  j  a va2  s .  c  o m
 */
public static void copyCookiesToEndpoint(ProxyContext context) {
    HttpServletRequest clientRequest = FlexContext.getHttpRequest();
    context.clearRequestCookies();
    if (clientRequest != null) {
        javax.servlet.http.Cookie[] cookies = clientRequest.getCookies();
        HttpState initState = context.getHttpClient().getState();

        if (cookies != null) {
            // Gather up the cookies keyed on the length of the path.
            // This is done so that if we have two cookies with the same name,
            // we pass the cookie with the longest path first to the endpoint
            TreeMap cookieMap = new TreeMap();
            for (javax.servlet.http.Cookie cookie : cookies) {
                CookieInfo origCookie = new CookieInfo(cookie.getName(), cookie.getDomain(), cookie.getName(),
                        cookie.getValue(), cookie.getPath(), cookie.getMaxAge(), null, cookie.getSecure());
                CookieInfo newCookie = RequestUtil.createCookie(origCookie, context,
                        context.getTarget().getUrl().getHost(), context.getTarget().getUrl().getPath());

                if (newCookie != null) {
                    Integer pathInt = Integer.valueOf(0 - newCookie.path.length());
                    ArrayList list = (ArrayList) cookieMap.get(pathInt);
                    if (list == null) {
                        list = new ArrayList();
                        cookieMap.put(pathInt, list);
                    }
                    list.add(newCookie);
                }
            }

            // loop through (in order) the cookies we've gathered
            for (Object mapValue : cookieMap.values()) {
                ArrayList list = (ArrayList) mapValue;
                for (Object aList : list) {
                    CookieInfo cookieInfo = (CookieInfo) aList;
                    if (Log.isInfo()) {
                        String str = "-- Cookie in request: " + cookieInfo;
                        Log.getLogger(HTTPProxyService.LOG_CATEGORY).debug(str);
                    }

                    Cookie cookie = new Cookie(cookieInfo.domain, cookieInfo.name, cookieInfo.value,
                            cookieInfo.path, cookieInfo.maxAge, cookieInfo.secure);

                    // If this is a session cookie and we're dealing with local domain, make sure the session
                    // cookie has the latest session id. This check is needed when the session was invalidated
                    // and then recreated in this request; we shouldn't be sending the old session id to the endpoint.
                    if (context.isLocalDomain() && STRING_JSESSIONID.equalsIgnoreCase(cookieInfo.clientName)) {
                        FlexSession flexSession = FlexContext.getFlexSession();
                        if (flexSession != null && flexSession.isValid()) {
                            String sessionId = flexSession.getId();
                            String cookieValue = cookie.getValue();
                            if (!cookieValue.contains(sessionId)) {
                                int colonIndex = cookieValue.indexOf(':');
                                if (colonIndex != -1) {
                                    // Websphere changes jsession id to the following format:
                                    // 4 digit cacheId + jsessionId + ":" + cloneId.
                                    ServletContext servletContext = FlexContext.getServletContext();
                                    String serverInfo = servletContext != null ? servletContext.getServerInfo()
                                            : null;
                                    boolean isWebSphere = serverInfo != null
                                            && serverInfo.contains("WebSphere");
                                    if (isWebSphere) {
                                        String cacheId = cookieValue.substring(0, 4);
                                        String cloneId = cookieValue.substring(colonIndex);
                                        String wsSessionId = cacheId + sessionId + cloneId;
                                        cookie.setValue(wsSessionId);
                                    } else {
                                        cookie.setValue(sessionId);
                                    }
                                } else {
                                    cookie.setValue(sessionId);
                                }
                            }
                        }
                    }
                    // finally add the cookie to the current request
                    initState.addCookie(cookie);
                    context.addRequestCookie(cookie);
                }
            }
        }
    }
}

From source file:com.google.gsa.valve.modules.utils.CookieManagement.java

/**
 * Transforms Apache cookies into Servlet Cookies
 * //  w w w. j ava2 s  . c  om
 * @param apacheCookie apache cookie 
 * 
 * @return servlet cookie
 */
public static javax.servlet.http.Cookie transformApacheCookie(
        org.apache.commons.httpclient.Cookie apacheCookie) {

    javax.servlet.http.Cookie newCookie = null;

    if (apacheCookie != null) {
        Date expire = apacheCookie.getExpiryDate();
        int maxAge = -1;

        if (expire == null) {
            maxAge = -1;
        } else {
            Date now = Calendar.getInstance().getTime();
            // Convert milli-second to second
            Long second = new Long((expire.getTime() - now.getTime()) / 1000);
            maxAge = second.intValue();
        }

        newCookie = new javax.servlet.http.Cookie(apacheCookie.getName(), apacheCookie.getValue());
        //Hardcoding the domain
        newCookie.setDomain(apacheCookie.getDomain());
        newCookie.setPath(apacheCookie.getPath());
        newCookie.setMaxAge(maxAge);
        newCookie.setSecure(apacheCookie.getSecure());
    }
    return newCookie;
}

From source file:at.ait.dme.yuma.suite.apps.core.server.annotation.AnnotationManager.java

private RESTAnnotationServer getAnnotationServer() {
    HttpClient client = new HttpClient();

    // Forward all cookies from the calling request
    if (request != null) {

        javax.servlet.http.Cookie[] cookies = request.getCookies();

        if (cookies != null) {
            for (javax.servlet.http.Cookie c : cookies) {
                c.setDomain(request.getServerName());
                c.setPath("/");

                Cookie apacheCookie = new Cookie(c.getDomain(), c.getName(), c.getValue(), c.getPath(),
                        c.getMaxAge(), c.getSecure());
                client.getState().addCookie(apacheCookie);
            }/*from  w  w  w .j  a  va 2s. c om*/
            client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);
        }
    }

    return ProxyFactory.create(RESTAnnotationServer.class, annotationServerBaseUrl,
            new ApacheHttpClientExecutor(client));
}

From source file:com.celamanzi.liferay.portlets.rails286.OnlineClient.java

protected void debugCookies(Cookie[] cookies) {
    log.debug("Cookie inspector found " + cookies.length + " cookies ------v");
    for (Cookie cookie : cookies)
        log.debug(cookie.toString() + ", domain=" + cookie.getDomain() + ", path=" + cookie.getPath()
                + ", max-age=" + cookie.getExpiryDate() + ", secure=" + cookie.getSecure());
    log.debug("----------------------------");
}

From source file:at.ait.dme.yuma.server.annotation.ImageAnnotationManager.java

private EuropeanaAnnotationService getAnnotationService(MultivaluedMap<String, String> headers) {

    List<String> cookieHeaders = (headers != null) ? headers.get("Set-Cookie") : new ArrayList<String>();

    HttpClient client = new HttpClient();
    // make sure to forward all cookies             
    javax.servlet.http.Cookie[] cookies = clientRequest.getCookies();
    for (javax.servlet.http.Cookie c : cookies) {
        c.setDomain(clientRequest.getServerName());
        c.setPath("/");

        String value = c.getValue();
        for (String cookieHeader : cookieHeaders) {
            if (cookieHeader.startsWith(c.getName())) {
                String cookieHeaderParts[] = cookieHeader.split("=");
                if (cookieHeaderParts.length >= 2)
                    value = cookieHeaderParts[1];
            }//from  w  w w .  j  a v a  2 s  .c o m
        }
        Cookie apacheCookie = new Cookie(c.getDomain(), c.getName(), value, c.getPath(), c.getMaxAge(),
                c.getSecure());
        client.getState().addCookie(apacheCookie);
    }
    client.getParams().setCookiePolicy(CookiePolicy.BROWSER_COMPATIBILITY);

    return ProxyFactory.create(EuropeanaAnnotationService.class, annotationServiceBaseUrl,
            new ApacheHttpClientExecutor(client));
}

From source file:com.owncloud.android.lib.common.OwnCloudClient.java

@SuppressWarnings("unused")
private void logCookie(Cookie cookie) {
    Log_OC.d(TAG, "Cookie name: " + cookie.getName());
    Log_OC.d(TAG, "       value: " + cookie.getValue());
    Log_OC.d(TAG, "       domain: " + cookie.getDomain());
    Log_OC.d(TAG, "       path: " + cookie.getPath());
    Log_OC.d(TAG, "       version: " + cookie.getVersion());
    Log_OC.d(TAG, "       expiryDate: "
            + (cookie.getExpiryDate() != null ? cookie.getExpiryDate().toString() : "--"));
    Log_OC.d(TAG, "       comment: " + cookie.getComment());
    Log_OC.d(TAG, "       secure: " + cookie.getSecure());
}

From source file:com.cerema.cloud2.lib.common.OwnCloudClient.java

private void logCookie(Cookie cookie) {
    Log_OC.d(TAG, "Cookie name: " + cookie.getName());
    Log_OC.d(TAG, "       value: " + cookie.getValue());
    Log_OC.d(TAG, "       domain: " + cookie.getDomain());
    Log_OC.d(TAG, "       path: " + cookie.getPath());
    Log_OC.d(TAG, "       version: " + cookie.getVersion());
    Log_OC.d(TAG, "       expiryDate: "
            + (cookie.getExpiryDate() != null ? cookie.getExpiryDate().toString() : "--"));
    Log_OC.d(TAG, "       comment: " + cookie.getComment());
    Log_OC.d(TAG, "       secure: " + cookie.getSecure());
}

From source file:com.twinsoft.convertigo.engine.Context.java

public Vector<String> getCookieStrings() {
    // Use the HandleCookie Property of the transaction to return or not the cookies.
    ////from www .  j  a v  a2  s .  c o  m
    // We noticed a Bug in tomcat when too much cookies where set in the response to the client. This causes a 
    // IndexOutOfBoundException:  4096 in coyote.
    // To overcome this situation, now you can configure HandleCookies to false in the transaction to prevent cookies to be reflected
    // to the client.
    if (requestedObject instanceof AbstractHttpTransaction) {
        if (!((AbstractHttpTransaction) requestedObject).isHandleCookie())
            return new Vector<String>();
    }

    Vector<String> cookies = new Vector<String>();
    if (httpState != null) {
        Cookie[] httpCookies = httpState.getCookies();
        int len = httpCookies.length;
        Cookie cookie = null;
        String sCookie;

        DateFormat df = new SimpleDateFormat("EEE, dd-MMM-yyyy HH:mm:ss z", Locale.US);
        df.setTimeZone(TimeZone.getTimeZone("GMT"));
        for (int i = 0; i < len; i++) {
            cookie = httpCookies[i];
            sCookie = cookie.getName() + "=" + cookie.getValue() + ";";
            sCookie += (cookie.getExpiryDate() != null) ? "expires=" + df.format(cookie.getExpiryDate()) + ";"
                    : "";
            sCookie += "path=" + cookie.getPath() + ";";
            sCookie += "domain=" + cookie.getDomain() + ";";
            sCookie += cookie.getSecure() ? "secure" : "";
            cookies.add(sCookie);
        }
    }
    return cookies;
}

From source file:com.cyberway.issue.crawler.fetcher.FetchHTTP.java

/**
 * Saves cookies to a file.//from ww  w .jav  a2 s  .  c o m
 *
 * Output file is in the Netscape 'cookies.txt' format.
 *
 * @param saveCookiesFile output file.
 */
public void saveCookies(String saveCookiesFile) {
    // Do nothing if cookiesFile is not specified.
    if (saveCookiesFile == null || saveCookiesFile.length() <= 0) {
        return;
    }

    FileOutputStream out = null;
    try {
        out = new FileOutputStream(new File(saveCookiesFile));
        @SuppressWarnings("unchecked")
        Map<String, Cookie> cookies = http.getState().getCookiesMap();
        String tab = "\t";
        out.write("# Heritrix Cookie File\n".getBytes());
        out.write("# This file is the Netscape cookies.txt format\n\n".getBytes());
        for (Cookie cookie : cookies.values()) {
            MutableString line = new MutableString(1024 * 2 /*Guess an initial size*/);
            line.append(cookie.getDomain());
            line.append(tab);
            line.append(cookie.isDomainAttributeSpecified() == true ? "TRUE" : "FALSE");
            line.append(tab);
            line.append(cookie.getPath());
            line.append(tab);
            line.append(cookie.getSecure() == true ? "TRUE" : "FALSE");
            line.append(tab);
            line.append(cookie.getName());
            line.append(tab);
            line.append((null == cookie.getValue()) ? "" : cookie.getValue());
            line.append("\n");
            out.write(line.toString().getBytes());
        }
    } catch (FileNotFoundException e) {
        // We should probably throw FatalConfigurationException.
        System.out.println("Could not find file: " + saveCookiesFile + " (Element: " + ATTR_SAVE_COOKIES + ")");
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        try {
            if (out != null) {
                out.close();
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}