java - 将 REST 请求从 Node 发送到 Jetty 时出现问题

标签 java node.js rest jetty jersey-2.0

我在从 Node.js 向 Jetty 发送 REST (POST) 请求时遇到问题。当我从 REST 客户端发送相同的请求时,它工作正常。 这是 Node js代码:

    var postheaders = {
    'Content-Type' : 'application/json',
    'Content-Length' : Buffer.byteLength(jsonObject, 'utf8')
};
var optionsPost = {
    host : '127.0.0.1', // here only the domain name
    // (no http/https !)
    port : 8080,
    path : '/external/session', // the rest of the url with parameters if needed
    method : 'POST', // do GET
    headers :postheaders    
};

console.info('Options prepared:');
console.info(jsonObject);
console.info('Do the POST call');


var reqPost = https.request(optionsPost, function(res) {
    console.log("statusCode: ", res.statusCode);
    // uncomment it for header details
//  console.log("headers: ", res.headers);


     res.on('data', function(d) {
        console.info('POST result:\n');
        process.stdout.write(d);
        resp.contentType('application/json');
        resp.send(d);
        console.info('\n\nCall completed');
    }); 


});
reqPost.end();
reqPost.on('error', function(e) {
    console.error(e);
});
};

这是 Jetty 中的错误:

Jul 30, 2015 4:18:58 PM com.sun.jersey.spi.container.ContainerResponse mapMappableContainerException
SEVERE: The exception contained within MappableContainerException could not be mapped to a response, re-throwing to the HTTP container
java.io.IOException: java.util.concurrent.TimeoutException: Idle timeout expired: 30001/30000 ms
    at org.eclipse.jetty.util.SharedBlockingCallback$Blocker.block(SharedBlockingCallback.java:234)
    at org.eclipse.jetty.server.HttpInputOverHTTP.blockForContent(HttpInputOverHTTP.java:67)
    at org.eclipse.jetty.server.HttpInput$1.waitForContent(HttpInput.java:500)

有人可以帮我解决这个问题吗? 谢谢

最佳答案

您没有发送任何响应内容,Jetty 一直在等待数据,直到发生超时。

要在 reqPost.end() 之前发送数据,请调用 reqPost.write(...your data...)

关于java - 将 REST 请求从 Node 发送到 Jetty 时出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31721808/

相关文章:

java - 在特定gradle任务上设置调试JVM args

java - 如何为ProxyFactoryBean设置多个目标并根据Config调用其中一个目标方法?

java - 返回未找到方法的错误响应正文 - Spring Rest WebService

java - Java 读/写文件

java - 使用有状态 session Bean (EJB)

node.js - 下面代码中的 "this"Animal' "this.model(' this.type"中的 )"and "代表什么?

javascript - 如何使用 socket.io 发送消息

javascript - 如何使用 mysql 数据库中的 nodejs 和 socket.io 在网页上获取实时更新?

mysql - 将数据发送到 REST api 的良好实现?

java - 记录 Jersey rest api 的