SoapMessageDispatcher extends MessageDispatcher { @Override protected boolean handleRequest(EndpointInvocationChain mappedEndpoint, MessageContext messageContext) { if (messageContext.getRequest() instanceof SoapMessage) { String[] actorsOrRoles = null; boolean isUltimateReceiver = true; if (mappedEndpoint instanceof SoapEndpointInvocationChain) { SoapEndpointInvocationChain soapChain = (SoapEndpointInvocationChain) mappedEndpoint; actorsOrRoles = soapChain.getActorsOrRoles(); isUltimateReceiver = soapChain.isUltimateReceiver(); } return handleHeaders(mappedEndpoint, messageContext, actorsOrRoles, isUltimateReceiver); } return true; }  void setMustUnderstandFaultString(String mustUnderstandFaultString); void setMustUnderstandFaultStringLocale(Locale mustUnderstandFaultStringLocale); static final String DEFAULT_MUST_UNDERSTAND_FAULT_STRING; }
@Test public void testProcessMustUnderstandHeadersUnderstoodSoap11() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); SOAPMessage request = messageFactory.createMessage(); SOAPHeaderElement header = request.getSOAPHeader() .addHeaderElement(new QName("http: header.setActor(SOAPConstants.URI_SOAP_ACTOR_NEXT); header.setMustUnderstand(true); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory); expect(interceptorMock.understands(isA(SoapHeaderElement.class))).andReturn(true); replay(interceptorMock); SoapEndpointInvocationChain chain = new SoapEndpointInvocationChain(new Object(), new SoapEndpointInterceptor[] { interceptorMock }); boolean result = dispatcher.handleRequest(chain, context); Assert.assertTrue("Header not understood", result); verify(interceptorMock); }
@Test public void testProcessMustUnderstandHeadersUnderstoodSoap12() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage request = messageFactory.createMessage(); SOAPHeaderElement header = request.getSOAPHeader() .addHeaderElement(new QName("http: header.setMustUnderstand(true); header.setRole(SOAPConstants.URI_SOAP_1_2_ROLE_NEXT); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory); expect(interceptorMock.understands(isA(SoapHeaderElement.class))).andReturn(true); replay(interceptorMock); SoapEndpointInvocationChain chain = new SoapEndpointInvocationChain(new Object(), new SoapEndpointInterceptor[] { interceptorMock }); boolean result = dispatcher.handleRequest(chain, context); Assert.assertTrue("Header not understood", result); verify(interceptorMock); }
@Test public void testProcessMustUnderstandHeadersNotUnderstoodSoap11() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); SOAPMessage request = messageFactory.createMessage(); SOAPHeaderElement header = request.getSOAPHeader() .addHeaderElement(new QName("http: header.setActor(SOAPConstants.URI_SOAP_ACTOR_NEXT); header.setMustUnderstand(true); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory); expect(interceptorMock.understands(isA(SoapHeaderElement.class))).andReturn(false); replay(interceptorMock); SoapEndpointInvocationChain chain = new SoapEndpointInvocationChain(new Object(), new SoapEndpointInterceptor[] { interceptorMock }); boolean result = dispatcher.handleRequest(chain, context); Assert.assertFalse("Header understood", result); Assert.assertTrue("Context has no response", context.hasResponse()); SoapBody responseBody = ((SoapMessage) context.getResponse()).getSoapBody(); Assert.assertTrue("Response body has no fault", responseBody.hasFault()); Soap11Fault fault = (Soap11Fault) responseBody.getFault(); Assert.assertEquals("Invalid fault code", new QName(SOAPConstants.URI_NS_SOAP_1_1_ENVELOPE, "MustUnderstand"), fault.getFaultCode()); Assert.assertEquals("Invalid fault string", SoapMessageDispatcher.DEFAULT_MUST_UNDERSTAND_FAULT_STRING, fault.getFaultStringOrReason()); Assert.assertEquals("Invalid fault string locale", Locale.ENGLISH, fault.getFaultStringLocale()); verify(interceptorMock); }
@Test public void testProcessMustUnderstandHeadersNotUnderstoodSoap12() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage request = messageFactory.createMessage(); SOAPHeaderElement header = request.getSOAPHeader() .addHeaderElement(new QName("http: header.setMustUnderstand(true); header.setRole(SOAPConstants.URI_SOAP_1_2_ROLE_NEXT); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory); expect(interceptorMock.understands(isA(SoapHeaderElement.class))).andReturn(false); replay(interceptorMock); SoapEndpointInvocationChain chain = new SoapEndpointInvocationChain(new Object(), new SoapEndpointInterceptor[] { interceptorMock }); boolean result = dispatcher.handleRequest(chain, context); Assert.assertFalse("Header understood", result); Assert.assertTrue("Context has no response", context.hasResponse()); SoapMessage response = (SoapMessage) context.getResponse(); SoapBody responseBody = response.getSoapBody(); Assert.assertTrue("Response body has no fault", responseBody.hasFault()); Soap12Fault fault = (Soap12Fault) responseBody.getFault(); Assert.assertEquals("Invalid fault code", new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "MustUnderstand"), fault.getFaultCode()); Assert.assertEquals("Invalid fault string", SoapMessageDispatcher.DEFAULT_MUST_UNDERSTAND_FAULT_STRING, fault.getFaultReasonText(Locale.ENGLISH)); SoapHeader responseHeader = response.getSoapHeader(); Iterator<SoapHeaderElement> iterator = responseHeader.examineAllHeaderElements(); Assert.assertTrue("Response header has no elements", iterator.hasNext()); SoapHeaderElement headerElement = iterator.next(); Assert.assertEquals("No NotUnderstood header", new QName(SOAPConstants.URI_NS_SOAP_1_2_ENVELOPE, "NotUnderstood"), headerElement.getName()); verify(interceptorMock); }
@Test public void testProcessMustUnderstandHeadersForActorSoap11() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); SOAPMessage request = messageFactory.createMessage(); SOAPHeaderElement header = request.getSOAPHeader() .addHeaderElement(new QName("http: String headerActor = "http: header.setActor(headerActor); header.setMustUnderstand(true); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory); expect(interceptorMock.understands(isA(SoapHeaderElement.class))).andReturn(true); replay(interceptorMock); SoapEndpointInvocationChain chain = new SoapEndpointInvocationChain(new Object(), new SoapEndpointInterceptor[] { interceptorMock }, new String[] { headerActor }, true); boolean result = dispatcher.handleRequest(chain, context); Assert.assertTrue("actor-specific header not understood", result); verify(interceptorMock); }
@Test public void testProcessMustUnderstandHeadersForRoleSoap12() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_2_PROTOCOL); SOAPMessage request = messageFactory.createMessage(); SOAPHeaderElement header = request.getSOAPHeader() .addHeaderElement(new QName("http: String headerRole = "http: header.setRole(headerRole); header.setMustUnderstand(true); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory); expect(interceptorMock.understands(isA(SoapHeaderElement.class))).andReturn(true); replay(interceptorMock); SoapEndpointInvocationChain chain = new SoapEndpointInvocationChain(new Object(), new SoapEndpointInterceptor[] { interceptorMock }, new String[] { headerRole }, true); boolean result = dispatcher.handleRequest(chain, context); Assert.assertTrue("role-specific header not understood", result); verify(interceptorMock); }
@Test public void testProcessNoHeader() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); SOAPMessage request = messageFactory.createMessage(); request.getSOAPHeader().detachNode(); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory); replay(interceptorMock); SoapEndpointInvocationChain chain = new SoapEndpointInvocationChain(new Object(), new SoapEndpointInterceptor[] { interceptorMock }, new String[] { "role" }, true); boolean result = dispatcher.handleRequest(chain, context); Assert.assertTrue("Invalid result", result); verify(interceptorMock); }
@Test public void testProcessMustUnderstandHeadersNoInterceptors() throws Exception { MessageFactory messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL); SOAPMessage request = messageFactory.createMessage(); SOAPHeaderElement header = request.getSOAPHeader() .addHeaderElement(new QName("http: header.setActor(SOAPConstants.URI_SOAP_ACTOR_NEXT); header.setMustUnderstand(true); SoapMessageFactory factory = new SaajSoapMessageFactory(messageFactory); MessageContext context = new DefaultMessageContext(new SaajSoapMessage(request), factory); replay(interceptorMock); SoapEndpointInvocationChain chain = new SoapEndpointInvocationChain(new Object(), null); boolean result = dispatcher.handleRequest(chain, context); Assert.assertFalse("Header understood", result); verify(interceptorMock); }