-
Notifications
You must be signed in to change notification settings - Fork 636
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fixes #2247 create router-config module to share with light-lambda-na…
…tive (#2248)
- Loading branch information
Showing
32 changed files
with
345 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
33 changes: 33 additions & 0 deletions
33
handler/src/main/java/com/networknt/handler/AuditAttachmentUtil.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.networknt.handler; | ||
|
||
import com.networknt.httpstring.AttachmentConstants; | ||
import io.undertow.server.HttpServerExchange; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
public class AuditAttachmentUtil { | ||
private static final Logger logger = LoggerFactory.getLogger(AuditAttachmentUtil.class); | ||
|
||
public static void populateAuditAttachmentField(final HttpServerExchange exchange, String fieldName, String fieldValue) { | ||
Map<String, Object> auditInfo = exchange.getAttachment(AttachmentConstants.AUDIT_INFO); | ||
|
||
if(auditInfo == null) { | ||
logger.trace("AuditInfo is null, creating a new one and inserting the key-value pair '{}:{}'", fieldName, fieldValue); | ||
auditInfo = new HashMap<>(); | ||
auditInfo.put(fieldName, fieldValue); | ||
|
||
} else { | ||
logger.trace("AuditInfo is not null, inserting the key-value pair '{}:{}'", fieldName, fieldValue); | ||
|
||
if (auditInfo.containsKey(fieldName)) | ||
logger.debug("AuditInfo already contains the field '{}'! Replacing the value '{}' with '{}'.", fieldName, auditInfo.get(fieldName), fieldValue); | ||
|
||
auditInfo.put(fieldName, fieldValue); | ||
} | ||
exchange.putAttachment(AttachmentConstants.AUDIT_INFO, auditInfo); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>light-4j</artifactId> | ||
<groupId>com.networknt</groupId> | ||
<version>2.1.34-SNAPSHOT</version> | ||
<relativePath>../pom.xml</relativePath> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
<artifactId>router-config</artifactId> | ||
<packaging>jar</packaging> | ||
<description>A config module for egress-router shared with light-lambda-native.</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>config</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>utility</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>handler-config</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.slf4j</groupId> | ||
<artifactId>slf4j-api</artifactId> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.networknt</groupId> | ||
<artifactId>service</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>ch.qos.logback</groupId> | ||
<artifactId>logback-classic</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
3 changes: 2 additions & 1 deletion
3
.../router/middleware/ServiceDictConfig.java → .../router/middleware/ServiceDictConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
--- | ||
# Light Router Configuration | ||
# As this router is built to support discovery and security for light-4j services, | ||
# the outbound connection is always HTTP 2.0 with TLS enabled. | ||
# If HTTP 2.0 protocol will be accepted from incoming request. | ||
http2Enabled: false | ||
|
||
# If TLS is enabled when accepting incoming request. Should be true on test and prod. | ||
httpsEnabled: true | ||
|
||
# Max request time in milliseconds before timeout to the server. | ||
maxRequestTime: 1000 | ||
|
||
# If a particular downstream service has different timeout than the above global definition, you can | ||
# add the path prefix and give it another timeout in millisecond. For downstream APIs not defined here, | ||
# they will use the global timeout defined in router.maxRequestTime. | ||
pathPrefixMaxRequestTime: ${router.pathPrefixMaxRequestTime:} | ||
|
||
# Connections per thread. | ||
connectionsPerThread: 10 | ||
|
||
# The max queue size for the requests if there is no connection to the downstream API in the connection pool. | ||
# The default value is 0 that means there is queued requests. As we have maxConnectionRetries, there is no | ||
# need to use the request queue to increase the memory usage. It should only be used when you see 503 errors | ||
# in the log after maxConnectionRetries to accommodate slow backend API. | ||
maxQueueSize: ${router.maxQueueSize:0} | ||
|
||
# Soft max connections per thread. | ||
softMaxConnectionsPerThread: 5 | ||
|
||
# Rewrite Host Header with the target host and port and write X_FORWARDED_HOST with original host | ||
rewriteHostHeader: true | ||
|
||
# Reuse XForwarded for the target XForwarded header | ||
reuseXForwarded: false | ||
|
||
# Max Connection Retries | ||
maxConnectionRetries: 3 | ||
|
||
# allowed host list. Use Regex to do wildcard match | ||
hostWhitelist: ${router.hostWhitelist:} | ||
|
||
# support serviceId in the query parameter for routing to overwrite serviceId in header routing. | ||
# by default, it is false and should not be used unless you are dealing with a legacy client that | ||
# does not support header manipulation. Once this flag is true, we are going to overwrite the header | ||
# service_id derived with other handlers from prefix, path, endpoint etc. | ||
serviceIdQueryParameter: ${router.serviceIdQueryParameter:false} | ||
|
||
# URL rewrite rules, each line will have two parts: the regex patten and replace string separated | ||
# with a space. The light-router has service discovery for host routing, so whe working on the | ||
# url rewrite rules, we only need to create about the path in the URL. | ||
# Test your rules at https://www.freeformatter.com/java-regex-tester.html | ||
urlRewriteRules: ${router.urlRewriteRules:} | ||
|
||
# Method rewrite rules for legacy clients that do not support DELETE, PUT, and PATCH HTTP methods to | ||
# send a request with GET and POST instead. The gateway will rewrite the method from GET to DELETE or | ||
# from POST to PUT or PATCH. This will be set up at the endpoint level to limit the application. | ||
# The format of the rule will be "endpoint-pattern source-method target-method". Please refer to test | ||
# values.yml for examples. The endpoint-pattern is a pattern in OpenAPI specification. The following is | ||
# a list of examples: | ||
# /v1/pets/{petId} PATCH POST | ||
# /v1/pets PUT POST | ||
# Note: you cannot rewrite a method with a body to a method without a body or vice versa. | ||
methodRewriteRules: ${router.methodRewriteRules:} | ||
|
||
# Query parameter rewrite rules for client applications that send different query parameter keys or values | ||
# than the target server expecting. When overwriting a value, the key must be specified in order to | ||
# identify the right query parameter. If only the ok and nk are specified, the router will rewrite the | ||
# query parameter key ok with different key nk and keep the value. | ||
# The format of the rule will be a map with the path as the key. Please refer to test values.yml for | ||
# examples. | ||
queryParamRewriteRules: ${router.queryParamRewriteRules:} | ||
|
||
# Header rewrite rules for client applications that send different header keys or values than the target | ||
# server expecting. When overwriting a value, the key must be specified in order to identify the right | ||
# header. If only the ok and nk are specified, the router will rewrite the header key ok with different | ||
# key nk and keep the value. | ||
# The format of the rule will be a map with the path as the key. Please refer to test values.yml for | ||
# examples. | ||
headerRewriteRules: ${router.headerRewriteRules:} |
Oops, something went wrong.