I am using Smack version 4.5.0-beta5 for a C2S web socket implementation. I am trying to search for users but I am getting a java.lang.IllegalArgumentException on the getSearchForm method call, however the form does return.
Here is a code snippet:
public IMUserSearchResult[] searchForUser(IMUserSearchRequest searchRequest){
ArrayList<IMUserSearchResult> resultList = new ArrayList<IMUserSearchResult>();
boolean searchValuesValid = false;
try {
UserSearchManager searchMgr = new UserSearchManager(connection);
List<DomainBareJid> searchServices = searchMgr.getSearchServices();
for (DomainBareJid searchService: searchServices){
logger.debug("searchService = " + searchService);
//does not get pass the below line
Form searchForm = searchMgr.getSearchForm(searchService);
FillableForm fillableSearchForm = searchForm.getFillableForm();
if(searchRequest.getEmailAddress() != null &&
searchRequest.getEmailAddress().length() > 0){
logger.debug("Setting search value for email: " + searchRequest.getEmailAddress());
fillableSearchForm.setAnswer("mail", searchRequest.getEmailAddress());
searchValuesValid = true;
}
if(searchRequest.getFirstName() != null && searchRequest.getFirstName().length() > 0){
logger.debug("Setting search value for first name: " + searchRequest.getFirstName());
fillableSearchForm.setAnswer("givenname", searchRequest.getFirstName());
searchValuesValid = true;
}
if(searchRequest.getLastName() != null && searchRequest.getLastName().length() > 0){
logger.info("Setting search value for last name: " + searchRequest.getLastName());
fillableSearchForm.setAnswer("sn", searchRequest.getLastName());
searchValuesValid = true;
}
// Only want to search if the user has entered at least 1 value. Otherwise an error will be
// generated by the server.
if(searchValuesValid){
ReportedData rd = searchMgr.getSearchResults(fillableSearchForm,
JidCreate.domainBareFrom(userSearchService));
resultList = this.parseSearchResults(rd);
}
}
}
catch (Exception e) {
logger.error("Exception while searching for user: " + e);
e.printStackTrace();
}
return resultList.toArray(new IMUserSearchResult[resultList.size()]);
}
Error:
2024-11-21 21:08:37.830 [xmpp.client.XmppClientHandler.main()] ERROR xmpp.client.search.UserSearch - Exception while searching for user:
java.lang.IllegalArgumentException: Can not provide null argument
at org.jivesoftware.smack.util.Objects.requireNonNull(Objects.java:42)
at org.jivesoftware.smack.util.Objects.requireNonNull(Objects.java:48)
at org.jivesoftware.smackx.xdata.form.FilledForm.<init>(FilledForm.java:32)
at org.jivesoftware.smackx.xdata.form.Form.<init>(Form.java:26)
at org.jivesoftware.smackx.search.UserSearchManager.getSearchForm(UserSearchManager.java:79)
at xmpp.client.search.IMUserSearch.searchForUser(IMUserSearch.java:78)
at xmpp.client.XmppClient.getUserSearchResults(XmppClient.java:129)
at xmpp.client.XmppClientHandler.handleRequest(XmppClientHandler.java:61)
at xmpp.client.XmppClientHandler.main(XmppClientHandler.java:96)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.base/java.lang.reflect.Method.invoke(Method.java:566)
at org.codehaus.mojo.exec.ExecJavaMojo$1.run(ExecJavaMojo.java:282)
at java.base/java.lang.Thread.run(Thread.java:834)
XMPP output:
when=2024-11-21T21:08:37.811561+00:00 level=debug what=mam_user_send_packet pid=<0.32525.7> at=mod_mam:user_send_packet/4:276 from_jid="theresa@<domain>/IM_XMPP_LAMBDA_CLIENT - <server>" to_jid=directory.<domain> packet="<iq xmlns='jabber:client' to='directory.<domain>' id='YVTH8-15' type='get'><query xmlns='jabber:iq:search'/></iq>" origin_pid=<0.32525.7> acc_timestamp=2024-11-21T21:08:37.811499+00:00
when=2024-11-21T21:08:37.811701+00:00 level=debug what=route pid=<0.32525.7> at=ejabberd_router:route/4:153 from_jid="theresa@<domain>/IM_XMPP_LAMBDA_CLIENT - <server>" to_jid=directory.<domain> packet="<iq xmlns='jabber:client' to='directory.<domain>' id='YVTH8-15' type='get'><query xmlns='jabber:iq:search'/></iq>" origin_pid=<0.32525.7> acc_timestamp=2024-11-21T21:08:37.811499+00:00
when=2024-11-21T21:08:37.811848+00:00 level=debug what=mam_user_receive_packet pid=<0.32525.7> at=mod_mam:filter_packet/1:295 from_jid="theresa@<domain>/IM_XMPP_LAMBDA_CLIENT - <server>" to_jid=directory.<domain> packet="<iq xmlns='jabber:client' to='directory.<domain>' id='YVTH8-15' type='get'><query xmlns='jabber:iq:search'/></iq>" origin_pid=<0.32525.7> acc_timestamp=2024-11-21T21:08:37.811499+00:00
when=2024-11-21T21:08:37.811993+00:00 level=debug pid=<0.32525.7> at=ejabberd_auth:call_auth_modules_for_host_type/3:725 unstructured_log="Modules used for auth: [ejabberd_auth_headers,ejabberd_auth_pki]"
when=2024-11-21T21:08:37.812284+00:00 level=debug what=route pid=<0.32525.7> at=ejabberd_router:route/4:153 from_jid=directory.<domain> to_jid="theresa@<domain>/IM_XMPP_LAMBDA_CLIENT - <server>" packet="<iq id='YVTH8-15' type='result'><query xmlns='jabber:iq:search'><instructions>You need an x:data capable client to search</instructions><x xmlns='jabber:x:data' type='form'><title>Search users in directory.<domain></title><instructions>Fill in fields to search for any matching Jabber User</instructions><field type='text-single' label='Full Name' var='cn'/><field type='text-single' label='First Name' var='givenname'/><field type='text-single' label='Last Name' var='sn'/><field type='text-single' label='Email Address' var='mail'/></x></query></iq>" origin_pid=<0.32525.7> acc_timestamp=2024-11-21T21:08:37.811499+00:00