Skip to content

Commit

Permalink
fixes #207 add isoxml lps config to test body-encoder plugin (#208)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevehu authored Aug 16, 2024
1 parent 6404df2 commit 35257a2
Show file tree
Hide file tree
Showing 5 changed files with 307 additions and 1 deletion.
2 changes: 1 addition & 1 deletion config/client-proxy-transform/values.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
3 changes: 3 additions & 0 deletions config/server-proxy-isoxml/README.md
Original file line number Diff line number Diff line change
@@ -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.
110 changes: 110 additions & 0 deletions config/server-proxy-isoxml/logback.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
~ Copyright (c) 2016 Network New Technologies Inc.
~
~ Licensed under the Apache License, Version 2.0 (the "License");
~ you may not use this file except in compliance with the License.
~ You may obtain a copy of the License at
~
~ http://www.apache.org/licenses/LICENSE-2.0
~
~ Unless required by applicable law or agreed to in writing, software
~ distributed under the License is distributed on an "AS IS" BASIS,
~ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
~ See the License for the specific language governing permissions and
~ limitations under the License.
-->

<configuration>
<!-- TODO create logger for audit only.
http://stackoverflow.com/questions/2488558/logback-to-log-different-messages-to-two-files -->
<turboFilter class="ch.qos.logback.classic.turbo.MarkerFilter">
<Marker>PROFILER</Marker>
<!--<OnMatch>DENY</OnMatch>-->
<OnMatch>NEUTRAL</OnMatch>
</turboFilter>

<!--stdout log-->
<appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
<!-- encoders are assigned the type
ch.qos.logback.classic.encoder.PatternLayoutEncoder by default -->
<encoder>
<pattern>%d{HH:mm:ss.SSS} [%thread] %X{sId} %X{cId} %-5level %class{36}:%L %M - %msg%n</pattern>
</encoder>
</appender>

<!--stdout-file log-->
<appender name="stdout-file" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>log/stdout.log.json</file>
<encoder class="net.logstash.logback.encoder.LoggingEventCompositeJsonEncoder">
<providers>
<timestamp>
<fieldName>timestamp</fieldName>
<pattern>yyyy-MM-dd'T'HH:mm:ss.SSSZ</pattern>
</timestamp>
<pattern>
<pattern>
{
"thread": "%thread",
"level": "%-5level",
"logger": "%logger{64}",
"correlationId": "%X{cId}",
"serviceId": "%X{sId}",
"class": "%F",
"lineNumber": "%class{64}:%L",
"method": "%M",
"logMessage": "#tryJson{%message}"
}
</pattern>
</pattern>
<rootStackTraceElement/>
<stackTrace/>
</providers>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>log/stdout.log.json.%i.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>5</maxIndex> <!-- max number of archived logs that are kept -->
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>200MB
</maxFileSize> <!-- The size of the logfile that triggers a switch to a new logfile, and the current one archived -->
</triggeringPolicy>
</appender>

<!--audit log-->
<appender name="audit" class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>log/audit.log.json</file> <!-- logfile location -->
<encoder>
<pattern>%msg%n</pattern> <!-- the layout pattern used to format log entries -->
<immediateFlush>true</immediateFlush>
</encoder>
<rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
<fileNamePattern>log/audit.log.json.%i.zip</fileNamePattern>
<minIndex>1</minIndex>
<maxIndex>5</maxIndex> <!-- max number of archived logs that are kept -->
</rollingPolicy>
<triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>200MB
</maxFileSize> <!-- The size of the logfile that triggers a switch to a new logfile, and the current one archived -->
</triggeringPolicy>
</appender>

<root level="info">
<appender-ref ref="stdout"/>
<appender-ref ref="stdout-file"/>
</root>

<logger name="Audit" level="info" additivity="false">
<appender-ref ref="audit"/>
</logger>

<logger name="com.networknt" level="trace" additivity="false">
<appender-ref ref="stdout"/>
</logger>

<logger name="io.undertow.server.handlers.proxy" level="trace" additivity="false">
<appender-ref ref="stdout"/>
</logger>

</configuration>
19 changes: 19 additions & 0 deletions config/server-proxy-isoxml/rules.yml
Original file line number Diff line number Diff line change
@@ -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
174 changes: 174 additions & 0 deletions config/server-proxy-isoxml/values.yml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 35257a2

Please sign in to comment.