You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by nf...@apache.org on 2017/01/27 12:56:33 UTC

[1/8] camel git commit: CAMEL-10730: small fixes and source check

Repository: camel
Updated Branches:
  refs/heads/master 4690b070b -> c5570fb17


CAMEL-10730: small fixes and source check


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

Branch: refs/heads/master
Commit: c5570fb1730c0552370a605ec6fbeb1df1618765
Parents: 68c7233
Author: Nicola Ferraro <ni...@gmail.com>
Authored: Fri Jan 27 13:51:45 2017 +0100
Committer: Nicola Ferraro <ni...@gmail.com>
Committed: Fri Jan 27 13:56:19 2017 +0100

----------------------------------------------------------------------
 .../telegram/service/TelegramServiceRestBotAPIAdapter.java       | 4 ++--
 .../apache/camel/component/telegram/util/TelegramConverter.java  | 2 +-
 .../component/telegram/integration/TelegramServiceTest.java      | 3 +--
 .../apache/camel/component/telegram/util/TelegramTestUtil.java   | 2 +-
 .../camel-telegram/src/test/resources/attachments/sample.txt     | 1 +
 5 files changed, 6 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/c5570fb1/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java
index 70dce2d..98fd0e8 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java
@@ -27,8 +27,8 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
 
 import org.apache.camel.component.telegram.TelegramService;
 import org.apache.camel.component.telegram.model.OutgoingAudioMessage;
-import org.apache.camel.component.telegram.model.OutgoingMessage;
 import org.apache.camel.component.telegram.model.OutgoingDocumentMessage;
+import org.apache.camel.component.telegram.model.OutgoingMessage;
 import org.apache.camel.component.telegram.model.OutgoingPhotoMessage;
 import org.apache.camel.component.telegram.model.OutgoingTextMessage;
 import org.apache.camel.component.telegram.model.OutgoingVideoMessage;
@@ -65,7 +65,7 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
             this.sendMessage(authorizationToken, (OutgoingAudioMessage) message);
         } else if (message instanceof OutgoingVideoMessage) {
             this.sendMessage(authorizationToken, (OutgoingVideoMessage) message);
-        } else if(message instanceof OutgoingDocumentMessage) {
+        } else if (message instanceof OutgoingDocumentMessage) {
             this.sendMessage(authorizationToken, (OutgoingDocumentMessage) message);
         } else {
             throw new IllegalArgumentException("Unsupported message type " + (message != null ? message.getClass().getName() : null));

http://git-wip-us.apache.org/repos/asf/camel/blob/c5570fb1/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java
index 81433f0..8ff0832 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java
@@ -168,7 +168,7 @@ public final class TelegramConverter {
 
             result = document;
             break;
-            }
+        }
         }
 
         return result;

http://git-wip-us.apache.org/repos/asf/camel/blob/c5570fb1/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
index bbf7226..376a3ef 100644
--- a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
+++ b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
@@ -187,8 +187,7 @@ public class TelegramServiceTest {
         OutgoingDocumentMessage msg = new OutgoingDocumentMessage();
         msg.setDocument(document);
         msg.setChatId(chatId);
-        msg.setFilenameWithExtension("file.png");
-
+        msg.setFilenameWithExtension("file.txt");
 
         service.sendMessage(authorizationToken, msg);
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/c5570fb1/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/util/TelegramTestUtil.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/util/TelegramTestUtil.java b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/util/TelegramTestUtil.java
index 1479c9c..9f813dd 100644
--- a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/util/TelegramTestUtil.java
+++ b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/util/TelegramTestUtil.java
@@ -59,7 +59,7 @@ public final class TelegramTestUtil {
     }
 
     public static byte[] createSampleDocument() throws IOException {
-        byte[] document = IOUtils.readBytesFromStream(TelegramTestUtil.class.getResourceAsStream("/attachments/sample.png"));
+        byte[] document = IOUtils.readBytesFromStream(TelegramTestUtil.class.getResourceAsStream("/attachments/sample.txt"));
         return document;
     }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/c5570fb1/components/camel-telegram/src/test/resources/attachments/sample.txt
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/test/resources/attachments/sample.txt b/components/camel-telegram/src/test/resources/attachments/sample.txt
new file mode 100644
index 0000000..85dbcfc
--- /dev/null
+++ b/components/camel-telegram/src/test/resources/attachments/sample.txt
@@ -0,0 +1 @@
+A sample text file.
\ No newline at end of file


[4/8] camel git commit: no extension for general file

Posted by nf...@apache.org.
no extension for general file


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

Branch: refs/heads/master
Commit: 17a5a4c9294ed774741196e51f33cab8812bbb3d
Parents: b8d2cdc
Author: Neffez <ma...@steffen-eitelmann.com>
Authored: Fri Jan 20 13:52:33 2017 +0100
Committer: Nicola Ferraro <ni...@gmail.com>
Committed: Fri Jan 27 13:56:19 2017 +0100

----------------------------------------------------------------------
 .../component/telegram/util/TelegramConverter.java | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/17a5a4c9/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java
index cf19994..81433f0 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java
@@ -158,17 +158,16 @@ public final class TelegramConverter {
         }
         case DOCUMENT:
         default: {
-                // this can be any file
-                OutgoingDocumentMessage document = new OutgoingDocumentMessage();
-                String title = (String) exchange.getIn().getHeader(TelegramConstants.TELEGRAM_MEDIA_TITLE_CAPTION);
-                String fileName = "file." + type.getFileExtension();
+            // this can be any file
+            OutgoingDocumentMessage document = new OutgoingDocumentMessage();
+            String title = (String) exchange.getIn().getHeader(TelegramConstants.TELEGRAM_MEDIA_TITLE_CAPTION);
 
-                document.setCaption(title);
-                document.setFilenameWithExtension(fileName);
-                document.setDocument(message);
+            document.setCaption(title);
+            document.setFilenameWithExtension("file");
+            document.setDocument(message);
 
-                result = document;
-                break;
+            result = document;
+            break;
             }
         }
 


[2/8] camel git commit: manage imports

Posted by nf...@apache.org.
manage imports


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

Branch: refs/heads/master
Commit: 5f74b46c67499357af17445dc6a9b86096a1b32d
Parents: bf663f9
Author: Neffez <ma...@steffen-eitelmann.com>
Authored: Fri Jan 20 14:01:51 2017 +0100
Committer: Nicola Ferraro <ni...@gmail.com>
Committed: Fri Jan 27 13:56:19 2017 +0100

----------------------------------------------------------------------
 .../component/telegram/integration/TelegramServiceTest.java   | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/5f74b46c/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
index 43342ae..bbf7226 100644
--- a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
+++ b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
@@ -20,7 +20,12 @@ import java.io.IOException;
 
 import org.apache.camel.component.telegram.TelegramService;
 import org.apache.camel.component.telegram.TelegramServiceProvider;
-import org.apache.camel.component.telegram.model.*;
+import org.apache.camel.component.telegram.model.OutgoingAudioMessage;
+import org.apache.camel.component.telegram.model.OutgoingDocumentMessage;
+import org.apache.camel.component.telegram.model.OutgoingPhotoMessage;
+import org.apache.camel.component.telegram.model.OutgoingTextMessage;
+import org.apache.camel.component.telegram.model.OutgoingVideoMessage;
+import org.apache.camel.component.telegram.model.UpdateResult;
 import org.apache.camel.component.telegram.util.TelegramTestUtil;
 import org.junit.Assert;
 import org.junit.BeforeClass;


[7/8] camel git commit: updated documentation (added type OutgoingDocumentMessage)

Posted by nf...@apache.org.
updated documentation (added type  OutgoingDocumentMessage)


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

Branch: refs/heads/master
Commit: 68c7233a6a61da492308f3a8bd91ecc5d658de75
Parents: 5f74b46
Author: Neffez <ma...@steffen-eitelmann.com>
Authored: Fri Jan 20 14:04:37 2017 +0100
Committer: Nicola Ferraro <ni...@gmail.com>
Committed: Fri Jan 27 13:56:19 2017 +0100

----------------------------------------------------------------------
 components/camel-telegram/src/main/docs/telegram-component.adoc | 1 +
 1 file changed, 1 insertion(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/68c7233a/components/camel-telegram/src/main/docs/telegram-component.adoc
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/main/docs/telegram-component.adoc b/components/camel-telegram/src/main/docs/telegram-component.adoc
index b9bbb42..4b6db56 100644
--- a/components/camel-telegram/src/main/docs/telegram-component.adoc
+++ b/components/camel-telegram/src/main/docs/telegram-component.adoc
@@ -156,6 +156,7 @@ The following message bodies are allowed for a producer endpoint (messages of ty
 | `OutgoingPhotoMessage` | To send a photo (JPG, PNG) to a chat
 | `OutgoingAudioMessage` | To send a mp3 audio to a chat
 | `OutgoingVideoMessage` | To send a mp4 video to a chat
+| `OutgoingDocumentMessage` | To send a file to a chat (any media type)
 | `byte[]` | To send any media type supported. It requires the `CamelTelegramMediaType` header to be set to the appropriate media type
 | `String` | To send a text message to a chat. It gets converted automatically into a `OutgoingTextMessage`
 


[5/8] camel git commit: added support of telegram documents (general files, uncompressed)

Posted by nf...@apache.org.
added support of telegram documents (general files, uncompressed)


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

Branch: refs/heads/master
Commit: e488460548f7f7a2ccacbd56dcd50bc978b64959
Parents: 4690b07
Author: Steffen Eitelmann <ma...@steffen-eitelmann.com>
Authored: Fri Jan 20 13:15:20 2017 +0100
Committer: Nicola Ferraro <ni...@gmail.com>
Committed: Fri Jan 27 13:56:19 2017 +0100

----------------------------------------------------------------------
 .../component/telegram/TelegramMediaType.java   |  2 +-
 .../telegram/model/IncomingDocument.java        | 97 ++++++++++++++++++++
 .../telegram/model/IncomingMessage.java         | 11 +++
 .../telegram/model/OutgoingDocumentMessage.java | 68 ++++++++++++++
 .../component/telegram/service/RestBotAPI.java  |  5 +
 .../TelegramServiceRestBotAPIAdapter.java       | 16 ++++
 .../telegram/util/TelegramConverter.java        | 16 +++-
 7 files changed, 212 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/e4884605/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramMediaType.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramMediaType.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramMediaType.java
index bab9f76..5321f2b 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramMediaType.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/TelegramMediaType.java
@@ -22,7 +22,7 @@ package org.apache.camel.component.telegram;
  */
 public enum TelegramMediaType {
 
-    TEXT("txt"), PHOTO_PNG("png"), PHOTO_JPG("jpg"), AUDIO("mp3"), VIDEO("mp4");
+    TEXT("txt"), PHOTO_PNG("png"), PHOTO_JPG("jpg"), AUDIO("mp3"), VIDEO("mp4"), DOCUMENT("-");
 
     private String fileExtension;
 

http://git-wip-us.apache.org/repos/asf/camel/blob/e4884605/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingDocument.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingDocument.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingDocument.java
new file mode 100644
index 0000000..86c6743
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingDocument.java
@@ -0,0 +1,97 @@
+/**
+ * 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.telegram.model;
+
+import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
+import com.fasterxml.jackson.annotation.JsonProperty;
+
+/**
+ * Contains information about a general file.
+ */
+@JsonIgnoreProperties(ignoreUnknown = true)
+public class IncomingDocument {
+
+    @JsonProperty("file_id")
+    private String fileId;
+
+    @JsonProperty("thumb")
+    private IncomingPhotoSize thumb;
+
+    @JsonProperty("file_name")
+    private String fileName;
+
+    @JsonProperty("mime_type")
+    private String mimeType;
+
+    @JsonProperty("file_size")
+    private Long fileSize;
+
+    public IncomingDocument() {
+    }
+
+    public String getFileId() {
+        return fileId;
+    }
+
+    public void setFileId(String fileId) {
+        this.fileId = fileId;
+    }
+
+    public IncomingPhotoSize getThumb() {
+        return thumb;
+    }
+
+    public void setThumb(IncomingPhotoSize thumb) {
+        this.thumb = thumb;
+    }
+
+    public String getFileName() {
+        return fileName;
+    }
+
+    public void setFileName(String fileName) {
+        this.fileName = fileName;
+    }
+
+    public String getMimeType() {
+        return mimeType;
+    }
+
+    public void setMimeType(String mimeType) {
+        this.mimeType = mimeType;
+    }
+
+    public Long getFileSize() {
+        return fileSize;
+    }
+
+    public void setFileSize(Long fileSize) {
+        this.fileSize = fileSize;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder("IncomingAudio{");
+        sb.append("fileId='").append(fileId).append('\'');
+        sb.append(", thumbSize='").append(thumb).append('\'');
+        sb.append(", fileName='").append(fileName).append('\'');
+        sb.append(", mimeType='").append(mimeType).append('\'');
+        sb.append(", fileSize=").append(fileSize);
+        sb.append('}');
+        return sb.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/e4884605/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingMessage.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingMessage.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingMessage.java
index 66e4d27..44d1fde 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingMessage.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingMessage.java
@@ -50,6 +50,8 @@ public class IncomingMessage implements Serializable {
 
     private IncomingAudio audio;
 
+    private IncomingDocument document;
+
     public IncomingMessage() {
     }
 
@@ -117,6 +119,14 @@ public class IncomingMessage implements Serializable {
         this.audio = audio;
     }
 
+    public IncomingDocument getDocument() {
+        return document;
+    }
+
+    public void setDocument(IncomingDocument document) {
+        this.document = document;
+    }
+
 
     @Override
     public String toString() {
@@ -129,6 +139,7 @@ public class IncomingMessage implements Serializable {
         sb.append(", photo=").append(photo);
         sb.append(", video=").append(video);
         sb.append(", audio=").append(audio);
+        sb.append(", document=").append(document);
         sb.append('}');
         return sb.toString();
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/e4884605/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/OutgoingDocumentMessage.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/OutgoingDocumentMessage.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/OutgoingDocumentMessage.java
new file mode 100644
index 0000000..eea5c5a
--- /dev/null
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/OutgoingDocumentMessage.java
@@ -0,0 +1,68 @@
+/**
+ * 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.telegram.model;
+
+/**
+ * An outgoing document message.
+ */
+public class OutgoingDocumentMessage extends OutgoingMessage {
+
+    private byte[] document;
+
+    private String filenameWithExtension;
+
+    private String caption;
+
+    public OutgoingDocumentMessage() {
+    }
+
+    public byte[] getDocument() {
+        return document;
+    }
+
+    public void setDocument(byte[] document) {
+        this.document = document;
+    }
+
+    public String getFilenameWithExtension() {
+        return filenameWithExtension;
+    }
+
+    public void setFilenameWithExtension(String filenameWithExtension) {
+        this.filenameWithExtension = filenameWithExtension;
+    }
+
+    public String getCaption() {
+        return caption;
+    }
+
+    public void setCaption(String caption) {
+        this.caption = caption;
+    }
+
+    @Override
+    public String toString() {
+        final StringBuilder sb = new StringBuilder("OutgoingVideoMessage{");
+        sb.append("document(length)=").append(document != null ? document.length : null);
+        sb.append(", filenameWithExtension='").append(filenameWithExtension).append('\'');
+        sb.append(", caption='").append(caption).append('\'');
+        sb.append('}');
+        sb.append(' ');
+        sb.append(super.toString());
+        return sb.toString();
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/e4884605/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/RestBotAPI.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/RestBotAPI.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/RestBotAPI.java
index 559f3db..99f3ab3 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/RestBotAPI.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/RestBotAPI.java
@@ -80,4 +80,9 @@ public interface RestBotAPI {
     @Produces(MediaType.APPLICATION_JSON)
     void sendVideo(@PathParam("authorizationToken") String authorizationToken, List<Attachment> attachments);
 
+    @POST
+    @Path("/bot{authorizationToken}/sendDocument")
+    @Consumes(MediaType.MULTIPART_FORM_DATA)
+    @Produces(MediaType.APPLICATION_JSON)
+    void sendDocument(@PathParam("authorizationToken") String authorizationToken, List<Attachment> attachments);
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/e4884605/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java
index 9d14f05..70dce2d 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/service/TelegramServiceRestBotAPIAdapter.java
@@ -28,6 +28,7 @@ import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;
 import org.apache.camel.component.telegram.TelegramService;
 import org.apache.camel.component.telegram.model.OutgoingAudioMessage;
 import org.apache.camel.component.telegram.model.OutgoingMessage;
+import org.apache.camel.component.telegram.model.OutgoingDocumentMessage;
 import org.apache.camel.component.telegram.model.OutgoingPhotoMessage;
 import org.apache.camel.component.telegram.model.OutgoingTextMessage;
 import org.apache.camel.component.telegram.model.OutgoingVideoMessage;
@@ -64,6 +65,8 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
             this.sendMessage(authorizationToken, (OutgoingAudioMessage) message);
         } else if (message instanceof OutgoingVideoMessage) {
             this.sendMessage(authorizationToken, (OutgoingVideoMessage) message);
+        } else if(message instanceof OutgoingDocumentMessage) {
+            this.sendMessage(authorizationToken, (OutgoingDocumentMessage) message);
         } else {
             throw new IllegalArgumentException("Unsupported message type " + (message != null ? message.getClass().getName() : null));
         }
@@ -130,6 +133,19 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService {
         api.sendVideo(authorizationToken, parts);
     }
 
+    private void sendMessage(String authorizationToken, OutgoingDocumentMessage message) {
+        List<Attachment> parts = new LinkedList<>();
+
+        fillCommonMediaParts(parts, message);
+
+        parts.add(buildMediaPart("document", message.getFilenameWithExtension(), message.getDocument()));
+        if (message.getCaption() != null) {
+            parts.add(buildTextPart("caption", message.getCaption()));
+        }
+
+        api.sendDocument(authorizationToken, parts);
+    }
+
     private void fillCommonMediaParts(List<Attachment> parts, OutgoingMessage message) {
         parts.add(buildTextPart("chat_id", message.getChatId()));
 

http://git-wip-us.apache.org/repos/asf/camel/blob/e4884605/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java
index f585a73..cf19994 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/util/TelegramConverter.java
@@ -22,6 +22,7 @@ import org.apache.camel.component.telegram.TelegramConstants;
 import org.apache.camel.component.telegram.TelegramMediaType;
 import org.apache.camel.component.telegram.model.IncomingMessage;
 import org.apache.camel.component.telegram.model.OutgoingAudioMessage;
+import org.apache.camel.component.telegram.model.OutgoingDocumentMessage;
 import org.apache.camel.component.telegram.model.OutgoingMessage;
 import org.apache.camel.component.telegram.model.OutgoingPhotoMessage;
 import org.apache.camel.component.telegram.model.OutgoingTextMessage;
@@ -155,9 +156,20 @@ public final class TelegramConverter {
             result = video;
             break;
         }
+        case DOCUMENT:
         default: {
-            throw new IllegalArgumentException("Unsupported conversion from byte[] to media type " + type);
-        }
+                // this can be any file
+                OutgoingDocumentMessage document = new OutgoingDocumentMessage();
+                String title = (String) exchange.getIn().getHeader(TelegramConstants.TELEGRAM_MEDIA_TITLE_CAPTION);
+                String fileName = "file." + type.getFileExtension();
+
+                document.setCaption(title);
+                document.setFilenameWithExtension(fileName);
+                document.setDocument(message);
+
+                result = document;
+                break;
+            }
         }
 
         return result;


[3/8] camel git commit: fix copy paste error

Posted by nf...@apache.org.
fix copy paste error


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

Branch: refs/heads/master
Commit: b8d2cdce2ba0a033f8e1f898c1b4e0b5e7bd7954
Parents: e488460
Author: Steffen Eitelmann <ma...@steffen-eitelmann.com>
Authored: Fri Jan 20 13:27:54 2017 +0100
Committer: Nicola Ferraro <ni...@gmail.com>
Committed: Fri Jan 27 13:56:19 2017 +0100

----------------------------------------------------------------------
 .../apache/camel/component/telegram/model/IncomingDocument.java    | 2 +-
 .../camel/component/telegram/model/OutgoingDocumentMessage.java    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/b8d2cdce/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingDocument.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingDocument.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingDocument.java
index 86c6743..e90dd6b 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingDocument.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/IncomingDocument.java
@@ -85,7 +85,7 @@ public class IncomingDocument {
 
     @Override
     public String toString() {
-        final StringBuilder sb = new StringBuilder("IncomingAudio{");
+        final StringBuilder sb = new StringBuilder("IncomingDocument{");
         sb.append("fileId='").append(fileId).append('\'');
         sb.append(", thumbSize='").append(thumb).append('\'');
         sb.append(", fileName='").append(fileName).append('\'');

http://git-wip-us.apache.org/repos/asf/camel/blob/b8d2cdce/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/OutgoingDocumentMessage.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/OutgoingDocumentMessage.java b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/OutgoingDocumentMessage.java
index eea5c5a..fbc8ebf 100644
--- a/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/OutgoingDocumentMessage.java
+++ b/components/camel-telegram/src/main/java/org/apache/camel/component/telegram/model/OutgoingDocumentMessage.java
@@ -56,7 +56,7 @@ public class OutgoingDocumentMessage extends OutgoingMessage {
 
     @Override
     public String toString() {
-        final StringBuilder sb = new StringBuilder("OutgoingVideoMessage{");
+        final StringBuilder sb = new StringBuilder("OutgoingDocumentMessage{");
         sb.append("document(length)=").append(document != null ? document.length : null);
         sb.append(", filenameWithExtension='").append(filenameWithExtension).append('\'');
         sb.append(", caption='").append(caption).append('\'');


[6/8] camel git commit: added unit tests for outgoing and incoming documents

Posted by nf...@apache.org.
added unit tests for outgoing and incoming documents


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

Branch: refs/heads/master
Commit: fc745de0c5a1b9423423fe6eb078ace9b76ee53c
Parents: 17a5a4c
Author: Neffez <ma...@steffen-eitelmann.com>
Authored: Fri Jan 20 13:53:06 2017 +0100
Committer: Nicola Ferraro <ni...@gmail.com>
Committed: Fri Jan 27 13:56:19 2017 +0100

----------------------------------------------------------------------
 .../TelegramConsumerMediaDocumentTest.java      | 87 ++++++++++++++++++++
 .../telegram/TelegramProducerMediaTest.java     | 23 ++++++
 .../telegram/util/TelegramTestUtil.java         |  4 +
 .../messages/updates-media-document.json        | 35 ++++++++
 4 files changed, 149 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/fc745de0/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerMediaDocumentTest.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerMediaDocumentTest.java b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerMediaDocumentTest.java
new file mode 100644
index 0000000..268e3ec
--- /dev/null
+++ b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramConsumerMediaDocumentTest.java
@@ -0,0 +1,87 @@
+/**
+ * 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.telegram;
+
+import org.apache.camel.EndpointInject;
+import org.apache.camel.Exchange;
+import org.apache.camel.RoutesBuilder;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.telegram.model.IncomingDocument;
+import org.apache.camel.component.telegram.model.IncomingMessage;
+import org.apache.camel.component.telegram.model.UpdateResult;
+import org.apache.camel.component.telegram.util.TelegramTestSupport;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.when;
+
+/**
+ * Tests the reception of messages without text having media content.
+ */
+public class TelegramConsumerMediaDocumentTest extends TelegramTestSupport {
+
+    @EndpointInject(uri = "mock:telegram")
+    private MockEndpoint endpoint;
+
+    @Before
+    public void mockAPIs() {
+        TelegramService api = mockTelegramService();
+
+        UpdateResult res = getJSONResource("messages/updates-media-document.json", UpdateResult.class);
+
+        UpdateResult defaultRes = getJSONResource("messages/updates-empty.json", UpdateResult.class);
+
+        when(api.getUpdates(any(), any(), any(), any()))
+                .thenReturn(res)
+                .thenAnswer((i) -> defaultRes);
+    }
+
+    @Test
+    public void testReceptionOfMessageWithADocument() throws Exception {
+        endpoint.expectedMinimumMessageCount(1);
+        endpoint.assertIsSatisfied();
+
+        Exchange mediaExchange = endpoint.getExchanges().get(0);
+        IncomingMessage msg = mediaExchange.getIn().getBody(IncomingMessage.class);
+
+        IncomingDocument document = msg.getDocument();
+
+        assertNotNull(document);
+        assertEquals("AgADBAADq6cxG0bQcwnUb4Cga-eXxnodQxkABLXiiSI1vzZK8XXXXXXX", document.getFileId());
+        assertEquals(Long.valueOf(12530), document.getFileSize());
+        assertEquals("file.png", document.getFileName());
+        assertEquals("image/png", document.getMimeType());
+        assertNotNull(document.getThumb());
+        assertEquals(Integer.valueOf(90), document.getThumb().getWidth());
+        assertEquals(Integer.valueOf(80), document.getThumb().getHeight());
+        assertEquals(Long.valueOf(1253), document.getThumb().getFileSize());
+        assertEquals("AgADBAADq6cxG0bQcwnUb4Cga-eXxnodQxkABLXiiSI1vzZK9XXXXXXX", document.getThumb().getFileId());
+    }
+
+    @Override
+    protected RoutesBuilder createRouteBuilder() throws Exception {
+        return new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("telegram:bots/mock-token")
+                        .to("mock:telegram");
+            }
+        };
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/fc745de0/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramProducerMediaTest.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramProducerMediaTest.java b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramProducerMediaTest.java
index 8831ea4..f4a6c02 100644
--- a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramProducerMediaTest.java
+++ b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/TelegramProducerMediaTest.java
@@ -22,6 +22,7 @@ import org.apache.camel.Exchange;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.builder.RouteBuilder;
 import org.apache.camel.component.telegram.model.OutgoingAudioMessage;
+import org.apache.camel.component.telegram.model.OutgoingDocumentMessage;
 import org.apache.camel.component.telegram.model.OutgoingPhotoMessage;
 import org.apache.camel.component.telegram.model.OutgoingVideoMessage;
 import org.apache.camel.component.telegram.util.TelegramTestSupport;
@@ -128,6 +129,28 @@ public class TelegramProducerMediaTest extends TelegramTestSupport {
         assertEquals("Video", captor.getValue().getCaption());
     }
 
+    @Test
+    public void testRouteWithDocument() throws Exception {
+
+        TelegramService service = mockTelegramService();
+
+        Exchange ex = endpoint.createExchange();
+        ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TITLE_CAPTION, "Document");
+        ex.getIn().setHeader(TelegramConstants.TELEGRAM_MEDIA_TYPE, TelegramMediaType.DOCUMENT.name());
+        byte[] document = TelegramTestUtil.createSampleDocument();
+        ex.getIn().setBody(document);
+
+        context().createProducerTemplate().send(endpoint, ex);
+
+        ArgumentCaptor<OutgoingDocumentMessage> captor = ArgumentCaptor.forClass(OutgoingDocumentMessage.class);
+
+        Mockito.verify(service).sendMessage(eq("mock-token"), captor.capture());
+        assertEquals("my-id", captor.getValue().getChatId());
+        assertEquals(document, captor.getValue().getDocument());
+        assertEquals("file", captor.getValue().getFilenameWithExtension());
+        assertEquals("Document", captor.getValue().getCaption());
+    }
+
     @Override
     protected RoutesBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {

http://git-wip-us.apache.org/repos/asf/camel/blob/fc745de0/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/util/TelegramTestUtil.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/util/TelegramTestUtil.java b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/util/TelegramTestUtil.java
index 1457314..1479c9c 100644
--- a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/util/TelegramTestUtil.java
+++ b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/util/TelegramTestUtil.java
@@ -58,4 +58,8 @@ public final class TelegramTestUtil {
         return video;
     }
 
+    public static byte[] createSampleDocument() throws IOException {
+        byte[] document = IOUtils.readBytesFromStream(TelegramTestUtil.class.getResourceAsStream("/attachments/sample.png"));
+        return document;
+    }
 }

http://git-wip-us.apache.org/repos/asf/camel/blob/fc745de0/components/camel-telegram/src/test/resources/messages/updates-media-document.json
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/test/resources/messages/updates-media-document.json b/components/camel-telegram/src/test/resources/messages/updates-media-document.json
new file mode 100644
index 0000000..31891b6
--- /dev/null
+++ b/components/camel-telegram/src/test/resources/messages/updates-media-document.json
@@ -0,0 +1,35 @@
+{
+  "ok": true,
+  "result": [
+    {
+      "update_id": 525704899,
+      "message": {
+        "message_id": 180,
+        "from": {
+          "id": 1585844777,
+          "first_name": "John",
+          "last_name": "Doe"
+        },
+        "chat": {
+          "id": 158584478,
+          "first_name": "John",
+          "last_name": "Doe",
+          "type": "private"
+        },
+        "date": 1463479642,
+        "document": {
+          "file_id": "AgADBAADq6cxG0bQcwnUb4Cga-eXxnodQxkABLXiiSI1vzZK8XXXXXXX",
+          "file_size": 12530,
+          "file_name": "file.png",
+          "mime_type": "image/png",
+          "thumb": {
+            "file_id": "AgADBAADq6cxG0bQcwnUb4Cga-eXxnodQxkABLXiiSI1vzZK9XXXXXXX",
+            "width": 90,
+            "height": 80,
+            "file_size": 1253
+          }
+        }
+      }
+    }
+  ]
+}
\ No newline at end of file


[8/8] camel git commit: added further unit tests for outgoing and incoming documents

Posted by nf...@apache.org.
added further unit tests for outgoing and incoming documents


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

Branch: refs/heads/master
Commit: bf663f9f41fd67b1938a716e2d0e5b8960253c5f
Parents: fc745de
Author: Neffez <ma...@steffen-eitelmann.com>
Authored: Fri Jan 20 13:56:41 2017 +0100
Committer: Nicola Ferraro <ni...@gmail.com>
Committed: Fri Jan 27 13:56:19 2017 +0100

----------------------------------------------------------------------
 .../integration/TelegramServiceTest.java        | 36 +++++++++++++++++---
 1 file changed, 31 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/bf663f9f/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
----------------------------------------------------------------------
diff --git a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
index e1721d7..43342ae 100644
--- a/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
+++ b/components/camel-telegram/src/test/java/org/apache/camel/component/telegram/integration/TelegramServiceTest.java
@@ -20,11 +20,7 @@ import java.io.IOException;
 
 import org.apache.camel.component.telegram.TelegramService;
 import org.apache.camel.component.telegram.TelegramServiceProvider;
-import org.apache.camel.component.telegram.model.OutgoingAudioMessage;
-import org.apache.camel.component.telegram.model.OutgoingPhotoMessage;
-import org.apache.camel.component.telegram.model.OutgoingTextMessage;
-import org.apache.camel.component.telegram.model.OutgoingVideoMessage;
-import org.apache.camel.component.telegram.model.UpdateResult;
+import org.apache.camel.component.telegram.model.*;
 import org.apache.camel.component.telegram.util.TelegramTestUtil;
 import org.junit.Assert;
 import org.junit.BeforeClass;
@@ -177,4 +173,34 @@ public class TelegramServiceTest {
         service.sendMessage(authorizationToken, msg);
     }
 
+    @Test
+    public void testSendDocument() throws IOException {
+        TelegramService service = TelegramServiceProvider.get().getService();
+
+        byte[] document = TelegramTestUtil.createSampleDocument();
+
+        OutgoingDocumentMessage msg = new OutgoingDocumentMessage();
+        msg.setDocument(document);
+        msg.setChatId(chatId);
+        msg.setFilenameWithExtension("file.png");
+
+
+        service.sendMessage(authorizationToken, msg);
+    }
+
+    @Test
+    public void testSendDocumentFull() throws IOException {
+        TelegramService service = TelegramServiceProvider.get().getService();
+
+        byte[] document = TelegramTestUtil.createSampleDocument();
+
+        OutgoingDocumentMessage msg = new OutgoingDocumentMessage();
+        msg.setDocument(document);
+        msg.setChatId(chatId);
+        msg.setFilenameWithExtension("file.png");
+        msg.setCaption("A document");
+
+        service.sendMessage(authorizationToken, msg);
+    }
+
 }