GlassFish Java Web服务超时

时间:2019-02-18 08:43:45

标签: java c# web-services web-applications glassfish

我正在设置一个新的GlassFish Server 4.1.1,上面部署了一个Java Web服务。该Web服务具有一个Web方法,该方法接收JSON作为输入参数,因此它还返回JSON。要将Java对象与JSON序列化/反序列化,我使用Gson库。 Web方法正在调用其他Web服务,一次运行大约需要2-3分钟。我在一个循环中多次调用此Web服务例如6-10次,因此Web方法正在等待大约16-30分钟以返回值。问题是超时,但是我不知道在哪里以及如何为我的问题设置它。

我尝试从Visual Studio C#项目中调用此Java Web服务,在其中添加了Web引用,并在其中定义了Web服务的Web引用URL。我还设置了XML Web服务客户端等待对同步XML Web服务请求的答复应该等待多长时间的时间。我将其设置为10小时,如下所示。

static string CallEARSjDE(string json)
{
    EARSWebReference.EARSWebService EARSWS = new EARSWebReference.EARSWebService();
    EARSWS.Timeout = 36000000;    // 10 hours

    return EARSWS.EARSjDE(json);
}

我还为在Java Web方法中发出的Web服务请求设置了超时。我将其设置为1小时。

Gson gson = new Gson();
RequestConfig requestConfig = RequestConfig.custom().setConnectTimeout(1 * 3600000).build();   // timeout set to 1 hour
HttpClient httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build();
HttpPost post = new HttpPost(this.ServiceURL);
StringEntity postingString = new StringEntity(gson.toJson(problemLCSRequest));
post.setEntity(postingString);
post.setHeader("Content-type", "application/json");
HttpResponse response = httpClient.execute(post);
HttpEntity entity = response.getEntity();
String responseString = EntityUtils.toString(entity, "UTF-8");

ProblemLCSResponse responseJson = gson.fromJson(responseString, ProblemLCSResponse.class);

除了这两个超时,我还在GlassFish管理控制台中设置了超时。我是在“配置”→“服务器配置”→“ Web容器”部分中完成的,在该部分中,将会话超时设置为36.000秒(10小时)。

例如,当我在Web方法内调用Web服务6次时,将获得所需的响应。但是,当我多次调用Web服务超过6次时,将引发以下异常。我认为发生此异常的原因是超时,但我不知道是哪个原因导致的,我应该在哪里更改。

  

警告:StandardWrapperValve [EARSWebService]:Servlet EARSWebService的Servlet.service()抛出异常   java.nio.channels.ClosedByInterruptException       在java.nio.channels.spi.AbstractInterruptibleChannel.end(AbstractInterruptibleChannel.java:202)       在sun.nio.ch.SocketChannelImpl.write(SocketChannelImpl.java:478)       在org.glassfish.grizzly.nio.transport.TCPNIOUtils.flushByteBuffer(TCPNIOUtils.java:149)       在org.glassfish.grizzly.nio.transport.TCPNIOUtils.writeCompositeBuffer(TCPNIOUtils.java:87)       在org.glassfish.grizzly.nio.transport.TCPNIOAsyncQueueWriter.write0(TCPNIOAsyncQueueWriter.java:129)       在org.glassfish.grizzly.nio.transport.TCPNIOAsyncQueueWriter.write0(TCPNIOAsyncQueueWriter.java:106)       在org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter.write(AbstractNIOAsyncQueueWriter.java:260)       在org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter.write(AbstractNIOAsyncQueueWriter.java:169)       在org.glassfish.grizzly.nio.AbstractNIOAsyncQueueWriter.write(AbstractNIOAsyncQueueWriter.java:71)       在org.glassfish.grizzly.nio.transport.TCPNIOTransportFilter.handleWrite(TCPNIOTransportFilter.java:126)       在org.glassfish.grizzly.filterchain.TransportFilter.handleWrite(TransportFilter.java:191)       在org.glassfish.grizzly.filterchain.ExecutorResolver $ 8.execute(ExecutorResolver.java:111)       在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)       在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)       在org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)       在org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)       在org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)       在org.glassfish.grizzly.filterchain.FilterChainContext.write(FilterChainContext.java:890)       在org.glassfish.grizzly.filterchain.FilterChainContext.write(FilterChainContext.java:858)       在org.glassfish.grizzly.http.io.OutputBuffer.flushBuffer(OutputBuffer.java:1029)       在org.glassfish.grizzly.http.io.OutputBuffer.flushBinaryBuffers(OutputBuffer.java:1016)       在org.glassfish.grizzly.http.io.OutputBuffer.flushAllBuffers(OutputBuffer.java:987)       在org.glassfish.grizzly.http.io.OutputBuffer.flush(OutputBuffer.java:738)       在org.apache.catalina.connector.OutputBuffer.doFlush(OutputBuffer.java:291)       在org.apache.catalina.connector.OutputBuffer.flush(OutputBuffer.java:275)       在org.apache.catalina.connector.CoyoteOutputStream.flush(CoyoteOutputStream.java:175)       在java.io.FilterOutputStream.flush(FilterOutputStream.java:140)       在com.ctc.wstx.io.UTF8Writer.flush(UTF8Writer.java:103)       在com.ctc.wstx.sw.BufferingXmlWriter.flush(BufferingXmlWriter.java:225)       在com.ctc.wstx.sw.BaseStreamWriter.flush(BaseStreamWriter.java:259)       在com.sun.xml.ws.util.xml.XMLStreamWriterFilter.flush(XMLStreamWriterFilter.java:71)       在com.sun.xml.ws.streaming.XMLStreamWriterUtil.getOutputStream(XMLStreamWriterUtil.java:103)       在com.sun.xml.ws.message.jaxb.JAXBMe​​ssage.writePayloadTo(JAXBMe​​ssage.java:403)       在com.sun.xml.ws.message.AbstractMessageImpl.writeTo(AbstractMessageImpl.java:192)       在com.sun.xml.ws.api.message.MessageWrapper.writeTo(MessageWrapper.java:226)       在com.sun.xml.ws.encoding.StreamSOAPCodec.encode(StreamSOAPCodec.java:144)       在com.sun.xml.ws.encoding.SOAPBindingCodec.encode(SOAPBindingCodec.java:242)       在com.sun.xml.ws.transport.http.HttpAdapter.encodePacket(HttpAdapter.java:636)       在com.sun.xml.ws.transport.http.HttpAdapter.access $ 100(HttpAdapter.java:108)       在com.sun.xml.ws.transport.http.HttpAdapter $ HttpToolkit.handle(HttpAdapter.java:878)       在com.sun.xml.ws.transport.http.HttpAdapter.handle(HttpAdapter.java:422)       在com.sun.xml.ws.transport.http.servlet.ServletAdapter.handle(ServletAdapter.java:169)       在org.glassfish.webservices.JAXWSServlet.doPost(JAXWSServlet.java:169)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:707)       在javax.servlet.http.HttpServlet.service(HttpServlet.java:790)       在org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682)       在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:318)       在org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160)       在org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734)       在org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673)       在com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99)       在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174)       在org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:416)       在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:283)       在com.sun.enterprise.v3.services.impl.ContainerMapper $ HttpHandlerCallable.call(ContainerMapper.java:459)       在com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167)       在org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:206)       在org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:180)       在org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235)       在org.glassfish.grizzly.filterchain.ExecutorResolver $ 9.execute(ExecutorResolver.java:119)       在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:283)       在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:200)       在org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:132)       在org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:111)       在org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)       在org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:536)       在org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)       在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117)       at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access $ 100(WorkerThreadIOStrategy.java:56)       在org.glassfish.grizzly.strategies.WorkerThreadIOStrategy $ WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137)中       在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.doWork(AbstractThreadPool.java:591)       在org.glassfish.grizzly.threadpool.AbstractThreadPool $ Worker.run(AbstractThreadPool.java:571)       在java.lang.Thread.run(Thread.java:748)

1 个答案:

答案 0 :(得分:0)

最后,我找到了正确的超时设置。我必须转到管理面板,并在Configurations → server-config → Network Config内部,必须设置http-listener-1的 HTTP请求超时