setPath ( )源码实例Demo

java.net.HttpCookie#setPath ( )源码实例Demo

下面列出了java.net.HttpCookie#setPath ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: leetcode-editor   文件: CookieUtils.java
public static List<HttpCookie> toHttpCookie(String json) {

        List<HttpCookie> cookieList = new ArrayList<>();

        JSONArray jsonArray = JSONArray.parseArray(json);
        for (int i = 0; i < jsonArray.size(); i++) {
            JSONObject jsonObject = jsonArray.getJSONObject(i);
            HttpCookie clientCookie = new HttpCookie(jsonObject.getString("name"), jsonObject.getString("value"));
            clientCookie.setDomain(jsonObject.getString("domain"));
            clientCookie.setPath(jsonObject.getString("path"));
            clientCookie.setMaxAge(7 * 24 * 60);
            cookieList.add(clientCookie);
        }

        return cookieList;
    }
 
源代码2 项目: Kalle   文件: CookieManager.java
/**
 * Cookie for the specified URI to save, where path and port will be verified.
 *
 * @param uri        uri.
 * @param cookieList all you want to save the Cookie, does not meet the rules will not be saved.
 */
public void add(URI uri, List<String> cookieList) {
    for (String cookieValue : cookieList) {
        List<HttpCookie> cookies = HttpCookie.parse(cookieValue);
        for (HttpCookie cookie : cookies) {
            if (cookie.getPath() == null) {
                String path = normalizePath(uri.getPath());
                cookie.setPath(path);
            } else if (!pathMatches(uri, cookie)) {
                continue;
            }

            if (cookie.getDomain() == null) cookie.setDomain(uri.getHost());

            String portList = cookie.getPortlist();
            int port = getPort(uri);
            if (TextUtils.isEmpty(portList) || containsPort(portList, port)) {
                cookieJar.add(uri, cookie);
            }
        }
    }
}
 
源代码3 项目: httplite   文件: SerializableCookie.java
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    clientCookie = new HttpCookie(name, value);

    clientCookie.setComment((String) in.readObject());
    clientCookie.setCommentURL((String) in.readObject());
    clientCookie.setDomain((String) in.readObject());
    clientCookie.setPath((String) in.readObject());

    clientCookie.setMaxAge(in.readLong());
    clientCookie.setVersion(in.readInt());

    clientCookie.setSecure(in.readBoolean());
    clientCookie.setDiscard(in.readBoolean());
}
 
源代码4 项目: 4pdaClient-plus   文件: SerializableHttpCookie.java
private void readObject(ObjectInputStream in) throws IOException,
        ClassNotFoundException {
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    cookie = new HttpCookie(name, value);
    cookie.setComment((String) in.readObject());
    cookie.setCommentURL((String) in.readObject());
    cookie.setDomain((String) in.readObject());
    cookie.setMaxAge(in.readLong());
    cookie.setPath((String) in.readObject());
    cookie.setPortlist((String) in.readObject());
    cookie.setVersion(in.readInt());
    cookie.setSecure(in.readBoolean());
    cookie.setDiscard(in.readBoolean());
    setHttpOnly(in.readBoolean());
}
 
源代码5 项目: Nimingban   文件: TransportableHttpCookie.java
@Nullable
public HttpCookie to() {
    if (name == null || value == null) {
        return null;
    }

    HttpCookie cookie = new HttpCookie(name, value);
    cookie.setComment(comment);
    cookie.setCommentURL(commentURL);
    cookie.setDiscard(discard);
    cookie.setDomain(domain);
    cookie.setMaxAge(maxAge);
    cookie.setPath(path);
    cookie.setPortlist(portList);
    cookie.setSecure(secure);
    cookie.setVersion(version);

    return cookie;
}
 
源代码6 项目: DaVinci   文件: SerializableHttpCookie.java
private void readObject(ObjectInputStream in) throws IOException,
        ClassNotFoundException {
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    cookie = new HttpCookie(name, value);
    cookie.setComment((String) in.readObject());
    cookie.setCommentURL((String) in.readObject());
    cookie.setDomain((String) in.readObject());
    cookie.setMaxAge(in.readLong());
    cookie.setPath((String) in.readObject());
    cookie.setPortlist((String) in.readObject());
    cookie.setVersion(in.readInt());
    cookie.setSecure(in.readBoolean());
    cookie.setDiscard(in.readBoolean());
    setHttpOnly(in.readBoolean());
}
 
源代码7 项目: redkale   文件: HttpResultCoder.java
public static List<HttpCookie> getCookieList(ByteBuffer buffer) {
    int len = buffer.getChar();
    if (len == 0) return null;
    final List<HttpCookie> list = new ArrayList<>(len);
    for (int i = 0; i < len; i++) {
        HttpCookie cookie = new HttpCookie(getShortString(buffer), getShortString(buffer));
        cookie.setDomain(getShortString(buffer));
        cookie.setPath(getShortString(buffer));
        cookie.setPortlist(getShortString(buffer));
        cookie.setMaxAge(buffer.getLong());
        cookie.setSecure(buffer.get() == 1);
        cookie.setHttpOnly(buffer.get() == 1);
        list.add(cookie);
    }
    return list;
}
 
源代码8 项目: NoHttp   文件: CookieEntity.java
/**
 * Into {@link HttpCookie}.
 *
 * @return {@link HttpCookie}.
 */
public HttpCookie toHttpCookie() {
    HttpCookie cookie = new HttpCookie(name, value);
    cookie.setComment(comment);
    cookie.setCommentURL(commentURL);
    cookie.setDiscard(discard);
    cookie.setDomain(domain);
    if (expiry == -1L)
        cookie.setMaxAge(-1L);
    else
        cookie.setMaxAge((expiry - System.currentTimeMillis()) / 1000L);
    cookie.setPath(path);
    cookie.setPortlist(portList);
    cookie.setSecure(secure);
    cookie.setVersion(version);
    return cookie;
}
 
源代码9 项目: redkale-demo   文件: UserServlet.java
@HttpMapping(url = "/user/qqlogin", auth = false)
public void qqlogin(HttpRequest req, HttpResponse resp) throws IOException {
    String access_token = req.getParameter("access_token");
    String openid = req.getParameter("openid");
    if (finest) logger.finest("/user/qqlogin :  " + openid + "," + access_token);
    LoginQQBean bean = new LoginQQBean();
    bean.setAccesstoken(access_token);
    bean.setApptoken(req.getParameter("apptoken", ""));
    bean.setOpenid(openid);
    bean.setLoginaddr(req.getRemoteAddr());
    bean.setLoginagent(req.getHeader("User-Agent"));
    bean.setSessionid(req.changeSessionid());
    RetResult<UserInfo> rr = service.qqlogin(bean);
    if (rr.isSuccess()) {
        UserInfo info = rr.getResult();
        int age = 1000 * 24 * 60 * 60;
        String key = info.getUser36id() + "$2" + info.getQqopenid() + "?" + age + "-" + System.currentTimeMillis();
        HttpCookie cookie = new HttpCookie(COOKIE_AUTOLOGIN, UserService.encryptAES(key));
        cookie.setHttpOnly(true);
        cookie.setPath("/");
        cookie.setMaxAge(age);
        resp.addCookie(cookie);
    }
    if (access_token == null || access_token.isEmpty()) {
        resp.setHeader("Location", req.getParameter("url", "/"));
        resp.finish(302, null);
    } else { //APP 模式
        resp.finishJson(rr);
    }
}
 
源代码10 项目: NewsMe   文件: SerializableHttpCookie.java
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException
{
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    clientCookie = new HttpCookie(name, value);
    clientCookie.setComment((String) in.readObject());
    clientCookie.setCommentURL((String) in.readObject());
    clientCookie.setDomain((String) in.readObject());
    clientCookie.setMaxAge(in.readLong());
    clientCookie.setPath((String) in.readObject());
    clientCookie.setPortlist((String) in.readObject());
    clientCookie.setVersion(in.readInt());
    clientCookie.setSecure(in.readBoolean());
    clientCookie.setDiscard(in.readBoolean());
}
 
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    clientCookie = new HttpCookie(name, value);
    clientCookie.setComment((String) in.readObject());
    clientCookie.setCommentURL((String) in.readObject());
    clientCookie.setDomain((String) in.readObject());
    clientCookie.setMaxAge(in.readLong());
    clientCookie.setPath((String) in.readObject());
    clientCookie.setPortlist((String) in.readObject());
    clientCookie.setVersion(in.readInt());
    clientCookie.setSecure(in.readBoolean());
    clientCookie.setDiscard(in.readBoolean());
}
 
源代码12 项目: ratebeer   文件: SerializableHttpCookie.java
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
	String name = (String) in.readObject();
	String value = (String) in.readObject();
	cookie = new HttpCookie(name, value);
	cookie.setComment((String) in.readObject());
	cookie.setCommentURL((String) in.readObject());
	cookie.setDomain((String) in.readObject());
	cookie.setMaxAge(in.readLong());
	cookie.setPath((String) in.readObject());
	cookie.setPortlist((String) in.readObject());
	cookie.setVersion(in.readInt());
	cookie.setSecure(in.readBoolean());
	cookie.setDiscard(in.readBoolean());
	setHttpOnly(in.readBoolean());
}
 
源代码13 项目: AndroidStudyDemo   文件: SerializableHttpCookie.java
private void readObject(ObjectInputStream in) throws IOException, ClassNotFoundException {
    String name = (String) in.readObject();
    String value = (String) in.readObject();
    mClientCookie = new HttpCookie(name, value);
    mClientCookie.setComment((String) in.readObject());
    mClientCookie.setCommentURL((String) in.readObject());
    mClientCookie.setDomain((String) in.readObject());
    mClientCookie.setMaxAge(in.readLong());
    mClientCookie.setPath((String) in.readObject());
    mClientCookie.setPortlist((String) in.readObject());
    mClientCookie.setVersion(in.readInt());
    mClientCookie.setSecure(in.readBoolean());
    mClientCookie.setDiscard(in.readBoolean());
}
 
源代码14 项目: Nimingban   文件: CookieDBJar.java
private HttpCookie cookie2HttpCookie(Cookie cookie) {
    HttpCookie httpCookie = new HttpCookie(cookie.name(), cookie.value());
    if (cookie.expiresAt() < System.currentTimeMillis()) {
        httpCookie.setMaxAge(-100L);
    } else {
        httpCookie.setMaxAge((cookie.expiresAt() - System.currentTimeMillis()) / 1000);
    }
    httpCookie.setDomain(cookie.domain());
    httpCookie.setPath(cookie.path());
    httpCookie.setSecure(cookie.secure());
    return httpCookie;
}
 
源代码15 项目: redkale-demo   文件: UserServlet.java
/**
 * 修改密码
 *
 * @param req
 * @param resp
 *
 * @throws IOException
 */
@HttpMapping(url = "/user/updatepwd")
public void updatepwd(HttpRequest req, HttpResponse resp) throws IOException {
    UserPwdBean bean = req.getJsonParameter(UserPwdBean.class, "bean");
    UserInfo curr = req.currentUser();
    if (curr != null) bean.setSessionid(req.getSessionid(false));
    RetResult<UserInfo> result = service.updatePwd(bean);
    if (result.isSuccess() && curr == null) { //找回的密码
        curr = result.getResult();
        LoginBean loginbean = new LoginBean();
        loginbean.setAccount(curr.getEmail().isEmpty() ? curr.getMobile() : curr.getEmail());
        loginbean.setPassword(UserService.secondPasswordMD5(bean.getNewpwd()));
        loginbean.setSessionid(req.changeSessionid());
        loginbean.setLoginagent(req.getHeader("User-Agent"));
        loginbean.setLoginip(req.getRemoteAddr());
        result = service.login(loginbean);
    }
    String autologin = req.getCookie(COOKIE_AUTOLOGIN);
    if (result.isSuccess() && autologin != null) {
        autologin = UserService.decryptAES(autologin);
        if (autologin.contains("$0")) { //表示COOKIE_AUTOLOGIN 为密码类型存储
            String newpwd = UserService.secondPasswordMD5(bean.getNewpwd());
            int wen = autologin.indexOf('?');
            int mei = autologin.indexOf('$');
            String key = autologin.substring(0, mei + 2) + newpwd + autologin.substring(wen);
            HttpCookie cookie = new HttpCookie(COOKIE_AUTOLOGIN, UserService.encryptAES(key));
            cookie.setHttpOnly(true);
            cookie.setPath("/");
            String time = autologin.substring(wen + 1);
            int fen = time.indexOf('-');
            int age = Integer.parseInt(time.substring(0, fen)); //秒数
            long point = Long.parseLong(time.substring(fen + 1)); //毫秒数
            cookie.setMaxAge(age - (System.currentTimeMillis() - point) / 1000);
            resp.addCookie(cookie);
        }
    }
    resp.finishJson(result);
}
 
源代码16 项目: Nimingban   文件: SimpleCookieStore.java
public void fixLostCookiePath() {
    for (URL url : map.keySet()) {
        List<HttpCookieWithId> list = map.get(url);
        for (HttpCookieWithId hcwi : list) {
            HttpCookie cookie = hcwi.httpCookie;
            if (TextUtils.isEmpty(cookie.getPath())) {
                cookie.setPath("/");
                HttpCookieDB.updateCookie(hcwi, url);
            }
        }
    }
}
 
源代码17 项目: keywhiz   文件: JsonCookie.java
public static HttpCookie toHttpCookie(JsonCookie cookieContents) {
  HttpCookie cookie = new HttpCookie(cookieContents.name(), cookieContents.value());
  cookie.setDomain(cookieContents.domain());
  cookie.setPath(cookieContents.path());
  cookie.setSecure(cookieContents.isSecure());
  cookie.setHttpOnly(cookieContents.isHttpOnly());
  cookie.setVersion(1); // Always set version to 1 or important fields will be dropped
  return cookie;
}
 
源代码18 项目: keywhiz   文件: JsonCookieTest.java
@Test public void cookiesAlwaysVersion1() throws Exception {
  HttpCookie cookieVersionZero = new HttpCookie("session", "session-contents");
  cookieVersionZero.setPath("/");
  cookieVersionZero.setDomain("localhost");
  cookieVersionZero.setVersion(0);

  HttpCookie convertedCookie = JsonCookie.toHttpCookie(
      JsonCookie.fromHttpCookie(cookieVersionZero));
  assertThat(convertedCookie.getVersion()).isEqualTo(1);
}
 
源代码19 项目: redkale-demo   文件: UserServlet.java
@HttpMapping(url = "/user/logout", auth = false)
public void logout(HttpRequest req, HttpResponse resp) throws IOException {
    String sessionid = req.getSessionid(false);
    if (sessionid != null) service.logout(sessionid);
    HttpCookie cookie = new HttpCookie(COOKIE_AUTOLOGIN, "");
    cookie.setPath("/");
    cookie.setMaxAge(1);
    resp.addCookie(cookie);
    resp.finish("{\"success\":true}");
}
 
源代码20 项目: redkale-demo   文件: UserServlet.java
/**
 * 微信登陆 https://open.weixin.qq.com/connect/qrconnect?appid=wx微信ID&redirect_uri=xxxxx&response_type=code&scope=snsapi_login&state=wx微信ID_1#wechat_redirect
 * 接收两种形式:
 * WEB端微信登录: /user/wxlogin?code=XXXXXX&state=wx微信ID_1&apptoken=XXX
 * APP端微信登录: /user/wxlogin?openid=XXXX&state=1&access_token=XXX&apptoken=XXX
 * <p>
 * @param req
 * @param resp
 *
 * @throws IOException
 */
@HttpMapping(url = "/user/wxlogin", auth = false)
public void wxlogin(HttpRequest req, HttpResponse resp) throws IOException {
    String code = req.getParameter("code");
    String state = req.getParameter("state");  //state值格式: appid_autoregflag

    String access_token = req.getParameter("access_token");
    String openid = req.getParameter("openid");

    if (finest) logger.finest("/user/wxlogin :  code = " + code + ", access_token = " + access_token + ", openid = " + openid + ", state =" + state);
    int pos = state.indexOf('_');
    String appid = pos > 0 ? state.substring(0, pos) : state;
    if (appid.length() < 2) appid = "";
    boolean autoreg = (pos > 0 || "1".equals(state)) ? (state.charAt(pos + 1) == '1') : true;
    final boolean wxbrowser = req.getHeader("User-Agent", "").contains("MicroMessenger");
    LoginWXBean bean = new LoginWXBean();
    { //WEB方式
        bean.setAppid(appid);
        bean.setCode(code);
    }
    { //APP方式
        bean.setAccesstoken(access_token);
        bean.setOpenid(openid);
    }
    bean.setAutoreg(autoreg);
    bean.setApptoken(req.getParameter("apptoken", ""));
    bean.setLoginaddr(req.getRemoteAddr());
    bean.setLoginagent(req.getHeader("User-Agent"));
    if (autoreg) bean.setSessionid(req.changeSessionid());
    RetResult<UserInfo> rr = service.wxlogin(bean);
    if (autoreg && rr.isSuccess() && (wxbrowser || (access_token != null && !access_token.isEmpty()))) {
        UserInfo info = rr.getResult();
        int age = 1000 * 24 * 60 * 60;
        String key = (bean.emptyApptoken() ? "" : (bean.getApptoken() + "#")) + info.getUser36id() + "$1" + info.getWxunionid() + "?" + age + "-" + System.currentTimeMillis();
        HttpCookie cookie = new HttpCookie(COOKIE_AUTOLOGIN, UserService.encryptAES(key));
        cookie.setHttpOnly(true);
        cookie.setPath("/");
        cookie.setMaxAge(age);
        resp.addCookie(cookie);
    }
    if (access_token == null || access_token.isEmpty()) { //WEB登录
        resp.setHeader("Location", req.getParameter("url", "/"));
        resp.finish(302, null);
    } else { //APP 模式
        resp.finishJson(rr);
    }
}