Package com.consol.citrus.message

Examples of com.consol.citrus.message.Message


        VertxSingleMessageHandler vertxMessageHandler = new VertxSingleMessageHandler();
        vertx.eventBus().registerHandler(endpointConfiguration.getAddress(), vertxMessageHandler);

        long timeLeft = timeout;
        Message message = endpointConfiguration.getMessageConverter().convertInbound(vertxMessageHandler.getMessage(), endpointConfiguration);

        while (message == null && timeLeft > 0) {
            timeLeft -= endpointConfiguration.getPollingInterval();

            if (RETRY_LOG.isDebugEnabled()) {
View Full Code Here


   
    @Test
    public void testMessageProcessing() throws Exception {
        WebServiceEndpoint endpoint = new WebServiceEndpoint();

        final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>");

        final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>");

        endpoint.setEndpointAdapter(new StaticEndpointAdapter() {
            public Message handleMessageInternal(Message message) {
                Assert.assertEquals(message.copyHeaders().size(), requestMessage.copyHeaders().size());
                Assert.assertEquals(message.getPayload(), requestMessage.getPayload());

                return responseMessage;
            }
        });

        org.springframework.ws.soap.SoapMessage soapRequest = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
        SoapHeader soapRequestHeader = EasyMock.createMock(SoapHeader.class);

        org.springframework.ws.soap.SoapMessage soapResponse = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
       
        StringResult soapResponsePayload = new StringResult();
       
        reset(messageContext, soapRequest, soapRequestHeader, soapResponse);
       
        expect(messageContext.getRequest()).andReturn(soapRequest).anyTimes();
       
        expect(soapRequest.getPayloadSource()).andReturn(new StringSource("<TestRequest><Message>Hello World!</Message></TestRequest>")).times(2);
       
        expect(messageContext.getPropertyNames()).andReturn(new String[]{}).once();
       
        expect(soapRequest.getSoapHeader()).andReturn(soapRequestHeader).once();
        expect(soapRequestHeader.getSource()).andReturn(null).once();
       
        Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();
        expect(soapRequestHeader.examineAllHeaderElements()).andReturn(emptyHeaderSet.iterator()).once();
       
        expect(soapRequest.getSoapAction()).andReturn(null).anyTimes();
       
        Set<Attachment> emptyAttachmentSet = Collections.emptySet();
        expect(soapRequest.getAttachments()).andReturn(emptyAttachmentSet.iterator()).once();
       
        expect(messageContext.getResponse()).andReturn(soapResponse).once();

        expect(soapResponse.getPayloadResult()).andReturn(soapResponsePayload).once();
       
        replay(messageContext, soapRequest, soapRequestHeader, soapResponse);
       
        endpoint.invoke(messageContext);
       
        Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());
       
        verify(messageContext, soapRequest, soapRequestHeader, soapResponse);
    }
View Full Code Here

    public void testMessageProcessingWithSoapAction() throws Exception {
        WebServiceEndpoint endpoint = new WebServiceEndpoint();

        Map<String, Object> requestHeaders = new HashMap<String, Object>();
        requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");
        final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);

        final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>");

        endpoint.setEndpointAdapter(new StaticEndpointAdapter() {
            public Message handleMessageInternal(Message message) {
                Assert.assertEquals(message.copyHeaders().size(), requestMessage.copyHeaders().size());

                Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));
                Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");

                Assert.assertEquals(message.getPayload(), requestMessage.getPayload());

                return responseMessage;
            }
        });

        org.springframework.ws.soap.SoapMessage soapRequest = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
        SoapHeader soapRequestHeader = EasyMock.createMock(SoapHeader.class);

        org.springframework.ws.soap.SoapMessage soapResponse = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
       
        StringResult soapResponsePayload = new StringResult();
       
        reset(messageContext, soapRequest, soapRequestHeader, soapResponse);
       
        expect(messageContext.getRequest()).andReturn(soapRequest).anyTimes();
       
        expect(soapRequest.getPayloadSource()).andReturn(new StringSource("<TestRequest><Message>Hello World!</Message></TestRequest>")).times(2);
       
        expect(messageContext.getPropertyNames()).andReturn(new String[]{}).once();
       
        expect(soapRequest.getSoapHeader()).andReturn(soapRequestHeader).once();
        expect(soapRequestHeader.getSource()).andReturn(null).once();
       
        Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();
        expect(soapRequestHeader.examineAllHeaderElements()).andReturn(emptyHeaderSet.iterator()).once();
       
        expect(soapRequest.getSoapAction()).andReturn("sayHello").anyTimes();
       
        Set<Attachment> emptyAttachmentSet = Collections.emptySet();
        expect(soapRequest.getAttachments()).andReturn(emptyAttachmentSet.iterator()).once();
       
        expect(messageContext.getResponse()).andReturn(soapResponse).once();

        expect(soapResponse.getPayloadResult()).andReturn(soapResponsePayload).once();
       
        replay(messageContext, soapRequest, soapRequestHeader, soapResponse);
       
        endpoint.invoke(messageContext);
       
        Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());
       
        verify(messageContext, soapRequest, soapRequestHeader, soapResponse);
    }
View Full Code Here

        WebServiceEndpoint endpoint = new WebServiceEndpoint();

        Map<String, Object> requestHeaders = new HashMap<String, Object>();
        requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");
        requestHeaders.put("Operation", "sayHello");
        final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);

        final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>");

        endpoint.setEndpointAdapter(new StaticEndpointAdapter() {
            public Message handleMessageInternal(Message message) {
                Assert.assertEquals(message.copyHeaders().size(), requestMessage.copyHeaders().size());

                Assert.assertNotNull(message.getHeader("Operation"));
                Assert.assertEquals(message.getHeader("Operation"), "sayHello");

                Assert.assertEquals(message.getPayload(), requestMessage.getPayload());

                return responseMessage;
            }
        });

        org.springframework.ws.soap.SoapMessage soapRequest = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
        SoapHeader soapRequestHeader = EasyMock.createMock(SoapHeader.class);
        Set<SoapHeaderElement> soapRequestHeaders = new HashSet<SoapHeaderElement>();
        SoapHeaderElement soapRequestHeaderEntry = EasyMock.createMock(SoapHeaderElement.class);
        soapRequestHeaders.add(soapRequestHeaderEntry);

        org.springframework.ws.soap.SoapMessage soapResponse = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
       
        StringResult soapResponsePayload = new StringResult();
       
        reset(messageContext, soapRequest, soapRequestHeader, soapRequestHeaderEntry, soapResponse);
       
        expect(messageContext.getRequest()).andReturn(soapRequest).anyTimes();
       
        expect(soapRequest.getPayloadSource()).andReturn(new StringSource("<TestRequest><Message>Hello World!</Message></TestRequest>")).times(2);
       
        expect(messageContext.getPropertyNames()).andReturn(new String[]{}).once();
       
        expect(soapRequest.getSoapHeader()).andReturn(soapRequestHeader).once();
        expect(soapRequestHeader.getSource()).andReturn(null).once();
       
        expect(soapRequestHeader.examineAllHeaderElements()).andReturn(soapRequestHeaders.iterator()).once();
       
        expect(soapRequestHeaderEntry.getName()).andReturn(QNameUtils.createQName("http://www.consol.de/citrus", "Operation", "citrus")).once();
        expect(soapRequestHeaderEntry.getText()).andReturn("sayHello").once();
       
        expect(soapRequest.getSoapAction()).andReturn("sayHello").anyTimes();
       
        Set<Attachment> emptyAttachmentSet = Collections.emptySet();
        expect(soapRequest.getAttachments()).andReturn(emptyAttachmentSet.iterator()).once();
       
        expect(messageContext.getResponse()).andReturn(soapResponse).once();

        expect(soapResponse.getPayloadResult()).andReturn(soapResponsePayload).once();
       
        replay(messageContext, soapRequest, soapRequestHeader, soapRequestHeaderEntry, soapResponse);
       
        endpoint.invoke(messageContext);
       
        Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());
       
        verify(messageContext, soapRequest, soapRequestHeader, soapRequestHeaderEntry, soapResponse);
    }
View Full Code Here

        requestHeaders.put("Host", "localhost:8080");
        requestHeaders.put("Content-Length", "236");
        requestHeaders.put("Accept", "text/xml, text/html, image/gif, image/jpeg");
        requestHeaders.put("Content-Type", "text/xml");
       
        final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);

        final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>");

        endpoint.setEndpointAdapter(new StaticEndpointAdapter() {
            public Message handleMessageInternal(Message message) {
                Assert.assertEquals(message.copyHeaders().size(), requestMessage.copyHeaders().size());

                Assert.assertNotNull(message.getHeader("Operation"));
                Assert.assertEquals(message.getHeader("Operation"), "sayHello");

                Assert.assertEquals(message.getPayload(), requestMessage.getPayload());

                return responseMessage;
            }
        });
       
        SaajSoapMessage soapRequest = EasyMock.createMock(SaajSoapMessage.class);
        SoapHeader soapRequestHeader = EasyMock.createMock(SoapHeader.class);
        SoapBody soapRequestBody = EasyMock.createMock(SoapBody.class);
        SoapEnvelope soapRequestEnvelope = EasyMock.createMock(SoapEnvelope.class);
       
        SOAPMessage soapRequestMessage = EasyMock.createMock(SOAPMessage.class);
        MimeHeaders mimeHeaders = new MimeHeaders();
        mimeHeaders.addHeader("Host", "localhost:8080");
        mimeHeaders.addHeader("Content-Length", "236");
        mimeHeaders.addHeader("Accept", "text/xml");
        mimeHeaders.addHeader("Accept", "text/html");
        mimeHeaders.addHeader("Accept", "image/gif");
        mimeHeaders.addHeader("Accept", "image/jpeg");
        mimeHeaders.addHeader("Content-Type", "text/xml");
       
        Set<SoapHeaderElement> soapRequestHeaders = new HashSet<SoapHeaderElement>();
        SoapHeaderElement soapRequestHeaderEntry = EasyMock.createMock(SoapHeaderElement.class);
        soapRequestHeaders.add(soapRequestHeaderEntry);

        org.springframework.ws.soap.SoapMessage soapResponse = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
       
        StringResult soapResponsePayload = new StringResult();
       
        reset(messageContext, soapRequestEnvelope, soapRequestHeader, soapRequestBody, soapRequestHeaderEntry, soapResponse, soapRequest, soapRequestMessage);

        expect(soapRequest.getEnvelope()).andReturn(soapRequestEnvelope).times(3);
        expect(soapRequest.getSoapAction()).andReturn("sayHello").anyTimes();
        Set<Attachment> emptyAttachmentSet = Collections.emptySet();
        expect(soapRequest.getAttachments()).andReturn(emptyAttachmentSet.iterator()).once();
       
        expect(soapRequest.getSaajMessage()).andReturn(soapRequestMessage).once();
        expect(soapRequestMessage.getMimeHeaders()).andReturn(mimeHeaders).once();
       
        expect(messageContext.getRequest()).andReturn(soapRequest).anyTimes();

        expect(soapRequestEnvelope.getBody()).andReturn(soapRequestBody).times(2);
        expect(soapRequestBody.getPayloadSource()).andReturn(new StringSource("<TestRequest><Message>Hello World!</Message></TestRequest>")).times(2);
       
        expect(soapRequestEnvelope.getHeader()).andReturn(soapRequestHeader).once();
        expect(soapRequestHeader.getSource()).andReturn(null).once();
       
        expect(messageContext.getPropertyNames()).andReturn(new String[]{}).once();
       
        expect(soapRequestHeader.examineAllHeaderElements()).andReturn(soapRequestHeaders.iterator()).once();
       
        expect(soapRequestHeaderEntry.getName()).andReturn(QNameUtils.createQName("http://www.consol.de/citrus", "Operation", "citrus")).once();
        expect(soapRequestHeaderEntry.getText()).andReturn("sayHello").once();
       
        expect(messageContext.getResponse()).andReturn(soapResponse).once();

        expect(soapResponse.getPayloadResult()).andReturn(soapResponsePayload).once();
       
        replay(messageContext, soapRequestEnvelope, soapRequestHeader, soapRequestBody, soapRequestHeaderEntry, soapResponse, soapRequest, soapRequestMessage);
       
        endpoint.invoke(messageContext);
       
        Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());
       
        verify(messageContext, soapRequestEnvelope, soapRequestHeader, soapRequestBody, soapRequestHeaderEntry, soapResponse, soapRequest, soapRequestMessage);
    }
View Full Code Here

    public void testMessageProcessingWithSoapResponseHeaders() throws Exception {
        WebServiceEndpoint endpoint = new WebServiceEndpoint();

        Map<String, Object> requestHeaders = new HashMap<String, Object>();
        requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");
        final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);

        Map<String, Object> responseHeaders = new HashMap<String, Object>();
        responseHeaders.put("{http://www.consol.de/citrus}citrus:Operation", "sayHello");
        final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>", responseHeaders);

        endpoint.setEndpointAdapter(new StaticEndpointAdapter() {
            public Message handleMessageInternal(Message message) {
                Assert.assertEquals(message.copyHeaders().size(), requestMessage.copyHeaders().size());

                Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));
                Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");

                Assert.assertEquals(message.getPayload(), requestMessage.getPayload());

                return responseMessage;
            }
        });

        org.springframework.ws.soap.SoapMessage soapRequest = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
        SoapHeader soapRequestHeader = EasyMock.createMock(SoapHeader.class);

        org.springframework.ws.soap.SoapMessage soapResponse = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
        SoapHeader soapResponseHeader = EasyMock.createMock(SoapHeader.class);
       
        final SoapHeaderElement soapRequestHeaderEntry = EasyMock.createMock(SoapHeaderElement.class);
       
        StringResult soapResponsePayload = new StringResult();
       
        reset(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);
       
        expect(messageContext.getRequest()).andReturn(soapRequest).anyTimes();
       
        expect(soapRequest.getPayloadSource()).andReturn(new StringSource("<TestRequest><Message>Hello World!</Message></TestRequest>")).times(2);
       
        expect(messageContext.getPropertyNames()).andReturn(new String[]{}).once();
       
        expect(soapRequest.getSoapHeader()).andReturn(soapRequestHeader).once();
        expect(soapRequestHeader.getSource()).andReturn(null).once();
       
        Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();
        expect(soapRequestHeader.examineAllHeaderElements()).andReturn(emptyHeaderSet.iterator()).once();
       
        expect(soapRequest.getSoapAction()).andReturn("sayHello").anyTimes();
       
        Set<Attachment> emptyAttachmentSet = Collections.emptySet();
        expect(soapRequest.getAttachments()).andReturn(emptyAttachmentSet.iterator()).once();
       
        expect(messageContext.getResponse()).andReturn(soapResponse).once();

        expect(soapResponse.getPayloadResult()).andReturn(soapResponsePayload).once();
       
        expect(soapResponse.getSoapHeader()).andReturn(soapResponseHeader).anyTimes();
       
        expect(soapResponseHeader.addHeaderElement((QName)anyObject())).andAnswer(new IAnswer<SoapHeaderElement>() {
            public SoapHeaderElement answer() throws Throwable {
                QName headerQName = (QName)EasyMock.getCurrentArguments()[0];
               
                Assert.assertEquals(headerQName.getLocalPart(), "Operation");
                Assert.assertEquals(headerQName.getPrefix(), "citrus");
                Assert.assertEquals(headerQName.getNamespaceURI(), "http://www.consol.de/citrus");
                return soapRequestHeaderEntry;
            }
        }).once();
       
        soapRequestHeaderEntry.setText("sayHello");
        expectLastCall().once();
       
        replay(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);
       
        endpoint.invoke(messageContext);
       
        Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());
       
        verify(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);
    }
View Full Code Here

    public void testMessageProcessingWithDefaultHeaderQName() throws Exception {
        WebServiceEndpoint endpoint = new WebServiceEndpoint();

        Map<String, Object> requestHeaders = new HashMap<String, Object>();
        requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");
        final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);

        Map<String, Object> responseHeaders = new HashMap<String, Object>();
        responseHeaders.put("Operation", "sayHello");
        final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>", responseHeaders);

        endpoint.setEndpointAdapter(new StaticEndpointAdapter() {
            public Message handleMessageInternal(Message message) {
                Assert.assertEquals(message.copyHeaders().size(), requestMessage.copyHeaders().size());

                Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));
                Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");

                Assert.assertEquals(message.getPayload(), requestMessage.getPayload());

                return responseMessage;
            }
        });

        endpoint.setDefaultNamespaceUri("http://www.consol.de/citrus");
        endpoint.setDefaultPrefix("citrus");

        org.springframework.ws.soap.SoapMessage soapRequest = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
        SoapHeader soapRequestHeader = EasyMock.createMock(SoapHeader.class);

        org.springframework.ws.soap.SoapMessage soapResponse = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
        SoapHeader soapResponseHeader = EasyMock.createMock(SoapHeader.class);
       
        final SoapHeaderElement soapRequestHeaderEntry = EasyMock.createMock(SoapHeaderElement.class);
       
        StringResult soapResponsePayload = new StringResult();
       
        reset(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);
       
        expect(messageContext.getRequest()).andReturn(soapRequest).anyTimes();
       
        expect(soapRequest.getPayloadSource()).andReturn(new StringSource("<TestRequest><Message>Hello World!</Message></TestRequest>")).times(2);
       
        expect(messageContext.getPropertyNames()).andReturn(new String[]{}).once();
       
        expect(soapRequest.getSoapHeader()).andReturn(soapRequestHeader).once();
        expect(soapRequestHeader.getSource()).andReturn(null).once();
       
        Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();
        expect(soapRequestHeader.examineAllHeaderElements()).andReturn(emptyHeaderSet.iterator()).once();
       
        expect(soapRequest.getSoapAction()).andReturn("sayHello").anyTimes();
       
        Set<Attachment> emptyAttachmentSet = Collections.emptySet();
        expect(soapRequest.getAttachments()).andReturn(emptyAttachmentSet.iterator()).once();
       
        expect(messageContext.getResponse()).andReturn(soapResponse).once();

        expect(soapResponse.getPayloadResult()).andReturn(soapResponsePayload).once();
       
        expect(soapResponse.getSoapHeader()).andReturn(soapResponseHeader).anyTimes();
       
        expect(soapResponseHeader.addHeaderElement((QName)anyObject())).andAnswer(new IAnswer<SoapHeaderElement>() {
            public SoapHeaderElement answer() throws Throwable {
                QName headerQName = (QName)EasyMock.getCurrentArguments()[0];
               
                Assert.assertEquals(headerQName.getLocalPart(), "Operation");
                Assert.assertEquals(headerQName.getPrefix(), "citrus");
                Assert.assertEquals(headerQName.getNamespaceURI(), "http://www.consol.de/citrus");
                return soapRequestHeaderEntry;
            }
        }).once();
       
        soapRequestHeaderEntry.setText("sayHello");
        expectLastCall().once();
       
        replay(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);
       
        endpoint.invoke(messageContext);
       
        Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());
       
        verify(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);
    }
View Full Code Here

        String queryParams = pathHelper.getOriginatingQueryString(servletRequest);
        request.setQueryParams(queryParams != null ? queryParams : "");

        request.setRequestMethod(method);

        Message response = endpointAdapter.handleMessage(request);
        if (response == null) {
            responseCache = new ResponseEntity(HttpStatus.OK);
        } else {
            HttpMessage httpResponse;
            if (response instanceof HttpMessage) {
View Full Code Here

    public void testMessageProcessingWithDefaultHeaderQNameNoPrefix() throws Exception {
        WebServiceEndpoint endpoint = new WebServiceEndpoint();

        Map<String, Object> requestHeaders = new HashMap<String, Object>();
        requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");
        final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);

        Map<String, Object> responseHeaders = new HashMap<String, Object>();
        responseHeaders.put("Operation", "sayHello");
        final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>", responseHeaders);

        endpoint.setEndpointAdapter(new StaticEndpointAdapter() {
            public Message handleMessageInternal(Message message) {
                Assert.assertEquals(message.copyHeaders().size(), requestMessage.copyHeaders().size());

                Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));
                Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");

                Assert.assertEquals(message.getPayload(), requestMessage.getPayload());

                return responseMessage;
            }
        });

        endpoint.setDefaultNamespaceUri("http://www.consol.de/citrus");

        org.springframework.ws.soap.SoapMessage soapRequest = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
        SoapHeader soapRequestHeader = EasyMock.createMock(SoapHeader.class);

        org.springframework.ws.soap.SoapMessage soapResponse = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
        SoapHeader soapResponseHeader = EasyMock.createMock(SoapHeader.class);
       
        final SoapHeaderElement soapRequestHeaderEntry = EasyMock.createMock(SoapHeaderElement.class);
       
        StringResult soapResponsePayload = new StringResult();
       
        reset(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);
       
        expect(messageContext.getRequest()).andReturn(soapRequest).anyTimes();
       
        expect(soapRequest.getPayloadSource()).andReturn(new StringSource("<TestRequest><Message>Hello World!</Message></TestRequest>")).times(2);
       
        expect(messageContext.getPropertyNames()).andReturn(new String[]{}).once();
       
        expect(soapRequest.getSoapHeader()).andReturn(soapRequestHeader).once();
        expect(soapRequestHeader.getSource()).andReturn(null).once();
       
        Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();
        expect(soapRequestHeader.examineAllHeaderElements()).andReturn(emptyHeaderSet.iterator()).once();
       
        expect(soapRequest.getSoapAction()).andReturn("sayHello").anyTimes();
       
        Set<Attachment> emptyAttachmentSet = Collections.emptySet();
        expect(soapRequest.getAttachments()).andReturn(emptyAttachmentSet.iterator()).once();
       
        expect(messageContext.getResponse()).andReturn(soapResponse).once();

        expect(soapResponse.getPayloadResult()).andReturn(soapResponsePayload).once();
       
        expect(soapResponse.getSoapHeader()).andReturn(soapResponseHeader).anyTimes();
       
        expect(soapResponseHeader.addHeaderElement((QName)anyObject())).andAnswer(new IAnswer<SoapHeaderElement>() {
            public SoapHeaderElement answer() throws Throwable {
                QName headerQName = (QName)EasyMock.getCurrentArguments()[0];
               
                Assert.assertEquals(headerQName.getLocalPart(), "Operation");
                Assert.assertEquals(headerQName.getPrefix(), "");
                Assert.assertEquals(headerQName.getNamespaceURI(), "http://www.consol.de/citrus");
                return soapRequestHeaderEntry;
            }
        }).once();
       
        soapRequestHeaderEntry.setText("sayHello");
        expectLastCall().once();
       
        replay(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);
       
        endpoint.invoke(messageContext);
       
        Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());
       
        verify(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);
    }
View Full Code Here

    public void testMessageProcessingMissingNamespaceUri() throws Exception {
        WebServiceEndpoint endpoint = new WebServiceEndpoint();

        Map<String, Object> requestHeaders = new HashMap<String, Object>();
        requestHeaders.put(SoapMessageHeaders.SOAP_ACTION, "sayHello");
        final Message requestMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestRequest><Message>Hello World!</Message></TestRequest>", requestHeaders);

        Map<String, Object> responseHeaders = new HashMap<String, Object>();
        responseHeaders.put("Operation", "sayHello");
        final Message responseMessage = new DefaultMessage("<?xml version=\"1.0\" encoding=\"UTF-8\"?><TestResponse><Message>Hello World!</Message></TestResponse>", responseHeaders);

        endpoint.setEndpointAdapter(new StaticEndpointAdapter() {
            public Message handleMessageInternal(Message message) {
                Assert.assertEquals(message.copyHeaders().size(), requestMessage.copyHeaders().size());

                Assert.assertNotNull(message.getHeader(SoapMessageHeaders.SOAP_ACTION));
                Assert.assertEquals(message.getHeader(SoapMessageHeaders.SOAP_ACTION), "sayHello");

                Assert.assertEquals(message.getPayload(), requestMessage.getPayload());

                return responseMessage;
            }
        });

        org.springframework.ws.soap.SoapMessage soapRequest = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
        SoapHeader soapRequestHeader = EasyMock.createMock(SoapHeader.class);

        org.springframework.ws.soap.SoapMessage soapResponse = EasyMock.createMock(org.springframework.ws.soap.SoapMessage.class);
        SoapHeader soapResponseHeader = EasyMock.createMock(SoapHeader.class);
       
        final SoapHeaderElement soapRequestHeaderEntry = EasyMock.createMock(SoapHeaderElement.class);
       
        StringResult soapResponsePayload = new StringResult();
       
        reset(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);
       
        expect(messageContext.getRequest()).andReturn(soapRequest).anyTimes();
       
        expect(soapRequest.getPayloadSource()).andReturn(new StringSource("<TestRequest><Message>Hello World!</Message></TestRequest>")).times(2);
       
        expect(messageContext.getPropertyNames()).andReturn(new String[]{}).once();
       
        expect(soapRequest.getSoapHeader()).andReturn(soapRequestHeader).once();
        expect(soapRequestHeader.getSource()).andReturn(null).once();
       
        Set<SoapHeaderElement> emptyHeaderSet = Collections.emptySet();
        expect(soapRequestHeader.examineAllHeaderElements()).andReturn(emptyHeaderSet.iterator()).once();
       
        expect(soapRequest.getSoapAction()).andReturn("sayHello").anyTimes();
       
        Set<Attachment> emptyAttachmentSet = Collections.emptySet();
        expect(soapRequest.getAttachments()).andReturn(emptyAttachmentSet.iterator()).once();
       
        expect(messageContext.getResponse()).andReturn(soapResponse).once();

        expect(soapResponse.getPayloadResult()).andReturn(soapResponsePayload).once();
       
        expect(soapResponse.getSoapHeader()).andReturn(soapResponseHeader).anyTimes();
       
        expect(soapResponseHeader.addHeaderElement((QName)anyObject())).andAnswer(new IAnswer<SoapHeaderElement>() {
            public SoapHeaderElement answer() throws Throwable {
                QName headerQName = (QName)EasyMock.getCurrentArguments()[0];
               
                Assert.assertEquals(headerQName.getLocalPart(), "Operation");
                Assert.assertEquals(headerQName.getPrefix(), "");
                Assert.assertEquals(headerQName.getNamespaceURI(), "");
                return soapRequestHeaderEntry;
            }
        }).once();
       
        soapRequestHeaderEntry.setText("sayHello");
        expectLastCall().once();
       
        replay(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);
       
        endpoint.invoke(messageContext);
       
        Assert.assertEquals(soapResponsePayload.toString(), responseMessage.getPayload());
       
        verify(messageContext, soapRequest, soapRequestHeader, soapResponse, soapResponseHeader);
    }
View Full Code Here

TOP

Related Classes of com.consol.citrus.message.Message

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.