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;
Related
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.
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
I have a stand alone Java application that needs to get information (string data) from a Java EE application, running on a Glassfish 3.1 Application server. I have created a web service for my Java app, but I'm wondering how I could achieve communication with the Java EE glass fish app (using servlet?).
I hope to have a method on my app that can be called from, for example, a client running on glassfish (and vice-versa). This method would have something like a String array as parameter, so that I would be able to pass the data between the apps.
Note: I am unable to deploy my app on Glassfish, since we are trying to achieve separation till we are sure the application I am developing will not cause Glassfish to crash ( we currently have other critical apps running on Glassfish). Also note that this is all taking place on the same machine.
You should develop a web service and deploy it on Glassfish within your existing application. You can do this via a Servlet based web service, or a Session Bean web service, whichever is more appropriate for you.
You will then create a web service client against that web service for your Java app, and integrate it appropriately with calls to the servers via the web service.
Of course, this should all be done against development servers, not your production servers. Glassfish can be deployed pretty much anywhere: your machine, another machine, a VM, in "the cloud". Not having a development server available for, well, development is unacceptable. There is no way you can determine if your app will "crash Glassfish" unless you can test it.
To quote the esteemed Donald Knuth: "I have only proved it correct, not tried it."
Get a test server, develop against it. Move forward.
Have you looked at the URL class.
try this url Java URL example
This may help
I have problem, In my case i use ExtJS as Web Client Front-end framework and that front-end deployed in IIS server, i try to request using Ext.data.Store.load() to Back-end Application Server deployed in Apache Tomcat(Because my Back-end programming language is Java), and there no action when i execute Ext.data.Store.load(),
why Ext.data.Store.load() not working in IIS Server, Whereas it worked fine when Front-end deployed in Apache Tomcat,,
There is something must i configure with IIS Server ?
Did you configure the store proxy to invoke the tomcat service specifying tomcats host:port/contextpath ?
By default store proxy will just use the context path. That's the reason the same codebase is working as expected when deployed in tomcat.
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.