本文整理汇总了Java中org.apache.commons.httpclient.methods.PostMethod.addParameter方法的典型用法代码示例。如果您正苦于以下问题:Java PostMethod.addParameter方法的具体用法?Java PostMethod.addParameter怎么用?Java PostMethod.addParameter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.methods.PostMethod
的用法示例。
在下文中一共展示了PostMethod.addParameter方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: chcekConnectionStatus
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void chcekConnectionStatus() throws IOException {
HttpClient httpClient = new HttpClient();
//TODO : add connection details while testing only,remove it once done
String teradatajson = "{\"username\":\"\",\"password\":\"\",\"hostname\":\"\",\"database\":\"\",\"dbtype\":\"\",\"port\":\"\"}";
PostMethod postMethod = new PostMethod("http://" + HOST_NAME + ":" + PORT + "/getConnectionStatus");
//postMethod.addParameter("request_parameters", redshiftjson);
postMethod.addParameter("request_parameters", teradatajson);
int response = httpClient.executeMethod(postMethod);
InputStream inputStream = postMethod.getResponseBodyAsStream();
byte[] buffer = new byte[1024 * 1024 * 5];
String path = null;
int length;
while ((length = inputStream.read(buffer)) > 0) {
path = new String(buffer);
}
System.out.println("Response of service: " + path);
System.out.println("==================");
}
示例2: calltoReadService
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void calltoReadService() throws IOException {
HttpClient httpClient = new HttpClient();
PostMethod postMethod = new PostMethod("http://" + HOST_NAME + ":" + PORT + "/read");
postMethod.addParameter("jobId", JOB_ID);
postMethod.addParameter("componentId", COMPONENT_ID);
postMethod.addParameter("socketId", SOCKET_ID);
postMethod.addParameter("basePath", BASE_PATH);
postMethod.addParameter("userId", USER_ID);
postMethod.addParameter("password", PASSWORD);
postMethod.addParameter("file_size", FILE_SIZE_TO_READ);
postMethod.addParameter("host_name", HOST_NAME);
InputStream inputStream = postMethod.getResponseBodyAsStream();
byte[] buffer = new byte[1024 * 1024 * 5];
String path = null;
int length;
while ((length = inputStream.read(buffer)) > 0) {
path = new String(buffer);
}
System.out.println("response of service: " + path);
}
示例3: toPostMethod
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
/**
* Returns result POST method.<br/>
* Result POST method is composed by baseURL + action (if baseURL is not null).<br/>
* All parameters are set and encoded.
* At least one of the parameter has to be not null and the string has to start with 'http'.
*
* @return new instance of HttpMethod with POST request
* @throws BuildMethodException if something goes wrong
*/
public HttpMethod toPostMethod() throws BuildMethodException {
if (referer != null)
client.setReferer(referer);
String s = generateURL();
if (encodePathAndQuery)
try {
s = URIUtil.encodePathQuery(s, encoding);
} catch (URIException e) {
throw new BuildMethodException("Cannot create URI");
}
s = checkURI(s);
final PostMethod postMethod = client.getPostMethod(s);
for (Map.Entry<String, String> entry : parameters.entrySet()) {
postMethod.addParameter(entry.getKey(), (encodeParameters) ? encode(entry.getValue()) : entry.getValue());
}
setAdditionalHeaders(postMethod);
return postMethod;
}
示例4: getDebugFileMethod
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
/**
*
* Get post method to get csv debug file
*
* @param jobDetails
* @param fileSize
* @return {@link PostMethod}
* @throws NumberFormatException
* @throws MalformedURLException
*/
public PostMethod getDebugFileMethod(JobDetails jobDetails,String fileSize) throws NumberFormatException, MalformedURLException {
URL url = new URL(POST_PROTOCOL, getHost(jobDetails), getPortNo(jobDetails), DebugServiceMethods.GET_DEBUG_FILE_PATH);
PostMethod postMethod = new PostMethod(url.toString());
postMethod.addParameter(DebugServicePostParameters.JOB_ID, jobDetails.getUniqueJobID());
postMethod.addParameter(DebugServicePostParameters.COMPONENT_ID, jobDetails.getComponentID());
postMethod.addParameter(DebugServicePostParameters.SOCKET_ID, jobDetails.getComponentSocketID());
postMethod.addParameter(DebugServicePostParameters.BASE_PATH, jobDetails.getBasepath());
postMethod.addParameter(DebugServicePostParameters.USER_ID, jobDetails.getUsername());
postMethod.addParameter(DebugServicePostParameters.DEBUG_SERVICE_PWD, jobDetails.getPassword());
postMethod.addParameter(DebugServicePostParameters.FILE_SIZE, fileSize);
postMethod.addParameter(DebugServicePostParameters.HOST_NAME, getHost(jobDetails));
LOGGER.debug("Calling debug service to get csv debug file from url :: "+url);
return postMethod;
}
示例5: calltoReadMetastore
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void calltoReadMetastore() throws IOException {
HttpClient httpClient = new HttpClient();
//TODO : add connection details while testing only,remove it once done
String teradatajson = "{\"table\":\"testting2\",\"username\":\"\",\"password\":\"\",\"hostname\":\"\",\"database\":\"\",\"dbtype\":\"\",\"port\":\"\"}";
PostMethod postMethod = new PostMethod("http://" + HOST_NAME + ":" + PORT + "/readFromMetastore");
//postMethod.addParameter("request_parameters", redshiftjson);
postMethod.addParameter("request_parameters", teradatajson);
int response = httpClient.executeMethod(postMethod);
InputStream inputStream = postMethod.getResponseBodyAsStream();
byte[] buffer = new byte[1024 * 1024 * 5];
String path = null;
int length;
while ((length = inputStream.read(buffer)) > 0) {
path = new String(buffer);
}
System.out.println("Response of service: " + path);
System.out.println("==================");
}
示例6: testSetRootProperty
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void testSetRootProperty() throws Exception {
String url = HTTP_BASE_URL;
if(!url.endsWith("/")) {
url += "/";
}
final PostMethod post = new PostMethod(url);
final String name = getClass().getSimpleName();
final String value = getClass().getSimpleName() + System.currentTimeMillis();
post.addParameter(name, value);
final int status = httpClient.executeMethod(post);
assertEquals(200, status);
final String json = getContent(url + ".json", CONTENT_TYPE_JSON);
assertJavascript(value, json, "out.print(data." + name + ")");
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:17,代码来源:PostToRootTest.java
示例7: runTest
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
private void runTest(String acceptHeaderValue, boolean useHttpEquiv, String expectedContentType) throws Exception {
final String info = (useHttpEquiv ? "Using http-equiv parameter" : "Using Accept header") + ": ";
final String url = HTTP_BASE_URL + MY_TEST_PATH;
final PostMethod post = new PostMethod(url);
post.setFollowRedirects(false);
if(acceptHeaderValue != null) {
if(useHttpEquiv) {
post.addParameter(":http-equiv-accept", acceptHeaderValue);
} else {
post.addRequestHeader("Accept", acceptHeaderValue);
}
}
final int status = httpClient.executeMethod(post) / 100;
assertEquals(info + "Expected status 20x for POST at " + url, 2, status);
final Header h = post.getResponseHeader("Content-Type");
assertNotNull(info + "Expected Content-Type header", h);
final String ct = h.getValue();
assertTrue(info + "Expected Content-Type '" + expectedContentType + "' for Accept header=" + acceptHeaderValue
+ " but got '" + ct + "'",
ct.startsWith(expectedContentType));
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:24,代码来源:PostServletOutputContentTypeTest.java
示例8: testJsonContentTypeException
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void testJsonContentTypeException() throws Exception {
// Perform a POST that fails: invalid PostServlet operation
// with Accept header set to JSON
final String url = HTTP_BASE_URL + MY_TEST_PATH;
final PostMethod post = new PostMethod(url);
post.setFollowRedirects(false);
post.addParameter(new NameValuePair(
SlingPostConstants.RP_OPERATION,
"InvalidTestOperationFor" + getClass().getSimpleName()));
post.addRequestHeader("Accept", CONTENT_TYPE_JSON);
final int status = httpClient.executeMethod(post);
assertEquals(500, status);
final String contentType = post.getResponseHeader("Content-Type").getValue();
final String expected = CONTENT_TYPE_JSON;
assertTrue("Expecting content-type " + expected + " for failed POST request, got " + contentType,
contentType!=null && contentType.startsWith(expected));
}
开发者ID:apache,项目名称:sling-org-apache-sling-launchpad-integration-tests,代码行数:20,代码来源:PostServletOutputContentTypeTest.java
示例9: addParameters
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
/**
* Parses content and search for parameter's value in tag form.<br />
* Html <code><form></code> should have structure <code>name="paramName" .... value="paramValue"</code></br>
* This parameter and its value are added to POST method.
*
* @param postMethod method to add found parameters
* @param content <code>String</code> to search in
* @param parameters form parameter names
* @throws PluginImplementationException any of the parameter were not found in given content
* @see cz.vity.freerapid.plugins.webclient.utils.PlugUtils#getParameter(String, String)
*/
public static void addParameters(final PostMethod postMethod, final String content, final String[] parameters) throws PluginImplementationException {
if (parameters.length == 0)
throw new IllegalArgumentException("You have to provide some parameter names");
final Set<String> set = new HashSet<String>(parameters.length);
set.addAll(Arrays.asList(parameters));
initParameterPatterns();
int start = 0;
Matcher matcher = parameterInputPattern.matcher(content);
while (matcher.find(start)) {
final String input = matcher.group(1);
final Matcher matchName = parameterNamePattern.matcher(input);
if (matchName.find()) {
String paramName = getCorrectGroup(matchName);
if (set.contains(paramName)) {
final Matcher matchValue = parameterValuePattern.matcher(input);
String paramValue = "";
if (matchValue.find()) {
paramValue = getCorrectGroup(matchValue);
}
set.remove(paramName);
postMethod.addParameter(paramName, paramValue);
if (set.isEmpty())
break;
}
}
start = matcher.end();
}
if (!set.isEmpty()) {
throw new PluginImplementationException("The parameters " + Arrays.toString(set.toArray()) + " were not found");
}
}
示例10: getDeleteDebugFileMethod
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
/**
*
* Get post method to delete csv debug file
*
* @param jobDetails
* @return {@link PostMethod}
* @throws NumberFormatException
* @throws MalformedURLException
*/
public PostMethod getDeleteDebugFileMethod(JobDetails jobDetails) throws NumberFormatException, MalformedURLException {
URL url = new URL(POST_PROTOCOL, getHost(jobDetails), getPortNo(jobDetails), DebugServiceMethods.DELETE_DEBUG_CSV_FILE);
PostMethod postMethod = new PostMethod(url.toString());
postMethod.addParameter(DebugServicePostParameters.JOB_ID, jobDetails.getUniqueJobID());
postMethod.addParameter(DebugServicePostParameters.COMPONENT_ID, jobDetails.getComponentID());
postMethod.addParameter(DebugServicePostParameters.SOCKET_ID, jobDetails.getComponentSocketID());
LOGGER.debug("Calling debug service for deleting csv debug file url :: "+url);
return postMethod;
}
示例11: getDeleteBasePathFileMethod
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
/**
*
* Get post method to delete basepath debug files
*
* @param host
* @param port
* @param unique job ID
* @param base path
* @param User
* @param password
* @param isRemote
* @return {@link PostMethod}
* @throws NumberFormatException
* @throws MalformedURLException
*/
public PostMethod getDeleteBasePathFileMethod(String host, String port, String uniqJobID, String basePath, String user, String password, boolean isRemote
) throws NumberFormatException, MalformedURLException {
if (isRemote) {
port =PlatformUI.getPreferenceStore().getString(PreferenceConstants.REMOTE_PORT_NO);
if(StringUtils.isBlank(port)){
port = PreferenceConstants.DEFAULT_PORT_NO;
}
if (PlatformUI.getPreferenceStore().getBoolean(PreferenceConstants.USE_REMOTE_CONFIGURATION)) {
host = PlatformUI.getPreferenceStore().getString(PreferenceConstants.REMOTE_HOST);
}
}
URL url = new URL(POST_PROTOCOL, host, Integer.valueOf(port), DebugServiceMethods.DELETE_BASEPATH_FILES);
PostMethod postMethod = new PostMethod(url.toString());
postMethod.addParameter(DebugServicePostParameters.JOB_ID, uniqJobID);
postMethod.addParameter(DebugServicePostParameters.BASE_PATH, basePath);
postMethod.addParameter(DebugServicePostParameters.USER_ID, user);
postMethod.addParameter(DebugServicePostParameters.DEBUG_SERVICE_PWD, password);
LOGGER.debug("Calling debug service to delete basepath debug files through url :: "+url);
return postMethod;
}
示例12: getFilteredFileMethod
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
/**
* Method to get file based on the filter condition
* @param jsonString Filter condition string
* @param jobDetails
* @return
* @throws NumberFormatException
* @throws MalformedURLException
*/
public PostMethod getFilteredFileMethod(String jsonString,JobDetails jobDetails) throws NumberFormatException, MalformedURLException {
URL url = new URL(POST_PROTOCOL,getHost(jobDetails),getPortNo(jobDetails), DebugServiceMethods.GET_FILTERED_FILE_PATH);
PostMethod postMethod = new PostMethod(url.toString());
postMethod.addParameter(DebugServicePostParameters.FILTER_JSON_OBJECT,jsonString);
LOGGER.debug("Calling debug service to get file based on the filter condition through url :: "+url);
return postMethod;
}
示例13: readMetaDataMethod
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
/**
* Method to get hive table details
* @param jsonString Db name and table details
* @param jobDetails
* @param userCredentials
* @return
* @throws NumberFormatException
* @throws MalformedURLException
*/
public PostMethod readMetaDataMethod(MetaDataDetails metaDataDetails, String host, String port) throws NumberFormatException, MalformedURLException {
URL url = new URL(POST_PROTOCOL,host,Integer.valueOf(port),DebugServiceMethods.READ_METASTORE);
PostMethod postMethod = new PostMethod(url.toString());
Gson gson = new Gson();
postMethod.addParameter(DebugServicePostParameters.REQUEST_PARAMETERS, gson.toJson(metaDataDetails) );
LOGGER.debug("Calling Metadata service to get Metadata details through url :: "+url);
return postMethod;
}
示例14: getConnectionStatus
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public PostMethod getConnectionStatus(MetaDataDetails metaDataDetails, String host, String port) throws NumberFormatException, MalformedURLException {
URL url = new URL(POST_PROTOCOL,host,Integer.valueOf(port),DebugServiceMethods.TEST_CONNECTION);
PostMethod postMethod = new PostMethod(url.toString());
Gson gson = new Gson();
postMethod.addParameter(DebugServicePostParameters.REQUEST_PARAMETERS, gson.toJson(metaDataDetails) );
LOGGER.debug("Calling service to test connection for database components through url :: "+url);
return postMethod;
}
示例15: calltoFilterService
import org.apache.commons.httpclient.methods.PostMethod; //导入方法依赖的package包/类
public void calltoFilterService() throws IOException {
HttpClient httpClient = new HttpClient();
// String json =
// "{\"condition\":\"abc\",\"schema\":[{\"fieldName\":\"f1\",\"dateFormat\":\"\",\"dataType\":\"1\",\"scale\":\"scale\",\"dataTypeValue\":\"java.lang.String\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f2\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.util.Date\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f3\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.util.Date\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f4\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.math.BigDecimal\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"}],\"fileSize\":1,\"jobDetails\":{\"host\":\"127.0.0.1\",\"port\":\"8005\",\"username\":\"hduser\",\"password\":\"Bitwise2012\",\"basepath\":\"C:/Users/santlalg/git/Hydrograph/hydrograph.engine/hydrograph.engine.command-line\",\"uniqueJobID\":\"debug_job\",\"componentID\":\"input\",\"componentSocketID\":\"out0\",\"isRemote\":false}}";
String json = "{\"condition\":\"(f1 LIKE 'should')\",\"schema\":[{\"fieldName\":\"f1\",\"dateFormat\":\"\",\"dataType\":\"1\",\"scale\":\"scale\",\"dataTypeValue\":\"java.lang.String\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f2\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.util.Date\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f3\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.lang.Float\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"},{\"fieldName\":\"f4\",\"dateFormat\":\"\",\"dataType\":1,\"scale\":\"scale\",\"dataTypeValue\":\"java.lang.Double\",\"scaleType\":1,\"scaleTypeValue\":\"scaleTypeValue\",\"precision\":\"precision\",\"description\":\"description\"}],\"fileSize\":"
+ FILE_SIZE_TO_READ + ",\"jobDetails\":{\"host\":\"" + HOST_NAME + "\",\"port\":\"" + PORT
+ "\",\"username\":\"" + USER_ID + "\",\"password\":\"" + PASSWORD + "\",\"basepath\":\"" + BASE_PATH
+ "\",\"uniqueJobID\":\"" + JOB_ID + "\",\"componentID\":\"" + COMPONENT_ID
+ "\",\"componentSocketID\":\"" + SOCKET_ID + "\",\"isRemote\":false}}";
PostMethod postMethod = new PostMethod("http://" + HOST_NAME + ":" + PORT + "/filter");
postMethod.addParameter("request_parameters", json);
int response = httpClient.executeMethod(postMethod);
InputStream inputStream = postMethod.getResponseBodyAsStream();
byte[] buffer = new byte[1024 * 1024 * 5];
String path = null;
int length;
while ((length = inputStream.read(buffer)) > 0) {
path = new String(buffer);
}
System.out.println("response of service: " + path);
}