Package com.consol.citrus.ws.message

Examples of com.consol.citrus.ws.message.SoapAttachment


        PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();
        messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");
       
        context.setVariable("myText", "Hello World!");

        SoapAttachment attachment = new SoapAttachment();
        attachment.setContentResourcePath("classpath:com/consol/citrus/ws/actions/test-attachment-with-variables.xml");
        soapMessageAction.setAttachments(Collections.singletonList(attachment));

        soapMessageAction.setMessageBuilder(messageBuilder);
       
        reset(webServiceEndpoint, producer);

        expect(webServiceEndpoint.createProducer()).andReturn(producer).once();
        producer.send(anyObject(Message.class), anyObject(TestContext.class));
        expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                Assert.assertEquals(((SoapMessage)EasyMock.getCurrentArguments()[0]).getAttachments().size(), 1L);
                SoapAttachment constructedAttachment = ((SoapMessage)EasyMock.getCurrentArguments()[0]).getAttachments().get(0);
                Assert.assertNull(constructedAttachment.getContentId());
                Assert.assertEquals(constructedAttachment.getContentType(), "text/plain");
                Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");
                Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8");
               
                return null;
            }
        }).once();
       
View Full Code Here


    protected void handleInboundAttachments(org.springframework.ws.soap.SoapMessage soapMessage, SoapMessage message) {
        Iterator<?> attachments = soapMessage.getAttachments();

        while (attachments.hasNext()) {
            Attachment attachment = (Attachment)attachments.next();
            SoapAttachment soapAttachment = SoapAttachment.from(attachment);

            if (log.isDebugEnabled()) {
                log.debug(String.format("SOAP message contains attachment with contentId '%s'", attachment.getContentId()));
            }
View Full Code Here

        verify(soapResponse, soapEnvelope, soapBody, soapHeader, soapHeaderElement);
    }
   
    @Test
    public void testSoapAttachment() throws TransformerException, IOException {
        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");
       
        SoapResponseMessageCallback callback = new SoapResponseMessageCallback(new WebServiceEndpointConfiguration());
       
        StringSource soapBodySource = new StringSource(responsePayload);
       
        Set<SoapHeaderElement> soapHeaders = new HashSet<SoapHeaderElement>();
        Set<Attachment> soapAttachments = new HashSet<Attachment>();
        soapAttachments.add(attachment);
       
        reset(soapResponse, soapEnvelope, soapBody, soapHeader);
       
        expect(soapResponse.getEnvelope()).andReturn(soapEnvelope).anyTimes();
        expect(soapResponse.getPayloadSource()).andReturn(soapBodySource).times(2);
        expect(soapResponse.getSoapHeader()).andReturn(soapHeader).anyTimes();
        expect(soapEnvelope.getHeader()).andReturn(soapHeader).anyTimes();
        expect(soapHeader.examineAllHeaderElements()).andReturn(soapHeaders.iterator()).once();
        expect(soapHeader.getSource()).andReturn(null).once();
       
        expect(soapResponse.getSoapAction()).andReturn("soapOperation").anyTimes();
       
        expect(soapResponse.getAttachments()).andReturn(soapAttachments.iterator()).once();
       
        replay(soapResponse, soapEnvelope, soapBody, soapHeader);
       
        callback.doWithMessage(soapResponse);
       
        Message responseMessage = callback.getResponse();
        Assert.assertEquals(responseMessage.getPayload(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + responsePayload);
        Assert.assertEquals(responseMessage.getHeader(SoapMessageHeaders.SOAP_ACTION), "soapOperation");
        Assert.assertEquals(responseMessage.getHeaderData().size(), 0L);

        Assert.assertTrue(SoapMessage.class.isInstance(responseMessage));

        SoapMessage soapResponseMessage = (SoapMessage) responseMessage;
        Assert.assertEquals(soapResponseMessage.getAttachments().get(0).getContentId(), attachment.getContentId());
        Assert.assertEquals(soapResponseMessage.getAttachments().get(0).getContentType(), attachment.getContentType());
        Assert.assertEquals(FileUtils.readToString(soapResponseMessage.getAttachments().get(0).getInputStream()), attachment.getContent());

        verify(soapResponse, soapEnvelope, soapBody, soapHeader);
    }
View Full Code Here

        verify(saajSoapRequest, soapBody, soapHeader, soapEnvelope, saajMessage);
    }

    @Test
    public void testOutboundSoapAttachment() throws TransformerException, IOException {
        SoapAttachment attachment = new SoapAttachment();
        attachment.setContentId("attContentId");
        attachment.setContent("This is a SOAP attachment\nwith multi-line");
        attachment.setContentType("plain/text");

        SoapMessage testMessage = new SoapMessage(requestPayload);
        testMessage.addAttachment(attachment);

        SoapMessageConverter soapMessageConverter = new SoapMessageConverter();

        reset(soapRequest, soapBody);

        expect(soapRequest.getSoapBody()).andReturn(soapBody).once();
        expect(soapBody.getPayloadResult()).andReturn(new StringResult()).once();

        expect(soapRequest.addAttachment(eq(attachment.getContentId()), (InputStreamSource)anyObject(), eq(attachment.getContentType()))).andAnswer(new IAnswer<Attachment>() {
            public Attachment answer() throws Throwable {
                InputStreamSource contentStream = (InputStreamSource)EasyMock.getCurrentArguments()[1];
                BufferedReader reader = new BufferedReader(new InputStreamReader(contentStream.getInputStream()));

                Assert.assertEquals(reader.readLine(), "This is a SOAP attachment");
View Full Code Here

        verify(soapResponse, soapEnvelope, soapBody, soapHeader, soapHeaderElement);
    }

    @Test
    public void testInboundSoapAttachment() throws TransformerException, IOException {
        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");

        SoapMessageConverter soapMessageConverter = new SoapMessageConverter();

        StringSource soapBodySource = new StringSource(responsePayload);

        Set<SoapHeaderElement> soapHeaders = new HashSet<SoapHeaderElement>();
        Set<Attachment> soapAttachments = new HashSet<Attachment>();
        soapAttachments.add(attachment);

        reset(soapResponse, soapEnvelope, soapBody, soapHeader);

        expect(soapResponse.getEnvelope()).andReturn(soapEnvelope).anyTimes();
        expect(soapResponse.getPayloadSource()).andReturn(soapBodySource).times(2);
        expect(soapResponse.getSoapHeader()).andReturn(soapHeader).anyTimes();
        expect(soapEnvelope.getHeader()).andReturn(soapHeader).anyTimes();
        expect(soapHeader.examineAllHeaderElements()).andReturn(soapHeaders.iterator()).once();
        expect(soapHeader.getSource()).andReturn(null).once();

        expect(soapResponse.getSoapAction()).andReturn("soapOperation").anyTimes();

        expect(soapResponse.getAttachments()).andReturn(soapAttachments.iterator()).once();

        replay(soapResponse, soapEnvelope, soapBody, soapHeader);

        Message responseMessage = soapMessageConverter.convertInbound(soapResponse, new WebServiceEndpointConfiguration());
        Assert.assertTrue(SoapMessage.class.isInstance(responseMessage));

        SoapMessage soapResponseMessage = (SoapMessage) responseMessage;
        Assert.assertEquals(soapResponseMessage.getPayload(), "<?xml version=\"1.0\" encoding=\"UTF-8\"?>" + responsePayload);
        Assert.assertEquals(soapResponseMessage.getSoapAction(), "soapOperation");
        Assert.assertEquals(soapResponseMessage.getHeaderData().size(), 0L);

        List<SoapAttachment> attachments = soapResponseMessage.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());

        verify(soapResponse, soapEnvelope, soapBody, soapHeader);
    }
View Full Code Here

        soapMessageAction.setEndpoint(webServiceEndpoint);

        PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();
        messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");

        SoapAttachment attachment = new SoapAttachment();
        attachment.setContent("<TestAttachment><Message>Hello World!</Message></TestAttachment>");
        soapMessageAction.setAttachments(Collections.singletonList(attachment));
       
        soapMessageAction.setMessageBuilder(messageBuilder);
       
        reset(webServiceEndpoint, producer);

        expect(webServiceEndpoint.createProducer()).andReturn(producer).once();
        producer.send(anyObject(Message.class), anyObject(TestContext.class));
        expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                Assert.assertEquals(((SoapMessage)EasyMock.getCurrentArguments()[0]).getAttachments().size(), 1L);
                SoapAttachment constructedAttachment = ((SoapMessage)EasyMock.getCurrentArguments()[0]).getAttachments().get(0);
                Assert.assertNull(constructedAttachment.getContentId());
                Assert.assertEquals(constructedAttachment.getContentType(), "text/plain");
                Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");
                Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-8");
               
                return null;
            }
        }).once();
       
View Full Code Here

        PayloadTemplateMessageBuilder messageBuilder = new PayloadTemplateMessageBuilder();
        messageBuilder.setPayloadData("<TestRequest><Message>Hello World!</Message></TestRequest>");
       
        soapMessageAction.setMessageBuilder(messageBuilder);

        SoapAttachment attachment = new SoapAttachment();
        attachment.setContentId("myAttachment");
        attachment.setContentType("text/xml");
        attachment.setContent("<TestAttachment><Message>Hello World!</Message></TestAttachment>");
        attachment.setCharsetName("UTF-16");
        soapMessageAction.setAttachments(Collections.singletonList(attachment));

        reset(webServiceEndpoint, producer);

        expect(webServiceEndpoint.createProducer()).andReturn(producer).once();
        producer.send(anyObject(Message.class), anyObject(TestContext.class));
        expectLastCall().andAnswer(new IAnswer<Object>() {
            public Object answer() throws Throwable {
                Assert.assertEquals(((SoapMessage)EasyMock.getCurrentArguments()[0]).getAttachments().size(), 1L);
                SoapAttachment constructedAttachment = ((SoapMessage)EasyMock.getCurrentArguments()[0]).getAttachments().get(0);
                Assert.assertEquals(constructedAttachment.getContentId(), "myAttachment");
                Assert.assertEquals(constructedAttachment.getContentType(), "text/xml");
                Assert.assertEquals(constructedAttachment.getContent(), "<TestAttachment><Message>Hello World!</Message></TestAttachment>");
                Assert.assertEquals(constructedAttachment.getCharsetName(), "UTF-16");
               
                return null;
            }
        }).once();
       
View Full Code Here

    /**
     * Parse the attachment element with all children and attributes.
     * @param attachmentElement
     */
    public static SoapAttachment parseAttachment(Element attachmentElement) {
        SoapAttachment soapAttachment = new SoapAttachment();

        if (attachmentElement.hasAttribute("content-id")) {
            soapAttachment.setContentId(attachmentElement.getAttribute("content-id"));
        }

        if (attachmentElement.hasAttribute("content-type")) {
            soapAttachment.setContentType(attachmentElement.getAttribute("content-type"));
        }

        if (attachmentElement.hasAttribute("charset-name")) {
            soapAttachment.setCharsetName(attachmentElement.getAttribute("charset-name"));
        }

        Element attachmentDataElement = DomUtils.getChildElementByTagName(attachmentElement, "data");
        if (attachmentDataElement != null) {
            soapAttachment.setContent(DomUtils.getTextValue(attachmentDataElement));
        }
       
        Element attachmentResourceElement = DomUtils.getChildElementByTagName(attachmentElement, "resource");
        if (attachmentResourceElement != null) {
            soapAttachment.setContentResourcePath(attachmentResourceElement.getAttribute("file"));
        }

        return soapAttachment;
    }
View Full Code Here

    @Override
    public void validateAttachment(SoapMessage soapMessage, List<SoapAttachment> controlAttachments) {
        log.info("Validating SOAP attachments ...");

        for (SoapAttachment controlAttachment : controlAttachments) {
            SoapAttachment attachment = findAttachment(soapMessage, controlAttachment);

            if (log.isDebugEnabled()) {
                log.debug("Found attachment with contentId '" + controlAttachment.getContentId() + "'");
            }
View Full Code Here

TOP

Related Classes of com.consol.citrus.ws.message.SoapAttachment

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.