Java Code Examples for org.apache.commons.httpclient.NameValuePair#getValue()
The following examples show how to use
org.apache.commons.httpclient.NameValuePair#getValue() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: RFC2965Spec.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Parse RFC 2965 specific cookie attribute and update the corresponsing * {@link org.apache.commons.httpclient.Cookie} properties. * * @param attribute {@link org.apache.commons.httpclient.NameValuePair} cookie attribute from the * <tt>Set-Cookie2</tt> header. * @param cookie {@link org.apache.commons.httpclient.Cookie} to be updated * @throws MalformedCookieException if an exception occurs during parsing */ public void parseAttribute( final NameValuePair attribute, final Cookie cookie) throws MalformedCookieException { if (attribute == null) { throw new IllegalArgumentException("Attribute may not be null."); } if (attribute.getName() == null) { throw new IllegalArgumentException("Attribute Name may not be null."); } if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null."); } final String paramName = attribute.getName().toLowerCase(); final String paramValue = attribute.getValue(); CookieAttributeHandler handler = findAttribHandler(paramName); if (handler == null) { // ignore unknown attribute-value pairs if (LOG.isDebugEnabled()) LOG.debug("Unrecognized cookie attribute: " + attribute.toString()); } else { handler.parse(cookie, paramValue); } }
Example 2
Source File: EncodingUtil.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 6 votes |
/** * Form-urlencoding routine. * * The default encoding for all forms is `application/x-www-form-urlencoded'. * A form data set is represented in this media type as follows: * * The form field names and values are escaped: space characters are replaced * by `+', and then reserved characters are escaped as per [URL]; that is, * non-alphanumeric characters are replaced by `%HH', a percent sign and two * hexadecimal digits representing the ASCII code of the character. Line breaks, * as in multi-line text field values, are represented as CR LF pairs, i.e. `%0D%0A'. * * @param pairs the values to be encoded * @param charset the character set of pairs to be encoded * * @return the urlencoded pairs * @throws UnsupportedEncodingException if charset is not supported * * @since 2.0 final */ private static String doFormUrlEncode(NameValuePair[] pairs, String charset) throws UnsupportedEncodingException { StringBuffer buf = new StringBuffer(); for (int i = 0; i < pairs.length; i++) { URLCodec codec = new URLCodec(); NameValuePair pair = pairs[i]; if (pair.getName() != null) { if (i > 0) { buf.append("&"); } buf.append(codec.encode(pair.getName(), charset)); buf.append("="); if (pair.getValue() != null) { buf.append(codec.encode(pair.getValue(), charset)); } } } return buf.toString(); }
Example 3
Source File: FlexGetMethod.java From flex-blazeds with Apache License 2.0 | 6 votes |
protected String getContentCharSet(Header contentheader) { String charset = null; if (contentheader != null) { HeaderElement values[] = contentheader.getElements(); if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { charset = param.getValue(); } } } if (charset == null) { charset = "UTF-8"; } return charset; }
Example 4
Source File: FlexPostMethod.java From flex-blazeds with Apache License 2.0 | 6 votes |
protected String getContentCharSet(Header contentheader) { String charset = null; if (contentheader != null) { HeaderElement values[] = contentheader.getElements(); if (values.length == 1) { NameValuePair param = values[0].getParameterByName("charset"); if (param != null) { charset = param.getValue(); } } } if (charset == null) { charset = "UTF-8"; } return charset; }
Example 5
Source File: RegionsApiUtil.java From cloudstack with Apache License 2.0 | 6 votes |
/** * Builds parameters string with command and encoded param values * @param command * @param params * @return */ protected static String buildParams(String command, List<NameValuePair> params) { StringBuffer paramString = new StringBuffer("command=" + command); Iterator<NameValuePair> iter = params.iterator(); try { while (iter.hasNext()) { NameValuePair param = iter.next(); if (param.getValue() != null && !(param.getValue().isEmpty())) { paramString.append("&" + param.getName() + "=" + URLEncoder.encode(param.getValue(), "UTF-8")); } } } catch (UnsupportedEncodingException e) { s_logger.error(e.getMessage()); return null; } return paramString.toString(); }
Example 6
Source File: PaymentServiceProviderBean.java From development with Apache License 2.0 | 5 votes |
/** * Checks all present name value pairs for the existence of an entry with * name FRONTEND.REDIRECT_URL. The found entry will be returned, null if * there is none. * * @param result * The list of name value pairs to search in. * @return The redirect URL, null if it is not set. */ private String getRedirectURL(List<NameValuePair> result) { String redirectURL = null; for (NameValuePair nvp : result) { if (HeidelpayPostParameter.FRONTEND_REDIRECT_URL.equals(nvp .getName())) { redirectURL = nvp.getValue(); break; } } return redirectURL; }
Example 7
Source File: PaymentServiceProviderBeanTest.java From development with Apache License 2.0 | 5 votes |
private void validateDeregistrationXMLResponse(PaymentInfo pi, NameValuePair[] requestBodyDetails, String pspPaymentTypeId) throws ParserConfigurationException, SAXException, IOException, XPathExpressionException { NameValuePair nameValuePair = requestBodyDetails[0]; String value = nameValuePair.getValue(); System.out.println(value); Document doc = XMLConverter.convertToDocument(value, true); Assert.assertEquals("1.0", XMLConverter.getNodeTextContentByXPath(doc, "/Request/@version")); Assert.assertEquals("securitySender", XMLConverter .getNodeTextContentByXPath(doc, "/Request/Header/Security/@sender")); Assert.assertEquals("INTEGRATOR_TEST", XMLConverter .getNodeTextContentByXPath(doc, "/Request/Transaction/@mode")); Assert.assertEquals("txnChannel", XMLConverter.getNodeTextContentByXPath(doc, "/Request/Transaction/@channel")); Assert.assertEquals("SYNC", XMLConverter.getNodeTextContentByXPath(doc, "/Request/Transaction/@response")); Assert.assertEquals("userLogin", XMLConverter .getNodeTextContentByXPath(doc, "/Request/Transaction/User/@login")); Assert.assertEquals("userPwd", XMLConverter.getNodeTextContentByXPath( doc, "/Request/Transaction/User/@pwd")); Assert.assertEquals( String.valueOf(pi.getKey()), XMLConverter .getNodeTextContentByXPath(doc, "/Request/Transaction/Identification/TransactionID/text()")); Assert.assertEquals( "externalId", XMLConverter .getNodeTextContentByXPath(doc, "/Request/Transaction/Identification/ReferenceID/text()")); Assert.assertEquals(pspPaymentTypeId + ".DR", XMLConverter .getNodeTextContentByXPath(doc, "/Request/Transaction/Payment/@code")); }
Example 8
Source File: NetscapeDraftSpec.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Parse the cookie attribute and update the corresponsing {@link Cookie} * properties as defined by the Netscape draft specification * * @param attribute {@link NameValuePair} cookie attribute from the * <tt>Set- Cookie</tt> * @param cookie {@link Cookie} to be updated * @throws MalformedCookieException if an exception occurs during parsing */ public void parseAttribute( final NameValuePair attribute, final Cookie cookie) throws MalformedCookieException { if (attribute == null) { throw new IllegalArgumentException("Attribute may not be null."); } if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null."); } final String paramName = attribute.getName().toLowerCase(); final String paramValue = attribute.getValue(); if (paramName.equals("expires")) { if (paramValue == null) { throw new MalformedCookieException( "Missing value for expires attribute"); } try { DateFormat expiryFormat = new SimpleDateFormat( "EEE, dd-MMM-yyyy HH:mm:ss z", Locale.US); Date date = expiryFormat.parse(paramValue); cookie.setExpiryDate(date); } catch (ParseException e) { throw new MalformedCookieException("Invalid expires " + "attribute: " + e.getMessage()); } } else { super.parseAttribute(attribute, cookie); } }
Example 9
Source File: RFC2109Spec.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Return a name/value string suitable for sending in a <tt>"Cookie"</tt> * header as defined in RFC 2109 for backward compatibility with cookie * version 0 * @param buffer The string buffer to use for output * @param param The parameter. * @param version The cookie version */ private void formatParam(final StringBuffer buffer, final NameValuePair param, int version) { if (version < 1) { buffer.append(param.getName()); buffer.append("="); if (param.getValue() != null) { buffer.append(param.getValue()); } } else { this.formatter.format(buffer, param); } }
Example 10
Source File: StringRequestEntity.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Creates a new entity with the given content, content type, and charset. * * @param content The content to set. * @param contentType The type of the content, or <code>null</code>. The value retured * by {@link #getContentType()}. If this content type contains a charset and the charset * parameter is null, the content's type charset will be used. * @param charset The charset of the content, or <code>null</code>. Used to convert the * content to bytes. If the content type does not contain a charset and charset is not null, * then the charset will be appended to the content type. */ public StringRequestEntity(String content, String contentType, String charset) throws UnsupportedEncodingException { super(); if (content == null) { throw new IllegalArgumentException("The content cannot be null"); } this.contentType = contentType; this.charset = charset; // resolve the content type and the charset if (contentType != null) { HeaderElement[] values = HeaderElement.parseElements(contentType); NameValuePair charsetPair = null; for (int i = 0; i < values.length; i++) { if ((charsetPair = values[i].getParameterByName("charset")) != null) { // charset found break; } } if (charset == null && charsetPair != null) { // use the charset from the content type this.charset = charsetPair.getValue(); } else if (charset != null && charsetPair == null) { // append the charset to the content type this.contentType = contentType + "; charset=" + charset; } } if (this.charset != null) { this.content = content.getBytes(this.charset); } else { this.content = content.getBytes(); } }
Example 11
Source File: ParameterFormatter.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Produces textual representaion of the attribute/value pair using * formatting rules defined in RFC 2616 * * @param buffer output buffer * @param param the parameter to be formatted */ public void format(final StringBuffer buffer, final NameValuePair param) { if (buffer == null) { throw new IllegalArgumentException("String buffer may not be null"); } if (param == null) { throw new IllegalArgumentException("Parameter may not be null"); } buffer.append(param.getName()); String value = param.getValue(); if (value != null) { buffer.append("="); formatValue(buffer, value, this.alwaysUseQuotes); } }
Example 12
Source File: CookieSpecBase.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Parse the cookie attribute and update the corresponsing {@link Cookie} * properties. * * @param attribute {@link HeaderElement} cookie attribute from the * <tt>Set- Cookie</tt> * @param cookie {@link Cookie} to be updated * @throws MalformedCookieException if an exception occurs during parsing */ public void parseAttribute( final NameValuePair attribute, final Cookie cookie) throws MalformedCookieException { if (attribute == null) { throw new IllegalArgumentException("Attribute may not be null."); } if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null."); } final String paramName = attribute.getName().toLowerCase(); String paramValue = attribute.getValue(); if (paramName.equals("path")) { if ((paramValue == null) || (paramValue.trim().equals(""))) { paramValue = "/"; } cookie.setPath(paramValue); cookie.setPathAttributeSpecified(true); } else if (paramName.equals("domain")) { if (paramValue == null) { throw new MalformedCookieException( "Missing value for domain attribute"); } if (paramValue.trim().equals("")) { throw new MalformedCookieException( "Blank value for domain attribute"); } cookie.setDomain(paramValue); cookie.setDomainAttributeSpecified(true); } else if (paramName.equals("max-age")) { if (paramValue == null) { throw new MalformedCookieException( "Missing value for max-age attribute"); } int age; try { age = Integer.parseInt(paramValue); } catch (NumberFormatException e) { throw new MalformedCookieException ("Invalid max-age " + "attribute: " + e.getMessage()); } cookie.setExpiryDate( new Date(System.currentTimeMillis() + age * 1000L)); } else if (paramName.equals("secure")) { cookie.setSecure(true); } else if (paramName.equals("comment")) { cookie.setComment(paramValue); } else if (paramName.equals("expires")) { if (paramValue == null) { throw new MalformedCookieException( "Missing value for expires attribute"); } try { cookie.setExpiryDate(DateUtil.parseDate(paramValue, this.datepatterns)); } catch (DateParseException dpe) { LOG.debug("Error parsing cookie date", dpe); throw new MalformedCookieException( "Unable to parse expiration date parameter: " + paramValue); } } else { if (LOG.isDebugEnabled()) { LOG.debug("Unrecognized cookie attribute: " + attribute.toString()); } } }
Example 13
Source File: RFC2109Spec.java From knopflerfish.org with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * Parse RFC 2109 specific cookie attribute and update the corresponsing * {@link Cookie} properties. * * @param attribute {@link NameValuePair} cookie attribute from the * <tt>Set- Cookie</tt> * @param cookie {@link Cookie} to be updated * @throws MalformedCookieException if an exception occurs during parsing */ public void parseAttribute( final NameValuePair attribute, final Cookie cookie) throws MalformedCookieException { if (attribute == null) { throw new IllegalArgumentException("Attribute may not be null."); } if (cookie == null) { throw new IllegalArgumentException("Cookie may not be null."); } final String paramName = attribute.getName().toLowerCase(); final String paramValue = attribute.getValue(); if (paramName.equals("path")) { if (paramValue == null) { throw new MalformedCookieException( "Missing value for path attribute"); } if (paramValue.trim().equals("")) { throw new MalformedCookieException( "Blank value for path attribute"); } cookie.setPath(paramValue); cookie.setPathAttributeSpecified(true); } else if (paramName.equals("version")) { if (paramValue == null) { throw new MalformedCookieException( "Missing value for version attribute"); } try { cookie.setVersion(Integer.parseInt(paramValue)); } catch (NumberFormatException e) { throw new MalformedCookieException("Invalid version: " + e.getMessage()); } } else { super.parseAttribute(attribute, cookie); } }