Axis2频繁连接重置

时间:2012-10-16 11:00:49

标签: java axis apache-httpclient-4.x connection-reset

情况是这样的:

我使用Axis2 1.6.2并为2个Web服务生成了Stubs(带有 wsdl2java ) - 让我们称之为 WS#1 WS#2

我通过实现扩展BasePoolableObjectFactory(org.apache.commons.pool.BasePoolableObjectFactory)的StubPoolableFactory为Stubs使用池化机制

为了达到这个目的,Stubs被作为Singletons的Adapters“包裹”。适配器的骨架如下所示:

/** The Adapter class */
public class PdfServiceAdapter extends PoolableStubAdapter<PdfServiceStub> {

    /** The Singleton. */
private static PdfServiceAdapter pdfServiceAdapter;

/**
 * Gets the PdfService adapter instance.
 * 
 * @return the PdfService adapter
 */
public synchronized static PdfServiceAdapter getPdfServiceAdapter() {
    if (null == pdfServiceAdapter) {
        pdfServiceAdapter = new PdfServiceAdapter();
        pdfServiceAdapter.initiateStubPool();
    }
    return pdfServiceAdapter;
}

public void doSomething() throws AdapterException {

    try {
        stub = getStub();
    } catch (final Exception e) {
        throw new AdapterPreparationException(e);
    }
    try {

        //call some actual Stub method here...

    } catch (final Exception e) {
        stopWatch.stop("PdfService.doSomething.FAILURE");
        throw new AdapterExecutionException(e);
    } finally {
        final ServiceClient client = stub._getServiceClient();
        if (client != null) {
            try {
                client.cleanupTransport();
                client.cleanup();
            } catch (final AxisFault e) {
                log.warn("Something went wrong while cleaning up service client: ", e);
            }
        }
        releaseStub(stub);
    }
}

@Override
protected int getMaxActive() {
    return Integer.parseInt(ESignatureConfig.getInstance().getConfig().getString(
        "AXIS_STUB_POOL_EREQUEST_COMMUNICATION_MAX_ACTIVE"));
}

@Override
protected boolean getLifo() {
    return Boolean.parseBoolean(ESignatureConfig.getInstance().getConfig().getString(
        "AXIS_STUB_POOL_EREQUEST_COMMUNICATION_LIFO_FLAG"));
}

@Override
protected int getMaxIdle() {
    return Integer.parseInt(ESignatureConfig.getInstance().getConfig().getString(
        "AXIS_STUB_POOL_EREQUEST_COMMUNICATION_MAX_IDLE"));
}


@Override
protected long getMaxWait() {
    return Integer.parseInt(ESignatureConfig.getInstance().getConfig().getString(
        "AXIS_STUB_POOL_EREQUEST_COMMUNICATION_MAX_WAIT"));
}

@Override
protected String getEndPointURL() {
    return ESignatureConfig.getInstance().getConfig().getString("PDF_SERVICE_ENDPONT");
}
@Override
protected Stub getInstance() throws Exception {
    return new PdfServiceStub(AxisConfigurationContextFactory.getInstance().getConfigurationContext());
}

}

正如您在请求存根实例时所看到的那样,轴配置将传递给存根。 此Axis配置从工厂返回,它是Singleton,基于具有缓存HTTP客户端的MultiThreadedHttpConnectionManager

现在,问题出在哪里:

  • 有时候,通常在长时间调用Web服务之后, 如果我们在 WS#2 之后调用 WS#1 ,则会有连接重置 调用WS#2时出错。如果在此连接重置后我们再次呼叫 WS#1和WS#2之后再一次,没问题。
  • 此外,在对应用程序进行压力测试时,我们没有任何问题。只要 当我们让它闲置时,只有当呼叫“返回2回” WS#1 WS#2 始终在WS#2呼叫上发生连接重置

你认为这与我的实施有关吗? 也许Singleton Axis配置或某些环境下的缓存HTTP客户端负责此重置?

0 个答案:

没有答案