|
1 | 1 | package com.ericsson.eiffel.remrem.producer.controller;
|
2 | 2 |
|
| 3 | +import com.google.gson.JsonArray; |
| 4 | +import com.google.gson.JsonElement; |
| 5 | + |
3 | 6 | import com.ericsson.eiffel.remrem.producer.helper.ResponseHelper;
|
4 | 7 | import com.ericsson.eiffel.remrem.producer.service.MessageService;
|
5 | 8 | import com.ericsson.eiffel.remrem.producer.service.SendResult;
|
6 |
| -import com.google.gson.Gson; |
7 |
| -import com.google.gson.reflect.TypeToken; |
8 |
| -import lombok.extern.slf4j.Slf4j; |
| 9 | + |
9 | 10 | import org.springframework.beans.factory.annotation.Autowired;
|
10 | 11 | import org.springframework.beans.factory.annotation.Qualifier;
|
11 | 12 | import org.springframework.web.bind.annotation.RequestBody;
|
|
15 | 16 | import org.springframework.web.bind.annotation.ResponseBody;
|
16 | 17 | import org.springframework.web.bind.annotation.RestController;
|
17 | 18 |
|
18 |
| -import java.lang.reflect.Type; |
| 19 | +import java.util.ArrayList; |
19 | 20 | import java.util.List;
|
20 | 21 |
|
| 22 | +import lombok.extern.slf4j.Slf4j; |
21 | 23 |
|
22 | 24 | @Slf4j @RestController @RequestMapping("/producer") public class ProducerController {
|
23 | 25 |
|
|
26 | 28 |
|
27 | 29 | @RequestMapping(value = "/msg", method = RequestMethod.POST) @ResponseBody
|
28 | 30 | public List<String> send(@RequestParam(value = "rk", required = true) String routingKey,
|
29 |
| - @RequestBody String body) { |
| 31 | + @RequestBody JsonArray body) { |
30 | 32 | log.debug("routingKey: " + routingKey);
|
31 | 33 | log.debug("body: " + body);
|
32 |
| - Type type = new TypeToken<List<String>>() { |
33 |
| - }.getType(); |
34 |
| - List<String> msgs = new Gson().fromJson(body, type); |
| 34 | + |
| 35 | + List<String> msgs = new ArrayList<>(); |
| 36 | + for (JsonElement obj : body) { |
| 37 | + msgs.add(obj.toString()); |
| 38 | + } |
35 | 39 | List<SendResult> results = messageService.send(routingKey, msgs);
|
36 | 40 | return responseHelper.convert(results);
|
37 | 41 | }
|
|
0 commit comments