写响应期间的MappableException

时间:2017-01-20 01:45:13

标签: web-services tomcat jersey jackson tomcat8

我正在使用Jersey编写Web服务,但在客户的响应请求中我遇到了异常。

我在下面遇到了例外:(我解释并在异常后附加我的代码)。

jan 19, 2017 7:55:31 PM org.glassfish.jersey.server.ServerRuntime$Responder writeResponse
GRAVE: An I/O error has occurred while writing a response message entity to the container output stream.
org.glassfish.jersey.server.internal.process.MappableException: org.apache.catalina.connector.ClientAbortException: java.io.IOException: Uma conexão estabelecida foi anulada pelo software no computador host
    at org.glassfish.jersey.server.internal.MappableExceptionWrapperInterceptor.aroundWriteTo(MappableExceptionWrapperInterceptor.java:92)
    at org.glassfish.jersey.message.internal.WriterInterceptorExecutor.proceed(WriterInterceptorExecutor.java:162)
    at org.glassfish.jersey.message.internal.MessageBodyFactory.writeTo(MessageBodyFactory.java:1130)
    at org.glassfish.jersey.server.ServerRuntime$Responder.writeResponse(ServerRuntime.java:711)
    at org.glassfish.jersey.server.ServerRuntime$Responder.processResponse(ServerRuntime.java:444)
    at org.glassfish.jersey.server.ServerRuntime$Responder.process(ServerRuntime.java:434)
    at org.glassfish.jersey.server.ServerRuntime$2.run(ServerRuntime.java:329)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:317)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:305)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1154)
    at org.glassfish.jersey.servlet.WebComponent.serviceImpl(WebComponent.java:473)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:427)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:388)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:341)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:228)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:230)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:53)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:192)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:165)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:108)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:620)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:349)
    at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:784)
    at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:802)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1455)
    at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)

我用实体响应参数上的列表撰写一个Response(javax.ws.rs.core.Response),这个列表有对象,数组很大,因为它,我尝试使用" StreamingOutput"来尝试缩小其大小,但没有成功,请关注我的代码:

回复综合

@GET
    @Path("/request/getSales")
    public Response getSales(@QueryParam(value = "loginKey") String loginKey, 
            @QueryParam(value = "saleID") String saleID, @QueryParam(value = "date") String date) {
        Response response = null;

        try {
            // if profile has logged on server, it's necessary to get his state.
            LoggedProfile loggedProfile = ServerGlobal.getInstance().getLoggedProfile(loginKey);
            if(loggedProfile != null) {
                List<Sale> sales = null;
                if("".equals(saleID) && "".equals(date)) {
                    log.debug("saleID && date is empty.");
                    // No sale are saved, it's necessary to check if server saved some sale for current Profile                 
                    sales = SaleDao.getInstance().getAllSalesByProfileID(loggedProfile.getProfileID());
                } else if(!"".equals(date)) {
                    log.debug("date is not empty.");
                    // Search sale for one period
                    sales = SaleDao.getInstance().getSalesByPeriod(
                            new Timestamp(Long.valueOf(date)), 
                            !("".equals(saleID)) ? Integer.parseInt(saleID) : null);
                }

                // Big data compress, low memory and high performance to process json.
                StreamingOutput stream = Parser.parserSalesToStreaming(sales);

                response = **Response.ok().status(ResponseStatus.RESPONSE_GET_SALES_OK).entity(stream).build();**

我的StreamingOutput

public static StreamingOutput parserSalesToStreaming(List<Sale> sales) {

        StreamingOutput stream = new StreamingOutput() {

            @Override
            public void write(OutputStream arg0) throws IOException, WebApplicationException {
                JsonFactory jsonFactory = new JsonFactory();
                JsonGenerator generator = jsonFactory.createGenerator(arg0, JsonEncoding.UTF8);
                ObjectMapper mapper = new ObjectMapper();
                generator.writeStartArray();

                for(Sale sale : sales) {
                    generator.writeObject(mapper.writeValueAsString(sale));
                }

                generator.writeEndArray();
                generator.close();
            }
        };

        return stream;
    }

我开始与泽西岛合作,所以我怀疑根本原因是&#34; 实体&#34;,因为它只是发生了一个大清单和这个案例。请问有人帮帮我吗?

我使用的是Tomcat, Jersey版本2.23.1

提前致谢

0 个答案:

没有答案