SearchFormServlet.java
3.86 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* javax.servlet.ServletException
* org.apache.commons.lang3.StringEscapeUtils
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Properties
* org.apache.felix.scr.annotations.Property
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.api.SlingHttpServletResponse
* org.apache.sling.api.servlets.SlingAllMethodsServlet
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.io.JSONWriter
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.searchpromote.impl.servlet;
import com.day.cq.searchpromote.SearchPromoteException;
import com.day.cq.searchpromote.SearchPromoteService;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.Writer;
import javax.servlet.ServletException;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Properties;
import org.apache.felix.scr.annotations.Property;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.api.SlingHttpServletResponse;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.io.JSONWriter;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(metatype=0)
@Service
@Properties(value={@Property(name="sling.servlet.paths", value={"/libs/cq/searchpromote/searchform"}), @Property(name="sling.servlet.methods", value={"POST"})})
public class SearchFormServlet
extends SlingAllMethodsServlet {
private final Logger log;
private static final String PARAM_MEMBERID = "memberid";
private static final String PARAM_ACCOUNTNO = "accountno";
@Reference
private SearchPromoteService searchpromote;
public SearchFormServlet() {
this.log = LoggerFactory.getLogger(this.getClass());
}
/*
* WARNING - Removed try catching itself - possible behaviour change.
*/
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
String memberId = request.getParameter("memberid");
String accountNo = request.getParameter("accountno");
PrintWriter out = response.getWriter();
JSONWriter writer = new JSONWriter((Writer)out);
try {
String searchformXml = this.searchpromote.getSearchForm(memberId, accountNo);
if (searchformXml.endsWith("html>")) {
this.log.warn("Search form XML could not be found for {}-{}", (Object)memberId, (Object)accountNo);
throw new SearchPromoteException("Credentials invalid");
}
writer.object();
writer.key("xml").value((Object)StringEscapeUtils.escapeXml((String)searchformXml));
writer.endObject();
}
catch (Exception e) {
this.log.error(e.getMessage(), (Throwable)e);
try {
writer.object();
writer.key("error").value((Object)e.getMessage());
writer.endObject();
}
catch (JSONException ignored) {
this.log.error(ignored.getMessage(), (Throwable)ignored);
}
}
finally {
out.flush();
}
}
protected void bindSearchpromote(SearchPromoteService searchPromoteService) {
this.searchpromote = searchPromoteService;
}
protected void unbindSearchpromote(SearchPromoteService searchPromoteService) {
if (this.searchpromote == searchPromoteService) {
this.searchpromote = null;
}
}
}