Java Axis2频繁连接重置

Java Axis2频繁连接重置,java,axis,apache-httpclient-4.x,connection-reset,Java,Axis,Apache Httpclient 4.x,Connection Reset,情况是这样的: 我使用Axis2 1.6.2,并为两个Web服务生成了存根(使用wsdl2java),我们将它们称为WS#1和WS#2 我通过实现StubPoolableFactory为存根使用池机制,该工厂扩展了BasePoolableObjectFactory(org.apache.commons.pool.BasePoolableObjectFactory) 为了实现这一点,存根由作为单体的适配器“包装”起来。适配器的框架如下所示: /** The Adapter class */ pub

情况是这样的:

我使用Axis2 1.6.2,并为两个Web服务生成了存根(使用wsdl2java),我们将它们称为WS#1WS#2

我通过实现StubPoolableFactory为存根使用池机制,该工厂扩展了BasePoolableObjectFactory(org.apache.commons.pool.BasePoolableObjectFactory)

为了实现这一点,存根由作为单体的适配器“包装”起来。适配器的框架如下所示:

/** 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());
}
/**适配器类*/
公共类PdfServiceAdapter扩展PoolableStubAdapter{
/**单身汉*/
专用静态PdfServiceAdapter PdfServiceAdapter;
/**
*获取PdfService适配器实例。
* 
*@返回PdfService适配器
*/
公共同步静态PdfServiceAdapter getPdfServiceAdapter(){
if(null==pdfServiceAdapter){
pdfServiceAdapter=新的pdfServiceAdapter();
pdfServiceAdapter.InitiateSubpool();
}
返回pdfServiceAdapter;
}
public void doSomething()引发AdapterException{
试一试{
stub=getStub();
}捕获(最终异常e){
抛出新适配器准备异常(e);
}
试一试{
//在这里调用一些实际的存根方法。。。
}捕获(最终异常e){
秒表停止(“PdfService.doSomething.FAILURE”);
抛出新的AdapterExecutionException(e);
}最后{
最终ServiceClient=stub.\u getServiceClient();
如果(客户端!=null){
试一试{
client.cleanupTransport();
client.cleanup();
}捕捉(最终轴故障e){
log.warn(“清理服务客户端时出错:,e”);
}
}
释放存根(存根);
}
}
@凌驾
受保护的int getMaxActive(){
返回Integer.parseInt(ESignatureConfig.getInstance().getConfig().getString(
“AXIS_STUB_POOL_EREQUEST_COMMUNICATION_MAX_ACTIVE”);
}
@凌驾
受保护的布尔getLifo(){
返回Boolean.parseBoolean(ESignatureConfig.getInstance().getConfig().getString(
“AXIS_STUB_POOL_EREQUEST_COMMUNICATION_LIFO_FLAG”);
}
@凌驾
受保护的int getMaxIdle(){
返回Integer.parseInt(ESignatureConfig.getInstance().getConfig().getString(
“AXIS_STUB_POOL_EREQUEST_COMMUNICATION_MAX_IDLE”);
}
@凌驾
受保护的长getMaxWait(){
返回Integer.parseInt(ESignatureConfig.getInstance().getConfig().getString(
“AXIS_STUB_POOL_EREQUEST_COMMUNICATION_MAX_WAIT”);
}
@凌驾
受保护的字符串getEndPointURL(){
返回ESignatureConfig.getInstance().getConfig().getString(“PDF_SERVICE_ENDPONT”);
}
@凌驾
受保护的存根getInstance()引发异常{
返回新的PdfServiceStub(AxisConfigurationContextFactory.getInstance().getConfigurationContext());
}
}

正如您在请求存根实例时所看到的,轴配置被传递给存根此Axis配置是从工厂返回的,它是一个单实例,基于多线程HttpConnectionManager和缓存的HTTP客户端

现在,问题出在哪里:

  • 有时,通常在长时间调用Web服务之后, 如果我们调用WS#1并在WS#2之后立即进行连接重置 调用WS#2时出错。如果此连接重置后,我们将再次呼叫 WS#1和WS#2,再过一次,没问题
  • 此外,我们在对应用程序进行压力测试时也没有问题。只有 当我们让它空闲时,只在调用“back 2 back”WS#1时 WS#2总是在WS#2调用时重置连接
你认为这与我的执行有关吗? 可能是Singleton Axis配置或某些情况下缓存的HTTP客户端导致了此重置