0

I have a Java EE application with its EJB and database server. I'm now trying to make the client version of my app an android one. I have entity beans along with database on the server(desktop pc) and I want to get these data, and on timely basis to the android app and see the updated state of my database's content.

My question is, how would I make android app to communicate with the server. I tried to read what protocol to use but I still am not clear with them. Do I use java socket like I used to do when I developed tcp/ip chat application? Or, REST(which I have no much clue about or ...)

Thanks in advance for your astute recommendations

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Abraham
  • 603
  • 7
  • 19

4 Answers4

1

Traditional Java EE Apps utilize relatively reliable and broadband network connection with reasonable latency. Network connectivity of android devices does not show those properties ( it is not reliable, can be broken at any time and is slow ). You have to take this into account while designing you exchange protocol.

Usable solution is REST service with reasonably short messages and protocol tolerating network failures. Nowadays it is pretty easy to create REST endpoints into Java EE server (there are differences between server brands, but they are pretty minor)

Arjan Tijms
  • 37,782
  • 12
  • 108
  • 140
Konstantin Pribluda
  • 12,329
  • 1
  • 30
  • 35
0

You can use REST. Android supports REST and you watch this video on Google IO 2010, also web is full of working example to help you.

Gaurav Agarwal
  • 18,754
  • 29
  • 105
  • 166
0

A sample application that demostrates using native mobile Android and iOS clients using a Java EE 7 backend. The server-side consists of a chat WebSocket API and a to do list REST API implemented using the Java API for WebSocket, JSON-P, JAX-RS 2, CDI, Bean Validation, EJB 3 and JPA.

https://github.com/m-reza-rahman/javaee-mobile

  • While this link may answer the question, it is better to include the essential parts of the answer here and provide the link for reference. Link-only answers can become invalid if the linked page changes. – Roman Marusyk Mar 18 '16 at 15:22
0

You can! but in this way you have some advantage and disadvantage , Important disadvantage is lack of security by adding all Beans into android , maybe I'm wrong thinking in open world. But here Steps for using Java Beans(EJB) or Java Library that need share with android , webapp , desktop app and etc...

in eclipse way match easier to do that , by the way in this year I use intellij so Given example of what I'm doing for app I create.

About structure if we have:

  • Project/MyEnterpriseProject/Webapp
  • Project/MyEnterpriseProject/Android
  • Project/MyEnterpriseProject/Desktop
  • Project/MyEnterpriseProject/NativeTools
  • Project/MyEnterpriseProject/Ejb

The Steps:

  1. One Go to Main App(Desktop or WebbApp) create/import Module from out side of project root called ejb or some library you need shared. example : Project/MyEnterpriseProject/Webapp the main root project is MyEnterpriseProject ->So I add NativeTools and Ejb
  2. Add The NativeTools/Ejb as maven Library to web Application and Desktop Application by using maven(not jar file)
  3. set into pom file of NativeTools/Ejb packaging as jar(so you finish for web or desktop and you can use and update from one intellij project But can't use in android studio! go for step 4
  4. In Main Project (can desktop or webapplication) Add artifacts for NativeTools/Ejb set destination whatever you want , but I use target folder in NativeTools/Ejb folder. build artifacts and compiled project if any problems shows , use maven view in intellij and click genrat src and doc and than click reload all project after that click on build artifacts.
  5. go to android studio or any Ide add jar files you build from NativeTools/Ejb , in android studio just go to build.gradle and see this post (https://stackoverflow.com/a/25660287/10992709) :
dependencies {
    implementation files('libs/your jar file.jar')
}
  1. Change the libs/your jar file.jar to your placed NativeTools/Ejb jar file.
  2. if you need to update the NativeTools/Ejb you need rebuild and create artifact from main project , than you can use it from other IDE.
Farhood Naqizade
  • 102
  • 1
  • 12