1

我正在使用 node.js 和 spring web 服务。我在 tomcat 服务器上部署了 spring web 服务应用程序,并且节点正在运行。我正在使用将调用节点的 Web 应用程序,并且从节点调用 Spring REST Web 服务。我能够将 JSON 数据获取到节点中,但是在从节点调用 Spring REST Web 服务时出现以下错误:

    at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:202)
    at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:136)
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:159)
    at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:257)
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:222)
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:211)
    at org.jboss.resteasy.springmvc.ResteasyHandlerAdapter.createModelAndView(ResteasyHandlerAdapter.java:87)
    at org.jboss.resteasy.springmvc.ResteasyHandlerAdapter.handle(ResteasyHandlerAdapter.java:74)
    at org.jboss.resteasy.springmvc.ResteasyHandlerAdapter.handle(ResteasyHandlerAdapter.java:24)
    at org.jboss.resteasy.springmvc.ResteasyWebHandlerTemplate.handle(ResteasyWebHandlerTemplate.java:39)
    at org.jboss.resteasy.springmvc.ResteasyHandlerAdapter.handle(ResteasyHandlerAdapter.java:45)
    at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
    at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
    at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
    at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:789)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:647)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:305)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at com.project.webservices.filter.AuthorizationFilter.doFilter(AuthorizationFilter.java:76)
    at org.springframework.web.filter.DelegatingFilterProxy.invokeDelegate(DelegatingFilterProxy.java:346)
    at org.springframework.web.filter.DelegatingFilterProxy.doFilter(DelegatingFilterProxy.java:259)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:243)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:210)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:222)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:171)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:947)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1009)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:589)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
    at java.lang.Thread.run(Thread.java:722)
Caused by: java.io.EOFException: No content to map to Object due to end of input
    at org.codehaus.jackson.map.ObjectMapper._initForReading(ObjectMapper.java:2775)
    at org.codehaus.jackson.map.ObjectMapper._readValue(ObjectMapper.java:2691)
    at org.codehaus.jackson.map.ObjectMapper.readValue(ObjectMapper.java:1315)
    at org.codehaus.jackson.jaxrs.JacksonJsonProvider.readFrom(JacksonJsonProvider.java:419)
    at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:105)
    at org.jboss.resteasy.plugins.interceptors.encoding.GZIPDecodingInterceptor.read(GZIPDecodingInterceptor.java:63)
    at org.jboss.resteasy.core.interception.MessageBodyReaderContextImpl.proceed(MessageBodyReaderContextImpl.java:108)
    at org.jboss.resteasy.core.MessageBodyParameterInjector.inject(MessageBodyParameterInjector.java:169)
    ... 37 more

以下是我的 node.js 代码:

    var express = require("express"), 
    app = express(), 
    http = require("http").createServer(app);
    var requestObj = require('request');  

    var responseBody = "";

    app.use(express.bodyParser());

    function getSample(token){
        requestObj({
                url : "http://127.0.0.1:8080/project/sample/get",
                method : "POST",
                headers : { "Content-Type" : "application/json","pubKey":token}
            },
            function (error, response, body) {
                responseBody=body;
            }
        );
        console.log("responseBody:= "+responseBody);
    }

    function something(token,jsonbody){
        console.log("jsonbody :- "+JSON.stringify(jsonbody));
        requestObj({
                url : "http://127.0.0.1:8080/project/something/childurl",
                method : "POST",
                headers : { "Content-Type" : "application/json","pubKey":token},
                bosy : JSON.stringify(jsonbody)
            },
            function (error, response, body) {
                responseBody=body;
            }
        );
        console.log("responseBody:= "+responseBody);
    }

    app.post('/samples', function(request, response){
        console.log(request.body);
        var methodName = request.method;
        var token = request.body.pubKey;
        console.log("Called method is :-"+methodName);
        if(methodName=="POST"){
            getSample(token);
        }
        response.send(responseBody);
    });


    app.post('/something', function(request, response){
        console.log(request.body);
        var methodName = request.method;
        var token = request.body.pubKey;
        console.log("Called method is :-"+methodName);
        if(methodName=="POST"){
            something(token,request.body);
        }
        response.send(responseBody);
    });


    app.listen(8088);
4

1 回答 1

2

在功能something()中,您缺少body:参数。同样,如果您有 json 有效负载和响应,您应该使用json:true.

requestObj({
                url : "http://127.0.0.1:8080/project/something/childurl",
                method : "POST",
                headers : { "Content-Type" : "application/json","pubKey":token},
                body : JSON.stringify(jsonbody),
                json: true
            },
            function (error, response, body) {
                responseBody=body;
            }
        );
于 2013-08-26T10:16:23.880 回答