fix NullPointerException

feature/traccar-sync
Rushdi Mohamed 2 years ago
parent 5c14315b4a
commit bd164ea78f

@ -122,6 +122,8 @@ public class TraccarClient implements org.wso2.carbon.device.mgt.core.traccar.ap
response = client.newCall(request).execute(); response = client.newCall(request).execute();
if(method==TraccarHandlerConstants.Methods.POST){ if(method==TraccarHandlerConstants.Methods.POST){
String result = response.body().string(); String result = response.body().string();
log.info(result);
if(result.charAt(0)=='{'){
JSONObject obj = new JSONObject(result); JSONObject obj = new JSONObject(result);
if (obj.has("id")){ if (obj.has("id")){
int traccarId = obj.getInt("id"); int traccarId = obj.getInt("id");
@ -167,6 +169,8 @@ public class TraccarClient implements org.wso2.carbon.device.mgt.core.traccar.ap
if (log.isDebugEnabled()) { if (log.isDebugEnabled()) {
log.debug("Successfully the request is proceed and communicated with Traccar"); log.debug("Successfully the request is proceed and communicated with Traccar");
} }
}
} catch (IOException e) { } catch (IOException e) {
log.error("Couldnt connect to traccar.", e); log.error("Couldnt connect to traccar.", e);
} }
@ -362,11 +366,13 @@ public class TraccarClient implements org.wso2.carbon.device.mgt.core.traccar.ap
TrackerManagementDAOFactory.closeConnection(); TrackerManagementDAOFactory.closeConnection();
} }
if(obj != null){
String context = defaultPort+"/api/devices/"+obj.getInt("traccarDeviceId"); String context = defaultPort+"/api/devices/"+obj.getInt("traccarDeviceId");
Runnable trackerExecutor = new TrackerExecutor(obj.getInt("traccarDeviceId"), tenantId, endpoint, context, null, Runnable trackerExecutor = new TrackerExecutor(obj.getInt("traccarDeviceId"), tenantId, endpoint, context, null,
TraccarHandlerConstants.Methods.DELETE, TraccarHandlerConstants.Types.DEVICE); TraccarHandlerConstants.Methods.DELETE, TraccarHandlerConstants.Types.DEVICE);
executor.execute(trackerExecutor); executor.execute(trackerExecutor);
} }
}
/** /**
* Add Traccar Device operation. * Add Traccar Device operation.

Loading…
Cancel
Save