Hi All, Thanks for the suggested approaches. Was able to get it working by submitting the form directly as Supun mentioned. As Rasika pointed out, it was going through another jag controller which was generalizing all the POST calls hence the request was altered.
@Supun: It seems that this .jag is used to make the actual POST request, so that it can be generalized and reused. Since most POST calls to the API hve the same structure this jag is included. Therefore there won't be two POST calls happening, only the call in .JAG. Thanks for the help everyone! Thanks & Regards, Himasha On Sun, Jun 21, 2015 at 9:14 PM, Supun Sethunga <[email protected]> wrote: > Hi, > > Would like to highlight a couple of things in the current implementation. > > 1. From what I understood, currently, the form is submitted to a .jag > file and again inside that .jag file, a POST is done to the back end. > (Please correct me if I've mistaken)? This sounds expensive as there are > two network-calls happen for a single action. Why not do this with a single > post? You can actually eliminate the Jaggery layer here. > 2. First POST (form submission) is done with url parameters. Not > really sure how preferred that approach is. Feels its better to stick to > either url parameters OR post parameters, but not both. > > If (1) is fixed, then (2) will not be applicable anyway. Think It would > solve the "null" issue too. > > Thanks, > Supun > > On Sun, Jun 21, 2015 at 11:23 AM, Rasika Perera <[email protected]> wrote: > >> Hi Supun & Himasha, >> >> The AJAX call for the " >> https://192.168.1.2:9443/bpmn-explorer/send?req=/bpmn/runtime/tasks/15048/attachments >> <https://www.google.com/url?q=https%3A%2F%2F192.168.1.2%3A9443%2Fbpmn-explorer%2Fsend%3Freq%3D%2Fbpmn%2Fruntime%2Ftasks%2F15048%2Fattachments&sa=D&sntz=1&usg=AFQjCNGtlHGgHQIkEKjRr4tnkFlGAySrqw> >> " resolves to a controller called "communication.jag" [1] inside the >> "bpmn-explorer" jaggery app. >> >> 1. localIP = process.getProperty('carbon.local.ip'), >> 2. httpPort = process.getProperty('mgt.transport.http.port'), >> 3. httpUrl = "http://"+localIP+":"+httpPort, >> 4. //.... >> 5. run = request.getMethod(); >> 6. if(run == "POST"){ >> 7. req = request.getParameter("req"); >> 8. url = req; >> 9. data = request.getContent(); >> 10. result = post( httpUrl + url, JSON.stringify(data), headers, "text"); >> 11. log.debug("BPMN Rest POST results: " + result); >> 12. } >> 13. //.... >> >> 1. This controller passes the call for the service url mentioned in "req" >> parameter. httpUrl is always HTTP(not HTTPs) and port is 9763(not 9443). >> Please refer above line #3; this is the reason for getting >> "*http://192.168.1.2:9763 >> <http://192.168.1.2:9763>*" instead of "*https://192.168.1.2:9443 >> <https://192.168.1.2:9443>*". >> >> 2. The reason for getting "null" for "req" parameter is quite >> unclear(Refer above line #7). Try to pass it as a "form parameter" instead >> of "query parameter" for the "POST" request[2]. >> >> Thank you >> >> [1] >> https://github.com/wso2/carbon-business-process/blob/e5e669d97e6f77dab7b26682bb1d8abcb0e5d576/components/bpmn/bpmn-explorer-web/src/web/controller/communication.jag#L26 >> >> [2] http://www.w3.org/TR/html4/interact/forms.html#submit-format >> >> On Sun, Jun 21, 2015 at 9:03 AM, Supun Sethunga <[email protected]> wrote: >> >>> @Rasika, >>> >>> >>>> She's still getting the same error. Then I suggested just try and see >>>> the output of hardcoding the desired url into "url" parameter. >>>> *url*: " >>>> https://192.168.1.2:9443/bpmn-explorer/send?req=/bpmn/runtime/tasks/15048/attachments >>>> <https://www.google.com/url?q=https%3A%2F%2F192.168.1.2%3A9443%2Fbpmn-explorer%2Fsend%3Freq%3D%2Fbpmn%2Fruntime%2Ftasks%2F15048%2Fattachments&sa=D&sntz=1&usg=AFQjCNGtlHGgHQIkEKjRr4tnkFlGAySrqw> >>>> ", >>>> ..... >>>> }) >>>> Still getting the same error. >>> >>> $('#attachForm').ajaxForm({ >>>> >>> >>> If it is the *exact* error as mentioned above, then probably it is due >>> to caching. >>> >>> >>> @Himasha, >>> >>> One other option is to submit the form directly to the backend webapp >>> (without interfering with java-script). In ML we had to go for java-script >>> since we needed to set some custom headers to the request. Here I don't see >>> such a requirement, hence you may avoid javascript and use "action" >>> attribute of the html form.. >>> >>> Thanks, >>> Supun >>> >>> On Sat, Jun 20, 2015 at 11:37 AM, Rajith Vitharana <[email protected]> >>> wrote: >>> >>>> Hi Himasha, >>>> >>>> I was able to do that file uploading with below code sample. >>>> >>>> Below is the client side ajax call >>>> >>>> function addAttachment(id){ >>>> >>>> var data = new FormData(); >>>> jQuery.each(jQuery('#files')[0].files, function(i, file) { >>>> data.append('file-'+i, file); >>>> }); >>>> >>>> jQuery.ajax({ >>>> url: '/test3/endpoint.jag', >>>> data: data, >>>> cache: false, >>>> contentType: false, >>>> processData: false, >>>> type: 'POST', >>>> success: function(data){ >>>> alert(data); >>>> } >>>> }); >>>> } >>>> >>>> and below is the way to read the file inside jaggery app.(endpoint.jag) >>>> >>>> var file = request.getFile("file-0"); >>>> file.open("r"); >>>> var message = ""; >>>> message = file.readAll(); >>>> log.info("file content "+message); >>>> file.close(); >>>> >>>> Thanks, >>>> >>>> >>>> On Sat, Jun 20, 2015 at 11:31 AM, Rasika Perera <[email protected]> >>>> wrote: >>>> >>>>> Hi Nirmal & all, >>>>> >>>>> I suppose below error is getting due to conflicting of the "url" >>>>> parameter defined by user and "url" >>>>> parameter inside "ajaxForm" method. >>>>> >>>>> >>>>>> Caused by: org.mozilla.javascript.WrappedException: Wrapped >>>>>> java.lang.IllegalArgumentException: Invalid uri ' >>>>>> *http://192.168.1.2:9763null'*: invalid port number >>>>>> (<<http>>/META-INF/scripts/http.js#220) >>>>> >>>>> >>>>> >>>>> var *url* = "/" + CONTEXT + "/send?req=/bpmn/runtime/tasks/" + id + >>>>> "/attachments"; >>>>> $('#attachForm').ajaxForm({ >>>>> *url*: httpUrl + *url* >>>>> , >>>>> ..... >>>>> }) >>>>> >>>>> So I suggested; >>>>> >>>>> var >>>>> >>>>> *serviceUrl*= "/" + CONTEXT + "/send?req=/bpmn/runtime/tasks/" + id >>>>> + "/attachments"; >>>>> $('#attachForm').ajaxForm({ >>>>> *url*: httpUrl + >>>>> *serviceUrl* >>>>> , >>>>> ..... >>>>> }) >>>>> >>>>> She's still getting the same error. Then I suggested just try and >>>>> see the output of hardcoding the desired url into "url" parameter. >>>>> >>>>> $('#attachForm').ajaxForm({ >>>>> *url*: " >>>>> https://192.168.1.2:9443/bpmn-explorer/send?req=/bpmn/runtime/tasks/15048/attachments >>>>> <https://www.google.com/url?q=https%3A%2F%2F192.168.1.2%3A9443%2Fbpmn-explorer%2Fsend%3Freq%3D%2Fbpmn%2Fruntime%2Ftasks%2F15048%2Fattachments&sa=D&sntz=1&usg=AFQjCNGtlHGgHQIkEKjRr4tnkFlGAySrqw> >>>>> ", >>>>> >>>>> ..... >>>>> }) >>>>> >>>>> Still getting the same error. So three things needs to be clarified. >>>>> >>>>> 1. Does HTML form has an action parameter which affects the jQuery >>>>> .ajaxForm method. >>>>> 2. Any javascript that replaces the value of url parameter? >>>>> 3. Is it a problem with caching? >>>>> >>>>> >>>>> Thank you >>>>> >>>>> On Sat, Jun 20, 2015 at 10:54 AM, Himasha Guruge <[email protected]> >>>>> wrote: >>>>> >>>>>> Hi Nirmal, >>>>>> >>>>>> it passes the intended url to send the form data. >>>>>> var httpUrl = location.protocol + "//" + location.host; ( >>>>>> https://192.168.1.2:9443) >>>>>> var url = "/" + CONTEXT + "/send?req=/bpmn/runtime/tasks/" + id + >>>>>> "/attachments"; >>>>>> >>>>>> On Sat, Jun 20, 2015 at 10:44 AM, Nirmal Fernando <[email protected]> >>>>>> wrote: >>>>>> >>>>>>> >>>>>>> >>>>>>> On Sat, Jun 20, 2015 at 9:47 AM, Himasha Guruge <[email protected]> >>>>>>> wrote: >>>>>>> >>>>>>>> Hi All, >>>>>>>> >>>>>>>> In order to send an input file using Ajax I'm using [1] which is >>>>>>>> also used in ES and ML . My ajax call looks like following where the >>>>>>>> url >>>>>>>> value is ( >>>>>>>> https://192.168.1.2:9443/bpmn-explorer/send?req=/bpmn/runtime/tasks/15048/attachments >>>>>>>> ). >>>>>>>> >>>>>>>> $('#attachForm').ajaxForm({ >>>>>>>> url: httpUrl + url, >>>>>>>> >>>>>>> What does the above line do? >>>>>>> >>>>>>> >>>>>>>> success : function(res){ >>>>>>>> window.location = httpUrl + "/" + CONTEXT + "/inbox"; >>>>>>>> >>>>>>>> }, >>>>>>>> error : function(res){ >>>>>>>> var errorText = res.responseText >>>>>>>> alert('ERROR' + errorText); >>>>>>>> } >>>>>>>> >>>>>>>> }); >>>>>>>> >>>>>>>> When clicking on submit button of form, it goes to error function >>>>>>>> and i'm getting following exception trace on console. >>>>>>>> >>>>>>>> Caused by: org.mozilla.javascript.WrappedException: Wrapped >>>>>>>> java.lang.IllegalArgumentException: Invalid uri ' >>>>>>>> *http://192.168.1.2:9763null'*: invalid port number >>>>>>>> (<<http>>/META-INF/scripts/http.js#220) >>>>>>>> >>>>>>>> at >>>>>>>> org.mozilla.javascript.Context.throwAsScriptRuntimeEx(Context.java:1754) >>>>>>>> >>>>>>>> at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:148) >>>>>>>> >>>>>>>> at >>>>>>>> org.mozilla.javascript.FunctionObject.call(FunctionObject.java:386) >>>>>>>> >>>>>>>> at >>>>>>>> org.mozilla.javascript.optimizer.OptRuntime.call1(OptRuntime.java:32) >>>>>>>> >>>>>>>> at >>>>>>>> org.jaggeryjs.rhino.<<http>>.META_INF.scripts.c0._c_anonymous_5(<<http>>/META-INF/scripts/http.js:220) >>>>>>>> >>>>>>>> at >>>>>>>> org.jaggeryjs.rhino.<<http>>.META_INF.scripts.c0.call(<<http>>/META-INF/scripts/http.js) >>>>>>>> >>>>>>>> at >>>>>>>> org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:63) >>>>>>>> >>>>>>>> at >>>>>>>> org.jaggeryjs.rhino.<<http>>.META_INF.scripts.c0._c_anonymous_8(<<http>>/META-INF/scripts/http.js:232) >>>>>>>> >>>>>>>> at >>>>>>>> org.jaggeryjs.rhino.<<http>>.META_INF.scripts.c0.call(<<http>>/META-INF/scripts/http.js) >>>>>>>> >>>>>>>> at >>>>>>>> org.mozilla.javascript.optimizer.OptRuntime.callName(OptRuntime.java:63) >>>>>>>> >>>>>>>> at >>>>>>>> org.jaggeryjs.rhino.bpmn_explorer.controller.c4._c_script_0(/bpmn-explorer/controller/communication.jag:39) >>>>>>>> >>>>>>>> at >>>>>>>> org.jaggeryjs.rhino.bpmn_explorer.controller.c4.call(/bpmn-explorer/controller/communication.jag) >>>>>>>> >>>>>>>> at >>>>>>>> org.mozilla.javascript.ContextFactory.doTopCall(ContextFactory.java:394) >>>>>>>> >>>>>>>> at >>>>>>>> org.mozilla.javascript.ScriptRuntime.doTopCall(ScriptRuntime.java:3091) >>>>>>>> >>>>>>>> at >>>>>>>> org.jaggeryjs.rhino.bpmn_explorer.controller.c4.call(/bpmn-explorer/controller/communication.jag) >>>>>>>> >>>>>>>> at >>>>>>>> org.jaggeryjs.rhino.bpmn_explorer.controller.c4.exec(/bpmn-explorer/controller/communication.jag) >>>>>>>> >>>>>>>> at >>>>>>>> org.jaggeryjs.scriptengine.engine.RhinoEngine.execScript(RhinoEngine.java:567) >>>>>>>> >>>>>>>> ... 41 more >>>>>>>> >>>>>>>> Caused by: java.lang.IllegalArgumentException: Invalid uri >>>>>>>> 'http://192.168.1.2:9763null': invalid port number >>>>>>>> >>>>>>>> at >>>>>>>> org.apache.commons.httpclient.HttpMethodBase.<init>(HttpMethodBase.java:222) >>>>>>>> >>>>>>>> at >>>>>>>> org.apache.commons.httpclient.methods.ExpectContinueMethod.<init>(ExpectContinueMethod.java:93) >>>>>>>> >>>>>>>> at >>>>>>>> org.apache.commons.httpclient.methods.EntityEnclosingMethod.<init>(EntityEnclosingMethod.java:119) >>>>>>>> >>>>>>>> at >>>>>>>> org.apache.commons.httpclient.methods.PostMethod.<init>(PostMethod.java:106) >>>>>>>> >>>>>>>> at >>>>>>>> org.jaggeryjs.hostobjects.xhr.XMLHttpRequestHostObject.send(XMLHttpRequestHostObject.java:472) >>>>>>>> >>>>>>>> at >>>>>>>> org.jaggeryjs.hostobjects.xhr.XMLHttpRequestHostObject.jsFunction_send(XMLHttpRequestHostObject.java:284) >>>>>>>> >>>>>>>> at sun.reflect.GeneratedMethodAccessor82.invoke(Unknown Source) >>>>>>>> >>>>>>>> at >>>>>>>> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) >>>>>>>> >>>>>>>> at java.lang.reflect.Method.invoke(Method.java:601) >>>>>>>> >>>>>>>> at org.mozilla.javascript.MemberBox.invoke(MemberBox.java:126) >>>>>>>> >>>>>>>> I can't figure out what's being passed as null, because when >>>>>>>> analyzing the request file binary value is sent as expected. Any >>>>>>>> ideas/hints on what could be the issue would be appreciated. >>>>>>>> >>>>>>>> Thanks, >>>>>>>> Himasha Guruge >>>>>>>> *Software Engineer* >>>>>>>> WS*O2* *Inc.* >>>>>>>> Mobile: +94 777459299 >>>>>>>> [email protected] >>>>>>>> >>>>>>>> _______________________________________________ >>>>>>>> Dev mailing list >>>>>>>> [email protected] >>>>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev >>>>>>>> >>>>>>>> >>>>>>> >>>>>>> >>>>>>> -- >>>>>>> >>>>>>> Thanks & regards, >>>>>>> Nirmal >>>>>>> >>>>>>> Associate Technical Lead - Data Technologies Team, WSO2 Inc. >>>>>>> Mobile: +94715779733 >>>>>>> Blog: http://nirmalfdo.blogspot.com/ >>>>>>> >>>>>>> >>>>>>> >>>>>> >>>>>> >>>>>> -- >>>>>> Himasha Guruge >>>>>> *Software Engineer* >>>>>> WS*O2* *Inc.* >>>>>> Mobile: +94 777459299 >>>>>> [email protected] >>>>>> >>>>>> _______________________________________________ >>>>>> Dev mailing list >>>>>> [email protected] >>>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev >>>>>> >>>>>> >>>>> >>>>> >>>>> -- >>>>> With Regards, >>>>> >>>>> *Rasika Perera* >>>>> Software Engineer >>>>> M: +94 71 680 9060 E: [email protected] >>>>> LinkedIn: http://lk.linkedin.com/in/rasika90 >>>>> >>>>> WSO2 Inc. www.wso2.com >>>>> lean.enterprise.middleware >>>>> >>>>> _______________________________________________ >>>>> Dev mailing list >>>>> [email protected] >>>>> http://wso2.org/cgi-bin/mailman/listinfo/dev >>>>> >>>>> >>>> >>>> >>>> -- >>>> Rajith Vitharana >>>> >>>> Software Engineer, >>>> WSO2 Inc. : wso2.com >>>> Mobile : +94715883223 >>>> Blog : http://lankavitharana.blogspot.com/ >>>> >>>> _______________________________________________ >>>> Dev mailing list >>>> [email protected] >>>> http://wso2.org/cgi-bin/mailman/listinfo/dev >>>> >>>> >>> >>> >>> -- >>> *Supun Sethunga* >>> Software Engineer >>> WSO2, Inc. >>> http://wso2.com/ >>> lean | enterprise | middleware >>> Mobile : +94 716546324 >>> >> >> >> >> -- >> With Regards, >> >> *Rasika Perera* >> Software Engineer >> M: +94 71 680 9060 E: [email protected] >> LinkedIn: http://lk.linkedin.com/in/rasika90 >> >> WSO2 Inc. www.wso2.com >> lean.enterprise.middleware >> > > > > -- > *Supun Sethunga* > Software Engineer > WSO2, Inc. > http://wso2.com/ > lean | enterprise | middleware > Mobile : +94 716546324 > -- Himasha Guruge *Software Engineer* WS*O2* *Inc.* Mobile: +94 777459299 [email protected]
_______________________________________________ Dev mailing list [email protected] http://wso2.org/cgi-bin/mailman/listinfo/dev
