Skip to content

Commit

Permalink
Property substitution doesn't happen in from URI apache#392
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Jul 14, 2020
1 parent 4cdf93e commit 00aeba6
Show file tree
Hide file tree
Showing 34 changed files with 302 additions and 152 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.ChoiceDefinition;
import org.apache.camel.model.OtherwiseDefinition;
import org.apache.camel.model.ProcessorDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.CircuitBreakerDefinition;
import org.apache.camel.model.HystrixConfigurationDefinition;
import org.apache.camel.model.OnFallbackDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.CatchDefinition;
import org.apache.camel.model.FinallyDefinition;
import org.apache.camel.model.ProcessorDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StartStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.RouteDefinition;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.FilterDefinition;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.reifier.FilterReifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,23 @@
*/
package org.apache.camel.k.loader.yaml.parser;

import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.camel.k.annotation.yaml.YAMLNodeDefinition;
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.StartStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.util.URISupport;

@YAMLStepParser(id = "from", definition = FromStepParser.Definition.class)
public class FromStepParser implements StartStepParser {
@Override
public Object process(Context context) {
final Definition definition = context.node(Definition.class);
final String uri = definition.getEndpointUri();
final String uri = StepParserSupport.createEndpointUri(definition.uri, definition.parameters);
final RouteDefinition route = context.builder().from(uri);

// as this is a start converter, steps are mandatory
Expand All @@ -57,21 +53,6 @@ public static final class Definition {
public Map<String, Object> parameters;
@JsonProperty(required = true)
public List<Step> steps;

@JsonIgnore
public String getEndpointUri() {
String answer = uri;

if (parameters != null) {
try {
answer = URISupport.appendParametersToURI(answer, parameters);
} catch (URISyntaxException | UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}

return answer;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.IdempotentConsumerDefinition;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.reifier.IdempotentConsumerReifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.ExpressionSubElementDefinition;
import org.apache.camel.model.LoadBalanceDefinition;
import org.apache.camel.model.LoadBalancerDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.LoopDefinition;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.reifier.LoopReifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.MulticastDefinition;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.reifier.MulticastReifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StartStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.ExpressionSubElementDefinition;
import org.apache.camel.model.OnExceptionDefinition;
import org.apache.camel.model.ProcessorDefinition;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.PipelineDefinition;
import org.apache.camel.model.ProcessorDefinition;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.ResequenceDefinition;
import org.apache.camel.model.config.BatchResequencerConfig;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.StartStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.rest.RestBindingMode;
import org.apache.camel.model.rest.RestDefinition;
import org.apache.camel.util.ObjectHelper;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,28 +16,24 @@
*/
package org.apache.camel.k.loader.yaml.parser;

import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.camel.k.annotation.yaml.YAMLNodeDefinition;
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.StartStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.RouteDefinition;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.URISupport;

@YAMLStepParser(id = "route", definition = RouteStepParser.Definition.class)
public class RouteStepParser implements StartStepParser {
@Override
public Object process(Context context) {
final Definition definition = context.node(Definition.class);
final String uri = definition.from.getEndpointUri();
final String uri = StepParserSupport.createEndpointUri(definition.from.uri, definition.from.parameters);
final RouteDefinition route = context.builder().from(uri);

ObjectHelper.ifNotEmpty(definition.id, route::routeId);
Expand Down Expand Up @@ -78,21 +74,6 @@ public From() {
public From(String uri) {
this.uri = uri;
}

@JsonIgnore
public String getEndpointUri() {
String answer = uri;

if (parameters != null) {
try {
answer = URISupport.appendParametersToURI(answer, parameters);
} catch (URISyntaxException | UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}

return answer;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.SagaDefinition;
import org.apache.camel.reifier.SagaReifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.SamplingDefinition;
import org.apache.camel.reifier.SamplingReifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.SplitDefinition;
import org.apache.camel.reifier.SplitReifier;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.model.Step;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.spi.StepParserSupport;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.StepDefinition;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,23 @@
*/
package org.apache.camel.k.loader.yaml.parser;

import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.camel.k.annotation.yaml.YAMLNodeDefinition;
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.ToDynamicDefinition;
import org.apache.camel.util.URISupport;

@YAMLStepParser(id = "tod", definition = ToDynamicStepParser.Definition.class)
public class ToDynamicStepParser implements ProcessorStepParser {
@Override
public ProcessorDefinition<?> toProcessor(Context context) {
final Definition definition = context.node(Definition.class);
final ToDynamicDefinition answer = new ToDynamicDefinition(definition.getEndpointUri());
final String uri = StepParserSupport.createEndpointUri(definition.getUri(), definition.parameters);
final ToDynamicDefinition answer = new ToDynamicDefinition(uri);

return answer;
}
Expand All @@ -50,21 +48,6 @@ public Definition() {
public Definition(String uri) {
super(uri);
}

@JsonIgnore
public String getEndpointUri() {
String answer = getUri();

if (parameters != null) {
try {
answer = URISupport.appendParametersToURI(answer, parameters);
} catch (URISyntaxException | UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}

return answer;
}
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -16,25 +16,23 @@
*/
package org.apache.camel.k.loader.yaml.parser;

import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.util.Map;

import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonProperty;
import org.apache.camel.k.annotation.yaml.YAMLNodeDefinition;
import org.apache.camel.k.annotation.yaml.YAMLStepParser;
import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser;
import org.apache.camel.k.loader.yaml.support.StepParserSupport;
import org.apache.camel.model.ProcessorDefinition;
import org.apache.camel.model.ToDefinition;
import org.apache.camel.util.URISupport;

@YAMLStepParser(id = "to", definition = ToStepParser.Definition.class)
public class ToStepParser implements ProcessorStepParser {
@Override
public ProcessorDefinition<?> toProcessor(Context context) {
final Definition definition = context.node(Definition.class);
final ToDefinition answer = new ToDefinition(definition.getEndpointUri());
final String uri = StepParserSupport.createEndpointUri(definition.getUri(), definition.parameters);
final ToDefinition answer = new ToDefinition(uri);

return answer;
}
Expand All @@ -50,21 +48,6 @@ public Definition() {
public Definition(String uri) {
super(uri);
}

@JsonIgnore
public String getEndpointUri() {
String answer = uri;

if (parameters != null) {
try {
answer = URISupport.appendParametersToURI(answer, parameters);
} catch (URISyntaxException | UnsupportedEncodingException e) {
throw new RuntimeException(e);
}
}

return answer;
}
}
}

Loading

0 comments on commit 00aeba6

Please sign in to comment.