You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by GitBox <gi...@apache.org> on 2019/08/15 17:02:21 UTC

[GitHub] [camel-quarkus] lburgazzoli commented on a change in pull request #138: Add tests to the twitter itest project

lburgazzoli commented on a change in pull request #138: Add tests to the twitter itest project
URL: https://github.com/apache/camel-quarkus/pull/138#discussion_r314405007
 
 

 ##########
 File path: integration-tests/twitter/src/main/java/org/apache/camel/quarkus/component/twitter/CamelRoute.java
 ##########
 @@ -16,25 +16,118 @@
  */
 package org.apache.camel.quarkus.component.twitter;
 
-import io.quarkus.runtime.annotations.RegisterForReflection;
+import java.util.Arrays;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.camel.Exchange;
 import org.apache.camel.builder.RouteBuilder;
-import org.eclipse.microprofile.config.inject.ConfigProperty;
+import org.apache.camel.component.twitter.TwitterConstants;
 
-@RegisterForReflection
 public class CamelRoute extends RouteBuilder {
 
-    @ConfigProperty(name = "twitter.user.name")
-    String twitterUserName;
+    private static final Set<String> TWITTER_SEARCH_HEADERS = new HashSet<>(
+            Arrays.asList(TwitterConstants.TWITTER_COUNT, TwitterConstants.TWITTER_KEYWORDS,
+                    TwitterConstants.TWITTER_MAXID, TwitterConstants.TWITTER_NUMBER_OF_PAGES,
+                    TwitterConstants.TWITTER_SEARCH_LANGUAGE, TwitterConstants.TWITTER_SINCEID));
+
+    private final StringBuilder ownTweets = new StringBuilder();
+    private final StringBuilder directMessages = new StringBuilder();
 
     @Override
     public void configure() {
-        from("twitter-timeline:user?user=ApacheCamel&count=1")
-            .to("log:timeline?showAll=true");
+        rest()
+            .get("/timeline")
+                /* Expose the polled messages */
+                .route()
+                .id("get-timeline")
+                .setBody(() -> {
+                    synchronized (ownTweets) {
+                        return ownTweets.toString();
+                    }
+                })
+                .endRest()
+            .post("/timeline")
+                .route()
+                .id("post-timeline")
+                .to("twitter-timeline://user")
+                .setHeader(Exchange.HTTP_RESPONSE_CODE, simple("201"))
+                .endRest()
+
+            .get("/search")
+                .route()
+                .id("get-search")
+                // The servlet component does not pass the query params as camel message headers for some reason
+                .process(e -> {
+                    final String query = e.getIn().getHeader("CamelHttpQuery", String.class);
+                    for (String kv : query.split("&")) {
+                        final String[] keyVal = kv.split("=");
+                        if (TWITTER_SEARCH_HEADERS.contains(keyVal[0])) {
+                            // Consider URL decoding if you copy this to production code
+                            e.getOut().setHeader(keyVal[0], keyVal[1]);
+                        }
+                    }
+                })
+                .to("twitter-search://_keywords_passed_via_CamelTwitterKeywords_header_")
+                .to("log:search?showAll=true")
+                .endRest()
+
+            .post("/directmessage")
+                .route()
+                .id("post-directmessage")
+                .to("twitter-directmessage://{{camel.component.twitter-directmessage.user}}")
 
 Review comment:
   `camel.component.twitter-directmessage` is a syntax used to automatically bind properties to a component so I would use a property like `twitter.user` to avoid confusion

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services