Code example for CookieManager

Methods: put

0
    } 
 
    void populateCookieStore(URI uri)
            throws IOException { 
 
        CookieManager cm = new CookieManager(null, CookiePolicy.ACCEPT_ALL);
        CookieHandler.setDefault(cm);
        Map<String,List<String>> header = new HashMap<>();
        List<String> values = new ArrayList<>();
        values.add("JSESSIONID=" + SESSION_ID + "; version=1; Path="
                   + URI_PATH +"; HttpOnly");
        values.add("CUSTOMER=WILE_E_COYOTE; version=1; Path=" + URI_PATH);
        header.put("Set-Cookie", values);
        cm.put(uri, header);
    } 
 
    void doClient(URI uri) throws Exception {
        HttpURLConnection uc = (HttpURLConnection) uri.toURL().openConnection();
        int resp = uc.getResponseCode();
        check(resp == 200,
              "Unexpected response code. Expected 200, got " + resp);