本文整理匯總了Java中org.springframework.web.util.UriUtils.decode方法的典型用法代碼示例。如果您正苦於以下問題:Java UriUtils.decode方法的具體用法?Java UriUtils.decode怎麽用?Java UriUtils.decode使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.springframework.web.util.UriUtils
的用法示例。
在下文中一共展示了UriUtils.decode方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: createRequestBuilderWithMethodAndUri
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
protected MockHttpServletRequestBuilder createRequestBuilderWithMethodAndUri(Pact.InteractionRequest request) throws Exception {
String uri = request.getUri().contains(getServletContextPathWithoutTrailingSlash())
? StringUtils.substringAfter(request.getUri(), getServletContextPathWithoutTrailingSlash())
: request.getUri();
uri = UriUtils.decode(uri, "UTF-8");
switch (request.getMethod()) {
case GET:
return get(uri);
case POST:
return post(uri);
case PUT:
return put(uri);
case DELETE:
return delete(uri);
default:
throw new RuntimeException("Unsupported method " + request.getMethod());
}
}
示例2: fileOutputStream
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
public void fileOutputStream(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String filepath = req.getRequestURI();
int index = filepath.indexOf(Global.USERFILES_BASE_URL);
if (index >= 0) {
filepath = filepath.substring(index + Global.USERFILES_BASE_URL.length());
}
try {
filepath = UriUtils.decode(filepath, "UTF-8");
} catch (UnsupportedEncodingException e1) {
logger.error(String.format("解釋文件路徑失敗,URL地址為%s", filepath), e1);
}
File file = new File(Global.getUserfilesBaseDir() + Global.USERFILES_BASE_URL + filepath);
try {
FileCopyUtils.copy(new FileInputStream(file), resp.getOutputStream());
resp.setHeader("Content-Type", "application/octet-stream");
return;
} catch (FileNotFoundException e) {
req.setAttribute("exception", new FileNotFoundException("請求的文件不存在"));
req.getRequestDispatcher("/WEB-INF/views/error/404.jsp").forward(req, resp);
}
}
示例3: getCallbackParam
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
protected final String getCallbackParam(ServerHttpRequest request) {
String query = request.getURI().getQuery();
MultiValueMap<String, String> params = UriComponentsBuilder.newInstance().query(query).build().getQueryParams();
String value = params.getFirst("c");
if (StringUtils.isEmpty(value)) {
return null;
}
try {
String result = UriUtils.decode(value, "UTF-8");
return (CALLBACK_PARAM_PATTERN.matcher(result).matches() ? result : null);
}
catch (UnsupportedEncodingException ex) {
// should never happen
throw new SockJsException("Unable to decode callback query parameter", null, ex);
}
}
示例4: fileOutputStream
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
public void fileOutputStream(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
String filepath = req.getRequestURI();
int index = filepath.indexOf(Global.USERFILES_BASE_URL);
if(index >= 0) {
filepath = filepath.substring(index + Global.USERFILES_BASE_URL.length());
}
try {
filepath = UriUtils.decode(filepath, "UTF-8");
} catch (UnsupportedEncodingException e1) {
logger.error(String.format("解釋文件路徑失敗,URL地址為%s", filepath), e1);
}
File file = new File(Global.getUserfilesBaseDir() + Global.USERFILES_BASE_URL + filepath);
try {
FileCopyUtils.copy(new FileInputStream(file), resp.getOutputStream());
resp.setHeader("Content-Type", "application/octet-stream");
return;
} catch (FileNotFoundException e) {
req.setAttribute("exception", new FileNotFoundException("請求的文件不存在"));
req.getRequestDispatcher("/WEB-INF/views/error/404.jsp").forward(req, resp);
}
}
示例5: copyQueryParams
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
void copyQueryParams(UriComponents uriComponents, MockHttpServletRequest servletRequest){
try {
if (uriComponents.getQuery() != null) {
String query = UriUtils.decode(uriComponents.getQuery(), UTF_8);
servletRequest.setQueryString(query);
}
for (Entry<String, List<String>> entry : uriComponents.getQueryParams().entrySet()) {
for (String value : entry.getValue()) {
servletRequest.addParameter(
UriUtils.decode(entry.getKey(), UTF_8),
UriUtils.decode(value, UTF_8));
}
}
}
catch (UnsupportedEncodingException ex) {
// shouldn't happen
}
}
示例6: isDescendentOrEqual
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
private static boolean isDescendentOrEqual(URL collection,
URL test) {
if(collection == null || test == null){
return false;
}
if (collection.toString().equals(test.toString())) {
return true;
}
try {
String testPathDecoded = UriUtils.decode(test.getPath(), "UTF-8");
String collectionPathDecoded = UriUtils.decode(collection.getPath(), "UTF-8");
return testPathDecoded.startsWith(collectionPathDecoded);
} catch (UnsupportedEncodingException e) {
return test.getPath().startsWith(collection.getPath());
}
}
示例7: unescapeUrlPart
import org.springframework.web.util.UriUtils; //導入方法依賴的package包/類
/**
* Unescapes an already escaped url part so the server can query the original value
*/
public static String unescapeUrlPart(String part){
if(part == null){
return null;
}
try {
return UriUtils.decode(part, "UTF-8");
}
catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return null;
}