Quantcast
Channel: Appcelerator Developer Center Q&A Unanswered Questions 20
Viewing all articles
Browse latest Browse all 8068

Node ACS 404 Not found response code

$
0
0

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.js 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);
});

Viewing all articles
Browse latest Browse all 8068

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>