Skip to content

Commit

Permalink
Fixes #4314 - Fix handling async invoke with a TRACE request (#4315)
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem authored Dec 3, 2024
1 parent 9e60d9a commit 9cea5be
Show file tree
Hide file tree
Showing 14 changed files with 479 additions and 168 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ public void start() {
networkListener.setSecure(ssl);
networkListener.registerAddOn(new Http2AddOn());
}
httpServer.getServerConfiguration().setPassTraceRequest(true);
httpServer.getServerConfiguration().addHttpHandler(new HttpHandler() {
@Override
public void service(Request request, Response response) throws Exception {
Expand Down
12 changes: 3 additions & 9 deletions test/coreprofile/integration/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,9 @@
</dependency>
<!-- test -->
<dependency>
<groupId>cloud.piranha.arquillian</groupId>
<artifactId>piranha-arquillian-managed</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit5</groupId>
<artifactId>arquillian-junit5-container</artifactId>
<version>${arquillian.version}</version>
<groupId>org.glassfish.jersey.core</groupId>
<artifactId>jersey-client</artifactId>
<version>${jersey.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
* Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.test.coreprofile.distribution;

import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import static jakarta.ws.rs.core.MediaType.TEXT_PLAIN;

/**
* The bean to test the Produces annotation.
*
* @author Manfred Riem (mriem@manorrock.com)
*/
@Path("async")
public class AsyncBean {

/**
* Test to validate NOT_ACCEPTABLE (406) is returned.
*
* @return "This should not show up!"
*/
@TRACE
@Path("notAcceptable")
@Produces(TEXT_PLAIN)
public String notAcceptable() {
return "This should not show up!";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.test.coreprofile.distribution;

import jakarta.ws.rs.HttpMethod;
import java.lang.annotation.Retention;
import java.lang.annotation.Target;
import static java.lang.annotation.ElementType.METHOD;
import static java.lang.annotation.RetentionPolicy.RUNTIME;

@Target(METHOD)
@Retention(RUNTIME)
@HttpMethod("TRACE")
public @interface TRACE {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
/*
* Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.test.coreprofile.distribution;

import static cloud.piranha.test.coreprofile.distribution.ITBase.baseUrl;
import jakarta.ws.rs.client.AsyncInvoker;
import jakarta.ws.rs.client.Client;
import jakarta.ws.rs.client.ClientBuilder;
import jakarta.ws.rs.client.WebTarget;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import java.net.URI;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.fail;
import org.junit.jupiter.api.Test;

/**
* The integration tests validating async integration works.
*
* @author Manfred Riem (mriem@manorrock.com)
*/
public class AsyncIT extends ITBase {

/**
* Test that validates that an async invocation to an endpoint with the
* wrong accept header and using the TRACE HTTP method returns the
* NOT_ACCEPTABlE status code.
*/
@Test
void testAsyncNotAcceptable() {
Client client = ClientBuilder.newClient();
WebTarget target = client.target(baseUrl + "/async/notAcceptable");
AsyncInvoker invoker = target.request(MediaType.TEXT_XML).async();
Future<Response> future = invoker.trace(Response.class);
try {
Response response = future.get();
assertEquals(406, response.getStatus());
} catch (InterruptedException | ExecutionException ex) {
fail(ex);
}
}

/**
* Test that validates that a sync invocation to an endpoint with the
* wrong accept header returns the NOT_ACCEPTABlE status code.
*/
@Test
void testAsyncNotAcceptableSync() throws Exception {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create(baseUrl
+ "/async/notAcceptable"))
.header("Accept", "text/xml")
.method("TRACE", BodyPublishers.noBody())
.build();

HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());

assertEquals(406, response.statusCode());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,20 +35,19 @@
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;

public class BeanParamIT {
public class BeanParamIT extends ITBase {

@Test
public void testBeanParamAnnotationWithoutContent() throws Exception {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:"
+ System.getProperty("httpPort")
+ "/piranha-test-coreprofile-integration/beanParam/withoutContent?queryParam=10"))
.uri(URI.create(baseUrl
+ "/beanParam/withoutContent?queryParam=10"))
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(HttpRequest.BodyPublishers.ofString("formParam=formParam1"))
.build();

HttpResponse<String> response = client.send(request,
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());

assertEquals(200, response.statusCode());
Expand All @@ -59,14 +58,13 @@ public void testBeanParamAnnotationWithoutContent() throws Exception {
public void testBeanParamAnnotationWithContent() throws Exception {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:"
+ System.getProperty("httpPort")
+ "/piranha-test-coreprofile-integration/beanParam/withContent?queryParam=10"))
.uri(URI.create(baseUrl
+ "/beanParam/withContent?queryParam=10"))
.header("Content-Type", "application/x-www-form-urlencoded")
.POST(HttpRequest.BodyPublishers.ofString("CONTENT"))
.build();

HttpResponse<String> response = client.send(request,
HttpResponse<String> response = client.send(request,
HttpResponse.BodyHandlers.ofString());

assertEquals(200, response.statusCode());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,13 @@
import java.net.http.HttpResponse;
import static org.junit.jupiter.api.Assertions.assertTrue;

public class DependencyInjectionIT {
public class DependencyInjectionIT extends ITBase {

@Test
public void testDependencyInjection() throws Exception {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest
.newBuilder(URI.create("http://localhost:"
+ System.getProperty("httpPort")
+ "/piranha-test-coreprofile-integration/dependencyInjection"))
.newBuilder(URI.create(baseUrl + "/dependencyInjection"))
.build();
HttpResponse<String> response = client.send(request, HttpResponse.BodyHandlers.ofString());
assertTrue(response.body().contains("Dependency Injection works!"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice,
* this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. Neither the name of the copyright holder nor the names of its
* contributors may be used to endorse or promote products derived from
* this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
* POSSIBILITY OF SUCH DAMAGE.
*/
package cloud.piranha.test.coreprofile.distribution;

/**
* A base class for all integration tests in this package.
*
* @author Manfred Riem (mriem@manorrock.com)
*/
class ITBase {

/**
* Stores the base URL used by our tests.
*/
public static String baseUrl = "http://localhost:"
+ System.getProperty("httpPort", "8080")
+ "/piranha-test-coreprofile-integration";
}
Loading

0 comments on commit 9cea5be

Please sign in to comment.