summaryrefslogtreecommitdiffstats
path: root/sample-apps/http-api-using-searcher/src/main/java/com/yahoo/demo/DemoHandler.java
diff options
context:
space:
mode:
authorKristian Aune <kraune@yahoo-inc.com>2017-06-13 12:51:11 +0200
committerKristian Aune <kraune@yahoo-inc.com>2017-06-13 12:51:11 +0200
commit7914f1fe5b3e7e0e73534fb800315a6b55622f6d (patch)
tree4f0869586950ade87618bd588d1d01749fdb4976 /sample-apps/http-api-using-searcher/src/main/java/com/yahoo/demo/DemoHandler.java
parent9fe6a9f635a5277d6d6c58ccbe5b279449e016c1 (diff)
Sample app for handler and searcher
- first cut, not properly tested yet
Diffstat (limited to 'sample-apps/http-api-using-searcher/src/main/java/com/yahoo/demo/DemoHandler.java')
-rw-r--r--sample-apps/http-api-using-searcher/src/main/java/com/yahoo/demo/DemoHandler.java50
1 files changed, 50 insertions, 0 deletions
diff --git a/sample-apps/http-api-using-searcher/src/main/java/com/yahoo/demo/DemoHandler.java b/sample-apps/http-api-using-searcher/src/main/java/com/yahoo/demo/DemoHandler.java
new file mode 100644
index 00000000000..cf14f6d58cd
--- /dev/null
+++ b/sample-apps/http-api-using-searcher/src/main/java/com/yahoo/demo/DemoHandler.java
@@ -0,0 +1,50 @@
+// Copyright 2016 Yahoo Inc. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
+package com.yahoo.demo;
+
+import com.google.inject.Inject;
+import com.yahoo.container.jdisc.HttpRequest;
+import com.yahoo.container.jdisc.HttpResponse;
+import com.yahoo.container.jdisc.LoggingRequestHandler;
+import com.yahoo.container.logging.AccessLog;
+import com.yahoo.search.handler.SearchHandler;
+import com.yahoo.search.query.Model;
+import com.yahoo.search.query.Presentation;
+
+import java.util.concurrent.Executor;
+
+/**
+ * Forward requests to search handler after adding "Red Hat" as query and "demo"
+ * as renderer ID.
+ */
+public class DemoHandler extends LoggingRequestHandler {
+
+ private final SearchHandler searchHandler;
+
+ /**
+ * Constructor for use in injection. The requested objects are subclasses of
+ * component or have dedicated providers, so the container will know how to
+ * create this handler.
+ *
+ * @param executor
+ * threadpool, provided by Vespa
+ * @param accessLog
+ * access log for incoming queries, provided by Vespa
+ * @param searchHandler
+ * the Vespa search handler, also automatically injected
+ */
+ @Inject
+ public DemoHandler(Executor executor, AccessLog accessLog,
+ SearchHandler searchHandler) {
+ super(executor, accessLog, null, true);
+ this.searchHandler = searchHandler;
+ }
+
+ @Override
+ public HttpResponse handle(HttpRequest request) {
+ HttpRequest searchRequest = new HttpRequest.Builder(request)
+ .put(Model.QUERY_STRING, "Red Hat")
+ .put(Presentation.FORMAT, "demo").createDirectRequest();
+ HttpResponse r = searchHandler.handle(searchRequest);
+ return r;
+ }
+}