contact.setInList(MsnList.BL, false);
}
public void copyFriend(Email email, String groupId)
{
MsnContactListImpl contactList = (MsnContactListImpl) session
.getMessenger().getContactList();
MsnContactImpl contact = (MsnContactImpl)contactList.getContactByEmail(email);
StringBuilder mess = new StringBuilder();
mess.append("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
mess.append("<soap:Envelope xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\"");
mess.append(" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"");
mess.append(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"");
mess.append(" xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">");
mess.append("<soap:Header>");
mess.append(" <ABApplicationHeader xmlns=\"http://www.msn.com/webservices/AddressBook\">");
mess.append(" <ApplicationId>996CDE1E-AA53-4477-B943-2BE802EA6166</ApplicationId>");
mess.append(" <IsMigration>false</IsMigration>");
mess.append(" <PartnerScenario>GroupSave</PartnerScenario>");
mess.append(" </ABApplicationHeader>");
mess.append(" <ABAuthHeader xmlns=\"http://www.msn.com/webservices/AddressBook\">");
mess.append(" <ManagedGroupRequest>false</ManagedGroupRequest>");
mess.append(" <TicketToken>" + sso.getContactTicket().replaceAll("&", "&") + "</TicketToken>");
mess.append(" </ABAuthHeader>");
mess.append("</soap:Header>");
mess.append("<soap:Body>");
mess.append(" <ABGroupContactAdd xmlns=\"http://www.msn.com/webservices/AddressBook\">");
mess.append(" <abId>00000000-0000-0000-0000-000000000000</abId>");
mess.append(" <contacts><Contact><contactId>" + contact.getId() + "</contactId></Contact></contacts>");
mess.append(" <groupFilter><groupIds>");
mess.append(" <guid>" + groupId + "</guid>");
mess.append(" </groupIds></groupFilter>");
mess.append(" </ABGroupContactAdd>");
mess.append("</soap:Body>");
mess.append("</soap:Envelope>");
String res = sendRequest(
mess.toString(), addressbook_url, addressbook_action_groupContactAdd, "POST");
DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
dbfactory.setIgnoringComments(true);
DocumentBuilder docBuilder;
Document doc;
try
{
docBuilder = dbfactory.newDocumentBuilder();
ByteArrayInputStream in = new ByteArrayInputStream(res.getBytes("UTF-8"));
doc = docBuilder.parse(in);
}
catch (ParserConfigurationException ex)
{
logger.error("", ex);
return;
}catch (SAXException ex)
{
logger.error("", ex);
return;
}catch (IOException ex)
{
logger.error("", ex);
return;
}
Element el =
XmlUtils.locateElement(
doc.getDocumentElement(),
"ABGroupContactAddResponse",
"xmlns",
"http://www.msn.com/webservices/AddressBook");
// todo if something missing throw failed event
if(el == null)
return;
el = XmlUtils.findChildByChain(el, new String[]{"ABGroupContactAddResult", "guid"});
if(el != null)
{
contact.addBelongGroup(groupId);
MsnGroup group = contactList.getGroup(groupId);
((AbstractMessenger) session.getMessenger())
.fireContactAddInGroupCompleted(contact, group);
}
}