Skip to content

Commit

Permalink
String has been replaced with JsonArray
Browse files Browse the repository at this point in the history
  • Loading branch information
Vitaly Ustinov committed May 13, 2016
1 parent 1de05d8 commit 55b80b9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package com.ericsson.eiffel.remrem.producer.controller;

import com.google.gson.JsonArray;
import com.google.gson.JsonElement;

import com.ericsson.eiffel.remrem.producer.helper.ResponseHelper;
import com.ericsson.eiffel.remrem.producer.service.MessageService;
import com.ericsson.eiffel.remrem.producer.service.SendResult;
import com.google.gson.Gson;
import com.google.gson.reflect.TypeToken;
import lombok.extern.slf4j.Slf4j;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.RequestBody;
Expand All @@ -15,9 +16,10 @@
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.List;

import lombok.extern.slf4j.Slf4j;

@Slf4j @RestController @RequestMapping("/producer") public class ProducerController {

Expand All @@ -26,12 +28,14 @@

@RequestMapping(value = "/msg", method = RequestMethod.POST) @ResponseBody
public List<String> send(@RequestParam(value = "rk", required = true) String routingKey,
@RequestBody String body) {
@RequestBody JsonArray body) {
log.debug("routingKey: " + routingKey);
log.debug("body: " + body);
Type type = new TypeToken<List<String>>() {
}.getType();
List<String> msgs = new Gson().fromJson(body, type);

List<String> msgs = new ArrayList<>();
for (JsonElement obj : body) {
msgs.add(obj.toString());
}
List<SendResult> results = messageService.send(routingKey, msgs);
return responseHelper.convert(results);
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,5 @@ logging.level.com.ericsson.eiffel.remrem.producer=ERROR
#rabbitmq.host=127.0.0.1
# must exist
#rabbitmq.exchange.name=eiffel.poc

spring.http.converters.preferred-json-mapper=gson

0 comments on commit 55b80b9

Please sign in to comment.