-
Notifications
You must be signed in to change notification settings - Fork 63
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Spring cloud gateway routing (#3031)
Signed-off-by: Pavel Jareš <pavel.jares@broadcom.com> Signed-off-by: Elena Kubantseva <elena.kubantseva@broadcom.com> Co-authored-by: Elena Kubantseva <elena.kubantseva@broadcom.com>
- Loading branch information
Showing
38 changed files
with
1,282 additions
and
318 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
62 changes: 62 additions & 0 deletions
62
...rc/main/java/org/zowe/apiml/cloudgatewayservice/filters/HeaderRouteStepFilterFactory.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,62 @@ | ||
/* | ||
* This program and the accompanying materials are made available under the terms of the | ||
* Eclipse Public License v2.0 which accompanies this distribution, and is available at | ||
* https://www.eclipse.org/legal/epl-v20.html | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 | ||
* | ||
* Copyright Contributors to the Zowe Project. | ||
*/ | ||
|
||
package org.zowe.apiml.cloudgatewayservice.filters; | ||
|
||
import lombok.Data; | ||
import org.springframework.cloud.gateway.filter.GatewayFilter; | ||
import org.springframework.cloud.gateway.filter.factory.AbstractGatewayFilterFactory; | ||
import org.springframework.stereotype.Service; | ||
|
||
/** | ||
* This filter is responsible to update request header during the routing. The header contain a locator to which server | ||
* route. It could contain also multiple steps separated by /. | ||
* | ||
* In the case header contain multiple steps the filter remove just the first part, otherwise it remove header at all. | ||
* | ||
* Examples: | ||
* "step1/step2/step3" > "step2/step3" | ||
* "node" > null (removed) | ||
*/ | ||
@Service | ||
public class HeaderRouteStepFilterFactory extends AbstractGatewayFilterFactory<HeaderRouteStepFilterFactory.Config> { | ||
|
||
public HeaderRouteStepFilterFactory() { | ||
super(Config.class); | ||
} | ||
|
||
@Override | ||
public GatewayFilter apply(Config config) { | ||
String header = config.getHeader(); | ||
return (exchange, chain) -> { | ||
if (exchange.getRequest().getHeaders().containsKey(header)) { | ||
exchange.mutate().request(request -> exchange.getRequest().mutate().headers(headers -> { | ||
String headerValue = headers.getFirst(header); | ||
int index = headerValue.indexOf("/"); | ||
if ((index >= 0) && (index + 1 < headerValue.length())) { | ||
headers.set(header, headerValue.substring(index + 1)); | ||
} else { | ||
headers.remove(header); | ||
} | ||
})); | ||
} | ||
|
||
return chain.filter(exchange); | ||
}; | ||
} | ||
|
||
@Data | ||
public static class Config { | ||
|
||
private String header; | ||
|
||
} | ||
|
||
} |
62 changes: 0 additions & 62 deletions
62
...y-service/src/main/java/org/zowe/apiml/cloudgatewayservice/service/ProxyRouteLocator.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.