I am trying to search an user in open fire.
public void searchUser(String username) {
UserSearchManager userSearchManager = new UserSearchManager(
xmppConnection);
Form searchForm;
try {
searchForm = userSearchManager.getSearchForm("search."
+ xmppConnection.getServiceName());
Form answerForm = searchForm.createAnswerForm();
answerForm.setAnswer("Username", true);
answerForm.setAnswer("search", username);
org.jivesoftware.smackx.ReportedData data = userSearchManager
.getSearchResults(answerForm,
"search." + xmppConnection.getServiceName());
if (data.getRows() != null) {
Iterator<Row> it = data.getRows();
while (it.hasNext()) {
Row row = it.next();
Iterator<?> iterator = row.getValues("jid");
if (iterator.hasNext()) {
String value = iterator.next().toString();
System.out.println(value);
}
}
}
} catch (XMPPException e) {
e.printStackTrace();
}
}
There are some similar thread so i followed them and added this provider manager before connection.
public void getProviderManager(ProviderManager providerManager) {
// Private Data Storage
providerManager.addIQProvider("query", "jabber:iq:private",
new PrivateDataManager.PrivateDataIQProvider());
// Time
try {
providerManager.addIQProvider("query", "jabber:iq:time",
Class.forName("org.jivesoftware.smackx.packet.Time"));
} catch (ClassNotFoundException e) {
Log.w("TestClient",
"Can't load class for org.jivesoftware.smackx.packet.Time");
}
// Roster Exchange
providerManager.addExtensionProvider("x", "jabber:x:roster",
new RosterExchangeProvider());
// Message Events
providerManager.addExtensionProvider("x", "jabber:x:event",
new MessageEventProvider());
// Chat State
providerManager.addExtensionProvider("active",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
providerManager.addExtensionProvider("composing",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
providerManager.addExtensionProvider("paused",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
providerManager.addExtensionProvider("inactive",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
providerManager.addExtensionProvider("gone",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
// XHTML
providerManager.addExtensionProvider("html",
"http://jabber.org/protocol/xhtml-im",
new XHTMLExtensionProvider());
// Group Chat Invitations
providerManager.addExtensionProvider("x", "jabber:x:conference",
new GroupChatInvitation.Provider());
// Service Discovery # Items
providerManager.addIQProvider("query",
"http://jabber.org/protocol/disco#items",
new DiscoverItemsProvider());
// Service Discovery # Info
providerManager.addIQProvider("query",
"http://jabber.org/protocol/disco#info",
new DiscoverInfoProvider());
// Data Forms
providerManager.addExtensionProvider("x", "jabber:x:data",
new DataFormProvider());
// MUC User
providerManager.addExtensionProvider("x",
"http://jabber.org/protocol/muc#user", new MUCUserProvider());
// MUC Admin
providerManager.addIQProvider("query",
"http://jabber.org/protocol/muc#admin", new MUCAdminProvider());
// MUC Owner
providerManager.addIQProvider("query",
"http://jabber.org/protocol/muc#owner", new MUCOwnerProvider());
// Delayed Delivery
providerManager.addExtensionProvider("x", "jabber:x:delay",
new DelayInformationProvider());
// Version
try {
providerManager.addIQProvider("query", "jabber:iq:version",
Class.forName("org.jivesoftware.smackx.packet.Version"));
} catch (ClassNotFoundException e) {
// Not sure what's happening here.
}
// VCard
providerManager.addIQProvider("vCard", "vcard-temp",
new VCardProvider());
// Offline Message Requests
providerManager.addIQProvider("offline",
"http://jabber.org/protocol/offline",
new OfflineMessageRequest.Provider());
// Offline Message Indicator
providerManager.addExtensionProvider("offline",
"http://jabber.org/protocol/offline",
new OfflineMessageInfo.Provider());
// Last Activity
providerManager.addIQProvider("query", "jabber:iq:last",
new LastActivity.Provider());
// User Search
providerManager.addIQProvider("query", "jabber:iq:search",
new UserSearch.Provider());
// SharedGroupsInfo
providerManager.addIQProvider("sharedgroup",
"http://www.jivesoftware.org/protocol/sharedgroup",
new SharedGroupsInfo.Provider());
// JEP-33: Extended Stanza Addressing
providerManager.addExtensionProvider("addresses",
"http://jabber.org/protocol/address",
new MultipleAddressesProvider());
// FileTransfer
providerManager.addIQProvider("si", "http://jabber.org/protocol/si",
new StreamInitiationProvider());
providerManager.addIQProvider("query",
"http://jabber.org/protocol/bytestreams",
new BytestreamsProvider());
// Privacy
providerManager.addIQProvider("query", "jabber:iq:privacy",
new PrivacyProvider());
providerManager.addIQProvider("command",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider());
providerManager.addExtensionProvider("malformed-action",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.MalformedActionError());
providerManager.addExtensionProvider("bad-locale",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.BadLocaleError());
providerManager.addExtensionProvider("bad-payload",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.BadPayloadError());
providerManager.addExtensionProvider("bad-sessionid",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.BadSessionIDError());
providerManager.addExtensionProvider("session-expired",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.SessionExpiredError());
}
Still i am getting
12-07 01:14:58.027: W/System.err(1591): bad-request(400)
12-07 01:14:58.037: W/System.err(1591): at org.jivesoftware.smackx.search.UserSearch.getSearchForm(UserSearch.java:84)
12-07 01:14:58.037: W/System.err(1591): at org.jivesoftware.smackx.search.UserSearchManager.getSearchForm(UserSearchManager.java:73)
12-07 01:14:58.037: W/System.err(1591): at com.afinity.core.chat.ChatManager.searchUser(ChatManager.java:107)
12-07 01:14:58.037: W/System.err(1591): at com.afinity.chat.ui.Activity.<init>(Activity.java:19)
12-07 01:14:58.037: W/System.err(1591): at java.lang.Class.newInstanceImpl(Native Method)
12-07 01:14:58.047: W/System.err(1591): at java.lang.Class.newInstance(Class.java:1208)
12-07 01:14:58.047: W/System.err(1591): at android.app.Instrumentation.newActivity(Instrumentation.java:1061)
12-07 01:14:58.047: W/System.err(1591): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2093)
12-07 01:14:58.047: W/System.err(1591): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2226)
12-07 01:14:58.047: W/System.err(1591): at android.app.ActivityThread.access$700(ActivityThread.java:135)
12-07 01:14:58.047: W/System.err(1591): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1397)
12-07 01:14:58.047: W/System.err(1591): at android.os.Handler.dispatchMessage(Handler.java:102)
12-07 01:14:58.047: W/System.err(1591): at android.os.Looper.loop(Looper.java:137)
12-07 01:14:58.047: W/System.err(1591): at android.app.ActivityThread.main(ActivityThread.java:4998)
12-07 01:14:58.047: W/System.err(1591): at java.lang.reflect.Method.invokeNative(Native Method)
12-07 01:14:58.047: W/System.err(1591): at java.lang.reflect.Method.invoke(Method.java:515)
12-07 01:14:58.047: W/System.err(1591): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:777)
12-07 01:14:58.047: W/System.err(1591): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:593)
12-07 01:14:58.047: W/System.err(1591): at dalvik.system.NativeStart.main(Native Method)
I solve this problem by the following steps:
step 1:invoke the follow method configure before invoking XMPPConnection's connection.
step 2:invoke XMPPConnection's addConnectionListener and addPacketListener after invoking login(make sure XMPPConnection's isAuthenticated is true).
The configure method:
public void configure(ProviderManager pm) {
pm.addIQProvider("query", "jabber:iq:private",
new PrivateDataManager.PrivateDataIQProvider());
// Time
try {
pm.addIQProvider("query", "jabber:iq:time",
Class.forName("org.jivesoftware.smackx.packet.Time"));
} catch (Exception e) {
e.printStackTrace();
}
// Roster Exchange
pm.addExtensionProvider("x", "jabber:x:roster",
new RosterExchangeProvider());
// Message Events
pm.addExtensionProvider("x", "jabber:x:event",
new MessageEventProvider());
// Chat State
pm.addExtensionProvider("active",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
pm.addExtensionProvider("composing",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
pm.addExtensionProvider("paused",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
pm.addExtensionProvider("inactive",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
pm.addExtensionProvider("gone",
"http://jabber.org/protocol/chatstates",
new ChatStateExtension.Provider());
// XHTML
pm.addExtensionProvider("html", "http://jabber.org/protocol/xhtml-im",
new XHTMLExtensionProvider());
// Group Chat Invitations
pm.addExtensionProvider("x", "jabber:x:conference",
new GroupChatInvitation.Provider());
pm.addIQProvider("query", "http://jabber.org/protocol/disco#items",
new DiscoverItemsProvider());
pm.addIQProvider("query", "http://jabber.org/protocol/disco#info",
new DiscoverInfoProvider());
// Data Forms
pm.addExtensionProvider("x", "jabber:x:data", new DataFormProvider());
// MUC User
pm.addExtensionProvider("x", "http://jabber.org/protocol/muc#user",
new MUCUserProvider());
// MUC Admin
pm.addIQProvider("query", "http://jabber.org/protocol/muc#admin",
new MUCAdminProvider());
// MUC Owner
pm.addIQProvider("query", "http://jabber.org/protocol/muc#owner",
new MUCOwnerProvider());
// Delayed Delivery
pm.addExtensionProvider("x", "jabber:x:delay",
new DelayInformationProvider());
// Version
try {
pm.addIQProvider("query", "jabber:iq:version",
Class.forName("org.jivesoftware.smackx.packet.Version"));
} catch (ClassNotFoundException e) {
// Not sure what's happening here.
}
// VCard
pm.addIQProvider("vCard", "vcard-temp", new VCardProvider());
// Offline Message Requests
pm.addIQProvider("offline", "http://jabber.org/protocol/offline",
new OfflineMessageRequest.Provider());
// Offline Message Indicator
pm.addExtensionProvider("offline",
"http://jabber.org/protocol/offline",
new OfflineMessageInfo.Provider());
// Last Activity
pm.addIQProvider("query", "jabber:iq:last", new LastActivity.Provider());
// User Search
pm.addIQProvider("query", "jabber:iq:search", new UserSearch.Provider());
// SharedGroupsInfo
pm.addIQProvider("sharedgroup",
"http://www.jivesoftware.org/protocol/sharedgroup",
new SharedGroupsInfo.Provider());
// JEP-33: Extended Stanza Addressing
pm.addExtensionProvider("addresses",
"http://jabber.org/protocol/address",
new MultipleAddressesProvider());
pm.addIQProvider("si", "http://jabber.org/protocol/si",
new StreamInitiationProvider());
pm.addIQProvider("query", "http://jabber.org/protocol/bytestreams",
new BytestreamsProvider());
pm.addIQProvider("query", "jabber:iq:privacy", new PrivacyProvider());
pm.addIQProvider("command", "http://jabber.org/protocol/commands",
new AdHocCommandDataProvider());
pm.addExtensionProvider("malformed-action",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.MalformedActionError());
pm.addExtensionProvider("bad-locale",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.BadLocaleError());
pm.addExtensionProvider("bad-payload",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.BadPayloadError());
pm.addExtensionProvider("bad-sessionid",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.BadSessionIDError());
pm.addExtensionProvider("session-expired",
"http://jabber.org/protocol/commands",
new AdHocCommandDataProvider.SessionExpiredError());
}
Related
I am using Kafka. This is my code , where i want to send messages to kafka server,Topic name is "west" with message "message1".I'm not getting any error though i haven't seen my sent messages in the topic is there anything wrong here?
class SimpleProducer {
public static void main(String[] args) throws Exception{
Properties props = new Properties();
props.put("bootstrap.servers","172.xxxxxxxxx:9092");
props.put("serializer.class", "kafka.serializer.DefaultEncoder");
props.put("acks", "1");
props.put("retries", 1);
props.put("batch.size", 16384);
props.put("linger.ms", 0);
props.put("client.id", "foo");
props.put("buffer.memory", 33554432);
props.put("timeout.ms", "500");
props.put("key.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.put("value.serializer", "org.apache.kafka.common.serialization.StringSerializer");
props.setProperty(ProducerConfig.MAX_BLOCK_MS_CONFIG, "500");
props.setProperty(ProducerConfig.RETRY_BACKOFF_MS_CONFIG, "100");
System.out.println("ready to send msg");
try {
Producer<String, String> producer = new KafkaProducer<String, String>(props);
producer.send(new ProducerRecord<String, String>("west","message1"));
System.out.println("Message sent successfully");
producer.close();
}
catch(Exception e)
{
System.out.println("Messgae doesn't sent successfully");
e.printStackTrace();
}
}
}
The API you used to send the message is asynchronous. Use the form of send() which has two arguments. The second argument is a Callback which you can use to see if the send really worked or if there was an error somewhere.
producer.send(yourRecord,
new Callback() {
public void onCompletion(RecordMetadata metadata, Exception e) {
if(e != null) {
e.printStackTrace();
} else {
System.out.println("The offset of the record we just sent is: " + metadata.offset());
}
}
});
I'm trying to write a XMPP client to connect to Quickblox and use it as a bot for a chat application. I'm using Smack 4.1.3 for this purpose. Here's my code:
public static void sendChat1() {
XMPPTCPConnectionConfiguration config = XMPPTCPConnectionConfiguration.builder()
.setUsernameAndPassword("4461610-26179", "pass")
.setServiceName("chat.quickblox.com")
.setPort(5222)
.build();
System.out.println("Establishing Connection");
AbstractXMPPConnection conn2 = new XMPPTCPConnection(config);
try {
conn2.connect();
} catch (SmackException e) {
System.out.println("ERROR");
e.printStackTrace();
} catch (IOException e) {
System.out.println("ERROR");
e.printStackTrace();
} catch (XMPPException e) {
System.out.println("ERROR");
e.printStackTrace();
}
MultiUserChatManager manager = MultiUserChatManager.getInstanceFor(conn2);
System.out.println("Creating multi user chat room");
MultiUserChat muc = manager.getMultiUserChat("26179_55b76303535c12544b00b550#muc.chat.quickblox.com");
System.out.println("Joining chat room");
try {
muc.join("4461610");
} catch (XMPPException.XMPPErrorException e) {
System.out.println("ERROR");
e.printStackTrace();
return;
} catch (SmackException e) {
System.out.println("ERROR");
e.printStackTrace();
return;
}
System.out.println("Chat room request");
try {
muc.sendConfigurationForm(new Form(DataForm.Type.submit));
} catch (SmackException.NoResponseException e) {
System.out.println("ERROR");
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
System.out.println("ERROR");
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
System.out.println("ERROR");
e.printStackTrace();
}
}
public static void main(String[] args) {
sendChat1();
}
For some reason, I'm unable to make the client connect to a chat room using MultiUserChat. Here's the output when I run this code:
Establishing Connection
Creating multi user chat room
Joining chat room
ERROR
org.jivesoftware.smack.XMPPException$XMPPErrorException: XMPPError: not-authorized - auth
at org.jivesoftware.smack.XMPPException$XMPPErrorException.ifHasErrorThenThrow(XMPPException.java:135)
at org.jivesoftware.smack.PacketCollector.nextResultOrThrow(PacketCollector.java:232)
at org.jivesoftware.smackx.muc.MultiUserChat.enter(MultiUserChat.java:311)
at org.jivesoftware.smackx.muc.MultiUserChat.join(MultiUserChat.java:495)
at org.jivesoftware.smackx.muc.MultiUserChat.join(MultiUserChat.java:430)
at Main.sendChat1(Main.java:53)
at Main.main(Main.java:80)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:140)
Jul 29, 2015 12:52:36 AM org.jivesoftware.smack.roster.Roster$PresencePacketListener processPacket
WARNING: Roster not loaded while processing presence stanza
Process finished with exit code 0
I turned on debugging and found this:
Establishing Connection
01:28:55 AM SENT (0): <stream:stream xmlns='jabber:client' to='chat.quickblox.com' xmlns:stream='http://etherx.jabber.org/streams' version='1.0' from='4461610-26179#chat.quickblox.com#chat.quickblox.com' xml:lang='en'>
01:28:56 AM RECV (0): <?xml version='1.0'?><stream:stream xmlns='jabber:client' xmlns:stream='http://etherx.jabber.org/streams' id='tigase-error-tigase' from='chat.quickblox.com' version='1.0' xml:lang='en'><stream:error><improper-addressing xmlns='urn:ietf:params:xml:ns:xmpp-streams'/></stream:error></stream:stream>
The app configuration on quickblox seems correct as well. I've created a user that I'm using in this app. I've also created a public dialogue that is being used in this app as well. Not sure what's going on here.
Btw, I cannot use the SDKs provided with Quickblox since I've to deploy this code on my web server which is built on a java framework.
improper-addressing error says what it says
This jid is strange 4461610-26179#chat.quickblox.com#chat.quickblox.com
it should be just 4461610-26179#chat.quickblox.com
that's why you receive this error
I don't see where it could be a problem with this in your code, anyway please check such a possibility
I have problem with registering new user on my OpenFire server. This is a reply from server.
<iq id='XILKN-9' to='pc-pc/b529612d' from='192.168.21.107' type='error'>
<query xmlns='jabber:iq:register'>
<password>123</password>
<email>bear#bear.com</email>
<username>bear</username>
</query>
<error type="modify">
<bad-request xmlns="urn:ietf:params:xml:ns:xmpp-stanzas"/>
</error>
</iq>
But when I login with any existing user before registering new user, I can register new user successfully and this is the reply from server
<iq id='XILKN-15' to='kkk#pc-pc/Smack' from='pc-pc' type='result'></iq>
Here is my code :
String user ="bear";
String pass = "123";
String email = "bear#bear.com";
HashMap<String,String> attr = new HashMap<String, String>();
attr.put("username",user);
attr.put("password",pass);
attr.put("email", email);
if(conn2!=null) {
Registration reg = new Registration();
reg.setType(IQ.Type.SET);
reg.setTo(conn2.getServiceName());
reg.setAttributes(attr);
PacketFilter filter = new AndFilter(new PacketIDFilter(
reg.getPacketID()), new PacketTypeFilter(IQ.class));
PacketCollector collector = conn2 .createPacketCollector(filter);
try {
conn2.sendPacket(reg);
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
}
IQ result = (IQ) collector.nextResult(SmackConfiguration
.getDefaultPacketReplyTimeout());
System.out.println(result);
collector.cancel();
I used OpenFire 3.9.3 and aSmack 4.0.7 .
If I understand you correct I solve this issue by the next steps.
creat connection with the server.
then you use with AccountManager
then you create new account by createAccount
So with should be something like that:
AccountManager am = connection.getAccountManager();
Map<String, String> attributes = new HashMap<String, String>();
attributes.put("username", username);
attributes.put("password", password);
attributes.put("email", email);
attributes.put("name", name);
try {
am.createAccount(username, password,attributes);
Toast.makeText(getActivity(),"User create: " + username,Toast.LENGTH_SHORT).show();
} catch (XMPPException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
I just started witg greenDao, but i can't initialize the DaoGenerator : calling new DaoGenerator(); throws the exception
java.lang.ExceptionInInitializerError
at de.greenrobot.daogenerator.DaoGenerator.(DaoGenerator.java:60)
Here is my code:
Schema schema = new Schema(1,"com.emt.testdb.greendao");
schema.setDefaultJavaPackageTest("com.emt.testdb.greendao.test");
schema.setDefaultJavaPackageDao("com.emt.testdb.greendao.dao");
Entity user = schema.addEntity("User");
user.addIdProperty();
user.addStringProperty("name");
user.addStringProperty("password");
user.addIntProperty("yearOfBirth");
DaoGenerator daoGenerator = null;
try
{
daoGenerator = new DaoGenerator();
// daoGenerator.generateAll(schema, "../project/src-gen");
} catch (IOException e)
{
e.printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
many thanks for your help!
PostMethod post = new PostMethod(
"http://bbs.elecfans.com/member.php?action=login&mod=logging&loginsubmit=yes&loginhash=L55gn");
NameValuePair name = new NameValuePair("username", userName);
NameValuePair pass = new NameValuePair("password", password);
NameValuePair __VIEWSTATE = new NameValuePair(
"__VIEWSTATE",
"loginAddr");
NameValuePair btnLoginx = new NameValuePair("btnLogin.x", "0");
NameValuePair btnLoginy = new NameValuePair("btnLogin.y", "5");
post.setRequestBody(new NameValuePair[] { name, pass, __VIEWSTATE,
btnLoginx, btnLoginy });
try {
client.executeMethod(post);
} catch (HttpException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
post.releaseConnection();
tks
You need to analyze this log on address to find the correct login address and The HttpClient Head to the scrambling of data to.