This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 0c439f4374 Register HttpOperationFailedException for reflection
0c439f4374 is described below
commit 0c439f4374b1e695a20c135f522dc0ba3b891f5c
Author: James Netherton <[email protected]>
AuthorDate: Fri Aug 19 09:09:41 2022 +0100
Register HttpOperationFailedException for reflection
Fixes #3971
---
.../component/http/deployment/HttpProcessor.java | 2 ++
integration-tests/http/pom.xml | 17 ++++++++++
.../quarkus/component/http/it/HttpResource.java | 8 +++++
.../camel/quarkus/component/http/it/HttpRoute.java | 38 ++++++++--------------
.../camel/quarkus/component/http/it/HttpTest.java | 33 ++++++++++++++-----
5 files changed, 65 insertions(+), 33 deletions(-)
diff --git
a/extensions/http/deployment/src/main/java/org/apache/camel/quarkus/component/http/deployment/HttpProcessor.java
b/extensions/http/deployment/src/main/java/org/apache/camel/quarkus/component/http/deployment/HttpProcessor.java
index 9db31fd2b1..d0d024337e 100644
---
a/extensions/http/deployment/src/main/java/org/apache/camel/quarkus/component/http/deployment/HttpProcessor.java
+++
b/extensions/http/deployment/src/main/java/org/apache/camel/quarkus/component/http/deployment/HttpProcessor.java
@@ -21,6 +21,7 @@ import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import org.apache.camel.http.base.HttpOperationFailedException;
import org.apache.http.client.config.RequestConfig;
class HttpProcessor {
@@ -41,5 +42,6 @@ class HttpProcessor {
reflectiveClasses.produce(new ReflectiveClassBuildItem(true, false,
"org.apache.camel.component.http.HttpMethods"));
reflectiveClasses.produce(new ReflectiveClassBuildItem(true, false,
"org.apache.http.impl.client.HttpClientBuilder"));
reflectiveClasses.produce(new ReflectiveClassBuildItem(true, false,
RequestConfig.Builder.class.getName()));
+ reflectiveClasses.produce(new ReflectiveClassBuildItem(false, false,
HttpOperationFailedException.class));
}
}
diff --git a/integration-tests/http/pom.xml b/integration-tests/http/pom.xml
index 58303308ec..ea1811f88f 100644
--- a/integration-tests/http/pom.xml
+++ b/integration-tests/http/pom.xml
@@ -43,6 +43,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-netty-http</artifactId>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-seda</artifactId>
+ </dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-vertx-http</artifactId>
@@ -181,6 +185,19 @@
</exclusion>
</exclusions>
</dependency>
+ <dependency>
+ <groupId>org.apache.camel.quarkus</groupId>
+ <artifactId>camel-quarkus-seda-deployment</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>test</scope>
+ <exclusions>
+ <exclusion>
+ <groupId>*</groupId>
+ <artifactId>*</artifactId>
+ </exclusion>
+ </exclusions>
+ </dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-vertx-http-deployment</artifactId>
diff --git
a/integration-tests/http/src/main/java/org/apache/camel/quarkus/component/http/it/HttpResource.java
b/integration-tests/http/src/main/java/org/apache/camel/quarkus/component/http/it/HttpResource.java
index 35c786b547..07dffbb0fd 100644
---
a/integration-tests/http/src/main/java/org/apache/camel/quarkus/component/http/it/HttpResource.java
+++
b/integration-tests/http/src/main/java/org/apache/camel/quarkus/component/http/it/HttpResource.java
@@ -167,6 +167,14 @@ public class HttpResource {
.request(String.class);
}
+ @Path("/http/operation/failed/exception")
+ @GET
+ @Produces(MediaType.TEXT_PLAIN)
+ public String httpOperationFailedException() {
+ producerTemplate.to("direct:httpOperationFailedException").send();
+ return consumerTemplate.receiveBody("seda:dlq", 5000, String.class);
+ }
+
@Path("/http/serialized/exception")
@GET
@Produces(MediaType.TEXT_PLAIN)
diff --git
a/integration-tests/http/src/main/java/org/apache/camel/quarkus/component/http/it/HttpRoute.java
b/integration-tests/http/src/main/java/org/apache/camel/quarkus/component/http/it/HttpRoute.java
index a6b0d17aea..26b8625295 100644
---
a/integration-tests/http/src/main/java/org/apache/camel/quarkus/component/http/it/HttpRoute.java
+++
b/integration-tests/http/src/main/java/org/apache/camel/quarkus/component/http/it/HttpRoute.java
@@ -16,8 +16,6 @@
*/
package org.apache.camel.quarkus.component.http.it;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
import java.io.InputStream;
import javax.inject.Named;
@@ -26,6 +24,7 @@ import io.quarkus.runtime.annotations.RegisterForReflection;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.http.base.HttpOperationFailedException;
import org.apache.camel.support.jsse.KeyManagersParameters;
import org.apache.camel.support.jsse.KeyStoreParameters;
import org.apache.camel.support.jsse.SSLContextParameters;
@@ -44,6 +43,18 @@ public class HttpRoute extends RouteBuilder {
from("netty-http:http://0.0.0.0:{{camel.netty-http.compression-test-port}}/compressed?compression=true")
.transform().constant("Netty Hello World Compressed");
+ from("direct:httpOperationFailedException")
+ .onException(HttpOperationFailedException.class)
+ .handled(true)
+ .setBody().constant("Handled HttpOperationFailedException")
+ .to("seda:dlq")
+ .end()
+
.to("http://localhost:{{camel.netty-http.test-port}}/test/server/error");
+
+
from("netty-http:http://0.0.0.0:{{camel.netty-http.test-port}}/test/server/error")
+ .removeHeaders("CamelHttp*")
+ .setHeader(Exchange.HTTP_RESPONSE_CODE).constant(500);
+
from("netty-http:http://0.0.0.0:{{camel.netty-http.https-test-port}}/countries/cz?ssl=true&sslContextParameters=#sslContextParameters")
.process(new Processor() {
@Override
@@ -62,6 +73,7 @@ public class HttpRoute extends RouteBuilder {
.staticServiceDiscovery()
.servers("myService@localhost:{{camel.netty-http.test-port}}")
.end();
+
from("netty-http:http://0.0.0.0:{{camel.netty-http.test-port}}/test/server/myService")
.transform().constant("Hello from myService");
@@ -89,26 +101,4 @@ public class HttpRoute extends RouteBuilder {
return sslContextParameters;
}
-
- private static byte[] readStore(String path) throws IOException {
- byte[] data = null;
- final InputStream resource = HttpRoute.class.getResourceAsStream(path);
- if (resource != null) {
- try (InputStream is = resource) {
- data = inputStreamToBytes(is);
- }
- }
- return data;
- }
-
- private static byte[] inputStreamToBytes(InputStream is) throws
IOException {
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- byte[] buf = new byte[1024];
- int r;
- while ((r = is.read(buf)) > 0) {
- out.write(buf, 0, r);
- }
- return out.toByteArray();
- }
-
}
diff --git
a/integration-tests/http/src/test/java/org/apache/camel/quarkus/component/http/it/HttpTest.java
b/integration-tests/http/src/test/java/org/apache/camel/quarkus/component/http/it/HttpTest.java
index 77435158c0..e9d330bc5f 100644
---
a/integration-tests/http/src/test/java/org/apache/camel/quarkus/component/http/it/HttpTest.java
+++
b/integration-tests/http/src/test/java/org/apache/camel/quarkus/component/http/it/HttpTest.java
@@ -67,8 +67,7 @@ class HttpTest {
@ParameterizedTest
@MethodSource("getHttpComponentNames")
public void httpsProducer(String component) {
- final int port =
ConfigProvider.getConfig().getValue("camel.netty-http.https-test-port",
Integer.class);
-
+ final int port = getPort("camel.netty-http.https-test-port");
RestAssured
.given()
.queryParam("test-port", port)
@@ -147,7 +146,7 @@ class HttpTest {
@ParameterizedTest
@MethodSource("getHttpComponentNames")
public void compression(String component) {
- final int port =
ConfigProvider.getConfig().getValue("camel.netty-http.compression-test-port",
Integer.class);
+ final int port = getPort("camel.netty-http.compression-test-port");
RestAssured
.given()
.queryParam("test-port", port)
@@ -161,10 +160,9 @@ class HttpTest {
@ParameterizedTest
@MethodSource("getHttpComponentNames")
public void transferException(String component) {
- final int port =
ConfigProvider.getConfig().getValue("camel.netty-http.test-port",
Integer.class);
RestAssured
.given()
- .queryParam("test-port", port)
+ .queryParam("test-port", getPort())
.when()
.get("/test/client/{component}/serialized/exception",
component)
.then()
@@ -174,10 +172,9 @@ class HttpTest {
@Test
public void basicNettyHttpServer() {
- final int port =
ConfigProvider.getConfig().getValue("camel.netty-http.test-port",
Integer.class);
RestAssured
.given()
- .port(port)
+ .port(getPort())
.when()
.get("/test/server/hello")
.then()
@@ -202,10 +199,9 @@ class HttpTest {
@Test
public void serviceCall() {
- final int port =
ConfigProvider.getConfig().getValue("camel.netty-http.test-port",
Integer.class);
RestAssured
.given()
- .port(port)
+ .port(getPort())
.when()
.get("/test/server/serviceCall")
.then()
@@ -213,6 +209,25 @@ class HttpTest {
.body(Matchers.is("Hello from myService"));
}
+ @Test
+ public void httpOperationFailedException() {
+ RestAssured
+ .given()
+ .when()
+ .get("/test/client/http/operation/failed/exception")
+ .then()
+ .statusCode(200)
+ .body(is("Handled HttpOperationFailedException"));
+ }
+
+ private Integer getPort() {
+ return getPort("camel.netty-http.test-port");
+ }
+
+ private Integer getPort(String configKey) {
+ return ConfigProvider.getConfig().getValue(configKey, Integer.class);
+ }
+
private static String[] getHttpComponentNames() {
return HTTP_COMPONENTS;
}