Return-Path: Delivered-To: apmail-ws-axis-dev-archive@www.apache.org Received: (qmail 16387 invoked from network); 21 Mar 2008 13:41:27 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 21 Mar 2008 13:41:27 -0000 Received: (qmail 11632 invoked by uid 500); 21 Mar 2008 13:41:24 -0000 Delivered-To: apmail-ws-axis-dev-archive@ws.apache.org Received: (qmail 11481 invoked by uid 500); 21 Mar 2008 13:41:23 -0000 Mailing-List: contact axis-cvs-help@ws.apache.org; run by ezmlm Precedence: bulk list-help: list-unsubscribe: List-Post: List-Id: Delivered-To: mailing list axis-cvs@ws.apache.org Received: (qmail 11470 invoked by uid 500); 21 Mar 2008 13:41:23 -0000 Delivered-To: apmail-ws-axis2-cvs@ws.apache.org Received: (qmail 11467 invoked by uid 99); 21 Mar 2008 13:41:23 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Mar 2008 06:41:23 -0700 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 21 Mar 2008 13:40:29 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 04E251A9832; Fri, 21 Mar 2008 06:40:46 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r639636 - in /webservices/axis2/trunk/java/modules: jaxws-integration/test/org/apache/axis2/jaxws/handler/header/ jaxws/src/org/apache/axis2/jaxws/handler/ jaxws/src/org/apache/axis2/jaxws/server/ jaxws/test/org/apache/axis2/jaxws/handler/ Date: Fri, 21 Mar 2008 13:40:39 -0000 To: axis2-cvs@ws.apache.org From: barrettj@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20080321134047.04E251A9832@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: barrettj Date: Fri Mar 21 06:40:17 2008 New Revision: 639636 URL: http://svn.apache.org/viewvc?rev=639636&view=rev Log: AXIS2-3567 Add server-side role-based JAXWS Application Handler mustUnderstand processing and associated tests Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandHandler.java webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandTests.xml webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandTests2.xml webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUndertandTests.java Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/handler/header/handler.xml webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerUtils.java webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java Modified: webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/handler/header/handler.xml URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/handler/header/handler.xml?rev=639636&r1=639635&r2=639636&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/handler/header/handler.xml (original) +++ webservices/axis2/trunk/java/modules/jaxws-integration/test/org/apache/axis2/jaxws/handler/header/handler.xml Fri Mar 21 06:40:17 2008 @@ -24,6 +24,7 @@ org.apache.axis2.jaxws.handler.header.DemoHandler + http://DemoHandler/Role Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java?rev=639636&r1=639635&r2=639636&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java (original) +++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerResolverImpl.java Fri Mar 21 06:40:17 2008 @@ -119,6 +119,11 @@ return handlers; } + public List getRoles(PortInfo portInfo) { + List handlerRoles = new ArrayList(); + resolveHandlers(portInfo, handlerRoles); + return handlerRoles; + } /* * The list of handlers (rather, list of class names) is already * available per port. Ports are stored under the ServiceDelegate @@ -129,6 +134,9 @@ * and returning it. We do not sort here. */ private ArrayList resolveHandlers(PortInfo portinfo) throws WebServiceException { + return resolveHandlers(portinfo, null); + } + private ArrayList resolveHandlers(PortInfo portinfo, List handlerRoles) throws WebServiceException { /* A sample XML file for the handler-chains: @@ -146,6 +154,7 @@ MyHandler org.apache.axis2.jaxws.MyHandler + http://org/apache/axis2/jaxws/MyRole @@ -281,6 +290,22 @@ // TODO: NLS better error message throw ExceptionFactory.makeWebServiceException(Messages .getMessage("handlerChainErr2", aClass.getName())); + } + // If a role was specified, add it to the roles played + if (handlerRoles != null) { + List soapRolesList = + handlerType.getSoapRole(); + Iterator + soapRolesIterator = soapRolesList.iterator(); + while (soapRolesIterator.hasNext()) { + org.apache.axis2.jaxws.description.xml.handler.String soapRoleElement = + soapRolesIterator.next(); + String addSoapRole = soapRoleElement.getValue(); + handlerRoles.add(addSoapRole); + if (log.isDebugEnabled()) { + log.debug("Adding soap role " + addSoapRole); + } + } } } } Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerUtils.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerUtils.java?rev=639636&r1=639635&r2=639636&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerUtils.java (original) +++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/handler/HandlerUtils.java Fri Mar 21 06:40:17 2008 @@ -19,10 +19,12 @@ package org.apache.axis2.jaxws.handler; +import org.apache.axiom.soap.RolePlayer; import org.apache.axiom.soap.SOAP11Constants; import org.apache.axiom.soap.SOAP12Constants; import org.apache.axiom.soap.SOAPConstants; import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axiom.soap.SOAPHeaderBlock; import org.apache.axis2.AxisFault; import org.apache.axis2.Constants; import org.apache.axis2.context.MessageContext; @@ -38,6 +40,7 @@ import javax.xml.ws.handler.Handler; import javax.xml.ws.handler.soap.SOAPHandler; import java.util.ArrayList; +import java.util.Iterator; import java.util.List; import java.util.Set; /* @@ -47,8 +50,8 @@ private static Log log = LogFactory.getLog(HandlerUtils.class); /** - * IregisterHandlerHeaders will invoke getHeaders on SOAPHandlers and register these headers - * with AxisService as Understood headers. + * registerHandlerHeaders will invoke getHeaders on SOAPHandlers and return a List of headers + * that are Understood by the handlers. * @param msgContext * @param handlers */ @@ -85,10 +88,21 @@ /** * checkMustUnderstand will validate headers that where delegated by Axis Engine * to MessageReceiver for mustUnderstand check. - * @param msgContext - * @throws AxisFault + * + * Note that there is other JAX-WS related mustUnderstand checking occuring elsewhere: + * @see org.apache.axis2.jaxws.dispatchers.MustUnderstandValidationDispatcher + * @see org.apache.axis2.jaxws.dispatchers.MustUnderstandChecker + * + * @param msgContext Contains the SOAPEnvelope and optionally a list of headers not + * understood by the AxisEngine + * @param understood A list of header QNames understood by JAX-WS, for example those understood + * by associated application handlers. Can be null. + * @param additionalRoles An instance of RolePlayer for any addtional roles played by JAX-WS + * for example, roles configured for associated handlers. Can be null. + * + * @throws AxisFault if any headers marked mustUndersand are not understood. */ - public static void checkMustUnderstand(MessageContext msgContext, List understood)throws AxisFault{ + public static void checkMustUnderstand(MessageContext msgContext, List understood, List additionalRoles) throws AxisFault { if (msgContext == null || !msgContext.isHeaderPresent()) { return; } @@ -102,12 +116,36 @@ } List unprocessed = (List)msgContext.getProperty(Constants.UNPROCESSED_HEADER_QNAMES); + + // Add to the unprocessed header list any headers that are unprocssed and mustUnderstand + // for addtional roles, for example those played by associated JAXWS handlers + if (additionalRoles != null) { + if (log.isDebugEnabled()) { + log.debug("Adding any mustUnderstand headers based on additonal SOAP roles: " + additionalRoles); + } + HandlerRolePlayer handlerRolePlayer = new HandlerRolePlayer(additionalRoles); + Iterator headerBlocks = envelope.getHeader().getHeadersToProcess(handlerRolePlayer); + while (headerBlocks.hasNext()) { + SOAPHeaderBlock shb = (SOAPHeaderBlock) headerBlocks.next(); + if (unprocessed == null) { + unprocessed = new ArrayList(); + } + if (!shb.isProcessed() && shb.getMustUnderstand()) { + unprocessed.add(shb.getQName()); + if (log.isDebugEnabled()) { + log.debug("Added header to unprocessed list: " + shb.getQName()); + } + } + } + } + if(unprocessed == null || unprocessed.size() == 0){ if(log.isDebugEnabled()){ log.debug("UNPROCESSED_HEADER_QNAMES not found."); } return; } + //lets go thru each header only if @HandlerChain is present if(!canUnderstand(msgContext)){ QName[] qNames = unprocessed.toArray(new QName[0]); @@ -186,3 +224,17 @@ } } +class HandlerRolePlayer implements RolePlayer { + List roles = new ArrayList(); + + HandlerRolePlayer(List additionalRoles) { + roles.addAll(additionalRoles); + } + public List getRoles() { + return roles; + } + public boolean isUltimateDestination() { + return false; + } +} + Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java?rev=639636&r1=639635&r2=639636&view=diff ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java (original) +++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/EndpointController.java Fri Mar 21 06:40:17 2008 @@ -56,6 +56,8 @@ import javax.xml.stream.XMLStreamReader; import javax.xml.ws.WebServiceException; import javax.xml.ws.handler.Handler; +import javax.xml.ws.handler.PortInfo; + import java.io.StringReader; import java.security.PrivilegedActionException; import java.security.PrivilegedExceptionAction; @@ -224,11 +226,15 @@ // // Since we're on the server, and there apparently is no Binding object // anywhere to be found... + List handlerRoles = null; if (eic.getHandlers() == null) { if (log.isDebugEnabled()) { log.debug("No handlers found on the InvocationContext, initializing handler list."); } - eic.setHandlers(new HandlerResolverImpl(endpointDesc.getServiceDescription()).getHandlerChain(endpointDesc.getPortInfo())); + HandlerResolverImpl hri = new HandlerResolverImpl(endpointDesc.getServiceDescription()); + PortInfo portInfo = endpointDesc.getPortInfo(); + eic.setHandlers(hri.getHandlerChain(portInfo)); + handlerRoles = hri.getRoles(portInfo); } //Lets Initialize the understood QName here, add only the headers that the handler //injects when we invoke the getHeader(). @@ -247,7 +253,7 @@ saveRequestMessage(request); //As per section 10.2.1 of JAXWS Specification, perform a mustUnderstand processing before //invoking inbound handlers. - HandlerUtils.checkMustUnderstand(request.getAxisMessageContext(), understood); + HandlerUtils.checkMustUnderstand(request.getAxisMessageContext(), understood, handlerRoles); // Invoke inbound application handlers. It's safe to use the first object on the iterator because there is // always exactly one EndpointDescription on a server invoke Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandHandler.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandHandler.java?rev=639636&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandHandler.java (added) +++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandHandler.java Fri Mar 21 06:40:17 2008 @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.axis2.jaxws.handler; + +import java.util.Set; + +import javax.xml.ws.handler.MessageContext; +import javax.xml.ws.handler.MessageContext.Scope; +import javax.xml.ws.handler.soap.SOAPMessageContext; + +/* + * You can't actually specify whether a handler is for client or server, + * you just have to check in the handleMessage and/or handleFault to make + * sure what direction we're going. + */ + +public class RoleBasedMustUnderstandHandler implements javax.xml.ws.handler.soap.SOAPHandler { + + public void close(MessageContext messagecontext) { + } + + public boolean handleFault(SOAPMessageContext messagecontext) { + return true; + } + + public Set getHeaders() { + return null; + } + + public boolean handleMessage(SOAPMessageContext messagecontext) { + return true; + } + +} Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandTests.xml URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandTests.xml?rev=639636&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandTests.xml (added) +++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandTests.xml Fri Mar 21 06:40:17 2008 @@ -0,0 +1,29 @@ + + + + + + + org.apache.axis2.jaxws.handler.RoleBasedMustUnderstandHandler + http://org/apache/axis2/jaxws/handler/AddedRole + + + + Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandTests2.xml URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandTests2.xml?rev=639636&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandTests2.xml (added) +++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUnderstandTests2.xml Fri Mar 21 06:40:17 2008 @@ -0,0 +1,30 @@ + + + + + + + org.apache.axis2.jaxws.handler.RoleBasedMustUnderstandHandler + http://org/apache/axis2/jaxws/handler/AddedRole + http://org/apache/axis2/jaxws/handler/AddedRole2 + + + + Added: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUndertandTests.java URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUndertandTests.java?rev=639636&view=auto ============================================================================== --- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUndertandTests.java (added) +++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/handler/RoleBasedMustUndertandTests.java Fri Mar 21 06:40:17 2008 @@ -0,0 +1,539 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you 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.axis2.jaxws.handler; + +import org.apache.axiom.om.OMAbstractFactory; +import org.apache.axiom.om.OMFactory; +import org.apache.axiom.soap.RolePlayer; +import org.apache.axiom.soap.SOAPEnvelope; +import org.apache.axiom.soap.SOAPFactory; +import org.apache.axiom.soap.SOAPHeader; +import org.apache.axiom.soap.SOAPHeaderBlock; +import org.apache.axis2.AxisFault; +import org.apache.axis2.Constants; +import org.apache.axis2.context.ConfigurationContext; +import org.apache.axis2.context.ConfigurationContextFactory; +import org.apache.axis2.context.MessageContext; +import org.apache.axis2.description.AxisService; +import org.apache.axis2.engine.AxisConfiguration; +import org.apache.axis2.jaxws.description.DescriptionFactory; +import org.apache.axis2.jaxws.description.EndpointDescription; +import org.apache.axis2.jaxws.description.ServiceDescription; +import org.apache.axis2.jaxws.description.xml.handler.HandlerChainType; +import org.apache.axis2.jaxws.description.xml.handler.HandlerChainsType; +import org.apache.axis2.jaxws.description.xml.handler.HandlerType; + +import javax.jws.HandlerChain; +import javax.jws.WebService; +import javax.xml.namespace.QName; +import javax.xml.ws.handler.Handler; +import javax.xml.ws.handler.PortInfo; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import junit.framework.TestCase; + +/** + * Test Role (SOAP 1.2 terminology) or Actor (SOAP 1.1 terminology) mustUndertand processing. + */ +public class RoleBasedMustUndertandTests extends TestCase { + private SOAPFactory soap11Factory; + private SOAPFactory soap12Factory; + private OMFactory omFactory; + + private String namespace = "http://RoleBasedMustUnderstandTest/good/namespace"; + private String soap11Namespace = "http://schemas.xmlsoap.org/soap/envelope/"; + private String header_ultimateReceiver = "header_ultimateReceiver"; + private String header_ultimateReceiver_processed = "header_ultmiateReceiver_processed"; + private String header_rolePlayed = "header_rolePlayed"; + private String header_roleNotPlayed = "header_roleNotPlayed"; + private String header_bindingAdded = "header_bindingAdded"; + private String header_SoapNext = "header_SoapNext"; + + private String rolePlayed1 = "http://Role/Played/role1"; + private String roleNotPlayed = "http://Role/Not/Played/role1"; + private String roleBindingAdded = "http://Role/Added/By/Binding"; + private String roleNoHeaders = "http://Role/Played/No/Headers"; + private String roleHandlerAdded = "http://org/apache/axis2/jaxws/handler/AddedRole"; + private String roleHandlerAdded2 = "http://org/apache/axis2/jaxws/handler/AddedRole2"; + private String roleSoap11Next = "http://schemas.xmlsoap.org/soap/actor/next"; + + public RoleBasedMustUndertandTests(String testName) { + super(testName); + soap11Factory = OMAbstractFactory.getSOAP11Factory(); + soap12Factory = OMAbstractFactory.getSOAP12Factory(); + omFactory = OMAbstractFactory.getOMFactory(); + } + + /** + * The JAXWS Spec, section 10, says roles can be set on the SOAP binding. Verify that a + * mustUnderstand header which is not processed for a role added by the SOAPBinding causes + * a Not Understood fault + */ + public void testRoleAddedToSoapBinding() { + RolePlayer rolePlayer = new UltimateDestinationRoles(); + + MessageContext mscCtx11 = createMessageContext(soap11Factory); + // Note that since this role is UltimateReceiver, all unprocessed headers will be set + // on the message context + setUnprocessedHeaders(mscCtx11, rolePlayer); + + // Indicate we understand (e.g. via handlers) the headers for Ultimate Receiver and the + // role we are acting in. We don't indicate we understand the header that the SOAPBinding + // added, so that should cause an exception + List understoodHeaders = new ArrayList(); + understoodHeaders.add(new QName(namespace, header_ultimateReceiver)); + understoodHeaders.add(new QName(namespace, header_rolePlayed)); + + // Create a list of additional roles that acted in (e.g. one played by a JAXWS + // handler) + List headerRolesPlayed = bindingAddedRole(); + + try { + HandlerUtils.checkMustUnderstand(mscCtx11, understoodHeaders, headerRolesPlayed); + fail("Should have gotten NotUnderstood fault for header for role added by binding: " + header_bindingAdded); + } catch (AxisFault af) { + // Expected path; should get exception for ultimate receiver not processed. + String checkFault = af.toString(); + if (!checkFault.contains("Must Understand check failed") + || !checkFault.contains(header_bindingAdded)) { + fail("Did not get expected NotUnderstood AxisFault. Unexpected fault " + af); + } + } catch (Exception e) { + fail("Caught unexpected exception + e"); + } + } + + /** + * Test where there are no previous non-understood headers on the MessageContext and there's an + * additional Role added by a JAXWS handler + */ + public void testOnlySoapBindingRole() { + MessageContext mscCtx11 = createMessageContext(soap11Factory); + // Note that we are not putting any non-understood headers on the message context + // Create a list of additional roles (e.g. one played by a JAXWS + // handler + List headerRolesPlayed = bindingAddedRole(); + + try { + HandlerUtils.checkMustUnderstand(mscCtx11, null, headerRolesPlayed); + fail("Should have gotten NotUnderstood fault for header for role added by binding: " + header_bindingAdded); + } catch (AxisFault af) { + // Expected path; should get exception for ultimate receiver not processed. + String checkFault = af.toString(); + if (!checkFault.contains("Must Understand check failed") + || !checkFault.contains(header_bindingAdded)) { + fail("Did not get expected NotUnderstood AxisFault. Unexpected fault " + af); + } + } catch (Exception e) { + fail("Caught unexpected exception + e"); + } + } + + /** + * Test that adding a role for headers that does not exist does not cause any fault + */ + public void testNoHeadersForSoapBindingRole() { + MessageContext mscCtx11 = createMessageContext(soap11Factory); + + List headerRolesPlayed = noHeadersRole(); + + try { + HandlerUtils.checkMustUnderstand(mscCtx11, null, headerRolesPlayed); + } catch (AxisFault af) { + fail("Unexpected AxisFault "+ af); + } catch (Exception e) { + fail("Caught unexpected exception + e"); + } + + } + /** + * A mustUnderstand header for a role not being acted in should NOT cause a notUnderstood + * fault. + */ + public void testRoleNotActingIn() { + RolePlayer rolePlayer = new UltimateDestinationRoles(); + + MessageContext mscCtx11 = createMessageContext(soap11Factory); + // Note that since this role is UltimateReceiver, all unprocessed headers will be set + // on the message context + setUnprocessedHeaders(mscCtx11, rolePlayer); + + // Indicate we understand (e.g. via handlers) the headers for Ultimate Receiver and the + // role we are acting in. This leaves the mustUnderstand header for the role we are not + // acting in, which should not cause an exception. + List understoodHeaders = new ArrayList(); + understoodHeaders.add(new QName(namespace, header_ultimateReceiver)); + understoodHeaders.add(new QName(namespace, header_rolePlayed)); + try { + HandlerUtils.checkMustUnderstand(mscCtx11, understoodHeaders, null); + } catch (AxisFault e) { + fail("Should not have caught an AxisFault " + e); + } + } + + /** + * Test mustUnderstand processing for Ultimate Receiver with an understood header list + * passed to the mustUnderstand checking + */ + public void testUltimateReceiverRoles() { + + RolePlayer rolePlayer = new UltimateDestinationRoles(); + MessageContext mscCtx11 = createMessageContext(soap11Factory); + setUnprocessedHeaders(mscCtx11, rolePlayer); + // Indicate we understand (e.g. via handlers) all the headers. + List understoodHeaders = new ArrayList(); + understoodHeaders.add(new QName(namespace, header_ultimateReceiver)); + understoodHeaders.add(new QName(namespace, header_rolePlayed)); + try { + HandlerUtils.checkMustUnderstand(mscCtx11, understoodHeaders, null); + } catch (AxisFault e) { + fail("Should not have caught an AxisFault " + e); + } + } + + /** + * Verify that an Ultimate Receiver with no roles only yields the header with no role specified + * as unprocessed and that passing a list of understood headers including just that one causes + * the mustUnderstand checks to pass. + */ + public void testUltimateReceiver() { + RolePlayer rolePlayer = new UltimateDestinationNoRoles(); + MessageContext msgCtx = createMessageContext(soap11Factory); + // Indicate the must understand header without an explicit role will be understood. + // The other headers, with explicit roles, should not cause an error. + setUnprocessedHeaders(msgCtx, rolePlayer); + List understoodHeaders = new ArrayList(); + understoodHeaders.add(new QName(namespace, header_ultimateReceiver)); + try { + HandlerUtils.checkMustUnderstand(msgCtx, understoodHeaders, null); + } catch (AxisFault e) { + fail("Should not have caught and AxisFault " + e); + } + } + /** + * Test mustUnderstand processing for Ultimate Receiver without additional understood headers + * being passed to the checker. This should cause a notUnderstood fault + */ + public void testUltimateReceiverNoRoles() { + RolePlayer rolePlayer = new UltimateDestinationNoRoles(); + + MessageContext messageContext11 = createMessageContext(soap11Factory); + setUnprocessedHeaders(messageContext11, rolePlayer); + try { + HandlerUtils.checkMustUnderstand(messageContext11, null, null); + fail("Should have gotten MustUnderstand Header Not Understood fault"); + } catch (AxisFault af) { + // Expected path; should get exception for ultimate receiver not processed. + String checkFault = af.toString(); + if (!checkFault.contains("Must Understand check failed") + || !checkFault.contains(header_ultimateReceiver)) { + fail("Did not get expected NotUnderstood AxisFault. Unexpected fault " + af); + } + } catch (Exception e) { + fail("Caught unexpected exception + e"); + } + + MessageContext messageContext12 = createMessageContext(soap12Factory); + setUnprocessedHeaders(messageContext12, rolePlayer); + try { + HandlerUtils.checkMustUnderstand(messageContext12, null, null); + fail("Should have gotten MustUnderstand Header Not Understood fault"); + } catch (AxisFault af) { + // Expected path; should get exception for ultimate receiver not processed. + if (!af.toString().contains("Must Understand check failed")) { + fail("Did not get expected NotUnderstood AxisFault. Unexpected fault " + af); + } + } catch (Exception e) { + fail("Caught unexpected exception + e"); + } + } + + /** + * Test a RolePlayer that is not an ultimate receiver and does not act in any roles + * corresponding to headers. There should be no faults cause by the mustUnderstand headers + */ + public void testNotUltimateReceiverNoRoles() { + RolePlayer rolePlayer = new NotUltimateDestinationNoRoles(); + + MessageContext msgCtx11 = createMessageContext(soap11Factory); + setUnprocessedHeaders(msgCtx11, rolePlayer); + try { + HandlerUtils.checkMustUnderstand(msgCtx11, null, null); + } catch (AxisFault e) { + fail("Should not have caught and AxisFault"); + } + + MessageContext msgCtx12 = createMessageContext(soap12Factory); + setUnprocessedHeaders(msgCtx12, rolePlayer); + try { + HandlerUtils.checkMustUnderstand(msgCtx12, null, null); + } catch (AxisFault e) { + fail("Should not have caught and AxisFault"); + } + } + + /** + * Test that the HandlerResolverImpl returns the correct roles defined in the handler config + * file elements. + */ + public void testHandlerResolverGetRoles() { + ServiceDescription serviceDesc = DescriptionFactory.createServiceDescription(RoleBasedMUServiceImpl.class); + HandlerResolverImpl handlerResolver = new HandlerResolverImpl(serviceDesc); + + EndpointDescription epDesc = serviceDesc.getEndpointDescriptions()[0]; + + // Make sure the role information is specified in the handler config file + HandlerChainsType epHandlerChains = epDesc.getHandlerChain(); + assertNotNull(epHandlerChains); + List epHandlerChain = epHandlerChains.getHandlerChain(); + assertEquals(1, epHandlerChain.size()); + List epHandler = epHandlerChain.get(0).getHandler(); + assertEquals(1, epHandler.size()); + HandlerType handlerType = epHandler.get(0); + List soapRoles = + handlerType.getSoapRole(); + assertNotNull(soapRoles); + assertEquals(1, soapRoles.size()); + String addedRole = soapRoles.get(0).getValue(); + assertEquals(roleHandlerAdded, addedRole); + + // Now verify the role information in the handler config file correctly affects the + // roles played returned from the Resolver + PortInfo portInfo = epDesc.getPortInfo(); + + List handlerRoles = handlerResolver.getRoles(portInfo); + assertNotNull(handlerRoles); + assertEquals(1, handlerRoles.size()); + assertEquals(roleHandlerAdded, handlerRoles.get(0)); + + List handlerChain = handlerResolver.getHandlerChain(portInfo); + assertNotNull(handlerChain); + assertEquals(1, handlerChain.size()); + } + + /** + * Test that multiple elements in the handler config file work correctly. + */ + public void testHandlerResolverGerRoles2() { + ServiceDescription serviceDesc = DescriptionFactory.createServiceDescription(RoleBasedMUServiceImpl2.class); + HandlerResolverImpl handlerResolver = new HandlerResolverImpl(serviceDesc); + EndpointDescription epDesc = serviceDesc.getEndpointDescriptions()[0]; + + // Make sure the role information is specified in the handler config file + HandlerChainsType epHandlerChains = epDesc.getHandlerChain(); + assertNotNull(epHandlerChains); + List epHandlerChain = epHandlerChains.getHandlerChain(); + assertEquals(1, epHandlerChain.size()); + List epHandler = epHandlerChain.get(0).getHandler(); + assertEquals(1, epHandler.size()); + HandlerType handlerType = epHandler.get(0); + List soapRoles = + handlerType.getSoapRole(); + assertNotNull(soapRoles); + assertEquals(2, soapRoles.size()); + ArrayList checkRoles = new ArrayList(); + checkRoles.add(soapRoles.get(0).getValue()); + checkRoles.add(soapRoles.get(1).getValue()); + assertTrue(checkRoles.contains(roleHandlerAdded)); + assertTrue(checkRoles.contains(roleHandlerAdded2)); + + // Now verify the role information in the handler config file correctly affects the + // roles played returned from the Resolver + PortInfo portInfo = epDesc.getPortInfo(); + + List handlerRoles = handlerResolver.getRoles(portInfo); + assertNotNull(handlerRoles); + assertEquals(2, handlerRoles.size()); + ArrayList checkResolverRoles = new ArrayList(); + checkResolverRoles.add((String) handlerRoles.get(0)); + checkResolverRoles.add((String) handlerRoles.get(1)); + assertTrue(checkResolverRoles.contains(roleHandlerAdded)); + assertTrue(checkResolverRoles.contains(roleHandlerAdded2)); + + List handlerChain = handlerResolver.getHandlerChain(portInfo); + assertNotNull(handlerChain); + assertEquals(1, handlerChain.size()); + + + } + + /** + * Test that a RolePlayer with no roles doesn't cause any problems in the mustUnderstand + * checking. + */ + public void testHandlerResolverEmptyRolesPlayed() { + + RolePlayer rolePlayer = new UltimateDestinationRoles(); + MessageContext msgCtx11 = createMessageContext(soap11Factory); + setUnprocessedHeaders(msgCtx11, rolePlayer); + // Indicate we understand (e.g. via handlers) all the headers. + List understoodHeaders = new ArrayList(); + understoodHeaders.add(new QName(namespace, header_ultimateReceiver)); + understoodHeaders.add(new QName(namespace, header_rolePlayed)); + + List handlerRolePlayer = new ArrayList(); + try { + HandlerUtils.checkMustUnderstand(msgCtx11, understoodHeaders, handlerRolePlayer); + } catch (AxisFault e) { + fail("Should not have caught and AxisFault"); + } + } + + // ============================================================================================= + // Utility methods + // ============================================================================================= + + private MessageContext createMessageContext(SOAPFactory soapFactory) { + MessageContext messageContext = null; + AxisService as1 = new AxisService("Service1"); + ConfigurationContext cc = null; + try { + cc = ConfigurationContextFactory.createEmptyConfigurationContext(); + AxisConfiguration ac = cc.getAxisConfiguration(); + ac.addService(as1); + messageContext = cc.createMessageContext(); + messageContext.setAxisService(as1); + + SOAPEnvelope se = soapFactory.createSOAPEnvelope(); + + SOAPHeader sh = soapFactory.createSOAPHeader(se); + + SOAPHeaderBlock shb1 = sh.addHeaderBlock(header_ultimateReceiver, + omFactory.createOMNamespace(namespace, header_ultimateReceiver)); + // Since no role was set on the shb1, default is ultimate receiver + shb1.setMustUnderstand(true); + + SOAPHeaderBlock shb2 = sh.addHeaderBlock(header_rolePlayed, + omFactory.createOMNamespace(namespace, header_rolePlayed)); + shb2.setRole(rolePlayed1); + shb2.setMustUnderstand(true); + + SOAPHeaderBlock shb3 = sh.addHeaderBlock(header_roleNotPlayed, + omFactory.createOMNamespace(namespace, header_roleNotPlayed)); + shb3.setRole(roleNotPlayed); + shb3.setMustUnderstand(true); + + SOAPHeaderBlock shb4 = sh.addHeaderBlock(header_bindingAdded, + omFactory.createOMNamespace(namespace, header_bindingAdded)); + shb4.setRole(roleBindingAdded); + shb4.setMustUnderstand(true); + + // This header is destined for the ulmiate receiver, but it is already processed + // so it shouldn't cause mustUnderstand fault + SOAPHeaderBlock shb5 = sh.addHeaderBlock(header_ultimateReceiver_processed, + omFactory.createOMNamespace(namespace, header_ultimateReceiver_processed)); + // Since no role was set on the shb1, default is ultimate receiver + shb5.setMustUnderstand(true); + shb5.setProcessed(); + + // Header targeted for SOAP11 role of Next, not set to MustUnderstand + SOAPHeaderBlock shb6 = sh.addHeaderBlock(header_SoapNext, + omFactory.createOMNamespace(soap11Namespace, header_SoapNext)); + shb6.setRole(roleSoap11Next); + + messageContext.setEnvelope(se); + } catch (AxisFault e) { + fail("Caught unexpected exception creating message context" + e); + } + return messageContext; + } + + private void setUnprocessedHeaders(MessageContext messageContext, RolePlayer rolePlayer) { + SOAPEnvelope envelope = messageContext.getEnvelope(); + Iterator headerBlocks = envelope.getHeader().getHeadersToProcess(rolePlayer); + List unprocessedHeaders = new ArrayList(); + while (headerBlocks.hasNext()) { + SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) headerBlocks.next(); + QName headerName = headerBlock.getQName(); + // if this header block has been processed or mustUnderstand isn't + // turned on then its cool + if (headerBlock.isProcessed() || !headerBlock.getMustUnderstand()) { + continue; + } else { + unprocessedHeaders.add(headerName); + } + } + if(unprocessedHeaders !=null && unprocessedHeaders.size()>0){ + messageContext.setProperty(Constants.UNPROCESSED_HEADER_QNAMES, unprocessedHeaders); + } + } + + private List bindingAddedRole() { + List roles = new ArrayList(); + roles.add(roleBindingAdded); + return roles; + } + + private List noHeadersRole() { + List roles = new ArrayList(); + roles.add(roleNoHeaders); + return roles; + } + + + // ============================================================================================= + // Inner Test Classes + // ============================================================================================= + + class UltimateDestinationNoRoles implements RolePlayer { + public List getRoles() { + return null; + } + public boolean isUltimateDestination() { + return true; + } + } + + class NotUltimateDestinationNoRoles implements RolePlayer { + public List getRoles() { + return null; + } + public boolean isUltimateDestination() { + return false; + } + } + + class UltimateDestinationRoles implements RolePlayer { + List roles = new ArrayList(); + public UltimateDestinationRoles() { + roles.add(rolePlayed1); + } + public List getRoles() { + return roles; + } + public boolean isUltimateDestination() { + return true; + } + } + + @WebService + @HandlerChain(file="RoleBasedMustUnderstandTests.xml") + class RoleBasedMUServiceImpl { + + } + + @WebService + @HandlerChain(file="RoleBasedMustUnderstandTests2.xml") + class RoleBasedMUServiceImpl2 { + + } +} --------------------------------------------------------------------- To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org For additional commands, e-mail: axis-cvs-help@ws.apache.org