I need to send a request to a third-party service, then get an object from the response and display it on the browser.
package com.statusinfonew.springboot.controller;
import java.util.Collections;
import java.util.List;
import lombok.Data;
import lombok.val;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;
import com.statusinfonew.springboot.model.ParamsPays;
import com.statusinfonew.springboot.service.dto.OpenJsonFormat;
@Controller
@RestController
public class MyRestController {
RestTemplate restTemlate;
@GetMapping({"/"})
public String showGeneralPage(Model model) {
model.addAttribute("general", "Welcome to App");
return "hello";
}
@GetMapping(path = "/go")
public List<ParamsPays> getInfoError(@RequestParam(value="token") String token,
@RequestParam(value="orderId")String orderId){
final String url =String.format("https://exemple.ru/payment/rest/getOrderStatus.do?
token=%s&orderId=%s", token, orderId);
OpenJsonFormat dto =restTemlate.getForObject(url, OpenJsonFormat.class);
return Collections.singletonList(toModel(dto));
}
private ParamsPays toModel(OpenJsonFormat dto) {
return new ParamsPays();
}
package com.statusinfonew.springboot.service.dto;
import java.util.Date;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import lombok.Data;
@Data
public class OpenJsonFormat {
@JsonProperty("actionCode")
private String actionCode;
@JsonProperty("amount")
private String amount;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "dd-MM-yyyy hh:mm:ss")
private Date date;
}
When I enter a get request, an error is issued:
This application has no explicit mapping for /error, so you are seeing this as a fallback.
http://localhost:8080/go?token=sdwggvpa0k4ponpkt9&orderId=6afsf0-a0bc-7ffd-a9a8-790d4s179
Wed Apr 21 21:26:35 SAMT 2021 There was an unexpected error (type=Internal Server Error, status=500).
I understand that I am making a gross mistake. Please help me figure it out