Subversion Repositories SmartDukaan

Rev

Rev 24383 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
21574 ashik.ali 1
package com.spice.profitmandi.web.util;
2
 
3
import com.fasterxml.jackson.core.JsonProcessingException;
4
import com.fasterxml.jackson.databind.ObjectMapper;
5
import com.spice.profitmandi.common.ResponseCodeHolder;
31281 amit.gupta 6
import org.apache.logging.log4j.LogManager;
7
import org.apache.logging.log4j.Logger;
8
import org.springframework.beans.factory.annotation.Autowired;
9
import org.springframework.stereotype.Component;
21574 ashik.ali 10
 
31281 amit.gupta 11
import java.util.HashMap;
12
import java.util.Map;
13
 
21574 ashik.ali 14
@Component
15
public class MVCResponseSender {
31281 amit.gupta 16
 
23568 govind 17
	private static final Logger LOGGER = LogManager.getLogger(MVCResponseSender.class);
31281 amit.gupta 18
	@Autowired
19
	ObjectMapper objectMapper;
20
 
21
	public String createResponseString(String responseCode, boolean status, String redirectUrl) throws Exception {
21574 ashik.ali 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
	}
31281 amit.gupta 33
 
34
	public String createResponseString(String responseCode, boolean status, String redirectUrl, String name) throws Exception {
24383 amit.gupta 35
		Map<String, Object> response = new HashMap<>();
36
		response.put("message", ResponseCodeHolder.getMessage(responseCode));
37
		response.put("status", status);
38
		response.put("redirectUrl", redirectUrl);
39
		response.put("name",name);
40
		try {
41
			return objectMapper.writeValueAsString(response);
42
		} catch (JsonProcessingException e) {
43
			LOGGER.error("Error occured while converting response to json", e);
44
			throw e;
45
		}
46
	}
23405 amit.gupta 47
 
48
	public String createResponseString(Object object) throws Exception {
49
		try {
50
			return objectMapper.writeValueAsString(object);
51
		} catch (JsonProcessingException e) {
52
			LOGGER.error("Error occured while converting response to json", e);
53
			throw e;
54
		}
55
 
56
	}
21574 ashik.ali 57
}