WCF service(Let's say WCF1) is calling a Web API which internally receives data from another WCF service(Let's say WCF2). WCF1 receives JSON response and converts it to the response object. But problem is response object has properties which are somewhat different from WCF2 service.
My question is do I need to create same response object as WCF2 or there is a more convenient way to achieve this?
Related
I had an application that is running with servelets. I want to test that application using REST services or POSTMAN.
So, I want to know, whether it could be possible to convert a servelet application's request and response into JSON for testing it with Postman or REST services.
If this possible, how do I do this conversion?
Some context would be helpful. What does the request to your application look like?
You don't need to convert an application's request / response into JSON to use postman. Postman is pretty flexible, you can send a variety of request content types to your application.
As far as whether or not this is possible, absolutely. If you want to convert your request & response objects to JSON, consider using something like Jackson. You can use the ObjectMapper of this tool to go from JSON to POJO & vice versa
I can register a so called webhook in JIRA if I want JIRA to inform an external application about changes. Some JSON is generated when an issue is changed and sent to the webhook.
Is this JSON ...just a Stirng...or is it the representation of a specific Java class? If this would be the case: which class is it?
Or: how to I have to handle this JSON when it is sent to my SpringBoot application (webhook)? Just as a String or can I map this JSON via Jackson to a particular class...and how do I have to do this?
A callback for an issue-related event is structured like this...
I have a simple Spring boot project that uses controller mappings to get hard coded information from a class in my project.
For example, if I run the request : localhost:8080/topics, A JSON response is returned with the list of Topic Objects that i have previously created
I want to take this one step further and have a class who's variables are populated by calling this API and parsing the response : https://www.alphavantage.co/query?function=TIME_SERIES_INTRADAY&symbol=MSFT&interval=1min&apikey=demo
I believe this can be done in Java by creating a HTTP connection and reading the data from an input stream, but is the an easier way of doing this with spring boot? Im not fully sure of the name of this procedure hence Im having trouble finding solutions online
Since you are using Spring Boot, making use of Spring's RestTemplate makes sense. It comes with several message converters out of the box, and uses Jackson by default for json content.
Spring has published a good Getting Started page for consuming RESTful web services.
However, the json content returned by that services doesn't look like it will map well to a Java object, so you may have to deserialize it to a HashMap to get to the data you want.
I did an attempt to create something like this.
https://github.com/StanislavLapitsky/SpringSOAProxy
The idea is to register controller interfaces. Each of the interfaces are mapped to some URL. For the interfaces a dynamic proxy are generated (if the implementations are not available locally). So developer just call controller's interface method. The method is invoked for dynamically generated proxy. The proxy uses RestTemplate to call remote URL. It sends and receive JSON and deserializes the returned JSOn to POJO objects returned from the controller.
You need to declare contract - controller interfaces plus DTO to exchange data as well as mapping to understand which URL should be called for each controller.
I have been creating Spring RESTful services for a while and typically I am building my own services so I create domain objects and populate them and the framework takes care of the conversion to JSON.
I have a situation now where I simply need my service to act as a pass through to another system's service that is already RESTful and returns JSON.
URL https://:/service/serviceInfo
Method GET
HTTP Content Type Produces: application/json
I simply want to wrap this call (I will apply some security checks on the service) and pass that JSON returned straight back to my service without mapping it back to Java objects, only to return as JSON to the client. Is there a simple way to do this, with minimal code?
Thanks in advance.
Can you see if this works for you?
#RequestMapping("/child")
public String testMethod(#RequestParam String param) {
return new RestTemplate().exchange("https://api.twitter.com/1/statuses/user_timeline.json", HttpMethod.GET, null, String.class).getBody();
}
You just replace the url for your own. I can also guide you to using the RestTemplate with POST or DELETE requests etc. if you need. Also adding parameters or headers if you need. I've used it extensively in some projects.
I am using Spring 3.0 and ExtJS. I have been trying to send a Map object from my controller to jsp. When I putting a pojo in HashMap and sending that HashMap to view.
From controller it is returning a Map but in ExtJS it is not able to read the response and gives below error.
HTTP Error code: 406
message
description The resource identified by this request is only capable of generating responses with characteristics not acceptable according to the request "accept" headers ().
Can anyone tell that how this can be resolved?
I dont think you can just shove any POJO into a map and return it via an HttpResponse. That's not how JSON works.
In order to send JSON from Java, you have to do the equivalent of serializing it using a JSON API (or roll your own). FlexJSON is one I use, as it ships in Spring Roo and is pretty easy.