camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/3] camel git commit: CAMEL-11520 URL-encode hipchat room names
Date Fri, 07 Jul 2017 07:41:28 GMT
CAMEL-11520 URL-encode hipchat room names

This allows messages to be sent to room names containing spaces or other URL-unsafe characters.

Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/a6c3c86a
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a6c3c86a
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a6c3c86a

Branch: refs/heads/camel-2.18.x
Commit: a6c3c86a84ececb6fd70f31c613239b7c8b08e3f
Parents: dd9e896
Author: Andy Bell <andyrbell@gmail.com>
Authored: Thu Jul 6 23:37:38 2017 +0100
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Fri Jul 7 09:41:18 2017 +0200

----------------------------------------------------------------------
 .../camel/component/hipchat/HipchatProducer.java   |  5 ++++-
 .../HipchatProducerIntegrationTest.java            | 17 +++++++++++++++++
 2 files changed, 21 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a6c3c86a/components/camel-hipchat/src/main/java/org/apache/camel/component/hipchat/HipchatProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-hipchat/src/main/java/org/apache/camel/component/hipchat/HipchatProducer.java
b/components/camel-hipchat/src/main/java/org/apache/camel/component/hipchat/HipchatProducer.java
index 0a580ff..7df991b 100644
--- a/components/camel-hipchat/src/main/java/org/apache/camel/component/hipchat/HipchatProducer.java
+++ b/components/camel-hipchat/src/main/java/org/apache/camel/component/hipchat/HipchatProducer.java
@@ -27,6 +27,7 @@ import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.Message;
 import org.apache.camel.impl.DefaultProducer;
 import org.apache.camel.util.URISupport;
+import org.apache.camel.util.UnsafeUriCharactersEncoder;
 import org.apache.http.StatusLine;
 import org.apache.http.client.methods.CloseableHttpResponse;
 import org.apache.http.client.methods.HttpPost;
@@ -37,6 +38,8 @@ import org.apache.http.impl.client.HttpClients;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
+import static org.apache.camel.util.UnsafeUriCharactersEncoder.encodeHttpURI;
+
 /**
  * The Hipchat producer to send message to a user and/or a room.
  */
@@ -71,7 +74,7 @@ public class HipchatProducer extends DefaultProducer {
             jsonParam.put(HipchatApiConstants.API_MESSAGE_COLOR, backGroundColor);
         }
         LOG.info("Sending message to room: " + room + ", " + MAPPER.writeValueAsString(jsonParam));
-        StatusLine statusLine = post(urlPath, jsonParam);
+        StatusLine statusLine = post(encodeHttpURI(urlPath), jsonParam);
         LOG.debug("Response status for send room message: " + statusLine);
         return statusLine;
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/a6c3c86a/components/camel-hipchat/src/test/java/org/apache/camel/component/hipchat/integration/HipchatProducerIntegrationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-hipchat/src/test/java/org/apache/camel/component/hipchat/integration/HipchatProducerIntegrationTest.java
b/components/camel-hipchat/src/test/java/org/apache/camel/component/hipchat/integration/HipchatProducerIntegrationTest.java
index 071c0a1..7dfbe24 100644
--- a/components/camel-hipchat/src/test/java/org/apache/camel/component/hipchat/integration/HipchatProducerIntegrationTest.java
+++ b/components/camel-hipchat/src/test/java/org/apache/camel/component/hipchat/integration/HipchatProducerIntegrationTest.java
@@ -72,6 +72,23 @@ public class HipchatProducerIntegrationTest extends CamelTestSupport {
 
     }
 
+    @Test
+    public void sendToUriUnsafeRoomName() throws Exception {
+        result.expectedMessageCount(1);
+
+        Exchange exchange1 = template.send("direct:start", ExchangePattern.InOnly, new Processor()
{
+            public void process(Exchange exchange) throws Exception {
+                exchange.getIn().setHeader(HipchatConstants.TO_ROOM, "Camel Test");
+                exchange.getIn().setHeader(HipchatConstants.TO_USER, "@ShreyasPurohit");
+                exchange.getIn().setBody("A room with spaces");
+            }
+        });
+
+        assertMockEndpointsSatisfied();
+
+        assertResponseMessage(exchange1.getIn());
+    }
+
     private void assertResponseMessage(Message message) {
         assertEquals(204, message.getHeader(HipchatConstants.TO_ROOM_RESPONSE_STATUS, StatusLine.class).getStatusCode());
         assertEquals(204, message.getHeader(HipchatConstants.TO_USER_RESPONSE_STATUS, StatusLine.class).getStatusCode());


Mime
View raw message