Spring integration and Microservice communication - spring

I am pretty new to Spring Integration. I have an application written in spring integration which does a rest call to my microservice(spring boot application)
The request is a pure String and the request message(header+payload) has content type set as TEXT_PLAIN and my microservice's controller consumes as mediatype.PLAIN_TEXT_VALUE
When initiate a request to the microservice from the spring integration application it is throwing an error as "unsupported type"
Why does it throw error and what other alternative do i have?
I do not want or can't have JSON as request or response. It is just an unformatted string as input and a formatted string as output

Related

Java client for streaming Data with Spring Boot using StreamingResponseBody

A spring rest endpoint to stream data seems to be programmed rather straigthforward using a StreamingResponseBody (example). Could anybody point me to a resource on how to write a client in java (another spring app)?
You must consume the data as any other web resource, for example with spring :
String value = new RestTemplate().getForObject("https://someuri.com", String.class);

Consume Kafka Messages and Post to REST API using Spring Boot

I have below the requirement to be implemented in Spring Boot.
How to achieve this?
Consume a message from a topic and Transform the message fields for the REST API
POST it to a REST API via HTTP or HTTPs.
Capture the API response.
Record any errors while posting the message.
You can use Spring Kafka or Spring Cloud Stream with Kafka binder to receive the message.
It will deserialize it you, then you can transfrom it to object you want.
Then you can use (inject) RestTemplate (or Webclient for reactive) to post the message. It will send the message and receive the response. For error handling, you can use the default ones via try/catch, or implement your own by implementing ResponseErrorHandler .
Some useful links:
RestTemplate
RestTemplate Error handling
Spring Kafka

Using Gateway to consume Spring Boot application from Spring Integration application

I am just starting with Spring Integration with Spring Boot 2.
I am working on a application which uses Spring Integration's HTTP outbound gateway to consume a Spring boot Service.
I am consuming the spring boot service from Spring Integration application using Gateway.
When I call the Gateway method which in turn will use the outbound gateway to call the spring boot service, the request does not seem to be completed. It is just going on when I make the HTTP GET request via the browser.
The request is also not received by the Spring Boot service.
I am not able to identify what is wrong in my Integration application when using gateway to consume a Spring Boot 2 service.
I have shared my Spring Boot 2 Application and also the Integration application which I am using to consume it in the below github folder. it contains 2 folders, one for the spring Integration application and the other for the spring boot application.
https://github.com/gsamartian/spring-int-demos
I have exposed a REST interface for the Integration application using RestController.
I access the boot application from integration application via the url, http://localhost:8763/callExternalServiceViaGateway
I am able to access the spring boot application directly from its port.
If anyone can help me identify the cause it would be great.
Thanks,
Your problem that the gateway method is without any args:
#Gateway(requestChannel = "get.request.channel", replyChannel = "reply.channel")
String getCustomMessage();
In this case the gateway works as receiving. No any requests is send because nothing to wrap to the payload. See more info on the matter in the Reference Manual.
Right now I see several bugs with the payloadExpression and no arg, so I suggest you to add some String payload arg to the getCustomMessage() gateway method and perform it with an empty string.
Will take a look into the bugs and will fix them soon.
Thank you for a good sample how to catch and reproduce!
https://jira.spring.io/browse/INT-4448
https://jira.spring.io/browse/INT-4449

Spring Integration webservice outbound gateway - capturing request and response to DB with additional values

I am using Spring integration WS 2.2 outbound gateway to invoke a webservice.
One of our requirement is to capture the soap request and response xmls to the database in addition to some other values like transaction id etc.
If i use ClientInterceptor to save the request/response to DB, it only has access to the soap request and the response but not to the values like transaction Id. So is there a way to retrieve and return the soap request and response from the interceptor OR a way to pass custom values to the interceptor?
Thanks

custom HTTP status code with spring and restful webservice

I am new to the spring and restful framework. My server hosts 3 restful web services. I have used spring support for the restful web services to implement the server. The client sends JSON request to the server and gets JSON response. Client is based on spring support for the restful. The server returns 200/OK for successful processing, which is default.
What I want is the server to send custom HTTP status code 550 to the client in case there is an issue while processing the request. It should not throw any exception to the client. It should only send 550/an_error_object(as json) back to the client.
How is it possible with the spring support of restful ? I am doing the following on the server side.
HttpServletResponse.setStatus(550)
but, the client side is failing to recognize the status code 550; it throws an exception since org.springframework.http.HttpStatus doesn't have any enum constant '550' defined.
Any suggestions will be great!
Thanks in advance.
Rohit
1) Don't use unregistered status codes. See the registered status codes.
2) That being said, that's a bug in the Spring framework. It should deal properly with extension status codes.
It'll probably going to be fixed in version 4.3 of Spring.
https://jira.spring.io/browse/SPR-14205

Resources