Java Spring RestTemplate身份验证性能问题

Java Spring RestTemplate身份验证性能问题,java,spring,rest,Java,Spring,Rest,我使用SpringRESTTemplate从restful服务器检索对象,并使用拦截器进行基本身份验证。然而,我发现localhost和dev环境之间存在巨大的性能差异 在本地运行客户端和restful服务器时,RestTemplate getForObject需要3秒钟。在本地和DEV中的restful服务器上运行客户机时,需要59秒。我在DEV中的拦截器中做了一些日志记录,restful服务器响应非常快(在1秒内)。导致延迟的原因是getForObject,所以我猜在DEV RestTemp

我使用SpringRESTTemplate从restful服务器检索对象,并使用拦截器进行基本身份验证。然而,我发现localhost和dev环境之间存在巨大的性能差异

在本地运行客户端和restful服务器时,RestTemplate getForObject需要3秒钟。在本地和DEV中的restful服务器上运行客户机时,需要59秒。我在DEV中的拦截器中做了一些日志记录,restful服务器响应非常快(在1秒内)。导致延迟的原因是getForObject,所以我猜在DEV RestTemplate中,将响应主体转换为对象需要很多时间

我在localhost和DEV中进行了相同的调用,因此我希望响应主体的大小相同。有人知道如何提高DEV的性能吗?非常感谢

拦截器:

public class BasicAuthInterceptor implements ClientHttpRequestInterceptor {

public static final Log log = LogFactory.getLog(BasicAuthInterceptor.class);

private String username;
private String password;

public BasicAuthInterceptor( String username, String password ) {
    this.username = username;
    this.password = password;
}

@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution)
        throws IOException {
    //Build the auth-header
    final String auth = username + ":" + password;
    final byte[] encodedAuth = Base64.encodeBase64( auth.getBytes( Charset.forName( "US-ASCII" ) ) );
    final String authHeader = "Basic " + new String( encodedAuth );

    //Add the auth-header
    request.getHeaders().add( "Authorization", authHeader );

    log.info("Sending request to the data server");
    ClientHttpResponse response = execution.execute(request, body);
    log.info("Got response from the data server. Status: " + response.getStatusCode() + " " + response.getStatusText());
    log.info("Response header: " + response.getHeaders());

    return response;
} }
RestTemplate调用:

RestTemplate restTemplate = new RestTemplate();

            final List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
            interceptors.add( new BasicAuthInterceptor( "user", "xxx" ) );
            restTemplate.setInterceptors( interceptors );

            AggregatedCptyExposure[] expoIq = restTemplate.getForObject(fullUrl, AggregatedCptyExposure[].class);
开发人员:


启用spring调试以获取有关提取器花费如此长时间的原因的日志详细信息。验证spring JAR及其依赖项在本地和开发人员之间的版本是否相同。此外,
RestTemplate
是线程安全的,并且拦截器对于所有请求都是相同的。考虑制作<代码> RestMadie,以及它的拦截器,为所有请求共享一个单独的作用域Spring bean。@安德鲁斯-谢谢您的响应!我试图通过向log4j.xml添加
来启用spring调试。但是,我没有获取提取器的日志详细信息。您能告诉我如何正确定义提取器的日志记录吗?它可能是一个依赖项jar,例如jackson。
INFO  09/12 13:41:00.160 {} [pool-6-thread-8] BasicAuthInterceptor - Response header: {Content-Type=[application/json;charset=UTF-8], Transfer-Encoding=[chunked], Date=[Wed, 12 Sep 2018 17:41:00 GMT]}
INFO  09/12 13:44:05.800 {} [pool-6-thread-13] BasicAuthInterceptor - Response header: {Date=[Wed, 12 Sep 2018 17:44:05 GMT], Set-Cookie=[X-Session-Token=mode&BASICAUTH&user&name&token&AAEAAAFlzuIHW2wljAAXQ5zrkYZFE75H7p9MfbH6REVWICAgICAgIAEnuj5LmEhn8vdL8atZ9j6DGGmXSimKUUSEc%2BpPv6uJ2A%3D%3D; path=/; HttpOnly, ROUTEID=.2; path=/, ROUTEID=.2; path=/, EncryptCookie=!MUIcv63qIjUiv0DaswGZ/7EuVxdhGlpB0wRK4L7mIcd8CeqPrqCaQXDpIomEbw5h3/vRHDvPYFxjQQ==; expires=Wed, 12-Sep-2018 21:44:05 GMT; path=/; Httponly; Secure], Strict-Transport-Security=[max-age=31536000], Content-Type=[application/json;charset=UTF-8], Vary=[Accept-Encoding], X-Frame-Options=[SAMEORIGIN], Content-Security-Policy-Report-Only=[default-src 'self'; script-src 'self' 'unsafe-inline' 'unsafe-eval'; style-src 'self' 'unsafe-inline' 'unsafe-eval'; report-uri ....], X-Content-Type-Options=[nosniff], Access-Control-Allow-Origin=[.....], Access-Control-Allow-Credentials=[true], X-XSS-Protection=[1; mode=block], X-Route-Ref=[Route:2;dcts01aa/1=dcts03;2=dcts01; P59357], Cache-Control=[no-cache, no-store, must-revalidate], Pragma=[no-cache], Expires=[0], Keep-Alive=[timeout=5, max=100], Connection=[Keep-Alive], Transfer-Encoding=[chunked]}