Servlet resteasy-servlet的Servlet.service()抛出异常:org.jboss.resteasy.spi.UnhandledException:java.lang.NullPointerException

时间:2018-11-05 08:12:09

标签: java unirest

我提出了从Web服务获取令牌的特殊请求,但我一直收到以下错误消息:

ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/HO_JOBS].[resteasy-servlet]] (http-DRBPWB02%2F10.121.9.67-8150-1) Servlet.service() for servlet resteasy-servlet threw exception: org.jboss.resteasy.spi.UnhandledException: java.lang.NullPointerException
    at org.jboss.resteasy.core.SynchronousDispatcher.unwrapException(SynchronousDispatcher.java:345)
    at org.jboss.resteasy.core.SynchronousDispatcher.handleApplicationException(SynchronousDispatcher.java:321)
    at org.jboss.resteasy.core.SynchronousDispatcher.handleException(SynchronousDispatcher.java:214)
    at org.jboss.resteasy.core.SynchronousDispatcher.handleInvokerException(SynchronousDispatcher.java:190)
    at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:534)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:496)
    at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:119)
    at org.jboss.resteasy.plugins.server.servlet.ServletContainerDispatcher.service(ServletContainerDispatcher.java:208)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:55)
    at org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher.service(HttpServletDispatcher.java:50)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:847)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:324)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:242)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161)
    at org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:181)
    at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.event(CatalinaContext.java:285)
    at org.jboss.modcluster.catalina.CatalinaContext$RequestListenerValve.invoke(CatalinaContext.java:261)
    at org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:88)
    at org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:100)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:159)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
    at org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
    at org.jboss.web.tomcat.service.request.ActiveRequestResponseCacheValve.invoke(ActiveRequestResponseCacheValve.java:53)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:362)
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877)
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:654)
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:951)
    at java.lang.Thread.run(Thread.java:662)
Caused by: java.lang.NullPointerException
    at com.sm.bps.api.nuvelco.NuvelcoUtil.getToken(NuvelcoUtil.java:27)
    at com.sm.bps.api.nuvelco.NuvelcoService.getToken(NuvelcoService.java:18)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:140)
    at org.jboss.resteasy.core.ResourceMethod.invokeOnTarget(ResourceMethod.java:255)
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:220)
    at org.jboss.resteasy.core.ResourceMethod.invoke(ResourceMethod.java:209)
    at org.jboss.resteasy.core.SynchronousDispatcher.getResponse(SynchronousDispatcher.java:519)
    ... 25 more

我的班级部署在jBoss应用程序服务器中。作为新手,我从字面上无法确定哪里出了问题。如果我做错了任何事情,请检查我的源代码:

package com.sm.bps.api.nuvelco;

import org.apache.log4j.Logger;

import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;
import com.mashape.unirest.http.exceptions.UnirestException;

public class NuvelcoUtil {
    protected static Logger logger = Logger.getLogger(NuvelcoUtil.class);

    public static String getToken() {
        HttpResponse<String> response = null;
        try {
             response = Unirest.post("http://api.nuvelco.com/token")
                     .header("content-type", "application/x-www-form-urlencoded")
                     .header("cache-control", "no-cache")
                     .body("grant_type=password&username=demo_user&password=demo_pass&client_id=paymentApp")
                     .asString();
        } catch (UnirestException e) {
            e.printStackTrace();
        }

        return response.getBody();
    }

    public static String refreshToken() {
        HttpResponse<String> response = null;
        try {
            response = Unirest.post("http://api.nuvelco.com/token")
                     .header("content-type", "application/x-www-form-urlencoded")
                     .header("cache-control", "no-cache")
                     .body("refresh_token=5a788c269d714dbabcf77e2aa19b95e2&grant_type=refresh_token&client_id=paymentApp")
                     .asString();
        } catch (UnirestException e) {
            e.printStackTrace();
        }

        return response.getStatusText();
    }

    public static String getConsumerBill(String accNum) {
        HttpResponse<String> response = null;
        try {
            response = Unirest.post("http://api.nuvelco.com/v1/bill/inquiry")
                     .header("accept", "application/json")
                     .header("content-type", "application/json")
                     .header("authorization", "Bearer ivEKsRy0eg4dZ4MFDutQ4SYKYxmapmUkluabdXR26lmjpqqQ1ipyTF71HHcPzbkpXQkYCyS2H4zafmKTiIPsKaiosGP5SAxCL6__qe9yYCbHdmuKRIAjW             cBn2WC5tYunMJiht4PlBA_UAx4NDSNV2Ozjt07pRzFQvntto-T87YZ4XADDCzpmRo-Ti43uuiRyNrcn6crhlUKkKZqyGiv_5QVdmzA2xRZgz_SqbVBi4VQIzyNqWf32WrC_LmxTxAw-d6rICYjTYFspwtaNq_aJMFDQBLQPPyHoNjVGmRZLdwiLtBn4INdnkwmvOBvPAf6_7peYQ1i3pBw7Ar6aOcw")
                     .header("cache-control", "no-cache")
                     .body("{\"accountNo\":\"" + accNum + "\"}")
                     .asString();
        } catch (UnirestException e) {
            e.printStackTrace();
        }

        return response.getStatusText();
    }
}

任何帮助将不胜感激。谢谢。

0 个答案:

没有答案