master
王兵 4 years ago
parent aeda6699df
commit 0cd097f65c

@ -405,10 +405,11 @@ public class GlobalController {
@PathVariable String target,
@PathVariable String method,
@RequestBody String data,
HttpServletRequest httpServletRequest,
HttpServletResponse httpServletResponse) {
@RequestHeader String token) {
BaseResponse response = new BaseResponse();
LocalData.setToken(MapperUtil.toJava(token,Token.class));
// 开始处理业务
try {
String beanClassName = (ActionConfig.MSVR_PREFIX + module + "/" + target).toLowerCase();

@ -1,17 +1,35 @@
package com.example.config;
package ${domain}.config;
import ${domain}.frame.auth.LocalData;
import ${domain}.frame.utils.MapperUtil;
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpRequest;
import org.springframework.http.client.ClientHttpRequestExecution;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.ClientHttpResponse;
import org.springframework.web.client.RestTemplate;
import java.io.IOException;
import java.util.Collections;
@Configuration
public class CloudConfig {
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
RestTemplate restTemplate = new RestTemplate();
restTemplate.setInterceptors(Collections.singletonList(new ClientHttpRequestInterceptor() {
@Override
public ClientHttpResponse intercept(HttpRequest httpRequest, byte[] bytes, ClientHttpRequestExecution clientHttpRequestExecution) throws IOException {
HttpHeaders headers = httpRequest.getHeaders();
headers.add("token", MapperUtil.toJson(LocalData.getToken()));
return clientHttpRequestExecution.execute(httpRequest, bytes);
}
}));
return restTemplate;
}
}

@ -47,6 +47,7 @@ import ${domain}.module.${moduleName}.rsp.${table.getCName()}${item.getAbbName()
</#if>
</#list>
import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestClientException;
import org.springframework.web.client.RestTemplate;
@ -84,7 +85,7 @@ public class ${table.getCName()}ServiceImpl implements ${table.getCName()}Servic
return response;
}
try {
response = post.postForObject(SERVICE_URL + "create", request, NewTableCreateResponse.class);
response = restTemplate.postForObject(SERVICE_URL + "create", request, NewTableCreateResponse.class);
} catch (RestClientException e) {
response.addError(ErrorType.BUSINESS_ERROR, Message.SERVICE_FAILURE);
}

Loading…
Cancel
Save

Powered by TurnKey Linux.