WsAddressingMessageConverter extends SoapMessageConverter { @Override public void convertOutbound(WebServiceMessage webServiceMessage, Message message, WebServiceEndpointConfiguration endpointConfiguration, TestContext context) { super.convertOutbound(webServiceMessage, message, endpointConfiguration, context); SoapMessage soapMessage = (SoapMessage) webServiceMessage; URI messageId; if (message.getHeader(WsAddressingMessageHeaders.MESSAGE_ID) != null) { messageId = URI.create(context.replaceDynamicContentInString(message.getHeader(WsAddressingMessageHeaders.MESSAGE_ID).toString())); } else if (addressingHeaders.getMessageId() != null) { messageId = addressingHeaders.getMessageId(); } else { messageId = messageIdStrategy.newMessageId(soapMessage); } EndpointReference from = addressingHeaders.getFrom(); if (message.getHeader(WsAddressingMessageHeaders.FROM) != null) { from = new EndpointReference(URI.create(context.replaceDynamicContentInString(message.getHeader(WsAddressingMessageHeaders.FROM).toString()))); } URI to = addressingHeaders.getTo(); if (message.getHeader(WsAddressingMessageHeaders.TO) != null) { to = URI.create(context.replaceDynamicContentInString(message.getHeader(WsAddressingMessageHeaders.TO).toString())); } URI action = addressingHeaders.getAction(); if (message.getHeader(WsAddressingMessageHeaders.ACTION) != null) { action = URI.create(context.replaceDynamicContentInString(message.getHeader(WsAddressingMessageHeaders.ACTION).toString())); } EndpointReference replyTo = addressingHeaders.getReplyTo(); if (message.getHeader(WsAddressingMessageHeaders.REPLY_TO) != null) { replyTo = new EndpointReference(URI.create(context.replaceDynamicContentInString(message.getHeader(WsAddressingMessageHeaders.REPLY_TO).toString()))); } EndpointReference faultTo = addressingHeaders.getReplyTo(); if (message.getHeader(WsAddressingMessageHeaders.FAULT_TO) != null) { faultTo = new EndpointReference(URI.create(context.replaceDynamicContentInString(message.getHeader(WsAddressingMessageHeaders.FAULT_TO).toString()))); } MessageAddressingProperties map = new MessageAddressingProperties(to, from, replyTo, faultTo, action, messageId); AddressingVersion version; if (WsAddressingVersion.VERSION10.equals(addressingHeaders.getVersion())) { version = new Addressing10(); } else if (WsAddressingVersion.VERSION200408.equals(addressingHeaders.getVersion())) { version = new Addressing200408(); } else { throw new CitrusRuntimeException("Unsupported ws addressing version '" + addressingHeaders.getVersion() + "'"); } version.addAddressingHeaders(soapMessage, map); } WsAddressingMessageConverter(WsAddressingHeaders addressingHeaders); @Override void convertOutbound(WebServiceMessage webServiceMessage, Message message, WebServiceEndpointConfiguration endpointConfiguration, TestContext context); MessageIdStrategy getMessageIdStrategy(); void setMessageIdStrategy(MessageIdStrategy messageIdStrategy); WsAddressingHeaders getAddressingHeaders();  }
@Test public void testOutboundWsAddressingHeaders() throws TransformerException, IOException { Message testMessage = new DefaultMessage(requestPayload); StringResult soapBodyResult = new StringResult(); StringResult soapHeaderResult = new StringResult(); SoapHeaderElement soapHeaderElement = Mockito.mock(SoapHeaderElement.class); reset(soapRequest, soapBody, soapHeader, soapHeaderElement); when(soapRequest.getSoapBody()).thenReturn(soapBody); when(soapBody.getPayloadResult()).thenReturn(soapBodyResult); when(soapRequest.getSoapHeader()).thenReturn(soapHeader); when(soapHeader.addHeaderElement(eq(new QName("http: when(soapHeader.addHeaderElement(eq(new QName("http: when(soapHeader.addHeaderElement(eq(new QName("http: when(soapHeader.addHeaderElement(eq(new QName("http: when(soapHeaderElement.getResult()).thenReturn(new StringResult()); when(soapHeader.getResult()).thenReturn(soapHeaderResult); messageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(soapBodyResult.toString(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + requestPayload); Assert.assertEquals(soapHeaderResult.toString(), ""); verify(soapHeader).addNamespaceDeclaration("wsa", "http: verify(soapHeaderElement).setText("Test"); verify(soapHeaderElement).setMustUnderstand(true); verify(soapHeaderElement).setText("wsAddressing"); verify(soapHeaderElement).setText("urn:uuid:aae36050-2853-4ca8-b879-fe366f97c5a1"); }
@Test public void testOverwriteWsAddressingHeaders() throws TransformerException, IOException { Message testMessage = new DefaultMessage(requestPayload) .setHeader(WsAddressingMessageHeaders.FROM, "customFrom") .setHeader(WsAddressingMessageHeaders.TO, "customTo") .setHeader(WsAddressingMessageHeaders.ACTION, "customAction") .setHeader(WsAddressingMessageHeaders.MESSAGE_ID, "${messageId}"); context.setVariable("messageId", "urn:custom"); StringResult soapBodyResult = new StringResult(); StringResult soapHeaderResult = new StringResult(); SoapHeaderElement soapHeaderElement = Mockito.mock(SoapHeaderElement.class); reset(soapRequest, soapBody, soapHeader, soapHeaderElement); when(soapRequest.getSoapBody()).thenReturn(soapBody); when(soapBody.getPayloadResult()).thenReturn(soapBodyResult); when(soapRequest.getSoapHeader()).thenReturn(soapHeader); when(soapHeader.addHeaderElement(eq(new QName("http: when(soapHeader.addHeaderElement(eq(new QName("http: when(soapHeader.addHeaderElement(eq(new QName("http: when(soapHeader.addHeaderElement(eq(new QName("http: when(soapHeaderElement.getResult()).thenReturn(new StringResult()); when(soapHeader.getResult()).thenReturn(soapHeaderResult); messageConverter.convertOutbound(soapRequest, testMessage, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(soapBodyResult.toString(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + requestPayload); Assert.assertEquals(soapHeaderResult.toString(), ""); verify(soapHeader).addNamespaceDeclaration("wsa", "http: verify(soapHeaderElement).setText("customTo"); verify(soapHeaderElement).setMustUnderstand(true); verify(soapHeaderElement).setText("customAction"); verify(soapHeaderElement).setText("urn:custom"); }