Skip to content

Commit 04529b4

Browse files
committed
Added Route4Me account registration. Telematics Gateway Management
1 parent 3fc5d1f commit 04529b4

28 files changed

+1157
-29
lines changed

pom.xml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
<modelVersion>4.0.0</modelVersion>
55
<groupId>com.route4me</groupId>
66
<artifactId>route4me-java-sdk</artifactId>
7-
<version>RELEASE-1.1.4</version>
7+
<version>RELEASE-1.2.0</version>
88
<packaging>jar</packaging>
99
<properties>
1010
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
@@ -17,7 +17,7 @@
1717
<dependency>
1818
<groupId>org.apache.logging.log4j</groupId>
1919
<artifactId>log4j-api</artifactId>
20-
<version>2.11.2</version>
20+
<version>2.13.2</version>
2121
</dependency>
2222

2323
<dependency>

src/main/java/com/route4me/sdk/Manager.java

+14-15
Original file line numberDiff line numberDiff line change
@@ -8,29 +8,27 @@
88
import com.google.gson.annotations.SerializedName;
99
import com.route4me.sdk.exception.APIException;
1010
import com.route4me.sdk.queryconverter.QueryConverter;
11+
import java.io.*;
12+
import java.lang.reflect.Type;
13+
import java.net.URISyntaxException;
14+
import java.util.List;
1115
import org.apache.http.HttpEntity;
16+
import org.apache.http.HttpHost;
1217
import org.apache.http.NameValuePair;
18+
import org.apache.http.client.config.RequestConfig;
1319
import org.apache.http.client.entity.UrlEncodedFormEntity;
1420
import org.apache.http.client.methods.CloseableHttpResponse;
1521
import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
1622
import org.apache.http.client.methods.HttpRequestBase;
1723
import org.apache.http.client.utils.URIBuilder;
1824
import org.apache.http.entity.StringEntity;
19-
import org.apache.http.impl.client.HttpClients;
20-
21-
import java.io.*;
22-
import java.lang.reflect.Type;
23-
import java.net.URISyntaxException;
24-
import java.util.List;
25-
import org.apache.http.HttpHost;
26-
import org.apache.http.client.config.RequestConfig;
2725
import org.apache.http.impl.client.CloseableHttpClient;
26+
import org.apache.http.impl.client.HttpClients;
2827
import org.apache.logging.log4j.LogManager;
2928

3029
public abstract class Manager {
31-
32-
protected static final org.apache.logging.log4j.Logger logger = LogManager.getLogger(Manager.class);
3330

31+
protected static final org.apache.logging.log4j.Logger logger = LogManager.getLogger(Manager.class);
3432

3533
private final String apiKey;
3634
protected Gson gson;
@@ -184,7 +182,9 @@ private <T> T makeRequest(RequestMethod method, URIBuilder builder, HttpEntity b
184182
builder.addParameter("redirect", "0");
185183
client = HttpClients.custom().disableRedirectHandling().build();
186184
}
187-
builder.addParameter("api_key", this.apiKey);
185+
if (this.apiKey != null) {
186+
builder.addParameter("api_key", this.apiKey);
187+
}
188188
HttpRequestBase hrb = method.create(builder.build());
189189
if (requestContentType != null) {
190190
hrb.setHeader("Content-type", requestContentType);
@@ -201,12 +201,12 @@ private <T> T makeRequest(RequestMethod method, URIBuilder builder, HttpEntity b
201201
}
202202
//try with resources to close streams
203203

204-
try ( CloseableHttpResponse resp = client.execute(hrb); InputStream is = resp.getEntity().getContent()) {
204+
try (CloseableHttpResponse resp = client.execute(hrb); InputStream is = resp.getEntity().getContent()) {
205205
//response should always be present
206206
if (is == null) {
207207
throw new APIException("Response body is null.");
208208
}
209-
try ( InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr)) {
209+
try (InputStreamReader isr = new InputStreamReader(is); BufferedReader br = new BufferedReader(isr)) {
210210
if (resp.getStatusLine().getStatusCode() < 200 || resp.getStatusLine().getStatusCode() > 303) {
211211
try {
212212
StringBuilder respString = responseContentParser(br);
@@ -218,11 +218,10 @@ private <T> T makeRequest(RequestMethod method, URIBuilder builder, HttpEntity b
218218
//deserialize json into an object
219219
if (clazz != null && clazz != String.class) {
220220
StringBuilder respString = responseContentParser(br);
221-
222221
try {
223222
return this.gson.fromJson(respString.toString(), clazz);
224223
} catch (JsonSyntaxException ex) {
225-
throw new APIException(respString.toString());
224+
throw new APIException(ex.toString());
226225
}
227226
} else if (type != null) {
228227
StringBuilder respString = responseContentParser(br);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.route4me.sdk.examples.telematics;
7+
8+
import com.route4me.sdk.exception.APIException;
9+
import com.route4me.sdk.services.telematics.TelematicsConnection;
10+
import com.route4me.sdk.services.telematics.TelematicsManager;
11+
import java.util.logging.Level;
12+
import java.util.logging.Logger;
13+
14+
/**
15+
*
16+
* @author Route4Me
17+
*/
18+
public class TelematicsCreateVendorConnection {
19+
20+
public static void main(String[] args) {
21+
String apiKey = "11111111111111111111111111111111";
22+
TelematicsManager manager = new TelematicsManager(apiKey);
23+
TelematicsConnection credentials = new TelematicsConnection();
24+
25+
credentials.setVendorID(4);
26+
credentials.setAccountID("12345");
27+
credentials.setUsername("username");
28+
credentials.setPassword("password");
29+
credentials.setVehiclePositionRefreshRate(60);
30+
credentials.setName("Test Connection from Java SDK");
31+
credentials.setValidateRemoteCredentials("false");
32+
try {
33+
34+
TelematicsConnection connection = manager.createTelematicsConnection("a8a60c1fccb5db60bbb9ca6a6ff71aef", credentials);
35+
System.out.println(connection);
36+
} catch (IllegalAccessException ex) {
37+
Logger.getLogger(TelematicsCreateVendorConnection.class.getName()).log(Level.SEVERE, null, ex);
38+
} catch (APIException ex) {
39+
Logger.getLogger(TelematicsCreateVendorConnection.class.getName()).log(Level.SEVERE, ex.toString());
40+
}
41+
42+
}
43+
44+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.route4me.sdk.examples.telematics;
7+
8+
import com.route4me.sdk.exception.APIException;
9+
import com.route4me.sdk.services.telematics.TelematicsConnection;
10+
import com.route4me.sdk.services.telematics.TelematicsManager;
11+
import java.util.logging.Level;
12+
import java.util.logging.Logger;
13+
14+
/**
15+
*
16+
* @author Route4Me
17+
*/
18+
public class TelematicsDeleteVendorConnection {
19+
20+
public static void main(String[] args) {
21+
String apiKey = "11111111111111111111111111111111";
22+
TelematicsManager manager = new TelematicsManager(apiKey);
23+
try {
24+
25+
TelematicsConnection connection = manager.deleteTelematicsConnection("a8a60c1fccb5db60bbb9ca6a6ff71aef", "7DltI9rWz11HAZPL4tZPL4tz4pthRPLu3AvuM");
26+
System.out.println(connection);
27+
} catch (IllegalAccessException ex) {
28+
Logger.getLogger(TelematicsDeleteVendorConnection.class.getName()).log(Level.SEVERE, null, ex);
29+
} catch (APIException ex) {
30+
Logger.getLogger(TelematicsDeleteVendorConnection.class.getName()).log(Level.SEVERE, ex.toString());
31+
}
32+
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.route4me.sdk.examples.telematics;
7+
8+
import com.route4me.sdk.exception.APIException;
9+
import com.route4me.sdk.services.telematics.TelematicsConnection;
10+
import com.route4me.sdk.services.telematics.TelematicsManager;
11+
import java.util.List;
12+
import java.util.logging.Level;
13+
import java.util.logging.Logger;
14+
15+
/**
16+
*
17+
* @author Route4Me
18+
*/
19+
public class TelematicsGetConnections {
20+
21+
public static void main(String[] args) {
22+
String apiKey = "11111111111111111111111111111111";
23+
TelematicsManager manager = new TelematicsManager(apiKey);
24+
try {
25+
List<TelematicsConnection> connections = manager.getTelematicsConnections("a8a60c1fccb5db60bbb9ca6a6ff71aef");
26+
System.out.println(connections);
27+
} catch (APIException ex) {
28+
Logger.getLogger(TelematicsGetConnections.class.getName()).log(Level.SEVERE, ex.toString());
29+
}
30+
}
31+
32+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.route4me.sdk.examples.telematics;
7+
8+
import com.route4me.sdk.exception.APIException;
9+
import com.route4me.sdk.services.telematics.TelematicsConnection;
10+
import com.route4me.sdk.services.telematics.TelematicsManager;
11+
import java.util.logging.Level;
12+
import java.util.logging.Logger;
13+
14+
/**
15+
*
16+
* @author Route4Me
17+
*/
18+
public class TelematicsGetVendorConnection {
19+
20+
public static void main(String[] args) {
21+
String apiKey = "11111111111111111111111111111111";
22+
TelematicsManager manager = new TelematicsManager(apiKey);
23+
try {
24+
25+
TelematicsConnection connection = manager.getTelematicsConnection("a8a60c1fccb5db60bbb9ca6a6ff71aef", "7DltI9rWz11HAZPL4tZPL4tz4pthRPLu3AvuM");
26+
System.out.println(connection);
27+
} catch (IllegalAccessException ex) {
28+
Logger.getLogger(TelematicsGetVendorConnection.class.getName()).log(Level.SEVERE, null, ex);
29+
} catch (APIException ex) {
30+
Logger.getLogger(TelematicsGetVendorConnection.class.getName()).log(Level.SEVERE, ex.toString());
31+
}
32+
33+
}
34+
35+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.route4me.sdk.examples.telematics;
7+
8+
import com.route4me.sdk.exception.APIException;
9+
import com.route4me.sdk.services.telematics.TelematicsManager;
10+
import com.route4me.sdk.services.telematics.TelematicsVendorsInfo;
11+
import java.util.logging.Level;
12+
import java.util.logging.Logger;
13+
14+
/**
15+
*
16+
* @author Route4Me
17+
*/
18+
public class TelematicsGetVendorInfo {
19+
20+
public static void main(String[] args) {
21+
String apiKey = "11111111111111111111111111111111";
22+
TelematicsManager manager = new TelematicsManager(apiKey);
23+
24+
try {
25+
TelematicsVendorsInfo vendor = manager.getTelematicsVendorInfo("3");
26+
System.out.println(vendor.getVendor());
27+
28+
} catch (APIException ex) {
29+
Logger.getLogger(TelematicsRegisterMember.class.getName()).log(Level.INFO, ex.toString());
30+
}
31+
32+
}
33+
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.route4me.sdk.examples.telematics;
7+
8+
import com.route4me.sdk.exception.APIException;
9+
import com.route4me.sdk.services.telematics.TelematicsManager;
10+
import com.route4me.sdk.services.telematics.TelematicsVendorInfo;
11+
import com.route4me.sdk.services.telematics.TelematicsVendorsInfo;
12+
import java.util.logging.Level;
13+
import java.util.logging.Logger;
14+
15+
/**
16+
*
17+
* @author Route4Me
18+
*/
19+
public class TelematicsGetVendorsInfo {
20+
21+
public static void main(String[] args) {
22+
String apiKey = "11111111111111111111111111111111";
23+
TelematicsManager manager = new TelematicsManager(apiKey);
24+
25+
try {
26+
TelematicsVendorsInfo vendors = manager.getTelematicsVendorsInfo();
27+
for (TelematicsVendorInfo vendor : vendors.getVendors()) {
28+
System.out.println(vendor);
29+
30+
}
31+
} catch (APIException ex) {
32+
Logger.getLogger(TelematicsRegisterMember.class.getName()).log(Level.INFO, ex.toString());
33+
}
34+
35+
}
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
/*
2+
* To change this license header, choose License Headers in Project Properties.
3+
* To change this template file, choose Tools | Templates
4+
* and open the template in the editor.
5+
*/
6+
package com.route4me.sdk.examples.telematics;
7+
8+
import com.route4me.sdk.exception.APIException;
9+
import com.route4me.sdk.services.telematics.TelematicsManager;
10+
import com.route4me.sdk.services.telematics.TelematicsMemberRegister;
11+
import java.util.logging.Level;
12+
import java.util.logging.Logger;
13+
14+
/**
15+
*
16+
* @author Route4Me
17+
*/
18+
public class TelematicsRegisterMember {
19+
20+
public static void main(String[] args) {
21+
String apiKey = "11111111111111111111111111111111";
22+
TelematicsManager manager = new TelematicsManager(apiKey);
23+
24+
try {
25+
TelematicsMemberRegister register = manager.registerMember(1);
26+
System.out.println(register);
27+
} catch (APIException ex) {
28+
Logger.getLogger(TelematicsRegisterMember.class.getName()).log(Level.INFO, ex.toString());
29+
}
30+
}
31+
32+
}

0 commit comments

Comments
 (0)