Skip to content

Commit

Permalink
feat($AuthCenter): access other service by RestTemplate
Browse files Browse the repository at this point in the history
  • Loading branch information
Johnny Miller (锺俊) committed Dec 25, 2020
1 parent 2997221 commit f8df08c
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import org.springframework.cloud.client.discovery.DiscoveryClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

import java.util.LinkedHashMap;
import java.util.List;
Expand All @@ -33,7 +34,16 @@ public class PermissionController {
private final DiscoveryClient discoveryClient;
private final HttpApiScanHelper httpApiScanHelper;
private final ProjectProperty projectProperty;
private final RestTemplate restTemplate;

/**
* Services info response body bean.
*
* @return the response body bean
* @author Johnny Miller (锺俊), email: johnnysviva@outlook.com, date: 12/25/2020 5:44 PM
* @see
* <a href='https://github.com/spring-cloud/spring-cloud-netflix/issues/990#issuecomment-214943106'>RestTemplate Excample</a>
*/
@GetMapping("/permissions/services-info")
@ApiOperation(value = "Get services info", notes = "Get services info")
public ResponseBodyBean<?> servicesInfo() {
Expand All @@ -44,6 +54,9 @@ public ResponseBodyBean<?> servicesInfo() {
val instances = discoveryClient.getInstances(service);
log.info("Instances: {}", instances);
resultMap.put(service, instances);
Object httpApiResources = restTemplate.getForObject(
"http://" + service + "/http-api-resources", Object.class);
log.info("httpApiResources: {}", httpApiResources);
});
val httpApiMap = httpApiScanHelper.scan(projectProperty.getBasePackage());
resultMap.put("httpApiMap", httpApiMap.toString());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.jmsoftware.maf.authcenter.universal.configuration;

import org.springframework.cloud.client.loadbalancer.LoadBalanced;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.client.RestTemplate;

/**
* Description: RestTemplateConfiguration, change description here.
*
* @author 钟俊(zhongjun), email: zhongjun@toguide.cn, date: 12/25/2020 5:42 PM
**/
@Configuration
public class RestTemplateConfiguration {
@Bean
@LoadBalanced
public RestTemplate restTemplate() {
return new RestTemplate();
}
}

0 comments on commit f8df08c

Please sign in to comment.