CAMEL-11469 Use remainder of uri to parse config The configuration now uses the remainder of the uri to parse out the properties. This can now cope with a '//' or not and stops further string manipulation where it isn't needed
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a2029608 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a2029608 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a2029608 Branch: refs/heads/camel-2.19.x Commit: a20296085980771200ae3d59c93e0c04e6f5ae80 Parents: d922ad6 Author: Paul Watson <paul.wat...@pdwtech.com> Authored: Tue Jun 27 22:51:15 2017 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Jun 28 18:30:45 2017 +0200 ---------------------------------------------------------------------- .../component/hipchat/HipchatComponent.java | 8 +-- .../HipchatXmlDefinedComponentProducerTest.java | 66 ++++++++++++++++++++ ...hatXmlDefinedComponentProducerTest-route.xml | 30 +++++++++ 3 files changed, 99 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/a2029608/components/camel-hipchat/src/main/java/org/apache/camel/component/hipchat/HipchatComponent.java ---------------------------------------------------------------------- diff --git a/components/camel-hipchat/src/main/java/org/apache/camel/component/hipchat/HipchatComponent.java b/components/camel-hipchat/src/main/java/org/apache/camel/component/hipchat/HipchatComponent.java index 47ed883..fc12ef6 100644 --- a/components/camel-hipchat/src/main/java/org/apache/camel/component/hipchat/HipchatComponent.java +++ b/components/camel-hipchat/src/main/java/org/apache/camel/component/hipchat/HipchatComponent.java @@ -53,15 +53,13 @@ public class HipchatComponent extends UriEndpointComponent { if (endpoint.getConfiguration().getAuthToken() == null) { throw new HipchatException("OAuth 2 auth token must be specified"); } - parseUri(uri, endpoint); + parseUri(remaining, endpoint); LOG.debug("Using Hipchat API URL: {}", endpoint.getConfiguration().hipChatUrl()); return endpoint; } - private void parseUri(String uri, HipchatEndpoint endpoint) throws Exception { - // strip scheme - uri = ObjectHelper.after(uri, ":"); - uri = URISupport.normalizeUri(uri); + private void parseUri(String remaining, HipchatEndpoint endpoint) throws Exception { + String uri = URISupport.normalizeUri(remaining); URI hipChatUri = new URI(uri); if (hipChatUri.getHost() != null) { http://git-wip-us.apache.org/repos/asf/camel/blob/a2029608/components/camel-hipchat/src/test/java/org/apache/camel/component/hipchat/HipchatXmlDefinedComponentProducerTest.java ---------------------------------------------------------------------- diff --git a/components/camel-hipchat/src/test/java/org/apache/camel/component/hipchat/HipchatXmlDefinedComponentProducerTest.java b/components/camel-hipchat/src/test/java/org/apache/camel/component/hipchat/HipchatXmlDefinedComponentProducerTest.java new file mode 100644 index 0000000..589a83b --- /dev/null +++ b/components/camel-hipchat/src/test/java/org/apache/camel/component/hipchat/HipchatXmlDefinedComponentProducerTest.java @@ -0,0 +1,66 @@ +/** + * 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. + */ +package org.apache.camel.component.hipchat; + +import java.io.InputStream; +import org.apache.camel.CamelContext; +import org.apache.camel.Endpoint; +import org.apache.camel.EndpointInject; +import org.apache.camel.model.ModelHelper; +import org.apache.camel.model.RoutesDefinition; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.junit.Test; + + +import static org.hamcrest.core.Is.is; + +public class HipchatXmlDefinedComponentProducerTest extends CamelTestSupport { + + @EndpointInject(uri = "hipchat:https:foobar.com:443?authToken=abc123") + protected Endpoint endpoint; + + @Test + public void shouldConfigureEndpointCorrectlyViaXml() throws Exception { + assertIsInstanceOf(HipchatEndpoint.class, endpoint); + HipchatEndpoint hipchatEndpoint = (HipchatEndpoint) endpoint; + HipchatConfiguration configuration = hipchatEndpoint.getConfiguration(); + assertThat(configuration.getAuthToken(), is("abc123")); + assertThat(configuration.getHost(), is("foobar.com")); + assertThat(configuration.getProtocol(), is("https")); + assertThat(configuration.getPort(), is(443)); + } + + @Override + protected CamelContext createCamelContext() throws Exception { + final CamelContext context = super.createCamelContext(); + HipchatComponent component = new HipchatComponent(context) { + @Override + protected HipchatEndpoint getHipchatEndpoint(String uri) { + return new HipchatEPSuccessTestSupport(uri, this, null, null); + } + }; + context.addComponent("hipchat", component); + + // This test is all about ensuring the endpoint is configured correctly when using the XML DSL so this + try (InputStream routes = getClass().getResourceAsStream("HipchatXmlDefinedComponentProducerTest-route.xml")) { + RoutesDefinition routesDefinition = ModelHelper.loadRoutesDefinition(context, routes); + context.addRouteDefinition(routesDefinition.getRoutes().get(0)); + } + + return context; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/a2029608/components/camel-hipchat/src/test/resources/org/apache/camel/component/hipchat/HipchatXmlDefinedComponentProducerTest-route.xml ---------------------------------------------------------------------- diff --git a/components/camel-hipchat/src/test/resources/org/apache/camel/component/hipchat/HipchatXmlDefinedComponentProducerTest-route.xml b/components/camel-hipchat/src/test/resources/org/apache/camel/component/hipchat/HipchatXmlDefinedComponentProducerTest-route.xml new file mode 100644 index 0000000..cf1e827 --- /dev/null +++ b/components/camel-hipchat/src/test/resources/org/apache/camel/component/hipchat/HipchatXmlDefinedComponentProducerTest-route.xml @@ -0,0 +1,30 @@ +<?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. + +--> +<routes xmlns="http://camel.apache.org/schema/spring" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://camel.apache.org/schema/spring + http://camel.apache.org/schema/spring/camel-spring.xsd"> + + <route id="hipchatTest"> + <from uri="direct://foo"/> + <to id="hipchat" uri="hipchat:https:foobar.com:443?authToken=abc123"/> + </route> + +</routes> \ No newline at end of file