DTMWorkflowLauncherServlet.java
3.67 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.workflow.WorkflowException
* com.day.cq.workflow.WorkflowService
* javax.jcr.PathNotFoundException
* 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.request.RequestPathInfo
* org.apache.sling.api.resource.Resource
* org.apache.sling.api.resource.ValueMap
* org.apache.sling.api.servlets.SlingAllMethodsServlet
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.adobe.cq.dtm.impl.servlets;
import com.adobe.cq.dtm.impl.constants.DTMServerType;
import com.adobe.cq.dtm.impl.util.DTMConfigurationUtil;
import com.day.cq.workflow.WorkflowException;
import com.day.cq.workflow.WorkflowService;
import java.io.IOException;
import javax.jcr.PathNotFoundException;
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.request.RequestPathInfo;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ValueMap;
import org.apache.sling.api.servlets.SlingAllMethodsServlet;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@SlingServlet(methods={"POST"}, resourceTypes={"cq/dtm/components/dynamictagmanagementpage"}, selectors={"staging", "production"}, extensions={"html"})
public class DTMWorkflowLauncherServlet
extends SlingAllMethodsServlet {
private static final Logger LOG = LoggerFactory.getLogger(DTMWorkflowLauncherServlet.class);
@Reference
private WorkflowService workflowService;
/*
* Enabled force condition propagation
* Lifted jumps to return sites
*/
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response) throws ServletException, IOException {
String[] selectors = request.getRequestPathInfo().getSelectors();
if (selectors == null || selectors.length != 1) throw new ServletException("Unable to extract the request sling selector.");
DTMServerType dtmServerType = DTMServerType.valueOf(selectors[0].toUpperCase());
Resource dtmConfigResource = request.getResource();
String urlString = (String)((ValueMap)dtmConfigResource.adaptTo(ValueMap.class)).get((Object)((Object)((Object)dtmServerType) + "BundleURL"));
if (!this.isUrlValid(urlString)) throw new ServletException("The provided DTM Bundle URL is invalid.");
try {
DTMConfigurationUtil.triggerDTMWorkflow(this.workflowService, dtmConfigResource, dtmServerType);
LOG.info("DTM {} bundle download workflow started.", (Object)dtmServerType);
return;
}
catch (WorkflowException e) {
throw new ServletException((Throwable)e);
}
catch (PathNotFoundException e) {
throw new ServletException((Throwable)e);
}
}
private boolean isUrlValid(String urlString) {
String URL_REGEX = "^(https?://)(([a-z.-]+).([a-z.]{2,6})|localhost|\\b(?:\\d{1,3}\\.){3}\\d{1,3}\\b)(:[0-9]{1,5})?[\\w .\\-/]*$";
return urlString.matches(URL_REGEX);
}
protected void bindWorkflowService(WorkflowService workflowService) {
this.workflowService = workflowService;
}
protected void unbindWorkflowService(WorkflowService workflowService) {
if (this.workflowService == workflowService) {
this.workflowService = null;
}
}
}