Smack version 3.1.0 and GMail server
October 19th, 2010Currently I’m working on my Master’s Dissertation, and one of my needs is to connect a XMPP server, GMail for instance.
To do this, I was using Smack version 3.0.0 and everything was going well, even connecting GMail, but… when I did update to version 3.1.0 it started to show an f@&*$!* error message: SASL authentication failed using mechanism PLAIN
It took a while (at least to me ), but I was able to figure out this solution. Note: I’ve googled a lot without success ;-)
So, bellow is the working code, hope it helps you.
Cheers,
Vilson C. Gärtner
http://twitter.com/VilsonGartner
Code
public static void main(String[] args) | |
{ | |
| |
System.out.println("Starting..."); | |
| |
ConnectionConfiguration connCfg = new ConnectionConfiguration("talk.google.com", 5222, "gmail.com"); | |
| |
connCfg.setSASLAuthenticationEnabled(false); | |
XMPPConnection connection = new XMPPConnection(connCfg); | |
| |
System.out.println("Connecting..."); | |
try | |
{ | |
connection.connect(); | |
System.out.println("Connected to " + connection.getHost()); | |
} | |
catch (XMPPException ex) | |
{ | |
System.out.println("Failed to connect to " + connection.getHost() + ": " + ex.getMessage()); | |
System.exit(1); | |
} | |
| |
System.out.println("Loggin in..."); | |
| |
try | |
{ | |
connection.login("userName", "password"); | |
System.out.println("Logged in as " + connection.getUser()); | |
| |
Presence presence = new Presence(Presence.Type.available); | |
connection.sendPacket(presence); | |
| |
} | |
catch (XMPPException ex) | |
{ | |
System.out.println("Failed to log in as " + connection.getUser() + ": " + ex.getMessage()); | |
System.exit(1); | |
} | |
| |
Roster roster = connection.getRoster(); | |
Collection<RosterEntry> entries = roster.getEntries(); | |
| |
System.out.println("\n\n" + entries.size() + " buddy(ies):"); | |
for (RosterEntry r : entries) | |
{ | |
System.out.println(r.getUser()); | |
} | |
| |
connection.disconnect(); | |
} |
Criar um arquivo novo no Netbeans via programação
October 16th, 2010(English note: this post is about creating a new file programatically in Netbeans. Bellow is the code I used to do it. If you want to read this post in english, access this link: http://vgdata.net/l/10787/ - Google Translator )
Como você deve saber (ou não) o Netbeans é uma IDE que possibilita sua expansão através da criação de plugins. Aliás, só para registrar, no Netbeans os plugins são chamados de Módulos.
Além disso, o Netbeans possui um framework sobre o qual é possível desenvolver aplicativos, mas sem a necessidade de ter que carregar toda a IDE. Mas enfim, isso é assunto para outro post.
Dito isso, vamos ao que trata o assunto: criar um arquivo novo no Netbeans via programação.
Caso você esteja desenvolvendo um módulo no Netbeans e necessite criar um novo documento, adicionar um conteúdo e então abrir ele no Netbeans, segue o código que utilizo para isso:
Code
// Caminho e nome do arquivo | |
String fileName = "path_and_file.java"; | |
| |
// Criar o novo arquivo | |
PrintWriter out = new PrintWriter(new FileWriter(fileName)); | |
// Adicionar o conteúdo | |
out.println("conteúdo a ser colocado no arquivo"); | |
// Fechar | |
out.close(); | |
| |
// Agora é só abrir no Netbeans | |
DataObject file = DataObject.find(FileUtil.toFileObject(new File(fileName))); | |
Openable fileOpener = file.getLookup().lookup(Openable.class); | |
fileOpener.open(); |
Barbada, hein?! ;-)
Não esqueça de deixar seus comentários/feedback.
[ ]’s
Vilson C. Gärtner
http://twitter.com/VilsonGartner