RPC with Angular-Wakanda - wakanda

How do I call a method in module declared as rpc module server side at client side with angular-wakanda? I installed angular-json-rpc but I don't know what is the correct url for the module. I always receive an error "not found".

The correct Url for the RPC module is :
<script type="text/javascript" src="/rpc-proxy/rpcName"></script>
But it doesn't work with angularJs, it work only with the WAF framework(prototype).
I suggest you to use entity methods or dataclass methods to communicate with the server.
Walid.

Related

Java Servlet on Tomcat called from AJAX

I want to call a Servlet from ajax in a Java WebApp, using Tomcat7.
I used the annotation #WebServlet("/VServlet") to mapping it in the WebApp, because of Tomcat7 support Servlet 3.0.
I call the servlet with the jquery command "$.getJSON('VServlet', function(data){ ... });" but if I use the string 'VServlet', it doesn't work.
Only if I use the entire url 'http:// localhost:8080/WebAppName/VServlet' it works, but only in my pc. However I have to deploy it on a server that has a commercial domain name, obviously different from "localhost".
Please, can anyone tell me if there is a way to address the servlet with a relative url?
Because if I use a string like 'http://my.domain.it:8080/WebAppName/VServlet' it doesn't work on the Tomcat7 that is on the server machine.
Thanks.
------------------EDIT-----------------------
I try to explain better my problem.
I have a Java Servlet that return a json structure. The servlet is called in a javascript file that have to draw a graph in a web page, building a SVG image. I have to deploy this web app on a commercial Windows server with Tomcat7 installed.
The web app generally works. Any errors are displayed from the user point of view. Simply the image doesn't appear if I use that strings I wrote above, to call the servlet.
I suppose that the servlet doesn't respond because I use a wrong address/naming. If I use an absolute url, the servlet responds to the js caller, but I need a relative string, so if the domain name of the server will change, I won't change the code of the js file too.
When you call
$.getJSON('VServlet', ... );
you are making a HTTP GET request to an URL relative to the current URL. That is, if you're in /webapp/users/user.xhtml you'll be sending a request to /webapp/users/VServlet which obviously doesn't match the URL pattern of your servlet and not the thing you're trying to achieve.
You need to take into account the context path of a JSF application that's available in view as #{request.contextPath} to build up a proper absolute URL:
$.getJSON('#{request.contextPath}/VServlet', ... );
This will send a request to http://localhost:8080/webapp/VServlet.
In case you need to send request to a path relative to the root, such request URLs start with a slash, / and represent URLs relative to the root, no matter where you're right now:
$.getJSON('/VServlet', ... );
This will send a request to http://localhost:8080/VServlet.
if your js code is inside jsp page Instead of the code
$.getJSON('VServlet', function(data){ ... });
write
"$.getJSON('${request.contextPath}/VServlet', function(data){ ... });
other wise if this code is in some js file in a function something like
function someFunction(){
$.getJSON('VServlet', function(data){ ... });
}
and you are calling function someFunction() from jsp
then you add a parameter to the function like this -
function someFunction(url){
$.getJSON('VServlet', function(data){ ... });
}
and now call it from jsp like this -
someFunction('${request.contextPath}/VServlet')
because ${request.contextPath}/VServlet is an el tag and it will get compiled only in jsp page

getting jsonp to work in asp.net api

having issues getting my jsonp to work with my client backbone script,pagenator keep gettgin invalid key error
having looked around people say its to to do with my service not return jsonp.
For example SyntaxError: invalid label, i've written a mvc4 web api service this is what it returns does it look right and also is there anything i need to add to my api to support jsonp ?
{
"odata.metadata":"http://test.test.uk/api/odata/$metadata#lnews","value":[
{
"ID":1,"title":"This is a test news artical","mainContent":"<p>\r\n\tthis is a test article</p>\r\n","featured":1,"visiblehomepage":1,"thedatetime":"2013-08-05T10:36:05.98","expireon":"2013-08-15T00:00:00","category":17,"embargo":null,"embargotime":"PT0S","embargodate":null,"customthumbnail":null,"news_layout":3,"LNBE":0,"LNBN":0,"LNBS":0,"LNBW":0,"LNWV":0,"LNWS":1,"LNDY":0,"LNSW":0,"LNSH":0,"LNCV":0
},{
"ID":2,"title":"This is a test article","mainContent":"<p>\r\n\twelcome to the best site in the world</p>\r\n","featured":1,"homepage":1,"thedatetime":"2013-08-05T10:42:54.763","expireon":"2013-08-22T00:00:00","category":null,"embargo":null,"embargotime":"PT0S","embargodate":null,"customthumbnail":"Water lilies.jpg","news_layout":4,"LNBE":1,"LNBN":1,"LNBS":1,"ff":1,"LNWV":1,"LNWS":1,"LNDY":1,"LNSW":1,"LNSH":1,"LNCV":1
}
]
}
Here is a JSONP URL:
http://odata.netflix.com/v2/Catalog/Genres?$format=json&$callback=?
Here is a diagram:
CLIENT SERVER
------ ------
Makes URL request Looks up function matching this URL param ($callback)
Executes asynchonously If found, executes function asynchonously
Returns from callback Returns data from server side as a function, or error
References
Learn By Example Guide for Select State.gov Data (SSD): JSONP

Cross domain REST using Ajax in Dojo

I have using dojo.xhrPost method in Dojo and trying to call url from different domain server REST services. I have facing problem in cross-domain.
I have getting ERROR ::: “ RequestError: Unable to load https://core.dev.moxynetwork.com/rest/authservice/authuser status: 0”
Please help me.
Regards&Thanks,
Vijayalaxmi
dojo.xhrPost is deprecated and will be removed.
Use dojo/request/script with dojo 1.9 :
require(['dojo','dojo/ready','dojo/_base/lang','dojo/_base/array', 'dojo/request/script' ],
function(dojo, ready, lang, array, script){
ready(function(){
script.get('ENTER-YOUR-URL.com',{jsonp: "callback"}).then(function(resJson){
console.log(resJson);
});
});
});
You need to implement JSONP or Cross-Origin Resource Sharing (CORS) to manage cross domain calls. Both are techniques for the REST API that is nothing you can do on the client side.

Apache CXF Webservice failing on AJAX call

We have developed a webservice based on Apache CXF.
This is working fine when accessed normally that is using APIGEE or by using a JaxWsProxyFactoryBean (A clinet for Apache CXF). But when I tried to access this by providing the SOAP Address through AJAX call it is giving me the following exception:
INFO: Interceptor has thrown exception, unwinding now
org.apache.cxf.interceptor.Fault: No such operation: (HTTP GET PATH_INFO: /tata-ws-1.0/TataWeb)
at org.apache.cxf.interceptor.URIMappingInterceptor.handleMessage(URIMappingInterceptor.java:77)
at org.apache.cxf.phase.PhaseInterceptorChain.doIntercept(PhaseInterceptorChain.java:236)
at org.apache.cxf.transport.ChainInitiationObserver.onMessage(ChainInitiationObserver.java:89)
...
This is my AJAX call code happens on click of a button
<a onclick="sendRequest('GET','http://localhost:8080/tata-ws-1.0/services/TataWeb')"href="#">
Get Data:
function sendRequest(method, url)
{
method == 'POST';
{
http.open(method,url,true);
http.onreadystatechange = handleResponse;
http.send(null);
}
}
The URL for WSDL is correct because when i use
http://localhost:8080/tata-ws-1.0/services/TataWeb?wsdl it shows the WSDL for that webservice.
Please share your inputs.
Thanks.
Your need to send a SOAP request rather than a regular HTTP request.
Best way would be use something like this:
http://archive.plugins.jquery.com/project/jqSOAPClient

xhrPost : from an http view to an https url

using Dojo, is it possible to make an Ajax call using xhrPost from an HTTP view to a HTTPS url ?
The url must be HTTPS (as defined in Struts).
If I simply set "MyCommand" as the 'url' parameter of the xhrGet, I get a 302 error code.
If I transform "MyCommand" using javascript to something like "https://......./servlet/MyCommand" I see the following error in Firebug : "uncaught exception: Permission denied to call method XMLHttpRequest.open".
I'm stuck using both approaches, the only solution I found is to remove the "https" clause in the struts configuration file, and of course this is not a correct solution :)
Thanks for any help.
Best regards,
Nils
connection to https from http involves a different port of the target. This violates the same-origin policy which should be enforced by the browser to the running javascript code.
It should work with an iframe..
dojo.io.iframe encapsulates this behaviour for you
http://docs.dojocampus.org/dojo/io/iframe
If your server responds with a redirect to a non-ssl (correctly to same-origin) page you should be able to read the response (because the iframe is now in the same-origin).

Resources