RemoteIndexCallServlet.java
5.47 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.wcm.webservicesupport.Configuration
* com.day.cq.wcm.webservicesupport.ConfigurationManager
* com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory
* javax.servlet.ServletException
* org.apache.commons.lang3.StringUtils
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.sling.SlingServlet
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.servlets.SlingAllMethodsServlet
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.searchpromote.feed.impl.servlet;
import com.day.cq.searchpromote.SearchPromoteException;
import com.day.cq.searchpromote.SearchPromoteService;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import org.apache.commons.lang3.StringUtils;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SlingServlet(name="com.day.cq.searchpromote.feed.impl.servlet.RemoteIndexCallServlet", description="Calls the remote index retrieval for Search&Promote", paths={"/libs/cq/searchpromote/remoteindex"}, methods={"POST"})
public class RemoteIndexCallServlet
extends SlingAllMethodsServlet {
private final Logger log;
@Reference
private SearchPromoteService searchPromoteService;
@Reference
private ConfigurationManagerFactory configManagerFactory;
private static final String INDEX_ALL_PARAM_KEY = "fullfeed";
private static final String SP_ACCOUNT_PARAM_KEY = "sp_account";
private static final String INDEX_PASS_PARAM_KEY = "index_password";
private static final String BAD_REQUEST_ERR = "Some of the required parameters are missing (sp_account or index_password)";
public RemoteIndexCallServlet() {
this.log = LoggerFactory.getLogger(this.getClass());
}
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
String configPath = request.getParameter("configPath");
Configuration confObject = this.configManagerFactory.getConfigurationManager(request.getResourceResolver()).getConfiguration(configPath);
String indexPass = (String)confObject.get("remotectlpass", (Object)"");
String spAccount = (String)confObject.getInherited("accountno", (Object)"");
String fullIndex = request.getParameter("fullfeed");
boolean fullFeedRequested = StringUtils.isNotEmpty((CharSequence)fullIndex) && Boolean.TRUE.toString().equals(fullIndex);
this.log.debug("Calling remote index for account {} (password {})", (Object)spAccount, (Object)indexPass);
if (StringUtils.isEmpty((CharSequence)spAccount) || StringUtils.isEmpty((CharSequence)indexPass)) {
this.log.error("Some of the required parameters are missing (sp_account or index_password)");
response.sendError(400, "Some of the required parameters are missing (sp_account or index_password)");
}
try {
String responseStatus = this.searchPromoteService.callRemoteIndex(spAccount, indexPass, fullFeedRequested);
this.log.debug("Indexing requested, response status was {}", (Object)responseStatus);
this.sendResponse(responseStatus, response);
}
catch (SearchPromoteException e) {
this.log.error(e.getMessage(), (Throwable)e);
response.sendError(500, e.getMessage());
}
catch (JSONException e) {
response.sendError(500, e.getMessage());
}
}
private void sendResponse(String responseCode, SlingHttpServletResponse response) throws JSONException, IOException {
JSONObject jsonObject = new JSONObject();
jsonObject.append("status_code", (Object)responseCode);
response.setContentType("application/json");
response.setStatus(200);
PrintWriter out = response.getWriter();
out.write(jsonObject.toString());
}
protected void bindSearchPromoteService(SearchPromoteService searchPromoteService) {
this.searchPromoteService = searchPromoteService;
}
protected void unbindSearchPromoteService(SearchPromoteService searchPromoteService) {
if (this.searchPromoteService == searchPromoteService) {
this.searchPromoteService = null;
}
}
protected void bindConfigManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
this.configManagerFactory = configurationManagerFactory;
}
protected void unbindConfigManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
if (this.configManagerFactory == configurationManagerFactory) {
this.configManagerFactory = null;
}
}
}