Spring javaweb应用程序节点集成问题
我有一个web应用程序正在向node.js发送请求。节点模块正在调用我的Spring REST模块。 我的web应用程序到节点的调用如下所示Spring javaweb应用程序节点集成问题,spring,node.js,jquery,rest,express,Spring,Node.js,Jquery,Rest,Express,我有一个web应用程序正在向node.js发送请求。节点模块正在调用我的Spring REST模块。 我的web应用程序到节点的调用如下所示 $.ajax({ type : "POST", url : "http://localhost:9090/module", dataType : 'json', data : msgDetails, xhrFields : { withCredentials : tr
$.ajax({
type : "POST",
url : "http://localhost:9090/module",
dataType : 'json',
data : msgDetails,
xhrFields : { withCredentials : true },
success : function(data) {
console.log("getInbox" + JSON.stringify(data.message));
}, error : function(data) {
alert("Error in the AJAX response." + data);
} });
var express = require("express"),
app = express(),
http = require("http").createServer(app);
var requestObj = require('request');
responseBody = "";
indexresponseBody = null;
app.use(express.bodyParser());
app.post('/module', function(req, res){
var tempInbox = "";
var tmp = req;
var authKey = req.body.pubKey;
var reqBody = req.body;
console.log("POST"+" - "+JSON.stringify(reqBody)+" - "+authKey);
restCMCall("http://ip:port/restmodule/controller/call", req, res,authKey,reqBody);
//res.end(JSON.stringify(body));
res.header('Content-Type', 'application/json');
//resp.header('Charset', 'utf-8');
res.send({"name1":"name"});
});
function restCMCall(resturl, req, res, authKey,reqBody){
var i = 0;
console.log("reqBody :- "+reqBody+" resturl "+resturl+" "+i++);
requestObj({
url : resturl,
method : "POST",
headers : { "Content-Type" : "application/json","pubKey":authKey},
body : JSON.stringify(reqBody)
},
function (error, resp, body) {
tempInbox = body;
console.log(resp+" inbox body :- "+" -------- "+i++);
//resp.writeHead(200, {'Content-Type':'application/json','charset':'UTF-8'});
//res.write(JSON.stringify({"hello":"xxx"}));
//res.end(JSON.stringify(body));
res.header('Content-Type', 'application/json');
//resp.header('Charset', 'utf-8');
res.send(body);
}
);
console.log(i++);
}
我的节点如下所示
$.ajax({
type : "POST",
url : "http://localhost:9090/module",
dataType : 'json',
data : msgDetails,
xhrFields : { withCredentials : true },
success : function(data) {
console.log("getInbox" + JSON.stringify(data.message));
}, error : function(data) {
alert("Error in the AJAX response." + data);
} });
var express = require("express"),
app = express(),
http = require("http").createServer(app);
var requestObj = require('request');
responseBody = "";
indexresponseBody = null;
app.use(express.bodyParser());
app.post('/module', function(req, res){
var tempInbox = "";
var tmp = req;
var authKey = req.body.pubKey;
var reqBody = req.body;
console.log("POST"+" - "+JSON.stringify(reqBody)+" - "+authKey);
restCMCall("http://ip:port/restmodule/controller/call", req, res,authKey,reqBody);
//res.end(JSON.stringify(body));
res.header('Content-Type', 'application/json');
//resp.header('Charset', 'utf-8');
res.send({"name1":"name"});
});
function restCMCall(resturl, req, res, authKey,reqBody){
var i = 0;
console.log("reqBody :- "+reqBody+" resturl "+resturl+" "+i++);
requestObj({
url : resturl,
method : "POST",
headers : { "Content-Type" : "application/json","pubKey":authKey},
body : JSON.stringify(reqBody)
},
function (error, resp, body) {
tempInbox = body;
console.log(resp+" inbox body :- "+" -------- "+i++);
//resp.writeHead(200, {'Content-Type':'application/json','charset':'UTF-8'});
//res.write(JSON.stringify({"hello":"xxx"}));
//res.end(JSON.stringify(body));
res.header('Content-Type', 'application/json');
//resp.header('Charset', 'utf-8');
res.send(body);
}
);
console.log(i++);
}
到目前为止,我能够从spring模块获得响应,并且能够在节点控制台上打印。但当我试图添加此响应以响应web应用程序发出的请求时,它不会被发送
在Firefox浏览器中,firebug显示为
Response Headers
Connection keep-alive
Content-Length 21
Content-Type application/json
Date Mon, 07 Oct 2013 16:13:38 GMT
X-Powered-By Express
但响应选项卡为空
我正在使用express模块调用SpringRESTWeb服务调用node.js
如果我遗漏了什么,请告诉我。我也尝试过使用
response.json(body)
但这也不起作用。我认为您应该向
url:http://localhost:9090/getInbox“
因为您尚未在节点应用程序中创建与节点模块中的POST:/module
匹配的端点,所以我正在向节点模块中的节点发出请求。请查找更新的帖子。web应用程序和REST应用程序都部署在同一台机器上的tomcat服务器上,而我的节点应用程序正在另一台机器/服务器上运行。