本文整理汇总了Java中org.apache.commons.httpclient.NameValuePair类的典型用法代码示例。如果您正苦于以下问题:Java NameValuePair类的具体用法?Java NameValuePair怎么用?Java NameValuePair使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
NameValuePair类属于org.apache.commons.httpclient包,在下文中一共展示了NameValuePair类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: removeParameter
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
/**
* Removes all parameters with the given paramName. If there is more than
* one parameter with the given paramName, all of them are removed. If
* there is just one, it is removed. If there are none, then the request
* is ignored.
*
* @param paramName The parameter name to remove.
*
* @return true if at least one parameter was removed
*
* @throws IllegalArgumentException When the parameter name passed is null
*
* @since 2.0
*/
public boolean removeParameter(String paramName)
throws IllegalArgumentException {
LOG.trace("enter PostMethod.removeParameter(String)");
if (paramName == null) {
throw new IllegalArgumentException(
"Argument passed to removeParameter(String) cannot be null");
}
boolean removed = false;
Iterator iter = this.params.iterator();
while (iter.hasNext()) {
NameValuePair pair = (NameValuePair) iter.next();
if (paramName.equals(pair.getName())) {
iter.remove();
removed = true;
}
}
return removed;
}
示例2: toString
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
/**
* 将NameValuePairs数组转变为字符串
*
* @param nameValues
* @return
*/
protected String toString(NameValuePair[] nameValues) {
if (nameValues == null || nameValues.length == 0) {
return "null";
}
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < nameValues.length; i++) {
NameValuePair nameValue = nameValues[i];
if (i == 0) {
buffer.append(nameValue.getName() + "=" + nameValue.getValue());
} else {
buffer.append("&" + nameValue.getName() + "=" + nameValue.getValue());
}
}
return buffer.toString();
}
示例3: testUpdateUserResponseAsJSON
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
/**
* Test for SLING-1677
*/
@Test
public void testUpdateUserResponseAsJSON() throws IOException, JsonException {
testUserId = H.createTestUser();
String postUrl = HttpTest.HTTP_BASE_URL + "/system/userManager/user/" + testUserId + ".update.json";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair("displayName", "My Updated Test User"));
postParams.add(new NameValuePair("url", "http://www.apache.org/updated"));
Credentials creds = new UsernamePasswordCredentials(testUserId, "testPwd");
String json = H.getAuthenticatedPostContent(creds, postUrl, HttpTest.CONTENT_TYPE_JSON, postParams, HttpServletResponse.SC_OK);
//make sure the json response can be parsed as a JSON object
JsonObject jsonObj = JsonUtil.parseObject(json);
assertNotNull(jsonObj);
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:20,代码来源:UpdateUserTest.java
示例4: toString
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
/**
* 将NameValuePairs数组转变为字符串
*
* @param nameValues
* @return
*/
protected String toString(NameValuePair[] nameValues) {
if (nameValues == null || nameValues.length == 0) {
return "null";
}
StringBuffer buffer = new StringBuffer();
for (int i = 0; i < nameValues.length; i++) {
NameValuePair nameValue = nameValues[i];
if (i == 0) {
buffer.append(nameValue.getName() + "=" + nameValue.getValue());
} else {
buffer.append("&" + nameValue.getName() + "=" + nameValue.getValue());
}
}
return buffer.toString();
}
示例5: formatCookie
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
/**
* Return a string suitable for sending in a <tt>"Cookie"</tt> header as
* defined in RFC 2965
* @param cookie a {@link org.apache.commons.httpclient.Cookie} to be formatted as string
* @return a string suitable for sending in a <tt>"Cookie"</tt> header.
*/
public String formatCookie(final Cookie cookie) {
LOG.trace("enter RFC2965Spec.formatCookie(Cookie)");
if (cookie == null) {
throw new IllegalArgumentException("Cookie may not be null");
}
if (cookie instanceof Cookie2) {
Cookie2 cookie2 = (Cookie2) cookie;
int version = cookie2.getVersion();
final StringBuffer buffer = new StringBuffer();
this.formatter.format(buffer, new NameValuePair("$Version", Integer.toString(version)));
buffer.append("; ");
doFormatCookie2(cookie2, buffer);
return buffer.toString();
} else {
// old-style cookies are formatted according to the old rules
return this.rfc2109.formatCookie(cookie);
}
}
示例6: initPostParametersForReRegistration
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
/**
* Initializes the parameters required for the POST call to the PSP for
* re-registration..
*
* @param paymentInfo
* The current payment information object.
* @param paymentType
* The payment type the iframe should be pre-configured for.
* @param supplierId
* Supplier context
* @return The properties required for the connection to the PSP in order to
* register the credit card or direct debit.
*/
private List<NameValuePair> initPostParametersForReRegistration(
RequestData data) {
List<NameValuePair> regParams = new ArrayList<NameValuePair>();
setBasicPostParameters(regParams, data);
// operation code for re-registration, we use credit card as default.
regParams.add(new NameValuePair(HeidelpayPostParameter.PAYMENT_CODE,
getHeidelPayPaymentType(data.getPaymentTypeId()) + ".RR"));
// also set the already stored reference id
regParams.add(new NameValuePair(
HeidelpayPostParameter.IDENTIFICATION_REFERENCEID, data
.getExternalIdentifier()));
initGeneralRegistrationPostData(regParams, data);
return regParams;
}
示例7: setWPFControlParameters
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
/**
* Sets the parameters required to enable the WPF
*
* @param regParams
* The list of name value pairs the WPF control parameters will
* be added to.
*/
private void setWPFControlParameters(RequestData data,
List<NameValuePair> regParams) {
regParams.add(new NameValuePair(
HeidelpayPostParameter.FRONTEND_ENABLED, "true"));
regParams.add(new NameValuePair(HeidelpayPostParameter.FRONTEND_POPUP,
"false"));
regParams.add(new NameValuePair(HeidelpayPostParameter.FRONTEND_MODE,
"DEFAULT"));
regParams.add(new NameValuePair(
HeidelpayPostParameter.FRONTEND_LANGUAGE, data
.getCurrentUserLocale()));
regParams.add(new NameValuePair(
HeidelpayPostParameter.FRONTEND_ONEPAGE, "true"));
regParams.add(new NameValuePair(
HeidelpayPostParameter.FRONTEND_NEXT_TARGET,
"self.location.href"));
}
示例8: testRemoveAce
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
public void testRemoveAce() throws IOException, JsonException {
String folderUrl = createFolderWithAces(false);
//remove the ace for the testUser principal
String postUrl = folderUrl + ".deleteAce.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":applyTo", testUserId));
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
//fetch the JSON for the acl to verify the settings.
String getUrl = folderUrl + ".acl.json";
String json = getAuthenticatedContent(creds, getUrl, CONTENT_TYPE_JSON, null, HttpServletResponse.SC_OK);
assertNotNull(json);
JsonObject jsonObject = JsonUtil.parseObject(json);
assertNotNull(jsonObject);
assertEquals(0, jsonObject.size());
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:21,代码来源:RemoveAcesTest.java
示例9: determineReregistrationLink
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
@Override
public RegistrationLink determineReregistrationLink(RequestData data)
throws PSPCommunicationException {
if (data == null) {
throw new IllegalArgumentException("requestData must not be null!");
}
setProxyForHTTPClient(data);
List<NameValuePair> registrationParameters = initPostParametersForReRegistration(data);
String regLinkDetails = retrieveRegistrationLinkDetails(
registrationParameters, data);
String result = validateLinkDetails(regLinkDetails);
RegistrationLink link = new RegistrationLink(result, "");
return link;
}
示例10: testRemoveAuthorizables
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
public void testRemoveAuthorizables() throws IOException {
String userId = createTestUser();
String groupId = createTestGroup();
Credentials creds = new UsernamePasswordCredentials("admin", "admin");
String getUrl = HTTP_BASE_URL + "/system/userManager/user/" + userId + ".json";
assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
getUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".json";
assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_OK, null); //make sure the profile request returns some data
String postUrl = HTTP_BASE_URL + "/system/userManager.delete.html";
List<NameValuePair> postParams = new ArrayList<NameValuePair>();
postParams.add(new NameValuePair(":applyTo", "group/" + groupId));
postParams.add(new NameValuePair(":applyTo", "user/" + userId));
assertAuthenticatedPostStatus(creds, postUrl, HttpServletResponse.SC_OK, postParams, null);
getUrl = HTTP_BASE_URL + "/system/userManager/user/" + userId + ".json";
assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_NOT_FOUND, null); //make sure the profile request returns some data
getUrl = HTTP_BASE_URL + "/system/userManager/group/" + groupId + ".json";
assertAuthenticatedHttpStatus(creds, getUrl, HttpServletResponse.SC_NOT_FOUND, null); //make sure the profile request returns some data
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:25,代码来源:RemoveAuthorizablesTest.java
示例11: getParameter
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
/**
* Gets the parameter of the specified name. If there exists more than one
* parameter with the name paramName, then only the first one is returned.
*
* @param paramName name of the parameter
*
* @return If a parameter exists with the name argument, the coresponding
* NameValuePair is returned. Otherwise null.
*
* @since 2.0
*
*/
public NameValuePair getParameter(String paramName) {
LOG.trace("enter PostMethod.getParameter(String)");
if (paramName == null) {
return null;
}
Iterator iter = this.params.iterator();
while (iter.hasNext()) {
NameValuePair parameter = (NameValuePair) iter.next();
if (paramName.equals(parameter.getName())) {
return parameter;
}
}
return null;
}
示例12: extractParams
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
/**
* Extracts a map of challenge parameters from an authentication challenge.
* Keys in the map are lower-cased
*
* @param challengeStr the authentication challenge string
* @return a map of authentication challenge parameters
* @throws MalformedChallengeException when the authentication challenge string
* is malformed
*
* @since 2.0beta1
*/
public static Map extractParams(final String challengeStr)
throws MalformedChallengeException {
if (challengeStr == null) {
throw new IllegalArgumentException("Challenge may not be null");
}
int idx = challengeStr.indexOf(' ');
if (idx == -1) {
throw new MalformedChallengeException("Invalid challenge: " + challengeStr);
}
Map map = new HashMap();
ParameterParser parser = new ParameterParser();
List params = parser.parse(
challengeStr.substring(idx + 1, challengeStr.length()), ',');
for (int i = 0; i < params.size(); i++) {
NameValuePair param = (NameValuePair) params.get(i);
map.put(param.getName().toLowerCase(), param.getValue());
}
return map;
}
示例13: deregisterPaymentInformation_CreditCard
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
@Test
public void deregisterPaymentInformation_CreditCard()
throws PaymentDeregistrationException, XPathExpressionException,
ParserConfigurationException, SAXException, IOException {
// setup
RequestData requestData = createRequestData(CREDIT_CARD);
PostMethodStub.setStubReturnValue(sampleResponse);
PaymentInfo pi = createPaymentInfo(
PaymentCollectionType.PAYMENT_SERVICE_PROVIDER,
PaymentInfoType.CREDIT_CARD.name());
pi.setKey(2L);
// execute
psp.deregisterPaymentInformation(requestData);
// assert
NameValuePair[] requestBodyDetails = PostMethodStub
.getRequestBodyDetails();
Assert.assertNotNull("A request must have been generated",
requestBodyDetails);
Assert.assertEquals("Wrong number of parameters for the request", 1,
requestBodyDetails.length);
validateDeregistrationXMLResponse(pi, requestBodyDetails, "CC");
}
示例14: deregisterPaymentInformation_DirectDebit
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
@Test
public void deregisterPaymentInformation_DirectDebit()
throws PaymentDeregistrationException, XPathExpressionException,
ParserConfigurationException, SAXException, IOException {
// setup
RequestData requestData = createRequestData(DIRECT_DEBIT);
PostMethodStub.setStubReturnValue(sampleResponse);
PaymentInfo pi = createPaymentInfo(
PaymentCollectionType.PAYMENT_SERVICE_PROVIDER,
PaymentInfoType.CREDIT_CARD.name());
pi.setKey(2L);
// execute
psp.deregisterPaymentInformation(requestData);
// assert
NameValuePair[] requestBodyDetails = PostMethodStub
.getRequestBodyDetails();
Assert.assertNotNull("A request must have been generated",
requestBodyDetails);
Assert.assertEquals("Wrong number of parameters for the request", 1,
requestBodyDetails.length);
validateDeregistrationXMLResponse(pi, requestBodyDetails, "DD");
}
示例15: testValidatingCorrectFormCredentials
import org.apache.commons.httpclient.NameValuePair; //导入依赖的package包/类
@Test
public void testValidatingCorrectFormCredentials() throws Exception {
List<NameValuePair> params = new ArrayList<NameValuePair>();
params.add(new NameValuePair("j_username", "admin"));
params.add(new NameValuePair("j_password", "admin"));
params.add(new NameValuePair("j_validate", "true"));
HttpMethod post = H.assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_OK,
params, null);
assertTrue(post.getResponseBodyAsString().length() == 0);
List<NameValuePair> params2 = new ArrayList<NameValuePair>();
params2.add(new NameValuePair("j_validate", "true"));
HttpMethod post2 = H.assertPostStatus(HttpTest.HTTP_BASE_URL + "/j_security_check", HttpServletResponse.SC_OK,
params2, null);
assertTrue(post2.getResponseBodyAsString().length() == 0);
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:17,代码来源:AuthenticationResponseCodeTest.java