title: Can't use the SASLXFacebookPlatformMechanism class in making android xmpp facebook chat client
body: <p>I m trying to make a simple version facebook messenger.The code that i used has worked well for gtalk and requires facebook authentication to be used for chatting with facebook friends.For that, i have used SASLXFacebookPlatfromMechanism class where i will store the api token and api key along with the apisecret of my app. The problem is SASLXFacebookPlatfromMechanism.java class is full of errors which i cannot resolve at all.Here are my classes-</p>
  
  <pre><code>**MainActivity.java**
  
  public class MainActivity extends ActionBarActivity {
  
  private ArrayList&lt;String&gt; messages = new ArrayList();
  private Handler mHandler = new Handler();
  private SettingsDialog mDialog;
  private EditText mRecipient;
  private EditText mSendText;
  private ListView mList;
  private XMPPConnection connection;
  
  /**
   * Called with the activity is first created.
   */
  @Override
  public void onCreate(Bundle icicle) {
      super.onCreate(icicle);
      Log.i("XMPPClient", "onCreate called");
      setContentView(R.layout.activity_main);
  
      mRecipient = (EditText) this.findViewById(R.id.recipient);
      Log.i("XMPPClient", "mRecipient = " + mRecipient);
      mSendText = (EditText) this.findViewById(R.id.sendText);
      Log.i("XMPPClient", "mSendText = " + mSendText);
      mList = (ListView) this.findViewById(R.id.listMessages);
      Log.i("XMPPClient", "mList = " + mList);
      setListAdapter();
  
      // Dialog for getting the xmpp settings
      mDialog = new SettingsDialog(this);
  
      // Set a listener to show the settings dialog
      Button setup = (Button) this.findViewById(R.id.setup);
      setup.setOnClickListener(new View.OnClickListener() {
          public void onClick(View view) {
              mHandler.post(new Runnable() {
                  public void run() {
                      mDialog.show();
                  }
              });
          }
      });
  
      // Set a listener to send a chat text message
      Button send = (Button) this.findViewById(R.id.send);
      send.setOnClickListener(new View.OnClickListener() {
          public void onClick(View view) {
             try
             {
                 String to = mRecipient.getText().toString();
                 String text = mSendText.getText().toString();
  
                 Log.i("XMPPClient", "Sending text [" + text + "] to [" + to + "]");
                 Message msg = new Message(to, Message.Type.chat);
                 msg.setBody(text);
                 connection.sendPacket(msg);
                 messages.add(connection.getUser() + ":");
                 messages.add(text);
                 setListAdapter();
  
             }catch(Exception e)
             {
                 Toast.makeText(MainActivity.this, "Error="+e.getMessage(), Toast.LENGTH_LONG).show();
             }
          }
      });
  }
  
  
  
  
  
  /**
   * Called by Settings dialog when a connection is establised with the XMPP server
   *
   * @param connection
   */
  public void setConnection (XMPPConnection connection) {
      this.connection = connection;
      if (connection != null) {
          // Add a packet listener to get messages sent to us
          PacketFilter filter = new MessageTypeFilter(Message.Type.chat);
          connection.addPacketListener(new PacketListener() {
              public void processPacket(Packet packet) {
                  Message message = (Message) packet;
                  if (message.getBody() != null) {
                      String fromName = StringUtils.parseBareAddress(message.getFrom());
                      Log.i("XMPPClient", "Got text [" + message.getBody() + "] from [" + fromName + "]");
                      messages.add(fromName + ":");
                      messages.add(message.getBody());
                      // Add the incoming message to the list view
                      mHandler.post(new Runnable() {
                          public void run() {
                              setListAdapter();
                          }
                      });
                  }
              }
          }, filter);
      }
  }
  
  private void setListAdapter
          () {
      ArrayAdapter&lt;String&gt; adapter = new ArrayAdapter&lt;String&gt;(this,
              R.layout.multi_line_list_item,
              messages);
      mList.setAdapter(adapter);
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>SettingsDialog.java</strong></p>
  
  <pre><code>public class SettingsDialog  extends Dialog implements android.view.View.OnClickListener {
  private MainActivity xmppClient;
  
  public SettingsDialog(MainActivity xmppClient) {
      super(xmppClient);
      this.xmppClient = xmppClient;
  }
  
  protected void onStart() {
      super.onStart();
      setContentView(R.layout.settings);
      getWindow().setFlags(4, 4);
      setTitle("XMPP Settings");
      Button ok = (Button) findViewById(R.id.ok);
      ok.setOnClickListener(this);
  }
  
  public void onClick(View v) {
  
  
      final String host = "chat.facebook.com";
      final String port = ""+5222;
      final String service = "chat.facebook.com";
      final String username = "*****";
      final String password = "****";
  
      new Thread() {
          public void run() {
              // Create a connection
              ConnectionConfiguration connConfig =new ConnectionConfiguration(host, Integer.parseInt(port), service);
              connConfig.setSASLAuthenticationEnabled(true);
  
              XMPPConnection connection = new XMPPConnection(connConfig);
  
  
              try {
                  connection.connect();
                  Log.i("XMPPClient", "[SettingsDialog] Connected to " + connection.getHost());
              } catch (Exception ex) {
                  Log.e("XMPPClient", "[SettingsDialog] Failed to connect to " + connection.getHost());
                  Log.e("XMPPClient", ex.toString());
                  xmppClient.setConnection(null);
              }
  
              try {
                  connection.login(username, password);
                  Log.i("XMPPClient", "Logged in as " + connection.getUser());
  
                  // Set the status to available
                  Presence presence = new Presence(Presence.Type.available);
                  connection.sendPacket(presence);
                  xmppClient.setConnection(connection);
              } catch (XMPPException ex) {
                  Log.e("XMPPClient", "[SettingsDialog] Failed to log in as " + username);
                  Log.e("XMPPClient", ex.toString());
                      xmppClient.setConnection(null);
              }
  
          }
      }.start();
  
  
      dismiss();
  }
  
  private String getText(int id) {
      EditText widget = (EditText) this.findViewById(id);
      return widget.getText().toString();
  }
  </code></pre>
  
  <p>}</p>
  
  <p><strong>SASLXFacebookPlatformMechanism.java</strong></p>
  
  <pre><code>public class SASLXFacebookPlatformMechanism extends SASLMechanism
  </code></pre>
  
  <p>{</p>
  
  <pre><code>private static final String NAME              = "X-FACEBOOK-PLATFORM";
  
  private String              apiKey            = "";
  private String              applicationSecret = "";
  private String              sessionKey        = "";
  
  /**
   * Constructor.
   */
  public SASLXFacebookPlatformMechanism(SASLAuthentication saslAuthentication)
  {
      super(saslAuthentication);
  }
  
  @Override
  protected void authenticate() throws IOException, XMPPException
  {
  
      getSASLAuthentication().send(new AuthMechanism(NAME, ""));
  }
  
  @Override
  public void authenticate(String apiKeyAndSessionKey, String host,
          String applicationSecret) throws IOException, XMPPException
  {
      if (apiKeyAndSessionKey == null || applicationSecret == null)
      {
          throw new IllegalArgumentException("Invalid parameters");
      }
  
      String[] keyArray = apiKeyAndSessionKey.split("\\|", 2);
      if (keyArray.length &lt; 2)
      {
          throw new IllegalArgumentException(
                  "API key or session key is not present");
      }
  
      this.apiKey = keyArray[0];
      this.applicationSecret = applicationSecret;
      this.sessionKey = keyArray[1];
  
      this.authenticationId = sessionKey;
      this.password = applicationSecret;
      this.hostname = host;
  
      String[] mechanisms = { "DIGEST-MD5" };
      Map&lt;String, String&gt; props = new HashMap&lt;String, String&gt;();
      this.sc =
              Sasl.createSaslClient(mechanisms, null, "xmpp", host, props,
                      this);
      authenticate();
  }
  
  @Override
  public void authenticate(String username, String host, CallbackHandler cbh)
          throws IOException, XMPPException
  {
      String[] mechanisms = { "DIGEST-MD5" };
      Map&lt;String, String&gt; props = new HashMap&lt;String, String&gt;();
      this.sc =
              Sasl.createSaslClient(mechanisms, null, "xmpp", host, props,
                      cbh);
      authenticate();
  }
  
  @Override
  protected String getName()
  {
      return NAME;
  }
  
  @Override
  public void challengeReceived(String challenge) throws IOException
  {
      byte[] response = null;
  
      if (challenge != null)
      {
          String decodedChallenge = new String(Base64.decode(challenge));
          Map&lt;String, String&gt; parameters = getQueryMap(decodedChallenge);
  
          String version = "1.0";
          String nonce = parameters.get("nonce");
          String method = parameters.get("method");
  
          long callId = new GregorianCalendar().getTimeInMillis();
  
          String sig =
                  "api_key=" + apiKey + "call_id=" + callId + "method="
                          + method + "nonce=" + nonce + "session_key="
                          + sessionKey + "v=" + version + applicationSecret;
  
          try
          {
              sig = md5(sig);
          } catch (NoSuchAlgorithmException e)
          {
              throw new IllegalStateException(e);
          }
  
          String composedResponse =
                  "api_key=" + URLEncoder.encode(apiKey, "utf-8")
                          + "&amp;call_id=" + callId + "&amp;method="
                          + URLEncoder.encode(method, "utf-8") + "&amp;nonce="
                          + URLEncoder.encode(nonce, "utf-8")
                          + "&amp;session_key="
                          + URLEncoder.encode(sessionKey, "utf-8") + "&amp;v="
                          + URLEncoder.encode(version, "utf-8") + "&amp;sig="
                          + URLEncoder.encode(sig, "utf-8");
  
          response = composedResponse.getBytes("utf-8");
      }
  
      String authenticationText = "";
  
      if (response != null)
      {
          authenticationText =
                  Base64.encodeBytes(response, Base64.DONT_BREAK_LINES);
      }
  
      // Send the authentication to the server
      getSASLAuthentication().send(new Response(authenticationText));
  }
  
  private Map&lt;String, String&gt; getQueryMap(String query)
  {
      Map&lt;String, String&gt; map = new HashMap&lt;String, String&gt;();
      String[] params = query.split("\\&amp;");
  
      for (String param : params)
      {
          String[] fields = param.split("=", 2);
          map.put(fields[0], (fields.length &gt; 1 ? fields[1] : null));
      }
  
      return map;
  }
  
  private String md5(String text) throws NoSuchAlgorithmException,
          UnsupportedEncodingException
  {
      MessageDigest md = MessageDigest.getInstance("MD5");
      md.update(text.getBytes("utf-8"), 0, text.length());
      return convertToHex(md.digest());
  }
  
  private String convertToHex(byte[] data)
  {
      StringBuilder buf = new StringBuilder();
      int len = data.length;
  
      for (int i = 0; i &lt; len; i++)
      {
          int halfByte = (data[i] &gt;&gt;&gt; 4) &amp; 0xF;
          int twoHalfs = 0;
  
          do
          {
              if (0 &lt;= halfByte &amp;&amp; halfByte &lt;= 9)
              {
                  buf.append((char) ('0' + halfByte));
              }
              else
              {
                  buf.append((char) ('a' + halfByte - 10));
              }
              halfByte = data[i] &amp; 0xF;
          } while (twoHalfs++ &lt; 1);
      }
  
      return buf.toString();
  }
  
  @Override
  protected String getAuthenticationText(String arg0, String arg1, String arg2) {
      // TODO Auto-generated method stub
      return null;
  }
  
  @Override
  protected String getChallengeResponse(byte[] arg0) {
      // TODO Auto-generated method stub
      return null;
  }
  </code></pre>
  
  <p>}</p>
  
  <p>The code shows error stating
   <strong>"The method send(String) in the type SASLAuthentication is not applicable for         arguments(Response).The constructor Response(String) is undefined"</strong> 
      in the line--><strong>"getSASLAuthentication().send(new Response(authenticationText));"</strong></p>
  
  <p>I am also confused on how to use this SASLXFacebookPlatformMechanism.java class in my MainActivity.class.I have been trying to get a sense of how it works but failing.A complete guideline on how to develop a xmpp facebook chat client using asmack library would be appreciated since the internet lacks enough documentation on it.Thanks.
  [I have the apikeys and apitokens,so the empty string will not remain empty]</p>