0

We are using a three tiered architecture for an application. We have a database on one end, a front end server running IIS on the other end, and in the middle a glassfish server for java servlets.

So far we have been using javascript AJAX calls (which run on the client) to access the glassfish server to activate the servlets to get the data. When we make a call like this:

$.GET(url, function(response){
  ...code here
});

or

var data = new FormData();
    var request = new XMLHttpRequest();
        request.onreadystatechange = function() {

        };

    request.open("get", URL);
    request.send(data);

Then the network notes that the middle tier is being accessed by the client, at least for the first example. We need instead for the IIS server to make the request to the glassfish server.

We've considered using Node.js with Socket I/O, or DropWizard, or a number of other products but since we already have an existing architecture we are hoping to find something that will enable us to make the calls server side with minimal rewrite. Is there a best practice for this, does it involve using RESTful or SOAP on the Java side? Any help in this regard would be appreciated.

Marcel Marino
  • 962
  • 3
  • 17
  • 34
  • 1
    Outside of a web browser they're usually just called HTTP requests. – joews Oct 17 '16 at 21:29
  • So, is your entire question: "How's the best way to make HTTP requests to a remote server from a Java server?". – jfriend00 Oct 17 '16 at 21:31
  • @jfriend00 No, I should have been more specific. The front end web server is not running Java, that's the middle tier server. The front end web server is running IIS. – Marcel Marino Oct 17 '16 at 21:38
  • @joews Do you mean to tell me that AJAX calls made in Javascript come from the client, but HTTP or HTTPS requests run off of the server? My understanding (which I REALLY hope is false) is that both run off the client. Or are AJAX requests also HTTP requests and they are just called something else outside of the client? – Marcel Marino Oct 17 '16 at 21:39
  • "AJAX" is just another way of saying "Async HTTP(S) requests from a web browser". – joews Oct 17 '16 at 21:42
  • Then, please completely rewrite your question to explain exactly what you'r'e asking. Right now, your question contains all sorts of misleading and extraneous information that apparently has nothing to do with the question and what you are actually asking is not clear at all. – jfriend00 Oct 17 '16 at 21:43
  • @joews That's what I thought. Do you know what is best practice for doing those off of a server rather than client? – Marcel Marino Oct 17 '16 at 21:43
  • I'm afraid I don't understand - there isn't any difference. You use a HTTP library and point it at the right URL. – joews Oct 17 '16 at 21:44
  • Ajax requests are JUST http requests from a browser. AJAX is just a moniker invented by the browser people to describe the API they used, but once the request is on the network, it's JUST a plain HTTP request. Over the network, they are the same whether initiated by a browser or by some server. – jfriend00 Oct 17 '16 at 21:44
  • Authentication is one difference. Your server will need to understand how to act on behalf of many users. How you do that depends on the constraints of your environment - it's a complex topic. – joews Oct 17 '16 at 21:49
  • From what I'm being told, when I do a $.get(url, function(responseText){ ...code here}); that is the client getting the information and the front end server does nothing. Now we've also written code like var request = new XMLHttpRequest(); request.open("get", url); request.send(dataPackage); when sending forms. Is the latter option one that runs off the web server? I will update the question now. – Marcel Marino Oct 17 '16 at 21:49
  • Node.js doesn't have `XMLHttpRequest` - that's a browser API. You usually use the `http` library or something built on top of it like `request` or `axios`. – joews Oct 17 '16 at 21:52
  • `$.get` is jQuery's AJAX, built on top of XHR. And `var request = new XMLHttpRequest();` is the XHR itself - low-level way to make an HTTP request from the browser. Both examples you gave are HTTP requests made directly by the browser to the URL. – Buzinas Oct 17 '16 at 21:54
  • @Buzinas That's what I was afraid of. So how can we access a servlet on a glassfish server from code executed on an IIS server is the question. – Marcel Marino Oct 17 '16 at 21:57
  • @joews Could you be more specific about the http library? Is that something added onto Node.js or something else entirely? – Marcel Marino Oct 17 '16 at 21:59
  • 1
    It's a built-in library. It's the [first Google result for "node http"](https://nodejs.org/api/http.html). – joews Oct 17 '16 at 22:03
  • So I suppose I'll be running with Node.js and using an additional library to make the requests. My only concern is how easily this can be done dynamically. Most examples I've seen serve up an entire HTML page on load, rather than being able to press a button on the web page which executes server side code to retrieve data for the web page to play with. – Marcel Marino Oct 17 '16 at 22:08
  • It's pretty difficult to understand your problem, and even more difficult to understand what you're trying to achieve. – Buzinas Oct 17 '16 at 22:09
  • @MarcelMarino I think there might be a good question hiding here. Why don't you define what your IIS and glass flish server are doing and what code they are running. It might help with context. – Stewart Oct 17 '16 at 22:13
  • @Buzinas I would like to explain it better, but I don't know what more to say. I am executing httprequests on the client. I need the webserver to make those requests. – Marcel Marino Oct 17 '16 at 22:13
  • But in some way, you'll still need the browser to make the requests to this webserver that would proxy that request to the backend server, right? – Buzinas Oct 17 '16 at 22:14
  • @Stewart I'm under the impression I did that. The glassfish server is running java servlets which access a database. The IIS server is serving up web pages to the client. What other information should I include? – Marcel Marino Oct 17 '16 at 22:14
  • @Buzinas Oh my yes, the client can (in fact must) talk to the IIS server for these requests, our architecture just doesn't allow the client to directly talk to the glassfish server. – Marcel Marino Oct 17 '16 at 22:16
  • @MarcelMarino but your saying the IIS is making a request to the glassfish server. Why would it do that? – Stewart Oct 17 '16 at 22:16
  • @Stewart Because our architecture doesn't allow for the client to talk to glassfish on its own. – Marcel Marino Oct 17 '16 at 22:16
  • So do you want to use IIS as a proxy to glassfish? – Stewart Oct 17 '16 at 22:18
  • @Stewart That would solve the problem I am facing, so yes. I'm open to other suggestions of course. – Marcel Marino Oct 17 '16 at 22:19
  • So either expose glass fish to the client or proxy requests via IIS. Have I missed something? – Stewart Oct 17 '16 at 22:21
  • @Stewart The one thing I can't do is expose glassfish to the client. If I could, I wouldn't be having this issue. Is there a way to make proxy http requests through a server like IIS? My understanding is that I needed some server side implementation like Node.js. – Marcel Marino Oct 17 '16 at 22:24
  • I think I found what you meant @Stewart https://www.iis.net/learn/extensions/configuring-application-request-routing-arr/creating-a-forward-proxy-using-application-request-routing – Marcel Marino Oct 17 '16 at 22:28
  • Bingo! Forget node.js. You should not need to add another server to your setup. It's worth noting that your question has now taken on a completely different meaning. I would suggest a total rewrite to something along the lines of "How do I setup a reverse proxy with IIS"? – Stewart Oct 17 '16 at 22:30
  • @Stewart Now that I know that is the solution I've been looking for, I will probably do that. – Marcel Marino Oct 17 '16 at 22:32
  • It seems to me that you need to teach your frontend server to proxy the requests to you glashfish, only ofr the allowed clients – mtsdev Oct 17 '16 at 23:55

0 Answers0