76 lines
2.6 KiB
Java
76 lines
2.6 KiB
Java
package org.gcube.data.access.connector;
|
|
|
|
import java.net.Authenticator;
|
|
import java.net.InetSocketAddress;
|
|
import java.net.PasswordAuthentication;
|
|
import java.net.Proxy;
|
|
import java.util.Arrays;
|
|
|
|
import org.apache.commons.codec.binary.Base64;
|
|
import org.junit.Ignore;
|
|
//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.http.client.SimpleClientHttpRequestFactory;
|
|
//import org.springframework.web.client.RestTemplate;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
|
|
|
|
@Ignore
|
|
public class TestGN264 {
|
|
|
|
private static Logger logger = LoggerFactory
|
|
.getLogger(TestGN264.class);
|
|
|
|
|
|
public static void main(String[] args) {
|
|
try {
|
|
String url = "http://geonetwork-sdi.dev.d4science.org/geonetwork/srv/en/metadata.show?id=29";
|
|
/*RestTemplate restTemplate = getRestTemplate(); //new RestTemplate();
|
|
HttpHeaders headers = new HttpHeaders();
|
|
|
|
headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
|
|
|
|
String token = "admin:admin";
|
|
headers.add("Authorization", "Basic " + Base64.encodeBase64String(token.getBytes()));
|
|
|
|
HttpEntity<String> entity = new HttpEntity<String>("parameters", headers);
|
|
ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
|
|
System.out.println("Result - status ("+ response.getStatusCode() + ") has body: " + response.hasBody());
|
|
System.out.println(response.getBody());
|
|
// String response = restTemplate.getForObject(url, String.class);
|
|
// System.out.println(response);*/
|
|
} catch (Exception e) {
|
|
System.out.println("Error: " + e.getMessage());
|
|
}
|
|
|
|
}
|
|
|
|
private static void getRestTemplate() {
|
|
|
|
final Authenticator authenticator = new Authenticator() {
|
|
@Override
|
|
public PasswordAuthentication getPasswordAuthentication() {
|
|
return (new PasswordAuthentication("pvitale", "Mariapia_77".toCharArray()));
|
|
}
|
|
};
|
|
|
|
Authenticator.setDefault(authenticator);
|
|
|
|
/*final SimpleClientHttpRequestFactory factory = new SimpleClientHttpRequestFactory();
|
|
final InetSocketAddress address = new InetSocketAddress("proxy.eng.it", 3128);
|
|
final Proxy proxy = new Proxy(Proxy.Type.HTTP, address);
|
|
factory.setProxy(proxy);
|
|
|
|
final RestTemplate restTemplate = new RestTemplate();
|
|
restTemplate.setRequestFactory(factory);// pass the factory instance to restTemplate
|
|
|
|
*/
|
|
return;
|
|
}
|
|
|
|
}
|