本文整理汇总了Java中java.net.URLDecoder类的典型用法代码示例。如果您正苦于以下问题:Java URLDecoder类的具体用法?Java URLDecoder怎么用?Java URLDecoder使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
URLDecoder类属于java.net包,在下文中一共展示了URLDecoder类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: preHandle
import java.net.URLDecoder; //导入依赖的package包/类
public boolean preHandle(HttpServletRequest request,
HttpServletResponse response, Object handler)
throws Exception {
String uri = request.getRequestURI();
Weaver weaver = weaverService.getCurrentWeaver();
if(uri.contains("/tags:")){
String tags = uri.substring(uri.indexOf("/tags:")+6);
if(tags.contains("/"))
tags = tags.substring(0, tags.indexOf("/"));
tags = URLDecoder.decode(tags, "UTF-8");
List<String> tagList = tagService.stringToTagList(tags);
if(!tagService.validateTag(tagList, weaver)){
response.sendError(400);
return false;
}
}
return true;
}
示例2: verifyLogoutOneLogoutRequestNotAttempted
import java.net.URLDecoder; //导入依赖的package包/类
@Test
public void verifyLogoutOneLogoutRequestNotAttempted() throws Exception {
final SingleLogoutService service = new WebApplicationServiceFactory().createService(TEST_URL, SingleLogoutService.class);
final LogoutRequest logoutRequest = new DefaultLogoutRequest(TICKET_ID,
service,
new URL(TEST_URL));
final Event event = getLogoutEvent(Arrays.asList(logoutRequest));
assertEquals(FrontChannelLogoutAction.REDIRECT_APP_EVENT, event.getId());
final List<LogoutRequest> list = WebUtils.getLogoutRequests(this.requestContext);
assertEquals(1, list.size());
final String url = (String) event.getAttributes().get(FrontChannelLogoutAction.DEFAULT_FLOW_ATTRIBUTE_LOGOUT_URL);
assertTrue(url.startsWith(TEST_URL + '?' + FrontChannelLogoutAction.DEFAULT_LOGOUT_PARAMETER + '='));
final byte[] samlMessage = CompressionUtils.decodeBase64ToByteArray(
URLDecoder.decode(StringUtils.substringAfter(url, '?' + FrontChannelLogoutAction.DEFAULT_LOGOUT_PARAMETER + '='), "UTF-8"));
final Inflater decompresser = new Inflater();
decompresser.setInput(samlMessage);
final byte[] result = new byte[1000];
decompresser.inflate(result);
decompresser.end();
final String message = new String(result);
assertTrue(message.startsWith("<samlp:LogoutRequest xmlns:samlp=\"urn:oasis:names:tc:SAML:2.0:protocol\" ID=\""));
assertTrue(message.contains("<samlp:SessionIndex>" + TICKET_ID + "</samlp:SessionIndex>"));
}
示例3: createJobConfigData
import java.net.URLDecoder; //导入依赖的package包/类
public JobConfigData createJobConfigData(JSONObject formData, GlobalConfig globalConfig) {
JobConfigData firstInstanceJobConfigData = new JobConfigData();
String projectKey = formData.getString("projectKey");
if (!projectKey.startsWith("$")) {
try {
projectKey = URLDecoder.decode(projectKey, "UTF-8");
} catch (UnsupportedEncodingException e) {
throw new QGException("Error while decoding the project key. UTF-8 not supported.", e);
}
}
String name;
if (!globalConfig.fetchListOfGlobalConfigData().isEmpty()) {
name = hasFormDataKey(formData, globalConfig);
} else {
name = "";
}
firstInstanceJobConfigData.setProjectKey(projectKey);
firstInstanceJobConfigData.setSonarInstanceName(name);
return firstInstanceJobConfigData;
}
示例4: setViewport
import java.net.URLDecoder; //导入依赖的package包/类
@JSMethod(uiThread = false)
public void setViewport(String param) {
if (!TextUtils.isEmpty(param)) {
try {
param = URLDecoder.decode(param, "utf-8");
JSONObject jsObj = JSON.parseObject(param);
if (DEVICE_WIDTH.endsWith(jsObj.getString(WIDTH))) {
mWXSDKInstance.setViewPortWidth(WXViewUtils.getScreenWidth(mWXSDKInstance.getContext()));
} else {
int width = jsObj.getInteger(WIDTH);
if (width > 0) {
mWXSDKInstance.setViewPortWidth(width);
}
}
} catch (Exception e) {
WXLogUtils.e("[WXModalUIModule] alert param parse error ", e);
}
}
}
示例5: getLabelFromBuiltIn
import java.net.URLDecoder; //导入依赖的package包/类
private String getLabelFromBuiltIn(String uri) {
try {
IRI iri = IRI.create(URLDecoder.decode(uri, "UTF-8"));
// if IRI is built-in entity
if (iri.isReservedVocabulary()) {
// use the short form
String label = sfp.getShortForm(iri);
// if it is a XSD numeric data type, we attach "value"
if (uri.equals(XSD.nonNegativeInteger.getURI()) || uri.equals(XSD.integer.getURI())
|| uri.equals(XSD.negativeInteger.getURI()) || uri.equals(XSD.decimal.getURI())
|| uri.equals(XSD.xdouble.getURI()) || uri.equals(XSD.xfloat.getURI())
|| uri.equals(XSD.xint.getURI()) || uri.equals(XSD.xshort.getURI())
|| uri.equals(XSD.xbyte.getURI()) || uri.equals(XSD.xlong.getURI())) {
label += " value";
}
return label;
}
} catch (UnsupportedEncodingException e) {
logger.error("Getting short form of " + uri + "failed.", e);
}
return null;
}
示例6: verifyExporterUrlGeneration
import java.net.URLDecoder; //导入依赖的package包/类
protected <T> void verifyExporterUrlGeneration(T config, Object[][] dataTable) {
// 1. fill corresponding config with data
////////////////////////////////////////////////////////////
fillConfigs(config, dataTable, TESTVALUE1);
// 2. export service and get url parameter string from db
////////////////////////////////////////////////////////////
servConf.export();
String paramStringFromDb = getProviderParamString();
try {
paramStringFromDb = URLDecoder.decode(paramStringFromDb, "UTF-8");
} catch (UnsupportedEncodingException e) {
// impossible
}
assertUrlStringWithLocalTable(paramStringFromDb, dataTable, config.getClass().getName(), TESTVALUE1);
// 4. unexport service
////////////////////////////////////////////////////////////
servConf.unexport();
}
示例7: getUrlWithQueryString
import java.net.URLDecoder; //导入依赖的package包/类
/**
* Will encode url, if not disabled, and adds params on the end of it
*
* @param url String with URL, should be valid URL without params
* @param params RequestParams to be appended on the end of URL
* @param shouldEncodeUrl whether url should be encoded (replaces spaces with %20)
* @return encoded url if requested with params appended if any available
*/
public static String getUrlWithQueryString(boolean shouldEncodeUrl, String url, RequestParams params) {
if (url == null)
return null;
if (shouldEncodeUrl) {
try {
String decodedURL = URLDecoder.decode(url, "UTF-8");
URL _url = new URL(decodedURL);
URI _uri = new URI(_url.getProtocol(), _url.getUserInfo(), _url.getHost(), _url.getPort(), _url.getPath(), _url.getQuery(), _url.getRef());
url = _uri.toASCIIString();
} catch (Exception ex) {
// Should not really happen, added just for sake of validity
log.e(LOG_TAG, "getUrlWithQueryString encoding URL", ex);
}
}
if (params != null) {
// Construct the query string and trim it, in case it
// includes any excessive white spaces.
String paramString = params.getParamString().trim();
// Only add the query string if it isn't empty and it
// isn't equal to '?'.
if (!paramString.equals("") && !paramString.equals("?")) {
url += url.contains("?") ? "&" : "?";
url += paramString;
}
}
return url;
}
示例8: findContainingJar
import java.net.URLDecoder; //导入依赖的package包/类
/**
* Find a jar that contains a class of the same name, if any.
* It will return a jar file, even if that is not the first thing
* on the class path that has a class with the same name.
*
* @param clazz the class to find.
* @return a jar file that contains the class, or null.
* @throws IOException
*/
public static String findContainingJar(Class<?> clazz) {
ClassLoader loader = clazz.getClassLoader();
String classFile = clazz.getName().replaceAll("\\.", "/") + ".class";
try {
for(final Enumeration<URL> itr = loader.getResources(classFile);
itr.hasMoreElements();) {
final URL url = itr.nextElement();
if ("jar".equals(url.getProtocol())) {
String toReturn = url.getPath();
if (toReturn.startsWith("file:")) {
toReturn = toReturn.substring("file:".length());
}
toReturn = URLDecoder.decode(toReturn, "UTF-8");
return toReturn.replaceAll("!.*$", "");
}
}
} catch (IOException e) {
throw new RuntimeException(e);
}
return null;
}
示例9: setItemStyle
import java.net.URLDecoder; //导入依赖的package包/类
private XulHttpServerResponse setItemStyle(XulHttpServerRequest request, String[] params) {
if (params.length != 2 && params.length != 3) {
return null;
}
XulHttpServerResponse response = getResponse(request);
try {
String name = URLDecoder.decode(params[1], "utf-8");
String value = params.length > 2 ? URLDecoder.decode(params[2], "utf-8") : null;
if (_monitor.setItemStyle(XulUtils.tryParseInt(params[0]), name, value, request, response)) {
response.addHeader("Content-Type", "text/xml");
response.writeBody("<result status=\"OK\"/>");
} else {
response.setStatus(404);
}
} catch (Exception e) {
response.setStatus(501);
e.printStackTrace(new PrintStream(response.getBodyStream()));
}
return response;
}
示例10: setPostContentResultData
import java.net.URLDecoder; //导入依赖的package包/类
private void setPostContentResultData () {
final String postContentBody = this.header.getPostContentBody();
if (StringObjectUtils.isValid(postContentBody)) {
try {
final String[] postContentBodyArray = URLDecoder.decode(postContentBody, "UTF-8").split("&");
if (postContentBodyArray.length > 0) {
this.postContentResultData = new HashMap<String, String>();
}
for (String element : postContentBodyArray) {
final String[] elementArray = element.split("=");
if (elementArray.length == 2) {
this.postContentResultData.put(elementArray[0], elementArray[1]);
}
}
} catch (Exception ex) {
ES_CONSUMER_LOGGER.error("Sorry. an error occurred during parsing of post content. ("+ex.toString()+")");
}
}
}
示例11: startApplication
import java.net.URLDecoder; //导入依赖的package包/类
@Override
public StartingInfo startApplication(String appName) {
CloudApplication app = getApplication(appName);
if (app.getState() != CloudApplication.AppState.STARTED) {
HashMap<String, Object> appRequest = new HashMap<String, Object>();
appRequest.put("state", CloudApplication.AppState.STARTED);
HttpEntity<Object> requestEntity = new HttpEntity<Object>(appRequest);
ResponseEntity<String> entity = getRestTemplate().exchange(getUrl("/v2/apps/{guid}?stage_async=true"), HttpMethod.PUT,
requestEntity, String.class, app.getMeta().getGuid());
HttpHeaders headers = entity.getHeaders();
// Return a starting info, even with a null staging log value, as a non-null starting info
// indicates that the response entity did have headers. The API contract is to return starting info
// if there are headers in the response, null otherwise.
if (headers != null && !headers.isEmpty()) {
String stagingFile = headers.getFirst("x-app-staging-log");
if (stagingFile != null) {
try {
stagingFile = URLDecoder.decode(stagingFile, "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.error("unexpected inability to UTF-8 decode", e);
}
}
// Return the starting info even if decoding failed or staging file is null
return new StartingInfo(stagingFile);
}
}
return null;
}
示例12: getCookieValue
import java.net.URLDecoder; //导入依赖的package包/类
/**
* 得到Cookie的值,
*
* @param request
* @param cookieName
* @return
*/
public static String getCookieValue(HttpServletRequest request, String cookieName, String encodeString) {
Cookie[] cookieList = request.getCookies();
if (cookieList == null || cookieName == null) {
return null;
}
String retValue = null;
try {
for (int i = 0; i < cookieList.length; i++) {
if (cookieList[i].getName().equals(cookieName)) {
retValue = URLDecoder.decode(cookieList[i].getValue(), encodeString);
break;
}
}
} catch (UnsupportedEncodingException e) {
e.printStackTrace();
}
return retValue;
}
示例13: sign
import java.net.URLDecoder; //导入依赖的package包/类
private String sign(TreeMap<String, String> dynamicMap) {
String url = getHttpUrl().url().toString();
//url = url.replaceAll("%2F", "/");
StringBuilder sb = new StringBuilder("POST");
sb.append(url);
for (Map.Entry<String, String> entry : dynamicMap.entrySet()) {
sb.append(entry.getKey()).append("=").append(entry.getValue()).append("&");
}
sb.append(AppConstant.APP_SECRET);
String signStr = sb.toString();
try {
signStr = URLDecoder.decode(signStr, UTF8.name());
} catch (UnsupportedEncodingException exception) {
exception.printStackTrace();
}
HttpLog.i(signStr);
return MD5.encode(signStr);
}
示例14: getOrderFields
import java.net.URLDecoder; //导入依赖的package包/类
public static Map<String, String> getOrderFields(HttpServletRequest req, String statusCode,
FieldsConfig fc) {
if (req == null || statusCode == null || statusCode.isEmpty() || fc == null || fc.isEmpty()) {
return null;
}
Map<String, String> map = new HashMap<>();
List<FieldsConfig.Field> fields = fc.getByStatus(statusCode);
for (FieldsConfig.Field f : fields) {
String key = f.getId();
String val = req.getParameter(key);
if (val != null) {
try {
val = URLDecoder.decode(val, "UTF-8").trim();
} catch (UnsupportedEncodingException e) {
xLogger.warn("Unsupported encoding exception: {0}", e.getMessage());
}
if (val.isEmpty()) {
val = null;
}
map.put(key, val);
}
} // end while
return map;
}
示例15: scanImpl
import java.net.URLDecoder; //导入依赖的package包/类
private void scanImpl(final String packageName, final ClassLoader classLoader) throws IOException {
final Enumeration<URL> resources = classLoader.getResources(packageName.replace('.', '/'));
while (resources.hasMoreElements()) {
final URL url = resources.nextElement();
final String protocol = url.getProtocol();
if (protocol.equals("file")) {
checkDirectory(classLoader, new File(URLDecoder.decode(url.getPath(), "UTF-8")), packageName);
} else if (protocol.equals("jar")) {
checkJarFile(classLoader, url, packageName);
} else {
throw new IllegalArgumentException("Unrecognized classpath protocol: " + protocol);
}
}
}