本文整理汇总了Java中org.apache.commons.httpclient.util.URIUtil.encodePathQuery方法的典型用法代码示例。如果您正苦于以下问题:Java URIUtil.encodePathQuery方法的具体用法?Java URIUtil.encodePathQuery怎么用?Java URIUtil.encodePathQuery使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.util.URIUtil
的用法示例。
在下文中一共展示了URIUtil.encodePathQuery方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: toPostMethod
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的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;
}
示例2: getMethodData
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
/**
* Get InputStream for the GET method for the given path.
*
* @param path the server relative path of the resource to get
* @return InputStream
* @exception HttpException
* @exception IOException
*/
public InputStream getMethodData(String path)
throws HttpException, IOException {
setClient();
GetMethod method = new GetMethod(URIUtil.encodePathQuery(path));
generateTransactionHeader(method);
client.executeMethod(method);
int statusCode = method.getStatusLine().getStatusCode();
setStatusCode(statusCode);
if(statusCode >= 200 && statusCode < 300)
return method.getResponseBodyAsStream();
else
throw new IOException("Couldn't get file");
}
示例3: putMethod
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
/**
* Execute the PUT method for the given path.
*
* @param path the server relative path to put the data
* @param data The byte array.
* @return true if the method is succeeded.
* @exception HttpException
* @exception IOException
*/
public boolean putMethod(String path, byte[] data)
throws HttpException, IOException {
setClient();
PutMethod method = new PutMethod(URIUtil.encodePathQuery(path));
generateIfHeader(method);
if (getGetContentType() != null && !getGetContentType().equals(""))
method.setRequestHeader("Content-Type", getGetContentType());
method.setRequestHeader("Content-Length", String.valueOf(data.length));
method.setRequestBody(new ByteArrayInputStream(data));
generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
return (statusCode >= 200 && statusCode < 300) ? true : false;
}
示例4: toGetMethod
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
/**
* Returns result GET method.<br/>
* Result GET method is composed by baseURL + action (if baseURL is not null).<br/>
* 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 GET request
* @throws BuildMethodException if something goes wrong
*/
public HttpMethod toGetMethod() throws BuildMethodException {
if (referer != null)
client.setReferer(referer);
String uri = generateURL();
if (!parameters.isEmpty()) {
final StringBuilder builder = new StringBuilder(uri);
if (!uri.contains("?"))
builder.append('?');
for (Map.Entry<String, String> entry : parameters.entrySet()) {
final char lastChar = builder.charAt(builder.length() - 1);
if (lastChar != '&' && lastChar != '?' && lastChar != '/')
builder.append('&');
builder.append(entry.getKey()).append('=');
if (!encodeParameters)
builder.append(entry.getValue());
else
builder.append(encode(entry.getValue()));
}
uri = builder.toString();
}
String s;
try {
s = (encodePathAndQuery) ? URIUtil.encodePathQuery(uri, encoding) : uri;
} catch (URIException e) {
throw new BuildMethodException("Cannot create URI");
}
uri = checkURI(s);
HttpMethod getMethod = client.getGetMethod(uri);
setAdditionalHeaders(getMethod);
return getMethod;
}
示例5: encodeUri
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
public static String encodeUri(String uri) {
try {
return URIUtil.encodePathQuery(uri);
} catch (URIException ex) {
throw new EsHadoopIllegalArgumentException("Cannot escape uri" + uri);
}
}
示例6: getConfiguration
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
@Override
protected FilesDownloadConfig_V1 getConfiguration() throws DPUConfigException {
List<VfsFile> vfsFiles = new ArrayList<>();
if (isContainerValid(true)) {
try {
for (Object itemId : container.getItemIds()) {
VfsFile vfsFile = new VfsFile((VfsFile) itemId);
URI uri = new URI(URIUtil.encodePathQuery(URIUtil.decode(vfsFile.getUri(), "utf8"), "utf8"));
vfsFile.setUri(uri.toString());
vfsFiles.add(vfsFile);
}
} catch (Exception e) {
throw new DPUConfigException(ctx.tr("FilesDownloadVaadinDialog.getConfiguration.exception"), e);
}
}
FilesDownloadConfig_V1 result = new FilesDownloadConfig_V1();
result.setVfsFiles(vfsFiles);
if (!txtDefaultTimeout.isValid()) {
throw new DPUConfigException(ctx.tr("FilesDownloadVaadinDialog.getConfiguration.invalid"));
}
result.setDefaultTimeout(defaultTimeout.getValue());
result.setIgnoreTlsErrors(ignoreTlsErrors.getValue());
result.setSoftFail(chkSoftFail.getValue());
result.setCheckForDuplicatedInputFiles(chkCheckDuplicates.getValue());
if (!txtWaitBetweenCallsMs.isValid()) {
throw new DPUConfigException(ctx.tr("FilesDownloadVaadinDialog.getConfiguration.invalid"));
}
result.setWaitBetweenCallsMs(waitBeetweenCallsMs.getValue());
return result;
}
示例7: encode
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
private String encode(String url) {
url = Val.chkStr(url);
try {
return URIUtil.encodePathQuery(URIUtil.decode(url, "UTF-8"), "UTF-8");
} catch (URIException ex) {
return url;
}
}
示例8: encodeUri
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
/**
* Splits the given string on the first '?' then encodes the first half as a path (ignoring slashes and colons)
* and the second half as a query segment (ignoring questionmarks, equals signs, etc...).
*
* @deprecated Prefer to use {@link HttpEncodingTools#encode(String)} instead for encoding specific
* pieces of the URI. This method does not escape certain reserved characters, like '/', ':', '=', and '?'.
* As such, this is not safe to use on URIs that may contain these reserved characters in the wrong places.
*/
@Deprecated
public static String encodeUri(String uri) {
try {
return URIUtil.encodePathQuery(uri);
} catch (URIException ex) {
throw new EsHadoopIllegalArgumentException("Cannot escape uri [" + uri + "]", ex);
}
}
示例9: getMethodDataAsString
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
/**
* Get data as a String for the GET method for the given path.
*
* @param path the server relative path of the resource to get
* @return the contents of the given resource as a string
* @exception HttpException
* @exception IOException
*/
public String getMethodDataAsString(String path)
throws HttpException, IOException {
setClient();
GetMethod method = new GetMethod(URIUtil.encodePathQuery(path));
generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
return method.getResponseBodyAsString();
}
示例10: getMethod
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
/**
* Execute the GET method for the given path.
*
* @param path the server relative path of the resource to get
* @param file The local file.
* @return true if the method is succeeded.
* @exception HttpException
* @exception IOException
*/
public boolean getMethod(String path, File file)
throws HttpException, IOException {
setClient();
GetMethod method = new GetMethod(URIUtil.encodePathQuery(path));
generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
// get the file only if status is any kind of OK
if (statusCode >= 200 && statusCode < 300) {
// Do a simple little loop to read the response back into the passed
// file parameter.
InputStream inStream = method.getResponseBodyAsStream();
FileOutputStream fos = new FileOutputStream(file);
byte buffer[] = new byte[65535];
int bytesRead;
while ((bytesRead = inStream.read(buffer)) >= 0) {
fos.write(buffer, 0, bytesRead);
}
inStream.close();
fos.close();
return true;
} else {
return false;
}
}
示例11: headMethod
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
/**
* Execute the HEAD method for the given path.
*
* @param path the server relative path of the resource to request
* @return true if the method is succeeded.
* @exception HttpException
* @exception IOException
*/
public boolean headMethod(String path)
throws HttpException, IOException {
setClient();
HeadMethod method = new HeadMethod(URIUtil.encodePathQuery(path));
generateTransactionHeader(method);
int statusCode = client.executeMethod(method);
setStatusCode(statusCode);
return (statusCode >= 200 && statusCode < 300) ? true : false;
}