Am trying to authenticate my XMPP Smack connection when trying to connect to FCM CCS. I have two different ways of authentication that I am trying to use. Both ways throw exceptions.I feel like I just need a hint here to move in the right way. Thanks for any advice. Here's my code: Also note that I have a keystore set up in place to start TLS handshake with FCM CCS once I get this authentication error out of the way.
XMPPTCPConnectionConfiguration conf = XMPPTCPConnectionConfiguration.builder()
.setServiceName("rarigames.answerme").setHost("fcm- xmpp.googleapis.com").setUsernameAndPassword(s1, s2)
.setSocketFactory(SSLSocketFactory.getDefault())
.setSendPresence(false)
.setPort(5236)
.setCompressionEnabled(false).build();
other_connection = new XMPPTCPConnection(conf); //AbstractXMPPTCPConnection object
XMPPTCPConnection.setUseStreamManagementDefault(true);
other_connection.addConnectionListener(new ConnectionListener(){
@Override
public void connected(XMPPConnection connection) {
//I call either method1 or method2 here to authenticate connection
method1(); //gives the exception:
java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.jivesoftware.smack.sasl.SASLMechanism.getName()' on a null object reference
method2(); //gives the exception: CallbackHandler not (yet) supported??
}
}
new Thread(new Runnable(){
@Override
public void run() {
try {
// Connect and authenticate with to XMPP server (GCM CCS in this case).
other_connection.connect();
} catch (SmackException | IOException | XMPPException e) {
Log.d("ricky", "Unable to connect or login to FCM CCS. " + e);
}
}).start();
Here are the two methods showing two different ways of authentication:
private void method1{
SASLMechanism p = new SASLMechanism() {
@Override
protected void authenticateInternal(CallbackHandler cbh) throws SmackException {
}
@Override
protected byte[] getAuthenticationText() throws SmackException {
Log.d("batman", "hiya superman");
byte[] authcid = toBytes('\u0000' + this.authenticationId); //this.authenticationId
byte[] passw = toBytes('\u0000' + this.password);//this.password
return ByteUtils.concact(authcid, passw);
}
@Override
public String getName() {
return "PLAIN";
}
@Override
public int getPriority() {
return 410;
}
@Override
public void checkIfSuccessfulOrThrow() throws SmackException {
}
@Override
protected SASLMechanism newInstance() {
return this;
}
};
SASLAuthentication.registerSASLMechanism(p);
p.instanceForAuthentication(other_connection);
try {
p.authenticate("fcm-xmpp.googleapis.com", "rarigames.answerme", new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for(int i=0;i< callbacks.length;i++){
Log.d("flacka", "hehe: "+callbacks[i].toString());
}
}
});
} catch (SmackException e) {
Log.d("yaas","something "+e);
e.printStackTrace();
}
}
private void method2(){
SASLPlainMechanism plaino = new SASLPlainMechanism();
SASLAuthentication.registerSASLMechanism(plaino);
plaino.instanceForAuthentication(other_connection);
try {
plaino.authenticate("fcm-xmpp.googleapis.com", "rarigames.answerme", new CallbackHandler() {
@Override
public void handle(Callback[] callbacks) throws IOException, UnsupportedCallbackException {
for(int i=0;i< callbacks.length;i++){
Log.d("flacka", "hehe: "+callbacks[i].toString());
}
}
});
} catch (SmackException e) {
Log.d("yaas","something "+e);
e.printStackTrace();
}
}
As you can see method1() call gives the exception: java.lang.NullPointerException: Attempt to invoke virtual method 'java.lang.String org.jivesoftware.smack.sasl.SASLMechanism.getName()' on a null object reference
and a call to method2() gives the error CallbackHandler not (yet) supported??
Could anyone here provide any clues, ideas or answers as to what could be going on here? I see the mehod getName() is calling a null object reference, but which null object are the logs referring to?