List of usage examples for java.net HttpCookie getName
public String getName()
From source file:com.jaspersoft.android.jaspermobile.network.cookie.CookieMapper.java
@Nullable public org.apache.http.cookie.Cookie toApacheCookie(@Nullable HttpCookie cookie) { if (cookie == null) { return null; }/* w ww . ja va 2 s. com*/ BasicClientCookie clientCookie = new BasicClientCookie(cookie.getName(), cookie.getValue()); clientCookie.setDomain(cookie.getDomain()); clientCookie.setPath(cookie.getPath()); clientCookie.setVersion(cookie.getVersion()); Date expiryDate = new Date(new Date().getTime() + cookie.getMaxAge()); clientCookie.setExpiryDate(expiryDate); return clientCookie; }
From source file:com.subgraph.vega.ui.scanner.ScanExecutor.java
private List<Cookie> getCookieList(List<String> cookieStringList, URI uri) { if (cookieStringList.size() != 0) { ArrayList<Cookie> cookieList = new ArrayList<Cookie>(cookieStringList.size()); for (String cookieString : cookieStringList) { List<HttpCookie> parseList = HttpCookie.parse(cookieString); for (HttpCookie cookie : parseList) { BasicClientCookie cp = new BasicClientCookie(cookie.getName(), cookie.getValue()); cp.setComment(cookie.getComment()); if (cookie.getDomain() != null) { cp.setDomain(cookie.getDomain()); } else { // just set it to the target host for now - may need something slightly less specific cp.setDomain(uri.getHost()); }// w ww .j a v a2s .c om long maxAge = cookie.getMaxAge(); if (maxAge > 0) { Calendar calendar = Calendar.getInstance(); calendar.add(Calendar.SECOND, (int) maxAge); cp.setExpiryDate(calendar.getTime()); } cp.setPath(cookie.getPath()); cp.setSecure(cookie.getSecure()); cp.setVersion(cookie.getVersion()); cookieList.add(cp); } } return cookieList; } return null; }
From source file:interactivespaces.service.web.server.internal.netty.NettyHttpRequest.java
@Override public HttpCookie getCookie(String key) { Collection<HttpCookie> cookies = getCookies(); for (HttpCookie cookie : cookies) { if (key.equals(cookie.getName())) { return cookie; }/*from www.j a va 2s. c o m*/ } return null; }
From source file:com.threewks.thundr.http.service.gae.HttpResponseImpl.java
private Map<String, List<HttpCookie>> buildCookieMap(Map<String, List<String>> headersLower) { Map<String, List<HttpCookie>> cookies = new LinkedHashMap<String, List<HttpCookie>>(); for (String setCookieHeader : getCookieHeaders(headersLower)) { List<HttpCookie> cookieSet = parseCookies(setCookieHeader); for (HttpCookie httpCookie : cookieSet) { String name = httpCookie.getName(); List<HttpCookie> existingCookies = cookies.get(name); if (existingCookies == null) { existingCookies = new ArrayList<HttpCookie>(); cookies.put(name, existingCookies); }//from w ww . j av a 2 s . c o m existingCookies.add(httpCookie); } } return cookies; }
From source file:com.nominanuda.web.http.ServletHelper.java
public Cookie servletCookie(HttpCookie c) { Cookie _c = new Cookie(c.getName(), c.getValue()); if (c.getComment() != null) { _c.setComment(c.getComment());// w ww. ja v a 2 s . c om } if (c.getDomain() != null) { _c.setDomain(c.getDomain()); } if (c.getPath() != null) { _c.setPath(c.getPath()); } _c.setSecure(c.getSecure()); _c.setVersion(c.getVersion()); _c.setHttpOnly(c.getDiscard()); _c.setMaxAge((int) c.getMaxAge()); return _c; }
From source file:org.opentestsystem.shared.test.interactioncontext.FastInteractionContext.java
@Override public String getCookie(String key) { final List<HttpCookie> cookieList = _cookies.getCookieStore().get(_baseURI); for (HttpCookie cookie_i : cookieList) { if (cookie_i.getName().equalsIgnoreCase(key)) { return cookie_i.getValue(); }//w w w . ja v a2 s . co m } return null; }
From source file:org.nextlets.erc.defaults.http.ERCHttpInvokerImpl.java
private Cookie toCookie(URI uri, HttpCookie httpCookie) { SetCookie cookie = new BasicClientCookie(httpCookie.getName(), httpCookie.getValue()); cookie.setComment(httpCookie.getComment()); if (httpCookie.getDomain() != null) { cookie.setDomain(httpCookie.getDomain()); } else {/* ww w.j a va2 s . c om*/ cookie.setDomain(uri.getHost()); } if (httpCookie.getMaxAge() != -1) { cookie.setExpiryDate(new Date(httpCookie.getMaxAge() * 1000)); } if (httpCookie.getPath() != null) { cookie.setPath(httpCookie.getPath()); } else { cookie.setPath(uri.getPath()); } cookie.setSecure(httpCookie.getSecure()); cookie.setVersion(httpCookie.getVersion()); return cookie; }
From source file:com.handsome.frame.android.volley.stack.HurlStack.java
@Override public HttpResponse performRequest(Request<?> request) throws IOException, AuthFailureError { HashMap<String, String> map = new HashMap<String, String>(); if (!TextUtils.isEmpty(mUserAgent)) { map.put(HTTP.USER_AGENT, mUserAgent); }//from w w w. j av a2 s.c o m map.putAll(request.getHeaders()); URL parsedUrl = new URL(request.getUrl()); HttpURLConnection connection = openConnection(parsedUrl, request); for (String headerName : map.keySet()) { connection.addRequestProperty(headerName, map.get(headerName)); } if (HandsomeApplication.getCookies() != null) { HDLog.d(TAG + "-Req-Cookie:", HandsomeApplication.getCookies().toString()); connection.addRequestProperty("Cookie", HandsomeApplication.getCookies()); } else { HDLog.d(TAG + "-Req-Cookie:", "null"); } setConnectionParametersForRequest(connection, request); int responseCode = connection.getResponseCode(); if (responseCode == -1) { // -1 is returned by getResponseCode() if the response code could not be retrieved. // Signal to the caller that something was wrong with the connection. throw new IOException("Could not retrieve response code from HttpUrlConnection."); } StatusLine responseStatus = new BasicStatusLine(new ProtocolVersion("HTTP", 1, 1), connection.getResponseCode(), connection.getResponseMessage()); BasicHttpResponse response = new BasicHttpResponse(responseStatus); response.setEntity(entityFromConnection(connection)); for (Entry<String, List<String>> header : connection.getHeaderFields().entrySet()) { if (header.getKey() != null) { if (header.getKey().equalsIgnoreCase("Set-Cookie")) { List<String> cookies = header.getValue(); HashMap<String, HttpCookie> cookieMap = new HashMap<String, HttpCookie>(); for (String string : cookies) { List<HttpCookie> cookie = HttpCookie.parse(string); for (HttpCookie httpCookie : cookie) { cookieMap.put(httpCookie.getName(), httpCookie); } } HandsomeApplication.setCookies(cookieMap); HDLog.d(TAG + "-Rsp-Cookie:", HandsomeApplication.getCookies().toString()); } else { Header h = new BasicHeader(header.getKey(), header.getValue().get(0)); response.addHeader(h); } } } return response; }
From source file:com.codename1.corsproxy.CORSProxy.java
@Override protected void copyProxyCookie(HttpServletRequest servletRequest, HttpServletResponse servletResponse, Header header) {// ww w. ja v a 2 s . com 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 (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.setSecure(false); servletCookie.setVersion(cookie.getVersion()); servletResponse.addCookie(servletCookie); } }
From source file:com.muk.services.security.DefaultUaaLoginService.java
@SuppressWarnings("unchecked") @Override/*from w ww. j a va 2 s. c om*/ public Map<String, Object> loginForClient(String username, String password, String clientId, UriComponents inUrlComponents) { final Map<String, Object> responsePayload = new HashMap<String, Object>(); final HttpHeaders headers = new HttpHeaders(); headers.setAccept(Collections.singletonList(MediaType.APPLICATION_JSON_UTF8)); final UriComponentsBuilder uriBuilder = UriComponentsBuilder.fromUriString(cfgService.getOauthServer()); // login for csrf final UriComponents loginUri = uriBuilder.cloneBuilder().pathSegment("login").build(); ResponseEntity<String> response = exchangeForType(loginUri.toUriString(), HttpMethod.GET, null, headers, String.class); final List<String> cookies = new ArrayList<String>(); cookies.addAll(response.getHeaders().get(HttpHeaders.SET_COOKIE)); final MultiValueMap<String, String> formData = new LinkedMultiValueMap<>(); formData.add("username", username); formData.add("password", password); formData.add(CSRF, getCsrf(cookies)); headers.put(HttpHeaders.COOKIE, translateInToOutCookies(cookies)); headers.add(HttpHeaders.REFERER, loginUri.toUriString()); // login.do response = exchangeForType(uriBuilder.cloneBuilder().pathSegment("login.do").build().toUriString(), HttpMethod.POST, formData, headers, String.class); if (response.getStatusCode() != HttpStatus.FOUND || response.getHeaders().getFirst(HttpHeaders.LOCATION).contains("login")) { responsePayload.put("error", "bad credentials"); return responsePayload; } removeCookie(cookies, "X-Uaa-Csrf"); cookies.addAll(response.getHeaders().get(HttpHeaders.SET_COOKIE)); removeExpiredCookies(cookies); headers.remove(HttpHeaders.REFERER); headers.put(HttpHeaders.COOKIE, translateInToOutCookies(cookies)); // authorize final ResponseEntity<JsonNode> authResponse = exchangeForType( uriBuilder.cloneBuilder().pathSegment("oauth").pathSegment("authorize") .queryParam("response_type", "code").queryParam("client_id", clientId) .queryParam("redirect_uri", inUrlComponents.toUriString()).build().toUriString(), HttpMethod.GET, null, headers, JsonNode.class); if (authResponse.getStatusCode() == HttpStatus.OK) { removeCookie(cookies, "X-Uaa-Csrf"); cookies.addAll(authResponse.getHeaders().get(HttpHeaders.SET_COOKIE)); // return approval data final List<HttpCookie> parsedCookies = new ArrayList<HttpCookie>(); for (final String cookie : cookies) { parsedCookies.add(HttpCookie.parse(cookie).get(0)); } responsePayload.put(HttpHeaders.SET_COOKIE, new ArrayList<String>()); for (final HttpCookie parsedCookie : parsedCookies) { if (!parsedCookie.getName().startsWith("Saved-Account")) { parsedCookie.setPath(inUrlComponents.getPath()); ((List<String>) responsePayload.get(HttpHeaders.SET_COOKIE)) .add(httpCookieToString(parsedCookie)); } } responsePayload.put("json", authResponse.getBody()); } else { // get auth_code from Location Header responsePayload.put("code", authResponse.getHeaders().getLocation().getQuery().split("=")[1]); } return responsePayload; }