Commit 3d550470 by Gerrit Hübbers

Make RestTemplate follow 30x redirects

parent 26a4c291
......@@ -11,6 +11,9 @@ import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.gesis.dda.feeder.ssoar.SsoarRestService;
import org.gesis.dda.feeder.ssoar.domain.Bitstream;
import org.gesis.dda.feeder.ssoar.domain.Collection;
......@@ -32,6 +35,7 @@ import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.BufferingClientHttpRequestFactory;
import org.springframework.http.client.ClientHttpRequestInterceptor;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.http.client.SimpleClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
......@@ -57,13 +61,20 @@ public class SpringRestTemplateSsoarRestService implements SsoarRestService {
this.authenticationUser = new User( ingesterProperties.getEmail(), ingesterProperties.getPassword() );
if (activateDebug) {
restTemplate = new RestTemplate( new BufferingClientHttpRequestFactory( new SimpleClientHttpRequestFactory() ) );
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<ClientHttpRequestInterceptor>();
List<ClientHttpRequestInterceptor> interceptors = new ArrayList<>();
interceptors.add(new LoggingRequestInterceptor());
restTemplate.setInterceptors(interceptors);
}
else {
restTemplate = new RestTemplate();
}
final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
final HttpClient httpClient = HttpClientBuilder.create()
.setRedirectStrategy(new LaxRedirectStrategy())
.build();
factory.setHttpClient(httpClient);
restTemplate.setRequestFactory(factory);
ImmutableSet.Builder<String> setBuilder = ImmutableSet.builder();
setBuilder.add("dc.identifier.urn", "dc.identifier.doi", "dc.identifier.url", "dc.identifier.uri", "internal.dda.reference" /*, "dc.identifier.issn", "dc.identifier.isbn", "dc.identifier"*/);
......
......@@ -3,12 +3,17 @@ package org.gesis.dda.feeder.ssoar;
import java.util.Arrays;
import java.util.List;
import org.apache.http.client.HttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.LaxRedirectStrategy;
import org.gesis.dda.feeder.ssoar.domain.Bitstream;
import org.gesis.dda.feeder.ssoar.domain.Item;
import org.junit.Before;
import org.junit.Test;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.ResponseEntity;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;
......@@ -16,9 +21,22 @@ public class SsoarRestIntTest {
private static final Logger log = LoggerFactory.getLogger(SsoarRestIntTest.class);
private final static String INTEGRATION_SERVER_ENDPOINT = "http://ssoar.svko-dda-test.gesis.intra/rest/";
private RestTemplate restTemplate;
@Before
public void before() {
//restTemplate = new RestTemplate( new FollowRedirectsClientHttpRequestFactory() );
restTemplate = new RestTemplate();
final HttpComponentsClientHttpRequestFactory factory = new HttpComponentsClientHttpRequestFactory();
final HttpClient httpClient = HttpClientBuilder.create()
.setRedirectStrategy(new LaxRedirectStrategy())
.build();
factory.setHttpClient(httpClient);
restTemplate.setRequestFactory(factory);
}
@Test
public void makeSimpleRestCall() {
RestTemplate restTemplate = new RestTemplate();
Item item = restTemplate.getForObject(INTEGRATION_SERVER_ENDPOINT + "items/39921", Item.class);
log.info(item.toString());
log.info("hallo");
......@@ -26,9 +44,9 @@ public class SsoarRestIntTest {
@Test
public void getBitstreamsForItem() {
RestTemplate restTemplate = new RestTemplate();
ResponseEntity<Bitstream[]> bitstreamsResponse = restTemplate.getForEntity(INTEGRATION_SERVER_ENDPOINT + "items/39921/bitstreams", Bitstream[].class);
List<Bitstream> bitstreams = Arrays.asList( bitstreamsResponse.getBody() );
bitstreams.stream().forEach(b -> log.info(b.toString()) );
}
}
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