[
https://issues.apache.org/jira/browse/CAMEL-13162?focusedWorklogId=215344&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-215344
]
ASF GitHub Bot logged work on CAMEL-13162:
------------------------------------------
Author: ASF GitHub Bot
Created on: 19/Mar/19 09:27
Start Date: 19/Mar/19 09:27
Worklog Time Spent: 10m
Work Description: davsclaus commented on pull request #2829: (fix)
CAMEL-13162: Fixed rest-dsl advice-with using inlined route wit…
URL: https://github.com/apache/camel/pull/2829
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
Issue Time Tracking
-------------------
Worklog Id: (was: 215344)
Time Spent: 20m (was: 10m)
> Unknown parameter issue on weaving from-with on a REST-DSL route
> ----------------------------------------------------------------
>
> Key: CAMEL-13162
> URL: https://issues.apache.org/jira/browse/CAMEL-13162
> Project: Camel
> Issue Type: Bug
> Components: camel-test
> Affects Versions: 2.23.0, 2.23.1
> Reporter: Roman Vottner
> Assignee: Dmitry Volodin
> Priority: Minor
> Fix For: 3.0.0, 2.23.2, 2.24.0, 2.22.4, 3.0.0-M2
>
> Time Spent: 20m
> Remaining Estimate: 0h
>
> On attempting to weave a REST-DSL route and replace the route with something
> different, i.e. {color:#d04437}direct:start{color} seems to be fine in
> regards to the produced debug XML ...
> XML before weaving:
> {code:java}
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <route xmlns="http://camel.apache.org/schema/spring"
> customId="true"
> id="apiHeartbeat"
> rest="true">
> <from
> uri="rest://post:/heartbeat:/%7Bsender%7D?description=Test+description&routeId=apiHeartbeat"/>
> <log id="log1"
> message="Received request with payload ${body} and headers:
> ${headers}"/>
> <to id="to1" uri="mock:done"/>
> </route>{code}
> XML after weaving:
> {code:java}
> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
> <route xmlns="http://camel.apache.org/schema/spring"
> customId="true"
> id="apiHeartbeat"
> rest="true">
> <from uri="direct:start"/>
> <log id="log1"
> message="Received request with payload ${body} and headers:
> ${headers}"/>
> <to id="to1" uri="mock:done"/>
> </route>{code}
> ... though on sending a message via a producerTemplate will result in the
> following exception:
> {code:java}
> org.apache.camel.FailedToCreateRouteException: Failed to create route
> apiHeartbeat: Route(apiHeartbeat)[[From[direct://start?routeId=apiHeartbea...
> because of Failed to resolve endpoint: direct://start?routeId=apiHeartbeat
> due to: Failed to resolve endpoint: direct://start?routeId=apiHeartbeat due
> to: There are 1 parameters that couldn't be set on the endpoint. Check the
> uri if the parameters are spelt correctly and that they are properties of the
> endpoint. Unknown parameters=[{routeId=apiHeartbeat}]
> at
> org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:217)
> at
> org.apache.camel.impl.DefaultCamelContext.startRoute(DefaultCamelContext.java:1140)
> at
> org.apache.camel.model.RouteDefinition.adviceWith(RouteDefinition.java:318)
> at
> at.erpel.messaginghub.services.unit.routes.api.CamelRouteAdviceTest.testRouteWeaving(CamelRouteAdviceTest.java:69)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
> at java.lang.reflect.Method.invoke(Method.java:498)
> at
> org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
> at
> org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
> at
> org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
> at
> org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
> at
> org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:74)
> at
> org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:84)
> at
> org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
> at
> org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
> at
> org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
> at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
> at
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:251)
> at
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
> at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
> at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
> at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
> at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
> at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
> at
> org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
> at
> org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
> at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
> at
> org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:190)
> at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
> at
> com.intellij.junit4.JUnit4IdeaTestRunner.startRunnerWithArgs(JUnit4IdeaTestRunner.java:68)
> at
> com.intellij.rt.execution.junit.IdeaTestRunner$Repeater.startRunnerWithArgs(IdeaTestRunner.java:47)
> at
> com.intellij.rt.execution.junit.JUnitStarter.prepareStreamsAndStart(JUnitStarter.java:242)
> at com.intellij.rt.execution.junit.JUnitStarter.main(JUnitStarter.java:70)
> Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve
> endpoint: direct://start?routeId=apiHeartbeat due to: Failed to resolve
> endpoint: direct://start?routeId=apiHeartbeat due to: There are 1 parameters
> that couldn't be set on the endpoint. Check the uri if the parameters are
> spelt correctly and that they are properties of the endpoint. Unknown
> parameters=[{routeId=apiHeartbeat}]
> at
> org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:753)
> at
> org.apache.camel.util.CamelContextHelper.getMandatoryEndpoint(CamelContextHelper.java:80)
> at
> org.apache.camel.model.RouteDefinition.resolveEndpoint(RouteDefinition.java:227)
> at
> org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:116)
> at
> org.apache.camel.impl.DefaultRouteContext.resolveEndpoint(DefaultRouteContext.java:122)
> at
> org.apache.camel.model.FromDefinition.resolveEndpoint(FromDefinition.java:75)
> at
> org.apache.camel.impl.DefaultRouteContext.getEndpoint(DefaultRouteContext.java:98)
> at
> org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:1332)
> at
> org.apache.camel.model.RouteDefinition.addRoutes(RouteDefinition.java:212)
> ... 33 more
> Caused by: org.apache.camel.ResolveEndpointFailedException: Failed to resolve
> endpoint: direct://start?routeId=apiHeartbeat due to: There are 1 parameters
> that couldn't be set on the endpoint. Check the uri if the parameters are
> spelt correctly and that they are properties of the endpoint. Unknown
> parameters=[{routeId=apiHeartbeat}]
> at
> org.apache.camel.impl.DefaultComponent.validateParameters(DefaultComponent.java:215)
> at
> org.apache.camel.impl.DefaultComponent.createEndpoint(DefaultComponent.java:139)
> at
> org.apache.camel.impl.DefaultCamelContext.getEndpoint(DefaultCamelContext.java:706)
> ... 41 more{code}
>
> A code that reproduces this issue is listed below:
> {code:java}
> import java.util.ArrayList;
> import java.util.HashMap;
> import java.util.List;
> import java.util.Map;
> import java.util.UUID;
> import javax.annotation.Resource;
> import javax.servlet.http.HttpServletRequest;
> import org.apache.camel.CamelContext;
> import org.apache.camel.Exchange;
> import org.apache.camel.ProducerTemplate;
> import org.apache.camel.builder.AdviceWithRouteBuilder;
> import org.apache.camel.builder.RouteBuilder;
> import org.apache.camel.component.mock.MockEndpoint;
> import org.apache.camel.model.ModelCamelContext;
> import org.apache.camel.spring.javaconfig.CamelConfiguration;
> import org.apache.camel.test.spring.CamelSpringRunner;
> import org.apache.camel.test.spring.CamelTestContextBootstrapper;
> import org.apache.camel.test.spring.UseAdviceWith;
> import org.apache.commons.codec.binary.Base64;
> import org.junit.Test;
> import org.junit.runner.RunWith;
> import org.springframework.context.annotation.Configuration;
> import org.springframework.mock.web.MockHttpServletRequest;
> import org.springframework.test.context.BootstrapWith;
> import org.springframework.test.context.ContextConfiguration;
> import org.springframework.test.context.support.AnnotationConfigContextLoader;
> @RunWith(CamelSpringRunner.class)
> @BootstrapWith(CamelTestContextBootstrapper.class)
> @ContextConfiguration(
> classes = CamelRouteAdviceTest.Config.class,
> loader = AnnotationConfigContextLoader.class
> )
> @UseAdviceWith
> public class CamelRouteAdviceTest {
> @Configuration
> static class Config extends CamelConfiguration {
> @Override
> public List<RouteBuilder> routes() {
> List<RouteBuilder> routes = new ArrayList<>(1);
> routes.add(new RouteBuilder() {
> @Override
> public void configure() {
> rest("/heartbeat")
> .post("/{sender}")
> .description("Test description")
> .route().routeId("apiHeartbeat")
> .log("Received request with payload ${body} and headers:
> ${headers}")
> .to("mock:done");
> }
> });
> return routes;
> }
> }
> @Resource
> private CamelContext context;
> @Test
> public void testRouteWeaving() throws Exception {
> // Arrange
> context.getRouteDefinitions().get(0).adviceWith((ModelCamelContext)
> context,
> new AdviceWithRouteBuilder() {
> @Override
> public void configure() {
> this.replaceFromWith("direct:start");
> }
> });
> MockEndpoint doneEndpoint = context.getEndpoint("mock:done",
> MockEndpoint.class);
> doneEndpoint.expectedMessageCount(1);
> String sender = UUID.randomUUID().toString();
> HttpServletRequest request = new MockHttpServletRequest("PUT",
> "https://localhost:8383/api/v1/heartbeat/" + sender);
> Map<String, Object> headers = new HashMap<>();
> headers.put(Exchange.HTTP_METHOD, "PUT"); // required for
> check appKey
> headers.put("sender", sender);
> headers.put("Authorization", "Basic " +
> Base64.encodeBase64String(("test:abcd1234").getBytes()));
> headers.put("User-Agent", "Apache-HttpClient/4.5.2 (Java/1.8.0_101)");
> // Act
> ProducerTemplate template = context.createProducerTemplate();
> template.sendBodyAndHeaders("direct:start", request, headers);
> // Assert
> doneEndpoint.assertIsSatisfied();
> }
> }
> {code}
> Commenting out {color:#d04437}routeId("apiHeartbeat"){color} does not solve
> the problem as here {color:#d04437}route1{color} is taken as the routeId and
> appended to the endpoint to invoke
--
This message was sent by Atlassian JIRA
(v7.6.3#76005)