在RestEasy的异步请求空指针异常 [英] Null Pointer Exception in RestEasy Asynchronous Request

查看:1298
本文介绍了在RestEasy的异步请求空指针异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在RestEasy的工作,我已经做出异步请求到服务器。真正的目的是,我将提交将被转换成一个.xlsx文件将于ATLEAST 10秒填写一份表格。因此,异步请求是这里的最佳方式。我遵循的程序从以下链接。

<一个href=\"https://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html_single/#Asynchronous_HTTP_Request_Processing\" rel=\"nofollow\">https://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html_single/#Asynchronous_HTTP_Request_Processing

我正在做这样的Ajax请求。

  $。阿贾克斯({
    网址:'休息/ parentPath / childPath',
    输入:GET,
    成功:功能(数据,状态XHR){
        的console.log(xhr.getResponseHeader('位置'));
    },
    失败:功能(数据){
        的console.log(数据);
    },
    错误:功能(错误,状态){    }
});

ParentClass.java

 进口javax.ws.rs.container.AsyncResponse;
进口javax.ws.rs.container.Suspended;@零件
@Path(/ parentPath)
公共类父类{
    @得到
    @Path(childPath)
    @Produces(text / plain的)
    公共无效asyncFunction(@Suspended最终AsyncResponse响应){
        线程t =新的Thread(){
            @覆盖
            公共无效的run()
            {
                尝试
                {
                    。响应JAXRS = Response.ok(基础)类型(MediaType.TEXT_PLAIN).build();
                    的System.out.println(进入======================= =================== ==============================);
                    response.resume(JAXRS);
                }
                赶上(例外五){
                    e.printStackTrace();
                }
            }
        };
        t.start();
    }
}

如果我只是做一个Ajax请求,它给了我 503服务不可用错误,但我得到我的异步任务执行,我可以看到我的SYSOUT $ P $确认psent在wildfly日志。但是,这不是一个方式异步应该如何完成。我已经能够看到我的异步任务的第二个请求的响应。我遵循的程序在这个环节。

https://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html_single/#async_job

如果我把?非同步= TRUE 请求URL,我立刻让 202接受与响应异步工作在响应的位置。但它甚至没有进入try语句。引发错误在这样的wildfly终端。

  19:11:41733警告[org.jboss.resteasy.core.ExceptionHandler](池4线程1)未能执行GET / parentPath / childPath:org.jboss。 resteasy.spi.BadRequestExcept
离子:org.jboss.resteasy.spi.metadata.ResourceMethod@44d4407c的失败处理参数
        在org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:104)RestEasy的-JAXRS-3.0.10.Final.jar:]
        在org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:112)RestEasy的-JAXRS-3.0.10.Final.jar:]
        在org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296)RestEasy的-JAXRS-3.0.10.Final.jar:]
        在org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250)RestEasy的-JAXRS-3.0.10.Final.jar:]
        在org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237)RestEasy的-JAXRS-3.0.10.Final.jar:]
        在org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356)RestEasy的-JAXRS-3.0.10.Final.jar:]
        在org.jboss.resteasy.core.AsynchronousDispatcher.invokeSuper(AsynchronousDispatcher.java:237)RestEasy的-JAXRS-3.0.10.Final.jar:]
        在org.jboss.resteasy.core.AsynchronousDispatcher $ 1.call(AsynchronousDispatcher.java:278)RestEasy的-JAXRS-3.0.10.Final.jar:]
        在org.jboss.resteasy.core.AsynchronousDispatcher $ 1.call(AsynchronousDispatcher.java:269)RestEasy的-JAXRS-3.0.10.Final.jar:]
        在java.util.concurrent.FutureTask.run(FutureTask.java:266)的rt.jar:1.8.0_25]
        在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)的rt.jar:1.8.0_25]
        在java.util.concurrent.ThreadPoolExecutor中的$ Worker.run(ThreadPoolExecutor.java:617)的rt.jar:1.8.0_25]
        在java.lang.Thread.run(Thread.java:745)的rt.jar:1.8.0_25]
显示java.lang.NullPointerException:产生的原因
        在org.jboss.resteasy.core.ResourceMethodInvoker.initializeAsync(ResourceMethodInvoker.java:374)RestEasy的-JAXRS-3.0.10.Final.jar:]
        在org.jboss.resteasy.core.AsynchronousResponseInjector.inject(AsynchronousResponseInjector.java:43)RestEasy的-JAXRS-3.0.10.Final.jar:]
        在org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:89)RestEasy的-JAXRS-3.0.10.Final.jar:]
        ... 12更多

如果我再次提出同样的要求非同步= TRUE ,它显示了同样的错误,但(池4线程2) 而不是(池4线程1)

这意味着异常没有在服务器端,但在运行时发生层。怎么把我的code内发生任何异常将在日志文件present但不是在wildfly终端。我会发布了web.xml,WebConfig.java,的build.gradle文件。我只是复制其在JBoss文档做同样的事情,但我不能弄清楚为什么这个例外在wildfly层存在的。

在web.xml

 &LT;?XML版本=1.0编码=UTF-8&GT?;
&LT; web应用程序的xmlns =htt​​p://java.sun.com/xml/ns/javaee的xmlns:XSI =htt​​p://www.w3.org/2001/XMLSchema-instanceXSI:的schemaLocation = http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd版本=3.0&GT;    &lt;显示-名称&gt; Web应用程序&LT; /显示-名称&gt;    &LT;分配/&GT;    &LT;听者GT;
        <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
    &LT; /听者GT;    &LT;听者GT;
        <listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
    &LT; /听者GT;    &LT;! - 为Spring XML文件上下文配置的位置 - &GT;
    &LT;的context-param&GT;
        &LT;参数-名称&gt;&contextConfigLocation的LT; /参数 - 名称&gt;
        &LT;参数值&GT;
            类路径:/applicationContext-resources.xml
            类路径:/applicationContext-dao.xml
            类路径:/applicationContext-service.xml
            类路径*:/ applicationContext.xml中
            /WEB-INF/applicationContext*.xml
        &LT; /参数值&GT;
    &LT; /的context-param&GT;    &LT;的context-param&GT;
        &LT;参数名方式&gt; resteasy.servlet.mapping preFIX&LT; /参数 - 名称&gt;
        &LT;参数值&GT; /休息&LT; /参数值&GT;
    &LT; /的context-param&GT;    &LT;的context-param&GT;
        &LT;参数-名称&gt;&resteasy.async.job.service.enabled LT; /参数 - 名称&gt;
        &LT;参数值&GT;真&LT; /参数值&GT;
    &LT; /的context-param&GT;    &LT;的context-param&GT;
        &LT;参数-名称&gt;&resteasy.async.job.service.max.job.results LT; /参数 - 名称&gt;
        &所述; PARAM-值GT; 100℃/参数值&GT;
    &LT; /的context-param&GT;    &LT;! - 最长等待时间当客户端查询它的作业 - &GT;
    &LT;的context-param&GT;
        &LT;参数-名称&gt;&resteasy.async.job.service.max.wait LT; /参数 - 名称&gt;
        &LT;参数值&GT; 300000&LT; /参数值&GT;
    &LT; /的context-param&GT;    &LT;! - 那运行作业后台线程线程池的大小 - &GT;
    &LT;的context-param&GT;
        &LT;参数-名称&gt;&resteasy.async.job.service.thread.pool.size LT; /参数 - 名称&gt;
        &所述; PARAM-值GT; 100℃/参数值&GT;
    &LT; /的context-param&GT;    &LT;! - 设置作业的基本路径的URI - &GT;
    &LT;的context-param&GT;
        &LT;参数-名称&gt;&resteasy.async.job.service.base.path LT; /参数 - 名称&gt;
        &LT;参数值&GT; /非同步/工作与LT; /参数值&GT;
    &LT; /的context-param&GT;    &LT;&servlet的GT;
        &LT; servlet的名称&gt; RestEasy的-的servlet&LT; / servlet的名称&gt;
        <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
        &LT;初始化参数&GT;
            &LT;参数-名称&gt;&javax.ws.rs.Application LT; /参数 - 名称&gt;
            &LT;参数值&GT; com.mypackage.service.WebConfig&LT; /参数值&GT;
        &LT; /初始化参数&GT;
        &所述;负载上启动→1&下; /负载上启动&GT;
    &LT; / servlet的&GT;    &LT; Servlet映射&GT;
        &LT; servlet的名称&gt; RestEasy的-的servlet&LT; / servlet的名称&gt;
        &LT; URL模式&GT; / REST / *&LT; / URL模式&GT;
    &LT; / Servlet映射&GT;    &LT;欢迎-文件列表&gt;
        &LT;欢迎-文件&gt;&login.html的LT; /欢迎-文件&gt;
    &LT; /欢迎-文件列表&gt;&LT; / web-app的&GT;

WebConfig.java

 进口java.util.HashSet中;
进口java.util.Set中;进口javax.ws.rs.core.Application;公共类WebConfig扩展应用{    私人设置&LT;对象&gt;单身=新的HashSet&LT;对象&gt;();
    私人设置&LT;班级&LT;&GT;&GT;空=新的HashSet&LT;班级&LT;&GT;&GT;();    公共WebConfig(){
        //此处添加您的RESTful资源
        this.singletons.add(新SignupService());
        this.singletons.add(新UserService());
        this.singletons.add(新父类());
    }    公开组&LT;班级&LT;&GT;&GT; getClasses()
    {
        返回this.empty;
    }    公开组&LT;对象&gt; getSingletons()
    {
        返回this.singletons;
    }}

的build.gradle

 应用插件:Java的
应用插件:战争
应用插件:Eclipse的WTP
应用插件:日蚀//使用JDK 8
sourceCompatibility = 1.8
targetCompatibility = 1.8// 1. Maven的本地仓库获取依赖
// 2. Maven的中央存储库中获得的依赖
库{
    mavenLocal()
    mavenCentral()
    行家{
        网址http://repo1.maven.org/maven2
    }
}配置{
    提供
}
  sourceSets {
    主要{compileClasspath + = configurations.provided}
}//项目依赖
依赖{    // Spring框架的核心
    编译org.springframework:弹簧网址:4.1.4.RELEASE
    编译org.springframework:弹簧芯:4.1.4.RELEASE
    编译org.springframework:春天上下文:4.1.4.RELEASE
    编译org.springframework:弹簧上下文支持:4.1.4.RELEASE
    编译org.springframework:弹簧ORM:4.1.4.RELEASE    编译org.springframework.security:spring-security-core:4.0.0.RELEASE    // MySQL数据库驱动程序
    //编译MySQL的:使用mysql-connector-java的:5.1.34
    编译com.oracle:ojdbc6:11.2.0.1.0
    // Hibernate框架
    编译org.hibernate作为:休眠核心:4.3.8.Final
    编译公地DBCP:公地DBCP:1.2.2    // Servlet API的
    编译'的javax.servlet:servlet的API:2.5    // BASE-64阿帕奇公地
    编译commons- codeC:commons- codeC:1.10    // log4j的
    编译'的log4j:log4j的:1.2.17
    编译org.slf4j:SLF4J-简单:1.7.10    // XmlBeans的股票估值
    编译org.apache.xmlbeans:XMLBeans的:2.6.0    //浦二股权估值
    编译org.apache.poi:POI:3.10.1    //浦二OOXML股票估值
    编译org.apache.poi:POI-OOXML:3.10.1    //浦二OOXML架构股权估值
    编译org.apache.poi:POI-OOXML-模式:3.10.1    //雅各布股票​​估值
    编译雅各布:侨光:1.18-M2    //谷歌GSON
    编译com.google code.gson:GSON:2.3.1    提供'org.jboss.resteasy:RestEasy的-JAXRS:3.0.11.Final    提供'org.jboss.resteasy:RestEasy的弹簧:3.0.11.Final}


解决方案

试过在发表评论,但字数限制补充。结果
我能现在要做的异步工作。我发现,使用的 AsynchResponse 的和和的暂停的注释是造成此异常。这不是必需的异步作业处理。结果,其原因的空指针是,有两个混合起来。

有两个异步的东西和文档真正混合起来结果
1. 异步响应:使用暂停和AsynchResponse将释放接收请求和工作将由新创建的线程来完成服务器线程。但是,客户端将等待响应。直到新线程完成并发送回。对于这种不需要更改到web.xml。

页2。 异步工作处理:在这里,你设置的 resteasy.async.job.service.enabled 的到的真正的在web.xml和任何其他可选参数(如果需要)。没有其他的变化都需要的API。我的方法是结果
     @POST
    @Path(/ HelloWorld的)
    市民反应为getHelloWorld(){
        log.info(API调用);
        longLiftingJob();
        log.info(API调用完成);
        返回Response.status(200).entity(的Hello World),建立()。
    }

通过在web.xml中的真实参数框架将调用你在一个新的线程中调用(简单地说)和作业ID在202响应返回相同。作为Location头的结果
位置→http://127.0.0.1:8080/myrest/asynch/jobs/1432015827488-1

客户端不会对上述URL的GET / POST,并会获得响应由曾经的API完成的API返回。但实际的客户端永远不会等待这么异步工作。

I was working in Resteasy where I've to make a asynchronous request to server. The real purpose is, I'll be submitting a form which will be converted into a .xlsx file which will take atleast 10 seconds to complete. So Asynchronous request is the best way here. I followed the procedures from the following link.

https://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html_single/#Asynchronous_HTTP_Request_Processing

I'm making the ajax request like this.

$.ajax({
    url : 'rest/parentPath/childPath',
    type : 'GET',
    success : function(data, status, xhr) {
        console.log(xhr.getResponseHeader('Location'));
    },
    failure : function(data) {
        console.log(data);
    },
    error : function(error,status) {

    }
});

ParentClass.java

import javax.ws.rs.container.AsyncResponse;
import javax.ws.rs.container.Suspended;

@Component
@Path("/parentPath")
public class ParentClass {
    @GET
    @Path("childPath")
    @Produces("text/plain")
    public void asyncFunction(@Suspended final AsyncResponse response){
        Thread t = new Thread() {
            @Override
            public void run()
            {
                try
                {
                    Response jaxrs = Response.ok("basic").type(MediaType.TEXT_PLAIN).build();         
                    System.out.println("entered======================= =================================================");
                    response.resume(jaxrs);
                }
                catch (Exception e){
                    e.printStackTrace();
                }
            }
        };
        t.start();
    }
}

If I simply make a ajax request, it gives me 503 Service unavailable error but I do get my Asynchronous task executed, I can confirm by seeing my sysout present in wildfly log. But this is not a way how a asynchronous should be done. I've to be able to see the response of my asynchronous task in the second request. I followed the procedures in this link.

https://docs.jboss.org/resteasy/docs/3.0.9.Final/userguide/html_single/#async_job

If I put ?asynch=true in the request url, immediately i get a response of 202 Accepted with a location of asynchronous job in response. But it didn't even entered into the try statement. An error is thrown in the wildfly terminal like this.

19:11:41,733 WARN  [org.jboss.resteasy.core.ExceptionHandler] (pool-4-thread-1) Failed executing GET /parentPath/childPath: org.jboss.resteasy.spi.BadRequestExcept
ion: Failed processing arguments of org.jboss.resteasy.spi.metadata.ResourceMethod@44d4407c
        at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:104) [resteasy-jaxrs-3.0.10.Final.jar:]
        at org.jboss.resteasy.core.MethodInjectorImpl.invoke(MethodInjectorImpl.java:112) [resteasy-jaxrs-3.0.10.Final.jar:]
        at org.jboss.resteasy.core.ResourceMethodInvoker.invokeOnTarget(ResourceMethodInvoker.java:296) [resteasy-jaxrs-3.0.10.Final.jar:]
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:250) [resteasy-jaxrs-3.0.10.Final.jar:]
        at org.jboss.resteasy.core.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:237) [resteasy-jaxrs-3.0.10.Final.jar:]
        at org.jboss.resteasy.core.SynchronousDispatcher.invoke(SynchronousDispatcher.java:356) [resteasy-jaxrs-3.0.10.Final.jar:]
        at org.jboss.resteasy.core.AsynchronousDispatcher.invokeSuper(AsynchronousDispatcher.java:237) [resteasy-jaxrs-3.0.10.Final.jar:]
        at org.jboss.resteasy.core.AsynchronousDispatcher$1.call(AsynchronousDispatcher.java:278) [resteasy-jaxrs-3.0.10.Final.jar:]
        at org.jboss.resteasy.core.AsynchronousDispatcher$1.call(AsynchronousDispatcher.java:269) [resteasy-jaxrs-3.0.10.Final.jar:]
        at java.util.concurrent.FutureTask.run(FutureTask.java:266) [rt.jar:1.8.0_25]
        at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [rt.jar:1.8.0_25]
        at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [rt.jar:1.8.0_25]
        at java.lang.Thread.run(Thread.java:745) [rt.jar:1.8.0_25]
Caused by: java.lang.NullPointerException
        at org.jboss.resteasy.core.ResourceMethodInvoker.initializeAsync(ResourceMethodInvoker.java:374) [resteasy-jaxrs-3.0.10.Final.jar:]
        at org.jboss.resteasy.core.AsynchronousResponseInjector.inject(AsynchronousResponseInjector.java:43) [resteasy-jaxrs-3.0.10.Final.jar:]
        at org.jboss.resteasy.core.MethodInjectorImpl.injectArguments(MethodInjectorImpl.java:89) [resteasy-jaxrs-3.0.10.Final.jar:]
        ... 12 more

If I made the same request again with asynch=true, it shows the same error but with (pool-4-thread-2) instead of (pool-4-thread-1)

This means exception is not occured at the server side but at the runtime layer. Coz any exception occured inside my code will be present in log file but not in wildfly terminal. I'll post the web.xml, WebConfig.java, build.gradle files. I'm just replicating the same thing which is done in jboss docs, but I cant figure out why is this exception occuring at the wildfly layer.

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">

    <display-name>Web Application</display-name>

    <distributable />

    <listener>
        <listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
    </listener>

    <listener>
        <listener-class>org.jboss.resteasy.plugins.spring.SpringContextLoaderListener</listener-class>
    </listener>

    <!-- Context Configuration locations for Spring XML files -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            classpath:/applicationContext-resources.xml
            classpath:/applicationContext-dao.xml
            classpath:/applicationContext-service.xml
            classpath*:/applicationContext.xml
            /WEB-INF/applicationContext*.xml
        </param-value>
    </context-param>

    <context-param>
        <param-name>resteasy.servlet.mapping.prefix</param-name>
        <param-value>/rest</param-value>
    </context-param>

    <context-param>
        <param-name>resteasy.async.job.service.enabled</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <param-name>resteasy.async.job.service.max.job.results</param-name>
        <param-value>100</param-value>
    </context-param>

    <!-- Maximum wait time on a job when a client is querying for it -->
    <context-param>
        <param-name>resteasy.async.job.service.max.wait</param-name>
        <param-value>300000</param-value>
    </context-param>

    <!-- Thread pool size of background threads that run the job -->
    <context-param>
        <param-name>resteasy.async.job.service.thread.pool.size</param-name>
        <param-value>100</param-value>
    </context-param>

    <!-- Set the base path for the Job uris -->
    <context-param>
        <param-name>resteasy.async.job.service.base.path</param-name>
        <param-value>/asynch/jobs</param-value>
    </context-param>

    <servlet>
        <servlet-name>resteasy-servlet</servlet-name>
        <servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>com.mypackage.service.WebConfig</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet-mapping>
        <servlet-name>resteasy-servlet</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>

    <welcome-file-list>
        <welcome-file>login.html</welcome-file>
    </welcome-file-list>

</web-app>

WebConfig.java

import java.util.HashSet;
import java.util.Set;

import javax.ws.rs.core.Application;

public class WebConfig extends Application {

    private Set<Object> singletons = new HashSet<Object>();
    private Set<Class<?>> empty = new HashSet<Class<?>>();

    public WebConfig() {
        // ADD YOUR RESTFUL RESOURCES HERE
        this.singletons.add(new SignupService());
        this.singletons.add(new UserService());
        this.singletons.add(new ParentClass());
    }

    public Set<Class<?>> getClasses()
    {
        return this.empty;
    }

    public Set<Object> getSingletons()
    {
        return this.singletons;
    }

}

Build.gradle

apply plugin: 'java'
apply plugin: 'war'
apply plugin: 'eclipse-wtp'
apply plugin: 'eclipse'

// Uses JDK 8
sourceCompatibility = 1.8
targetCompatibility = 1.8

// 1. Get dependencies from Maven local repository
// 2. Get dependencies from Maven central repository
repositories {
    mavenLocal()
    mavenCentral()
    maven  {
        url "http://repo1.maven.org/maven2"
    }
}

configurations {
    provided
}
  sourceSets {
    main { compileClasspath += configurations.provided }
}

//Project dependencies
dependencies {

    //Spring framework core
    compile 'org.springframework:spring-web:4.1.4.RELEASE'
    compile 'org.springframework:spring-core:4.1.4.RELEASE'
    compile 'org.springframework:spring-context:4.1.4.RELEASE'
    compile 'org.springframework:spring-context-support:4.1.4.RELEASE'
    compile 'org.springframework:spring-orm:4.1.4.RELEASE'

    compile 'org.springframework.security:spring-security-core:4.0.0.RELEASE'

    //MySQL database driver
    //compile 'mysql:mysql-connector-java:5.1.34'
    compile 'com.oracle:ojdbc6:11.2.0.1.0'


    //Hibernate framework 
    compile 'org.hibernate:hibernate-core:4.3.8.Final'
    compile 'commons-dbcp:commons-dbcp:1.2.2'

    //Servlet API
    compile 'javax.servlet:servlet-api:2.5'

    //Base-64 Apache commons
    compile 'commons-codec:commons-codec:1.10'

    //log4j
    compile 'log4j:log4j:1.2.17'
    compile 'org.slf4j:slf4j-simple:1.7.10'

    //XmlBeans Equity Valuation
    compile 'org.apache.xmlbeans:xmlbeans:2.6.0'

    //Poi Equity Valuation
    compile 'org.apache.poi:poi:3.10.1'

    //Poi ooxml Equity Valuation
    compile 'org.apache.poi:poi-ooxml:3.10.1'

    //Poi ooxml Schemas Equity Valuation
    compile 'org.apache.poi:poi-ooxml-schemas:3.10.1'

    //Jacob Equity Valuation
    compile 'jacob:jacob:1.18-M2'

    //Google gson
    compile 'com.google.code.gson:gson:2.3.1'

    provided 'org.jboss.resteasy:resteasy-jaxrs:3.0.11.Final'

    provided 'org.jboss.resteasy:resteasy-spring:3.0.11.Final'

}

解决方案

Tried to add in the comment but word limit.
I am able to do the asynchronous job now. I found that using the AsynchResponse and the and the Suspended annotations are causing this Exception. this is not required for asynchronous job processing.
The reason for your null pointer is that there is a mix up for the two.

There are two asynchronous things and the documentation really mixes them up
1. Asynchronous response : Using Suspended and AsynchResponse will free the server thread that received the request and the work will be done by the new thread created. But the client will wait for the response. Until your new thread completes and sends it back. For this no changes are required to the web.xml.


2. Asynchronous Job processing : Here the you set the resteasy.async.job.service.enabled to true in the web.xml and any other optional parameters (if required). No other changes are required to the APi. My method was
@POST @Path("/helloworld") public Response getHelloWorld() { log.info("API invoked"); longLiftingJob(); log.info("API invoke done"); return Response.status(200).entity("Hello World").build(); }

With the true parameter in the web.xml the framework will invoke you call in a new thread (simply put) and return with the job id for the same in the 202 response. as Location header as
Location → http://127.0.0.1:8080/myrest/asynch/jobs/1432015827488-1

The client does a GET / POST on the above url and will get the response as returned by the API once the API finishes. But the actual client never waits so asynchronous job.

这篇关于在RestEasy的异步请求空指针异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆