From nuvem-commits-return-104-apmail-incubator-nuvem-commits-archive=incubator.apache.org@incubator.apache.org Sat May 7 23:23:45 2011 Return-Path: X-Original-To: apmail-incubator-nuvem-commits-archive@minotaur.apache.org Delivered-To: apmail-incubator-nuvem-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C125D2B97 for ; Sat, 7 May 2011 23:23:45 +0000 (UTC) Received: (qmail 97509 invoked by uid 500); 7 May 2011 23:23:45 -0000 Delivered-To: apmail-incubator-nuvem-commits-archive@incubator.apache.org Received: (qmail 97479 invoked by uid 500); 7 May 2011 23:23:45 -0000 Mailing-List: contact nuvem-commits-help@incubator.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: nuvem-dev@incubator.apache.org Delivered-To: mailing list nuvem-commits@incubator.apache.org Received: (qmail 97472 invoked by uid 99); 7 May 2011 23:23:45 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 May 2011 23:23:45 +0000 X-ASF-Spam-Status: No, hits=-1996.5 required=5.0 tests=ALL_TRUSTED,T_FRT_STOCK2,URIBL_BLACK X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Sat, 07 May 2011 23:23:36 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id A74462388901; Sat, 7 May 2011 23:23:13 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r1100659 - in /incubator/nuvem/trunk/nuvem-standalone: ./ src/main/java/org/apache/nuvem/cloud/xmpp/ src/main/java/org/apache/nuvem/cloud/xmpp/client/ src/main/java/org/apache/nuvem/cloud/xmpp/server/ src/main/java/org/apache/nuvem/xmpp/ sr... Date: Sat, 07 May 2011 23:23:13 -0000 To: nuvem-commits@incubator.apache.org From: johnp@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20110507232313.A74462388901@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: johnp Date: Sat May 7 23:23:12 2011 New Revision: 1100659 URL: http://svn.apache.org/viewvc?rev=1100659&view=rev Log: module restructuring + few folder structure changes to keep it consistent with all other modules Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/AbstractConnector.java incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/DefaultPresenceManager.java incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/DefaultXMPPEndPoint.java incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/MessageAdapter.java incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/MessageListenerAdapter.java incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/NuvemPacketFilter.java incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/NuvemPacketListener.java incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/PresenceAdapter.java incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/RosterListenerAdapter.java incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/SSLConnector.java incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/SimpleConnector.java incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/StatusAdapter.java incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/server/ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/server/DefaultXMPPServer.java incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/xmpp/ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/xmpp/client/ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/xmpp/server/ incubator/nuvem/trunk/nuvem-standalone/src/main/resources/ incubator/nuvem/trunk/nuvem-standalone/src/main/resources/META-INF/ incubator/nuvem/trunk/nuvem-standalone/src/main/resources/META-INF/sca-contribution.xml incubator/nuvem/trunk/nuvem-standalone/src/main/resources/config/ incubator/nuvem/trunk/nuvem-standalone/src/main/resources/config/bogus_mina_tls.cert (with props) incubator/nuvem/trunk/nuvem-standalone/src/main/resources/config/xmpp.cert incubator/nuvem/trunk/nuvem-standalone/src/main/resources/nuvemxmpp.composite incubator/nuvem/trunk/nuvem-standalone/src/test/ incubator/nuvem/trunk/nuvem-standalone/src/test/java/ incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/ incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/ incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/ incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/ incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/data/ incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/data/impl/ incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/data/impl/MapDocumentServiceImplTestCase.java incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/xmpp/ incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/xmpp/client/ incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/xmpp/client/DefaultXMPPEndPointTestCase.java incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/xmpp/client/XMPPEndPointIntegrationTest.java incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/xmpp/server/ incubator/nuvem/trunk/nuvem-standalone/src/test/resources/ incubator/nuvem/trunk/nuvem-standalone/src/test/resources/testnuvemxmpp.composite Modified: incubator/nuvem/trunk/nuvem-standalone/pom.xml Modified: incubator/nuvem/trunk/nuvem-standalone/pom.xml URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/pom.xml?rev=1100659&r1=1100658&r2=1100659&view=diff ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/pom.xml (original) +++ incubator/nuvem/trunk/nuvem-standalone/pom.xml Sat May 7 23:23:12 2011 @@ -1,56 +1,135 @@ - - - 4.0.0 - - org.apache.nuvem - nuvem - 1.0-incubating-SNAPSHOT - ../pom.xml - - nuvem-cloud-standalone + + + 4.0.0 + + org.apache.nuvem + nuvem + 1.0-incubating-SNAPSHOT + ../pom.xml + + nuvem-standalone 1.0-incubating-SNAPSHOT - Apache Nuvem Cloud API Implementation for Standlone Applications + Apache Nuvem Cloud API Implementation for Standlone Applications org.apache.nuvem - nuvem-cloud-api + nuvem-api ${project.version} - - org.apache.tuscany.sca - tuscany-node-impl - ${tuscany.version} - test - - - - junit - junit - 4.8.1 - test - + + org.apache.tuscany.sca + tuscany-assembly + ${tuscany.version} + + + + org.apache.tuscany.sca + tuscany-node-impl + ${tuscany.version} + test + + + + org.apache.tuscany.sca + tuscany-sca-api + ${tuscany.version} + + + + org.apache.tuscany.sca + tuscany-implementation-java-runtime + ${tuscany.version} + runtime + + + + org.apache.tuscany.sca + tuscany-domain-node + ${tuscany.version} + + + + junit + junit + 4.8.1 + test + + + + org.apache.vysper + vysper-server + pom + 1.0.0-SNAPSHOT + + + + org.apache.vysper + vysper-core + 1.0.0-SNAPSHOT + + + + org.apache.vysper + vysper-extensions + pom + 1.0.0-SNAPSHOT + + + + org.slf4j + slf4j-api + 1.5.3 + + + + org.slf4j + slf4j-simple + 1.5.3 + + + + org.slf4j + jcl-over-slf4j + 1.5.3 + + + + junit + junit + 4.8.1 + test + + + + jivesoftware + smackx + 3.1.0 + + + + org.easymock + easymock + 3.0 + test + + Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/AbstractConnector.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/AbstractConnector.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/AbstractConnector.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/AbstractConnector.java Sat May 7 23:23:12 2011 @@ -0,0 +1,99 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import java.util.Map; +import java.util.logging.Logger; + +import org.apache.nuvem.cloud.xmpp.XMPPConnectException; +import org.apache.nuvem.cloud.xmpp.XMPPConnector; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; +import org.oasisopen.sca.annotation.Property; + +/** + * Common Template to establish conneciton to the XMPPServer, which is extended + * by a more specific mechanisms. + * + * + */ +public abstract class AbstractConnector implements + XMPPConnector { + /** + * Logger. + */ + protected static final Logger log = Logger.getLogger(XMPPConnector.class + .getName()); + + @Property(required = false) + protected String host = "localhost"; + @Property(required = false) + protected int port = 5222; + @Property(required = false) + protected String serviceName; + @Property + protected String clientJID = "nuvem@localhost"; + @Property + protected String clientPassword = "password"; + @Property(required = false) + protected String authenticationMechanism = "PLAIN"; + + /** + * The XMPP Connection. + */ + protected XMPPConnection connection; + + /** + * Connects to the XMPP Server and returns the XMPPConnection. + */ + public XMPPConnection getConnection() { + if (connection != null) + return connection; + log.info("Initializing a new connection..."); + checkConfigurations(); + try { + log.info("Connecting to XMPP Server...."); + establishConnection(); + log.info("Authenticating with the XMPP Server...."); + authenticateWithServer(); + log.info("EndPoint connected to XMPP Server successfuly!"); + } catch (XMPPException e) { + log.severe("Error while connecting to the XMPP Server..." + + e.getMessage()); + throw new XMPPConnectException( + "error while connecting to the xmpp server", e); + } + return connection; + } + + /** + * {@inheritDoc} + */ + public XMPPConnection getConnection(Map connectionProperties) { + throw new UnsupportedOperationException("still not supported"); + } + + protected abstract void checkConfigurations(); + + protected abstract void establishConnection() throws XMPPException; + + protected abstract void authenticateWithServer() throws XMPPException; + +} Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/DefaultPresenceManager.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/DefaultPresenceManager.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/DefaultPresenceManager.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/DefaultPresenceManager.java Sat May 7 23:23:12 2011 @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import org.apache.commons.lang.Validate; +import org.apache.nuvem.cloud.xmpp.XMPPConnector; +import org.apache.nuvem.cloud.xmpp.presence.PresenceListener; +import org.apache.nuvem.cloud.xmpp.presence.PresenceManager; +import org.apache.nuvem.cloud.xmpp.AbstractPresenceManager; +import org.jivesoftware.smack.XMPPConnection; +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Service; + +/** + * Utility Service to provide all presence related operations. + * + */ +@Service(PresenceManager.class) +public class DefaultPresenceManager extends AbstractPresenceManager { + + /** + * Connecter to fetch XMPP Connection. + */ + @Reference + protected XMPPConnector connector; + + /** + * {@inheritDoc} + */ + @Override + public void registerListener(PresenceListener listener) { + Validate.notNull(listener); + connector.getConnection().getRoster().addRosterListener( + new RosterListenerAdapter(listener)); + //Keeps a reference to the listener for later use. + listeners.add(listener); + } + +} Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/DefaultXMPPEndPoint.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/DefaultXMPPEndPoint.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/DefaultXMPPEndPoint.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/DefaultXMPPEndPoint.java Sat May 7 23:23:12 2011 @@ -0,0 +1,183 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import java.util.logging.Logger; + +import org.apache.commons.lang.Validate; +import org.apache.nuvem.cloud.xmpp.JID; +import org.apache.nuvem.cloud.xmpp.Status; +import org.apache.nuvem.cloud.xmpp.XMPPConnector; +import org.apache.nuvem.cloud.xmpp.XMPPEndPoint; +import org.apache.nuvem.cloud.xmpp.message.Message; +import org.apache.nuvem.cloud.xmpp.presence.PresenceManager; +import org.apache.nuvem.cloud.xmpp.AbstractXMPPEndPoint; +import org.jivesoftware.smack.Chat; +import org.jivesoftware.smack.Roster; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.packet.Presence; +import org.jivesoftware.smack.packet.Presence.Type; +import org.oasisopen.sca.annotation.Init; +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Scope; +import org.oasisopen.sca.annotation.Service; + +/** + * A Default Implemention of XMPP Client for cloud platforms without explicit + * XMPP support. + * + */ +@Service(XMPPEndPoint.class) +@Scope("COMPOSITE") +public class DefaultXMPPEndPoint extends AbstractXMPPEndPoint implements + XMPPEndPoint { + + /** + * Logger. + */ + private static final Logger log = Logger.getLogger(XMPPEndPoint.class + .getName()); + + @Reference + protected XMPPConnector connector; + + @Reference + protected PresenceManager presenceManager; + + + /** + * The packet filter to decide what packets to recieve from the XMPP + * Server.. + */ + private NuvemPacketFilter filter; + + /** + * The Packet listener. + */ + private NuvemPacketListener listener; + + /** + * Default constructor. + */ + public DefaultXMPPEndPoint() { + + } + + public DefaultXMPPEndPoint(XMPPConnector connector) { + Validate.notNull(connector); + this.connector = connector; + } + + @Init + public void init() { + log.info("Initializing DefaultXMPPEndPoint using connector " + + connector.getDescription()); + filter = new NuvemPacketFilter(this); + listener = new NuvemPacketListener(this); + connector.getConnection().addPacketListener(this.listener, filter); + } + + /** + * {@inheritDoc} + */ + public Status sendMessage(Message message) { + XMPPConnection connection = connector.getConnection(); + if (message == null || message.recipient() == null) { + throw new IllegalArgumentException("invalid message"); + } + Status deliveryStatus = new Status(); + + org.apache.nuvem.cloud.xmpp.message.MessageListener nuvemListener = getListenerFor(message + .recipient()); + + Chat chat = connection.getChatManager().createChat( + message.recipient().asString(), + new MessageListenerAdapter(nuvemListener)); + try { + chat.sendMessage(message.payLoad().content()); + } catch (XMPPException e) { + log.severe("error while sending xmpp message to " + + message.recipient().asString()); + deliveryStatus = StatusAdapter.toStatus(e.getXMPPError()); + } + return deliveryStatus; + } + + /** + * {@inheritDoc} + */ + public Status invite(JID jid) { + throw new UnsupportedOperationException("not supported yet"); + } + + /** + * {@inheritDoc} + */ + public Status invite(String jid) { + throw new UnsupportedOperationException("not supported yet"); + } + + /** + * {@inheritDoc} + */ + public boolean isPresent(JID jid) { + XMPPConnection connection = connector.getConnection(); + if (jid == null) + throw new IllegalArgumentException( + "Illegal JID passed for finding presence"); + + Roster roster = connection.getRoster(); + Presence presence = roster.getPresence(jid.asString()); + if (presence != null) + return presence.getType() == Type.available; + return false; + } + + /** + * {@inheritDoc} + */ + public boolean isPresent(String id) { + XMPPConnection connection = connector.getConnection(); + + if (id == null) + throw new IllegalArgumentException( + "Illegal JID passed for finding presence"); + + Roster roster = connection.getRoster(); + Presence presence = roster.getPresence(id); + if (presence != null) + return presence.getType() == Type.available; + return false; + } + + /** + * {@inheritDoc} + */ + public boolean isConnected() { + return connector.getConnection().isConnected(); + } + + @Override + public PresenceManager presenceManager() { + return presenceManager; + } +} Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/MessageAdapter.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/MessageAdapter.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/MessageAdapter.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/MessageAdapter.java Sat May 7 23:23:12 2011 @@ -0,0 +1,62 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import org.apache.nuvem.cloud.xmpp.message.MessageBuilder; +import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.packet.Presence; + +/** + * Adapter to transform nuvem message into smack message. + * + * + */ +public class MessageAdapter { + + /** + * Converts nuvem specific message object to the one smack API accepts. + * + */ + public static Message toSmackMessage( + org.apache.nuvem.cloud.xmpp.message.Message nuvemMessage, + String sender) { + Message smackMessage = new Message(); + smackMessage.setFrom(sender); + smackMessage.setBody(nuvemMessage.payLoad().content()); + smackMessage.setTo(nuvemMessage.recipient().asString()); + return smackMessage; + } + + + /** + * Converts smack message to Nuvem Message. + * + * @param message + * the smack message. + * @return nuvem message. + */ + public static org.apache.nuvem.cloud.xmpp.message.Message toNuvemMessage( + Message message) { + return new MessageBuilder().from(message.getFrom()).toRecipient( + message.getTo()).containing(message.getBody()).build(); + } + +} Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/MessageListenerAdapter.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/MessageListenerAdapter.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/MessageListenerAdapter.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/MessageListenerAdapter.java Sat May 7 23:23:12 2011 @@ -0,0 +1,53 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import org.apache.nuvem.cloud.xmpp.message.MessageBuilder; +import org.jivesoftware.smack.Chat; +import org.jivesoftware.smack.MessageListener; +import org.jivesoftware.smack.packet.Message; + +/** + * Message Listener to listen to smack api and adapt it to nuvem specific + * messages. + * + */ +public class MessageListenerAdapter implements MessageListener { + + /** + * The Nuvem Listener. + */ + private org.apache.nuvem.cloud.xmpp.message.MessageListener nuvemListener; + + public MessageListenerAdapter( + org.apache.nuvem.cloud.xmpp.message.MessageListener nuvemMessageListener) { + if (nuvemMessageListener == null) + throw new IllegalArgumentException("listener should not be null"); + this.nuvemListener = nuvemMessageListener; + } + + @Override + public void processMessage(Chat chat, Message message) { + nuvemListener.listen(new MessageBuilder().from(message.getFrom()) + .containing(message.getBody()).build()); + } + +} Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/NuvemPacketFilter.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/NuvemPacketFilter.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/NuvemPacketFilter.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/NuvemPacketFilter.java Sat May 7 23:23:12 2011 @@ -0,0 +1,57 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import org.apache.commons.lang.StringUtils; +import org.apache.nuvem.cloud.xmpp.JID; +import org.apache.nuvem.cloud.xmpp.XMPPEndPoint; +import org.apache.nuvem.cloud.xmpp.message.MessageListener; +import org.jivesoftware.smack.filter.PacketFilter; +import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.packet.Packet; + +/** + * A package filter to accept only necessary packets based on the the listeners + * registered for the reciever. + * + */ +public class NuvemPacketFilter implements PacketFilter { + + private XMPPEndPoint endPoint; + + public NuvemPacketFilter(XMPPEndPoint endPoint) { + this.endPoint = endPoint; + } + + /** + * Accepts only those packets for which a {@link MessageListener} is + * registered. + */ + public boolean accept(Packet packet) { + if (packet instanceof Message) { + String from = StringUtils.substringBeforeLast(packet.getFrom(), + "/"); + return endPoint.getListenerFor(new JID(from)) != null; + } + return false; + } + +} Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/NuvemPacketListener.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/NuvemPacketListener.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/NuvemPacketListener.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/NuvemPacketListener.java Sat May 7 23:23:12 2011 @@ -0,0 +1,56 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import org.apache.commons.lang.StringUtils; +import org.apache.nuvem.cloud.xmpp.JID; +import org.apache.nuvem.cloud.xmpp.XMPPEndPoint; +import org.apache.nuvem.cloud.xmpp.message.MessageListener; +import org.jivesoftware.smack.PacketListener; +import org.jivesoftware.smack.packet.Message; +import org.jivesoftware.smack.packet.Packet; + +/** + * Listens to Packets from XMPP Server and transfers them to the appropriate + * Listener registered with the XMPPEndPoint. + * + */ +public class NuvemPacketListener implements PacketListener { + + private XMPPEndPoint endPoint; + + public NuvemPacketListener(XMPPEndPoint endPoint) { + this.endPoint = endPoint; + } + + @Override + public void processPacket(Packet packet) { + if (packet instanceof Message) { + String from = StringUtils.substringBeforeLast(packet.getFrom(), + "/"); + MessageListener listener = endPoint + .getListenerFor(new JID(from)); + listener.listen(MessageAdapter + .toNuvemMessage((Message) packet)); + } + } + +} Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/PresenceAdapter.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/PresenceAdapter.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/PresenceAdapter.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/PresenceAdapter.java Sat May 7 23:23:12 2011 @@ -0,0 +1,91 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.commons.lang.StringUtils; +import org.apache.nuvem.cloud.xmpp.JID; +import org.apache.nuvem.cloud.xmpp.presence.Presence; +import org.apache.nuvem.cloud.xmpp.presence.PresenceBuilder; +import org.apache.nuvem.cloud.xmpp.presence.Presence.Show; +import org.apache.nuvem.cloud.xmpp.presence.Presence.Type; +import org.jivesoftware.smack.packet.Presence.Mode; + +/** + * Hepls convert smack specific presence object into nuvem specific presence + * object. + * + */ +public final class PresenceAdapter { + + private static final Map showConverstionMap = new HashMap(); + private static final Map typeConversionMap = new HashMap(); + + static { + showConverstionMap.put(Mode.available, Show.AVAILABLE); + showConverstionMap.put(Mode.away, Show.AWAY); + showConverstionMap.put(Mode.chat, Show.CHAT); + showConverstionMap.put(Mode.dnd, Show.DND); + showConverstionMap.put(Mode.xa, Show.XA); + + typeConversionMap.put( + org.jivesoftware.smack.packet.Presence.Type.available, + Type.AVAILABLE); + typeConversionMap.put( + org.jivesoftware.smack.packet.Presence.Type.unavailable, + Type.UNAVAILABLE); + typeConversionMap.put( + org.jivesoftware.smack.packet.Presence.Type.subscribe, + Type.SUBSCRIBE); + typeConversionMap.put( + org.jivesoftware.smack.packet.Presence.Type.subscribed, + Type.SUBSCRIBED); + typeConversionMap.put( + org.jivesoftware.smack.packet.Presence.Type.unsubscribe, + Type.UNSUBSCRIBE); + typeConversionMap.put( + org.jivesoftware.smack.packet.Presence.Type.unsubscribed, + Type.UNSUBSCRIBED); + typeConversionMap.put( + org.jivesoftware.smack.packet.Presence.Type.error, Type.ERROR); + } + + /** + * Converts smack's {@link org.jivesoftware.smack.packet.Presence} to + * Nuvem's {@link org.apache.nuvem.cloud.xmpp.presence.Presence} object. + */ + public static Presence toNuvemPresence( + org.jivesoftware.smack.packet.Presence presence) { + String from = presence.getFrom(); + String to = presence.getTo(); + String status = presence.getStatus(); + Show show = showConverstionMap.get(presence.getMode()); + Type type = typeConversionMap.get(presence.getType()); + PresenceBuilder builder = new PresenceBuilder().withShow(show) + .withType(type).withStatus(status); + builder.from(new JID(from)); + if (StringUtils.isNotEmpty(to)) { + builder.to(new JID(to)); + } + return builder.build(); + } +} Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/RosterListenerAdapter.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/RosterListenerAdapter.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/RosterListenerAdapter.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/RosterListenerAdapter.java Sat May 7 23:23:12 2011 @@ -0,0 +1,63 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import java.util.Collection; + +import org.apache.nuvem.cloud.xmpp.presence.PresenceListener; + +/** + * Listens to smack roster events and adapts it to nuvem roster events. + * + */ +public class RosterListenerAdapter implements + org.jivesoftware.smack.RosterListener { + + /** + * Nuvem Roster Listener. + */ + private PresenceListener listener; + + public RosterListenerAdapter(PresenceListener listener) { + this.listener = listener; + } + + @Override + public void entriesAdded(Collection arg0) { + + } + + @Override + public void entriesDeleted(Collection arg0) { + + } + + @Override + public void entriesUpdated(Collection arg0) { + + } + + @Override + public void presenceChanged(org.jivesoftware.smack.packet.Presence presence) { + listener.listen(PresenceAdapter + .toNuvemPresence(presence)); + } +} \ No newline at end of file Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/SSLConnector.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/SSLConnector.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/SSLConnector.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/SSLConnector.java Sat May 7 23:23:12 2011 @@ -0,0 +1,98 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import java.util.Map; + +import javax.net.SocketFactory; +import javax.net.ssl.SSLSocketFactory; + +import org.apache.nuvem.cloud.xmpp.XMPPConnector; +import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.SASLAuthentication; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; +import org.oasisopen.sca.annotation.Property; +import org.oasisopen.sca.annotation.Reference; +import org.oasisopen.sca.annotation.Service; + +/** + * Establishes a secure Stream to the XMPPServer. + * + */ +@Service(XMPPConnector.class) +public final class SSLConnector extends AbstractConnector { + + @Property + protected String trustStorePath; + @Property + protected String trustStorePassword; + @Reference(required = false) + protected SocketFactory socketFactory = SSLSocketFactory.getDefault(); + + /** + * {@inheritDoc} + */ + public XMPPConnection getConnection(Map connectionProperties) { + throw new UnsupportedOperationException("still not supported"); + } + + /** + * {@inheritDoc} + */ + public String getDescription() { + return "Single Connection Default connector"; + } + + @Override + protected void checkConfigurations() { + if (host == null || port == 0 || clientJID == null + || clientPassword == null || trustStorePassword == null + || trustStorePath == null) { + throw new IllegalStateException( + "the configuration parameters are not initlaized properly!"); + } + } + + /** + * Establishes a secure connection with the XMPP Server. + */ + protected void establishConnection() throws XMPPException { + ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration( + host, port, serviceName); + connectionConfiguration + .setSecurityMode(ConnectionConfiguration.SecurityMode.enabled); + connectionConfiguration.setSocketFactory(socketFactory); + connectionConfiguration.setTruststorePath(trustStorePath); + connectionConfiguration.setTruststorePassword(trustStorePassword); + SASLAuthentication.supportSASLMechanism(authenticationMechanism, 0); + this.connection = new XMPPConnection(connectionConfiguration); + this.connection.connect(); + } + + /** + * Authenticates with the XMPP Server. + */ + protected void authenticateWithServer() throws XMPPException { + this.connection.login(this.clientJID, this.clientPassword); + + } + +} Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/SimpleConnector.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/SimpleConnector.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/SimpleConnector.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/SimpleConnector.java Sat May 7 23:23:12 2011 @@ -0,0 +1,75 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import org.apache.nuvem.cloud.xmpp.XMPPConnector; +import org.jivesoftware.smack.ConnectionConfiguration; +import org.jivesoftware.smack.SASLAuthentication; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; +import org.oasisopen.sca.annotation.Service; + +/** + * Helps establish a connection to the XMPP Server and returns the same + * connection instance once connected. This specific implementation of + * {@link XMPPConnector} will try to connect to the XMPPServer in an unsecured + * way called. For more secure way of connecting to the XMPP server, please use + * {@link SSLConnector} + * + */ +@Service(XMPPConnector.class) +public class SimpleConnector extends AbstractConnector { + + /** + * {@inheritDoc} + */ + public String getDescription() { + return "Single Connection Default connector"; + } + + @Override + protected void checkConfigurations() { + if (host == null || port == 0 || clientJID == null + || clientPassword == null) { + throw new IllegalStateException( + "the configuration parameters are not initlaized properly!"); + } + } + + /** + * Establishes a simple connection with the XMPP Server. + */ + protected void establishConnection() throws XMPPException { + ConnectionConfiguration connectionConfiguration = new ConnectionConfiguration( + host, port, serviceName); + SASLAuthentication.supportSASLMechanism(authenticationMechanism, 0); + this.connection = new XMPPConnection(connectionConfiguration); + connection.connect(); + } + + /** + * Authenticates with the XMPPServer using client JID and password. + */ + protected void authenticateWithServer() throws XMPPException { + this.connection.login(this.clientJID, this.clientPassword); + + } + +} Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/StatusAdapter.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/StatusAdapter.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/StatusAdapter.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/client/StatusAdapter.java Sat May 7 23:23:12 2011 @@ -0,0 +1,61 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.nuvem.cloud.xmpp.Error; +import org.apache.nuvem.cloud.xmpp.ErrorCode; +import org.apache.nuvem.cloud.xmpp.Status; +import org.jivesoftware.smack.packet.XMPPError; + +/** + * Acts as an adapter to transform the status recieved by the the send API to + * the form compatible with nuvem. + */ +public class StatusAdapter { + + /** + * converstion map. + */ + private static Map converstionMap; + + static { + converstionMap = new HashMap(); + converstionMap.put(Integer.valueOf(400), ErrorCode.BAD_FORMAT); + converstionMap.put(Integer.valueOf(401), ErrorCode.NOT_AUTHORIZED); + converstionMap.put(Integer.valueOf(408), ErrorCode.CONNECTION_TIMEOUT); + } + + public static Status toStatus(XMPPError xmppError) { + Status status = new Status(); + if (xmppError != null + && converstionMap.containsKey(xmppError.getCode())) { + status.addError(new Error(converstionMap.get(xmppError.getCode()), + xmppError.getMessage())); + return status; + } + status.addError(new Error(ErrorCode.UNKNOWN_ERROR, xmppError + .getMessage())); + return status; + + } +} Added: incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/server/DefaultXMPPServer.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/server/DefaultXMPPServer.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/server/DefaultXMPPServer.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/java/org/apache/nuvem/cloud/xmpp/server/DefaultXMPPServer.java Sat May 7 23:23:12 2011 @@ -0,0 +1,122 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.server; + +import java.io.File; +import java.io.IOException; + +import org.apache.nuvem.cloud.xmpp.XMPPServer; +import org.apache.vysper.mina.TCPEndpoint; +import org.apache.vysper.stanzasession.StanzaSessionFactory; +import org.apache.vysper.storage.StorageProviderRegistry; +import org.apache.vysper.storage.inmemory.MemoryStorageProviderRegistry; +import org.apache.vysper.xmpp.authorization.AccountManagement; +import org.apache.vysper.xmpp.modules.extension.xep0049_privatedata.PrivateDataModule; +import org.apache.vysper.xmpp.modules.extension.xep0054_vcardtemp.VcardTempModule; +import org.apache.vysper.xmpp.modules.extension.xep0092_software_version.SoftwareVersionModule; +import org.apache.vysper.xmpp.modules.extension.xep0119_xmppping.XmppPingModule; +import org.apache.vysper.xmpp.modules.extension.xep0202_entity_time.EntityTimeModule; +import org.oasisopen.sca.annotation.Service; + +/** + * Default XMPP Server + */ +@Service(XMPPServer.class) +public class DefaultXMPPServer implements XMPPServer { + + private static String DEFAULT_HOST = "localhost"; + + private org.apache.vysper.xmpp.server.XMPPServer server; + + /** + * Default constructor + */ + public DefaultXMPPServer() { + + } + + /** + * {@inheritDoc} + */ + public void start() { + try { + StorageProviderRegistry providerRegistry = new MemoryStorageProviderRegistry(); + + final AccountManagement accountManagement = (AccountManagement) providerRegistry + .retrieve(AccountManagement.class); + + accountManagement.addUser("nuvem@localhost", "password"); + accountManagement.addUser("reciever@localhost", "password"); + + server = new org.apache.vysper.xmpp.server.XMPPServer(DEFAULT_HOST); + server.addEndpoint(new TCPEndpoint()); + server.addEndpoint(new StanzaSessionFactory()); + server.setStorageProviderRegistry(providerRegistry); + + server + .setTLSCertificateInfo(new File( + "C:\\john\\nuvem\\ssl\\bogus_mina_tls.cert"), + "boguspw"); + + try { + server.start(); + System.out.println("vysper server is running..."); + } catch (Exception e) { + e.printStackTrace(); + } + + server.addModule(new SoftwareVersionModule()); + server.addModule(new EntityTimeModule()); + server.addModule(new VcardTempModule()); + server.addModule(new XmppPingModule()); + server.addModule(new PrivateDataModule()); + + // server.addModule(new MUCModule()); + } catch (Exception e) { + // TODO Auto-generated catch block + e.printStackTrace(); + } + + } + + /** + * Stop the XMPP Server and perform any cleanup necessary + */ + public void stop() { + server.stop(); + + } + + /** + * For debug/test purposes only + * + * @param args + * @throws IOException + */ + public static void main(String args[]) throws IOException { + DefaultXMPPServer server = new DefaultXMPPServer(); + server.start(); + System.out.println("XMPP server started !!!"); + System.in.read(); + System.out.println("Stopping ..."); + server.stop(); + System.out.println(); + } +} Added: incubator/nuvem/trunk/nuvem-standalone/src/main/resources/META-INF/sca-contribution.xml URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/resources/META-INF/sca-contribution.xml?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/resources/META-INF/sca-contribution.xml (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/resources/META-INF/sca-contribution.xml Sat May 7 23:23:12 2011 @@ -0,0 +1,25 @@ + + + + + + \ No newline at end of file Added: incubator/nuvem/trunk/nuvem-standalone/src/main/resources/config/bogus_mina_tls.cert URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/resources/config/bogus_mina_tls.cert?rev=1100659&view=auto ============================================================================== Binary file - no diff available. Propchange: incubator/nuvem/trunk/nuvem-standalone/src/main/resources/config/bogus_mina_tls.cert ------------------------------------------------------------------------------ svn:mime-type = application/octet-stream Added: incubator/nuvem/trunk/nuvem-standalone/src/main/resources/config/xmpp.cert URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/resources/config/xmpp.cert?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/resources/config/xmpp.cert (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/resources/config/xmpp.cert Sat May 7 23:23:12 2011 @@ -0,0 +1,13 @@ +-----BEGIN CERTIFICATE----- +MIICTjCCAbcCBE2Y3+wwDQYJKoZIhvcNAQEEBQAwbjELMAkGA1UEBhMCSU4xEzARBgNVBAgTCkth +cmFuYXRha2ExEjAQBgNVBAcTCUJhbmdhbG9yZTEPMA0GA1UEChMGYXBhY2hlMQ4wDAYDVQQLEwVu +dXZlbTEVMBMGA1UEAxMMSm9obiBQcmFkZWVwMB4XDTExMDQwMzIxMDAyOFoXDTExMDcwMjIxMDAy +OFowbjELMAkGA1UEBhMCSU4xEzARBgNVBAgTCkthcmFuYXRha2ExEjAQBgNVBAcTCUJhbmdhbG9y +ZTEPMA0GA1UEChMGYXBhY2hlMQ4wDAYDVQQLEwVudXZlbTEVMBMGA1UEAxMMSm9obiBQcmFkZWVw +MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCCILFDAUPmDytYj4PTEn8Fqdr66BaLsclAcvqL +65kqmoELJOr+9g0QO5vneJVXv1HDbVs+z0+YZgUwBPu/kE5d1j8ZYJhbxgxWOSPBsWb1Fcr72VRc +duSwSlqIuDIx5Kzgd4yltvyE5QLepve6buWgiGYcQx3Ezu1H/SQR7JUjrwIDAQABMA0GCSqGSIb3 +DQEBBAUAA4GBAFs2SsUTIBPZn5itVuRWCSVc+o9i7dej/XD/x1uRwCxUj2oX5CSTOMib7NFZe2cU +NDJlE/tHlJTXRpcvDcBDFvQRExLvhQYd/Gsvccyx5JUmHYHCs3S/Rdx4mqXIXlJ4IKpG3hsDNeKg +3TdzJMoAbS3iYe7SI61fBejDLAKEvPVo +-----END CERTIFICATE----- Added: incubator/nuvem/trunk/nuvem-standalone/src/main/resources/nuvemxmpp.composite URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/main/resources/nuvemxmpp.composite?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/main/resources/nuvemxmpp.composite (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/main/resources/nuvemxmpp.composite Sat May 7 23:23:12 2011 @@ -0,0 +1,66 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + nuvem@localhost + password + + + + + + + + nuvem@localhost + password + truststorepath + changeit + + + Added: incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/data/impl/MapDocumentServiceImplTestCase.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/data/impl/MapDocumentServiceImplTestCase.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/data/impl/MapDocumentServiceImplTestCase.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/data/impl/MapDocumentServiceImplTestCase.java Sat May 7 23:23:12 2011 @@ -0,0 +1,5 @@ +package org.apache.nuvem.cloud.data.impl; + +public class MapDocumentServiceImplTestCase { + +} Added: incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/xmpp/client/DefaultXMPPEndPointTestCase.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/xmpp/client/DefaultXMPPEndPointTestCase.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/xmpp/client/DefaultXMPPEndPointTestCase.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/xmpp/client/DefaultXMPPEndPointTestCase.java Sat May 7 23:23:12 2011 @@ -0,0 +1,105 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import static org.easymock.EasyMock.createMock; +import static org.easymock.EasyMock.expect; +import static org.easymock.EasyMock.expectLastCall; +import static org.easymock.EasyMock.isA; +import static org.easymock.EasyMock.replay; + +import org.apache.nuvem.cloud.xmpp.Status; +import org.apache.nuvem.cloud.xmpp.XMPPConnector; +import org.apache.nuvem.cloud.xmpp.XMPPEndPoint; +import org.jivesoftware.smack.Chat; +import org.jivesoftware.smack.ChatManager; +import org.jivesoftware.smack.XMPPConnection; +import org.jivesoftware.smack.XMPPException; +import org.jivesoftware.smack.packet.XMPPError; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +public class DefaultXMPPEndPointTestCase { + + private static final String RECIPIENT = "recipient@host.com"; + + private static final String MESSAGE = "hi"; + + private XMPPConnector connector; + private XMPPConnection connection; + private ChatManager chatManager; + private Chat chat; + + private XMPPEndPoint endPoint; + + @Before + public void init() { + connection = createMock(XMPPConnection.class); + chatManager = createMock(ChatManager.class); + connector = createMock(XMPPConnector.class); + expect(connector.getConnection()).andReturn(connection); + chat = createMock(Chat.class); + endPoint = new DefaultXMPPEndPoint(connector); + } + + + @Test + public void shouldBeAbleToSendMessage() throws XMPPException, + IllegalArgumentException, IllegalAccessException { + expect(connection.isConnected()).andReturn(true); + expect(connection.getChatManager()).andReturn(chatManager); + expect( + chatManager.createChat(isA(String.class), + isA(MessageListenerAdapter.class))) + .andReturn(chat); + chat.sendMessage(MESSAGE); + expectLastCall(); + replay(connection); + replay(chatManager); + replay(chat); + replay(connector); + Status status = endPoint.sendTextMessage(MESSAGE, RECIPIENT); + Assert.assertNotNull(status); + Assert.assertTrue(!status.hasErrors()); + } + + @Test + public void shouldBeAbleToIdentifyErrors() throws IllegalArgumentException, + IllegalAccessException, XMPPException { + expect(connection.isConnected()).andReturn(true); + expect(connection.getChatManager()).andReturn(chatManager); + expect( + chatManager.createChat(isA(String.class), + isA(MessageListenerAdapter.class))) + .andReturn(chat); + chat.sendMessage(MESSAGE); + expectLastCall().andThrow( + new XMPPException("error", new XMPPError(302, "error"))); + replay(connection); + replay(chatManager); + replay(chat); + replay(connector); + Status status = endPoint.sendTextMessage(MESSAGE, RECIPIENT); + Assert.assertNotNull(status); + Assert.assertTrue(status.hasErrors()); + } + +} Added: incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/xmpp/client/XMPPEndPointIntegrationTest.java URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/xmpp/client/XMPPEndPointIntegrationTest.java?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/xmpp/client/XMPPEndPointIntegrationTest.java (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/test/java/org/apache/nuvem/cloud/xmpp/client/XMPPEndPointIntegrationTest.java Sat May 7 23:23:12 2011 @@ -0,0 +1,102 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.nuvem.cloud.xmpp.client; + +import junit.framework.Assert; + +import org.apache.nuvem.cloud.xmpp.JID; +import org.apache.nuvem.cloud.xmpp.XMPPEndPoint; +import org.apache.nuvem.cloud.xmpp.XMPPServer; +import org.apache.nuvem.cloud.xmpp.message.Message; +import org.apache.nuvem.cloud.xmpp.message.MessageListener; +import org.apache.nuvem.cloud.xmpp.server.DefaultXMPPServer; +import org.apache.tuscany.sca.node.Node; +import org.apache.tuscany.sca.node.NodeFactory; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class XMPPEndPointIntegrationTest { + + private static XMPPServer server; + private static Node xmppNode; + private static XMPPEndPoint xmppEndPointSender; + private static XMPPEndPoint xmppEndPointReciever; + + @BeforeClass + public static void setUp() throws Exception { + server = new DefaultXMPPServer(); + server.start(); + xmppNode = NodeFactory.getInstance().createNode( + "testnuvemxmpp.composite"); + xmppNode.start(); + xmppEndPointSender = xmppNode.getService(XMPPEndPoint.class, + "TestXMPPComponentSender/XMPPEndPoint"); + xmppEndPointReciever = xmppNode.getService(XMPPEndPoint.class, + "TestXMPPComponentReciever/XMPPEndPoint"); + + } + + @AfterClass + public static void tearDown() throws Exception { + if (xmppNode != null) { + xmppNode.stop(); + } + if (server != null) { + server.stop(); + } + } + + + @Test + public void SendAndRecieveMessage() throws InterruptedException { + final String message = "hello xmpp"; + MessageListenerValidator validator = new MessageListenerValidator( + message); + xmppEndPointReciever.registerListner(new JID("nuvem@localhost"), + validator); + xmppEndPointSender.sendTextMessage(message, "reciever@localhost"); + Thread.sleep(3000); + validator.checkIfValidMessageRecieved(); + } + + public class MessageListenerValidator implements MessageListener { + + private Message recievedMessage = null; + + private String expectedMessage; + + public MessageListenerValidator(String expectedMessage) { + this.expectedMessage = expectedMessage; + } + + @Override + public void listen(Message message) { + this.recievedMessage = message; + } + + public void checkIfValidMessageRecieved() { + Assert.assertNotNull(recievedMessage); + Assert.assertTrue(expectedMessage.equals(recievedMessage.payLoad() + .content())); + } + } + +} Added: incubator/nuvem/trunk/nuvem-standalone/src/test/resources/testnuvemxmpp.composite URL: http://svn.apache.org/viewvc/incubator/nuvem/trunk/nuvem-standalone/src/test/resources/testnuvemxmpp.composite?rev=1100659&view=auto ============================================================================== --- incubator/nuvem/trunk/nuvem-standalone/src/test/resources/testnuvemxmpp.composite (added) +++ incubator/nuvem/trunk/nuvem-standalone/src/test/resources/testnuvemxmpp.composite Sat May 7 23:23:12 2011 @@ -0,0 +1,104 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + nuvem@localhost + password + truststorepath + changeit + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + reciever@localhost + password + + + + + + + + nuvem@localhost + password + + + +