Commit bf722d5c by Jason Song

return users assigned and adjust rest template timeout

parent 78912008
package com.ctrip.framework.apollo.common.auth;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
import com.google.common.io.BaseEncoding;
import org.apache.http.Header;
import org.apache.http.auth.AuthScope;
......@@ -19,7 +17,9 @@ import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Component;
import org.springframework.web.client.RestTemplate;
import com.google.common.io.BaseEncoding;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.Collection;
@Component
public class RestTemplateFactory implements FactoryBean<RestTemplate>, InitializingBean {
......@@ -54,7 +54,11 @@ public class RestTemplateFactory implements FactoryBean<RestTemplate>, Initializ
.setDefaultHeaders(defaultHeaders).build();
restTemplate = new RestTemplate(httpMessageConverters.getConverters());
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory(httpClient));
HttpComponentsClientHttpRequestFactory requestFactory =
new HttpComponentsClientHttpRequestFactory(httpClient);
requestFactory.setConnectTimeout(3000);
requestFactory.setReadTimeout(10000);
restTemplate.setRequestFactory(requestFactory);
}
}
......@@ -12,6 +12,8 @@ import org.springframework.core.ParameterizedTypeReference;
import org.springframework.http.HttpEntity;
import org.springframework.http.HttpMethod;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.ClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.util.CollectionUtils;
import org.springframework.web.client.RestTemplate;
......@@ -31,13 +33,20 @@ public class CtripUserService implements UserService {
public CtripUserService(ServerConfigService serverConfigService) {
this.serverConfigService = serverConfigService;
this.restTemplate = new RestTemplate();
this.restTemplate = new RestTemplate(clientHttpRequestFactory());
this.searchUserMatchFields =
Lists.newArrayList("empcode", "empaccount", "displayname", "c_name", "pinyin");
this.responseType = new ParameterizedTypeReference<Map<String, List<UserServiceResponse>>>() {
};
}
private ClientHttpRequestFactory clientHttpRequestFactory() {
SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
factory.setReadTimeout(3000);
factory.setConnectTimeout(5000);
return factory;
}
@Override
public List<UserInfo> searchUsers(String keyword, int offset, int limit) {
UserServiceRequest request = assembleSearchUserRequest(keyword, offset, limit);
......
......@@ -87,9 +87,12 @@ public class RolePermissionService implements InitializingBean {
/**
* Assign role to users
*
* @return the users assigned roles
*/
@Transactional
public void assignRoleToUsers(String roleName, Set<String> userIds, String operatorUserId) {
public Set<String> assignRoleToUsers(String roleName, Set<String> userIds,
String operatorUserId) {
Role role = findRoleByRoleName(roleName);
Preconditions.checkState(role != null, "Role %s doesn't exist!", roleName);
......@@ -110,6 +113,7 @@ public class RolePermissionService implements InitializingBean {
});
userRoleRepository.save(toCreate);
return toAssignUserIds;
}
/**
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment