fix NullPointerException

master
Rushdi Mohamed 3 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();
if(method==TraccarHandlerConstants.Methods.POST){
String result = response.body().string();
log.info(result);
if(result.charAt(0)=='{'){
JSONObject obj = new JSONObject(result);
if (obj.has("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()) {
log.debug("Successfully the request is proceed and communicated with Traccar");
}
}
} catch (IOException 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();
}
if(obj != null){
String context = defaultPort+"/api/devices/"+obj.getInt("traccarDeviceId");
Runnable trackerExecutor = new TrackerExecutor(obj.getInt("traccarDeviceId"), tenantId, endpoint, context, null,
TraccarHandlerConstants.Methods.DELETE, TraccarHandlerConstants.Types.DEVICE);
executor.execute(trackerExecutor);
}
}
/**
* Add Traccar Device operation.

Loading…
Cancel
Save