Search in sources :

Example 1 with HttpRequestExecutingMessageHandler

use of org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler in project spring-integration by spring-projects.

the class HttpOutboundGatewayParserTests method minimalConfig.

@Test
public void minimalConfig() {
    HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler) new DirectFieldAccessor(this.minimalConfigEndpoint).getPropertyValue("handler");
    MessageChannel requestChannel = (MessageChannel) new DirectFieldAccessor(this.minimalConfigEndpoint).getPropertyValue("inputChannel");
    assertEquals(this.applicationContext.getBean("requests"), requestChannel);
    DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
    Object replyChannel = handlerAccessor.getPropertyValue("outputChannel");
    assertNull(replyChannel);
    DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("restTemplate"));
    ClientHttpRequestFactory requestFactory = (ClientHttpRequestFactory) templateAccessor.getPropertyValue("requestFactory");
    assertTrue(requestFactory instanceof SimpleClientHttpRequestFactory);
    Expression uriExpression = (Expression) handlerAccessor.getPropertyValue("uriExpression");
    assertEquals("http://localhost/test1", uriExpression.getValue());
    assertEquals(HttpMethod.POST.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString());
    assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset"));
    assertEquals(true, handlerAccessor.getPropertyValue("extractPayload"));
    assertEquals(false, handlerAccessor.getPropertyValue("transferCookies"));
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) HttpRequestExecutingMessageHandler(org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler) MessageChannel(org.springframework.messaging.MessageChannel) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Test(org.junit.Test)

Example 2 with HttpRequestExecutingMessageHandler

use of org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler in project spring-integration by spring-projects.

the class HttpOutboundChannelAdapterParserTests method minimalConfig.

@Test
public void minimalConfig() {
    DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(this.minimalConfig);
    RestTemplate restTemplate = TestUtils.getPropertyValue(this.minimalConfig, "handler.restTemplate", RestTemplate.class);
    assertNotSame(customRestTemplate, restTemplate);
    HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler) endpointAccessor.getPropertyValue("handler");
    DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
    assertEquals(false, handlerAccessor.getPropertyValue("expectReply"));
    assertEquals(this.applicationContext.getBean("requests"), endpointAccessor.getPropertyValue("inputChannel"));
    assertNull(handlerAccessor.getPropertyValue("outputChannel"));
    DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("restTemplate"));
    ClientHttpRequestFactory requestFactory = (ClientHttpRequestFactory) templateAccessor.getPropertyValue("requestFactory");
    assertTrue(requestFactory instanceof SimpleClientHttpRequestFactory);
    Expression uriExpression = (Expression) handlerAccessor.getPropertyValue("uriExpression");
    assertEquals("http://localhost/test1", uriExpression.getValue());
    assertEquals(HttpMethod.POST.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString());
    assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset"));
    assertEquals(true, handlerAccessor.getPropertyValue("extractPayload"));
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) HttpRequestExecutingMessageHandler(org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 3 with HttpRequestExecutingMessageHandler

use of org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler in project spring-integration by spring-projects.

the class HttpOutboundChannelAdapterParserTests method fullConfig.

@Test
@SuppressWarnings("unchecked")
public void fullConfig() {
    DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(this.fullConfig);
    HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler) endpointAccessor.getPropertyValue("handler");
    DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
    assertEquals(false, handlerAccessor.getPropertyValue("expectReply"));
    assertEquals(this.applicationContext.getBean("requests"), endpointAccessor.getPropertyValue("inputChannel"));
    assertNull(handlerAccessor.getPropertyValue("outputChannel"));
    assertEquals(77, handlerAccessor.getPropertyValue("order"));
    assertEquals(Boolean.FALSE, endpointAccessor.getPropertyValue("autoStartup"));
    DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("restTemplate"));
    ClientHttpRequestFactory requestFactory = (ClientHttpRequestFactory) templateAccessor.getPropertyValue("requestFactory");
    assertEquals(Boolean.class.getName(), TestUtils.getPropertyValue(handler, "expectedResponseTypeExpression", Expression.class).getValue());
    assertTrue(requestFactory instanceof SimpleClientHttpRequestFactory);
    Object converterListBean = this.applicationContext.getBean("converterList");
    assertEquals(converterListBean, templateAccessor.getPropertyValue("messageConverters"));
    Object requestFactoryBean = this.applicationContext.getBean("testRequestFactory");
    assertEquals(requestFactoryBean, requestFactory);
    Object errorHandlerBean = this.applicationContext.getBean("testErrorHandler");
    assertEquals(errorHandlerBean, templateAccessor.getPropertyValue("errorHandler"));
    Expression uriExpression = (Expression) handlerAccessor.getPropertyValue("uriExpression");
    assertEquals("http://localhost/test2/{foo}", uriExpression.getValue());
    assertEquals(HttpMethod.GET.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString());
    assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset"));
    assertEquals(false, handlerAccessor.getPropertyValue("extractPayload"));
    Map<String, Expression> uriVariableExpressions = (Map<String, Expression>) handlerAccessor.getPropertyValue("uriVariableExpressions");
    assertEquals(1, uriVariableExpressions.size());
    assertEquals("headers.bar", uriVariableExpressions.get("foo").getExpressionString());
    DirectFieldAccessor mapperAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("headerMapper"));
    String[] mappedRequestHeaders = (String[]) mapperAccessor.getPropertyValue("outboundHeaderNames");
    String[] mappedResponseHeaders = (String[]) mapperAccessor.getPropertyValue("inboundHeaderNames");
    assertEquals(2, mappedRequestHeaders.length);
    assertEquals(0, mappedResponseHeaders.length);
    assertTrue(ObjectUtils.containsElement(mappedRequestHeaders, "requestHeader1"));
    assertTrue(ObjectUtils.containsElement(mappedRequestHeaders, "requestHeader2"));
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) HttpRequestExecutingMessageHandler(org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) Map(java.util.Map) Test(org.junit.Test)

Example 4 with HttpRequestExecutingMessageHandler

use of org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler in project spring-integration by spring-projects.

the class HttpOutboundChannelAdapterParserTests method withUrlAndTemplate.

@Test
public void withUrlAndTemplate() {
    DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(this.withUrlAndTemplate);
    RestTemplate restTemplate = TestUtils.getPropertyValue(this.withUrlAndTemplate, "handler.restTemplate", RestTemplate.class);
    assertSame(customRestTemplate, restTemplate);
    HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler) endpointAccessor.getPropertyValue("handler");
    DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
    assertEquals(false, handlerAccessor.getPropertyValue("expectReply"));
    assertEquals(this.applicationContext.getBean("requests"), endpointAccessor.getPropertyValue("inputChannel"));
    assertNull(handlerAccessor.getPropertyValue("outputChannel"));
    DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("restTemplate"));
    ClientHttpRequestFactory requestFactory = (ClientHttpRequestFactory) templateAccessor.getPropertyValue("requestFactory");
    assertTrue(requestFactory instanceof SimpleClientHttpRequestFactory);
    Expression uriExpression = (Expression) handlerAccessor.getPropertyValue("uriExpression");
    assertEquals("http://localhost/test1", uriExpression.getValue());
    assertEquals(HttpMethod.POST.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString());
    assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset"));
    assertEquals(true, handlerAccessor.getPropertyValue("extractPayload"));
    // INT-3055
    Object uriVariablesExpression = handlerAccessor.getPropertyValue("uriVariablesExpression");
    assertNotNull(uriVariablesExpression);
    assertEquals("@uriVariables", ((Expression) uriVariablesExpression).getExpressionString());
    Object uriVariableExpressions = handlerAccessor.getPropertyValue("uriVariableExpressions");
    assertNotNull(uriVariableExpressions);
    assertTrue(((Map<?, ?>) uriVariableExpressions).isEmpty());
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) HttpRequestExecutingMessageHandler(org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) Expression(org.springframework.expression.Expression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Example 5 with HttpRequestExecutingMessageHandler

use of org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler in project spring-integration by spring-projects.

the class HttpOutboundChannelAdapterParserTests method withUrlExpressionAndTemplate.

@Test
public void withUrlExpressionAndTemplate() {
    DirectFieldAccessor endpointAccessor = new DirectFieldAccessor(this.withUrlExpressionAndTemplate);
    RestTemplate restTemplate = TestUtils.getPropertyValue(this.withUrlExpressionAndTemplate, "handler.restTemplate", RestTemplate.class);
    assertSame(customRestTemplate, restTemplate);
    HttpRequestExecutingMessageHandler handler = (HttpRequestExecutingMessageHandler) endpointAccessor.getPropertyValue("handler");
    DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler);
    assertEquals(false, handlerAccessor.getPropertyValue("expectReply"));
    assertEquals(this.applicationContext.getBean("requests"), endpointAccessor.getPropertyValue("inputChannel"));
    assertNull(handlerAccessor.getPropertyValue("outputChannel"));
    DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("restTemplate"));
    ClientHttpRequestFactory requestFactory = (ClientHttpRequestFactory) templateAccessor.getPropertyValue("requestFactory");
    assertTrue(requestFactory instanceof SimpleClientHttpRequestFactory);
    SpelExpression expression = (SpelExpression) handlerAccessor.getPropertyValue("uriExpression");
    assertNotNull(expression);
    assertEquals("'http://localhost/test1'", expression.getExpressionString());
    assertEquals(HttpMethod.POST.name(), TestUtils.getPropertyValue(handler, "httpMethodExpression", Expression.class).getExpressionString());
    assertEquals(Charset.forName("UTF-8"), handlerAccessor.getPropertyValue("charset"));
    assertEquals(true, handlerAccessor.getPropertyValue("extractPayload"));
}
Also used : SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) ClientHttpRequestFactory(org.springframework.http.client.ClientHttpRequestFactory) SimpleClientHttpRequestFactory(org.springframework.http.client.SimpleClientHttpRequestFactory) HttpRequestExecutingMessageHandler(org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler) SpelExpression(org.springframework.expression.spel.standard.SpelExpression) DirectFieldAccessor(org.springframework.beans.DirectFieldAccessor) RestTemplate(org.springframework.web.client.RestTemplate) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)9 DirectFieldAccessor (org.springframework.beans.DirectFieldAccessor)9 HttpRequestExecutingMessageHandler (org.springframework.integration.http.outbound.HttpRequestExecutingMessageHandler)9 SpelExpression (org.springframework.expression.spel.standard.SpelExpression)8 ClientHttpRequestFactory (org.springframework.http.client.ClientHttpRequestFactory)8 SimpleClientHttpRequestFactory (org.springframework.http.client.SimpleClientHttpRequestFactory)8 Expression (org.springframework.expression.Expression)5 RestTemplate (org.springframework.web.client.RestTemplate)4 MessageChannel (org.springframework.messaging.MessageChannel)3 Map (java.util.Map)2