You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by "Tim Cham (JIRA)" <ax...@ws.apache.org> on 2008/01/22 23:06:37 UTC

[jira] Created: (AXIS-2720) Stub.setTimeout() sets the timeout for ALL Stubs rather than for the instance

Stub.setTimeout() sets the timeout for ALL Stubs rather than for the instance
-----------------------------------------------------------------------------

                 Key: AXIS-2720
                 URL: https://issues.apache.org/jira/browse/AXIS-2720
             Project: Axis
          Issue Type: Bug
          Components: Basic Architecture
    Affects Versions: 1.4
         Environment: Windows XP,
java version "1.5.0_08"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.5.0_08-b03)
Java HotSpot(TM) Client VM (build 1.5.0_08-b03, mixed mode)
            Reporter: Tim Cham


************************
* Use Case Problem:
************************

java.net.URL portAddress1 = new URL(endpoint);
IntegrationAPI2Service serviceLocator1 = new IntegrationAPI2ServiceLocator();
IntegrationAPI2 api1 = serviceLocator1.getIntegrationAPI2(portAddress1);
Stub stub1 = (Stub) api1;
stub1.setTimeout(1000); 

// The very first call will have a connection timeout and a read timeout of 1 second
api1.distanceSearchOfCategoriesAtCityState( ... ) ; 


java.net.URL portAddress2 = new URL(endpoint);
IntegrationAPI2Service serviceLocator2 = new IntegrationAPI2ServiceLocator();
IntegrationAPI2 api2 = serviceLocator2.getIntegrationAPI2(portAddress);
Stub stub2 = (Stub) api2;
stub2.setTimeout(6000); 

// All other calls will STILL have a timeout of 1 second even though
// we explicitly set the timeout for this particular call to 6 seconds.
// Thus the following line will throw a SocketException if the connection
// takes more than 1 second.
api2.distanceSearchOfCategoriesAtCityState( ... ) ; 

************************
* Code Problem
************************
org.apache.axis.components.net.SocketFactoryFactory

 public static synchronized SocketFactory getFactory(String protocol,
                                                        Hashtable attributes) {
        SocketFactory theFactory = (SocketFactory)factories.get(protocol);

        .....
 }

Notice that the hashtable of factories is only keyed in with the protocol, where it should really be keyed in with both the protocol AND attributes (such as timeout).

************************
* Possible Solution
************************
/*
 * Copyright 2002-2004 The Apache Software Foundation.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.axis.components.net;

import org.apache.axis.AxisProperties;
import org.apache.axis.components.logger.LogFactory;
import org.apache.commons.logging.Log;

import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;

/**
 * Class SocketFactoryFactory
 *
 * @author
 * @version %I%, %G%
 */
public class SocketFactoryFactory {

    /** Field log           */
    protected static Log log =
            LogFactory.getLog(SocketFactoryFactory.class.getName());

    /** socket factory */
    private static Hashtable factories = new Hashtable();

    private static final Class classes[] = new Class[] { Hashtable.class };


    static {
        AxisProperties.setClassOverrideProperty(SocketFactory.class,
                                       "axis.socketFactory");

        AxisProperties.setClassDefault(SocketFactory.class,
                                       "org.apache.axis.components.net.DefaultSocketFactory");

        AxisProperties.setClassOverrideProperty(SecureSocketFactory.class,
                                       "axis.socketSecureFactory");

        AxisProperties.setClassDefault(SecureSocketFactory.class,
                                       "org.apache.axis.components.net.JSSESocketFactory");
    }

    /**
     * Returns a copy of the environment's default socket factory.
     *
     * @param protocol Today this only supports "http" & "https".
     * @param attributes
     *
     * @return
     */
    public static synchronized SocketFactory getFactory(String protocol,
                                                        Hashtable attributes) {
        FactoryKey key = new FactoryKey(protocol, attributes);
        SocketFactory theFactory = (SocketFactory)factories.get(key);

        if (theFactory == null) {
            Object objects[] = new Object[] { attributes };

            if (protocol.equalsIgnoreCase("http")) {
                theFactory = (SocketFactory)
                    AxisProperties.newInstance(SocketFactory.class, classes, objects);
            } else if (protocol.equalsIgnoreCase("https")) {
                theFactory = (SecureSocketFactory)
                    AxisProperties.newInstance(SecureSocketFactory.class, classes, objects);
            }

            if (theFactory != null) {
                factories.put(key, theFactory);
            }
        }
        return theFactory;
    }

    private static class FactoryKey
    {
        private String protocol;
        private Hashtable attributes;

        public FactoryKey(String protocol, Hashtable attributes)
        {
            this.protocol = protocol;
            this.attributes = attributes;
        }

        public int hashCode()
        {
            final int prime = 31;
            int result = 1;
            result = prime * result + ((attributes == null) ? 0 : attributes.hashCode());
            result = prime * result + ((protocol == null) ? 0 : protocol.hashCode());
            return result;
        }

        public boolean equals(Object obj)
        {
            if (this == obj)
                return true;
            if (obj == null)
                return false;
            if (getClass() != obj.getClass())
                return false;
            final FactoryKey other = (FactoryKey)obj;
            if (attributes == null)
            {
                if (other.attributes != null)
                    return false;
            }
            else if (!attributes.equals(other.attributes))
                return false;
            if (protocol == null)
            {
                if (other.protocol != null)
                    return false;
            }
            else if (!protocol.equals(other.protocol))
                return false;
            return true;
        }

        public String toString()
        {
            StringBuffer sb = new StringBuffer();
            sb.append("[protocol=").append(protocol).append(": ");

            for (Iterator iterator = attributes.entrySet().iterator(); iterator.hasNext();)
            {
                Map.Entry entry = (Map.Entry)iterator.next();
                sb.append(entry.getKey()).append("=").append(entry.getValue());
                if (iterator.hasNext())
                    sb.append(",");
            }
            sb.append("]");
            return sb.toString();
        }
    }
}

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-dev-help@ws.apache.org