From 35257a28d30f96658ca0c50152a98ac2cf8f4bc5 Mon Sep 17 00:00:00 2001 From: Steve Hu Date: Fri, 16 Aug 2024 11:09:11 -0400 Subject: [PATCH] fixes #207 add isoxml lps config to test body-encoder plugin (#208) --- config/client-proxy-transform/values.yml | 2 +- config/server-proxy-isoxml/README.md | 3 + config/server-proxy-isoxml/logback.xml | 110 ++++++++++++++ config/server-proxy-isoxml/rules.yml | 19 +++ config/server-proxy-isoxml/values.yml | 174 +++++++++++++++++++++++ 5 files changed, 307 insertions(+), 1 deletion(-) create mode 100644 config/server-proxy-isoxml/README.md create mode 100644 config/server-proxy-isoxml/logback.xml create mode 100644 config/server-proxy-isoxml/rules.yml create mode 100644 config/server-proxy-isoxml/values.yml diff --git a/config/client-proxy-transform/values.yml b/config/client-proxy-transform/values.yml index 4b2afc3..682e922 100644 --- a/config/client-proxy-transform/values.yml +++ b/config/client-proxy-transform/values.yml @@ -10,7 +10,7 @@ router.maxRequestTime: 30000 router.http2Enabled: true # rule-loader.yml -rule-Loader.ruleSource: config-folder +rule-loader.ruleSource: config-folder rule-loader.endpointRules: {"/v1/pets@get":{"request-transform":[{"ruleId":"petstore-request-header-replace"}],"response-transform":[{"ruleId":"petstore-response-header-replace"}]},"/v1/pets@post":{"request-transform":[{"ruleId":"body-sanitizer-request"}]},"/v1/notifications@get":{"response-transform":[{"ruleId":"petstore-notifications-transformer"}]},"/pets@get":{"request-transform":[{"ruleId":"petstore-request-path"}]},"/v1/flowers@post":{"request-transform":[{"ruleId":"petstore-flower-request"}],"response-transform":[{"ruleId":"petstore-flower-response"}]},"/devext/CANX/AntcMultiService@post":{"request-transform":[{"ruleId":"soap-security-request"}]}} # request-injection.yml request-injection.appliedBodyInjectionPathPrefixes: diff --git a/config/server-proxy-isoxml/README.md b/config/server-proxy-isoxml/README.md new file mode 100644 index 0000000..2faed10 --- /dev/null +++ b/config/server-proxy-isoxml/README.md @@ -0,0 +1,3 @@ +It is a test configuration for the light-gateway to router traffic to iso-xml server from light-example-4j. + +We use this proxy server instance to test the body-encoding plugin to convert the encoding from ISO-8859-1 to UTF-8. diff --git a/config/server-proxy-isoxml/logback.xml b/config/server-proxy-isoxml/logback.xml new file mode 100644 index 0000000..842e981 --- /dev/null +++ b/config/server-proxy-isoxml/logback.xml @@ -0,0 +1,110 @@ + + + + + + + PROFILER + + NEUTRAL + + + + + + + %d{HH:mm:ss.SSS} [%thread] %X{sId} %X{cId} %-5level %class{36}:%L %M - %msg%n + + + + + + log/stdout.log.json + + + + timestamp + yyyy-MM-dd'T'HH:mm:ss.SSSZ + + + + { + "thread": "%thread", + "level": "%-5level", + "logger": "%logger{64}", + "correlationId": "%X{cId}", + "serviceId": "%X{sId}", + "class": "%F", + "lineNumber": "%class{64}:%L", + "method": "%M", + "logMessage": "#tryJson{%message}" + } + + + + + + + + log/stdout.log.json.%i.zip + 1 + 5 + + + 200MB + + + + + + + log/audit.log.json + + %msg%n + true + + + log/audit.log.json.%i.zip + 1 + 5 + + + 200MB + + + + + + + + + + + + + + + + + + + + + + diff --git a/config/server-proxy-isoxml/rules.yml b/config/server-proxy-isoxml/rules.yml new file mode 100644 index 0000000..716258b --- /dev/null +++ b/config/server-proxy-isoxml/rules.yml @@ -0,0 +1,19 @@ +# local rules +response-body-encoding: + ruleId: response-body-encoding + host: lightapi.net + ruleType: response-transform + visibility: public + description: Convert ISO-8859-1 encoding to UTF-8 for the response body. + conditions: + - conditionId: path-conquest + propertyPath: requestPath + operatorCode: EQ + joinCode: AND + index: 1 + conditionValues: + - conditionValueId: path + conditionValue: /v1/pets + actions: + - actionId: iso-xml-response-transform + actionClassName: com.networknt.rule.encoder.ResponseBodyUtf8EncodingTransformAction diff --git a/config/server-proxy-isoxml/values.yml b/config/server-proxy-isoxml/values.yml new file mode 100644 index 0000000..f152341 --- /dev/null +++ b/config/server-proxy-isoxml/values.yml @@ -0,0 +1,174 @@ +# server.yml +server.httpsPort: 8443 +server.enableHttps: true +server.enableHttp2: true +server.serviceId: com.networknt.client-gateway-1.0.0 +server.environment: dev + +# router.yml +router.maxRequestTime: 30000 +router.http2Enabled: true + +# rule-loader.yml +rule-loader.ruleSource: config-folder +rule-loader.endpointRules: {"/v1/pets@get":{"response-transform":[{"ruleId":"response-body-encoding"}]}} + +# request-injection.yml +request-injection.appliedBodyInjectionPathPrefixes: + - /v1/pets + +# response-transformer.yml +response-injection.appliedBodyInjectionPathPrefixes: + - /v1/pets + +# response-transformer.yml +response-transformer.defaultBodyEncoding: ISO-8859-1 +response-transformer.appliedPathPrefixes: ["/v1/pets"] + +# request-transformer.yml +request-transformer.appliedPathPrefixes: ["/v1/pets"] + +# pathPrefixService.yml +pathPrefixService.mapping: + /v1/pets: com.networknt.petstore-1.0.0 + +# service.yml +service.singletons: + - com.networknt.server.StartupHookProvider: + - com.networknt.rule.RuleLoaderStartupHook + - com.networknt.registry.URL: + - com.networknt.registry.URLImpl + - com.networknt.registry.Registry: + - com.networknt.registry.support.DirectRegistry + - com.networknt.balance.LoadBalance: + - com.networknt.balance.RoundRobinLoadBalance + - com.networknt.cluster.Cluster: + - com.networknt.cluster.LightCluster + - com.networknt.cache.CacheManager: + - com.networknt.cache.CaffeineCacheManager + - com.networknt.handler.ResponseInterceptor: + - com.networknt.restrans.ResponseTransformerInterceptor + - com.networknt.body.ResponseBodyInterceptor + - com.networknt.handler.RequestInterceptor: + - com.networknt.body.RequestBodyInterceptor + - com.networknt.reqtrans.RequestTransformerInterceptor + +# direct-registry.yml +direct-registry.directUrls: + com.networknt.petstore-1.0.0: https://localhost:9443 + +# handler.yml +handler.basePath: / +handler.handlers: + # Light-framework cross-cutting concerns implemented in the microservice + - com.networknt.exception.ExceptionHandler@exception + # - com.networknt.metrics.MetricsHandler@metrics + - com.networknt.traceability.TraceabilityHandler@traceability + - com.networknt.correlation.CorrelationHandler@correlation + # Cors handler to handler post/put pre-flight. It is not used in the sidecar but only in the router. + - com.networknt.cors.CorsHttpHandler@cors + - com.networknt.openapi.OpenApiHandler@specification + - com.networknt.openapi.JwtVerifyHandler@security + - com.networknt.body.BodyHandler@body + - com.networknt.audit.AuditHandler@audit + - com.networknt.sanitizer.SanitizerHandler@sanitizer + - com.networknt.openapi.ValidatorHandler@validator + # Header middleware to manipulate request and/or response headers before or after downstream server + - com.networknt.header.HeaderHandler@header + # Rate limit middleware to prevent DDoS attacks externally or throttle requests internally + - com.networknt.limit.LimitHandler@limit + # IP whitelist handler to allow only one or several IPs to connect to the gateway. + # - com.networknt.whitelist.WhitelistHandler@whitelist + # Direct requests to named services based on the request path + # - com.networknt.router.middleware.GatewayServiceDictHandler@path + - com.networknt.router.middleware.PathPrefixServiceHandler@prefix + - com.networknt.router.RouterHandler@router + - com.networknt.proxy.LightProxyHandler@proxy + - com.networknt.proxy.ProxyServerInfoHandler@proxyServerInfo + # - com.networknt.resource.VirtualHostHandler@virtual + # Customer business domain specific cross-cutting concerns handlers + # - com.example.validator.CustomizedValidator@custvalidator + # Framework endpoint handlers + # Control Pane middleware handlers and API handler + - com.networknt.chaos.KillappAssaultHandler@killapp + - com.networknt.chaos.LatencyAssaultHandler@latency + - com.networknt.chaos.MemoryAssaultHandler@memory + - com.networknt.chaos.ExceptionAssaultHandler@exchaos + - com.networknt.chaos.ChaosMonkeyGetHandler@chaosget + - com.networknt.chaos.ChaosMonkeyPostHandler@chaospost + - com.networknt.health.HealthGetHandler@health + - com.networknt.info.ServerInfoGetHandler@info + - com.networknt.cache.CacheExplorerHandler@cache + - com.networknt.logging.handler.LoggerGetHandler@getLogger + - com.networknt.logging.handler.LoggerPostHandler@postLogger + - com.networknt.logging.handler.LoggerGetLogContentsHandler@getLogContents + - com.networknt.config.reload.handler.ModuleRegistryGetHandler@modules + - com.networknt.config.reload.handler.ConfigReloadHandler@configReload + - com.networknt.specification.SpecDisplayHandler@spec + - com.networknt.specification.SpecSwaggerUIHandler@swaggerui + - com.networknt.specification.FaviconHandler@favicon + - com.networknt.handler.ResponseInterceptorInjectionHandler@responseInterceptor + - com.networknt.handler.RequestInterceptorInjectionHandler@requestInterceptor + - com.networknt.proxy.ExternalServiceHandler@external + - com.networknt.apikey.ApiKeyHandler@apikey + - com.networknt.router.OAuthServerHandler@oauth + - com.networknt.router.OAuthServerGetHandler@getOauth + - com.networknt.server.handler.ServerShutdownHandler@shutdown + +handler.chains.default: + - exception + - prefix + # - metrics + # - limit + - traceability + - correlation + # - cors + # - stateless + - limit + - apikey + - specification + - security + - header + - requestInterceptor + - responseInterceptor + - audit + - external + #- path + #- body + - sanitizer + #- validator + - router + +# audit.yml +audit.auditOnError: false + +# body.yml +body.cacheRequestBody: true +body.cacheResponseBody: true +body.enabled: true +body.logFullRequestBody: false +body.logFullResponseBody: false + +# client.yml +client.verifyHostname: false + +# limit.yml +limit.enabled: false +limit.rateLimit: 1000/m + +# security.yml +security.skipPathPrefixes: ["/v1/documents", "/v1/pets", "/adm/server/info"] +security.keyResolver: X509Certificate +security.skipVerifyScopeWithoutSpec: true + +# openapi-handler.yml +openapi-handler.ignoreInvalidPath: true + +# cache.yml +cache.caches: + - cacheName: jwt + expiryInMinutes: 15 + maxSize: 100 + - cacheName: jwk + expiryInMinutes: 129600 + maxSize: 100