| | |
| | | import com.java110.core.context.PageData; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.beans.factory.annotation.Autowired; |
| | | import org.springframework.http.HttpStatus; |
| | | import org.springframework.http.ResponseEntity; |
| | | import org.springframework.web.bind.annotation.*; |
| | | import org.springframework.web.client.RestTemplate; |
| | | import org.springframework.web.multipart.MultipartFile; |
| | | |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | public class CallComponentController extends BaseController { |
| | | |
| | | private final static Logger logger = LoggerFactory.getLogger(CallComponentController.class); |
| | | |
| | | @Autowired |
| | | private RestTemplate restTemplate; |
| | | |
| | | /** |
| | | * 调用组件方法 |
| | |
| | | Assert.hasLength(componentCode, "参数错误,未传入组件编码"); |
| | | Assert.hasLength(componentMethod, "参数错误,未传入调用组件方法"); |
| | | |
| | | IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA); |
| | | //权限校验 |
| | | hasPrivilege(restTemplate, pd, "/" + componentCode + "/" + componentMethod); |
| | | |
| | | Object componentInstance = ApplicationContextFactory.getBean(componentCode); |
| | | |
| | | Assert.notNull(componentInstance, "未找到组件对应的处理类,请确认 " + componentCode); |
| | |
| | | |
| | | Assert.notNull(cMethod, "未找到组件对应处理类的方法,请确认 " + componentCode + "方法:" + componentMethod); |
| | | |
| | | IPageData pd = (IPageData) request.getAttribute(CommonConstant.CONTEXT_PAGE_DATA); |
| | | |
| | | logger.debug("组件编码{},组件方法{},pd 为{}", componentCode, componentMethod, pd.toString()); |
| | | |
| | |
| | | Assert.hasLength(componentCode, "参数错误,未传入组件编码"); |
| | | Assert.hasLength(componentMethod, "参数错误,未传入调用组件方法"); |
| | | |
| | | pd = freshPageDate(request); |
| | | //权限校验 |
| | | hasPrivilege(restTemplate, pd, "/" + componentCode + "/" + componentMethod); |
| | | |
| | | Object componentInstance = ApplicationContextFactory.getBean(componentCode); |
| | | |
| | | Assert.notNull(componentInstance, "未找到组件对应的处理类,请确认 " + componentCode); |
| | |
| | | Method cMethod = componentInstance.getClass().getDeclaredMethod(componentMethod, IPageData.class, MultipartFile.class); |
| | | |
| | | Assert.notNull(cMethod, "未找到组件对应处理类的方法,请确认 " + componentCode + "方法:" + componentMethod); |
| | | pd = freshPageDate(request); |
| | | |
| | | |
| | | logger.debug("组件编码{},组件方法{},pd 为{}", componentCode, componentMethod, pd.toString()); |
| | | |
| | | responseEntity = (ResponseEntity<String>) cMethod.invoke(componentInstance, pd, uploadFile); |
| | | |
| | | } catch (SMOException e) { |
| | | logger.error("组件运行异常",e); |
| | | logger.error("组件运行异常", e); |
| | | /*MultiValueMap<String, String> headers = new HttpHeaders(); |
| | | headers.add("code", e.getResult().getCode());*/ |
| | | responseEntity = new ResponseEntity<>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); |
| | | } catch (Exception e) { |
| | | logger.error("组件运行异常",e); |
| | | logger.error("组件运行异常", e); |
| | | String msg = ""; |
| | | if (e instanceof InvocationTargetException) { |
| | | Throwable targetEx = ((InvocationTargetException) e).getTargetException(); |
| | |
| | | try { |
| | | Assert.hasLength(componentCode, "参数错误,未传入组件编码"); |
| | | Assert.hasLength(componentMethod, "参数错误,未传入调用组件方法"); |
| | | pd = freshPageDate(request); |
| | | |
| | | hasPrivilege(restTemplate, pd, "/" + componentCode + "/" + componentMethod); |
| | | |
| | | |
| | | Object componentInstance = ApplicationContextFactory.getBean(componentCode); |
| | | |
| | |
| | | Method cMethod = componentInstance.getClass().getDeclaredMethod(componentMethod, IPageData.class); |
| | | |
| | | Assert.notNull(cMethod, "未找到组件对应处理类的方法,请确认 " + componentCode + "方法:" + componentMethod); |
| | | pd = freshPageDate(request); |
| | | responseEntity = (ResponseEntity<Object>) cMethod.invoke(componentInstance, pd); |
| | | |
| | | } catch (SMOException e) { |
| | | logger.error("组件运行异常",e); |
| | | logger.error("组件运行异常", e); |
| | | responseEntity = new ResponseEntity<Object>(e.getMessage(), HttpStatus.INTERNAL_SERVER_ERROR); |
| | | } catch (Exception e) { |
| | | logger.error("组件运行异常",e); |
| | | logger.error("组件运行异常", e); |
| | | String msg = ""; |
| | | if (e instanceof InvocationTargetException) { |
| | | Throwable targetEx = ((InvocationTargetException) e).getTargetException(); |
| | |
| | | reqData = paramObj.toJSONString(); |
| | | } |
| | | |
| | | IPageData newPd = PageData.newInstance().builder(pd.getUserId(), pd.getToken(), |
| | | reqData, pd.getComponentCode(), pd.getComponentMethod(), "", pd.getSessionId(),""); |
| | | IPageData newPd = PageData.newInstance().builder(pd.getUserId(),pd.getUserName(), pd.getToken(), |
| | | reqData, pd.getComponentCode(), pd.getComponentMethod(), "", pd.getSessionId(), ""); |
| | | return newPd; |
| | | } |
| | | |
| | | |
| | | public RestTemplate getRestTemplate() { |
| | | return restTemplate; |
| | | } |
| | | |
| | | public void setRestTemplate(RestTemplate restTemplate) { |
| | | this.restTemplate = restTemplate; |
| | | } |
| | | } |