I have developed a Spring MVC app that can detect Ajax requests sent into my local environment 'localhost:8000/examplePath' with a json body being received as a mapped parameter. So, until here, all is fine.
My question is: Do i still need to deploy my application on a container 'Apache Tomcat/ HTTP Server for example' for my application to be accessible externally on a possible production environment, and if so why?
I want to better understand the necessity of such, if my backend 'Spring MVC app' can already receive and respond to ajax requests
Spring MVC creates a Web application that must be deployed to a Web Application Server to run. The server handles the low level stuff such as raw sockets and the HTTP protocol.
This is because you can't access from internet to your local environment, you need a public adress to access your application from everywhere only if you want to access it over internet otherwise can do it with a local network connection to access it.
If you want any container, you can do it easy with Pivotal. This a container platform for Spring apps.
Related
I want to know how a web service written using java and spring framework able to receive and respond to HTTP request using web server. Is web server is one of the component of a web framework or it is independent of what framework we use. Can we deploy service written in node + express on a tomcat server ? If web server is a part of web framework then what is the flow. How spring instantiate a web server and how multiple clients request are responsed. Is it true that tomcat server can create a max limit of 200 threads only . What if we have more than 200 client request, why the response does not get delayed.
For handling http requests you will simply deploy the java/spring web application as war or convert into spring boot jar.
Tomcat can have more than 200 threads.
Can you deploy node+express on tomcat? the theoretical answer is possibly with some hack, but the practical answer is no.
Node is designed to run as a separate process. You can run your app using:
$node app.js
I have developed SAPUI5 application and trying to use servlets for implementing some server side functionality.
I have taken guidance from this tutorial
I use JQuery ajax call from SAPUI5 controller to Servlet which works fine on my local development environment ( i.e. Eclipse Neon , localhost ).
//Name of servlet is GetUserServlet , mapping defined in web.xml
$.get('GetUserServlet', {
userName : "Hello World"
}, function(responseText) {
alert(responseText);
});
This Ajax call successfully calls servlet (200 status) and Hello World is alerted when I run this from Eclipse on my local machine. Basically I capture in servlet parameter userName value and send back to controller js file
string text = request.getParameter("username");
response.getWriter().write(text );
But when this application is deployed to ABAP server , the Ajax call to servlet throws 404 (not found error) as seen in Network console of Chrome developer tools.
Has anybody deployed SAPUI5 application with servlet functionality on ABAP ?
Is it some path issue ?
Please tell cause of error or hint in direction to solve this issue.
You are mixing things up a little. The UI5 app is only a front-end component which, in your case, communicates with a backend JEE application (which contains your servlet). I would assume that you are deploying your servlet + UI5 app locally on e.g. a Tomcat instance (or any other web container). You cannot deploy a Java application to the BSP repository.
The page that you have linked from SCN refers to the old ABAP BSP functionality (which is now obsolete; the BSP repository is simply used to store static files of UI5 applications).
The only way in which you could deploy a JEE application (e.g. a WAR) to an ABAP backend is if the backend is in fact a ABAP+Java Netweaver installation. To be honest, I have never personally seen such a system in use. In this case, you don't even need to use the BSP repository, you can deploy the JEE backend (servlets and what ever else) and the static resources (the UI5 app) inside the JEE "Engine" of the server.
Otherwise, if you have only a plain ABAP system, you have the following possibilities:
Transform your Servlet in an ABAP REST Service or maybe a Gateway Service (depending on what you want to achieve).
Deploy the application to some external java web container or application server. Communicate with the ABAP backend through either JCo (RFC) or through some other mechanism (SOAP, REST, etc).
Deploy the application to the SAP Cloud Platform and communicate with the ABAP backend using the SAP Cloud Connector.
The reason why you are getting 404 is because the servlet is not deployed in SAP Server.
You can always connect to any Servlet or REST/Web Service API from a SAP UI5 Application but you will have below things to take care of to be able to access those services:
The service should be deployed properly on a server, if it is a an
ODATA or Hana Service then it will be easy to access as it will be in
same domain and can be deployed in Gateway or HANA servers.
If the service is deployed on any other server which is in a
different domain then you need to update the response headers of your
servelt/service to allow Cross Origin access otherwise browser will
block it and give Cross Origin not allowed error.
The 3 main response headers that you will need in this case are:
Access-Control-Allow-Origin : This can be either a "*" or comma separated domain names that you want to allow access to.
Access-Control-Allow-Methods : GET,POST etc
Access-Control-Allow-Headers : You can tell which header you want the browser to allow in cross domain service such as Origin, Content-Type, Accept;
I have a server which access DB and uses Apache MINA for managing connections.
I would like to expand this server and allow it to handle REST requests and I would like that every REST resource will have access to my server's context.
I have started implementing a Dynamic Web Application using Jersey 1.18 using Tomcat as container.
But I cannot figure out how to combine my server with the web service...
Is there a way to initialize the Jersey stack inside my custom service and avoid the Tomcat ??
I hope my question makes sense...
Thank you,
Oren
I want to run a standalone java application on a remote server. It would not be accessible to clients, but would do background calculations and interact with a database and Secure Socket connection to a third party site. It would also interact with a php site.
Do I have to deploy this with JSP, or can I write a standalone application? If so, how would I deploy a standalone java application (jar file) on a remote server? I understand that I must have them install a jvm on the server (not a problem) but then how would I deploy it (if possible). Would I start it with a command line?
I know I have much to learn, but I am not sure how I would access the command line on a remote server. Through the cPanel?
Thanks.
First of all, you'll want to set up some firewall rules to allow access to that server. I'm hoping that you don't expose that server naked to the Internet.
If all you need is database access exposed on the Internet, I don't see why it can't be a secured web app deployed on a servlet/JSP engine and accessed via a web server. You can leverage basic auth for security, JDBC access to the database from the server, and servlets as controllers to accept requests in a nice REST API.
It'll save you the complications of sockets and inventing your own protocol (use HTTP), starting and stopping the application (now it's just a web server/servlet engine), and deployment (send a WAR file).
Does it really must be a 'standalone' application? I think that in your case the best match would be to use Spring container to load your application within some server (tomcat?) and expose services via standard controllers - with Spring you only have to add some annotations on services methods actually.
Then, your php site can interact with these controllers using for example ajax requests.
If your application is written already, you can easily transform it to run within Spring container. It's very non-invasive and promotes usage of POJOs.
For my web application, I am thinking about using the Spring framework. Initially, I was thinking of having different actions like create user or login, but now I have to expose some functionality to other applications. Should I create a web service that I call from my application and others do as well, or create an action from Spring and then just have others call the web service? It seems like I should minimize the different ways to call something, but does it make sense to call a web service that is running on the same application server as my main app? Would this be a bad idea from a performance stand point?
Update
I was concerned that Tomcat wouldn't be able to serve both the static or dynamic pages on port 80 (so users could go to www.example.com/welcome.jsp instead of www.example.com:8080/welcome.jsp), as well as a web service but I guess it doesn't matter as both are just served as requests from Tomcat. I'm guessing this means I'll have to change Tomcat to run on port 80 and other applications will have access the web service via this port. Or I could leave Tomcat running on port 8080 and put Apache in front on Tomcat on port 80 and Apache will serve the requests to Tomcat. Is that correct?
I'd put the common business logic in a "business service" and :
call it from an action in your web app
expose it as a web service for other applications
To me, there is nothing bad with this approach and it's pretty easy and clean to implement it with Spring. Actually, I would find ugly to expose this business service as web service only and to call it from the web app (and I'm pretty sure that this will be more complicated to implement on the web app side). You have different "usage contexts", just expose the adequate interface for them.
(EDIT: I'm answering a question of the OP posted as comment below)
You can deploy the web application and the web service in the same WAR (but this is just a deployment choice, you could package the business logic in a JAR and use it in several WARs). Regarding the port, I'm not sure to understand your question. Traditionally, you'll use a web server (e.g. apache) in front of your application server. If you don't, you can always choose to run you app server on port 80. Actually, in both case you are free to use whatever port you want. Using port 80 is just convenient.
Yes, your update is correct.