Skip to content

Commit

Permalink
CAMEL-6589: Route should have exactly only 1 input.
Browse files Browse the repository at this point in the history
  • Loading branch information
davsclaus committed Mar 13, 2019
1 parent 773e77d commit 3311ba3
Show file tree
Hide file tree
Showing 7 changed files with 31 additions and 42 deletions.
Expand Up @@ -1026,7 +1026,7 @@ public void process(ComponentDefinitionRegistry componentDefinitionRegistry) {


// regular camel routes // regular camel routes
for (RouteDefinition rd : camelContext.adapt(ModelCamelContext.class).getRouteDefinitions()) { for (RouteDefinition rd : camelContext.adapt(ModelCamelContext.class).getRouteDefinitions()) {
findInputComponents(rd.getInputs(), components, languages, dataformats); findInputComponents(rd.getInput(), components, languages, dataformats);
findOutputComponents(rd.getOutputs(), components, languages, dataformats); findOutputComponents(rd.getOutputs(), components, languages, dataformats);
} }


Expand All @@ -1036,7 +1036,7 @@ public void process(ComponentDefinitionRegistry componentDefinitionRegistry) {
Object o = vd.getToOrRoute(); Object o = vd.getToOrRoute();
if (o instanceof RouteDefinition) { if (o instanceof RouteDefinition) {
RouteDefinition route = (RouteDefinition) o; RouteDefinition route = (RouteDefinition) o;
findInputComponents(route.getInputs(), components, languages, dataformats); findInputComponents(route.getInput(), components, languages, dataformats);
findOutputComponents(route.getOutputs(), components, languages, dataformats); findOutputComponents(route.getOutputs(), components, languages, dataformats);
} else if (o instanceof ToDefinition) { } else if (o instanceof ToDefinition) {
findUriComponent(((ToDefinition) o).getUri(), components); findUriComponent(((ToDefinition) o).getUri(), components);
Expand Down Expand Up @@ -1108,12 +1108,10 @@ public void process(ComponentDefinitionRegistry componentDefinitionRegistry) {


} }


private void findInputComponents(List<FromDefinition> defs, Set<String> components, Set<String> languages, Set<String> dataformats) { private void findInputComponents(FromDefinition from, Set<String> components, Set<String> languages, Set<String> dataformats) {
if (defs != null) { if (from != null) {
for (FromDefinition def : defs) { findUriComponent(from.getUri(), components);
findUriComponent(def.getUri(), components); findSchedulerUriComponent(from.getUri(), components);
findSchedulerUriComponent(def.getUri(), components);
}
} }
} }


Expand Down
Expand Up @@ -34,11 +34,6 @@ public class BlueprintJaxbRestTest extends TestSupport {


@Test @Test
public void test() throws Exception { public void test() throws Exception {
if (isJava16() && isJavaVendor("ibm")) {
// does not test well on java6 with ibm
return;
}

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true); dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder(); DocumentBuilder db = dbf.newDocumentBuilder();
Expand Down
Expand Up @@ -34,11 +34,6 @@ public class BlueprintJaxbTest extends TestSupport {


@Test @Test
public void test() throws Exception { public void test() throws Exception {
if (isJava16() && isJavaVendor("ibm")) {
// does not test well on java6 with ibm
return;
}

DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
dbf.setNamespaceAware(true); dbf.setNamespaceAware(true);
DocumentBuilder db = dbf.newDocumentBuilder(); DocumentBuilder db = dbf.newDocumentBuilder();
Expand All @@ -62,8 +57,7 @@ public void test() throws Exception {
assertNotNull(((CamelContextFactoryBean) object).getRoutes()); assertNotNull(((CamelContextFactoryBean) object).getRoutes());
assertEquals(1, ((CamelContextFactoryBean) object).getRoutes().size()); assertEquals(1, ((CamelContextFactoryBean) object).getRoutes().size());
assertNotNull(((CamelContextFactoryBean) object).getRoutes().get(0)); assertNotNull(((CamelContextFactoryBean) object).getRoutes().get(0));
assertNotNull(((CamelContextFactoryBean) object).getRoutes().get(0).getInputs()); assertNotNull(((CamelContextFactoryBean) object).getRoutes().get(0).getInput());
assertEquals(1, ((CamelContextFactoryBean) object).getRoutes().get(0).getInputs().size());
assertNotNull(((CamelContextFactoryBean) object).getRoutes().get(0).getOutputs()); assertNotNull(((CamelContextFactoryBean) object).getRoutes().get(0).getOutputs());
assertEquals(1, ((CamelContextFactoryBean) object).getRoutes().get(0).getOutputs().size()); assertEquals(1, ((CamelContextFactoryBean) object).getRoutes().get(0).getOutputs().size());
assertTrue(((CamelContextFactoryBean) object).getCamelPropertyPlaceholder().isCache()); assertTrue(((CamelContextFactoryBean) object).getCamelPropertyPlaceholder().isCache());
Expand Down
Expand Up @@ -83,10 +83,8 @@ public void verifyRouteContext() {
assertThat("Route context is incorrect!", routes, hasSize(1)); assertThat("Route context is incorrect!", routes, hasSize(1));
RouteDefinition route = routes.get(0); RouteDefinition route = routes.get(0);


assertThat("Route input is incorrect!", route.getInputs(), hasSize(1));

assertThat("Route is incorrect!", assertThat("Route is incorrect!",
route.getInputs().get(0).getEndpointUri(), is(equalTo("direct:inbound"))); route.getInput().getEndpointUri(), is(equalTo("direct:inbound")));
} }


@Test @Test
Expand Down
Expand Up @@ -35,7 +35,7 @@ public class CometdProducerConsumerInOutInteractiveMain {
private static final String URI = "cometd://127.0.0.1:9091/service/test?baseResource=file:./src/test/resources/webapp&" private static final String URI = "cometd://127.0.0.1:9091/service/test?baseResource=file:./src/test/resources/webapp&"
+ "timeout=240000&interval=0&maxInterval=30000&multiFrameInterval=1500&jsonCommented=true&logLevel=2"; + "timeout=240000&interval=0&maxInterval=30000&multiFrameInterval=1500&jsonCommented=true&logLevel=2";


private static final String URIS = "cometds://127.0.0.1:9443/service/test?baseResource=file:./src/test/resources/webapp&" private static final String URI2 = "cometds://127.0.0.1:9443/service/test?baseResource=file:./src/test/resources/webapp&"
+ "timeout=240000&interval=0&maxInterval=30000&multiFrameInterval=1500&jsonCommented=true&logLevel=2"; + "timeout=240000&interval=0&maxInterval=30000&multiFrameInterval=1500&jsonCommented=true&logLevel=2";


private CamelContext context; private CamelContext context;
Expand Down Expand Up @@ -63,7 +63,14 @@ public void configure() {
URI keyStoreUrl = file.toURI(); URI keyStoreUrl = file.toURI();
component.setSslKeystore(keyStoreUrl.getPath()); component.setSslKeystore(keyStoreUrl.getPath());


from(URI, URIS).setExchangePattern(ExchangePattern.InOut).process(new Processor() { from(URI).setExchangePattern(ExchangePattern.InOut).process(new Processor() {
public void process(Exchange exchange) throws Exception {
Message out = new DefaultMessage(exchange.getContext());
out.setBody("reply: " + exchange.getIn().getBody());
exchange.setOut(out);
}
});
from(URI2).setExchangePattern(ExchangePattern.InOut).process(new Processor() {
public void process(Exchange exchange) throws Exception { public void process(Exchange exchange) throws Exception {
Message out = new DefaultMessage(exchange.getContext()); Message out = new DefaultMessage(exchange.getContext());
out.setBody("reply: " + exchange.getIn().getBody()); out.setBody("reply: " + exchange.getIn().getBody());
Expand Down
Expand Up @@ -228,23 +228,20 @@ public CamelContextBuilder getCamelContextBuilder() {


protected void annotateKJarRoutes(RoutesDefinition routes, String deploymentId) { protected void annotateKJarRoutes(RoutesDefinition routes, String deploymentId) {
for (RouteDefinition route : routes.getRoutes()) { for (RouteDefinition route : routes.getRoutes()) {

FromDefinition from = route.getInput();
for (FromDefinition from : route.getInputs()) { if (from.getUri().startsWith("jbpm:events") && !from.getUri().contains("deploymentId")) {

StringBuilder uri = new StringBuilder(from.getUri());
if (from.getUri().startsWith("jbpm:events") && !from.getUri().contains("deploymentId")) {
StringBuilder uri = new StringBuilder(from.getUri()); String[] split = from.getUri().split("\\?");

if (split.length == 1) {
String[] split = from.getUri().split("\\?"); // no query given
if (split.length == 1) { uri.append("?");
// no query given } else {
uri.append("?"); // already query params exist
} else { uri.append("&");
// already query params exist
uri.append("&");
}
uri.append("deploymentId=").append(deploymentId);
from.setUri(uri.toString());
} }
uri.append("deploymentId=").append(deploymentId);
from.setUri(uri.toString());
} }
} }
} }
Expand Down
Expand Up @@ -36,7 +36,7 @@ public void testCustomId() {
assertNotNull(route); assertNotNull(route);
assertTrue(route.hasCustomIdAssigned()); assertTrue(route.hasCustomIdAssigned());


FromDefinition from = route.getInputs().get(0); FromDefinition from = route.getInput();
assertEquals("fromFile", from.getId()); assertEquals("fromFile", from.getId());
assertTrue(from.hasCustomIdAssigned()); assertTrue(from.hasCustomIdAssigned());


Expand Down

0 comments on commit 3311ba3

Please sign in to comment.