Why the server gives 500-a-Boo while attempting to pull record by id via REST?

0 like 0 dislike
I have the app A on Tomcat, the application B on WildFly. The problem is this: application A has three REST controller that:
  1. Return a list of all schedules for today
  2. Give a specific schedule id
  3. Return a list of all stations

When I run both applications, application B pulls out first a list of all the train schedules for today.

But now consider this use-case. In Appendix A changing a schedule (add new entry). A sends a message through the broker (RabbitMQ) B. Application B receives the message and attempts to pull a new schedule through the REST controller is the first application on id-shnik. And exactly here is the problem.

So, let's first show the code for the REST controller:
@RestController public class BoardScheduleController { private static final Logger LOGGER = Logger.getLogger(BoardScheduleController.class); @Autowired ScheduleService scheduleService; @Autowired StationService stationService; @GetMapping("/api/board/schedule/today") public ResponseEntity<?> getSchedulesForToday() { List schedules = null; try { schedules = scheduleService.getAllForToday(); } catch (ParseException e) { e.printStackTrace(); } LOGGER.info("RETRIEVED" + schedules.size() + "RECORDS"); return ResponseEntity.ok(schedules); } @GetMapping("/api/board/stations") public ResponseEntity<?> getStationList() { List stations = stationService.getAll(); LOGGER.info("RETRIEVED" + stations.size() + "RECORDS"); return ResponseEntity.ok(stations); } @GetMapping("/api/board/schedule/{id}") public ResponseEntity<?> getScheduleById(@PathVariable Long id) { ScheduleDTO schedule = scheduleService.getByIdScheduleDTO(id); LOGGER.info("DTO:" + schedule.getStationDepartureName() + "-> " + schedule.getStationArrivalName() + " (" + schedule.getDateDeparture() + "--> " + schedule.getDateArrival() + ")"); LOGGER.info("RETRIEVED" + schedule + "SCHEDULER"); return ResponseEntity.ok(schedule); } }

So, when the service-layer of the first application is sent a message indicating that there was a schedule change (created new). Then when it successfully reads a messageListener, the second application tries to pull it by id (id of new record I passed in the message as a string).

In the logs it is evident that it reads:
INFO 2018-10-12 22:49:33,799 [pool-9-thread-4] com.slandshow.helpers.Listener [x] Received 'create id=46' INFO 2018-10-12 22:49:33,800 [pool-9-thread-4] com.slandshow.helpers.Listener - create id=46

Now trying to get this record through the REST at id = 46:
public Schedule getById(Long id) { String response = getResultResponse(Utils.URL_SCHEDULE_BY_ID + id); Schedule Schedule = null; try { log.info(response); schedule = objectMapper.readValue(response, new TypeReference() { }); } catch (IOException e) { log.error("ERROR, CAN't LOAD SCHEDULE BY ID" + e.getMessage()); } return schedule; } ... // Inside the Loader class using this function to get JSON from REST at private String getResultResponse(String URL) { WebResource webResource = client.resource(URL); return webResource.accept(MediaType.APPLICATION_JSON).get(ClientResponse.class).GetEntity method(String.class); }

Well, Yes, within the second application uses the disk Schedule:
public class Schedule implements Serializable { private Long id; private String dateDeparture; private String dateArrival; private String trainName; private String stationDepartureName; private String stationArrivalName; private Integer price; /* Getters & setters */ public Long getId() { return id; } public void setId(Long id) { this.id = id; } public String getDateDeparture() { return dateDeparture; } public void setDateDeparture(String dateDeparture) { this.dateDeparture = dateDeparture; } public String getDateArrival() { return dateArrival; } public void setDateArrival(String dateArrival) { this.dateArrival = dateArrival; } public String getTrainName() { return trainName; } public void setTrainName(String train) { this.trainName = trainName; } public String getStationDepartureName() { return stationDepartureName; } public void setStationDepartureName(String stationDeparture) { this.stationDepartureName = stationDeparture; } public String getStationArrivalName() { return stationArrivalName; } public void setStationArrival(String stationArrival) { this.stationArrivalName = stationArrival; } public Integer getPrice() { return price; } public void setPrice(Integer price) { this.price = price; } }

So, when you retriving data via REST, I get requestor 500-ku. Rather, I get a string representation of a page with 500-Oh, where it says:
java.lang.IllegalArgumentException: source cannot be null

Don't know what's wrong? REST controller should work correctly, because the list of trains and schedules it sends, and id can't find (manually checked and indeed it returns valid JSON).
by | 33 views

1 Answer

0 like 0 dislike
If 500, then the server threw an unexpected error, threw an exception. Now look where it arises and see why.
The code is useless, even there is no code where it the exception. In the log you just chewed where the error and which error. Check out how come the data and where they are coming.

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
110,608 questions
257,187 answers
40,796 users