0

I have been requested to create a function for a web application where on the click of a button from Application A (Ruby on Rails Application) I generate a file with information that can be interpreted by Application B (Jboss/Maven Web App).

From web app A a new page opens up and shows a calculated result in web app B.

The calculated information from web app A is currently a json object to be sent (gson api) and the calculation performed on web app B is done in javascript.

So as of now I am using a form to send the data and open a new page via a GET request but I have concerns regarding the limitations of the GET request and how I should be able to retrieve the information from web app B's javascript on initiation.

Here is what I am currently doing.

Web App A

The json object

{ places: [ { latitude: 45.1, longitude: 15.2, city: 'Croatia' },
 { latitude: 30.254528,
   longitude: -97.84536,
   city: 'Regents School of Austin, 3230 Travis Country Circle, Austin, TX 78735, USA' },
 { latitude: 46.22764, longitude: 2.213749, city: 'France' },scores:[ 0,
 0,
 0,
 0.0055555557,
 0,
 0,
 0 ],transmissions: [ [ 0, 1, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ],
 [ 0, 0, 1, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0 ],
 [ 0, 1, 0, 0, 1, 3, 0, 0, 0, 0, 0, 0, 0, 2, 1, 1, 1 ],
 [ 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 ] ] }'"

The form code created by JQuery:

$('body').append($('<form/>').attr({
    'action': 'http://0.0.0.0:8080/webAppB',
        'method': 'get',
        'target': '_blank',
        'id': 'centrality'
}).append($('<input/>').attr({
    'type': 'application/json',
        'name': 'jsRequest',
        'value': JSON.stringify(arguments)
}))).find('#centrality').submit();

Web App B (javascript)

Parsing the GET data with

function getParameterByName(name) {
    name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
    var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
        results = regex.exec(location.search);
    return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " "));

then perform the action on start.

The information I am passing to web app B will vary in size. It is very possible to go over 2 kb with some of these json requests.

the current get parameter looks like this

jsRequest="{\"places\"%3A[{\"latitude\"%3A45.1%2C\"longitude\"%3A15.2%2C\"city\"%3A\"Croatia\"}%2C{\"latitude\"%3A30.254528%2C\"longitude\"%3A-97.84536%2C\"city\"%3A\"Regents+School+of+Austin%2C+3230+Travis+Country+Circle%2C+Austin%2C+TX+78735%2C+USA\"}%2C{\"latitude\"%3A46.22764%2C\"longitude\"%3A2.213749%2C\"city\"%3A\"France\"}%2C{\"latitude\"%3A53.41291%2C\"longitude\"%3A-8.24389%2C\"city\"%3A\"Ireland\"}%2C{\"latitude\"%3A37.09024%2C\"longitude\"%3A-95.71289%2C\"city\"%3A\"United+States\"}%2C{\"latitude\"%3A55.37805%2C\"longitude\"%3A-3.435973%2C\"city\"%3A\"United+Kingdom\"}%2C{\"latitude\"%3A-38.416096%2C\"longitude\"%3A-63.616673%2C\"city\"%3A\"Argentina\"}%2C{\"latitude\"%3A23.424076%2C\"longitude\"%3A53.847816%2C\"city\"%3A\"United+Arab+Emirates\"}%2C{\"latitude\"%3A56.130367%2C\"longitude\"%3A-106.34677%2C\"city\"%3A\"Canada\"}%2C{\"latitude\"%3A49.817493%2C\"longitude\"%3A15.472962%2C\"city\"%3A\"Czech+Republic\"}%2C{\"latitude\"%3A12.879721%2C\"longitude\"%3A121.77402%2C\"city\"%3A\"Philippines\"}%2C{\"latitude\"%3A41.87194%2C\"longitude\"%3A12.56738%2C\"city\"%3A\"Italy\"}%2C{\"latitude\"%3A51.16569%2C\"longitude\"%3A10.451526%2C\"city\"%3A\"Germany\"}%2C{\"latitude\"%3A60.128162%2C\"longitude\"%3A18.643501%2C\"city\"%3A\"Sweden\"}%2C{\"latitude\"%3A52.132633%2C\"longitude\"%3A5.291266%2C\"city\"%3A\"The+Netherlands\"}%2C{\"latitude\"%3A46.818188%2C\"longitude\"%3A8.227512%2C\"city\"%3A\"Switzerland\"}%2C{\"latitude\"%3A50.503887%2C\"longitude\"%3A4.469936%2C\"city\"%3A\"Belgium\"}]%2C\"scores\"%3A[0%2C0%2C0.05347222%2C0%2C0.0125%2C0.34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2C0%2C0%2C1%2C1%2C0]%2C[0%2C0%2C1%2C0%2C0%2C1%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0]%2C[0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0]%2C[0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0%2C0]]}"

As of now that GET parser does not function and even if I write/find a parser,this process may not get the job done for all data sets.

I have tried to use a post from a form, however it gives me the following error:

"NetworkError: 415 Unsupported Media Type

This only happens from the form though and I had assumed it was due to forms auto use of application/x-www-form-urlencoded data type.

the code on web app b runs fine if I make a straight ajax post, but that will not show the web page with the information I desire. Just a response json that I am further trying to send and run in client side javascript.

So Im wondering if I am taking the wrong approach?

Zach
  • 3
  • 2
  • 1
    why cant you use post ? – meda Sep 26 '14 at 14:41
  • @meda I am guessing he wanted a pure client-side method. JavaScript can't access POST data – Spokey Sep 26 '14 at 14:43
  • Well I am trying to use the web app B's existing code which plots the data using javascript.The app setup is way more complicated than it needs to be but there are more parties involved than just me so I need to use what I have. – Zach Sep 26 '14 at 14:46
  • 1
    So what exactly is your current problem ? Does the code not work? Performance issues? The GET limitations http://stackoverflow.com/questions/2659952/maximum-length-of-http-get-request – Spokey Sep 26 '14 at 14:50
  • If you only want a review of your code or best practices you may want to try http://codereview.stackexchange.com/ – Spokey Sep 26 '14 at 14:55

0 Answers0