com.infusers.core.user.RemoteUserService Maven / Gradle / Ivy
package com.infusers.core.user;
import java.net.URL;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import com.infusers.core.user.dto.UserDetailsDto;
import com.infusers.core.util.InfusersUtility;
@Service
public class RemoteUserService {
final Logger log = LogManager.getLogger(RemoteUserService.class);
@Value("${infusers.auth.getuser.endpoint}")
private String userEndpoint;
@Value("${infusers.auth.url}")
private String infusersAuthUrl;
@Value("${myapp.rom.request.mapping}")
private String requestMapping;
@Value("${infusers.token.inter.api.communication}")
private String infuserTokenInterApiCommunication;
public UserDetailsDto getUser(String userName) {
return getUserRemote(userName);
}
private UserDetailsDto getUserRemote(String userName) {
log.debug("RemoteUserService.getUserRemote() :: user name : " + userName);
String urlString = infusersAuthUrl + requestMapping + userEndpoint + userName;
String endpoint = "";
try {
URL url = new URL(urlString);
endpoint = url.toString();
String bearerToken = InfusersUtility.getInstance().getToken(userName);
RestTemplate restTemplate = new RestTemplate();
HttpHeaders requestHeaders = new HttpHeaders();
requestHeaders.setBearerAuth(bearerToken);
requestHeaders.setContentType(MediaType.APPLICATION_JSON);
HttpEntity requestEntity = new HttpEntity<>(null,
requestHeaders);
ResponseEntity userDto = restTemplate.exchange(endpoint, HttpMethod.GET, requestEntity, UserDetailsDto.class);
return userDto.getBody();
}
catch (Exception e) {
log.error("RemoteUserService.getUserRemote()" + e.getMessage());
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy