I have a Java Application(REST API, Jersey) that orchestrates a lot of backend calls for the front end.
It aggregates data from all the backend systems and then returns a JSON response.
Now I have to integrate one more backend system, so I added the response from the new backend API into the Aggregate response.
This new data is not super important so I don't want to fail the entire response if this new Call fails.
What is the best elegant way to do this and also inform the clients that one of the calls failed?
Related
I am looking for away to make “internal” rest calls from a service entry point into rest services that are declared in the same war file.
Currently, I am using http connection to localhost. However, I believe dispatching the request directly (with requestDispatcher ?) will be more efficient - no need for connection, no need for extra execution threads, no need to send data via tcp socket, etc.
When I need the “internal” call, I do not know what is the actual object that will represent the payload, or the class/method that will process the request. All I have is the url, and a json string for the payload. I expect the response to be a json string.
Is there a standard method that will work for all rest container (e.g. using the servlet api) or using specific functions of Jersey/spring ?
We struggle to find a solution for the following scenario:
Situation
Receive a message via Spring Cloud Streamlistener
Invoke a REST-Service via Feign-Client
We have configured several Feign-RequestInterceptor to enrich
request header data.
We want to avoid passing every request header on the method call and like the central configuration approach of the request interceptors.
Problem:
How to access data from a specific message, which contains informations, that need to be added to every request call via the Feign-RequestInterceptor.
We don't have a Request-Context, as we come from a message.
Can we be sure , that the message consumption and the REST call is happening on the same thread? If yes, we could use the NamedThreadLocal to store the information.
Yes, unless you hand off to another thread in your StreamListener, the rest call will be made on the same thread (assuming you are using RestTemplate and not the reactive web client).
#marcin
I am doing a pilot on implementing the spring cloud contract for Micro services which has around 50+ services talking to each other. I have few questions which I haven't found the answer precisely in your document.
The service which I am building has controller which processes and transforms my input payload to the desired output in json format. This json is used to build desired structure that should match the response in groovy (Our contract). However the controller, is sending json to another services with some URL as shown below.
request_url=http://localhost:8090/services/rest/transact/v2/pay/validate/0000118228/new response_body=null
Basically it is expecting the Response back from the other service by making use of this json and now response_body=null
My question is do I need to create a stub or mock the service? to make use of this response as an input to produce expected output from the response. Basically the microservice is expecting a ServiceResponse.
Another question is do we need to load in-memory data while doing the contract testing or do we need to just test the controller itself?
I don't really follow your description... "The service which I am building has controller which transforms my input payload sent from groovy and giving the desired output in json format" . Sent from which groovy? Groovy application? Can you explain that in more depth?
But I guess I can try to answer the question anyways...
My question is do I need to create a stub or mock the service? to make use of this response as input to produce expected output from the response. It is expecting a ServiceResponse.
If I understand correctly - service you mean a class not an application? If that's the case then, yes, in the controller I would inject a stubbed service.
Another question is do we need to load in-memory data while doing the contract testing or do we need to just test the controller itself?
That's connected with the previous answer. Your controller doesn't delegate work to any real implementation of a service, so no access to the DB takes place. If you check out the samples (https://github.com/spring-cloud-samples/spring-cloud-contract-samples/blob/master/producer/src/test/java/com/example/BeerRestBase.java) you'll see that the base class has mocks injected to it and no real integration takes place
EDIT:
"The service which I am building has controller which transforms my input payload sent from groovy and giving the desired output in json format" is actually the description of what is done via the Spring Cloud Contract generated test. The next sentence was
However the controller, is sending json to another services with some URL as shown below.
In Contract testing, I don't care what your controller further on does. If it's in the controller where you send the request to some other application then you should wrap it in a service class. Then such a service you would mock out in your contract tests. What we care about in the Contract tests is whether we can communicate. Not whether the whole end to end functionality is working correctly.
I am an aspiring Android Developer, I have faced many issues in integrating my REST apis in Android. Existing solutions like Retrofit, volley are very generic.
I have been working on creating a generic framework for REST apis. Need help to complete it. I have configured components as follows:
Assumptions: Json data type as request body and json data type as request response
CentralCommandClass (activities will access this class to perform network operations with callback method as parameter)
API class extends IntentService (static functions for get, post, put etc to start service with different parameters)
MyHttpRequest (having execute method to open url connection and gets response from server)
My questions are as follows:
Does this approach has any downside?
There is a requirement to fire few requests only after one specific request has been fired, how do I handle this case?
I've been working on a Spring (backend) and ExtJS (UI) application. I am using Spring Data REST to reduce code, with just an interface am able to do CRUD on my web endpoints. The hard nut is getting my event handlers to send JSON response back to my client after an event such as before and after crud. My handlers are registered and working since events are being logged on the console. Now I need to send such a response if create bank is successful
{success:true, 'msg':'Bank created successfully '
Help?
If you take a look at fundamentals, your code would depend on the http response status codes and headers after creation/update/delete requests. Note the headers for resources created. Optionally you could configure to return the content ( RepositoryRestConfiguration.returnBodyOnCreate & RepositoryRestConfiguration.returnBodyOnUpdate) using if you prefer.