Request Response transformation using freemarker in spring cloud gateway - spring-cloud

I am using spring cloud gateway Hoxton.M1 release to implement an API gateway. I have the following two spring boot apps -
Client <-> Router App <-> Wrapper App <-> Downstream application
Router App - This application has spring cloud gateway. All routes in application.yml point to a common REST controller end point in Wrapper application by passing a request header attribute "apiendpointid" to diff b/w diff api calls. Below is a sample route entry
- id: milestone
uri: http://localhost:5001
predicates:
- Path=/track/milestone
- Method=POST
filters:
- RewritePath=/track/milestone,/gateway/api/internal/process
- AddRequestHeader=apiendpointid,retailmilestone
- AddRequestHeader=appid,retail
- SecureHeaders
Wrapper App - This is a spring boot application which has Rest controller. Controller method does the following -
Identify JSON schema file basis the "apiendpointid" request
header attribute and apply JSON schema validation. Reject request in
case of schema validation failures by return 400 response to router
app.
Identity the freemarker request transformation file basis the "apiendpointid" request header attribute and transform incoming request to downstream expected format.
Send request to downstream.
Transform response from downstream to expected format again using freemarker response template.
Send response back to router app.
This works fine but there is an extra http "hop" from router to wrapper. We have not yet gone live; so not very sure if it will be a performance concern.
Currently wrapper is not built in a reactive way. Also team does not have much expertise in reactive programming. Are there any production implementations built this way (i.e. having this extra wrapper layer/app in the middle) or is it better to integrate all wrapper functionalities into router app itself? If yes, could you please direct me to some examples where request/response transformations/schema validations are being done in spring cloud gateway itself?

Related

Spring Cloud Gateway Custom Filter to Collect Chunks Before Routing

I am using Spring Cloud Gateway to route requests and I am trying to route a request that is sent by the client via POST with Transfer-Encoding: chunked which I want to "collect" all the chunks first before forwarding it as one large payload downstream (essentially removing the chunking). I would presume there's a way to do this by writing a custom filter (i.e., write an implementation of GatewayFilterFactory<T>) to process the http request to wait for all the chunks and create a new body of the combined chunks? Or is this an unrealistic expectation of what Spring Cloud Gateway is capable of?

REST API calls for setting namespace preferences and Program preferences

Can the namespace preferences and program preferences be set via REST API calls? If yes, what is the syntax for it?
Generally in Cloud Data Fusion, when we intend to perform the action on GCP side, like create/delete/restart etc. instance, it's feasible to use domestic Google Cloud API, giving the opportunity to interact with a service endpoint via JSON/HTTP calls interface as described in Google Cloud API design document.
Dedicated to Data Fusion you can follow the Cloud Data Fusion REST API reference document, nicely explaining the methods for composing REST API HTTP calls to manage Data Fusion instances, moreover every method description from the documentation contains Google API Explorer sub-panel, to get handy experience building JSON request on a live data.
Said above, I assume your initial question is related more to CDAP REST API, as it includes the methods for pure CDAP instance metadata/namespaces/application configuration.
From the user perspective your workflow might be the following:
Identify the CDAP API endpoint as explained in this guideline;
Compose an HTTP PUT/GET request relevant to Data Fusion
Namespace/Metadata/Preferences/Configuration
object via CDAP RESTful API.
Yes of course! You have two methods.
The first method is creating it from the platform. Follow the steps below:
Open your data fusion instance
Go to System Admin => Configuration => Make HTTP calls
To create a namespace, submit an HTTP PUT request:
PUT /v3/namespaces/<namespace-id>
Link of CDAP: CDAP
The second method is using terraform.

Spring cloud authentication service

I am trying to develop a system containing microservices. Generally my goal is to have:
1. Some front-end application,
2. Spring cloud gateway,
3. Auth service
4. Resource services
What i'd like gw to do is:
1. Validate token every request,
2. Prevent unauthenticated calls to our services.
What i'd like auth-service to do is:
1. Validate user credentials,
2. Return token is succeded
I have developed a gw instance, with Filter extending AbstractNameValueGatewayFilterFactory what therefore i apply for routes that should be secured.
I have no idea how to implement authentication-service, somehow can't go through security in webflux together with spring cloud. Eventually i want to have something simmilar to:
https://medium.com/omarelgabrys-blog/microservices-with-spring-boot-authentication-with-jwt-part-3-fafc9d7187e8 , but written in reactive approach. Has anyone seen good example for that? Or maybe u know how to do it?

URL design for a proxy API

We have multiple API's running for an enterprise. As per our limitation client will allow only one static IP to receive all Inbound/Outbound requests.
So, we need to expose a single API as a bridge between the client system and API's running behind.
How to approach this design?
How to design the URL for this proxy API?
What edge functions does this API need to provide?
Any help would be highly appreciated. Thanks!
You do not need to use web services consumer, yet will need to create a POC.
Define A RAML with required path and RAML, scaffolding should give you API took kit, and connect an HTTP request
use HTTP request
Examples:
Define Headers --- attributes.headers.id etc
queryParams ---- attributes.queryParams.date
if you are sending JSON payload across from ex: postman, change Mime type to application/json
sample http properties for request
http.host=myHost
http.port=8872
http.base.path=/myproxy/services

How to get URL from request within an action?

I'm writing a HATEOAS-driven REST API and it would be convenient to return responses from some actions with links to other resources.
As the REST API is currently implemented following a monolithic architecture, and in order to not only reduce redundancies but also simplify the job of migrating some parts to microservices, it would be nice if an action could send responses based on the URL that was routed to it.
So, does anyone know if ASP.NET core 2.1 offers any way to access the full URL that's routed to an action when a request is routed to said action?