0

I am trying a thrift client-server hello world call.

The server is written in java and the client is in javascript.

Client.html is as follows:

<html>
<script src="thrift.js" type="text/javascript"> </script>
<script src="helloWorld.js" type="text/javascript" ></script>
<script src="callServer.js" type="text/javascript" ></script>
<body>
Test The thrift call....
<button onclick="getInfo();">Click me</button>
</body>
</html>

Above thrift.js is thrift javascript library version 8.0 and helloWorld.js is the generated js file from the following thrift idl.

service helloWorld{
    string getWorld();
}

callServer.js

/*callServer.js*/
function getInfo() {
    alert("reached callServer.js");
    var url = "http://localhost:8080/myWebProj/HelloWorldServlet";
    var transport = new Thrift.Transport(url);
    var protocol  = new Thrift.Protocol(transport);


    var client    = new helloWorldClient(protocol);
     alert(client.getWorld());

}

At the server side I have a servlet mapped in web.xml and one implementation class

public class HelloWorldServlet extends TServlet{

    private static final long serialVersionUID = -3425847860067398133L;

    public HelloWorldServlet() {
        super(new HelloWorld.Processor(new Hworld()),
                new TJSONProtocol.Factory());
    }

}
public class Hworld implements HelloWorld.Iface{

    @Override
    public String getWorld() throws TException {
        // TODO Auto-generated method stub
        System.out.println(" in hello World .... ");
        return "Hello World";
    }

}

The sysout in above code is printed successfully when I try to hit the server.But at the client side I get NS_ERROR_FAILURE. I guess I am doing something wrong.Please help me.In case any other info is required plz post it as comment.

Abhinav
  • 1,720
  • 4
  • 21
  • 33
  • I can't see any problems in your code so far. Have you checked http://helpful.knobs-dials.com/index.php/0x80004005_%28NS_ERROR_FAILURE%29_and_other_firefox_errors and/or tested in other browsers? – JensG Dec 09 '13 at 19:16
  • checked in Chrome debugger.getting --> `XMLHttpRequest cannot load http://localhost:8080/myWebProj/HelloWorldServlet. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. ` – Abhinav Dec 10 '13 at 04:34
  • Then that's your issue. There are plenty of answers here on SO, e.g. http://stackoverflow.com/questions/20059658/xmlhttprequest-cannot-load-no-access-control-allow-origin-header-is-present-o or http://stackoverflow.com/questions/19821753/jquery-xml-error-no-access-control-allow-origin-header-is-present-on-the-req – JensG Dec 10 '13 at 19:41

0 Answers0