org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder Java Examples

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.handler.codec.http.QueryStringDecoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: RouterHandler.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext channelHandlerContext, HttpRequest httpRequest) {
	if (HttpHeaders.is100ContinueExpected(httpRequest)) {
		channelHandlerContext.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
		return;
	}

	// Route
	HttpMethod method = httpRequest.getMethod();
	QueryStringDecoder qsd = new QueryStringDecoder(httpRequest.uri());
	RouteResult<?> routeResult = router.route(method, qsd.path(), qsd.parameters());

	if (routeResult == null) {
		respondNotFound(channelHandlerContext, httpRequest);
		return;
	}

	routed(channelHandlerContext, routeResult, httpRequest);
}
 
Example #2
Source File: Router.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
private String[] decodePathTokens(String uri) {
	// Need to split the original URI (instead of QueryStringDecoder#path) then decode the tokens (components),
	// otherwise /test1/123%2F456 will not match /test1/:p1

	int qPos = uri.indexOf("?");
	String encodedPath = (qPos >= 0) ? uri.substring(0, qPos) : uri;

	String[] encodedTokens = PathPattern.removeSlashesAtBothEnds(encodedPath).split("/");

	String[] decodedTokens = new String[encodedTokens.length];
	for (int i = 0; i < encodedTokens.length; i++) {
		String encodedToken = encodedTokens[i];
		decodedTokens[i] = QueryStringDecoder.decodeComponent(encodedToken);
	}

	return decodedTokens;
}
 
Example #3
Source File: Router.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
/**
 * Returns allowed methods for a specific URI.
 *
 * <p>For {@code OPTIONS *}, use {@link #allAllowedMethods()} instead of this method.
 */
public Set<HttpMethod> allowedMethods(String uri) {
	QueryStringDecoder decoder = new QueryStringDecoder(uri);
	String[] tokens = PathPattern.removeSlashesAtBothEnds(decoder.path()).split("/");

	if (anyMethodRouter.anyMatched(tokens)) {
		return allAllowedMethods();
	}

	Set<HttpMethod> ret = new HashSet<HttpMethod>(routers.size());
	for (Map.Entry<HttpMethod, MethodlessRouter<T>> entry : routers.entrySet()) {
		MethodlessRouter<T> router = entry.getValue();
		if (router.anyMatched(tokens)) {
			HttpMethod method = entry.getKey();
			ret.add(method);
		}
	}

	return ret;
}
 
Example #4
Source File: RouterHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext channelHandlerContext, HttpRequest httpRequest) {
	if (HttpHeaders.is100ContinueExpected(httpRequest)) {
		channelHandlerContext.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
		return;
	}

	// Route
	HttpMethod method = httpRequest.getMethod();
	QueryStringDecoder qsd = new QueryStringDecoder(httpRequest.uri());
	RouteResult<?> routeResult = router.route(method, qsd.path(), qsd.parameters());

	if (routeResult == null) {
		respondNotFound(channelHandlerContext, httpRequest);
		return;
	}

	routed(channelHandlerContext, routeResult, httpRequest);
}
 
Example #5
Source File: Router.java    From flink with Apache License 2.0 6 votes vote down vote up
private String[] decodePathTokens(String uri) {
	// Need to split the original URI (instead of QueryStringDecoder#path) then decode the tokens (components),
	// otherwise /test1/123%2F456 will not match /test1/:p1

	int qPos = uri.indexOf("?");
	String encodedPath = (qPos >= 0) ? uri.substring(0, qPos) : uri;

	String[] encodedTokens = PathPattern.removeSlashesAtBothEnds(encodedPath).split("/");

	String[] decodedTokens = new String[encodedTokens.length];
	for (int i = 0; i < encodedTokens.length; i++) {
		String encodedToken = encodedTokens[i];
		decodedTokens[i] = QueryStringDecoder.decodeComponent(encodedToken);
	}

	return decodedTokens;
}
 
Example #6
Source File: Router.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Returns allowed methods for a specific URI.
 *
 * <p>For {@code OPTIONS *}, use {@link #allAllowedMethods()} instead of this method.
 */
public Set<HttpMethod> allowedMethods(String uri) {
	QueryStringDecoder decoder = new QueryStringDecoder(uri);
	String[] tokens = PathPattern.removeSlashesAtBothEnds(decoder.path()).split("/");

	if (anyMethodRouter.anyMatched(tokens)) {
		return allAllowedMethods();
	}

	Set<HttpMethod> ret = new HashSet<HttpMethod>(routers.size());
	for (Map.Entry<HttpMethod, MethodlessRouter<T>> entry : routers.entrySet()) {
		MethodlessRouter<T> router = entry.getValue();
		if (router.anyMatched(tokens)) {
			HttpMethod method = entry.getKey();
			ret.add(method);
		}
	}

	return ret;
}
 
Example #7
Source File: RouterHandler.java    From flink with Apache License 2.0 6 votes vote down vote up
@Override
protected void channelRead0(ChannelHandlerContext channelHandlerContext, HttpRequest httpRequest) {
	if (HttpHeaders.is100ContinueExpected(httpRequest)) {
		channelHandlerContext.writeAndFlush(new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.CONTINUE));
		return;
	}

	// Route
	HttpMethod method = httpRequest.getMethod();
	QueryStringDecoder qsd = new QueryStringDecoder(httpRequest.uri());
	RouteResult<?> routeResult = router.route(method, qsd.path(), qsd.parameters());

	if (routeResult == null) {
		respondNotFound(channelHandlerContext, httpRequest);
		return;
	}

	routed(channelHandlerContext, routeResult, httpRequest);
}
 
Example #8
Source File: Router.java    From flink with Apache License 2.0 6 votes vote down vote up
private String[] decodePathTokens(String uri) {
	// Need to split the original URI (instead of QueryStringDecoder#path) then decode the tokens (components),
	// otherwise /test1/123%2F456 will not match /test1/:p1

	int qPos = uri.indexOf("?");
	String encodedPath = (qPos >= 0) ? uri.substring(0, qPos) : uri;

	String[] encodedTokens = PathPattern.removeSlashesAtBothEnds(encodedPath).split("/");

	String[] decodedTokens = new String[encodedTokens.length];
	for (int i = 0; i < encodedTokens.length; i++) {
		String encodedToken = encodedTokens[i];
		decodedTokens[i] = QueryStringDecoder.decodeComponent(encodedToken);
	}

	return decodedTokens;
}
 
Example #9
Source File: Router.java    From flink with Apache License 2.0 6 votes vote down vote up
/**
 * Returns allowed methods for a specific URI.
 *
 * <p>For {@code OPTIONS *}, use {@link #allAllowedMethods()} instead of this method.
 */
public Set<HttpMethod> allowedMethods(String uri) {
	QueryStringDecoder decoder = new QueryStringDecoder(uri);
	String[] tokens = PathPattern.removeSlashesAtBothEnds(decoder.path()).split("/");

	if (anyMethodRouter.anyMatched(tokens)) {
		return allAllowedMethods();
	}

	Set<HttpMethod> ret = new HashSet<HttpMethod>(routers.size());
	for (Map.Entry<HttpMethod, MethodlessRouter<T>> entry : routers.entrySet()) {
		MethodlessRouter<T> router = entry.getValue();
		if (router.anyMatched(tokens)) {
			HttpMethod method = entry.getKey();
			ret.add(method);
		}
	}

	return ret;
}
 
Example #10
Source File: RoutedRequest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public RoutedRequest(RouteResult<T> result, HttpRequest request) {
	this.result = checkNotNull(result);
	this.request = checkNotNull(request);
	this.requestAsReferenceCounted = Optional.ofNullable((request instanceof ReferenceCounted) ? (ReferenceCounted) request : null);
	this.queryStringDecoder = new QueryStringDecoder(request.uri());
}
 
Example #11
Source File: RoutedRequest.java    From flink with Apache License 2.0 4 votes vote down vote up
public RoutedRequest(RouteResult<T> result, HttpRequest request) {
	this.result = checkNotNull(result);
	this.request = checkNotNull(request);
	this.requestAsReferenceCounted = Optional.ofNullable((request instanceof ReferenceCounted) ? (ReferenceCounted) request : null);
	this.queryStringDecoder = new QueryStringDecoder(request.uri());
}
 
Example #12
Source File: RoutedRequest.java    From flink with Apache License 2.0 4 votes vote down vote up
public RoutedRequest(RouteResult<T> result, HttpRequest request) {
	this.result = checkNotNull(result);
	this.request = checkNotNull(request);
	this.requestAsReferenceCounted = Optional.ofNullable((request instanceof ReferenceCounted) ? (ReferenceCounted) request : null);
	this.queryStringDecoder = new QueryStringDecoder(request.uri());
}