Author: veithen Date: Sun Oct 31 14:40:21 2010 New Revision: 1029372 URL: http://svn.apache.org/viewvc?rev=1029372&view=rev Log: Modified SOAPConnectionImpl so that it creates a single ConfigurationContext instance that will not be shared with others.
Reasons: * Starting with r921685, if no ConfigurationContext is supplied to the ServiceClient, it will create a new one (unless it can locate one using MessageContext.getCurrentMessageContext(), but this is not the most common use case for SOAPConnection). This means that SOAPConnection#call would create a new ConfigurationContext every time, and this is too expensive. * We need to disable mustUnderstand processing. However, we can't do that on an AxisConfiguration that is shared with other components, because this would lead to unpredictable results. Modified: axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java Modified: axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java?rev=1029372&r1=1029371&r2=1029372&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java (original) +++ axis/axis2/java/core/trunk/modules/saaj/src/org/apache/axis2/saaj/SOAPConnectionImpl.java Sun Oct 31 14:40:21 2010 @@ -32,6 +32,8 @@ import org.apache.axis2.addressing.Endpo import org.apache.axis2.client.OperationClient; import org.apache.axis2.client.Options; import org.apache.axis2.client.ServiceClient; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.ConfigurationContextFactory; import org.apache.axis2.context.MessageContext; import org.apache.axis2.engine.AxisConfiguration; import org.apache.axis2.engine.DispatchPhase; @@ -76,8 +78,31 @@ public class SOAPConnectionImpl extends /** Attribute which keeps track of whether this connection has been closed */ private boolean closed = false; + private final ConfigurationContext configurationContext; private ServiceClient serviceClient; + SOAPConnectionImpl() throws SOAPException { + // Create a new ConfigurationContext that will be used by all ServiceClient instances. + // There are two reasons why this is necessary: + // * Starting with r921685, if no ConfigurationContext is supplied to the ServiceClient, + // it will create a new one (unless it can locate one using MessageContext.getCurrentMessageContext(), + // but this is not the most common use case for SOAPConnection). This means that + // SOAPConnection#call would create a new ConfigurationContext every time, and this is + // too expensive. + // * We need to disable mustUnderstand processing. However, we can't do that on an AxisConfiguration + // that is shared with other components, because this would lead to unpredictable results. + // Note that we could also use a single ServiceClient instance, but then the SOAPConnection + // implementation would no longer be thread safe. Although thread safety is not explicitly required + // by the SAAJ specs, it appears that the SOAPConnection in Sun's reference implementation is + // thread safe. + try { + configurationContext = ConfigurationContextFactory.createConfigurationContextFromFileSystem(null, null); + disableMustUnderstandProcessing(configurationContext.getAxisConfiguration()); + } catch (AxisFault ex) { + throw new SOAPException(ex); + } + } + /** * Sends the given message to the specified endpoint and blocks until it has returned the * response. @@ -111,8 +136,7 @@ public class SOAPConnectionImpl extends // initialize the Sender OperationClient opClient; try { - serviceClient = new ServiceClient(); - disableMustUnderstandProcessing(serviceClient.getAxisConfiguration()); + serviceClient = new ServiceClient(configurationContext, null); opClient = serviceClient.createClient(ServiceClient.ANON_OUT_IN_OP); } catch (AxisFault e) { throw new SOAPException(e); @@ -220,11 +244,11 @@ public class SOAPConnectionImpl extends */ private void disableMustUnderstandProcessing(AxisConfiguration config) { DispatchPhase phase; - phase = getDispatchPhase(serviceClient.getAxisConfiguration().getInFlowPhases()); + phase = getDispatchPhase(config.getInFlowPhases()); if (phase != null) { phase.addHandler(new UnderstandAllHeadersHandler()); } - phase = getDispatchPhase(serviceClient.getAxisConfiguration().getInFaultFlowPhases()); + phase = getDispatchPhase(config.getInFaultFlowPhases()); if (phase != null) { phase.addHandler(new UnderstandAllHeadersHandler()); }