MboxListServlet.java
4.11 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
/*
* 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
* com.google.gson.Gson
* javax.servlet.ServletException
* 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.Resource
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.api.servlets.SlingSafeMethodsServlet
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.analytics.testandtarget.impl.servlets;
import com.day.cq.analytics.testandtarget.TestandtargetService;
import com.day.cq.wcm.webservicesupport.Configuration;
import com.day.cq.wcm.webservicesupport.ConfigurationManager;
import com.day.cq.wcm.webservicesupport.ConfigurationManagerFactory;
import com.google.gson.Gson;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.ServletException;
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.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.servlets.SlingSafeMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SlingServlet(generateComponent=1, methods={"GET"}, extensions={"json"}, selectors={"mboxlist"}, resourceTypes={"cq/analytics/components/testandtargetpage", "cq/analytics/components/cbframework"}, label="Adobe Target Integration Mbox List Servlet", description="Provides the mbox names list in JSON format")
public class MboxListServlet
extends SlingSafeMethodsServlet {
private final Logger LOGGER;
@Reference
private ConfigurationManagerFactory cfgManagerFactory;
@Reference
private TestandtargetService tntService;
public MboxListServlet() {
this.LOGGER = LoggerFactory.getLogger(this.getClass());
}
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
Resource tntConfigResource = request.getResource();
if (tntConfigResource != null) {
ConfigurationManager cfgManager = this.cfgManagerFactory.getConfigurationManager(tntConfigResource.getResourceResolver());
Configuration tntConfig = cfgManager.getConfiguration(tntConfigResource.getParent().getPath());
if (tntConfig != null) {
try {
List<String> mboxList = this.tntService.listMboxNames(tntConfig);
response.setContentType("application/json");
response.setStatus(200);
response.getWriter().write(new Gson().toJson(mboxList));
}
catch (Exception e) {
response.setStatus(500);
this.LOGGER.error("Can't get the mbox list for TnT configuration " + tntConfigResource.getPath(), (Throwable)e);
}
} else {
this.LOGGER.warn("No Test and Target cloud configuration at path " + tntConfigResource.getPath());
}
}
}
protected void bindCfgManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
this.cfgManagerFactory = configurationManagerFactory;
}
protected void unbindCfgManagerFactory(ConfigurationManagerFactory configurationManagerFactory) {
if (this.cfgManagerFactory == configurationManagerFactory) {
this.cfgManagerFactory = null;
}
}
protected void bindTntService(TestandtargetService testandtargetService) {
this.tntService = testandtargetService;
}
protected void unbindTntService(TestandtargetService testandtargetService) {
if (this.tntService == testandtargetService) {
this.tntService = null;
}
}
}