Rest webservices GET call not working in java after hosting - java

I have hosted Java Web application developed using RestFul Web services, hibernate and angularjs. MySql is the DB. After Hosting in Tomcat, restful webservices GET calls are not pulling correct data from the DB after making a transaction.
i.e.,
GET call is accessed for a resource
POST call is made to the Resource
Again the GET call is made, which shows the initial values alone but not the newly posted entry.
This happens in few machines only. While in few other machines, it works as expected.
I have cleared the browser cache as well. still not working.
Please help on this.

Related

Java web application calling a SOAP service on weblogic is unstable in production

I have a Java web application deployed on an Oracle WebLogic 11g server. The application makes calls to a SOAP service also written in java and deployed on the same WebLogic 11g server. The SOAP service has two method which are called one after the other. The Body of the two calls are very similar, with the only difference being that the second one has two extra parameters, one of them being a base64 encoded signature image.
We have the same setup on our Production server and our Test server.
The application works 100% of the time on the test server. On the production server the call to the first method of the SOAP service executes correctly all of the time but the call to the second method only works sometimes. From what we can see so far is that when the method does not work then the method is not being called at all.
Is there anything that might cause this instability that we have missed?
UPDATE
I was incorrect in saying We have the same setup on our Production server and our Test server.
The production environment is actually distributed over two servers. If we hard code the calls to the SOAP service to only access one of the nodes then the application works perfectly.
It seems as though we have set up the load balancing or available hosts incorrectly.
It could be that an exception is preventing from reaching the 2nd method call or some configuration properties are not set on the production server...
Try running your application with Production profile and investigate further.

Deploying springboot app and ui separately

Currently, I have a springboot jar file with a bunch of rest and apis including calls for login deployed on ec2. I also have a separate code base for my ui i.e with js,html,css. What is the best way to deploy this on aws and keep it separate from the backend.
This can be done in many ways. But will share a simple way.
Deploy your spring boot app in one aws instance.
Deploy the other front end app on the other aws instance.
This is a kind of two tier application where the server and client app are hosted in different instance. You can restrict the access of your rest api to be accessed only by the instance where you host front end app. For trial you can use heroku account. E.g.
Github: https://github.com/krishna28/springbootapi
Also check https://github.com/krishna28/etodo

JAVA RESTful server on Heroku: allow the upload/reading of the SQLite database

I'm developing a RESTful web service. I developed both the server and the client in JAVA using JPA and a SQLite database, and locally it works perfectly. I simply run the Application class of the client and it sends the requests to localhost and gets the responses in a perfect fashion.
However, when I deploy the server on Heroku, creating the .war needed (both using ant or exporting the .war from Eclipse), I successfully obtain the root element at myapp.example/rest/buildings, so it means that there is not any problems with the .war itself:
<buildings/>
However, if I try to do a simple POST request to add a new building (that locally works) I obtain the following 500 error:
**HTTP Status 500 - Exception [EclipseLink-4002] (Eclipse Persistence Services - 2.5.2.v20140319-9ad6abd): org.eclipse.persistence.exceptions.DatabaseException**
I think the problem is that it cannot know where to find the SQLite database, so the question is:
How can I upload the SQLite database to Heroku in order to allow my server to read the data from it and then to return responses to my local client? It must be included in some way on the .war package? (I read that Heroku hasn't the support for this RDBMS, however I heard that there are workarounds, since the SQLite database is simply a file as many others).
Thank you in advance, and feel free to ask me other snippets or something else if the question is not clear!
You will not want to use SQLite on Heroku because Heroku uses an ephemeral filesystem. That means the changes to your sqlite database will be lost every 24 hours. The ephemeral filesystem is important because it ensures consistency on the server (i.e. prevents snowflake servers). SQLite also prevents your app from scaling up (i.e. running more instance of your app) because they would each have a different database.
Heroku provides free PostgreSQL instances, which I recommend you use. You'll need to change you JDBC driver and configure your app use JDBC_DATABASE_URL, but probably not much else.
Sidenote: before you edited the post it looks like you mentioned a java.lang.NoSuchMethodError error. This is likely due to non-deterministic classpath loading.

What are some techniques for deploying a single page application that depends on a rest api?

I'm building a Single Page Application (using AngularJS) that renders data from a REST API call it makes to a legacy system. This legacy system is very large, written in Java and takes minutes to deploy so we decided it would be more productive to develop the Single Page Application completely separate from the legacy system.
The problems occurred once we tried to communicate with the legacy system's REST API. Although both apps were deployed locally to the same host, they were deployed on different app servers so I needed to use different ports when communicating. But because the SPA was communicating to a REST API on a different port, the browsers prevented my requests to protect against Cross Site Scripting attacks.
We found this build tool name lineman (that leverages grunt) that made it easy to proxy http requests. This got us around the cross site scripting limitation but this was only suitable in development mode.
Now that we've got a proof of concept working, we want to know how we're supposed to deploy these apps together without the proxying. It's hard for me to find advice on how to do this because Angular doesn't assume you have a backend in the first place and most people that use Angular on the front end aren't using Java in the backend (if that even matters).
We're running into issues like, the context paths of the apps change depending on if they're deployed in prod mode vs dev mode so we've gotta think of clever ways to avoid broken links that work for both modes. I wonder if/where I took a wrong step here along the way. Should I avoid developing the SPA on a separate server from the backend?
We had the same issues. The URL situation is that you will have different URL paths to your java REST API because you are in different environments.
In order to make these paths cascade down to the angular application, we had to first externalize the base paths in the web app (the app that spawns Angular) to use values that are set during deployment depending on where it is deployed to. We have values in our app servers that link to XML values in config files that we then reference in the application.
Then we create a call from the Angular app to the webapp that spawns it (not the java REST API) that will return the URL that is correct for the environment.
In the angular application, we can then setup the resuorce with the correct base path (the rest of the URL should stay the same from environment to environment).
If you can get the first part working correctly with externalizing the environmental settings, the rest is not difficult.
I would put apache in front and use mod_proxy as a reverse proxy to the apps.
Say your REST API is at http ://localhost:9000. If the angular app is only static assets you can deploy it directly under apache. If not you reverse proxy it as well.
For the REST api yoivsetup a reverse proxy for say /api to localhost:9000. So any request hitting the apache at http://some.host.name/api will now be forwarded to the legacy system. Now fix the angular app and you are done.
For local development you can use node-http-proxy which is ease to setup in a similar fashion

why does my Java session values refuses to update?

I have a strange problem here and I dont know if any one has an idea what could cause it. I'm working on a Java EE (Servlets & JSPs) web application project that uses AJAX to update the web page. When I test it on my localhost server (im using Tomcat 7.0.26) it works perfectly well. But when I run the same application on my hosting server, some of the values or the page itself refuse to update correctly. These values are stored in a session attribute and when they are typed in they are sent to the servlet via AJAX request, like I said, they work well as expected on my localhost but on the hosting server that I subscribed, there are errors. Does anyone have any idea what is going on there please? The site is http://www.optdesolver.com
I can think of a number of things
Your server configuration. How long that the session timeout is set?
Your app has a cache of files.
Your browser has some cache of files.
You are not deploying your proyect properly.
You have multple instances in your server.
You have to restart the server in order to make it refresh its contents.
I suggest you use some kind of version number in your html to verify that is not a cache realated problem.
I hope this helps.

Categories