1
|
package eu.dnetlib.msro.openaireplus.workflows.nodes.vre;
|
2
|
|
3
|
import java.net.URI;
|
4
|
|
5
|
import com.googlecode.sarasvati.Arc;
|
6
|
import com.googlecode.sarasvati.NodeToken;
|
7
|
import eu.dnetlib.msro.workflows.nodes.SimpleJobNode;
|
8
|
import org.apache.commons.logging.Log;
|
9
|
import org.apache.commons.logging.LogFactory;
|
10
|
import org.apache.http.client.methods.HttpPost;
|
11
|
import org.apache.http.client.utils.URIBuilder;
|
12
|
import org.apache.http.entity.ContentType;
|
13
|
import org.apache.http.entity.StringEntity;
|
14
|
import org.apache.http.impl.client.BasicResponseHandler;
|
15
|
import org.apache.http.impl.client.CloseableHttpClient;
|
16
|
import org.apache.http.impl.client.HttpClients;
|
17
|
|
18
|
/**
|
19
|
* Created by alessia on 24/03/16.
|
20
|
*/
|
21
|
public class VREPostJobNode extends SimpleJobNode {
|
22
|
|
23
|
private static final Log log = LogFactory.getLog(VREPostJobNode.class);
|
24
|
private String scheme;
|
25
|
private String host;
|
26
|
private String postPath;
|
27
|
|
28
|
//POST parameters
|
29
|
private String appToken;
|
30
|
private String previewTitle;
|
31
|
private String previewDescription;
|
32
|
private String text;
|
33
|
private String httpImageUrl;
|
34
|
private boolean enableNotification;
|
35
|
|
36
|
@Override
|
37
|
protected String execute(final NodeToken token) throws Exception {
|
38
|
CloseableHttpClient httpclient = HttpClients.createDefault();
|
39
|
try {
|
40
|
URI postUri = new URIBuilder().setScheme(scheme).setHost(host).setPath(postPath).build();
|
41
|
HttpPost postAction = new HttpPost(postUri);
|
42
|
StringBuilder strBuilder = new StringBuilder();
|
43
|
strBuilder.append("token=").append(appToken).append("&previewtitle=").append(previewTitle)
|
44
|
.append("&previewdescription=").append(previewDescription).append("&text=").append(text)
|
45
|
.append("&httpimageurl=").append(httpImageUrl).append("&enablenotification=").append(enableNotification);
|
46
|
String postBody = strBuilder.toString();
|
47
|
log.debug("POST body: " + postBody);
|
48
|
StringEntity ent = new StringEntity(postBody, ContentType.APPLICATION_FORM_URLENCODED);
|
49
|
|
50
|
postAction.setEntity(ent);
|
51
|
|
52
|
BasicResponseHandler responseHandler = new BasicResponseHandler();
|
53
|
|
54
|
httpclient.execute(postAction, responseHandler);
|
55
|
return Arc.DEFAULT_ARC;
|
56
|
} finally {
|
57
|
httpclient.close();
|
58
|
}
|
59
|
|
60
|
}
|
61
|
|
62
|
public String getScheme() {
|
63
|
return scheme;
|
64
|
}
|
65
|
|
66
|
public void setScheme(final String scheme) {
|
67
|
this.scheme = scheme;
|
68
|
}
|
69
|
|
70
|
public String getHost() {
|
71
|
return host;
|
72
|
}
|
73
|
|
74
|
public void setHost(final String host) {
|
75
|
this.host = host;
|
76
|
}
|
77
|
|
78
|
public String getPostPath() {
|
79
|
return postPath;
|
80
|
}
|
81
|
|
82
|
public void setPostPath(final String postPath) {
|
83
|
this.postPath = postPath;
|
84
|
}
|
85
|
|
86
|
public String getAppToken() {
|
87
|
return appToken;
|
88
|
}
|
89
|
|
90
|
public void setAppToken(final String token) {
|
91
|
this.appToken = token;
|
92
|
}
|
93
|
|
94
|
public String getPreviewTitle() {
|
95
|
return previewTitle;
|
96
|
}
|
97
|
|
98
|
public void setPreviewTitle(final String previewTitle) {
|
99
|
this.previewTitle = previewTitle;
|
100
|
}
|
101
|
|
102
|
public String getPreviewDescription() {
|
103
|
return previewDescription;
|
104
|
}
|
105
|
|
106
|
public void setPreviewDescription(final String previewDescription) {
|
107
|
this.previewDescription = previewDescription;
|
108
|
}
|
109
|
|
110
|
public String getText() {
|
111
|
return text;
|
112
|
}
|
113
|
|
114
|
public void setText(final String text) {
|
115
|
this.text = text;
|
116
|
}
|
117
|
|
118
|
public String getHttpImageUrl() {
|
119
|
return httpImageUrl;
|
120
|
}
|
121
|
|
122
|
public void setHttpImageUrl(final String httpImageUrl) {
|
123
|
this.httpImageUrl = httpImageUrl;
|
124
|
}
|
125
|
|
126
|
public boolean isEnableNotification() {
|
127
|
return enableNotification;
|
128
|
}
|
129
|
|
130
|
public void setEnableNotification(final boolean enablenotification) {
|
131
|
this.enableNotification = enablenotification;
|
132
|
}
|
133
|
}
|