Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class LocationTelcoAPI {
- private RestTemplate restTemplate = new RestTemplate();
- private String telco_location = "https://api.orange.pl/terminallocation/?msisdn={phone}";
- private void enableSSL() {
- TrustManager[] trustAllCerts = new TrustManager[]{
- new X509TrustManager() {
- public java.security.cert.X509Certificate[] getAcceptedIssuers() {
- return null;
- }
- public void checkClientTrusted(
- java.security.cert.X509Certificate[] certs, String authType) {
- }
- public void checkServerTrusted(
- java.security.cert.X509Certificate[] certs, String authType) {
- }
- }
- };
- try {
- SSLContext sc = SSLContext.getInstance("SSL");
- sc.init(null, trustAllCerts, new java.security.SecureRandom());
- HttpsURLConnection.setDefaultSSLSocketFactory(sc.getSocketFactory());
- } catch (Exception e) {
- }
- }
- public LocationResponse getLocation(String telephone_number) {
- enableSSL();
- String auth = TelcoAuth.USERNAME + ":" + TelcoAuth.PASSWORD;
- byte[] encodedAuth = Base64.encodeBase64(auth.getBytes());
- String authHeader = "Basic " + new String(encodedAuth);
- HttpHeaders headers = new HttpHeaders();
- headers.set("Accept", "application/json");
- headers.set("Authorization", authHeader);
- Map<String, String> variables = new HashMap<String, String>(1);
- variables.put("phone", telephone_number);
- ResponseEntity<LocationResponse> exchange = restTemplate.exchange(telco_location, HttpMethod.GET, new HttpEntity<String>(headers), LocationResponse.class, variables);
- System.out.println(exchange.getStatusCode());
- System.out.println(exchange.getBody().getResult());
- System.out.println(exchange.getBody().getLongitude());
- System.out.println(exchange.getBody().getLatitude());
- System.out.println(exchange.getBody().getAccuracy());
- System.out.println(exchange.getBody().getAltitude());
- System.out.println(exchange.getBody().getTimestamp());
- return exchange.getBody();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement