DTMPropertyDetailsServlet.java
4.58 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.crypto.CryptoSupport
* com.day.cq.i18n.I18n
* javax.servlet.ServletException
* javax.servlet.http.HttpServletRequest
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.sling.SlingServlet
* org.apache.http.osgi.services.HttpClientBuilderFactory
* 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
*/
package com.adobe.cq.dtm.impl.servlets;
import com.adobe.cq.dtm.impl.util.DTMConfigurationUtil;
import com.adobe.granite.crypto.CryptoSupport;
import com.day.cq.i18n.I18n;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.sling.SlingServlet;
import org.apache.http.osgi.services.HttpClientBuilderFactory;
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;
@SlingServlet(methods={"POST"}, resourceTypes={"cq/dtm/components/dynamictagmanagementpage"}, selectors={"details"}, extensions={"json"})
public class DTMPropertyDetailsServlet
extends SlingAllMethodsServlet {
@Reference
private CryptoSupport cryptoSupport;
@Reference
private HttpClientBuilderFactory clientBuilderFactory = null;
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
block10 : {
response.setContentType("application/json");
response.setCharacterEncoding("utf-8");
JSONObject jsonResponse = new JSONObject();
I18n i18n = new I18n((HttpServletRequest)request);
try {
ResourceResolver resourceResolver = request.getResourceResolver();
String dtmApiUrl = DTMConfigurationUtil.getDTMApiUrl(resourceResolver);
if (dtmApiUrl != null) {
String token = DTMConfigurationUtil.getValueIfEncrypted(this.cryptoSupport, request.getParameter("token"));
String company = request.getParameter("company");
String property = request.getParameter("property");
if (token != null && company != null && property != null) {
JSONObject jsonObject = DTMConfigurationUtil.callDTMApi(this.clientBuilderFactory, dtmApiUrl = dtmApiUrl + "/companies/" + company + "/" + "web_properties" + "/" + property, token);
if (jsonObject != null) {
jsonResponse = jsonObject;
} else {
DTMConfigurationUtil.setErrorResponse(response, jsonResponse, 500, i18n, "Failed to obtain a response from the DTM API Server.", null);
}
} else {
DTMConfigurationUtil.setErrorResponse(response, jsonResponse, 400, i18n, "Incorrect request parameters.", null);
}
break block10;
}
DTMConfigurationUtil.setErrorResponse(response, jsonResponse, 500, i18n, "DTM API server URL not set.", null);
}
catch (JSONException e) {
throw new ServletException("Error creating JSON response.", (Throwable)e);
}
finally {
response.getWriter().write(jsonResponse.toString());
}
}
}
protected void bindCryptoSupport(CryptoSupport cryptoSupport) {
this.cryptoSupport = cryptoSupport;
}
protected void unbindCryptoSupport(CryptoSupport cryptoSupport) {
if (this.cryptoSupport == cryptoSupport) {
this.cryptoSupport = null;
}
}
protected void bindClientBuilderFactory(HttpClientBuilderFactory httpClientBuilderFactory) {
this.clientBuilderFactory = httpClientBuilderFactory;
}
protected void unbindClientBuilderFactory(HttpClientBuilderFactory httpClientBuilderFactory) {
if (this.clientBuilderFactory == httpClientBuilderFactory) {
this.clientBuilderFactory = null;
}
}
}