Skip to content

Commit

Permalink
Add a User-Agent header when requesting partner APIs (fix #369)
Browse files Browse the repository at this point in the history
  • Loading branch information
arteymix committed Aug 24, 2023
1 parent 4ffb6ef commit ef34305
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions src/main/java/ubc/pavlab/rdp/RemoteResourceConfig.java
Original file line number Diff line number Diff line change
@@ -1,21 +1,32 @@
package ubc.pavlab.rdp;

import lombok.extern.apachecommons.CommonsLog;
import org.springframework.boot.info.BuildProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.task.SimpleAsyncTaskExecutor;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.AsyncRestTemplate;
import ubc.pavlab.rdp.settings.ApplicationSettings;

import java.io.IOException;
import java.net.HttpURLConnection;

@CommonsLog
@Configuration
public class RemoteResourceConfig {

@Bean
public AsyncRestTemplate remoteResourceRestTemplate( ApplicationSettings applicationSettings ) {
SimpleClientHttpRequestFactory httpRequestFactory = new SimpleClientHttpRequestFactory();
public AsyncRestTemplate remoteResourceRestTemplate( ApplicationSettings applicationSettings, BuildProperties buildProperties ) {
SimpleClientHttpRequestFactory httpRequestFactory = new SimpleClientHttpRequestFactory() {
@Override
protected void prepareConnection( HttpURLConnection connection, String httpMethod ) throws IOException {
super.prepareConnection( connection, httpMethod );
connection.setRequestProperty( "User-Agent", buildProperties.getArtifact() + "/" + buildProperties.getVersion() );
}
};
httpRequestFactory.setTaskExecutor( new SimpleAsyncTaskExecutor() );
//noinspection deprecation
if ( applicationSettings.getIsearch().getRequestTimeout() != null ) {
log.warn( "The 'rdp.settings.isearch.request-timeout' configuration is deprecated, use 'rdp.settings.isearch.connect-timeout' and 'rdp.settings.isearch.read-timeout' instead." );
httpRequestFactory.setConnectTimeout( 1000 );
Expand Down

0 comments on commit ef34305

Please sign in to comment.