在后台线程中获取MultipartFormDataInput的主体

时间:2018-09-03 14:43:37

标签: java wildfly resteasy

我有一个可能要解析的大文件,作为MultipartFormDataInput的一部分传递给REST服务。由于解析可能需要很长时间,因此我想在后台线程中进行解析:

@Resource
private ManagedExecutorService executorService;

@POST
@Path("file")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public void upload(MultipartFormDataInput input) {
    executorService.execute(() -> {
        for (InputPart inputPart : input.getFormDataMap().get("file")) {
            try {
                InputStream inputStream = inputPart.getBody(InputStream.class, null);
                CSVReader csvReader = new CSVReader(new InputStreamReader(inputStream, "UTF-8"));
                // further processing
            } catch (Exception e) {
                logger.error("Something went wrong", e);
            }
        }
    });
}

不幸的是,getBody引发以下错误:

org.jboss.resteasy.spi.LoggableFailure:RESTEASY003880:无法找到以下类型的上下文数据:javax.ws.rs.ext.Providers

有机会我可以在其他线程中提取身体吗?

下面的完整堆栈跟踪:

16:33:30,634 ERROR [MyService] (EE-ManagedExecutorService-default-Thread-4) Something went wrong: org.jboss.resteasy.spi.LoggableFailure: RESTEASY003880: Unable to find contextual data of type: javax.ws.rs.ext.Providers
    at org.jboss.resteasy.core.ContextParameterInjector$GenericDelegatingProxy.invoke(ContextParameterInjector.java:75)
    at com.sun.proxy.$Proxy112.getMessageBodyReader(Unknown Source)
    at org.jboss.resteasy.plugins.providers.multipart.MultipartInputImpl$PartImpl.getBody(MultipartInputImpl.java:335)
    at MyService.lambda$upload$0(MyService.java:189)
    at org.jboss.as.ee.concurrent.ControlPointUtils$ControlledRunnable.run(ControlPointUtils.java:105)
    at org.wildfly.security.auth.server.SecurityIdentity.runAsConsumer(SecurityIdentity.java:335)
    at org.wildfly.security.auth.server.Scoped.runAsConsumer(Scoped.java:101)
    at org.wildfly.security.auth.server.Scoped.runAs(Scoped.java:49)
    at org.jboss.as.ee.concurrent.SecurityIdentityUtils.lambda$doIdentityWrap$1(SecurityIdentityUtils.java:63)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run$$$capture(FutureTask.java:266)
    at java.util.concurrent.FutureTask.run(FutureTask.java)
    at org.glassfish.enterprise.concurrent.internal.ManagedFutureTask.run(ManagedFutureTask.java:141)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:748)
    at org.glassfish.enterprise.concurrent.ManagedThreadFactoryImpl$ManagedThread.run(ManagedThreadFactoryImpl.java:250)
    at org.jboss.as.ee.concurrent.service.ElytronManagedThreadFactory$ElytronManagedThread.lambda$run$0(ElytronManagedThreadFactory.java:76)
    at org.wildfly.security.auth.server.SecurityIdentity.runAsConsumer(SecurityIdentity.java:335)
    at org.wildfly.security.auth.server.Scoped.runAsConsumer(Scoped.java:101)
    at org.wildfly.security.auth.server.Scoped.runAs(Scoped.java:49)
    at org.jboss.as.ee.concurrent.service.ElytronManagedThreadFactory$ElytronManagedThread.run(ElytronManagedThreadFactory.java:76)

0 个答案:

没有答案