本文整理汇总了Java中org.apache.commons.httpclient.util.URIUtil.decode方法的典型用法代码示例。如果您正苦于以下问题:Java URIUtil.decode方法的具体用法?Java URIUtil.decode怎么用?Java URIUtil.decode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.apache.commons.httpclient.util.URIUtil
的用法示例。
在下文中一共展示了URIUtil.decode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getDecodedPath
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
/**
* Parse and decode the path component from the given request.
* @param request Http request to parse
* @param servletName the name of servlet that precedes the path
* @return decoded path component, null if UTF-8 is not supported
*/
public static String getDecodedPath(final HttpServletRequest request, String servletName) {
try {
return URIUtil.decode(getRawPath(request, servletName), "UTF-8");
} catch (URIException e) {
throw new AssertionError("JVM does not support UTF-8"); // should never happen!
}
}
示例2: testEncodeWithinQuery
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
public void testEncodeWithinQuery() {
//TODO: There was an unmappable character for encoding UTF8. YAGNI?
String unescaped1= "abc123+ %_?=&#.";
try {
String stringRet = URIUtil.encodeWithinQuery(unescaped1);
assertEquals("abc123%2B%20%25_%3F%3D%26%23.%C3%A4", stringRet);
stringRet = URIUtil.decode(stringRet);
assertEquals(unescaped1, stringRet);
} catch(Exception e) {
System.err.println("Exception thrown: "+e);
}
}
示例3: convertUriToDecodedString
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
/**
* Utility function used to convert a given URI to a decoded string
* representation sent to the backing store. URIs coming as input
* to this class will be encoded by the URI class, and we want
* the underlying storage to store keys in their original UTF-8 form.
*/
private static String convertUriToDecodedString(URI uri) {
try {
String result = URIUtil.decode(uri.toString());
return result;
} catch (URIException e) {
throw new AssertionError("Failed to decode URI: " + uri.toString());
}
}
示例4: testQueryParams
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
public void testQueryParams() throws Exception {
GetMethod get = new GetMethod("/");
String ru_msg = constructString(RUSSIAN_STUFF_UNICODE);
String ch_msg = constructString(SWISS_GERMAN_STUFF_UNICODE);
get.setQueryString(new NameValuePair[] {
new NameValuePair("ru", ru_msg),
new NameValuePair("ch", ch_msg)
});
Map params = new HashMap();
StringTokenizer tokenizer = new StringTokenizer(
get.getQueryString(), "&");
while (tokenizer.hasMoreTokens()) {
String s = tokenizer.nextToken();
int i = s.indexOf('=');
assertTrue("Invalid url-encoded parameters", i != -1);
String name = s.substring(0, i).trim();
String value = s.substring(i + 1, s.length()).trim();
value = URIUtil.decode(value, CHARSET_UTF8);
params.put(name, value);
}
assertEquals(ru_msg, params.get("ru"));
assertEquals(ch_msg, params.get("ch"));
}
示例5: testUrlEncodedRequestBody
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
public void testUrlEncodedRequestBody() throws Exception {
PostMethod httppost = new PostMethod("/");
String ru_msg = constructString(RUSSIAN_STUFF_UNICODE);
String ch_msg = constructString(SWISS_GERMAN_STUFF_UNICODE);
httppost.setRequestBody(new NameValuePair[] {
new NameValuePair("ru", ru_msg),
new NameValuePair("ch", ch_msg)
});
httppost.setRequestHeader("Content-Type", PostMethod.FORM_URL_ENCODED_CONTENT_TYPE
+ "; charset=" + CHARSET_UTF8);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
httppost.getRequestEntity().writeRequest(bos);
Map params = new HashMap();
StringTokenizer tokenizer = new StringTokenizer(
new String(bos.toByteArray(), CHARSET_UTF8), "&");
while (tokenizer.hasMoreTokens()) {
String s = tokenizer.nextToken();
int i = s.indexOf('=');
assertTrue("Invalid url-encoded parameters", i != -1);
String name = s.substring(0, i).trim();
String value = s.substring(i + 1, s.length()).trim();
value = URIUtil.decode(value, CHARSET_UTF8);
params.put(name, value);
}
assertEquals(ru_msg, params.get("ru"));
assertEquals(ch_msg, params.get("ch"));
}
示例6: decode
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
public static String decode(String encoded) {
try {
return URIUtil.decode(encoded, CharEncoding.UTF_8);
} catch (URIException e) {
throw RaptureExceptionFactory.create(String.format("Error decoding step name %s:", encoded), e);
}
}
示例7: decodePath
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
public static String decodePath(String path) {
try {
return URIUtil.decode(path, "UTF-8");
} catch (URIException ex) {
throw new EsHadoopIllegalArgumentException("Cannot encode path" + path, ex);
}
}
示例8: AuthenticatedWebdavResource
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
protected AuthenticatedWebdavResource(HttpURL url, String authCookieName,
String authCookieValue)
throws HttpException, IOException
{
super (URIUtil.decode(url.getEscapedURI()),
new TokenCredentials(authCookieName, authCookieValue),
true);
}
示例9: getLinkout
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
@GET
@Path("linkoutdata/{linkout}")
@Produces(MediaType.APPLICATION_JSON)
public Collection<LinkoutData> getLinkout(@PathParam("linkout") String linkout) throws JSONException, IOException {
String expandedURL = URIUtil.decode(linkout);
expandedURL = expandUrl(expandedURL);
expandedURL = URIUtil.decode(expandedURL);;
expandedURL = URIUtil.encodeQuery(expandedURL);
List<LinkoutData> infoOnLinkout = new ArrayList<LinkoutData>();
JSONArray lineItems = readJSONFeed(expandedURL);
for (int i = 0; i < lineItems.length(); ++i) {
JSONObject tempItem = lineItems.getJSONObject(i);
JSONObject tempSource = tempItem.getJSONObject("an");
String source = tempSource.getString("value");
LinkoutData info = new LinkoutData();
info.an = source;
tempSource = tempItem.getJSONObject("body");
source = tempSource.getString("value");
info.body = source;
tempSource = tempItem.getJSONObject("target");
source = tempSource.getString("value");
info.target = source;
tempSource = tempItem.getJSONObject("sourceURL");
source = tempSource.getString("value");
info.sourceURL = source;
tempSource = tempItem.getJSONObject("selector");
source = tempSource.getString("value");
info.selector = source;
tempSource = tempItem.getJSONObject("spl");
source = tempSource.getString("value");
info.spl = source;
tempSource = tempItem.getJSONObject("text");
source = tempSource.getString("value");
info.text = source;
infoOnLinkout.add(info);
}
return infoOnLinkout;
}
示例10: testEncodeWithinQuery
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
public void testEncodeWithinQuery() {
String unescaped1= "abc123+ %_?=&#.�";
try {
String stringRet = URIUtil.encodeWithinQuery(unescaped1);
assertEquals("abc123%2B%20%25_%3F%3D%26%23.%C3%A4", stringRet);
stringRet = URIUtil.decode(stringRet);
assertEquals(unescaped1, stringRet);
} catch(Exception e) {
System.err.println("Exception thrown: "+e);
}
}
示例11: getHref
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
private String getHref(Response response) {
String href = response.getHref();
if (this.decodeResponseHrefs != null) {
try {
href = URIUtil.decode(href, this.decodeResponseHrefs);
}
catch (URIException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
return href;
}
示例12: getName
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
public String getName() {
if(relPath!=null)
return relPath;
String escapedPath = httpUrl.getEscapedPath();
String escapedName =
URIUtil.getName(escapedPath.endsWith("/")
? escapedPath.substring(0, escapedPath.length() - 1)
: escapedPath);
try {
return URIUtil.decode(escapedName);
} catch (URIException e) {
return escapedName;
}
}
示例13: getParent
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
public String getParent() {
if(relPath!=null)
return null;
String escapedPath = httpUrl.getEscapedPath();
String parent = escapedPath.substring(
0, escapedPath.lastIndexOf('/', escapedPath.length() - 2) + 1);
if (parent.length() <= 1)
return null;
try {
return URIUtil.decode(parent);
} catch (URIException e) {
return parent;
}
}
示例14: getName
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
private static String getName(String uri) {
String escapedName = URIUtil.getName(
uri.endsWith("/") ? uri.substring(0, uri.length() - 1): uri);
try {
return URIUtil.decode(escapedName);
} catch (URIException e) {
return escapedName;
}
}
示例15: verifyURLSignature
import org.apache.commons.httpclient.util.URIUtil; //导入方法依赖的package包/类
/**
* 校验一下URL上的签名信息,确认这个请求来自敏行的服务器
*
* @param queryString
* url的query String部分,例如 http://g.com?abc=1&de=2 的url,query
* string 为abc=1&de=2
* @param securet
* ocu或者app的 securet。
* @return true 如果签名被认证。
*/
public boolean verifyURLSignature(String queryString, String secret) {
String signed = null;
String timestamp = null;
String nonce = null;
String mx_sso_token = null;
String login_name = null;
String qstring = queryString;
if (queryString.startsWith("http://")
|| queryString.startsWith("https://")) {
qstring = URIUtil.getQuery(queryString);
}
ParameterParser pp = new ParameterParser();
@SuppressWarnings("unchecked")
List<NameValuePair> list = (List<NameValuePair>) pp.parse(qstring, '&');
try {
for (NameValuePair np : list) {
if (np.getName().equals("timestamp")) {
timestamp = URIUtil.decode(np.getValue());
continue;
}
if (np.getName().equals("nonce")) {
nonce = URIUtil.decode(np.getValue());
continue;
}
if (np.getName().equals("login_name")) {
login_name = URIUtil.decode(np.getValue());
continue;
}
if (np.getName().equals("mx_sso_token")) {
mx_sso_token = URIUtil.decode(np.getValue());
continue;
}
if (np.getName().equals("signed")) {
signed = URIUtil.decode(np.getValue());
continue;
}
}
} catch (URIException e) {
throw new MxException("Query string not valid:" + queryString, e);
}
StringBuilder sb = new StringBuilder();
sb.append(timestamp).append(":").append(nonce).append(":")
.append(login_name).append(":").append(mx_sso_token);
String t = HMACSHA1.getSignature(sb.toString(), secret);
return t.equals(signed);
}