SoapMessageConverter implements WebServiceMessageConverter { @Override public SoapMessage convertInbound(final WebServiceMessage message, final WebServiceEndpointConfiguration endpointConfiguration, final TestContext context) { return convertInbound(message, null, endpointConfiguration); }  @Override WebServiceMessage convertOutbound(final Message internalMessage,
                                             final WebServiceEndpointConfiguration endpointConfiguration,
                                             final TestContext context); @Override void convertOutbound(final WebServiceMessage webServiceMessage,
                                final Message message,
                                final WebServiceEndpointConfiguration endpointConfiguration,
                                final TestContext context); @Override SoapMessage convertInbound(final WebServiceMessage message,
                                      final WebServiceEndpointConfiguration endpointConfiguration,
                                      final TestContext context); @Override SoapMessage convertInbound(final WebServiceMessage webServiceMessage,
                                      final MessageContext messageContext,
                                      final WebServiceEndpointConfiguration endpointConfiguration); String getCharset(); void setCharset(final String charset);  }
@Test public void testInboundSoapBody() { final StringSource soapBodySource = new StringSource(payload); when(soapResponse.getEnvelope()).thenReturn(soapEnvelope); when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload())); when(soapResponse.getPayloadSource()).thenReturn(soapBodySource); when(soapResponse.getSoapHeader()).thenReturn(soapHeader); when(soapEnvelope.getHeader()).thenReturn(soapHeader); when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator()); when(soapHeader.getSource()).thenReturn(null); when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator()); when(soapResponse.getSoapAction()).thenReturn(""); final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + payload); Assert.assertNull(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION)); Assert.assertEquals(responseMessage.getHeaderData().size(), 0L); }
@Test public void testInboundSoapBodyOnlyRootElement() { final StringSource soapBodySource = new StringSource("<testMessage/>"); when(soapResponse.getEnvelope()).thenReturn(soapEnvelope); when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload())); when(soapResponse.getPayloadSource()).thenReturn(soapBodySource); when(soapResponse.getSoapHeader()).thenReturn(soapHeader); when(soapEnvelope.getHeader()).thenReturn(soapHeader); when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator()); when(soapHeader.getSource()).thenReturn(null); when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator()); when(soapResponse.getSoapAction()).thenReturn(""); final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + "<testMessage/>"); Assert.assertNull(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION)); Assert.assertEquals(responseMessage.getHeaderData().size(), 0L); }
@Test public void testInboundSoapAction() { final StringSource soapBodySource = new StringSource(payload); when(soapResponse.getEnvelope()).thenReturn(soapEnvelope); when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload())); when(soapResponse.getPayloadSource()).thenReturn(soapBodySource); when(soapResponse.getSoapHeader()).thenReturn(soapHeader); when(soapEnvelope.getHeader()).thenReturn(soapHeader); when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator()); when(soapHeader.getSource()).thenReturn(null); when(soapResponse.getSoapAction()).thenReturn("soapOperation"); when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator()); final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + payload); Assert.assertEquals(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION), "soapOperation"); Assert.assertEquals(responseMessage.getHeaderData().size(), 0L); }
@Test public void testInboundSoapHeaderContent() { final String soapHeaderContent = "<header>" + "<operation>unitTest</operation>" + "<messageId>123456789</messageId>" + "</header>"; final StringSource soapBodySource = new StringSource(payload); when(soapResponse.getEnvelope()).thenReturn(soapEnvelope); when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload())); when(soapResponse.getPayloadSource()).thenReturn(soapBodySource); when(soapResponse.getSoapHeader()).thenReturn(soapHeader); when(soapEnvelope.getHeader()).thenReturn(soapHeader); when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator()); when(soapHeader.getSource()).thenReturn(new StringSource(soapHeaderContent)); when(soapResponse.getSoapAction()).thenReturn("\"\""); when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator()); final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + payload); Assert.assertEquals(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION), ""); Assert.assertEquals(responseMessage.getHeaderData().size(), 1L); Assert.assertEquals(responseMessage.getHeaderData().get(0), XML_PROCESSING_INSTRUCTION + soapHeaderContent); }
@Test public void testInboundSoapHeader() { final StringSource soapBodySource = new StringSource(payload); final Set<SoapHeaderElement> soapHeaders = new HashSet<>(); soapHeaders.add(soapHeaderElement); when(soapResponse.getEnvelope()).thenReturn(soapEnvelope); when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload())); when(soapResponse.getPayloadSource()).thenReturn(soapBodySource); when(soapResponse.getSoapHeader()).thenReturn(soapHeader); when(soapEnvelope.getHeader()).thenReturn(soapHeader); when(soapHeader.examineAllHeaderElements()).thenReturn(soapHeaders.iterator()); when(soapHeader.getSource()).thenReturn(null); when(soapHeaderElement.getName()).thenReturn(new QName("{http: when(soapHeaderElement.getText()).thenReturn("123456789"); when(soapResponse.getSoapAction()).thenReturn("soapOperation"); when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator()); final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + payload); Assert.assertEquals(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION), "soapOperation"); Assert.assertEquals(responseMessage.getHeader("{http: Assert.assertEquals(responseMessage.getHeaderData().size(), 0L); }
@Test public void testInboundSoapAttachment() throws IOException { final SoapAttachment attachment = new SoapAttachment(); attachment.setContentId("attContentId"); attachment.setContent("This is a SOAP attachment" + System.getProperty("line.separator") + "with multi-line"); attachment.setContentType("plain/text"); final StringSource soapBodySource = new StringSource(payload); final Set<Attachment> soapAttachments = new HashSet<>(); soapAttachments.add(attachment); when(soapResponse.getEnvelope()).thenReturn(soapEnvelope); when(soapEnvelope.getSource()).thenReturn(new StringSource(getSoapRequestPayload())); when(soapResponse.getPayloadSource()).thenReturn(soapBodySource); when(soapResponse.getSoapHeader()).thenReturn(soapHeader); when(soapEnvelope.getHeader()).thenReturn(soapHeader); when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator()); when(soapHeader.getSource()).thenReturn(null); when(soapResponse.getSoapAction()).thenReturn("soapOperation"); when(soapResponse.getAttachments()).thenReturn(soapAttachments.iterator()); final SoapMessage responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context); Assert.assertNotNull(responseMessage); Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + payload); Assert.assertEquals(responseMessage.getSoapAction(), "soapOperation"); Assert.assertEquals(responseMessage.getHeaderData().size(), 0L); final List<SoapAttachment> attachments = responseMessage.getAttachments(); Assert.assertEquals(attachments.size(), 1L); Assert.assertEquals(attachments.get(0).getContentId(), attachment.getContentId()); Assert.assertEquals(attachments.get(0).getContentType(), attachment.getContentType()); Assert.assertEquals(FileUtils.readToString(attachments.get(0).getInputStream()), attachment.getContent()); }
@Test public void testInboundSoapBodyWithNamespaceTranslation() { final StringSource soapBodySource = new StringSource(payload); when(soapResponse.getEnvelope()).thenReturn(soapEnvelope); when(soapEnvelope.getSource()).thenReturn(new DOMSource(XMLUtils.parseMessagePayload(getSoapRequestPayload(payload, "xmlns:foo=\"http: when(soapResponse.getPayloadSource()).thenReturn(soapBodySource); when(soapResponse.getSoapHeader()).thenReturn(soapHeader); when(soapEnvelope.getHeader()).thenReturn(soapHeader); when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator()); when(soapHeader.getSource()).thenReturn(null); when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator()); when(soapResponse.getSoapAction()).thenReturn(""); final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + "<testMessage xmlns:foo=\"http: Assert.assertNull(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION)); Assert.assertEquals(responseMessage.getHeaderData().size(), 0L); }
@Test public void testInboundSoapBodyWithNamespaceTranslationXmlProcessingInstruction() { final StringSource soapBodySource = new StringSource(XML_PROCESSING_INSTRUCTION + payload); when(soapResponse.getEnvelope()).thenReturn(soapEnvelope); when(soapEnvelope.getSource()).thenReturn(new DOMSource(XMLUtils.parseMessagePayload(getSoapRequestPayload(payload, "xmlns:foo=\"http: when(soapResponse.getPayloadSource()).thenReturn(soapBodySource); when(soapResponse.getSoapHeader()).thenReturn(soapHeader); when(soapEnvelope.getHeader()).thenReturn(soapHeader); when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator()); when(soapHeader.getSource()).thenReturn(null); when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator()); when(soapResponse.getSoapAction()).thenReturn(""); final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + "<testMessage xmlns:foo=\"http: Assert.assertNull(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION)); Assert.assertEquals(responseMessage.getHeaderData().size(), 0L); }
@Test public void testInboundSoapBodyWithNamespaceTranslationOnlyRootElement() { final String payload = "<testMessage xmlns:foo=\"http: "other=\"true\"/>"; final StringSource soapBodySource = new StringSource(payload); when(soapResponse.getEnvelope()).thenReturn(soapEnvelope); when(soapEnvelope.getSource()).thenReturn(new DOMSource(XMLUtils.parseMessagePayload(getSoapRequestPayload(payload, "skip=\"true\"", "xmlns:foo=\"http: "xmlns:new=\"http: when(soapResponse.getPayloadSource()).thenReturn(soapBodySource); when(soapResponse.getSoapHeader()).thenReturn(soapHeader); when(soapEnvelope.getHeader()).thenReturn(soapHeader); when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator()); when(soapHeader.getSource()).thenReturn(null); when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator()); when(soapResponse.getSoapAction()).thenReturn(""); final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + "<testMessage xmlns:foo=\"http: "other=\"true\" xmlns:new=\"http: Assert.assertNull(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION)); Assert.assertEquals(responseMessage.getHeaderData().size(), 0L); }
@Test public void testInboundSoapBodyWithNamespaceTranslationDuplicates() { final String payload = "<testMessage xmlns:foo=\"http: "other=\"true\">Hello</testMessage>"; final StringSource soapBodySource = new StringSource(payload); when(soapResponse.getEnvelope()).thenReturn(soapEnvelope); when(soapEnvelope.getSource()).thenReturn(new DOMSource(XMLUtils.parseMessagePayload(getSoapRequestPayload(payload, "skip=\"true\"", "xmlns:foo=\"http: "xmlns:new=\"http: when(soapResponse.getPayloadSource()).thenReturn(soapBodySource); when(soapResponse.getSoapHeader()).thenReturn(soapHeader); when(soapEnvelope.getHeader()).thenReturn(soapHeader); when(soapHeader.examineAllHeaderElements()).thenReturn(new HashSet<SoapHeaderElement>().iterator()); when(soapHeader.getSource()).thenReturn(null); when(soapResponse.getAttachments()).thenReturn(new HashSet<Attachment>().iterator()); when(soapResponse.getSoapAction()).thenReturn(""); final Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration(), context); Assert.assertEquals(responseMessage.getPayload(), XML_PROCESSING_INSTRUCTION + "<testMessage xmlns:foo=\"http: "other=\"true\" xmlns:new=\"http: Assert.assertNull(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION)); Assert.assertEquals(responseMessage.getHeaderData().size(), 0L); }
@Test public void testInboundSoapKeepEnvelope() throws IOException { final SaajSoapMessageFactory soapMessageFactory = new SaajSoapMessageFactory(); soapMessageFactory.afterPropertiesSet(); final WebServiceMessage soapMessage = soapMessageFactory.createWebServiceMessage(new ByteArrayInputStream((XML_PROCESSING_INSTRUCTION + getSoapRequestPayload()).getBytes())); final WebServiceEndpointConfiguration endpointConfiguration = new WebServiceEndpointConfiguration(); endpointConfiguration.setKeepSoapEnvelope(true); final Message responseMessage = soapMessageConverter.convertInbound(soapMessage, endpointConfiguration, context); Assert.assertEquals(StringUtils.trimAllWhitespace(responseMessage.getPayload(String.class)), StringUtils.trimAllWhitespace(XML_PROCESSING_INSTRUCTION + getSoapRequestPayload())); Assert.assertEquals(responseMessage.getHeaderData().size(), 1L); Assert.assertEquals(responseMessage.getHeaderData().get(0), XML_PROCESSING_INSTRUCTION + "<SOAP-ENV:Header xmlns:SOAP-ENV=\"http: }