| 21574 |
ashik.ali |
1 |
package com.spice.profitmandi.web.util;
|
|
|
2 |
|
|
|
3 |
import java.util.HashMap;
|
|
|
4 |
import java.util.Map;
|
|
|
5 |
|
|
|
6 |
import org.slf4j.Logger;
|
|
|
7 |
import org.slf4j.LoggerFactory;
|
|
|
8 |
import org.springframework.stereotype.Component;
|
|
|
9 |
|
|
|
10 |
import com.fasterxml.jackson.core.JsonProcessingException;
|
|
|
11 |
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
|
12 |
import com.spice.profitmandi.common.ResponseCodeHolder;
|
|
|
13 |
|
|
|
14 |
@Component
|
|
|
15 |
public class MVCResponseSender {
|
|
|
16 |
|
|
|
17 |
private ObjectMapper objectMapper = new ObjectMapper();
|
|
|
18 |
|
|
|
19 |
private static final Logger LOGGER = LoggerFactory.getLogger(MVCResponseSender.class);
|
|
|
20 |
|
|
|
21 |
public String createResponseString(String responseCode, boolean status, String redirectUrl) throws Exception{
|
|
|
22 |
Map<String, Object> response = new HashMap<>();
|
|
|
23 |
response.put("message", ResponseCodeHolder.getMessage(responseCode));
|
|
|
24 |
response.put("status", status);
|
|
|
25 |
response.put("redirectUrl", redirectUrl);
|
|
|
26 |
try {
|
|
|
27 |
return objectMapper.writeValueAsString(response);
|
|
|
28 |
} catch (JsonProcessingException e) {
|
|
|
29 |
LOGGER.error("Error occured while converting response to json", e);
|
|
|
30 |
throw e;
|
|
|
31 |
}
|
|
|
32 |
}
|
|
|
33 |
}
|