Package org.apache.http

Examples of org.apache.http.NameValuePair


            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()]));
View Full Code Here


            // Eliminate duplicate attributes. The first occurrence takes precedence
            // See RFC2965: 3.2  Origin Server Role
            Map<String, NameValuePair> attribmap =
                    new HashMap<String, NameValuePair>(attribs.length);
            for (int j = attribs.length - 1; j >= 0; j--) {
                NameValuePair param = attribs[j];
                attribmap.put(param.getName().toLowerCase(Locale.ENGLISH), param);
            }
            for (Map.Entry<String, NameValuePair> entry : attribmap.entrySet()) {
                NameValuePair attrib = entry.getValue();
                String s = attrib.getName().toLowerCase(Locale.ENGLISH);

                cookie.setAttribute(s, attrib.getValue());

                CookieAttributeHandler handler = findAttribHandler(s);
                if (handler != null) {
                    handler.parse(cookie, attrib.getValue());
                }
            }
            cookies.add(cookie);
        }
        return cookies;
View Full Code Here

            cookie.setDomain(getDefaultDomain(origin));

            // cycle through the parameters
            NameValuePair[] attribs = headerelement.getParameters();
            for (int j = attribs.length - 1; j >= 0; j--) {
                NameValuePair attrib = attribs[j];
                String s = attrib.getName().toLowerCase(Locale.ENGLISH);

                cookie.setAttribute(s, attrib.getValue());

                CookieAttributeHandler handler = findAttribHandler(s);
                if (handler != null) {
                    handler.parse(cookie, attrib.getValue());
                }
            }
            cookies.add(cookie);
        }
        return cookies;
View Full Code Here

        assertNotNull(elems);
        assertEquals(1, elems.length);

        HeaderElement elem = elems[0];
        assertEquals("multipart/form-data", elem.getName());
        NameValuePair p1 = elem.getParameterByName("boundary");
        assertNotNull(p1);
        assertEquals("whatever", p1.getValue());
        NameValuePair p2 = elem.getParameterByName("charset");
        assertNotNull(p2);
        assertEquals("UTF-8", p2.getValue());
    }
View Full Code Here

        assertNotNull(elems);
        assertEquals(1, elems.length);

        HeaderElement elem = elems[0];
        assertEquals("multipart/form-data", elem.getName());
        NameValuePair p1 = elem.getParameterByName("boundary");
        assertNotNull(p1);

        String boundary = p1.getValue();
        assertNotNull(boundary);

        assertTrue(boundary.length() >= 30);
        assertTrue(boundary.length() <= 40);

        NameValuePair p2 = elem.getParameterByName("charset");
        assertNull(p2);
    }
View Full Code Here

 
  @Test
  public void validateURIBuilder() throws ApplicationException {
    final String artistName = "Madonna";
    final String trackName = "Holiday";
    NameValuePair artist = new BasicNameValuePair(PARAM_ARTIST, artistName);
    NameValuePair track = new BasicNameValuePair(PARAM_TRACK, trackName);
    NameValuePair api_key = new BasicNameValuePair(PARAM_API_KEY, API_KEY);
    URI uri = new AbstractWSGetClient() {
    }.getURI(Arrays.asList(artist, track, api_key));
    String expected = HTTP + "://" + HOST + PATH
    + "?" + PARAM_ARTIST + "=" + artistName
    + "&" + PARAM_TRACK + "=" + trackName
View Full Code Here

  @Test
  public void validateURIBuilderForSpecialChars() throws ApplicationException, UnsupportedEncodingException {
    final String artistName = "Sonny & Cher";
    final String trackName = "I Got You Babe";
    NameValuePair artist = new BasicNameValuePair(PARAM_ARTIST, artistName);
    NameValuePair track = new BasicNameValuePair(PARAM_TRACK, trackName);
    NameValuePair api_key = new BasicNameValuePair(PARAM_API_KEY, API_KEY);
    URI uri = new AbstractWSGetClient() {
    }.getURI(Arrays.asList(artist, track, api_key));
    String expected = HTTP + "://" + HOST + PATH
    + "?" + PARAM_ARTIST + "=" + URLEncoder.encode(artistName, UTF8)
    + "&" + PARAM_TRACK + "=" + URLEncoder.encode(trackName, UTF8)
View Full Code Here

            for (Map.Entry<String, String> entry : definition.getPostParams().entrySet()) {
                String effectiveValue = entry.getValue();
                effectiveValue = ActionPlaceholders.substituteNode(effectiveValue, nodeAddress);
                effectiveValue = ActionPlaceholders.substituteExecution(effectiveValue, scheduleExecutionId);

                NameValuePair nameValuePair = new BasicNameValuePair(entry.getKey(), effectiveValue);
                nameValuePairs.add(nameValuePair);
            }

            HttpEntity encodedFormEntity = new UrlEncodedFormEntity(nameValuePairs, Consts.UTF_8);
            request.setEntity(encodedFormEntity);
View Full Code Here


 
  private boolean isUrlParamsEquals(URIBuilder actualUri, URIBuilder expectedUri) {
    for (final NameValuePair expectedParam : expectedUri.getQueryParams()) {
      NameValuePair actualParam = (NameValuePair) CollectionUtils.find(actualUri.getQueryParams(), new Predicate() {
       
        @Override
        public boolean evaluate(Object arg0) {
          if (!(arg0 instanceof NameValuePair))
            return false;
         
          NameValuePair otherObj = (NameValuePair) arg0;
          return otherObj.getName().equals(expectedParam.getName());
        }
      });
     

      List<String> actualParamList = new ArrayList<String>(Arrays.asList(actualParam.getValue().split(",")));
View Full Code Here

        String s = "test";
        CharArrayBuffer buffer = new CharArrayBuffer(16);
        buffer.append(s);
        ParserCursor cursor = new ParserCursor(0, s.length());
       
        NameValuePair param = parser.parseNameValuePair(buffer, cursor);
        assertEquals("test", param.getName());
        assertEquals(null, param.getValue());
        assertEquals(s.length(), cursor.getPos());
        assertTrue(cursor.atEnd());

        s = "test;";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
       
        param = parser.parseNameValuePair(buffer, cursor);
        assertEquals("test", param.getName());
        assertEquals(null, param.getValue());
        assertEquals(s.length(), cursor.getPos());
        assertTrue(cursor.atEnd());
       
        s = "test  ,12";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
       
        param = parser.parseNameValuePair(buffer, cursor);
        assertEquals("test", param.getName());
        assertEquals(null, param.getValue());
        assertEquals(s.length() - 2, cursor.getPos());
        assertFalse(cursor.atEnd());
       
        s = "test=stuff";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
       
        param = parser.parseNameValuePair(buffer, cursor);
        assertEquals("test", param.getName());
        assertEquals("stuff", param.getValue());
        assertEquals(s.length(), cursor.getPos());
        assertTrue(cursor.atEnd());
       
        s = "   test  =   stuff ";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
       
        param = parser.parseNameValuePair(buffer, cursor);
        assertEquals("test", param.getName());
        assertEquals("stuff", param.getValue());
        assertEquals(s.length(), cursor.getPos());
        assertTrue(cursor.atEnd());

        s = "   test  =   stuff ;1234";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
       
        param = parser.parseNameValuePair(buffer, cursor);
        assertEquals("test", param.getName());
        assertEquals("stuff", param.getValue());
        assertEquals(s.length() - 4, cursor.getPos());
        assertFalse(cursor.atEnd());
       
        s = "test  = \"stuff\"";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
       
        param = parser.parseNameValuePair(buffer, cursor);
        assertEquals("test", param.getName());
        assertEquals("stuff", param.getValue());
       
        s = "test  = \"  stuff\\\"\"";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
       
        param = parser.parseNameValuePair(buffer, cursor);
        assertEquals("test", param.getName());
        assertEquals("  stuff\\\"", param.getValue());
       
        s = "  test";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
       
        param = parser.parseNameValuePair(buffer, cursor);
        assertEquals("test", param.getName());
        assertEquals(null, param.getValue());

        s = "  ";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
       
        param = parser.parseNameValuePair(buffer, cursor);
        assertEquals("", param.getName());
        assertEquals(null, param.getValue());

        s = " = stuff ";
        buffer = new CharArrayBuffer(16);
        buffer.append(s);
        cursor = new ParserCursor(0, s.length());
       
        param = parser.parseNameValuePair(buffer, cursor);
        assertEquals("", param.getName());
        assertEquals("stuff", param.getValue());
    }
View Full Code Here

TOP

Related Classes of org.apache.http.NameValuePair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.