本文整理汇总了Java中org.eclipse.jetty.util.UrlEncoded类的典型用法代码示例。如果您正苦于以下问题:Java UrlEncoded类的具体用法?Java UrlEncoded怎么用?Java UrlEncoded使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
UrlEncoded类属于org.eclipse.jetty.util包,在下文中一共展示了UrlEncoded类的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JdbcUrlConnection
import org.eclipse.jetty.util.UrlEncoded; //导入依赖的package包/类
protected JdbcUrlConnection(URL url) {
super(url);
String urlAsString = url.toString();
int position = urlAsString.indexOf("?");
if (position == -1) {
jdbcBase = urlAsString;
} else {
jdbcBase = urlAsString.substring(0, position);
String rest = urlAsString.substring(position+1);
MultiMap<String> map = new MultiMap<>();
UrlEncoded.decodeTo(rest, map, (String) null, 10);
for (Map.Entry<String, List<String>> entry : map.entrySet()) {
if (entry.getValue().size()>1) {
throw new IllegalArgumentException("parameter " + entry.getKey() + " occurs more than once");
}
jdbcProperties.put(entry.getKey(), entry.getValue().get(0));
}
}
}
示例2: sendRequest
import org.eclipse.jetty.util.UrlEncoded; //导入依赖的package包/类
private static String sendRequest(String url, Map<String, Object> data) {
if (data == null)
url = _API_ADDRESS + url;
else {
StringBuilder requestBuilder = new StringBuilder();
Set<Map.Entry<String, Object>> entrySet = data.entrySet();
for (Map.Entry<String, Object> entry : entrySet) {
String key = entry.getKey();
Object value = entry.getValue();
requestBuilder.append(key).append("=");
if (value instanceof String)
requestBuilder.append(UrlEncoded.encodeString((String) value));
else
requestBuilder.append(String.valueOf(value));
requestBuilder.append("&");
}
String request = requestBuilder.toString();
url = _API_ADDRESS + url + "?" + request.substring(0, request.length() - 1);
}
StringBuilder response = new StringBuilder();
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(new URL(url).openStream()));
String thisLine;
while ((thisLine = reader.readLine()) != null)
response.append(thisLine);
reader.close();
} catch (Exception e) {
System.err.println("exception thrown while sendRequest to " + url + " " + e);
}
return response.toString();
}
示例3: extract
import org.eclipse.jetty.util.UrlEncoded; //导入依赖的package包/类
public static Optional<String> extract(String queryString, String key) {
// Note that we cannot use the servlet parameter methods as they read the body looking for form parameters
// which prevents the body from also being read
return ofNullable(queryString).map(qs -> {
final MultiMap<String> parameters = new MultiMap<>();
UrlEncoded.decodeUtf8To(qs, parameters);
return parameters.getString(key);
});
}
示例4: getContent
import org.eclipse.jetty.util.UrlEncoded; //导入依赖的package包/类
private String getContent(String m_url, ContentTaggingRule contentTaggingRule){
try {
URL url = new URL(m_url);
int ruleType = contentTaggingRule.getRuleType();
switch (ruleType) {
case pathRuleIndex:
String path = url.getPath();
//System.out.println("--------"+path);
Pattern pattern = Pattern.compile(contentTaggingRule.getPara());
Matcher matcher = pattern.matcher(path);
if(matcher.find()){
//System.out.println("--------"+matcher.group(1));
return matcher.group(1);
}
break;
case paraRuleIndex:
String query = url.getQuery();
MultiMap<String> values = new MultiMap<String>();
UrlEncoded.decodeTo(query, values, "UTF-8", 1000);
String para = contentTaggingRule.getPara();
if(values.containsKey(para)){
return values.get(para).get(0);
}
break;
default:
break;
}
} catch (MalformedURLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return "";
}
示例5: login
import org.eclipse.jetty.util.UrlEncoded; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private LoginContext login(BufferedReader body) throws IOException, LoginException {
try {
Subject subject = new Subject();
String parametersLine = body.readLine();
// Throws UnsupportedEncodingException.
byte[] utf8Bytes = parametersLine.getBytes("UTF-8");
CharsetDecoder utf8Decoder = Charset.forName("UTF-8").newDecoder();
utf8Decoder.onMalformedInput(CodingErrorAction.IGNORE);
utf8Decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
// Throws CharacterCodingException.
CharBuffer parsed = utf8Decoder.decode(ByteBuffer.wrap(utf8Bytes));
parametersLine = parsed.toString();
UrlEncoded parameters = new UrlEncoded();
parameters.decode(parametersLine);
CallbackHandler callbackHandler = new HttpRequestBasedCallbackHandler(parameters);
LoginContext context = new LoginContext("Wave", subject, callbackHandler, configuration);
// If authentication fails, login() will throw a LoginException.
context.login();
return context;
} catch (CharacterCodingException cce) {
throw new LoginException("Character coding exception (not utf-8): "
+ cce.getLocalizedMessage());
} catch (UnsupportedEncodingException uee) {
throw new LoginException("ad character encoding specification: " + uee.getLocalizedMessage());
}
}
示例6: parseParameters
import org.eclipse.jetty.util.UrlEncoded; //导入依赖的package包/类
/**
* Parse query parameters which might be embedded in the URI double
* encoded after and @ sign.
*/
private void parseParameters() {
if (parametersAlreadyParsed) {
return;
}
parametersAlreadyParsed = true;
final String uri = overrideUri;
final int atPos = uri.indexOf("@");
if (atPos == -1) {
requestUri = overrideUri;
parameters = request.getParameterMap();
return;
}
requestUri = uri.substring(0, atPos);
final String doubleEncodedContent = uri.substring(atPos + 1);
final Charset utf8 = Charset.forName("UTF-8");
final String singleEncodedContent = UrlEncoded.decodeString(
doubleEncodedContent, 0, doubleEncodedContent.length(),
utf8);
final MultiMap<String> tempParameters = new MultiMap<String>();
UrlEncoded.decodeTo(singleEncodedContent, tempParameters, utf8, 10);
parameters = new HashMap<String, String[]>();
final Iterator<Map.Entry<String, List<String>>> iter = tempParameters
.entrySet().iterator();
while (iter.hasNext()) {
final Map.Entry<String, List<String>> e = iter.next();
final String key = e.getKey();
final List<String> valsList = e.getValue();
final String[] valsArray = new String[valsList.size()];
valsList.toArray(valsArray);
parameters.put(key, valsArray);
}
}
示例7: login
import org.eclipse.jetty.util.UrlEncoded; //导入依赖的package包/类
@SuppressWarnings("unchecked")
private LoginContext login(BufferedReader body) throws IOException, LoginException {
try {
Subject subject = new Subject();
String parametersLine = body.readLine();
// Throws UnsupportedEncodingException.
byte[] utf8Bytes = parametersLine.getBytes("UTF-8");
CharsetDecoder utf8Decoder = Charset.forName("UTF-8").newDecoder();
utf8Decoder.onMalformedInput(CodingErrorAction.IGNORE);
utf8Decoder.onUnmappableCharacter(CodingErrorAction.IGNORE);
// Throws CharacterCodingException.
CharBuffer parsed = utf8Decoder.decode(ByteBuffer.wrap(utf8Bytes));
parametersLine = parsed.toString();
MultiMap<String> parameters = new UrlEncoded(parametersLine);
CallbackHandler callbackHandler = new HttpRequestBasedCallbackHandler(parameters);
LoginContext context = new LoginContext("Wave", subject, callbackHandler, configuration);
// If authentication fails, login() will throw a LoginException.
context.login();
return context;
} catch (CharacterCodingException cce) {
throw new LoginException("Character coding exception (not utf-8): "
+ cce.getLocalizedMessage());
} catch (UnsupportedEncodingException uee) {
throw new LoginException("ad character encoding specification: " + uee.getLocalizedMessage());
}
}