-
Notifications
You must be signed in to change notification settings - Fork 137
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(#1243): Add option to configure disable redirect for HttpClient
- Loading branch information
Showing
14 changed files
with
269 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 32 additions & 0 deletions
32
...rus-http/src/test/java/org/citrusframework/http/integration/HttpClientWithRedirectIT.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright the original author or authors. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package org.citrusframework.http.integration; | ||
|
||
import org.citrusframework.annotations.CitrusTestSource; | ||
import org.citrusframework.common.TestLoader; | ||
import org.citrusframework.testng.spring.TestNGCitrusSpringSupport; | ||
import org.testng.annotations.Test; | ||
|
||
@Test | ||
public class HttpClientWithRedirectIT extends TestNGCitrusSpringSupport { | ||
|
||
@CitrusTestSource(type = TestLoader.SPRING, name = "HttpClientWithRedirectIT") | ||
public void testHttpClientWithRedirect() {} | ||
|
||
@CitrusTestSource(type = TestLoader.SPRING, name = "HttpClientWithRedirectDisabledIT") | ||
public void testHttpClientWithRedirectDisabled() {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
...us-http/src/test/resources/org/citrusframework/http/citrus-http-with-redirect-servlet.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<beans xmlns="http://www.springframework.org/schema/beans" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xmlns:util="http://www.springframework.org/schema/util" | ||
xmlns:context="http://www.springframework.org/schema/context" | ||
xsi:schemaLocation= | ||
"http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd | ||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> | ||
<description>Contains the root context. Gets loaded via ContextLoaderListener in web.xml</description> | ||
|
||
<context:annotation-config/> | ||
|
||
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping"/> | ||
|
||
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter"> | ||
<property name="messageConverters"> | ||
<util:list id="converters"> | ||
<bean class="org.citrusframework.http.message.DelegatingHttpEntityMessageConverter"/> | ||
</util:list> | ||
</property> | ||
</bean> | ||
|
||
<!-- Controller for handling rest requests --> | ||
<bean class="org.citrusframework.http.controller.HttpMessageController"> | ||
<property name="endpointAdapter"> | ||
<bean class="org.citrusframework.endpoint.adapter.StaticResponseEndpointAdapter"> | ||
<property name="messageHeader"> | ||
<map> | ||
<entry key="citrus_http_status_code" value="302"/> | ||
<entry key="Location" value="http://localhost:11080/hello"/> | ||
<entry key="CorrelationId" value="1000000001"/> | ||
</map> | ||
</property> | ||
</bean> | ||
</property> | ||
</bean> | ||
|
||
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
63 changes: 63 additions & 0 deletions
63
.../test/resources/org/citrusframework/http/integration/HttpClientWithRedirectDisabledIT.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<spring:beans xmlns="http://www.citrusframework.org/schema/testcase" | ||
xmlns:spring="http://www.springframework.org/schema/beans" | ||
xmlns:http="http://www.citrusframework.org/schema/http/testcase" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.citrusframework.org/schema/testcase http://www.citrusframework.org/schema/testcase/citrus-testcase.xsd | ||
http://www.citrusframework.org/schema/http/testcase http://www.citrusframework.org/schema/http/testcase/citrus-http-testcase.xsd"> | ||
|
||
<testcase name="HttpClientWithRedirectDisabledIT"> | ||
<meta-info> | ||
<author>Thorsten Schlathoelter</author> | ||
<creationdate>2024-10-28</creationdate> | ||
<status>FINAL</status> | ||
</meta-info> | ||
|
||
<description> | ||
Tests sending messages to an HTTP server instance that issues a redirect. | ||
The HTTP client used for the request has redirectDisabled enabled, preventing | ||
automatic redirection. This allows direct assertion of the response. | ||
</description> | ||
|
||
<variables> | ||
<variable name="correlationId" value="1000000001"></variable> | ||
<variable name="messageId" value="@randomNumber(10)@"></variable> | ||
<variable name="user" value="User"></variable> | ||
</variables> | ||
|
||
<actions> | ||
<echo> | ||
<message>Test: Send Http request and receive redirect</message> | ||
</echo> | ||
|
||
<http:send-request client="helloHttpClientWithRedirectDisabled"> | ||
<http:POST> | ||
<http:headers> | ||
<http:header name="Operation" value="sayHello"/> | ||
<http:header name="CorrelationId" value="${correlationId}"/> | ||
</http:headers> | ||
<http:body> | ||
<http:data> | ||
<![CDATA[ | ||
<HelloRequest xmlns="http://citrusframework.org/schemas/samples/HelloService.xsd"> | ||
<MessageId>${messageId}</MessageId> | ||
<CorrelationId>${correlationId}</CorrelationId> | ||
<User>${user}</User> | ||
<Text>Hello Citrus</Text> | ||
</HelloRequest> | ||
]]> | ||
</http:data> | ||
</http:body> | ||
</http:POST> | ||
</http:send-request> | ||
|
||
<http:receive-response client="helloHttpClientWithRedirectDisabled"> | ||
<http:headers status="302" reason-phrase="FOUND" version="HTTP/1.1"> | ||
<http:header name="Location" value="http://localhost:11080/hello"/> | ||
</http:headers> | ||
</http:receive-response> | ||
|
||
</actions> | ||
</testcase> | ||
</spring:beans> |
69 changes: 69 additions & 0 deletions
69
...http/src/test/resources/org/citrusframework/http/integration/HttpClientWithRedirectIT.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<spring:beans xmlns="http://www.citrusframework.org/schema/testcase" | ||
xmlns:spring="http://www.springframework.org/schema/beans" | ||
xmlns:http="http://www.citrusframework.org/schema/http/testcase" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd | ||
http://www.citrusframework.org/schema/testcase http://www.citrusframework.org/schema/testcase/citrus-testcase.xsd | ||
http://www.citrusframework.org/schema/http/testcase http://www.citrusframework.org/schema/http/testcase/citrus-http-testcase.xsd"> | ||
|
||
<testcase name="HttpClientWithRedirectIT"> | ||
<meta-info> | ||
<author>Thorsten Schlathoelter</author> | ||
<creationdate>2024-10-28</creationdate> | ||
<status>FINAL</status> | ||
</meta-info> | ||
|
||
<description> | ||
Tests sending messages to an HTTP server instance that issues a redirect. | ||
By default, the HTTP client follows the redirect, which means the original | ||
response is not stored in the message store for evaluation. Receive-response | ||
therefore throws an error. Therefore, the receive-response action below is | ||
asserted. | ||
</description> | ||
|
||
<variables> | ||
<variable name="correlationId" value="1000000001"></variable> | ||
<variable name="messageId" value="@randomNumber(10)@"></variable> | ||
<variable name="user" value="User"></variable> | ||
</variables> | ||
|
||
<actions> | ||
<echo> | ||
<message>Test: Send Http request and fail on receive because of redirect</message> | ||
</echo> | ||
|
||
<http:send-request client="helloHttpClientWithRedirect"> | ||
<http:POST> | ||
<http:headers> | ||
<http:header name="Operation" value="sayHello"/> | ||
<http:header name="CorrelationId" value="${correlationId}"/> | ||
</http:headers> | ||
<http:body> | ||
<http:data> | ||
<![CDATA[ | ||
<HelloRequest xmlns="http://citrusframework.org/schemas/samples/HelloService.xsd"> | ||
<MessageId>${messageId}</MessageId> | ||
<CorrelationId>${correlationId}</CorrelationId> | ||
<User>${user}</User> | ||
<Text>Hello Citrus</Text> | ||
</HelloRequest> | ||
]]> | ||
</http:data> | ||
</http:body> | ||
</http:POST> | ||
</http:send-request> | ||
|
||
<assert exception="org.citrusframework.exceptions.CitrusRuntimeException"> | ||
<when> | ||
<http:receive-response client="helloHttpClientWithRedirect"> | ||
<http:headers status="302" reason-phrase="FOUND" version="HTTP/1.1"> | ||
<http:header name="Location" value="http://localhost:11080/hello"/> | ||
</http:headers> | ||
</http:receive-response> | ||
</when> | ||
</assert> | ||
|
||
</actions> | ||
</testcase> | ||
</spring:beans> |