Search in sources :

Example 1 with WebServiceIOException

use of org.springframework.ws.client.WebServiceIOException in project spring-integration by spring-projects.

the class UriVariableTests method testInt2720JmsUriVariables.

@Test
public void testInt2720JmsUriVariables() throws JMSException, IOException {
    final String destinationName = "SPRING.INTEGRATION.QUEUE";
    Queue queue = Mockito.mock(Queue.class);
    // Need for 'QueueSession#createQueue()'
    Mockito.when(queue.getQueueName()).thenReturn(destinationName);
    Session session = Mockito.mock(Session.class);
    Mockito.when(session.createQueue(Mockito.anyString())).thenReturn(queue);
    Mockito.when(session.createBytesMessage()).thenReturn(Mockito.mock(BytesMessage.class));
    MessageProducer producer = Mockito.mock(MessageProducer.class);
    Mockito.when(session.createProducer(queue)).thenReturn(producer);
    // For this test it's enough to not go ahead. Invoked in the 'JmsSenderConnection#onSendAfterWrite' on the
    // 'WebServiceTemplate#sendRequest' after invocation of our 'TestClientInterceptor'
    Mockito.when(session.createTemporaryQueue()).thenThrow(new WebServiceIOException("intentional"));
    Connection connection = Mockito.mock(Connection.class);
    Mockito.when(connection.createSession(Mockito.anyBoolean(), Mockito.anyInt())).thenReturn(session);
    Mockito.when(this.jmsConnectionFactory.createConnection()).thenReturn(connection);
    Message<?> message = MessageBuilder.withPayload("<spring/>").setHeader("jmsQueue", destinationName).setHeader("deliveryMode", "NON_PERSISTENT").setHeader("jms_priority", "5").build();
    try {
        this.inputJms.send(message);
    } catch (MessageHandlingException e) {
        // expected
        Class<?> causeType = e.getCause().getClass();
        // offline
        assertTrue(WebServiceIOException.class.equals(causeType));
    }
    URI uri = URI.create("jms:SPRING.INTEGRATION.QUEUE?deliveryMode=NON_PERSISTENT&priority=5");
    Mockito.verify(this.jmsMessageSender).createConnection(uri);
    Mockito.verify(session).createQueue(destinationName);
    assertEquals("jms:" + destinationName, this.interceptor.getLastUri().toString());
    Mockito.verify(producer).setDeliveryMode(DeliveryMode.NON_PERSISTENT);
    Mockito.verify(producer).setPriority(5);
}
Also used : WebServiceConnection(org.springframework.ws.transport.WebServiceConnection) XMPPConnection(org.jivesoftware.smack.XMPPConnection) Connection(javax.jms.Connection) MailSenderConnection(org.springframework.ws.transport.mail.MailSenderConnection) BytesMessage(javax.jms.BytesMessage) MessageProducer(javax.jms.MessageProducer) WebServiceIOException(org.springframework.ws.client.WebServiceIOException) Queue(javax.jms.Queue) URI(java.net.URI) MessageHandlingException(org.springframework.messaging.MessageHandlingException) Session(javax.jms.Session) Test(org.junit.Test)

Example 2 with WebServiceIOException

use of org.springframework.ws.client.WebServiceIOException in project spring-integration by spring-projects.

the class UriVariableTests method testHttpUriVariables.

@Test
@SuppressWarnings("unchecked")
public void testHttpUriVariables() {
    WebServiceTemplate webServiceTemplate = TestUtils.getPropertyValue(this.httpOutboundGateway, "webServiceTemplate", WebServiceTemplate.class);
    webServiceTemplate = Mockito.spy(webServiceTemplate);
    final AtomicReference<String> uri = new AtomicReference<>();
    doAnswer(invocation -> {
        uri.set(invocation.getArgument(0));
        throw new WebServiceIOException("intentional");
    }).when(webServiceTemplate).sendAndReceive(Mockito.anyString(), Mockito.any(WebServiceMessageCallback.class), (WebServiceMessageExtractor<Object>) Mockito.any(WebServiceMessageExtractor.class));
    new DirectFieldAccessor(this.httpOutboundGateway).setPropertyValue("webServiceTemplate", webServiceTemplate);
    Message<?> message = MessageBuilder.withPayload("<spring/>").setHeader("x", "integration").setHeader("param", "test1 & test2").build();
    try {
        this.inputHttp.send(message);
    } catch (MessageHandlingException e) {
        // expected
        // offline
        assertThat(e.getCause(), Matchers.is(Matchers.instanceOf(WebServiceIOException.class)));
    }
    assertEquals("http://localhost/spring-integration?param=test1%20&%20test2", uri.get());
}
Also used : WebServiceMessageCallback(org.springframework.ws.client.core.WebServiceMessageCallback) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) AtomicReference(java.util.concurrent.atomic.AtomicReference) WebServiceIOException(org.springframework.ws.client.WebServiceIOException) WebServiceTemplate(org.springframework.ws.client.core.WebServiceTemplate) MessageHandlingException(org.springframework.messaging.MessageHandlingException) Test(org.junit.Test)

Example 3 with WebServiceIOException

use of org.springframework.ws.client.WebServiceIOException in project spring-integration by spring-projects.

the class UriVariableTests method testInt2720XmppUriVariables.

@Test
public void testInt2720XmppUriVariables() throws Exception {
    willThrow(new WebServiceIOException("intentional")).given(this.xmppConnection).sendStanza(Mockito.any(Stanza.class));
    Message<?> message = MessageBuilder.withPayload("<spring/>").setHeader("to", "user").build();
    try {
        this.inputXmpp.send(message);
    } catch (MessageHandlingException e) {
        // expected
        Class<?> causeType = e.getCause().getClass();
        // offline
        assertTrue(WebServiceIOException.class.equals(causeType));
    }
    ArgumentCaptor<Stanza> argument = ArgumentCaptor.forClass(Stanza.class);
    Mockito.verify(this.xmppConnection).sendStanza(argument.capture());
    assertEquals("user@jabber.org", argument.getValue().getTo().toString());
    assertEquals("xmpp:user@jabber.org", this.interceptor.getLastUri().toString());
}
Also used : Stanza(org.jivesoftware.smack.packet.Stanza) WebServiceIOException(org.springframework.ws.client.WebServiceIOException) MessageHandlingException(org.springframework.messaging.MessageHandlingException) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)3 MessageHandlingException (org.springframework.messaging.MessageHandlingException)3 WebServiceIOException (org.springframework.ws.client.WebServiceIOException)3 URI (java.net.URI)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 BytesMessage (javax.jms.BytesMessage)1 Connection (javax.jms.Connection)1 MessageProducer (javax.jms.MessageProducer)1 Queue (javax.jms.Queue)1 Session (javax.jms.Session)1 XMPPConnection (org.jivesoftware.smack.XMPPConnection)1 Stanza (org.jivesoftware.smack.packet.Stanza)1 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)1 WebServiceMessageCallback (org.springframework.ws.client.core.WebServiceMessageCallback)1 WebServiceTemplate (org.springframework.ws.client.core.WebServiceTemplate)1 WebServiceConnection (org.springframework.ws.transport.WebServiceConnection)1 MailSenderConnection (org.springframework.ws.transport.mail.MailSenderConnection)1