Refine search
@Override public long getKeepAliveDuration(HttpResponse response, HttpContext context) { HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE)); while (it.hasNext()) { HeaderElement he = it.nextElement(); String param = he.getName(); String value = he.getValue(); if (value != null && param.equalsIgnoreCase(Constants.TIMEOUT_KEY)) { return Long.parseLong(value) * 1000; } } return HTTPCLIENT_KEEPALIVEDURATION; } })
private void parseNextElement() { // loop while there are headers left to parse while (this.headerIt.hasNext() || this.cursor != null) { if (this.cursor == null || this.cursor.atEnd()) { // get next header value bufferHeaderValue(); } // Anything buffered? if (this.cursor != null) { // loop while there is data in the buffer while (!this.cursor.atEnd()) { HeaderElement e = this.parser.parseHeaderElement(this.buffer, this.cursor); if (!(e.getName().length() == 0 && e.getValue() == null)) { // Found something this.currentElement = e; return; } } // if at the end of the buffer if (this.cursor.atEnd()) { // discard it this.cursor = null; this.buffer = null; } } } }
public final Object next() throws NoSuchElementException { return nextElement(); }
/** * getCookies: refer http://blog.csdn.net/alibert/article/details/42788189 * @author alterhu2020@gmail.com * @since JDK 1.8 */ public static void getCookies(){ HeaderElementIterator headerIterator = new BasicHeaderElementIterator(httpResponse.headerIterator("Set-Cookie")); while(headerIterator.hasNext()){ HeaderElement cookiesElement = headerIterator.nextElement(); logger.info(cookiesElement.getName() + " = " + cookiesElement.getValue()); NameValuePair[] params = cookiesElement.getParameters(); for (int i = 0; i < params.length; i++) { logger.info(" " + params[i]); } } }
@Override public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpContext) { // in case of errors keep-alive not always works. close connection just in case if (httpResponse.getStatusLine().getStatusCode() != HttpURLConnection.HTTP_OK) { return -1; } HeaderElementIterator it = new BasicHeaderElementIterator( httpResponse.headerIterator(HTTP.CONN_DIRECTIVE)); while (it.hasNext()) { HeaderElement he = it.nextElement(); String param = he.getName(); //String value = he.getValue(); if (param != null && param.equalsIgnoreCase(HTTP.CONN_KEEP_ALIVE)) { return properties.getKeepAliveTimeout(); } } return -1; } };
public boolean hasNext() { if (this.currentElement == null) { parseNextElement(); } return this.currentElement != null; }
/** * getCookies: refer http://blog.csdn.net/alibert/article/details/42788189 * @author alterhu2020@gmail.com * @since JDK 1.8 */ public static void getCookies(){ HeaderElementIterator headerIterator = new BasicHeaderElementIterator(httpResponse.headerIterator("Set-Cookie")); while(headerIterator.hasNext()){ HeaderElement cookiesElement = headerIterator.nextElement(); logger.info(cookiesElement.getName() + " = " + cookiesElement.getValue()); NameValuePair[] params = cookiesElement.getParameters(); for (int i = 0; i < params.length; i++) { logger.info(" " + params[i]); } } }
@Override public long getKeepAliveDuration(HttpResponse httpResponse, HttpContext httpContext) { // in case of errors keep-alive not always works. close connection just in case if (httpResponse.getStatusLine().getStatusCode() != HttpURLConnection.HTTP_OK) { return -1; } HeaderElementIterator it = new BasicHeaderElementIterator( httpResponse.headerIterator(HTTP.CONN_DIRECTIVE)); while (it.hasNext()) { HeaderElement he = it.nextElement(); String param = he.getName(); //String value = he.getValue(); if (param != null && param.equalsIgnoreCase(HTTP.CONN_KEEP_ALIVE)) { return properties.getKeepAliveTimeout(); } } return -1; } };
public HeaderElement nextElement() throws NoSuchElementException { if (this.currentElement == null) { parseNextElement(); } if (this.currentElement == null) { throw new NoSuchElementException("No more header elements available"); } HeaderElement element = this.currentElement; this.currentElement = null; return element; }
@Override public long getKeepAliveDuration(HttpResponse response, HttpContext context) { HeaderElementIterator it = new BasicHeaderElementIterator(response.headerIterator(HTTP.CONN_KEEP_ALIVE)); while (it.hasNext()) { HeaderElement he = it.nextElement(); String param = he.getName(); String value = he.getValue(); if (value != null && param.equalsIgnoreCase(Constants.TIMEOUT_KEY)) { return Long.parseLong(value) * 1000; } } return HTTPCLIENT_KEEPALIVEDURATION; } })
private void parseNextElement() { // loop while there are headers left to parse while (this.headerIt.hasNext() || this.cursor != null) { if (this.cursor == null || this.cursor.atEnd()) { // get next header value bufferHeaderValue(); } // Anything buffered? if (this.cursor != null) { // loop while there is data in the buffer while (!this.cursor.atEnd()) { final HeaderElement e = this.parser.parseHeaderElement(this.buffer, this.cursor); if (!(e.getName().length() == 0 && e.getValue() == null)) { // Found something this.currentElement = e; return; } } // if at the end of the buffer if (this.cursor.atEnd()) { // discard it this.cursor = null; this.buffer = null; } } } }
/** * getCookies: refer http://blog.csdn.net/alibert/article/details/42788189 * * @author alterhu2020@gmail.com * @since JDK 1.8 */ public static void getCookies() { HeaderElementIterator headerIterator = new BasicHeaderElementIterator( httpResponse.headerIterator("Set-Cookie")); while (headerIterator.hasNext()) { HeaderElement cookiesElement = headerIterator.nextElement(); logger.info(cookiesElement.getName() + " = " + cookiesElement.getValue()); NameValuePair[] params = cookiesElement.getParameters(); for (int i = 0; i < params.length; i++) { logger.info(" " + params[i]); } } }
@Override public boolean hasNext() { if (this.currentElement == null) { parseNextElement(); } return this.currentElement != null; }
@Override public final Object next() throws NoSuchElementException { return nextElement(); }
@Override public long getKeepAliveDuration(HttpResponse response, HttpContext context) { HeaderElementIterator it = new BasicHeaderElementIterator( response.headerIterator(HTTP.CONN_KEEP_ALIVE)); while (it.hasNext()) { HeaderElement he = it.nextElement(); String param = he.getName(); String value = he.getValue(); if (value != null && param.equalsIgnoreCase("timeout")) { try { return Long.parseLong(value) * 1000; } catch (NumberFormatException ignore) { } } } return keepAliveTimeOut * 1000; }
private void parseNextElement() { // loop while there are headers left to parse while (this.headerIt.hasNext() || this.cursor != null) { if (this.cursor == null || this.cursor.atEnd()) { // get next header value bufferHeaderValue(); } // Anything buffered? if (this.cursor != null) { // loop while there is data in the buffer while (!this.cursor.atEnd()) { final HeaderElement e = this.parser.parseHeaderElement(this.buffer, this.cursor); if (!(e.getName().length() == 0 && e.getValue() == null)) { // Found something this.currentElement = e; return; } } // if at the end of the buffer if (this.cursor.atEnd()) { // discard it this.cursor = null; this.buffer = null; } } } }
/** * getCookies: refer http://blog.csdn.net/alibert/article/details/42788189 * * @author alterhu2020@gmail.com * @since JDK 1.8 */ public static void getCookies() { HeaderElementIterator headerIterator = new BasicHeaderElementIterator( httpResponse.headerIterator("Set-Cookie")); while (headerIterator.hasNext()) { HeaderElement cookiesElement = headerIterator.nextElement(); logger.info(cookiesElement.getName() + " = " + cookiesElement.getValue()); NameValuePair[] params = cookiesElement.getParameters(); for (int i = 0; i < params.length; i++) { logger.info(" " + params[i]); } } }
public boolean hasNext() { if (this.currentElement == null) { parseNextElement(); } return this.currentElement != null; }
public final Object next() throws NoSuchElementException { return nextElement(); }
public long getKeepAliveDuration(HttpResponse response, HttpContext context) { if (response == null) { throw new IllegalArgumentException("HTTP response may not be null"); } HeaderElementIterator it = new BasicHeaderElementIterator( response.headerIterator(HTTP.CONN_KEEP_ALIVE)); while (it.hasNext()) { HeaderElement he = it.nextElement(); String param = he.getName(); String value = he.getValue(); if (value != null && param.equalsIgnoreCase("timeout")) { try { return Long.parseLong(value) * 1000; } catch(NumberFormatException ignore) { } } } return -1; }