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

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

源代码1 项目: XS2A-Sandbox   文件: CookiesUtils.java
public String resetCookies(List<String> cookieStrings) {
	String result = null;
	for (String cookieString : cookieStrings) {
		List<HttpCookie> parse = HttpCookie.parse(cookieString);
		for (HttpCookie httpCookie : parse) {
			if(StringUtils.isNoneBlank(httpCookie.getValue())) {
				String cookie = httpCookie.getName()+"="+httpCookie.getValue();
				if(result==null) {
					result = cookie;
				} else {
					result = result + " ; " + cookie;
				}
			}
		}
	}
	return result;
}
 
源代码2 项目: XS2A-Sandbox   文件: ResponseUtils.java
private String cookie(String cookieStringIn, String name) {
	String cookieString = cookieStringIn;
	if(cookieString==null) {
		return null;
	}

	String cookieParamName=name+"=";

	// Fix Java: rfc2965 want cookie to be separated by comma.
	// SOmehow i am receiving some semicolon separated cookies.
	// Quick Fix: First strip the preceeding cookies if not the first.
	if(!StringUtils.startsWithIgnoreCase(cookieString, cookieParamName)) {
		int indexOfIgnoreCase = StringUtils.indexOfIgnoreCase(cookieString, cookieParamName);
		cookieString = cookieString.substring(indexOfIgnoreCase);
	}
	// The proce
	List<HttpCookie> cookies = HttpCookie.parse(cookieString);
	for (HttpCookie httpCookie : cookies) {
		if(StringUtils.equalsIgnoreCase(httpCookie.getName(), name)){
			return httpCookie.getValue();
		}
	}
	return null;
}
 
源代码3 项目: verano-http   文件: Cookie.java
@Override
public final String asString() {
    final Map<String, List<String>> headers =
        new Headers.Of(this.dict).asMap();
    final String key = "Set-Cookie";
    if (headers.containsKey(key)) {
        for (final String header : headers.get(key)) {
            //@checkstyle LineLength (1 line)
            for (final HttpCookie candidate : HttpCookie.parse(header)) {
                if (candidate.getName().equals(this.name)) {
                    return candidate.getValue();
                }
            }
        }
        throw new IllegalStateException(
            String.format(
                "Cookie %s not found in Set-Cookie header.",
                this.name
            )
        );
    }
    throw new IllegalStateException("Set-Cookie header not found.");
}
 
private Cookie[] createCookies() {
  List<String> strCookies = httpHeaders.get(HttpHeaders.COOKIE);
  if (strCookies == null) {
    return new Cookie[] {};
  }

  List<Cookie> result = new ArrayList<>();
  for (String strCookie : strCookies) {
    List<HttpCookie> httpCookies = HttpCookie.parse(strCookie);
    for (HttpCookie httpCookie : httpCookies) {
      Cookie cookie = new Cookie(httpCookie.getName(), httpCookie.getValue());
      result.add(cookie);
    }
  }

  return result.toArray(new Cookie[result.size()]);
}
 
源代码5 项目: zest-writer   文件: ZdsHttp.java
/**
 * Authentication with google account
 * @param cookies cookies list keys from google auth
 * @param login username associated to zds login
 * @param id user id on ZdS associated to login
 */
public void authToGoogle(List<HttpCookie> cookies, String login, String id) {
    if(login != null && id != null) {
        this.login = login;
        this.idUser = id;
        log.info("L'identifiant de l'utilisateur " + this.login + " est : " + idUser);
        cookieStore = new BasicCookieStore();
        for(HttpCookie cookie:cookies) {
            BasicClientCookie c = new BasicClientCookie(cookie.getName(), cookie.getValue());
            c.setDomain(cookie.getDomain());
            c.setPath(cookie.getPath());
            c.setSecure(cookie.getSecure());
            c.setVersion(cookie.getVersion());
            c.setComment(cookie.getComment());
            cookieStore.addCookie(c);
        }
        context.setCookieStore(cookieStore);
        this.authenticated = true;
    }
    else {
        log.debug("Le login de l'utilisateur n'a pas pu être trouvé");
    }
}
 
源代码6 项目: haven-platform   文件: HttpProxy.java
/**
 * Copy cookie from the proxy to the servlet client.
 * Replaces cookie path to local path and renames cookie to avoid collisions.
 */
private void copyProxyCookie(HttpServletRequest servletRequest,
                             HttpServletResponse servletResponse, Header header) {
    List<HttpCookie> cookies = HttpCookie.parse(header.getValue());
    String path = servletRequest.getContextPath(); // path starts with / or is empty string
    path += servletRequest.getServletPath(); // servlet path starts with / or is empty string
    for (int i = 0, l = cookies.size(); i < l; i++) {
        HttpCookie cookie = cookies.get(i);
        //set cookie name prefixed w/ a proxy value so it won't collide w/ other cookies
        String proxyCookieName = getCookieNamePrefix() + cookie.getName();
        Cookie servletCookie = new Cookie(proxyCookieName, cookie.getValue());
        servletCookie.setComment(cookie.getComment());
        servletCookie.setMaxAge((int) cookie.getMaxAge());
        servletCookie.setPath(path); //set to the path of the proxy servlet
        // don't set cookie domain
        servletCookie.setSecure(cookie.getSecure());
        servletCookie.setVersion(cookie.getVersion());
        servletResponse.addCookie(servletCookie);
    }
}
 
源代码7 项目: Nimingban   文件: NMBApplication.java
public static void updateCookies(Context context) {
    SimpleCookieStore cookieStore = NMBApplication.getSimpleCookieStore(context);

    URL url = ACSite.getInstance().getSiteUrl();
    HttpCookieWithId hcwi = cookieStore.getCookie(url, "userId");
    if (hcwi != null) {
        HttpCookie oldCookie = hcwi.httpCookie;
        cookieStore.remove(url, oldCookie);

        HttpCookie newCookie = new HttpCookie("userhash", oldCookie.getValue());
        newCookie.setComment(oldCookie.getComment());
        newCookie.setCommentURL(oldCookie.getCommentURL());
        newCookie.setDiscard(oldCookie.getDiscard());
        newCookie.setDomain(oldCookie.getDomain());
        newCookie.setMaxAge(oldCookie.getMaxAge());
        newCookie.setPath(oldCookie.getPath());
        newCookie.setPortlist(oldCookie.getPortlist());
        newCookie.setSecure(oldCookie.getSecure());
        newCookie.setVersion(oldCookie.getVersion());

        cookieStore.add(url, newCookie);
    }
}
 
源代码8 项目: Nimingban   文件: TransportableHttpCookie.java
public static List<TransportableHttpCookie> from(URL url, List<HttpCookieWithId> list) {
    List<TransportableHttpCookie> result = new ArrayList<>(list.size());
    for (HttpCookieWithId hcwi : list) {
        HttpCookie cookie = hcwi.httpCookie;
        TransportableHttpCookie thc = new TransportableHttpCookie();
        thc.name = cookie.getName();
        thc.value = cookie.getValue();
        thc.comment = cookie.getComment();
        thc.commentURL = cookie.getCommentURL();
        thc.discard = cookie.getDiscard();
        thc.domain = cookie.getDomain();
        thc.maxAge = cookie.getMaxAge();
        thc.path = cookie.getPath();
        thc.portList = cookie.getPortlist();
        thc.secure = cookie.getSecure();
        thc.version = cookie.getVersion();
        thc.url = url.toString();
        result.add(thc);
    }
    return result;
}
 
源代码9 项目: onboard   文件: ApiProxyServlet.java
/**
 * Copy cookie from the proxy to the servlet client. Replaces cookie path to local path and renames cookie to avoid
 * collisions.
 */
protected void copyProxyCookie(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Header header) {
    List<HttpCookie> cookies = HttpCookie.parse(header.getValue());
    String path = getServletContext().getServletContextName();
    if (path == null) {
        path = "";
    }
    path += servletRequest.getServletPath();

    for (HttpCookie cookie : cookies) {
        // set cookie name prefixed w/ a proxy value so it won't collide w/ other cookies
        String proxyCookieName = getCookieNamePrefix() + cookie.getName();
        Cookie servletCookie = new Cookie(proxyCookieName, cookie.getValue());
        servletCookie.setComment(cookie.getComment());
        servletCookie.setMaxAge((int) cookie.getMaxAge());
        servletCookie.setPath(path); // set to the path of the proxy servlet
        // don't set cookie domain
        servletCookie.setSecure(cookie.getSecure());
        servletCookie.setVersion(cookie.getVersion());
        servletResponse.addCookie(servletCookie);
    }
}
 
源代码10 项目: NoHttp   文件: CookieEntity.java
/**
 * Cookie building database entities.
 *
 * @param uri    cookie corresponding uri.
 * @param cookie cookie.
 */
public CookieEntity(URI uri, HttpCookie cookie) {
    this.uri = uri == null ? null : uri.toString();
    this.name = cookie.getName();
    this.value = cookie.getValue();
    this.comment = cookie.getComment();
    this.commentURL = cookie.getCommentURL();
    this.discard = cookie.getDiscard();
    this.domain = cookie.getDomain();
    long maxAge = cookie.getMaxAge();
    if (maxAge != -1 && maxAge > 0) {
        this.expiry = (maxAge * 1000L) + System.currentTimeMillis();
        if (this.expiry < 0L) // 溢出
            this.expiry = HeaderUtils.getMaxExpiryMillis();
    } else
        this.expiry = -1L;

    this.path = cookie.getPath();
    if (!TextUtils.isEmpty(path) && path.length() > 1 && path.endsWith("/")) {
        this.path = path.substring(0, path.length() - 1);
    }
    this.portList = cookie.getPortlist();
    this.secure = cookie.getSecure();
    this.version = cookie.getVersion();
}
 
源代码11 项目: robe   文件: AuthenticatedWebSocket.java
@Override
public String onConnect(Session session) {
    for (HttpCookie cookie : session.getUpgradeRequest().getCookies()) {
        if ("auth-token".equals(cookie.getName())) {
            String authToken = cookie.getValue();
            TokenAuthenticator authenticator = getAuthenticator();
            org.hibernate.Session hSession = sessionFactory.openSession();
            ManagedSessionContext.bind(hSession);
            Optional<BasicToken> token;
            try {
                token = authenticator.authenticate(authToken);
            } catch (AuthenticationException e) {
                e.printStackTrace();
                return null;
            }
            if (!token.isPresent()) {
                return null;
            }
            hSession.close();
            return token.get().getUserId();
        }
    }
    return null;
}
 
源代码12 项目: utexas-utilities   文件: AuthCookie.java
/**
 * Executes a login request with the AuthCookie's OkHttpClient. This should only be called
 * when persistent login is activated.
 * @param request Request to execute
 * @return true if the cookie was set successfully, false if the cookie was not set
 * @throws IOException
 */
protected boolean performLogin(Request request) throws IOException {
    Response response = client.newCall(request).execute();
    if (!response.isSuccessful()) {
        throw new IOException("Bad response code: " + response + " during login.");
    }
    response.body().close();
    CookieManager cm = (CookieManager) CookieHandler.getDefault();
    List<HttpCookie> cookies = cm.getCookieStore().getCookies();
    for (HttpCookie cookie : cookies) {
        String cookieVal = cookie.getValue();
        if (cookie.getName().equals(authCookieKey)) {
            setAuthCookieVal(cookieVal);
            return true;
        }
    }
    return false;
}
 
源代码13 项目: SimpleProject   文件: CookieAdapter.java
public CookieAdapter(HttpCookie cookie) {
	this.name = cookie.getName();
	this.value = cookie.getValue();
	this.domain = cookie.getDomain();
	this.path = cookie.getPath();
	this.secure = cookie.getSecure();
}
 
源代码14 项目: zap-extensions   文件: JsoScanRule.java
private void checkJsoInCookies(HttpMessage msg, List<HttpCookie> cookies) {
    for (HttpCookie cookie : cookies) {
        String value = cookie.getValue();
        if (!hasJsoMagicSequence(value)) {
            continue;
        }

        raiseAlert(msg, cookie.toString());
    }
}
 
源代码15 项目: Mover   文件: MoverAuthenticator.java
private String findToken(List<HttpCookie> cookies){
    for(HttpCookie cookie : cookies){
        if(cookie.getName().equalsIgnoreCase("auth_sess")){
            return cookie.getValue();
        }
    }

    return null;
}
 
源代码16 项目: 4pdaClient-plus   文件: Client.java
private void checkLogin() {
    for (HttpCookie cookie : Http.Companion.getInstance().getCookieStore().getCookies()) {
        if ("4pda.User".equals(cookie.getName())) {
            UserInfoRepository.Companion.getInstance().setName(cookie.getValue());
        } else if ("4pda.K".equals(cookie.getName())) {
            m_K = cookie.getValue();
        }
    }
}
 
源代码17 项目: opensoc-streaming   文件: KafkaWebSocketCreator.java
@Override
public Object createWebSocket(ServletUpgradeRequest request, ServletUpgradeResponse response) 
{
	boolean authGood = false;
	List<HttpCookie> cookies = request.getCookies();
	for( HttpCookie cookie : cookies )
	{
		String name = cookie.getName();
		if( name!= null && name.equals( "authToken" ))
		{
			String value = cookie.getValue();
			
			try
			{
				if( value != null && AuthToken.validateToken(configProps, value))
				{
					authGood = true;
					break;
				}
			}
			catch( Exception e )
			{
				logger.error(" Exception validating authToken:", e );
				authGood = false;
				break;
			}
			
		}
		else
		{
			continue;
		}
	}

	return new KafkaMessageSenderSocket( configProps, authGood );
}
 
源代码18 项目: ChatApi-WeChat   文件: WeChatClient.java
/**
 * 初始化
 *
 * @return 初始化异常原因,为null表示正常初始化
 */
@Nullable
private String initial() {
    try {
        //通过Cookie获取重要参数
        XTools.logD(LOG_TAG, "正在获取Cookie");
        for (HttpCookie cookie : XHttpTools.EXECUTOR.getCookies()) {
            if ("wxsid".equalsIgnoreCase(cookie.getName())) {
                wxAPI.sid = cookie.getValue();
            } else if ("wxuin".equalsIgnoreCase(cookie.getName())) {
                wxAPI.uin = cookie.getValue();
            } else if ("webwx_data_ticket".equalsIgnoreCase(cookie.getName())) {
                wxAPI.dataTicket = cookie.getValue();
            }
        }

        //获取自身信息
        XTools.logD(LOG_TAG, "正在获取自身信息");
        RspInit rspInit = wxAPI.webwxinit();
        wxContacts.setMe(wxAPI.host, rspInit.User);

        //获取并保存最近联系人
        XTools.logD(LOG_TAG, "正在获取并保存最近联系人");
        loadContacts(rspInit.ChatSet, true);

        //发送初始化状态信息
        wxAPI.webwxstatusnotify(wxContacts.getMe().id, WXNotify.NOTIFY_INITED);

        //获取好友、保存的群聊、公众号列表。
        //这里获取的群没有群成员,不过也不能用fetchContact方法暴力获取群成员,因为这样数据量会很大
        XTools.logD(LOG_TAG, "正在获取好友、群、公众号列表");
        RspGetContact rspGetContact = wxAPI.webwxgetcontact();
        for (RspInit.User user : rspGetContact.MemberList) {
            wxContacts.putContact(wxAPI.host, user);
        }

        return null;
    } catch (Exception e) {
        e.printStackTrace();
        XTools.logW(LOG_TAG, String.format("初始化异常:%s", e.getMessage()));
        return INIT_EXCEPTION;
    }
}