This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit de7502d2c8c1d667784a7bbd17888ad8884ee805 Author: Willian Antunes <willian.lima.antu...@gmail.com> AuthorDate: Tue May 1 16:17:55 2018 -0700 Updated client to be more dynamic (JSON instead of FORM) --- .../camel/component/telegram/service/RestBotAPI.java | 13 +++++-------- .../service/TelegramServiceRestBotAPIAdapter.java | 20 ++++++++++++++------ 2 files changed, 19 insertions(+), 14 deletions(-) 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 99f3ab3..93642cf 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 @@ -17,8 +17,8 @@ package org.apache.camel.component.telegram.service; import java.util.List; + import javax.ws.rs.Consumes; -import javax.ws.rs.FormParam; import javax.ws.rs.GET; import javax.ws.rs.POST; import javax.ws.rs.Path; @@ -27,6 +27,7 @@ import javax.ws.rs.Produces; import javax.ws.rs.QueryParam; import javax.ws.rs.core.MediaType; +import org.apache.camel.component.telegram.model.OutgoingTextMessage; import org.apache.camel.component.telegram.model.UpdateResult; import org.apache.cxf.jaxrs.ext.multipart.Attachment; @@ -50,15 +51,11 @@ public interface RestBotAPI { @POST @Path("/bot{authorizationToken}/sendMessage") - @Consumes(MediaType.APPLICATION_FORM_URLENCODED) + @Consumes(MediaType.APPLICATION_JSON) + @Produces(MediaType.APPLICATION_JSON) void sendMessage( @PathParam("authorizationToken") String authorizationToken, - @FormParam("chat_id") String chatId, - @FormParam("text") String text, - @FormParam("parse_mode") String parseMode, - @FormParam("disable_web_page_preview") Boolean disableWebPagePreview, - @FormParam("disable_notification") Boolean disableNotification, - @FormParam("reply_to_message_id") Long replyToMessageId); + OutgoingTextMessage message); @POST 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 98fd0e8..7e6e7c9 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 @@ -20,11 +20,10 @@ import java.io.ByteArrayInputStream; import java.util.Collections; import java.util.LinkedList; import java.util.List; + import javax.ws.rs.core.MultivaluedHashMap; import javax.ws.rs.core.MultivaluedMap; -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.OutgoingDocumentMessage; @@ -38,6 +37,10 @@ import org.apache.cxf.jaxrs.client.WebClient; import org.apache.cxf.jaxrs.ext.multipart.Attachment; import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition; +import com.fasterxml.jackson.annotation.JsonInclude.Include; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; + /** * Adapts the {@code RestBotAPI} to the {@code TelegramService} interface. */ @@ -46,7 +49,7 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService { private RestBotAPI api; public TelegramServiceRestBotAPIAdapter() { - this.api = JAXRSClientFactory.create(RestBotAPI.BOT_API_DEFAULT_URL, RestBotAPI.class, Collections.singletonList(new JacksonJsonProvider())); + this.api = JAXRSClientFactory.create(RestBotAPI.BOT_API_DEFAULT_URL, RestBotAPI.class, Collections.singletonList(providerByCustomObjectMapper())); WebClient.getConfig(this.api).getHttpConduit().getClient().setAllowChunking(false); } @@ -74,8 +77,7 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService { private void sendMessage(String authorizationToken, OutgoingTextMessage message) { - api.sendMessage(authorizationToken, message.getChatId(), message.getText(), message.getParseMode(), message.getDisableWebPagePreview(), message.getDisableNotification(), message - .getReplyToMessageId()); + api.sendMessage(authorizationToken, message); } @@ -175,4 +177,10 @@ public class TelegramServiceRestBotAPIAdapter implements TelegramService { private String escapeMimeName(String name) { return name.replace("\"", ""); } -} + + private JacksonJsonProvider providerByCustomObjectMapper() { + ObjectMapper mapper = new ObjectMapper(); + mapper.setSerializationInclusion(Include.NON_NULL); + return new JacksonJsonProvider(mapper); + } +} \ No newline at end of file -- To stop receiving notification emails like this one, please contact acosent...@apache.org.