Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error when making call with content type application/xml #652

Closed
LucasAndersson opened this issue Nov 12, 2018 · 2 comments
Closed

Error when making call with content type application/xml #652

LucasAndersson opened this issue Nov 12, 2018 · 2 comments

Comments

@LucasAndersson
Copy link

LucasAndersson commented Nov 12, 2018

Hi

I'm building a gateway that will receive XML, map it to JSON, call an underlying external service using said JSON and then return a XML response to the gateway caller. I've set up a simple route that modifies the path, request and response bodies. When I call my gateway I get this response back:

{ "timestamp": "2018-11-12T15:43:22.621+0000", "path": "/v1/reserve", "status": 500, "error": "Internal Server Error", "message": "Content type 'application/xml' not supported" }

Does Spring Cloud Gateway not support XML? How do you propose that I deal with this problem?

@spencergibb
Copy link
Member

There's nothing specific in gateway for any content type. Can you explain how to reproduce the problem? What versions are you using? What is your configuration?

@spencergibb spencergibb changed the title XML support Error when making call with content type application/xml Nov 12, 2018
@LucasAndersson
Copy link
Author

LucasAndersson commented Nov 13, 2018

Thank you for the quick response Spencer!
I created a public github repo with a minimal example:

https://github.com/LucasAndersson/spring-cloud-gateway-xml-demo

curl -X POST "http://localhost:8080/post" -H "content-type:application/xml" -d '<foo>bar</foo>'
{"timestamp":"2018-11-13T09:35:22.496+0000","path":"/post","status":500,"error":"Internal Server Error","message":"Content type 'application/xml' not supported"}

I also tried serializing to a json string using jackson like this:

.modifyRequestBody(GatewayRequest.class, String.class, (s, g) ->
                                {
                                    DownstreamRequest downstreamRequest = new DownstreamRequest();
                                    downstreamRequest.setBar(g.getFoo());

                                    try
                                    {
                                        return Mono.just(new ObjectMapper().writeValueAsString(downstreamRequest));
                                    } catch (JsonProcessingException e)
                                    {
                                        return Mono.error(e);
                                    }
                                }

With that approach I get a slightly different error:

curl -X POST "http://localhost:8080/post" -H "content-type:application/xml" -d '<foo>bar</foo>'
{"timestamp":"2018-11-13T09:40:53.745+0000","path":"/post","status":415,"error":"Unsupported Media Type","message":"Content type 'application/xml' not supported"}

I created my project using Spring Initializr, however I had to downgrade to Finchley.RELEASE version of Spring Cloud and 2.0.6.RELEASE version of Spring Boot because of the issue described here: #577

What I'm trying to achieve is to receive an XML payload in my gateway, map it to a different model and pass it downstream as JSON, map the response from the downstream service (which is also JSON) to a different model and return it to the gateway caller as XML. In my example I've only added a filter to modify the request body, I never seem to reach the downstream service so I thought it would be irrelevant to include a filter to modify the response.

There will be 4 different models involved, the gateway request/response (which should be (de)serialized as XML) and the downstream service request/response (which should be (de)serialized as JSON).

Johnny850807 pushed a commit to Johnny850807/spring-cloud-gateway that referenced this issue Dec 14, 2020
…ing-cloud#652)

* Add each PropertySource from PropertySourceLocators individually instead of as a CompositePropertySource.  Fixes spring-cloud#611
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants