本文整理汇总了Java中org.eclipse.jetty.util.MultiMap类的典型用法代码示例。如果您正苦于以下问题:Java MultiMap类的具体用法?Java MultiMap怎么用?Java MultiMap使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
MultiMap类属于org.eclipse.jetty.util包,在下文中一共展示了MultiMap类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: JdbcUrlConnection
import org.eclipse.jetty.util.MultiMap; //导入依赖的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: testUserRequired_PreserveQueryParams
import org.eclipse.jetty.util.MultiMap; //导入依赖的package包/类
public void testUserRequired_PreserveQueryParams() throws Exception {
String path = "/user/blah";
Request request = new Request(null, null);
// request.setServerPort(9999);
HttpURI uri =new HttpURI("http", SERVER_NAME,9999, path,"foo=baqr","foo=bar","foo=barff");
HttpFields httpf = new HttpFields();
MetaData.Request metadata = new MetaData.Request("GET", uri, HttpVersion.HTTP_2, httpf);
request.setMetaData(metadata);
MultiMap<String> queryParameters = new MultiMap<> ();
queryParameters.add("ffo", "bar");
request.setQueryParameters(queryParameters);
request = spy(request);
/// request.setAuthority(SERVER_NAME,9999);
request.setQueryString("foo=bar");
Response response = mock(Response.class);
String output = runRequest2(path, request, response);
// Verify that the servlet never was run (there is no output).
assertEquals("", output);
// Verify that the request was redirected to the login url.
String loginUrl = UserServiceFactory.getUserService()
.createLoginURL(String.format("http://%s%s?foo=bar", SERVER_NAME + ":9999", path));
verify(response).sendRedirect(loginUrl);
}
开发者ID:GoogleCloudPlatform,项目名称:appengine-java-vm-runtime,代码行数:26,代码来源:AppEngineAuthenticationTest.java
示例3: queryParameters
import org.eclipse.jetty.util.MultiMap; //导入依赖的package包/类
@Signature
public Memory queryParameters() {
request.getParameterMap();
MultiMap<String> parameters = request.getQueryParameters();
if (parameters != null) {
ArrayMemory result = ArrayMemory.createHashed(parameters.size());
for (Map.Entry<String, List<String>> entry : parameters.entrySet()) {
List<String> value = entry.getValue();
if (value == null || value.isEmpty()) {
result.putAsKeyString(entry.getKey(), Memory.NULL);
} else if (value.size() == 1) {
result.putAsKeyString(entry.getKey(), StringMemory.valueOf(value.get(0)));
} else {
result.putAsKeyString(entry.getKey(), ArrayMemory.ofStringCollection(value));
}
}
return result;
} else {
return new ArrayMemory().toConstant();
}
}
示例4: extract
import org.eclipse.jetty.util.MultiMap; //导入依赖的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);
});
}
示例5: getContent
import org.eclipse.jetty.util.MultiMap; //导入依赖的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 "";
}
示例6: getUriQueryParameters
import org.eclipse.jetty.util.MultiMap; //导入依赖的package包/类
private static Map<String, List<String>> getUriQueryParameters(URI uri) {
MultiMap<String> queryParameters = new MultiMap<>();
new HttpURI(uri).decodeQueryTo(queryParameters);
// Do a deep copy so we do not leak Jetty classes outside
Map<String, List<String>> deepCopiedQueryParameters = new HashMap<>();
for (Map.Entry<String, List<String>> entry : queryParameters.entrySet()) {
deepCopiedQueryParameters.put(entry.getKey(), new ArrayList<>(entry.getValue()));
}
return deepCopiedQueryParameters;
}
示例7: verifyCredentials
import org.eclipse.jetty.util.MultiMap; //导入依赖的package包/类
/**
* Verifies user credentials.
*
* @param oldPassword the password to verify.
* @param participantId the participantId of the user.
* @throws LoginException if the user provided incorrect password.
*/
private void verifyCredentials(String password, ParticipantId participantId)
throws LoginException {
MultiMap<String> parameters = new MultiMap<String>();
parameters.put("password", password);
parameters.put("address", participantId.getAddress());
CallbackHandler callbackHandler = new HttpRequestBasedCallbackHandler(parameters);
LoginContext context = new LoginContext("Wave", new Subject(), callbackHandler, configuration);
// If authentication fails, login() will throw a LoginException.
context.login();
}
示例8: testBindsUsernameAndPassword
import org.eclipse.jetty.util.MultiMap; //导入依赖的package包/类
public void testBindsUsernameAndPassword() throws IOException, UnsupportedCallbackException {
MultiMap<String> args = new MultiMap<String>();
args.add("address", "[email protected]");
args.add("password", "internet");
CallbackHandler handler = new HttpRequestBasedCallbackHandler(args);
Callback[] callbacks =
new Callback[] {new NameCallback("ignored"), new PasswordCallback("ignored", false),};
handler.handle(callbacks);
assertEquals("[email protected]", ((NameCallback) callbacks[0]).getName());
assertEquals("internet", new String(((PasswordCallback) callbacks[1]).getPassword()));
}
示例9: testCallbackThrowsHandlingUnsupportedCallback
import org.eclipse.jetty.util.MultiMap; //导入依赖的package包/类
public void testCallbackThrowsHandlingUnsupportedCallback() throws IOException {
CallbackHandler handler = new HttpRequestBasedCallbackHandler(new MultiMap<String>());
try {
handler.handle(new Callback[] {new Callback() {}});
fail("Should have thrown due to unsupported callback");
} catch (UnsupportedCallbackException e) {
// Pass.
}
}
示例10: parseParameters
import org.eclipse.jetty.util.MultiMap; //导入依赖的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);
}
}
示例11: checkAndStartSession
import org.eclipse.jetty.util.MultiMap; //导入依赖的package包/类
private boolean checkAndStartSession(Request request, HttpServletResponse response) {
String username = null;
String password = null;
final String authorization = request.getHeader("Authorization");
if (authorization != null && authorization.startsWith("Basic")) {
// Authorization: Basic base64credentials
String base64Credentials = authorization.substring("Basic".length()).trim();
String credentials = new String(Base64.getDecoder().decode(base64Credentials), Charset.forName("UTF-8"));
// credentials = username:password
final String[] values = credentials.split(":", 2);
username = values[0];
password = values[1];
} else {
MultiMap<String> mm = new MultiMap<>();
request.extractFormParameters(mm);
for (String key : mm.keySet()) {
switch (key) {
case "username":
username = mm.getValue(key, 0);
break;
case "password":
password = mm.getValue(key, 0);
break;
}
}
}
//check username and password
if (!checkCreds(username, password)) {
return false;
}
String sessionId = sessionStore.createUserSession(username);
Cookie cookie = new Cookie(Const.COOKIE_SESSION, sessionId);
cookie.setMaxAge(Const.COOKIE_EXPRIY);
response.addCookie(cookie);
return true;
}
示例12: login
import org.eclipse.jetty.util.MultiMap; //导入依赖的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());
}
}
示例13: verifyCredentials
import org.eclipse.jetty.util.MultiMap; //导入依赖的package包/类
/**
* Verifies user credentials.
*
* @param oldPassword the password to verify.
* @param participantId the participantId of the user.
* @throws LoginException if the user provided incorrect password.
*/
private void verifyCredentials(String password, ParticipantId participantId)
throws LoginException {
MultiMap<String> parameters = new MultiMap<String>();
parameters.putAllValues(ImmutableMap.of("password", password, "address", participantId.getAddress()));
CallbackHandler callbackHandler = new HttpRequestBasedCallbackHandler(parameters);
LoginContext context = new LoginContext("Wave", new Subject(), callbackHandler, configuration);
// If authentication fails, login() will throw a LoginException.
context.login();
}
示例14: query
import org.eclipse.jetty.util.MultiMap; //导入依赖的package包/类
@Signature
public String query(String name) {
request.getParameterMap();
MultiMap<String> queryParameters = request.getQueryParameters();
if (queryParameters != null) {
return queryParameters.getString(name);
} else {
return null;
}
}
示例15: HttpRequestBasedCallbackHandler
import org.eclipse.jetty.util.MultiMap; //导入依赖的package包/类
public HttpRequestBasedCallbackHandler(MultiMap<String> parameters) {
this.parameters = parameters;
}