Adding user through REST API to Android App --- need HELP PLS

Hi Experts,

I am currently developing chat app in android and I am trying to register the phone to the openfire server

using the REST API provided by openfire plugin. Now my problem is I’m getting an error about this one

10-17 15:57:02.772 28847-30207/com.example.austin.weconnect E/iterInterceptorExecutor: MessageBodyWriter not found for media type=application/xml, type=class org.igniterealtime.restclient.entity.UserEntity, genericType=class org.igniterealtime.restclient.entity.UserEntity.

and then I figured out that the UserEntity class should be use as a class to be the xml element and this java file doesn’t support the jaxb

All this import is not recognized by android studio

import javax.xml.bind.annotation.XmlElement;
import javax.xml.bind.annotation.XmlElementWrapper;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlType;

and Also I am getting an ProcessingException when I am using the

Response resp = restApiClient.createUser(userEntity);

How do I handle and why I get this error?

I tried to put the jaxb plugin in gradle but it didn’t solve the problem because android and java plugin is not suitable for this.

I hope you can help me. Thank you!

Openfire Plugins@

That is not the answer to your problem, BUT it is not a good idea to call the REST API from a client/app.

Because everyone can sniff the password from the app, and misuse it.

The REST API should be only called from a managed system (your server).

but how can I register the phone to the openfire server, basically I want to register the phone to openfire server and to GCM through username and password

by the input of the user, right? so would you recommend me what kind of pattern/tech should I use for this registration through phone ?

I hope you can help me thank you!

@Redeyes observation is correct you should only call your REST API from an additional client facing service, exposing only the functionality you need. I will post a short php github project that does exactly this. The pattern would be:

  • create a client facing REST service, with a separate authentication mechanism for clients
  • expose only required behavior e.g. create or password reset
  • link this behavior to the openfire REST service, in a controlled manner

@@Austin If you need to create users from your end user application, to be distributed over the network, you must not use REST API directly, but you could at least use an adapter service. See the article here, An adapter-like pattern and code for the creation of XMPP users in an OpenFire server - CodeProject . It provides a PHP script for restricting the access to the creation and password reset operations of the REST API, for client applications possessing a client facing secret.

Using the java rest api client in Android is inefficient tasks. And also it is not suppose to be used in Android. Since android don’t have other java framwork required to works with (like jaxb etc). Even if you are going to manage this somehow , you will have to cost lots of memory space for this and your app size will be inscread with +10 MB size due to these library.
Here is a simple library Openfire-Rest-Api-Client-Android developed for specifically android. There is an app which is using this library to show users , groups session etc. You can see the app at Play store Openfire Admin - Android Apps on Google Play . The library is still in beta but still you can get your work done-
Here is an example directly from the GitHub-
``

OfApiClient.with(this).account(account).getUser("admin", new Listener<User>() { @Override public void onResponse(Object mTag, User user) { //Handle Success } }, new ErrorListener() { @Override public void onErrorResponse(VolleyError error) { //Handle Failure } });