Topic: Error during the creation of Geofence
Hello,
I would like to create Geofence via the API WIALON Java. But after execution my code I receive the following error Invalid input (error 4).
My code.
public final static int CLEANUP_SESSION_NOW = 0x1;
public final static int LOGOUT_SERVER = 0x2;
public final static int CLEAN_SESSION_AT_CALLBACK= 0x4;
public WialonGeoZone()
{
session = Session.getInstance();
logger.info("session it is initialize");
sessionId = null;
resourceId = -1;
}
public void login()
{
// TODO : Change logic implementation of this method
logger.info("Beginning loginToken Wialon SDK");
boolean b = session.initSession("http://hst-api.wialon.com");
session.loginToken("251a59d6b516d93194ebc406b8a79d192943B81D1D19C5C8BFAF6108D2562501AFA95CF7",
new ResponseHandler()
{
@Override
public void onSuccess(String response)
{
super.onSuccess(response);
System.out.println(response);
logger.info("Login is executed with success");
logger.info("User Wialon it is "+session.getCurrUser().getName());
obtainSessionId();
searchResourceId();
}
@Override
public void onFailure(int errorCode, Throwable throwableError)
{
super.onFailure(errorCode, throwableError);
System.out.println(errorCode);
logger.info("Login is execute with error");
logger.info("Error code it is "+errorCode);
if(throwableError != null)
logger.error("Error loginToken is caused by "+throwableError.getMessage());
else
logger.error("Error loginToken. ThrowableError it is null");
}
});
}
public void logout(int flags)
{
session.logout(flags, new ResponseHandler()
{
@Override
public void onSuccess(String response)
{
super.onSuccess(response);
logger.info("Logout is executed with success");
logger.info("User Wialon it is "+session.getCurrUser().getName());
System.out.print("Thread is terminate");
}
@Override
public void onFailure(int errorCode, Throwable throwableError)
{
super.onFailure(errorCode, throwableError);
logger.info("Logout is execute with error");
logger.info("Logout Error code is : "+errorCode);
if(throwableError != null)
logger.error("Logout Error loginToken is caused by "+throwableError.getMessage());
else
logger.info("Logout ThrowableError it is null");
}
});
}
private void obtainSessionId()
{
if(session.getId() != null)
{
sessionId = session.getId();
logger.info("SessionId it is : "+sessionId);
}
}
private void searchResourceId()
{
// TODO : Verify method with unit test
SearchSpec searchSpec = new SearchSpec();
searchSpec.setItemsType(Item.ItemType.avl_resource);
searchSpec.setPropName("sys_id");
searchSpec.setPropValueMask("*");
searchSpec.setSortType("sys_id");
session.searchItems(searchSpec,3,Item.dataFlag.base.getValue(),0,Integer.MAX_VALUE,
new SearchResponseHandler()
{
@Override
public void onSuccessSearch(Item... items)
{
super.onSuccessSearch(items);
if(items != null && items.length > 0)
{
for(Item resId : items)
{
WialonGeoZone.this.resourceId = resId.getId();
logger.info("Name Item : "+resId.getName());
logger.info("the resource Id it is = "+resId.getId());
}
String params = createJson("5.351970","-3.700000","words");
createWithRemoteCall(params);
}
else
{
logger.info("Items resource it is null or the Items size = 0");
}
}
@Override
public void onFailure(int errorCode, Throwable throwableError)
{
super.onFailure(errorCode, throwableError);
logger.error("Search Exception it is throw");
logger.error("Search Error code it is "+errorCode);
if(throwableError != null)
logger.error("Search Error code it is "+throwableError.getMessage());
}
});
}
public String createJsonString(String lat,String lng,String word)
{
if(resourceId != -1)
{
restGeo(lat,lng);
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("itemId",resourceId);
jsonObject.addProperty("id","");
jsonObject.addProperty("callMode","create");
jsonObject.addProperty("n",word);
jsonObject.addProperty("d","");
jsonObject.addProperty("t",3);
jsonObject.addProperty("w",20); // change later
jsonObject.addProperty("f","zone");
jsonObject.addProperty("c","");
jsonObject.addProperty("tc","");
jsonObject.addProperty("ts","12"); // change later
jsonObject.addProperty("min",5); // change later
jsonObject.addProperty("maw",5); // change later
jsonObject.addProperty("path",""); // value it is a path of Icon
jsonObject.addProperty("libId",0); // value it is library id
// jsonObject.addProperty("oldItemId","");
// jsonObject.addProperty("oldZoneId","");
JsonObject jsonPosition = new JsonObject();
jsonPosition.addProperty("x",lng);
jsonPosition.addProperty("y",lat);
jsonPosition.addProperty("r",1); // change later
JsonArray jsonArray = new JsonArray();
jsonArray.add(jsonPosition);
jsonObject.add("p",jsonArray);
System.out.println(jsonObject.toString());
return jsonObject.toString();
}
return null;
}
public void createWithRemoteCall(String params)
{
RemoteHttpClient remoteHttpClient = RemoteHttpClient.getInstance();
remoteHttpClient.remoteCall("resource/update_zone", params, new ResponseHandler()
{
@Override
public void onSuccess(String response)
{
super.onSuccess(response);
logger.info(response);
logout(LOGOUT_SERVER);
}
@Override
public void onFailure(int errorCode, Throwable throwableError)
{
super.onFailure(errorCode, throwableError);
logger.error("Create Geofence is fail.\nError code it is : "+errorCode);
if(throwableError !=null)
logger.error("Error message it is : "+throwableError.getMessage());
else
logger.error("Error message it is nulll");
logout(LOGOUT_SERVER);
}
});
}
public static void main(String... args)
{
WialonGeoZone wialonGeoZone = new WialonGeoZone();
wialonGeoZone.login();
}