Package org.springframework.ws.transport

Examples of org.springframework.ws.transport.WebServiceConnection


        boolean supported = false;
        for (WebServiceMessageSender messageSender : messageSenders) {
            if (messageSender.supports(replyEpr.getAddress())) {
                supported = true;
                WebServiceConnection connection = null;
                try {
                    connection = messageSender.createConnection(replyEpr.getAddress());
                    connection.send(messageContext.getResponse());
                    break;
                }
                finally {
                    messageContext.clearResponse();
                    if (connection != null) {
                        connection.close();
                    }
                }
            }
        }
        if (!supported && logger.isWarnEnabled()) {
View Full Code Here


        URI faultAction = new URI("urn:replyAction");
        interceptor =
                new AddressingEndpointInterceptor(getVersion(), strategyMock, new WebServiceMessageSender[]{senderMock},
                        replyAction, faultAction);

        WebServiceConnection connectionMock = createMock(WebServiceConnection.class);

        SaajSoapMessage valid = loadSaajMessage(getTestPath() + "/valid.xml");
        MessageContext context = new DefaultMessageContext(valid, new SaajSoapMessageFactory(messageFactory));
        SaajSoapMessage response = (SaajSoapMessage) context.getResponse();

        URI messageId = new URI("uid:1234");
        expect(strategyMock.newMessageId((SoapMessage) context.getResponse())).andReturn(messageId);

        URI uri = new URI("http://example.com/business/client1");
        expect(senderMock.supports(uri)).andReturn(true);
        expect(senderMock.createConnection(uri)).andReturn(connectionMock);
        connectionMock.send(response);
        connectionMock.close();

        replay(strategyMock, senderMock, connectionMock);

        boolean result = interceptor.handleResponse(context, null);
        assertFalse("Out of Band request handled", result);
View Full Code Here

        TransportContextHolder.setTransportContext(null);
    }

    @Test
    public void getLookupKeyForMessage() throws Exception {
        WebServiceConnection connectionMock = createMock(WebServiceConnection.class);
        TransportContextHolder.setTransportContext(new DefaultTransportContext(connectionMock));

        URI uri = new URI("jms://exampleQueue");
        expect(connectionMock.getUri()).andReturn(uri);

        replay(connectionMock);

        Assert.assertEquals("Invalid lookup key", uri.toString(), mapping.getLookupKeyForMessage(context));
View Full Code Here

    @Test
    public void getLookupKeyForMessagePath() throws Exception {
        mapping.setUsePath(true);

        WebServiceConnection connectionMock = createMock(WebServiceConnection.class);
        TransportContextHolder.setTransportContext(new DefaultTransportContext(connectionMock));

        URI uri = new URI("http://example.com/foo/bar");
        expect(connectionMock.getUri()).andReturn(uri);

        replay(connectionMock);

        Assert.assertEquals("Invalid lookup key", "/foo/bar", mapping.getLookupKeyForMessage(context));
View Full Code Here

    @Override
    protected String getLookupKeyForMessage(MessageContext messageContext) throws Exception {
        TransportContext transportContext = TransportContextHolder.getTransportContext();
        if (transportContext != null) {
            WebServiceConnection connection = transportContext.getConnection();
            if (connection != null) {
                URI connectionUri = connection.getUri();
                if (usePath) {
                    return connectionUri.getPath();
                }
                else {
                    return connectionUri.toString();
View Full Code Here

        Mailbox.clearAll();
    }

    @Test
    public void testSendAndReceiveQueueNoResponse() throws Exception {
        WebServiceConnection connection = null;
        try {
            URI mailTo = new URI("mailto:server@example.com?subject=SOAP%20Test");
            connection = messageSender.createConnection(mailTo);
            SOAPMessage saajMessage = messageFactory.createMessage();
            saajMessage.getSOAPBody().addBodyElement(new QName("http://springframework.org", "test"));
            SoapMessage soapRequest = new SaajSoapMessage(saajMessage);
            soapRequest.setSoapAction(SOAP_ACTION);
            connection.send(soapRequest);
            Assert.assertEquals("No mail message sent", 1, Mailbox.get("server@example.com").size());
        }
        finally {
            if (connection != null) {
                connection.close();
            }
        }
    }
View Full Code Here

        messageFactory = MessageFactory.newInstance(SOAPConstants.SOAP_1_1_PROTOCOL);
    }

    @Test
    public void testSendAndReceiveQueueBytesMessageTemporaryQueue() throws Exception {
        WebServiceConnection connection = null;
        try {
            URI uri = new URI("jms:SenderRequestQueue?deliveryMode=NON_PERSISTENT");
            connection = messageSender.createConnection(uri);
            SoapMessage soapRequest = new SaajSoapMessage(messageFactory.createMessage());
            soapRequest.setSoapAction(SOAP_ACTION);
            connection.send(soapRequest);

            BytesMessage request = (BytesMessage) jmsTemplate.receive();
            assertNotNull("No message received", request);
            assertTrue("No message content received", request.readByte() != -1);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            messageFactory.createMessage().writeTo(bos);
            final byte[] buf = bos.toByteArray();
            jmsTemplate.send(request.getJMSReplyTo(), new MessageCreator() {

                public Message createMessage(Session session) throws JMSException {
                    BytesMessage response = session.createBytesMessage();
                    response.setStringProperty(JmsTransportConstants.PROPERTY_SOAP_ACTION, SOAP_ACTION);
                    response.setStringProperty(JmsTransportConstants.PROPERTY_CONTENT_TYPE,
                            SoapVersion.SOAP_11.getContentType());
                    response.writeBytes(buf);
                    return response;
                }
            });
            SoapMessage response = (SoapMessage) connection.receive(new SaajSoapMessageFactory(messageFactory));
            assertNotNull("No response received", response);
            assertEquals("Invalid SOAPAction", SOAP_ACTION, response.getSoapAction());
            assertFalse("Message is fault", response.hasFault());
        }
        finally {
            if (connection != null) {
                connection.close();
            }
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testSendAndReceiveQueueBytesMessagePermanentQueue() throws Exception {
        WebServiceConnection connection = null;
        try {
            String responseQueueName = "SenderResponseQueue";
            URI uri = new URI(
                    "jms:SenderRequestQueue?replyToName=" + responseQueueName + "&deliveryMode=NON_PERSISTENT");
            connection = messageSender.createConnection(uri);
            SoapMessage soapRequest = new SaajSoapMessage(messageFactory.createMessage());
            soapRequest.setSoapAction(SOAP_ACTION);
            connection.send(soapRequest);

            final BytesMessage request = (BytesMessage) jmsTemplate.receive();
            assertNotNull("No message received", request);
            assertTrue("No message content received", request.readByte() != -1);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            messageFactory.createMessage().writeTo(bos);
            final byte[] buf = bos.toByteArray();
            jmsTemplate.send(responseQueueName, new MessageCreator() {

                public Message createMessage(Session session) throws JMSException {
                    BytesMessage response = session.createBytesMessage();
                    response.setJMSCorrelationID(request.getJMSMessageID());
                    response.setStringProperty(JmsTransportConstants.PROPERTY_SOAP_ACTION, SOAP_ACTION);
                    response.setStringProperty(JmsTransportConstants.PROPERTY_CONTENT_TYPE,
                            SoapVersion.SOAP_11.getContentType());
                    response.writeBytes(buf);
                    return response;
                }
            });
            SoapMessage response = (SoapMessage) connection.receive(new SaajSoapMessageFactory(messageFactory));
            assertNotNull("No response received", response);
            assertEquals("Invalid SOAPAction", SOAP_ACTION, response.getSoapAction());
            assertFalse("Message is fault", response.hasFault());
        }
        finally {
            if (connection != null) {
                connection.close();
            }
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testSendAndReceiveQueueTextMessage() throws Exception {
        WebServiceConnection connection = null;
        try {
            URI uri = new URI("jms:SenderRequestQueue?deliveryMode=NON_PERSISTENT&messageType=TEXT_MESSAGE");
            connection = messageSender.createConnection(uri);
            SoapMessage soapRequest = new SaajSoapMessage(messageFactory.createMessage());
            soapRequest.setSoapAction(SOAP_ACTION);
            connection.send(soapRequest);

            TextMessage request = (TextMessage) jmsTemplate.receive();
            assertNotNull("No message received", request);
            assertNotNull("No message content received", request.getText());
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            messageFactory.createMessage().writeTo(bos);
            final String text = new String(bos.toByteArray(), "UTF-8");
            jmsTemplate.send(request.getJMSReplyTo(), new MessageCreator() {

                public Message createMessage(Session session) throws JMSException {
                    TextMessage response = session.createTextMessage();
                    response.setStringProperty(JmsTransportConstants.PROPERTY_SOAP_ACTION, SOAP_ACTION);
                    response.setStringProperty(JmsTransportConstants.PROPERTY_CONTENT_TYPE,
                            SoapVersion.SOAP_11.getContentType());
                    response.setText(text);
                    return response;
                }
            });
            SoapMessage response = (SoapMessage) connection.receive(new SaajSoapMessageFactory(messageFactory));
            assertNotNull("No response received", response);
            assertEquals("Invalid SOAPAction", SOAP_ACTION, response.getSoapAction());
            assertFalse("Message is fault", response.hasFault());
        }
        finally {
            if (connection != null) {
                connection.close();
            }
        }
    }
View Full Code Here

        }
    }

    @Test
    public void testSendNoResponse() throws Exception {
        WebServiceConnection connection = null;
        try {
            URI uri = new URI("jms:SenderRequestQueue?deliveryMode=NON_PERSISTENT");
            connection = messageSender.createConnection(uri);
            SoapMessage soapRequest = new SaajSoapMessage(messageFactory.createMessage());
            soapRequest.setSoapAction(SOAP_ACTION);
            connection.send(soapRequest);

            BytesMessage request = (BytesMessage) jmsTemplate.receive();
            assertNotNull("No message received", request);
            ByteArrayOutputStream bos = new ByteArrayOutputStream();
            messageFactory.createMessage().writeTo(bos);
            SoapMessage response = (SoapMessage) connection.receive(new SaajSoapMessageFactory(messageFactory));
            assertNull("Response received", response);
        }
        finally {
            if (connection != null) {
                connection.close();
            }
        }
    }
View Full Code Here

TOP

Related Classes of org.springframework.ws.transport.WebServiceConnection

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.