i want to use spring cloud gateway to intercept a rest request and route it to a soap…
- User
i want to use spring cloud gateway to intercept a rest request and route it to a soap endpoint over jms, then i need to convert the soap response in http and return it. Is it possible to call a service which makes the soap call and put it in a filter inside the gateway ? provide me an example
- Assistant
- User
and how would look the code which has the filters and the routing?
- Assistant
Here is an example of how you can configure the filters and routing in Spring Cloud Gateway:
- User
i have this endpoint which has a pathvariable, but i want to pass as "uri" a stringified uri like this:/ESB/Service/FinanceAccnt/Overall/VATIdentNumber-001 . This is my controller: @GetMapping("/{uri}") public String hello(@PathVariable() String uri){ System.out.println(uri); XmlUtilitiesImpl impl = new XmlUtilitiesImpl(); RoutingElement element = impl.extractElementsFromFile(XmlUtilities.PATH_XML_FILE).get(uri); return element.toString(); }
I get 404 error because it tries to look for that full path which does not exist, how can i read this path in a controller without passing it inside the body?
- Assistant
To handle the stringified URI in your controller without passing it inside the request body, you can modify your controller method to read the stringified URI from the query parameter. Here's an updated version of your controller:
@GetMapping public String hello(@RequestParam("uri") String uri) { System.out.println(uri); XmlUtilitiesImpl impl = new XmlUtilitiesImpl(); RoutingElement element = impl.extractElementsFromFile(XmlUtilities.PATH_XML_FILE).get(uri); return element.toString(); }In this updated code, we changed the
@PathVariableannotation to@RequestParam("uri")to read the stringified URI from the query parameter instead of the path variable. Now you can pass the URI as a query parameter in your request, like this:/your-endpoint?uri=/ESB/Service/FinanceAccnt/Overall/VATIdentNumber-001.By doing this, the Spring framework will correctly read the stringified URI from the query parameter, allowing you to process it in your controller method without causing a 404 error due to the nonexistent path.
- User
how should i call the endpoint to avoid getting 404?
- Assistant
To call the modified endpoint and avoid getting a 404 error, you need to pass the URI as a query parameter in your request. Here's an example of how you can call the endpoint using cURL:
curl -X GET 'http://localhost:8080/your-endpoint?uri=/ESB/Service/FinanceAccnt/Overall/VATIdentNumber-001'In this example, replace
your-endpointwith the actual endpoint URL in your application.Alternatively, if you are using a web browser or a tool like Postman, you can construct the request URL with the query parameter. For example:
http://localhost:8080/your-endpoint?uri=/ESB/Service/FinanceAccnt/Overall/VATIdentNumber-001Make sure to adjust the hostname and port accordingly based on your application's configuration.
By specifying the URI as a query parameter in the request, you can successfully call the endpoint without receiving a 404 error.