Rev 22931 | Rev 23568 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
package com.spice.profitmandi.web.controller;import java.util.HashMap;import java.util.Map;import javax.servlet.http.HttpServletRequest;import org.apache.http.conn.HttpHostConnectException;import org.slf4j.Logger;import org.slf4j.LoggerFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Value;import org.springframework.http.MediaType;import org.springframework.http.ResponseEntity;import org.springframework.stereotype.Controller;import org.springframework.web.bind.annotation.PathVariable;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import com.google.gson.Gson;import com.spice.profitmandi.common.enumuration.SchemeType;import com.spice.profitmandi.common.exception.ProfitMandiBusinessException;import com.spice.profitmandi.common.model.ProfitMandiConstants;import com.spice.profitmandi.common.web.client.RestClient;import com.spice.profitmandi.common.web.util.ResponseSender;import com.spice.profitmandi.web.res.EntityResponse;import io.swagger.annotations.ApiImplicitParam;import io.swagger.annotations.ApiImplicitParams;import io.swagger.annotations.ApiOperation;@Controllerpublic class EntityController {private static final Logger logger=LoggerFactory.getLogger(EntityController.class);@Value("${saholic.api.host}")private String host;@Value("${saholic.api.port}")private int port;@Value("${saholic.api.webapp}")private String webapp;@Autowiredprivate ResponseSender<?> responseSender;@RequestMapping(value = ProfitMandiConstants.URL_ENTITY, method=RequestMethod.GET,produces = MediaType.APPLICATION_JSON_VALUE)@ApiImplicitParams({@ApiImplicitParam(name = "Auth-Token", value = "Auth-Token",required = true, dataType = "string", paramType = "header")})@ApiOperation(value = "Get entity content")public ResponseEntity<?> getEntity(HttpServletRequest request, @PathVariable(value="entityId") String entityId)throws ProfitMandiBusinessException{logger.info("Entity Id "+entityId);RestClient rc = new RestClient();Map<String, String> params = new HashMap<String, String>();String response = null;String uri = webapp+"/entity/"+entityId;EntityResponse entityResponse=null;try {response = rc.get(SchemeType.HTTP, host , port, uri, params);} catch (HttpHostConnectException e) {throw new ProfitMandiBusinessException("", "", "Could not connect to host");}Gson gson = new Gson();entityResponse = gson.fromJson(response, EntityResponse.class);return responseSender.ok(entityResponse);}}