polishing
This commit is contained in:
@@ -23,7 +23,7 @@ import org.springframework.integration.config.xml.IntegrationNamespaceUtils;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Parser for 'xmpp:roster-event-inbound-channel-adapter' element.
|
||||
* Parser for 'xmpp:presence-inbound-channel-adapter' element.
|
||||
*
|
||||
* @author Josh Long
|
||||
* @author Oleg Zhurakousky
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xmpp.config;
|
||||
|
||||
import org.jivesoftware.smack.ConnectionConfiguration;
|
||||
@@ -49,14 +50,18 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
private volatile XMPPConnection connection;
|
||||
|
||||
private volatile boolean autoStartup;
|
||||
|
||||
|
||||
private volatile int phase = Integer.MIN_VALUE;
|
||||
|
||||
private volatile boolean started;
|
||||
|
||||
|
||||
public XmppConnectionFactoryBean(ConnectionConfiguration connectionConfiguration) {
|
||||
Assert.notNull(connectionConfiguration, "'connectionConfiguration' must not be null");
|
||||
this.connectionConfiguration = connectionConfiguration;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public void setAutoStartup(boolean autoStartup) {
|
||||
this.autoStartup = autoStartup;
|
||||
}
|
||||
@@ -84,9 +89,7 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
|
||||
@Override
|
||||
protected XMPPConnection createInstance() throws Exception {
|
||||
connection = new XMPPConnection(connectionConfiguration);
|
||||
|
||||
return connection;
|
||||
return new XMPPConnection(this.connectionConfiguration);
|
||||
}
|
||||
|
||||
public void start() {
|
||||
@@ -94,9 +97,7 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
connection.connect();
|
||||
if (StringUtils.hasText(user)){
|
||||
connection.login(user, password, resource);
|
||||
|
||||
Assert.isTrue(connection.isAuthenticated(), "Failed to authenticate user: " + user);
|
||||
|
||||
if (StringUtils.hasText(this.subscriptionMode)) {
|
||||
Roster.SubscriptionMode subscriptionMode = Roster.SubscriptionMode.valueOf(this.subscriptionMode);
|
||||
connection.getRoster().setSubscriptionMode(subscriptionMode);
|
||||
@@ -106,13 +107,14 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
connection.loginAnonymously();
|
||||
}
|
||||
this.started = true;
|
||||
} catch (Exception e) {
|
||||
throw new BeanInitializationException("Failed to connect to " + this.connectionConfiguration.getHost(), e);
|
||||
}
|
||||
catch (Exception e) {
|
||||
throw new BeanInitializationException("failed to connect to " + this.connectionConfiguration.getHost(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void stop() {
|
||||
if (this.isRunning()){
|
||||
if (this.isRunning()) {
|
||||
this.connection.disconnect();
|
||||
this.started = false;
|
||||
}
|
||||
@@ -123,7 +125,7 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
}
|
||||
|
||||
public int getPhase() {
|
||||
return Integer.MIN_VALUE;
|
||||
return this.phase;
|
||||
}
|
||||
|
||||
public boolean isAutoStartup() {
|
||||
@@ -133,4 +135,5 @@ public class XmppConnectionFactoryBean extends AbstractFactoryBean<XMPPConnectio
|
||||
public void stop(Runnable callback) {
|
||||
callback.run();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xmpp.config;
|
||||
|
||||
import org.springframework.integration.config.xml.HeaderEnricherParserSupport;
|
||||
@@ -28,10 +29,8 @@ import org.springframework.integration.xmpp.XmppHeaders;
|
||||
public class XmppHeaderEnricherParser extends HeaderEnricherParserSupport {
|
||||
|
||||
public XmppHeaderEnricherParser() {
|
||||
|
||||
// chat headers
|
||||
this.addElementToHeaderMapping("message-to", XmppHeaders.CHAT_TO_USER);
|
||||
this.addElementToHeaderMapping("message-thread-id", XmppHeaders.CHAT_THREAD_ID);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xmpp.core;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
@@ -23,22 +24,26 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractXmppConnectionAwareEndpoint extends AbstractEndpoint {
|
||||
|
||||
protected volatile XMPPConnection xmppConnection;
|
||||
|
||||
protected volatile boolean initialized;
|
||||
|
||||
public AbstractXmppConnectionAwareEndpoint(){}
|
||||
|
||||
public AbstractXmppConnectionAwareEndpoint(XMPPConnection xmppConnection){
|
||||
|
||||
|
||||
public AbstractXmppConnectionAwareEndpoint() {
|
||||
}
|
||||
|
||||
public AbstractXmppConnectionAwareEndpoint(XMPPConnection xmppConnection) {
|
||||
Assert.notNull(xmppConnection, "'xmppConnection' must no be null");
|
||||
this.xmppConnection = xmppConnection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void onInit() throws Exception {
|
||||
BeanFactory bf = this.getBeanFactory();
|
||||
if (xmppConnection == null && bf != null){
|
||||
if (xmppConnection == null && bf != null) {
|
||||
xmppConnection = bf.getBean(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, XMPPConnection.class);
|
||||
}
|
||||
Assert.notNull(xmppConnection, "Failed to resolve XMPPConnection. XMPPConnection must either be set expicitly " +
|
||||
@@ -46,4 +51,5 @@ public abstract class AbstractXmppConnectionAwareEndpoint extends AbstractEndpoi
|
||||
"'org.jivesoftware.smack.XMPPConnection' in the Application Context");
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xmpp.core;
|
||||
|
||||
import org.jivesoftware.smack.XMPPConnection;
|
||||
@@ -23,22 +24,26 @@ import org.springframework.util.Assert;
|
||||
/**
|
||||
* @author Oleg Zhurakousky
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractXmppConnectionAwareMessageHandler extends AbstractMessageHandler {
|
||||
|
||||
protected volatile XMPPConnection xmppConnection;
|
||||
|
||||
protected volatile boolean initialized;
|
||||
|
||||
public AbstractXmppConnectionAwareMessageHandler(){}
|
||||
|
||||
public AbstractXmppConnectionAwareMessageHandler(XMPPConnection xmppConnection){
|
||||
|
||||
|
||||
public AbstractXmppConnectionAwareMessageHandler() {
|
||||
}
|
||||
|
||||
public AbstractXmppConnectionAwareMessageHandler(XMPPConnection xmppConnection) {
|
||||
Assert.notNull(xmppConnection, "'xmppConnection' must no be null");
|
||||
this.xmppConnection = xmppConnection;
|
||||
}
|
||||
|
||||
|
||||
|
||||
protected void onInit() throws Exception {
|
||||
BeanFactory bf = this.getBeanFactory();
|
||||
if (xmppConnection == null && bf != null){
|
||||
if (xmppConnection == null && bf != null) {
|
||||
xmppConnection = bf.getBean(XmppContextUtils.XMPP_CONNECTION_BEAN_NAME, XMPPConnection.class);
|
||||
}
|
||||
Assert.notNull(xmppConnection, "Failed to resolve XMPPConnection. XMPPConnection must either be set expicitly " +
|
||||
@@ -46,4 +51,5 @@ public abstract class AbstractXmppConnectionAwareMessageHandler extends Abstract
|
||||
"'org.jivesoftware.smack.XMPPConnection' in the Application Context");
|
||||
this.initialized = true;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.xmpp.core;
|
||||
|
||||
/**
|
||||
@@ -22,4 +23,5 @@ package org.springframework.integration.xmpp.core;
|
||||
public interface XmppContextUtils {
|
||||
|
||||
final String XMPP_CONNECTION_BEAN_NAME = "xmppConnection";
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user