Commit 8f2cbd63 authored by Aurelien Pupier's avatar Aurelien Pupier
Browse files

BS-2109: update twitter4j library in order to support SSl by default

which is mandatory since the 14th January 2014 with Twitter API. Initial
issue not reproduced with new library version
parent 61dac1b3
......@@ -9,12 +9,13 @@
</parent>
<artifactId>bonita-connector-twitter-common</artifactId>
<version>1.1.0</version>
<dependencies>
<dependency>
<groupId>org.twitter4j</groupId>
<artifactId>twitter4j-core</artifactId>
<version>3.0.3</version>
<version>4.0.2</version>
</dependency>
</dependencies>
......
/**
* Copyright (C) 2009-2011 BonitaSoft S.A.
* Copyright (C) 2009-2014 BonitaSoft S.A.
* BonitaSoft, 31 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -39,98 +39,98 @@ import twitter4j.conf.ConfigurationBuilder;
public abstract class TwitterConnector implements Connector {
private String proxyHost;
private Integer proxyPort;
private String proxyUser;
private String proxyPass;
private String consumerKey;
private String consumerSecret;
private String accessToken;
private String accessTokenSecret;
@Override
public void setInputParameters(final Map<String, Object> parameters) {
final Object proxyHostObject = parameters.get("proxyHost");
proxyHost = proxyHostObject != null ? (String) proxyHostObject : "";
final Object proxyPortObject = parameters.get("proxyPort");
proxyPort = proxyPortObject != null ? (Integer) proxyPortObject : 0;
final Object proxyUserObject = parameters.get("proxyUser");
proxyUser = proxyUserObject != null ? (String) proxyUserObject : "";
final Object proxyPassObject = parameters.get("proxyPass");
proxyPass = proxyPassObject != null ? (String) proxyPassObject : "";
final Object consumerKeyObject = parameters.get("consumerKey");
consumerKey = consumerKeyObject != null ? (String) consumerKeyObject
: "";
final Object consumerSecretObject = parameters.get("consumerSecret");
consumerSecret = consumerSecretObject != null ? (String) consumerSecretObject
: "";
final Object accessTokenObject = parameters.get("accessToken");
accessToken = accessTokenObject != null ? (String) accessTokenObject
: "";
final Object accessTokenSecretObject = parameters
.get("accessTokenSecret");
accessTokenSecret = accessTokenSecretObject != null ? (String) accessTokenSecretObject
: "";
}
@Override
public void validateInputParameters() throws ConnectorValidationException {
final List<String> errors = new ArrayList<String>(1);
if (proxyPort < 0) {
errors.add("proxyPort cannot be less than 0!");
} else if (proxyPort > 65535) {
errors.add("proxyPort cannot be greater than 65535!");
}
if (!errors.isEmpty()) {
throw new ConnectorValidationException(this, errors);
}
}
@Override
public Map<String, Object> execute() throws ConnectorException {
final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
if (proxyHost != null && proxyPort != null) {
configurationBuilder.setHttpProxyHost(proxyHost);
configurationBuilder.setHttpProxyPort(proxyPort);
if (proxyUser != null && proxyPass != null) {
configurationBuilder.setHttpProxyUser(proxyUser);
configurationBuilder.setHttpProxyPassword(proxyPass);
}
}
configurationBuilder.setOAuthConsumerKey(consumerKey);
configurationBuilder.setOAuthConsumerSecret(consumerSecret);
configurationBuilder.setOAuthAccessToken(accessToken);
configurationBuilder.setOAuthAccessTokenSecret(accessTokenSecret);
try {
final TwitterFactory tf = new TwitterFactory(
configurationBuilder.build());
final Twitter twitter = tf.getInstance();
executeTask(twitter);
} catch (final Exception e) {
throw new ConnectorException(e);
}
return Collections.emptyMap();
}
protected abstract void executeTask(Twitter twitter) throws Exception;
@Override
public void connect() throws ConnectorException {
}
@Override
public void disconnect() throws ConnectorException {
}
private String proxyHost;
private Integer proxyPort;
private String proxyUser;
private String proxyPass;
private String consumerKey;
private String consumerSecret;
private String accessToken;
private String accessTokenSecret;
@Override
public void setInputParameters(final Map<String, Object> parameters) {
final Object proxyHostObject = parameters.get("proxyHost");
proxyHost = proxyHostObject != null ? (String) proxyHostObject : "";
final Object proxyPortObject = parameters.get("proxyPort");
proxyPort = proxyPortObject != null ? (Integer) proxyPortObject : 0;
final Object proxyUserObject = parameters.get("proxyUser");
proxyUser = proxyUserObject != null ? (String) proxyUserObject : "";
final Object proxyPassObject = parameters.get("proxyPass");
proxyPass = proxyPassObject != null ? (String) proxyPassObject : "";
final Object consumerKeyObject = parameters.get("consumerKey");
consumerKey = consumerKeyObject != null ? (String) consumerKeyObject
: "";
final Object consumerSecretObject = parameters.get("consumerSecret");
consumerSecret = consumerSecretObject != null ? (String) consumerSecretObject
: "";
final Object accessTokenObject = parameters.get("accessToken");
accessToken = accessTokenObject != null ? (String) accessTokenObject
: "";
final Object accessTokenSecretObject = parameters
.get("accessTokenSecret");
accessTokenSecret = accessTokenSecretObject != null ? (String) accessTokenSecretObject
: "";
}
@Override
public void validateInputParameters() throws ConnectorValidationException {
final List<String> errors = new ArrayList<String>(1);
if (proxyPort < 0) {
errors.add("proxyPort cannot be less than 0!");
} else if (proxyPort > 65535) {
errors.add("proxyPort cannot be greater than 65535!");
}
if (!errors.isEmpty()) {
throw new ConnectorValidationException(this, errors);
}
}
@Override
public Map<String, Object> execute() throws ConnectorException {
final ConfigurationBuilder configurationBuilder = new ConfigurationBuilder();
if (proxyHost != null && proxyPort != null) {
configurationBuilder.setHttpProxyHost(proxyHost);
configurationBuilder.setHttpProxyPort(proxyPort);
if (proxyUser != null && proxyPass != null) {
configurationBuilder.setHttpProxyUser(proxyUser);
configurationBuilder.setHttpProxyPassword(proxyPass);
}
}
configurationBuilder.setOAuthConsumerKey(consumerKey);
configurationBuilder.setOAuthConsumerSecret(consumerSecret);
configurationBuilder.setOAuthAccessToken(accessToken);
configurationBuilder.setOAuthAccessTokenSecret(accessTokenSecret);
try {
final TwitterFactory tf = new TwitterFactory(
configurationBuilder.build());
final Twitter twitter = tf.getInstance();
executeTask(twitter);
} catch (final Exception e) {
throw new ConnectorException(e);
}
return Collections.emptyMap();
}
protected abstract void executeTask(Twitter twitter) throws Exception;
@Override
public void connect() throws ConnectorException {
}
@Override
public void disconnect() throws ConnectorException {
}
}
......@@ -5,7 +5,7 @@
<parent>
<artifactId>bonita-connector-twitter</artifactId>
<groupId>org.bonitasoft.connectors</groupId>
<version>1.0.0</version>
<version>1.1.0</version>
</parent>
<artifactId>bonita-connector-twitter-direct-impl</artifactId>
......
/**
* Copyright (C) 20012 BonitaSoft S.A.
* Copyright (C) 2012-2014 BonitaSoft S.A.
* BonitaSoft, 32 rue Gustave Eiffel - 38000 Grenoble
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
......@@ -24,23 +24,23 @@ import twitter4j.Twitter;
*/
public class TwitterDirectMessageConnector extends TwitterConnector {
private String message;
private String message;
private String recipientId;
private String recipientId;
@Override
public void setInputParameters(final Map<String, Object> parameters) {
super.setInputParameters(parameters);
final Object messageObject = parameters.get("message");
message = messageObject != null ? (String) messageObject : "";
final Object recipientIdObject = parameters.get("recipientId");
recipientId = recipientIdObject != null ? (String) recipientIdObject
: "";
}
@Override
public void setInputParameters(final Map<String, Object> parameters) {
super.setInputParameters(parameters);
final Object messageObject = parameters.get("message");
message = messageObject != null ? (String) messageObject : "";
final Object recipientIdObject = parameters.get("recipientId");
recipientId = recipientIdObject != null ? (String) recipientIdObject
: "";
}
@Override
protected void executeTask(final Twitter twitter) throws Exception {
twitter.sendDirectMessage(recipientId, message);
}
@Override
protected void executeTask(final Twitter twitter) throws Exception {
twitter.sendDirectMessage(recipientId, message);
}
}
......@@ -5,7 +5,7 @@
<parent>
<artifactId>bonita-connector-twitter</artifactId>
<groupId>org.bonitasoft.connectors</groupId>
<version>1.0.0</version>
<version>1.1.0</version>
</parent>
<artifactId>bonita-connector-twitter-update-impl</artifactId>
......
......@@ -10,7 +10,7 @@
</parent>
<artifactId>bonita-connector-twitter</artifactId>
<version>1.0.0</version>
<version>1.1.0</version>
<packaging>pom</packaging>
<modules>
......@@ -22,7 +22,8 @@
</modules>
<properties>
<bonita.engine.version>6.2.0</bonita.engine.version>
<bonita.engine.version>6.3.2</bonita.engine.version>
<twitter.common.version>1.1.0</twitter.common.version>
</properties>
<dependencies>
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment