REST API with Java, Tomcat, EclipseLink and MySQL - java

i want to build a REST API with Java.
I have a MySQL Database and want to use EclipseLink as my JPA Provider.
I want to run it on a Tomcat Server, alternatively i will use another Server if needed.
Now my real question. How do i set all of this up in Eclipse using Maven?
thanks.

Related

After installing a HAPI FHIR server, what database to use?

I'm new to HAPI FHIR, I created a google cloud compute engine VM, installed java and maven, cloned the hapi-fhir-jpaserver-starter and installed it with :
mvn install
Then runned it to test in my server with :
mvn jetty:run
Now I access it using : http://IP:8080/hapi-fhir-jpaserver
and I get this page :
Now all the resources are empty (patients etc..) , I need to know :
Is this a good server for production ?
What Database the server is actually using and how to access it ?
What type of Database I must set up and how ?
Thanks
EDIT :
I tried to install the hapi server using docker compose, I built the app with mvn clean install and ran the command docker-compose up -d --build but when the installation was finished I get the basic HAPI SERVER (the fresh one) not the version I edited and built.
Any ideas why ?
This s a question of opinion and isn't really an appropriate question to ask on this site. However, there certainly are many systems that do use HAPI in production.
It depends on which server. As per the documentation here, you can either use the 'plain' server and provide your own persistence layer or use the JPA server which uses JPA 2.0 with Derby as the default data store. Details about the database and its structure are defined in the aforementioned documentation
If you're not sure what to do and don't have an existing database you must use, it's probably simplest/wisest to stick with the JPA database as it's already properly configured and works pretty well.
This is an opinion question, so there is not a true right answer.
Having said that, I would stick with "known" setups.
https://smilecdr.com/docs/database_administration/database_design.html
Relationship between smilecdr and hapi
https://smilecdr.com/open-source.html
I am partial to Sql Server or Postgres.
I would not go with Oracle, unless my company is already heavily invested. See image later in this post.
https://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_6014.htm
The command “Create Schema” ‘does not actually create a schema’. #makesPerfectSense But you automatically get a schema when you create a user.
Do what?? I am not a fan of Oracle. Some of it is historical, which is why I think MySql may be the ripped off bandaid.
=========================
2022 UPDATE.
SmileCDR has "discouraged" MySql.
https://smilecdr.com/docs/database_administration/setting_up_mysql.html
Note that as of 2021.11.R01, MySQL is discouraged for production use
due to performance limitations of the database. SmileCDR will continue
to support customers on this database, but if serious performance
issues arise, we will suggest migrating to a more performant database.

Laravel Application on Oracle WebLogic Server

please i need someone to highlight firstly how i could execute php 5.x on Oracle Weblogic J2EE server and the settings required if any...
its a java based environment and i'm wondering how i could get this up and running seamlessly.
if you could provide in details the process required to get Apache working, alongside PHP, my intentions is to use it as the base for a Laravel application i'm currently working on and utilize Oracle as the backend database model...
any ideas ?

Is it possible to consume a web service deployed in glassfish by an application on client side using apache tomcat?

this may be two questions in one, so...Sorry, please correct me if I'm wrong.
I have to deploy a web service developed with JPA, JSP and Glassfish 3.1.2, in a machine which only has apache Tomcat 7 as server installed on Windows 7.
I don't really know how apache can connect to the database externally, or if that is really possible if you don't use TomEE.
I know in Glassfish you can have a connection pool and a jdbc resource, and if you're using JPA, that's how the connection to database works(kindof), so you can deploy the .war file. But, if you only have a Tomcat and the app is using JPA, so it does not connect itself to the database(It does not have a class with a connection credentials), How can I achieve this?
Or, Can I deploy the .war of the web service on Glassfish and then be consumed by an application that only works with apache Tomcat on client side? Am I mixing concepts which should not be mixed?
Any enlightenment is highly appreciated.
You can use Tomcat with JPA, you can even use it in a standalone java application. Define a persistence unit name in persistence.xml, make sure the transaction type is RESOURCE_LOCAL (you can't use JTA in Tomcat, make sure to check this), and get a reference to the EM using the following
EntityManagerFactory emf = Persistence.createEntityManagerFactory("persistenceUnitName");
em = emf.createEntityManager();
Finally, add the jpa provider jars to Tomcat, there are examples for that (I've never done it, but I'm sure some Tomcat expert could lend a hand)
The other option could also work, that is consume your webservice using a client deployed on another server
Good luck!
If your application uses advanced Java EE functionality (JTA, CDI), it won't work on Tomcat. If it uses JSTL, you will have to add a JSTL library to the tomcat installation. Read the docs, it should be stated somewhere, but I would not simply deploy the war to a tomcat.
If you just want to develop a relay webapp that consumes a webservice and displays the results, it will run on tomcat independantly of where the webservice runs.

How do you access SQL database from GWT?

I've read some articles on the Internet that this is not possible. To communicate own SQL database that is located on other server from GWT application. Jetty doesn't allow it.
I found a way how to perform it but it's not very cosy. I have client and server part inside GWT. The server has to communicate with MySQL database on localhost. So I've written an ant script to build a war that I can launch on Apache Tomcat server. It works perfectly there but I'm not able to debug the code effectively.
Do you have some advices how to perform this task? I was thinking of writing the clienty only in GWT and find some waz how to communicate my own server written outside the GWT. I've found Apache Thrift for GWT but this edited library of thrift seem not to work properly.
Thank you very much for your answers:)
It is possible to communicate with a database from a GWT application. The client side has to call the methods of the server via GWT-RPC, which can communicate with any database.
Maybe Jetty does not support it (have not tested it personally) but you can develop your web application using Apache too. There you can access the database the same way as from any web application:
You will need the mysql-connector-java-5.1.20-bin.jar file (downloadable from: http://dev.mysql.com/downloads/connector/j/ ), and restart the server added to the $CATALINA_HOME/common/lib directory.
OR added to the WEB-INF/lib folder of your web application.
You can find tutorials online of how to develop an application using Tomcat instead of Jetty. For example: https://wiki.auckland.ac.nz/display/BeSTGRID/Deploying+GWT+to+Tomcat+in+Eclipse
Reshi, stop and think about how applications really work. Nobody provides web pages with javascript to read/write databases, that would be crazy and unsecure. Servers are always in themiddle of all communication in this case. You need to create services that run inside your server, one of these services will be a database layer.
Javascript cant create network connections and read/write binary data, thus it would be insane to attempt to get the gwt compiler to compile any jdbc drvier and more.
Jetty does NOT stop us from connecting to a database. All you have to do is to follow the MVP model way. Although MVP is better bet against all hurdles, at a minimal point, you would have to try not having SQL code on the client package.

GWT Web Application project, with Hibernate?

I've made a Google Web Application Project in Eclipse and am now running into problems as I need to use from a server side point of view, with Hibernate with MySQL. I've just been told that Google Web Application projects can't run Hibernate connections to MySQL as they're deployed projects.
What's the best way for me to migrate this project somehow so it runs on say Glassfish and just uses GWT for the client side technologies that can then use Hibernate and MySQL, rather than actually being deployed?
Thanks,
David
You cannot access database from client-side directly.
GWT translates your client-side java code into Javascript which runs in browser; there is no way to directly access JDBC.
You will have to employ server-side which will handle your DB persistence. Your client can communicate via GWT-RPC, JSON, XML, or any other protocol - but the database connection part will always reside on server.
Note that the server part does not need to be in Java - it can use PHP or any other technology, as long as it understands the javascript generated out of your app.

Categories