HI experts,
I am using SMP sdk SP11 and latest android sdk to onboard the user with oData.
I am facing issues with device registration while onboarding the user. The registration is failed with Http:404. onODataRequestError method is called with null message.
Rest client shows http 200.
Server Url: http://mobdv.bajajauto.com/TICL
Below is the full source code used for LoginActivity. Please help.
public class LoginActivity extends Activity implements View.OnClickListener, UIListener {
private final String TAG = LoginActivity.class.getSimpleName();
private static final String VK_APPCID = "appcid";
private Button logonBtn;
private EditText usernameEdit, passwordEdit;
private ProgressDialog progressDialog;
private String appConnId;
private LogonCore lgCore;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
//Initialize UI elements in the screen
this.initializeViews();
//Get application connection id
this.initializeLogonCore();
//If application connection id exists, then display main screen
if (!TextUtils.isEmpty(appConnId)){
Intent goToNextActivity = new Intent(this, MainActivity.class);
startActivity(goToNextActivity);
}
}
@Override
public void onClick(View view) {
registerDevice();
}
@Override
public void onODataRequestError(Exception e) {
progressDialog.dismiss();
logonBtn.setEnabled(true);
//notify the user the registration fails
Toast.makeText(this, R.string.msg_registration_fail, Toast.LENGTH_LONG).show();
Toast.makeText(this, e.getMessage(), Toast.LENGTH_LONG).show();
}
@Override
public void onODataRequestSuccess(String info) {
progressDialog.dismiss();
//Store application connection Id in the secure store
//This way next time the app runs, we know if the user has been
//registered before
try {
appConnId = lgCore.getLogonContext().getConnId();
if (appConnId != null) {
// store it
if (!lgCore.isStoreOpen()) lgCore.unlockStore(null);
lgCore.addObjectToStore(VK_APPCID, appConnId);
}
//notify the user the registration was complete successfully
Toast.makeText(this, R.string.msg_registration_success, Toast.LENGTH_LONG).show();
//Display the main screen
Intent goToNextActivity = new Intent(this,MainActivity.class);
startActivity(goToNextActivity);
} catch (LogonCoreException e) {
Log.e(TAG, "error getting application connection id", e);
//notify the user the registration fails
Toast.makeText(this, R.string.msg_registration_fail, Toast.LENGTH_LONG).show();
logonBtn.setEnabled(true);
}
}
/**
* Initialize UI elements
*/
private void initializeViews() {
logonBtn = (Button) findViewById(R.id.logon_button);
logonBtn.setOnClickListener(this);
usernameEdit = (EditText) findViewById(R.id.txt_username);
passwordEdit = (EditText) findViewById(R.id.txt_password);
}
/**
* Initialize LogonCore component
*/
private void initializeLogonCore(){
//Get LogonCore instance
lgCore = LogonCore.getInstance();
//Create a LogonCoreListener for asynchronously registration
MyLogonCoreListener listener = new MyLogonCoreListener(10, this);
//Set the listener
lgCore.setLogonCoreListener(listener);
//Initialize LogonCore with application configuraton name
lgCore.init(this, "TICL");
LogonCoreContext context = lgCore.getLogonContext();
context.setChannel(LogonCore.Channel.REST);
//Check if application connection exists
try {
//check if secure store is available
if (lgCore.isStoreAvailable()) {
//Unlock the store
lgCore.unlockStore(null);
//Get application connection id
appConnId = lgCore.getObjectFromStore(VK_APPCID);
}
} catch (LogonCoreException e) {
Log.e(TAG, "error initializing logon core", e);
}
}
/**
* Onboard device with Mobile services
*/
private void registerDevice() {
logonBtn.setEnabled(false);
progressDialog =
ProgressDialog.show(this, "", getString(R.string.msg_registration_progress),true);
Log.d(TAG, "registerDevice " + appConnId);
//Check if the Application Connection Id already exists
if (TextUtils.isEmpty(appConnId)){
//Get LogonCoreContext instance
LogonCoreContext lgCtx = lgCore.getLogonContext();
lgCtx.setHost("mobdv.bajajauto.com");
lgCtx.setPort(80);
lgCtx.setAppId("com.sample");
//Set whether the registration uses secure connection or not
lgCtx.setHttps(false);
//set user creation policy
LogonCore.UserCreationPolicy ucPolicy = LogonCore.UserCreationPolicy.automatic;
lgCtx.setUserCreationPolicy(ucPolicy);
//Set username and password
try {
lgCtx.setBackendUser(usernameEdit.getText().toString());
lgCtx.setBackendPassword(passwordEdit.getText().toString());
} catch (LogonCoreException e) {
//Notifies the execution finished
onODataRequestError(e);
}
//Register user
lgCore.register(lgCtx);
} else {
//This means the user is already registered
Log.d(TAG, getString(R.string.msg_already_registered));
//notify the user the device is already regitered
Toast.makeText(this, R.string.msg_already_registered,
Toast.LENGTH_LONG).show();
}
}