0

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

Daniel Vai
  • 71
  • 8
  • Its highly likely that you have context after port and before /go. Could you please post what you have on top of the class also? – Sanju Thomas Apr 21 '21 at 18:08
  • I updated the code – Daniel Vai Apr 21 '21 at 18:41
  • RequestParam orderId is missing in the URL that you pasted? – Sanju Thomas Apr 21 '21 at 18:52
  • I said this as an example. The texture is so correct from the service that the api provides. Maybe there is a problem in the method itself. I do not know how to correctly send a third-party service request. – Daniel Vai Apr 21 '21 at 19:19
  • Have u tried debugging? Also where is the stacktrace? – J Asgarov Apr 21 '21 at 19:52
  • Definitely need some more information - eg server logs, stack trace etc. Right now we don't know what the error is so resolving it is going to be very, very difficult. If in doubt with SO questions, it's better to include too much info rather than the opposite – saywhatnow Apr 21 '21 at 20:01
  • { "timestamp": "2021-04-23T16:42:25.583+00:00", "status": 500, "error": "Internal Server Error", "message": "", "path": "/go" } – Daniel Vai Apr 23 '21 at 16:43
  • up cooment, Responce json who comes – Daniel Vai Apr 23 '21 at 16:45
  • it is logging: [nio-8080-exec-2] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is java.lang.NullPointerException] with root cause – Daniel Vai Apr 23 '21 at 16:52

0 Answers0