use of io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.
the class RouterPathTest method testRouterFeedsLookup.
@Test
public void testRouterFeedsLookup() {
final String namespacePath = "/v3//feeds/test";
HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("PUT"), namespacePath);
RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, namespacePath, httpRequest);
Assert.assertEquals(null, result);
}
use of io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.
the class RouterPathTest method testAppFabricPath.
@Test
public void testAppFabricPath() throws Exception {
// Default destination for URIs will APP_FABRIC_HTTP
String path = "/v3/ping/";
HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), path);
RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
path = "/status";
httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("GET"), path);
result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
path = "/v3/monitor///abcd/";
httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("POST"), path);
result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
}
use of io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.
the class RouterPathTest method testRouterDeployPathLookUp.
@Test
public void testRouterDeployPathLookUp() throws Exception {
String path = "/v3/namespaces/default//apps/";
HttpRequest httpRequest = new DefaultHttpRequest(VERSION, new HttpMethod("PUT"), path);
RouteDestination result = pathLookup.getRoutingService(FALLBACKSERVICE, path, httpRequest);
Assert.assertEquals(RouterPathLookup.APP_FABRIC_HTTP, result);
}
use of io.netty.handler.codec.http.HttpMethod in project cdap by caskdata.
the class RouterAuditLookUp method createMatcher.
private int createMatcher() {
List<ClassPath.ClassInfo> handlerClasses;
try {
handlerClasses = getAllHandlerClasses();
} catch (IOException e) {
LOG.error("Failed to get all handler classes for audit logging: {}", e.getCause());
return -1;
}
int count = 0;
for (ClassPath.ClassInfo classInfo : handlerClasses) {
Class<?> handlerClass = classInfo.load();
Path classPath = handlerClass.getAnnotation(Path.class);
String classPathStr = classPath == null ? "" : classPath.value();
for (Method method : handlerClass.getMethods()) {
Path methodPath = method.getAnnotation(Path.class);
AuditPolicy auditPolicy = method.getAnnotation(AuditPolicy.class);
HttpMethod httpMethod = getHttpMethod(method);
if (methodPath == null || auditPolicy == null || httpMethod == null) {
continue;
}
String methodPathStr = methodPath.value();
String completePath = classPathStr.endsWith("/") || methodPathStr.startsWith("/") ? classPathStr + methodPathStr : classPathStr + "/" + methodPathStr;
List<AuditDetail> auditContents = Arrays.asList(auditPolicy.value());
List<String> headerNames = new ArrayList<>();
if (auditContents.contains(AuditDetail.HEADERS)) {
Annotation[][] annotations = method.getParameterAnnotations();
for (Annotation[] annotationArr : annotations) {
if (annotationArr.length > 0) {
for (Annotation annotation : annotationArr) {
if (annotation instanceof HeaderParam) {
headerNames.add(((HeaderParam) annotation).value());
}
}
}
}
}
AuditLogConfig auditLogConfig = new AuditLogConfig(httpMethod, auditContents.contains(AuditDetail.REQUEST_BODY), auditContents.contains(AuditDetail.RESPONSE_BODY), headerNames);
LOG.trace("Audit log lookup: bootstrapped with path: {}", completePath);
patternMatcher.add(completePath, auditLogConfig);
// Don't count classes in unit-tests
if (!isTestClass(classInfo)) {
count++;
}
}
}
LOG.debug("Audit log lookup: bootstrapped with {} paths", count);
return count;
}
use of io.netty.handler.codec.http.HttpMethod in project spring-cloud-gateway by spring-cloud.
the class NettyRoutingFilter method filter.
@Override
public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {
URI requestUrl = exchange.getRequiredAttribute(GATEWAY_REQUEST_URL_ATTR);
String scheme = requestUrl.getScheme();
if (isAlreadyRouted(exchange) || (!"http".equals(scheme) && !"https".equals(scheme))) {
return chain.filter(exchange);
}
setAlreadyRouted(exchange);
ServerHttpRequest request = exchange.getRequest();
final HttpMethod method = HttpMethod.valueOf(request.getMethod().toString());
final String url = requestUrl.toString();
HttpHeaders filtered = filterRequest(this.headersFilters.getIfAvailable(), exchange);
final DefaultHttpHeaders httpHeaders = new DefaultHttpHeaders();
filtered.forEach(httpHeaders::set);
String transferEncoding = request.getHeaders().getFirst(HttpHeaders.TRANSFER_ENCODING);
boolean chunkedTransfer = "chunked".equalsIgnoreCase(transferEncoding);
boolean preserveHost = exchange.getAttributeOrDefault(PRESERVE_HOST_HEADER_ATTRIBUTE, false);
return this.httpClient.request(method, url, req -> {
final HttpClientRequest proxyRequest = req.options(NettyPipeline.SendOptions::flushOnEach).headers(httpHeaders).chunkedTransfer(chunkedTransfer).failOnServerError(false).failOnClientError(false);
if (preserveHost) {
String host = request.getHeaders().getFirst(HttpHeaders.HOST);
proxyRequest.header(HttpHeaders.HOST, host);
}
return // I shouldn't need this
proxyRequest.sendHeaders().send(request.getBody().map(dataBuffer -> ((NettyDataBuffer) dataBuffer).getNativeBuffer()));
}).doOnNext(res -> {
ServerHttpResponse response = exchange.getResponse();
// put headers and status so filters can modify the response
HttpHeaders headers = new HttpHeaders();
res.responseHeaders().forEach(entry -> headers.add(entry.getKey(), entry.getValue()));
HttpHeaders filteredResponseHeaders = HttpHeadersFilter.filter(this.headersFilters.getIfAvailable(), headers, exchange, Type.RESPONSE);
response.getHeaders().putAll(filteredResponseHeaders);
response.setStatusCode(HttpStatus.valueOf(res.status().code()));
// Defer committing the response until all route filters have run
// Put client response as ServerWebExchange attribute and write response later NettyWriteResponseFilter
exchange.getAttributes().put(CLIENT_RESPONSE_ATTR, res);
}).then(chain.filter(exchange));
}
Aggregations