You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/09/02 16:38:44 UTC
[camel-k-runtime] branch master updated: knative-http component
does not return response #130
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-k-runtime.git
The following commit(s) were added to refs/heads/master by this push:
new eeead64 knative-http component does not return response #130
eeead64 is described below
commit eeead642f43cff5e5fb74566e967b6ee06be8bf3
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Mon Sep 2 18:04:10 2019 +0200
knative-http component does not return response #130
---
camel-knative-http/pom.xml | 5 -
.../http/KnativeHttpConsumerDispatcher.java | 2 +-
.../knative/http/KnativeHttpProducer.java | 17 ++--
.../component/knative/http/KnativeHttpTest.java | 17 ++--
.../component/knative/KnativeComponentTest.java | 55 +++++++++++
examples/camel-k-runtime-example-knative/pom.xml | 105 +++++++++++++++++++++
.../src/main/resources/application.properties | 30 ++++++
.../src/main/resources/env.json | 11 +++
.../src/main/resources/routes.yaml | 28 ++++++
examples/pom.xml | 1 +
.../maven/processors/CatalogProcessor3x.java | 2 -
.../maven/processors/CatalogProcessor3Test.java | 6 --
12 files changed, 249 insertions(+), 30 deletions(-)
diff --git a/camel-knative-http/pom.xml b/camel-knative-http/pom.xml
index 82ed34d..bbd8d4b 100644
--- a/camel-knative-http/pom.xml
+++ b/camel-knative-http/pom.xml
@@ -46,11 +46,6 @@
<artifactId>camel-core-engine</artifactId>
<scope>provided</scope>
</dependency>
- <dependency>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-http-common</artifactId>
- <scope>provided</scope>
- </dependency>
<dependency>
<groupId>io.vertx</groupId>
diff --git a/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumerDispatcher.java b/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumerDispatcher.java
index 446dc6b..ed4af7f 100644
--- a/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumerDispatcher.java
+++ b/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpConsumerDispatcher.java
@@ -118,7 +118,7 @@ public final class KnativeHttpConsumerDispatcher {
throw new RuntimeException(result.cause());
}
- LOGGER.info("Vert.x HttpServer started on {}:{}", key.getPort(), key.getHost());
+ LOGGER.info("Vert.x HttpServer started on {}:{}", key.getHost(), key.getPort());
} finally {
latch.countDown();
}
diff --git a/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpProducer.java b/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpProducer.java
index c4aafed..f42adf0 100644
--- a/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpProducer.java
+++ b/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpProducer.java
@@ -26,15 +26,15 @@ import io.vertx.ext.web.client.HttpResponse;
import io.vertx.ext.web.client.WebClient;
import io.vertx.ext.web.client.WebClientOptions;
import org.apache.camel.AsyncCallback;
+import org.apache.camel.CamelException;
import org.apache.camel.Exchange;
import org.apache.camel.InvalidPayloadException;
import org.apache.camel.Message;
-import org.apache.camel.http.common.HttpOperationFailedException;
import org.apache.camel.support.DefaultAsyncProducer;
import org.apache.camel.support.DefaultMessage;
-import org.apache.camel.support.ExchangeHelper;
import org.apache.camel.support.MessageHelper;
import org.apache.camel.util.ObjectHelper;
+import org.apache.camel.util.URISupport;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -104,14 +104,11 @@ public class KnativeHttpProducer extends DefaultAsyncProducer {
exchange.setMessage(answer);
- if (response.failed() && endpoint.getThrowExceptionOnFailure()) {
- Exception cause = new HttpOperationFailedException(
- getURI(),
- result.statusCode(),
- result.statusMessage(),
- null,
- KnativeHttpSupport.asStringMap(answer.getHeaders()),
- ExchangeHelper.convertToType(exchange, String.class, answer.getBody())
+ if (response.succeeded()) {
+ answer.setBody(result.body().getBytes());
+ } else if (response.failed() && endpoint.getThrowExceptionOnFailure()) {
+ Exception cause = new CamelException(
+ "HTTP operation failed invoking " + URISupport.sanitizeUri(getURI()) + " with statusCode: " + result.statusCode()
);
exchange.setException(cause);
diff --git a/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTest.java b/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTest.java
index 0b40284..42fae3d 100644
--- a/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTest.java
+++ b/camel-knative-http/src/test/java/org/apache/camel/component/knative/http/KnativeHttpTest.java
@@ -210,19 +210,24 @@ public class KnativeHttpTest {
.to("mock:endpoint");
b.from("direct:start")
- .toF("knative-http:0.0.0.0:%d", port);
+ .toF("knative-http:0.0.0.0:%d", port)
+ .to("mock:start");
});
- MockEndpoint mock = context.getEndpoint("mock:endpoint", MockEndpoint.class);
- mock.expectedBodiesReceived("endpoint");
- mock.expectedHeaderReceived("Host", "0.0.0.0");
- mock.expectedMessageCount(1);
+ MockEndpoint mock1 = context.getEndpoint("mock:endpoint", MockEndpoint.class);
+ mock1.expectedHeaderReceived("Host", "0.0.0.0");
+ mock1.expectedMessageCount(1);
+
+ MockEndpoint mock2 = context.getEndpoint("mock:start", MockEndpoint.class);
+ mock2.expectedBodiesReceived("endpoint");
+ mock2.expectedMessageCount(1);
context.start();
template.sendBody("direct:start", "1");
- mock.assertIsSatisfied();
+ mock1.assertIsSatisfied();
+ mock2.assertIsSatisfied();
}
}
diff --git a/camel-knative/src/test/java/org/apache/camel/component/knative/KnativeComponentTest.java b/camel-knative/src/test/java/org/apache/camel/component/knative/KnativeComponentTest.java
index 996d43e..e704a85 100644
--- a/camel-knative/src/test/java/org/apache/camel/component/knative/KnativeComponentTest.java
+++ b/camel-knative/src/test/java/org/apache/camel/component/knative/KnativeComponentTest.java
@@ -590,4 +590,59 @@ public class KnativeComponentTest {
mock1.assertIsSatisfied();
mock2.assertIsSatisfied();
}
+
+ @Test
+ void testReply() throws Exception {
+ final int port = AvailablePortFinder.getNextAvailable();
+
+ KnativeEnvironment env = new KnativeEnvironment(Arrays.asList(
+ new KnativeEnvironment.KnativeServiceDefinition(
+ Knative.Type.endpoint,
+ Knative.Protocol.http,
+ "from",
+ "localhost",
+ port,
+ KnativeSupport.mapOf(
+ Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event",
+ Knative.CONTENT_TYPE, "text/plain"
+ )),
+ new KnativeEnvironment.KnativeServiceDefinition(
+ Knative.Type.endpoint,
+ Knative.Protocol.http,
+ "to",
+ "localhost",
+ port,
+ KnativeSupport.mapOf(
+ Knative.KNATIVE_EVENT_TYPE, "org.apache.camel.event",
+ Knative.CONTENT_TYPE, "text/plain"
+ ))
+ )
+ );
+
+ KnativeComponent component = context.getComponent("knative", KnativeComponent.class);
+ component.setCloudEventsSpecVersion(CloudEventsProcessors.v01.getVersion());
+ component.setEnvironment(env);
+
+ context.addRoutes(new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ from("knative:endpoint/from")
+ .convertBodyTo(String.class)
+ .setBody().constant("consumer");
+ from("direct:source")
+ .to("knative://endpoint/to")
+ .log("${body}")
+ .to("mock:to");
+ }
+ });
+
+ MockEndpoint mock = context.getEndpoint("mock:to", MockEndpoint.class);
+ mock.expectedBodiesReceived("consumer");
+ mock.expectedMessageCount(1);
+
+ context.start();
+ context.createProducerTemplate().sendBody("direct:source", "");
+
+ mock.assertIsSatisfied();
+ }
}
diff --git a/examples/camel-k-runtime-example-knative/pom.xml b/examples/camel-k-runtime-example-knative/pom.xml
new file mode 100644
index 0000000..5ada28d
--- /dev/null
+++ b/examples/camel-k-runtime-example-knative/pom.xml
@@ -0,0 +1,105 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <parent>
+ <groupId>org.apache.camel.k</groupId>
+ <artifactId>camel-k-runtime-examples</artifactId>
+ <version>1.0.2-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId><![CDATA[camel-k-runtime-example-knative]]></artifactId>
+
+ <dependencies>
+
+ <!-- ****************************** -->
+ <!-- -->
+ <!-- RUNTIME -->
+ <!-- -->
+ <!-- ****************************** -->
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-core-engine</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-main</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-log</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jackson</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-cloud</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.k</groupId>
+ <artifactId>camel-k-runtime-main</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.k</groupId>
+ <artifactId>camel-k-runtime-knative</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.k</groupId>
+ <artifactId>camel-k-loader-yaml</artifactId>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <defaultGoal>exec:java</defaultGoal>
+ <plugins>
+ <plugin>
+ <groupId>org.codehaus.mojo</groupId>
+ <artifactId>exec-maven-plugin</artifactId>
+ <version>${exec-maven-plugin.version}</version>
+ <executions>
+ <execution>
+ <goals>
+ <goal>java</goal>
+ </goals>
+ </execution>
+ </executions>
+ <configuration>
+ <mainClass>org.apache.camel.k.main.Application</mainClass>
+ <classpathScope>runtime</classpathScope>
+ <workingDirectory>${project.basedir}</workingDirectory>
+ <systemProperties>
+ <systemProperty>
+ <key>camel.k.conf</key>
+ <value>${project.basedir}/src/main/resources/application.properties</value>
+ </systemProperty>
+ <systemProperty>
+ <key>camel.k.routes</key>
+ <value>file:${project.basedir}/src/main/resources/routes.yaml</value>
+ </systemProperty>
+ </systemProperties>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
diff --git a/examples/camel-k-runtime-example-knative/src/main/resources/application.properties b/examples/camel-k-runtime-example-knative/src/main/resources/application.properties
new file mode 100644
index 0000000..4682185
--- /dev/null
+++ b/examples/camel-k-runtime-example-knative/src/main/resources/application.properties
@@ -0,0 +1,30 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## The ASF licenses this file to You 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.
+## ---------------------------------------------------------------------------
+#
+# Logging
+#
+logging.level.org.apache.camel.k = DEBUG
+
+#
+# Camel
+#
+camel.context.stream-caching = true
+
+#
+# Camel - components
+#
+camel.component.knative.environment-path = file:src/main/resources/env.json
\ No newline at end of file
diff --git a/examples/camel-k-runtime-example-knative/src/main/resources/env.json b/examples/camel-k-runtime-example-knative/src/main/resources/env.json
new file mode 100644
index 0000000..2220159
--- /dev/null
+++ b/examples/camel-k-runtime-example-knative/src/main/resources/env.json
@@ -0,0 +1,11 @@
+{
+ "services": [
+ {
+ "type": "endpoint",
+ "protocol": "http",
+ "name": "from",
+ "host": "0.0.0.0",
+ "port": 9090
+ }
+ ]
+}
\ No newline at end of file
diff --git a/examples/camel-k-runtime-example-knative/src/main/resources/routes.yaml b/examples/camel-k-runtime-example-knative/src/main/resources/routes.yaml
new file mode 100644
index 0000000..43a2622
--- /dev/null
+++ b/examples/camel-k-runtime-example-knative/src/main/resources/routes.yaml
@@ -0,0 +1,28 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one or more
+# contributor license agreements. See the NOTICE file distributed with
+# this work for additional information regarding copyright ownership.
+# The ASF licenses this file to You 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.
+#
+
+- id: "knative"
+ group: "routes"
+ from:
+ uri: "knative:endpoint/from"
+ steps:
+ - convert-body:
+ type: "java.lang.String"
+ - to:
+ uri: "log:knative"
+ - set-body:
+ constant: "Hello from camel-k (native)"
\ No newline at end of file
diff --git a/examples/pom.xml b/examples/pom.xml
index 9a797c0..dd3fda8 100644
--- a/examples/pom.xml
+++ b/examples/pom.xml
@@ -33,6 +33,7 @@
<module>camel-k-runtime-example-servlet</module>
<module>camel-k-runtime-example-health</module>
<module>camel-k-runtime-example-yaml</module>
+ <module>camel-k-runtime-example-knative</module>
</modules>
</project>
diff --git a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java
index 49b0adb..9e83a10 100644
--- a/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java
+++ b/tooling/camel-k-maven-plugin/src/main/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3x.java
@@ -208,7 +208,6 @@ public class CatalogProcessor3x implements CatalogProcessor {
artifact.setVersion(project.getVersion());
artifact.createScheme("knative").setHttp(true);
artifact.addDependency("org.apache.camel", "camel-cloud");
- artifact.addDependency("org.apache.camel", "camel-http-common");
artifacts.put(artifact.getArtifactId(), artifact);
}
@@ -256,7 +255,6 @@ public class CatalogProcessor3x implements CatalogProcessor {
artifact.setGroupId("org.apache.camel.k");
artifact.setArtifactId("camel-k-runtime-knative");
artifact.addDependency("org.apache.camel", "camel-cloud");
- artifact.addDependency("org.apache.camel", "camel-http-common");
artifact.addDependency("org.apache.camel.k", "camel-k-loader-yaml");
artifact.addDependency("org.apache.camel.k", "camel-k-loader-knative");
artifact.addDependency("org.apache.camel.k", "camel-knative");
diff --git a/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java b/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java
index 5051c12..daa06a2 100644
--- a/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java
+++ b/tooling/camel-k-maven-plugin/src/test/java/org/apache/camel/k/tooling/maven/processors/CatalogProcessor3Test.java
@@ -113,18 +113,12 @@ public class CatalogProcessor3Test extends AbstractCataloProcessorTest {
assertThat(a.getDependencies()).anyMatch(
d -> d.getGroupId().equals("org.apache.camel") && d.getArtifactId().equals("camel-cloud")
);
- assertThat(a.getDependencies()).anyMatch(
- d -> d.getGroupId().equals("org.apache.camel") && d.getArtifactId().equals("camel-http-common")
- );
});
assertThat(artifactMap.get("camel-knative")).satisfies(a -> {
assertThat(a.getDependencies()).anyMatch(
d -> d.getGroupId().equals("org.apache.camel") && d.getArtifactId().equals("camel-cloud")
);
- assertThat(a.getDependencies()).anyMatch(
- d -> d.getGroupId().equals("org.apache.camel") && d.getArtifactId().equals("camel-http-common")
- );
});
assertThat(artifactMap.get("camel-http4")).satisfies(a -> {