public HeaderElement parseHeader( final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException { if (buffer == null) { throw new IllegalArgumentException("Char array buffer may not be null"); } if (cursor == null) { throw new IllegalArgumentException("Parser cursor may not be null"); } NameValuePair nvp = parseNameValuePair(buffer, cursor); List<NameValuePair> params = new ArrayList<NameValuePair>(); while (!cursor.atEnd()) { NameValuePair param = parseNameValuePair(buffer, cursor); params.add(param); } return new BasicHeaderElement( nvp.getName(), nvp.getValue(), params.toArray(new NameValuePair[params.size()])); }
@Test public void createCookieForHeaderElementTest() { String cookiePath = "/client/api"; String paramName = "paramName1"; String paramValue = "paramVale1"; NameValuePair[] parameters = new NameValuePair[1]; parameters[0] = new BasicNameValuePair(paramName, paramValue); String headerName = "headerElementName"; String headerValue = "headerElementValue"; HeaderElement headerElement = new BasicHeaderElement(headerName, headerValue, parameters); Mockito.doNothing().when(apacheCloudStackClient).configureDomainForCookie(Mockito.any(BasicClientCookie.class)); BasicClientCookie cookieForHeaderElement = apacheCloudStackClient.createCookieForHeaderElement(headerElement); Assert.assertNotNull(cookieForHeaderElement); Assert.assertEquals(headerName, cookieForHeaderElement.getName()); Assert.assertEquals(headerValue, cookieForHeaderElement.getValue()); Assert.assertEquals(paramValue, cookieForHeaderElement.getAttribute(paramName)); Assert.assertEquals(cookiePath, cookieForHeaderElement.getPath()); Mockito.verify(apacheCloudStackClient).configureDomainForCookie(Mockito.eq(cookieForHeaderElement)); }
public HeaderElement parseHeader( final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException { if (buffer == null) { throw new IllegalArgumentException("Char array buffer may not be null"); } if (cursor == null) { throw new IllegalArgumentException("Parser cursor may not be null"); } NameValuePair nvp = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS); List<NameValuePair> params = new ArrayList<NameValuePair>(); while (!cursor.atEnd()) { NameValuePair param = this.nvpParser.parseNameValuePair(buffer, cursor, DELIMITERS); params.add(param); } return new BasicHeaderElement( nvp.getName(), nvp.getValue(), params.toArray(new NameValuePair[params.size()])); }
public HeaderElement parseHeader( final CharArrayBuffer buffer, final ParserCursor cursor) throws ParseException { Args.notNull(buffer, "Char array buffer"); Args.notNull(cursor, "Parser cursor"); final NameValuePair nvp = parseNameValuePair(buffer, cursor); final List<NameValuePair> params = new ArrayList<NameValuePair>(); while (!cursor.atEnd()) { final NameValuePair param = parseNameValuePair(buffer, cursor); params.add(param); } return new BasicHeaderElement( nvp.getName(), nvp.getValue(), params.toArray(new NameValuePair[params.size()])); }
public List<Header> formatCookies(final List<Cookie> cookies) { Args.notEmpty(cookies, "List of cookies"); final CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size()); buffer.append(SM.COOKIE); buffer.append(": "); for (int i = 0; i < cookies.size(); i++) { final Cookie cookie = cookies.get(i); if (i > 0) { buffer.append("; "); } final String cookieName = cookie.getName(); final String cookieValue = cookie.getValue(); if (cookie.getVersion() > 0 && !isQuoteEnclosed(cookieValue)) { BasicHeaderValueFormatterHC4.INSTANCE.formatHeaderElement( buffer, new BasicHeaderElement(cookieName, cookieValue), false); } else { // Netscape style cookies do not support quoted values buffer.append(cookieName); buffer.append("="); if (cookieValue != null) { buffer.append(cookieValue); } } } final List<Header> headers = new ArrayList<Header>(1); headers.add(new BufferedHeader(buffer)); return headers; }
@Override public List<Header> formatCookies(final List<Cookie> cookies) { Args.notEmpty(cookies, "List of cookies"); final CharArrayBuffer buffer = new CharArrayBuffer(20 * cookies.size()); buffer.append(SM.COOKIE); buffer.append(": "); for (int i = 0; i < cookies.size(); i++) { final Cookie cookie = cookies.get(i); if (i > 0) { buffer.append("; "); } final String cookieName = cookie.getName(); final String cookieValue = cookie.getValue(); if (cookie.getVersion() > 0 && !isQuoteEnclosed(cookieValue)) { BasicHeaderValueFormatter.INSTANCE.formatHeaderElement( buffer, new BasicHeaderElement(cookieName, cookieValue), false); } else { // Netscape style cookies do not support quoted values buffer.append(cookieName); buffer.append("="); if (cookieValue != null) { buffer.append(cookieValue); } } } final List<Header> headers = new ArrayList<Header>(1); headers.add(new BufferedHeader(buffer)); return headers; }