本文整理汇总了Java中io.undertow.server.HttpServerExchange.setRequestPath方法的典型用法代码示例。如果您正苦于以下问题:Java HttpServerExchange.setRequestPath方法的具体用法?Java HttpServerExchange.setRequestPath怎么用?Java HttpServerExchange.setRequestPath使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类io.undertow.server.HttpServerExchange
的用法示例。
在下文中一共展示了HttpServerExchange.setRequestPath方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: writeAttribute
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
int pos = newValue.indexOf('?');
if (pos == -1) {
exchange.setRelativePath(newValue);
exchange.setRequestURI(newValue);
exchange.setRequestPath(newValue);
exchange.setResolvedPath("");
} else {
final String path = newValue.substring(0, pos);
exchange.setRelativePath(path);
exchange.setRequestURI(path);
exchange.setRequestPath(path);
exchange.setResolvedPath("");
final String newQueryString = newValue.substring(pos);
exchange.setQueryString(newQueryString);
exchange.getQueryParameters().putAll(QueryParameterUtils.parseQueryString(newQueryString.substring(1), QueryParameterUtils.getQueryParamEncoding(exchange)));
}
}
示例2: writeAttribute
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void writeAttribute(final HttpServerExchange exchange, final String newValue) throws ReadOnlyAttributeException {
int pos = newValue.indexOf('?');
if (pos == -1) {
exchange.setRelativePath(newValue);
exchange.setRequestURI(exchange.getResolvedPath() + newValue);
exchange.setRequestPath(exchange.getResolvedPath() + newValue);
} else {
final String path = newValue.substring(0, pos);
exchange.setRelativePath(path);
exchange.setRequestURI(exchange.getResolvedPath() + newValue);
exchange.setRequestPath(exchange.getResolvedPath() + newValue);
final String newQueryString = newValue.substring(pos);
exchange.setQueryString(newQueryString);
exchange.getQueryParameters().putAll(QueryParameterUtils.parseQueryString(newQueryString.substring(1), QueryParameterUtils.getQueryParamEncoding(exchange)));
}
}
示例3: beginPathParameters
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
private void beginPathParameters(ParseState state, HttpServerExchange exchange, StringBuilder stringBuilder, int parseState, int canonicalPathStart, boolean urlDecodeRequired) {
final String path = stringBuilder.toString();
if (parseState < HOST_DONE) {
String decodedPath = decode(path, urlDecodeRequired, state, allowEncodedSlash);
exchange.setRequestPath(decodedPath);
exchange.setRelativePath(decodedPath);
exchange.setRequestURI(path);
} else {
String thePath = path.substring(canonicalPathStart);
exchange.setRequestPath(thePath);
exchange.setRelativePath(thePath);
exchange.setRequestURI(path, true);
}
state.state = ParseState.PATH_PARAMETERS;
state.stringBuilder.setLength(0);
state.parseState = 0;
state.pos = 0;
state.urlDecodeRequired = false;
}
示例4: beginQueryParameters
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
private void beginQueryParameters(ByteBuffer buffer, ParseState state, HttpServerExchange exchange, StringBuilder stringBuilder, int parseState, int canonicalPathStart, boolean urlDecodeRequired) {
final String path = stringBuilder.toString();
if (parseState < HOST_DONE) {
String decodedPath = decode(path, urlDecodeRequired, state, allowEncodedSlash);
exchange.setRequestPath(decodedPath);
exchange.setRelativePath(decodedPath);
exchange.setRequestURI(path, false);
} else {
handleFullUrl(state, exchange, canonicalPathStart, urlDecodeRequired, path);
}
state.state = ParseState.QUERY_PARAMETERS;
state.stringBuilder.setLength(0);
state.parseState = 0;
state.pos = 0;
state.urlDecodeRequired = false;
handleQueryParameters(buffer, state, exchange);
}
示例5: handleRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
boolean handlingRequired = File.separatorChar != '/';
if (handlingRequired) {
exchange.setRequestPath(canonicalize(exchange.getRequestPath().replace(File.separatorChar, '/')));
exchange.setRelativePath(canonicalize(exchange.getRelativePath().replace(File.separatorChar, '/')));
exchange.setResolvedPath(canonicalize(exchange.getResolvedPath().replace(File.separatorChar, '/')));
}
next.handleRequest(exchange);
}
示例6: handleRequest
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void handleRequest(final HttpServerExchange exchange) throws Exception {
boolean decodeDone = exchange.getConnection().getUndertowOptions().get(UndertowOptions.DECODE_URL, true);
if (!decodeDone) {
final StringBuilder sb = new StringBuilder();
final boolean decodeSlash = exchange.getConnection().getUndertowOptions().get(UndertowOptions.ALLOW_ENCODED_SLASH, false);
exchange.setRequestPath(URLUtils.decode(exchange.getRequestPath(), charset, decodeSlash, sb));
exchange.setRelativePath(URLUtils.decode(exchange.getRelativePath(), charset, decodeSlash, sb));
exchange.setResolvedPath(URLUtils.decode(exchange.getResolvedPath(), charset, decodeSlash, sb));
if (!exchange.getQueryString().isEmpty()) {
final TreeMap<String, Deque<String>> newParams = new TreeMap<>();
for (Map.Entry<String, Deque<String>> param : exchange.getQueryParameters().entrySet()) {
final Deque<String> newVales = new ArrayDeque<>(param.getValue().size());
for (String val : param.getValue()) {
newVales.add(URLUtils.decode(val, charset, true, sb));
}
newParams.put(URLUtils.decode(param.getKey(), charset, true, sb), newVales);
}
exchange.getQueryParameters().clear();
exchange.getQueryParameters().putAll(newParams);
}
}
next.handleRequest(exchange);
}
示例7: handlePath
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
/**
* Parses a path value
*
* @param buffer The buffer
* @param state The current state
* @param exchange The exchange builder
* @return The number of bytes remaining
*/
@SuppressWarnings("unused")
final void handlePath(ByteBuffer buffer, ParseState state, HttpServerExchange exchange) {
StringBuilder stringBuilder = state.stringBuilder;
int parseState = state.parseState;
int canonicalPathStart = state.pos;
boolean urlDecodeRequired = state.urlDecodeRequired;
while (buffer.hasRemaining()) {
char next = (char) (buffer.get() & 0xFF);
if (next == ' ' || next == '\t') {
if (stringBuilder.length() != 0) {
final String path = stringBuilder.toString();
if (parseState < HOST_DONE) {
String decodedPath = decode(path, urlDecodeRequired, state, allowEncodedSlash);
exchange.setRequestPath(decodedPath);
exchange.setRelativePath(decodedPath);
exchange.setRequestURI(path);
} else {
handleFullUrl(state, exchange, canonicalPathStart, urlDecodeRequired, path);
}
exchange.setQueryString("");
state.state = ParseState.VERSION;
state.stringBuilder.setLength(0);
state.parseState = 0;
state.pos = 0;
state.urlDecodeRequired = false;
return;
}
} else if (next == '\r' || next == '\n') {
throw UndertowMessages.MESSAGES.failedToParsePath();
} else if (next == '?' && (parseState == START || parseState == HOST_DONE || parseState == IN_PATH)) {
beginQueryParameters(buffer, state, exchange, stringBuilder, parseState, canonicalPathStart, urlDecodeRequired);
return;
} else if (next == ';' && (parseState == START || parseState == HOST_DONE || parseState == IN_PATH)) {
beginPathParameters(state, exchange, stringBuilder, parseState, canonicalPathStart, urlDecodeRequired);
handlePathParameters(buffer, state, exchange);
return;
} else {
if (decode && (next == '+' || next == '%' || next > 127)) {
urlDecodeRequired = true;
} else if (next == ':' && parseState == START) {
parseState = FIRST_COLON;
} else if (next == '/' && parseState == FIRST_COLON) {
parseState = FIRST_SLASH;
} else if (next == '/' && parseState == FIRST_SLASH) {
parseState = SECOND_SLASH;
} else if (next == '/' && parseState == SECOND_SLASH) {
parseState = HOST_DONE;
canonicalPathStart = stringBuilder.length();
} else if (parseState == FIRST_COLON || parseState == FIRST_SLASH) {
parseState = IN_PATH;
} else if (next == '/' && parseState != HOST_DONE) {
parseState = IN_PATH;
}
stringBuilder.append(next);
}
}
state.parseState = parseState;
state.pos = canonicalPathStart;
state.urlDecodeRequired = urlDecodeRequired;
}
示例8: handleFullUrl
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
private void handleFullUrl(ParseState state, HttpServerExchange exchange, int canonicalPathStart, boolean urlDecodeRequired, String path) {
String thePath = decode(path.substring(canonicalPathStart), urlDecodeRequired, state, allowEncodedSlash);
exchange.setRequestPath(thePath);
exchange.setRelativePath(thePath);
exchange.setRequestURI(path, true);
}
示例9: getConnection
import io.undertow.server.HttpServerExchange; //导入方法依赖的package包/类
@Override
public void getConnection(ProxyTarget target, HttpServerExchange exchange, ProxyCallback<ProxyConnection> callback, long timeout, TimeUnit timeUnit) {
Realm realm = realmCache.matches(exchange.getRequestPath());
if (realm != null) {
parseToken(exchange).ifPresent(token -> {
Optional<UserPermissionPrincipal> principal = authenticate(realm.getId(), token);
principal.ifPresent(p -> {
Map<String, Object> body = new HashMap<>();
body.put("sub", p.getName());
body.put("permissions", p.getPermissions());
p.getProfiles().forEach((k, v) -> {
body.put(k, v);
});
exchange.getRequestHeaders().put(HttpString.tryFromString(config.getBackendHeaderName()),
jwt.sign(body, jwtHeader, null));
});
});
} else {
exchange.setStatusCode(404);
exchange.endExchange();
return;
}
Application application = realmCache.getApplication(realm);
ClientConnection existing = exchange.getConnection().getAttachment(clientAttachmentKey);
if (existing != null) {
if (existing.isOpen()) {
//this connection already has a client, re-use it
String path = exchange.getRequestURI();
if (path.startsWith(application.getVirtualPath())) {
String passTo = calculatePathTo(path, application);
exchange.setRequestPath(passTo);
exchange.setRequestURI(passTo);
}
callback.completed(exchange, new ProxyConnection(existing, "/"));
return;
} else {
exchange.getConnection().removeAttachment(clientAttachmentKey);
}
}
try {
URI uri = application.getUriToPass();
client.connect(new ConnectNotifier(callback, exchange),
new URI(uri.getScheme(), /*userInfo*/null, uri.getHost(), uri.getPort(),
/*path*/null, /*query*/null, /*fragment*/null),
exchange.getIoThread(),
exchange.getConnection().getByteBufferPool(), OptionMap.EMPTY);
} catch (URISyntaxException e) {
throw new MisconfigurationException("", application.getUriToPass(), e);
}
}