Author: barrettj Date: Fri May 14 21:36:50 2010 New Revision: 944485 URL: http://svn.apache.org/viewvc?rev=944485&view=rev Log: Commit patch for AXIS2-4715 contributed by Katherine Sanders. Fix Addressing.required enforcement on client side.
Modified: axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingValidationHandler.java axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingValidationHandlerTest.java axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java Modified: axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingValidationHandler.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingValidationHandler.java?rev=944485&r1=944484&r2=944485&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingValidationHandler.java (original) +++ axis/axis2/java/core/trunk/modules/addressing/src/org/apache/axis2/handlers/addressing/AddressingValidationHandler.java Fri May 14 21:36:50 2010 @@ -73,19 +73,19 @@ public class AddressingValidationHandler private void checkUsingAddressing(MessageContext msgContext) throws AxisFault { String addressingFlag; - AxisDescription ad = msgContext.getAxisService(); - if (ad == null) { - // On client side, get required value from the message context + if (!msgContext.isServerSide()) { + // On client side, get required value from the request message context // (set by AddressingConfigurator). // We do not use the UsingAddressing required attribute on the // client side since it is not generated/processed by java tooling. - addressingFlag = AddressingHelper.getAddressingRequirementParemeterValue(msgContext); + addressingFlag = AddressingHelper.getRequestAddressingRequirementParameterValue(msgContext); if (log.isTraceEnabled()) { log.trace("checkUsingAddressing: WSAddressingFlag from MessageContext=" + addressingFlag); } } else { // On provider side, get required value from AxisOperation // (set by AddressingConfigurator and UsingAddressing WSDL processing). + AxisDescription ad = msgContext.getAxisService(); if(msgContext.getAxisOperation()!=null){ ad = msgContext.getAxisOperation(); } Modified: axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingValidationHandlerTest.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingValidationHandlerTest.java?rev=944485&r1=944484&r2=944485&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingValidationHandlerTest.java (original) +++ axis/axis2/java/core/trunk/modules/addressing/test/org/apache/axis2/handlers/addressing/AddressingValidationHandlerTest.java Fri May 14 21:36:50 2010 @@ -23,12 +23,18 @@ import junit.framework.TestCase; import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder; import org.apache.axis2.AxisFault; import org.apache.axis2.addressing.AddressingConstants; +import org.apache.axis2.context.ConfigurationContext; import org.apache.axis2.context.ConfigurationContextFactory; import org.apache.axis2.context.MessageContext; +import org.apache.axis2.context.OperationContext; +import org.apache.axis2.context.ServiceContext; +import org.apache.axis2.context.ServiceGroupContext; import org.apache.axis2.description.AxisOperation; import org.apache.axis2.description.AxisService; import org.apache.axis2.description.InOnlyAxisOperation; import org.apache.axis2.description.InOutAxisOperation; +import org.apache.axis2.description.OutInAxisOperation; +import org.apache.axis2.engine.AxisConfiguration; import org.apache.axis2.handlers.util.TestUtil; import javax.xml.namespace.QName; @@ -129,19 +135,40 @@ public class AddressingValidationHandler } public void testCheckUsingAdressingOnClient() throws Exception { - // Make addressing required using the same property as the AddressingConfigurator - MessageContext mc = new MessageContext(); - mc.setProperty(AddressingConstants.ADDRESSING_REQUIREMENT_PARAMETER, AddressingConstants.ADDRESSING_REQUIRED); + // Need to create full description hierarchy to prevent NullPointerExceptions + AxisOperation axisOperation = new OutInAxisOperation(new QName("Temp")); + AxisService axisService = new AxisService("Temp"); + AxisConfiguration axisConfiguration = new AxisConfiguration(); + axisService.addOperation(axisOperation); + axisConfiguration.addService(axisService); + ConfigurationContext configurationContext = new ConfigurationContext(axisConfiguration); + + // Make addressing required using the same property as the AddressingConfigurator on the request + MessageContext request = configurationContext.createMessageContext(); + request.setProperty(AddressingConstants.ADDRESSING_REQUIREMENT_PARAMETER, AddressingConstants.ADDRESSING_REQUIRED); - // Invoke the in handler for a message without addressing headers - mc.setConfigurationContext(ConfigurationContextFactory.createEmptyConfigurationContext()); + // Create a response to invoke the in handler on + MessageContext response = configurationContext.createMessageContext(); + + // Link the response to the request message context using the context hierarchy + ServiceGroupContext serviceGroupContext = configurationContext.createServiceGroupContext(axisService.getAxisServiceGroup()); + ServiceContext serviceContext = serviceGroupContext.getServiceContext(axisService); + OperationContext opContext = axisOperation.findOperationContext(request, serviceContext); + axisOperation.registerOperationContext(request, opContext); + request.setServiceContext(serviceContext); + response.setServiceContext(serviceContext); + request.setOperationContext(opContext); + response.setOperationContext(opContext); + + // Invoke the in handler for a response message without addressing headers StAXSOAPModelBuilder omBuilder = testUtil.getOMBuilder("addressingDisabledTest.xml"); - mc.setEnvelope(omBuilder.getSOAPEnvelope()); - inHandler.invoke(mc); + response.setEnvelope(omBuilder.getSOAPEnvelope()); + inHandler.invoke(response); - // Check the correct exception is thrown by the validation handler + // Check an exception is thrown by the validation handler because the client + // requires addressing but the response message does not have addressing headers try { - validationHandler.invoke(mc); + validationHandler.invoke(response); fail("An AxisFault should have been thrown due to the absence of addressing headers."); } catch (AxisFault axisFault) { // Confirm this is the correct fault Modified: axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java URL: http://svn.apache.org/viewvc/axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java?rev=944485&r1=944484&r2=944485&view=diff ============================================================================== --- axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java (original) +++ axis/axis2/java/core/trunk/modules/kernel/src/org/apache/axis2/addressing/AddressingHelper.java Fri May 14 21:36:50 2010 @@ -30,6 +30,7 @@ import org.apache.axis2.util.Utils; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; +import java.util.HashMap; import java.util.Map; public class AddressingHelper { @@ -158,7 +159,7 @@ public class AddressingHelper { value = value.trim(); } if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) { - log.debug("getAddressingRequirementParemeterValue(AxisDescription): value: '" + value + "'"); + log.debug("getAddressingRequirementParemeterValue: value: '" + value + "'"); } } @@ -168,12 +169,23 @@ public class AddressingHelper { return value; } - public static String getAddressingRequirementParemeterValue(MessageContext mc){ + public static String getRequestAddressingRequirementParameterValue(MessageContext response){ String value = ""; - if (mc != null) { - value = mc.getProperty(AddressingConstants.ADDRESSING_REQUIREMENT_PARAMETER).toString(); + if (response != null) { + HashMap<String,MessageContext> operationMessageContexts = response.getOperationContext().getMessageContexts(); + for(MessageContext messageContext : operationMessageContexts.values()) { + // Assumes at most 2 messages on operation, if there is more than 2 it + // will use the value from the first message it gets that is != response + if(!messageContext.equals(response)) { + value = (String) messageContext.getProperty(AddressingConstants.ADDRESSING_REQUIREMENT_PARAMETER); + if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) { + log.debug("getRequestAddressingRequirementParameterValue: got value from MessageContext "+messageContext+", value: '" + value + "'"); + } + break; + } + } if (LoggingControl.debugLoggingAllowed && log.isDebugEnabled()) { - log.debug("getAddressingRequirementParemeterValue(MessageContext): value: '" + value + "'"); + log.debug("getRequestAddressingRequirementParameterValue: value: '" + value + "'"); } }