Node ACS 404 Not found response code to Java http client

16 views
Skip to first unread message

Sunil Kumar Yadav

unread,
Nov 11, 2014, 6:28:23 AM11/11/14
to node...@googlegroups.com
Hi All,

I am working on a project in which there is a Java scheduler which is a HTTP Client and send xml as data to my node application. The Java http client uses the url as: "http://localhost:<nodeacs port>". In index function of application.js I have written my logic to receive the xml and convert the respective xml to json but when I run my app then I am getting 404 response code from acs but the same is working when I am sending request from browser. Please suggest me what I am lacking in this. I am posting both java http client and node acs code.

Java HTTP Client Code is
  
//http client

 URL url
= new URL("http://localhost:7654/");
 
HttpURLConnection httpCon = (HttpURLConnection) url.openConnection();
 httpCon
.setDoOutput(true);
 httpCon
.setRequestMethod("POST");
 
DataOutputStream os = new DataOutputStream(
 httpCon
.getOutputStream());
 
PrintWriter pw = new PrintWriter(os);
 pw
.println(xmlString.toString());
 pw
.flush();
 
System.out.println(httpCon.getResponseCode());
 
System.out.println(httpCon.getResponseMessage());




Following is my ACS index function:

function index(req, res) {
 console
.log("TEST *********************************");
 req
.on('data', function (data) {
 console
.log("Data arrived");
 
});
 req
.on('end', function () {
    console
.log('POSTed: ');
    res
.writeHead(200);
    res
.end();
 
});
}




I am runnig the code as: acs run --port 7654


From above code I am getting 404 response code in my java http client but if I write the same node logic in a simple js file as:


http.createServer(function (req, res) {
 req
.on('data', function (data) {
 console
.log("Data Arrived");
 
});
  req
.on('end', function () {
    console
.log('Done');
    res
.writeHead(200);
    res
.end();
 
});
}).listen('7654', function(){
console
.log("Server Connected to : "+ 7654);
});


and run the same as `node <jsfilename>` then it is working fine and sending 200 OK response to java http client.

1- Am I missing something in Node ACS app?
2- Do we need to configure http server in node acs app because if I write following logic in my application.js file then its working also in node acs:

http.createServer(function (req, res) {
 req
.on('data', function (data) {
 console
.log("Data Arrived");
 
});
  req
.on('end', function () {
    console
.log('Done');
    res
.writeHead(200);
    res
.end();
 
});
}).listen('7654', function(){
console
.log("Server Connected to : "+ 7654);
});




Wei Kong

unread,
Nov 11, 2014, 3:20:04 PM11/11/14
to node...@googlegroups.com
What exactly is the acs api call that returns 404 error? It is hard to tell from the code you are posting. and NO you don't need additional https server, if you use mvc framework it comes with express . 

--
You received this message because you are subscribed to the Google Groups "Node.ACS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-acs+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sunil Kumar Yadav

unread,
Nov 11, 2014, 11:49:54 PM11/11/14
to node...@googlegroups.com
Basically What I did is Created a simple Node ACS project and keep everything intact. I just make changes to application.js in controller folder which I have posted here.

Wei Kong

unread,
Nov 12, 2014, 4:07:24 PM11/12/14
to node...@googlegroups.com
Hi

By default, the ‘index’ route generated by acs new command will handle ‘GET’ requests.

But the request sent by your client is a ‘POST’ request.

Any particular reason for it? If you want to continue to use post, then you need to update config.son

 "routes": [ {
        "path": "/“,
        "method": “post",
        "callback": "application#index"
    }]

Sunil Kumar Yadav

unread,
Nov 13, 2014, 12:53:08 AM11/13/14
to node...@googlegroups.com
Hi

Thank for your response. I have updated my config.json file and in routes I put "method":"POST". Now its working fine but another issue is when my Java scheduler is posting xml to Node then also the req.on('data') event is not firing.
Reply all
Reply to author
Forward
0 new messages