SendNotificationOperation.java
3.44 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
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.adobe.granite.ui.components.HtmlResponse
* com.day.cq.i18n.I18n
* 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.http.client.HttpClient
* org.apache.http.impl.client.CloseableHttpClient
* org.apache.http.impl.client.HttpClientBuilder
* org.apache.http.osgi.services.HttpClientBuilderFactory
* org.apache.sling.api.SlingHttpServletRequest
* org.apache.sling.commons.json.JSONException
* org.apache.sling.commons.json.JSONObject
*/
package com.adobe.cq.mobile.notifications.impl.operations;
import com.adobe.cq.mobile.notifications.impl.exceptions.NotificationException;
import com.adobe.cq.mobile.notifications.impl.operations.AbstractNotificationOperation;
import com.adobe.cq.mobile.notifications.impl.services.NotificationService;
import com.adobe.cq.mobile.platform.MobileResource;
import com.adobe.cq.mobile.platform.MobileResourceType;
import com.adobe.granite.ui.components.HtmlResponse;
import com.day.cq.i18n.I18n;
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.http.client.HttpClient;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.osgi.services.HttpClientBuilderFactory;
import org.apache.sling.api.SlingHttpServletRequest;
import org.apache.sling.commons.json.JSONException;
import org.apache.sling.commons.json.JSONObject;
@Component(metatype=0, label="Send Push Notification Operation")
@Service
@Properties(value={@Property(name="sling.post.operation", value={"mobileapps:sendNotification"})})
public class SendNotificationOperation
extends AbstractNotificationOperation {
public static final String OPERATION_NAME = "sendNotification";
@Reference
private HttpClientBuilderFactory httpClientBuilderFactory;
@Override
protected void performOperation(SlingHttpServletRequest request, HtmlResponse response, MobileResource mobileResource, NotificationService notificationService) throws NotificationException, JSONException {
if (!this.verifyMobileResourceType(response, mobileResource, MobileResourceType.NOTIFICATION.getType())) {
return;
}
CloseableHttpClient httpclient = this.httpClientBuilderFactory.newBuilder().build();
JSONObject sendResult = notificationService.send(mobileResource, (HttpClient)httpclient);
JSONObject jsonResponse = new JSONObject();
jsonResponse.put("response", (Object)sendResult);
jsonResponse.put("status", (Object)"ok");
this.generateResponse(response, response.getStatusCode(), jsonResponse.toString(), this.i18n.get("Service Response"));
}
protected void bindHttpClientBuilderFactory(HttpClientBuilderFactory httpClientBuilderFactory) {
this.httpClientBuilderFactory = httpClientBuilderFactory;
}
protected void unbindHttpClientBuilderFactory(HttpClientBuilderFactory httpClientBuilderFactory) {
if (this.httpClientBuilderFactory == httpClientBuilderFactory) {
this.httpClientBuilderFactory = null;
}
}
}