Uploaded image for project: 'Camel'
  1. Camel
  2. CAMEL-13162

Unknown parameter issue on weaving from-with on a REST-DSL route

    XMLWordPrintableJSON

    Details

    • Type: Bug
    • Status: Resolved
    • Priority: Minor
    • Resolution: Fixed
    • Affects Version/s: 2.23.0, 2.23.1
    • Fix Version/s: 2.23.2, 2.24.0, 3.0.0-M2, 3.0.0
    • Component/s: camel-test
    • Labels:
      None
    • Estimated Complexity:
      Unknown

      Description

      On attempting to weave a REST-DSL route and replace the route with something different, i.e. direct:start seems to be fine in regards to the produced debug XML ...

      XML before weaving:

      <?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&amp;routeId=apiHeartbeat"/>
          <log id="log1"
              message="Received request with payload ${body} and headers: ${headers}"/>
          <to id="to1" uri="mock:done"/>
      </route>

      XML after weaving:

      <?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>

      ... though on sending a message via a producerTemplate will result in the following exception:

      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

       

      A code that reproduces this issue is listed below:

      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();
        }
      }
      

      Commenting out routeId("apiHeartbeat") does not solve the problem as here route1 is taken as the routeId and appended to the endpoint to invoke

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                dmvolod Dmitry Volodin
                Reporter:
                Rovo Roman Vottner
              • Votes:
                0 Vote for this issue
                Watchers:
                3 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:

                  Time Tracking

                  Estimated:
                  Original Estimate - Not Specified
                  Not Specified
                  Remaining:
                  Remaining Estimate - 0h
                  0h
                  Logged:
                  Time Spent - 20m
                  20m