Repository: camel
Updated Branches:
  refs/heads/camel-2.18.x dd9e89637 -> a6c3c86a8
  refs/heads/camel-2.19.x 09e8a0a8e -> c16ab4d04
  refs/heads/master 59fbba739 -> 175635f4a


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/175635f4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/175635f4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/175635f4

Branch: refs/heads/master
Commit: 175635f4adf4d3b1521bd7c6ea2add4b04b89f1c
Parents: 59fbba7
Author: Andy Bell <andyrb...@gmail.com>
Authored: Thu Jul 6 23:37:38 2017 +0100
Committer: Andy Bell <andyrb...@gmail.com>
Committed: Thu Jul 6 23:37:38 2017 +0100

----------------------------------------------------------------------
 .../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/175635f4/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/175635f4/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());

Reply via email to