{"id":24,"date":"2016-05-06T08:44:36","date_gmt":"2016-05-06T08:44:36","guid":{"rendered":"http:\/\/symbioticindia.in\/docu\/?p=24"},"modified":"2016-05-06T08:46:20","modified_gmt":"2016-05-06T08:46:20","slug":"sugarcrm-and-asterisk-integration-in-java-ii","status":"publish","type":"post","link":"http:\/\/symbioticindia.in\/docu\/2016\/05\/06\/sugarcrm-and-asterisk-integration-in-java-ii\/","title":{"rendered":"SugarCRM and Asterisk integration in Java ( II )"},"content":{"rendered":"<table class=\"contentpaneopen\">\n<tbody>\n<tr>\n<td colspan=\"2\" valign=\"top\">\n<div id=\"itmh\">\n<h3 id=\"qu.k\"><span style=\"font-size: small;\">Opening a customer SugarCRM page in the browser on incoming calls<br \/>\n<\/span><\/h3>\n<\/div>\n<table>\n<tbody>\n<tr>\n<td><object id=\"Player_4e8e304a-2c98-4df8-a168-be6690adc66a\" width=\"250px\" height=\"250px\" classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http:\/\/fpdownload.macromedia.com\/get\/flashplayer\/current\/swflash.cab\"><\/object><\/td>\n<td><center><\/p>\n<h4 id=\"qu.k\">Introduction<\/h4>\n<p><\/center><span style=\"font-size: small;\">Here comes the really interesting part, as this is what most readers have been asking for lately. The feature lots of people seem to be interested in is the possibility of , on an inbound asterisk call,\u00a0 opening\/redirecting the browser to the specific account\/contact SugarCRM page. Before we proceed you should first have a look at two of our previous articles:<\/p>\n<p><\/span><\/p>\n<ul>\n<li><span id=\"fbqv1\" style=\"font-size: medium;\"><a title=\"SugarCRM and Asterisk integration in Java - First steps\" href=\"http:\/\/www.beanizer.org\/site\/index.php\/en\/Articles\/SugarCRM-and-Asterisk-integration-in-Java-First-steps.html\" target=\"_blank\">SugarCRM and Asterisk integration in Java &#8211; First steps<\/a><\/span><\/li>\n<li><span id=\"jy5-0\" style=\"font-size: medium;\"><a title=\"SugarCRM integration - website session and SOAP session\" href=\"http:\/\/www.beanizer.org\/site\/index.php\/en\/Articles\/SugarCRM-integration-website-session-and-SOAP-session.html\" target=\"_blank\">SugarCRM integration &#8211; website session and SOAP session<\/a><\/span><\/li>\n<\/ul>\n<p><span style=\"font-size: small;\">In particular, we&#8217;ll take the code developed in the first one and add some features, while the second one is useful to see how we&#8217;re going to cope with SugarCRM authentication.<br \/>\nAs usual acknowledgments are due to the authors of\u00a0 <a title=\"AsteriskJava\" href=\"http:\/\/asterisk-java.org\/\" target=\"_blank\">AsteriskJava<\/a> for the great job they are doing with their library.<br \/>\n<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span style=\"font-size: small;\"><br \/>\n<\/span><\/p>\n<h4 id=\"qu.k\">The code<\/h4>\n<p><span style=\"font-size: small;\">In the first article we&#8217;ve written two java classes: &#8220;PhoneNumberResolver&#8221;, which is our main class and the listener for asterisk events, and &#8220;AccountFinder&#8221; which is in charge of querying SugarCRM for the Account owning the caller phone number for our inbound call. At the end of the article we were able to get a caller id from an asterisk event in the method &#8220;onManagerEvent&#8221; of our &#8220;PhoneNumberResolver&#8221; class, pass the caller id to the &#8220;searchAccountByNumber&#8221; method of our class &#8220;AccountFinder&#8221;, obtaining back an hashtable with data eventually extracted from Sugarcrm and show them.<br \/>\nWhat we are going to do now, is to create a new method &#8220;browserToSugarCRM&#8221; in our &#8220;AccountFinder&#8221; class. Again we&#8217;ll pass it the caller id and it will again check if a corresponding Account exists in SugarCRM , and if so it will open our browser to the specific SugarCrm page. Here is our new method:<\/p>\n<p><\/span><\/p>\n<pre><span id=\"rujc4\" style=\"color: #f5deb3;\"><span id=\"rujc5\" style=\"color: #ffffcc;\">   1:<\/span>    <span id=\"rujc6\" style=\"color: #ffa500;\">public<\/span> <span id=\"rujc7\" style=\"color: #cc6600;\">void<\/span> <span id=\"rujc8\" style=\"color: #b2dfee;\">browserToSugarCRM<\/span><span id=\"rujc9\" style=\"color: #00ffff;\">(<\/span>String phoneNumber<span id=\"rujc10\" style=\"color: #00ffff;\">)<\/span><span id=\"rujc11\" style=\"color: #00ffff;\">{<\/span>\r\n<span id=\"rujc13\" style=\"color: #ffffcc;\">   2:<\/span>        <span id=\"rujc14\" style=\"color: #ffa500;\">try<\/span><span id=\"rujc15\" style=\"color: #00ffff;\">{<\/span>\r\n<span id=\"rujc17\" style=\"color: #ffffcc;\">   3:<\/span>            Set_entry_result loginRes<span id=\"rujc18\" style=\"color: #00ffff;\">=<\/span>port.<span id=\"rujc19\" style=\"color: #b2dfee;\">login<\/span><span id=\"rujc20\" style=\"color: #00ffff;\">(<\/span>userAuth, <span id=\"rujc21\" style=\"color: #00cd00;\">\"<\/span><span id=\"rujc22\" style=\"color: #00cd00;\">myAppName<\/span><span id=\"rujc23\" style=\"color: #00cd00;\">\"<\/span><span id=\"rujc24\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"rujc26\" style=\"color: #ffffcc;\">   4:<\/span>            String sessionID <span id=\"rujc27\" style=\"color: #00ffff;\">=<\/span> loginRes.<span id=\"rujc28\" style=\"color: #b2dfee;\">getId<\/span><span id=\"rujc29\" style=\"color: #00ffff;\">(<\/span><span id=\"rujc30\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"rujc32\" style=\"color: #00cd00;\">   5:<\/span>            port.<span id=\"rujc33\" style=\"color: #b2dfee;\">seamless_login<\/span><span id=\"rujc34\" style=\"color: #00ffff;\">(<\/span>sessionID<span id=\"rujc35\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"rujc37\" style=\"color: #ffffcc;\">   6:<\/span>            Get_entry_list_result entryList<span id=\"rujc38\" style=\"color: #00ffff;\">=<\/span>port.<span id=\"rujc39\" style=\"color: #b2dfee;\">get_entry_list<\/span><span id=\"rujc40\" style=\"color: #00ffff;\">(<\/span>sessionID,<span id=\"rujc41\" style=\"color: #00cd00;\">\"<\/span><span id=\"rujc42\" style=\"color: #00cd00;\">Accounts<\/span><span id=\"rujc43\" style=\"color: #00cd00;\">\"<\/span>,<span id=\"rujc44\" style=\"color: #00cd00;\">\"accounts.<\/span><span id=\"rujc45\" style=\"color: #00cd00;\">phone_office='<\/span><span id=\"rujc46\" style=\"color: #00cd00;\">\"<\/span> <span id=\"rujc47\" style=\"color: #00ffff;\">+<\/span> \r\n<span id=\"rujc49\" style=\"color: #ffffcc;\">   7:<\/span>                                        phoneNumber <span id=\"rujc50\" style=\"color: #00ffff;\">+<\/span> <span id=\"rujc51\" style=\"color: #00cd00;\">\"<\/span><span id=\"rujc52\" style=\"color: #00cd00;\">'<\/span><span id=\"rujc53\" style=\"color: #00cd00;\">\"<\/span>, <span id=\"rujc54\" style=\"color: #00cd00;\">\"<\/span><span id=\"rujc55\" style=\"color: #00cd00;\">\"<\/span>,<span id=\"rujc56\" style=\"color: #cdcd00;\">0<\/span>,<span id=\"rujc57\" style=\"color: #ffa500;\">new<\/span> String[]<span id=\"rujc58\" style=\"color: #00ffff;\">{<\/span><span id=\"rujc59\" style=\"color: #00cd00;\">\"<\/span><span id=\"rujc60\" style=\"color: #00cd00;\">id<\/span><span id=\"rujc61\" style=\"color: #00cd00;\">\"<\/span>,<span id=\"rujc62\" style=\"color: #00cd00;\">\"<\/span><span id=\"rujc63\" style=\"color: #00cd00;\">name<\/span><span id=\"rujc64\" style=\"color: #00cd00;\">\"<\/span>,<span id=\"rujc65\" style=\"color: #00cd00;\">\"<\/span><span id=\"rujc66\" style=\"color: #00cd00;\">phone_fax<\/span><span id=\"rujc67\" style=\"color: #00cd00;\">\"<\/span>,<span id=\"rujc68\" style=\"color: #00cd00;\">\"<\/span><span id=\"rujc69\" style=\"color: #00cd00;\">website<\/span><span id=\"rujc70\" style=\"color: #00cd00;\">\"<\/span><span id=\"rujc71\" style=\"color: #00ffff;\">}<\/span>, \r\n<span id=\"rujc73\" style=\"color: #ffffcc;\">   8:<\/span>                                               <span id=\"rujc74\" style=\"color: #cdcd00;\">1<\/span>, <span id=\"rujc75\" style=\"color: #cdcd00;\">0<\/span><span id=\"rujc76\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"rujc78\" style=\"color: #ffffcc;\">   9:<\/span>            <span id=\"rujc79\" style=\"color: #ffa500;\">if<\/span><span id=\"rujc80\" style=\"color: #00ffff;\">(<\/span>entryList.<span id=\"rujc81\" style=\"color: #b2dfee;\">getEntry_list<\/span><span id=\"rujc82\" style=\"color: #00ffff;\">(<\/span><span id=\"rujc83\" style=\"color: #00ffff;\">)<\/span>.length<span id=\"rujc84\" style=\"color: #00ffff;\">&gt;<\/span><span id=\"rujc85\" style=\"color: #cdcd00;\">0<\/span><span id=\"rujc86\" style=\"color: #00ffff;\">)<\/span><span id=\"rujc87\" style=\"color: #00ffff;\">{<\/span>\r\n<span id=\"rujc89\" style=\"color: #00cd00;\">  10:<\/span>                Entry_value entry <span id=\"rujc90\" style=\"color: #00ffff;\">=<\/span> <span id=\"rujc91\" style=\"color: #00ffff;\">(<\/span>entryList.<span id=\"rujc92\" style=\"color: #b2dfee;\">getEntry_list<\/span><span id=\"rujc93\" style=\"color: #00ffff;\">(<\/span><span id=\"rujc94\" style=\"color: #00ffff;\">)<\/span><span id=\"rujc95\" style=\"color: #00ffff;\">)<\/span>[<span id=\"rujc96\" style=\"color: #cdcd00;\">0<\/span>];\r\n<span id=\"rujc98\" style=\"color: #ffffcc;\">  11:<\/span>                Name_value[] nvl<span id=\"rujc99\" style=\"color: #00ffff;\">=<\/span>entry.<span id=\"rujc100\" style=\"color: #b2dfee;\">getName_value_list<\/span><span id=\"rujc101\" style=\"color: #00ffff;\">(<\/span><span id=\"rujc102\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"rujc104\" style=\"color: #ffffcc;\">  12:<\/span>                String value <span id=\"rujc105\" style=\"color: #00ffff;\">=<\/span> nvl[<span id=\"rujc106\" style=\"color: #cdcd00;\">0<\/span>].<span id=\"rujc107\" style=\"color: #b2dfee;\">getValue<\/span><span id=\"rujc108\" style=\"color: #00ffff;\">(<\/span><span id=\"rujc109\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"rujc111\" style=\"color: #ffffcc;\">  13:<\/span>                String[] commandLine<span id=\"rujc112\" style=\"color: #00ffff;\">=<\/span> <span id=\"rujc113\" style=\"color: #00ffff;\">{<\/span><span id=\"rujc114\" style=\"color: #00cd00;\">\"<\/span><span id=\"rujc115\" style=\"color: #00cd00;\">\/usr\/bin\/firefox<\/span><span id=\"rujc116\" style=\"color: #00cd00;\">\"<\/span>,<span id=\"rujc117\" style=\"color: #00cd00;\">\"<\/span><span id=\"rujc118\" style=\"color: #00cd00;\">http:\/\/<\/span><\/span><span id=\"bqwm0\"><span id=\"bqwm1\"><span id=\"bqwm2\"><span id=\"p-4a\"><span id=\"otb5\" style=\"color: #f5deb3;\"><span id=\"t78e\" style=\"color: #00cd00;\">your_sugar_server_url<\/span><\/span><\/span><\/span><\/span><\/span><span id=\"rujc4\" style=\"color: #f5deb3;\"><span id=\"rujc118\" style=\"color: #00cd00;\">\/index.php?action=DetailView<\/span>\r\n\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0\u00a0                                                    <\/span><span id=\"rujc4\" style=\"color: #f5deb3;\"><span id=\"rujc118\" style=\"color: #00cd00;\">&amp;module=Accounts&amp;record=<\/span><span id=\"rujc119\" style=\"color: #00cd00;\">\"<\/span><span id=\"rujc120\" style=\"color: #00ffff;\">+<\/span><\/span><span id=\"rujc4\" style=\"color: #f5deb3;\">value+ \"&amp;MSID=\"+ sessionID<span id=\"rujc121\" style=\"color: #00ffff;\">}<\/span>;\r\n<span id=\"rujc123\" style=\"color: #ffffcc;\">  14:<\/span>                Process process <span id=\"rujc124\" style=\"color: #00ffff;\">=<\/span> Runtime.<span id=\"rujc125\" style=\"color: #b2dfee;\">getRuntime<\/span><span id=\"rujc126\" style=\"color: #00ffff;\">(<\/span><span id=\"rujc127\" style=\"color: #00ffff;\">)<\/span>.<span id=\"rujc128\" style=\"color: #b2dfee;\">exec<\/span><span id=\"rujc129\" style=\"color: #00ffff;\">(<\/span>commandLine<span id=\"rujc130\" style=\"color: #00ffff;\">)<\/span>;          \r\n<span id=\"rujc132\" style=\"color: #00cd00;\">  15:<\/span>            <span id=\"rujc133\" style=\"color: #00ffff;\">}<\/span>\r\n<span id=\"rujc135\" style=\"color: #ffffcc;\">  16:<\/span>        <span id=\"rujc136\" style=\"color: #00ffff;\">}<\/span> <span id=\"rujc137\" style=\"color: #ffa500;\">catch<\/span><span id=\"rujc138\" style=\"color: #00ffff;\">(<\/span>Exception ex<span id=\"rujc139\" style=\"color: #00ffff;\">)<\/span><span id=\"rujc140\" style=\"color: #00ffff;\">{<\/span>\r\n<span id=\"rujc142\" style=\"color: #ffffcc;\">  17:<\/span>            ex.<span id=\"rujc143\" style=\"color: #b2dfee;\">printStackTrace<\/span><span id=\"rujc144\" style=\"color: #00ffff;\">(<\/span><span id=\"rujc145\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"rujc147\" style=\"color: #ffffcc;\">  18:<\/span>        <span id=\"rujc148\" style=\"color: #00ffff;\">}<\/span>\r\n<span id=\"rujc150\" style=\"color: #ffffcc;\">  19:<\/span>    \r\n<span id=\"rujc152\" style=\"color: #00cd00;\">  20:<\/span>    <span id=\"rujc153\" style=\"color: #00ffff;\">}<\/span>\r\n<span id=\"rujc155\" style=\"color: #ffffcc;\">  21:<\/span> <\/span><\/pre>\n<p><span style=\"font-size: small;\"><span style=\"font-size: medium;\"><br \/>\n<\/span><\/span>The method used here is explained in the second <a title=\"article\" href=\"http:\/\/www.beanizer.org\/site\/index.php\/en\/Articles\/SugarCRM-integration-website-session-and-SOAP-session.html\" target=\"_blank\">article<\/a> cited above. We do a SOAP login to SugarCRM and get a session id (lines 3 and 4). then we use the session id to do a &#8220;seamless login&#8221;(line 5) which will allow us to be also logged in to the web interface.<\/p>\n<p><span style=\"font-size: small;\">On line 6 we query SugarCRM to see if an Account with the given telephone number exists and, if so(line 9),\u00a0 we get the id of the extracted account (line 12). A little explanation for line 12;\u00a0 the account id is at index &#8220;0&#8221; of the array &#8220;nvl&#8221; because on line 7, when querying SugarCRM, we&#8217;ve put &#8220;id&#8221; as the first (that is index 0) element of the String array of the required fields.<br \/>\nNow we have all we need to compose the URL to enter SugarCRM bypassing the login form and be redirected to the details page of the corresponding account record. On line 13 we create a 2 elements String array containing the path to our browser and the URL itself with variable &#8220;value&#8221; representing the account id on the database and the sessionID passed as parameter &#8220;MSID&#8221;. This is what allows us to bypass the login page.<\/p>\n<p><strong>WARNING<\/strong>: the &#8220;MSID method&#8221; of remotely logging in hasn&#8217;t been ported to version &#8220;5.0&#8221; of SugarCRM, while it seems it is present again on version &#8220;5.1&#8221; . For testing I&#8217;m using SugarCRM 4.2.1b, and the mechanism works properly.<\/p>\n<p>On line 13 we launch the browser. This string is strictly related to the OS and browser you&#8217;re using.In my case, if Firefox is already open, a new tab gets opened and I&#8217;m redirected to the\u00a0 account record sugarcrm page.<br \/>\nTo complete the modifications, we need to change the &#8220;onManageEvent&#8221; method of our &#8220;PhoneNumberResolver&#8221; class. Here is the code:<br \/>\n<\/span><\/p>\n<div id=\"d2in\">\n<pre><span id=\"lb4h8\"><span id=\"lb4h9\"><span id=\"mp4_\"><span id=\"p69h\" style=\"color: #f5deb3;\"><span id=\"svlw\" style=\"color: #ffffcc;\">  1 :<\/span>    <span id=\"vzkx\" style=\"color: #ffa500;\">public<\/span> <span id=\"pg0z\" style=\"color: #cc6600;\">void<\/span> <span id=\"zvcl\" style=\"color: #b2dfee;\">onManagerEvent<\/span><span id=\"y4rh\" style=\"color: #00ffff;\">(<\/span>ManagerEvent event<span id=\"w72b\" style=\"color: #00ffff;\">)<\/span> <span id=\"sv99\" style=\"color: #00ffff;\">{<\/span>\r\n<span id=\"t3l_\" style=\"color: #ffffcc;\">  2 :<\/span>        String event_name <span id=\"ghs8\" style=\"color: #00ffff;\">=<\/span> event.<span id=\"c-b4\" style=\"color: #b2dfee;\">getClass<\/span><span id=\"jw_q\" style=\"color: #00ffff;\">(<\/span><span id=\"dje5\" style=\"color: #00ffff;\">)<\/span>.<span id=\"k17l\" style=\"color: #b2dfee;\">getSimpleName<\/span><span id=\"g1x8\" style=\"color: #00ffff;\">(<\/span><span id=\"e97r\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"o:do\" style=\"color: #00cd00;\">  3 :<\/span>        <span id=\"fs4l\" style=\"color: #ffa500;\">if<\/span><span id=\"w8lz\" style=\"color: #00ffff;\">(<\/span>event_name.<span id=\"t8w8\" style=\"color: #b2dfee;\">equals<\/span><span id=\"i4_9\" style=\"color: #00ffff;\">(<\/span><span id=\"o-ii\" style=\"color: #00cd00;\">\"<\/span><span id=\"n1_s\" style=\"color: #00cd00;\">DialEvent<\/span><span id=\"rk3q\" style=\"color: #00cd00;\">\"<\/span><span id=\"w4g0\" style=\"color: #00ffff;\">)<\/span><span id=\"exyh\" style=\"color: #00ffff;\">)<\/span><span id=\"j6o4\" style=\"color: #00ffff;\">{<\/span>\r\n<span id=\"u4sc\" style=\"color: #ffffcc;\">  4 :<\/span>            DialEvent e<span id=\"o-5b\" style=\"color: #00ffff;\">=<\/span><span id=\"ukg:\" style=\"color: #00ffff;\">(<\/span>DialEvent<span id=\"qs06\" style=\"color: #00ffff;\">)<\/span>event;\r\n<span id=\"xu6-\" style=\"color: #ffffcc;\">  5 :<\/span>            af.<span id=\"e6700\" style=\"color: #b2dfee;\">browserToSugarCRM<\/span><span id=\"vgxs\" style=\"color: #00ffff;\">(<\/span>e.<span id=\"gcgv\" style=\"color: #b2dfee;\">getCallerId<\/span><span id=\"ft-8\" style=\"color: #00ffff;\">(<\/span><span id=\"n6ro\" style=\"color: #00ffff;\">)<\/span><span id=\"h8:5\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"xuhv\" style=\"color: #00cd00;\">  6 :<\/span>        <span id=\"u-qe\" style=\"color: #00ffff;\">}<\/span>\r\n<span id=\"xjnw\" style=\"color: #ffffcc;\">  7 :<\/span>    <span id=\"to6d\" style=\"color: #00ffff;\">}<\/span>\r\n<span id=\"y0w4\" style=\"color: #ffffcc;\">\r\n<\/span><\/span><\/span><\/span><\/span><\/pre>\n<p>We&#8217;ve only changed the call to AccountFinder, this time calling our new &#8220;browserToSugarCRM&#8221; method. Done this we don&#8217;t need anymore the method &#8220;showData&#8221;, so here is the final version of &#8220;PhoneNumberResolver&#8221;:<\/p>\n<\/div>\n<p><span style=\"font-size: small;\"><br \/>\n<\/span><\/p>\n<pre><span id=\"mp4_\"><span id=\"p69h\" style=\"color: #f5deb3;\"><span id=\"a63y\" style=\"color: #ffffcc;\">   1:<\/span><span id=\"u23b\" style=\"color: #00cc99;\">import<\/span> java.io.IOException;\r\n<span id=\"xzvt\" style=\"color: #ffffcc;\">   2:<\/span><span id=\"nqpu\" style=\"color: #00cc99;\">import<\/span> java.util.Date;\r\n<span id=\"e38y\" style=\"color: #ffffcc;\">   3:<\/span><span id=\"ecnp\" style=\"color: #00cc99;\">import<\/span> java.util.Enumeration;\r\n<span id=\"poi2\" style=\"color: #ffffcc;\">   4:<\/span><span id=\"oe.2\" style=\"color: #00cc99;\">import<\/span> java.util.Hashtable;\r\n<span id=\"i-7b\" style=\"color: #00cd00;\">   5:<\/span><span id=\"sjnv\" style=\"color: #00cc99;\">import<\/span> javax.swing.JFrame;\r\n<span id=\"tem7\" style=\"color: #ffffcc;\">   6:<\/span><span id=\"bu9e\" style=\"color: #00cc99;\">import<\/span> javax.swing.JLabel;\r\n<span id=\"h3ev\" style=\"color: #ffffcc;\">   7:<\/span><span id=\"b4wh\" style=\"color: #00cc99;\">import<\/span> javax.swing.JOptionPane;\r\n<span id=\"bst8\" style=\"color: #ffffcc;\">   8:<\/span><span id=\"dd7i\" style=\"color: #00cc99;\">import<\/span> org.asteriskjava.manager.*;\r\n<span id=\"jc3g\" style=\"color: #ffffcc;\">   9:<\/span><span id=\"hdu6\" style=\"color: #00cc99;\">import<\/span> org.asteriskjava.manager.event.*;\r\n<span id=\"von4\" style=\"color: #00cd00;\">  10:<\/span>\r\n<span id=\"ob44\" style=\"color: #ffffcc;\">  11:<\/span><span id=\"oa4p\" style=\"color: #ffa500;\">public<\/span> <span id=\"wm2u\" style=\"color: #cc6600;\">class<\/span> PhoneNumberResolver <span id=\"hi9w\" style=\"color: #ffa500;\">implements<\/span> ManagerEventListener<span id=\"jjai\" style=\"color: #00ffff;\">{<\/span>\r\n<span id=\"zb76\" style=\"color: #ffffcc;\">  12:<\/span>    <span id=\"gb53\" style=\"color: #ffa500;\">private<\/span> ManagerConnection managerConnection;\r\n<span id=\"uj:3\" style=\"color: #ffffcc;\">  13:<\/span>    <span id=\"k.oc\" style=\"color: #ffa500;\">private<\/span> AccountFinder af;\r\n<span id=\"exsl\" style=\"color: #ffffcc;\">  14:<\/span>    \r\n<span id=\"pm4g\" style=\"color: #00cd00;\">  15:<\/span>    <span id=\"n1b-\" style=\"color: #ffa500;\">public<\/span> <span id=\"tbdu\" style=\"color: #b2dfee;\">PhoneNumberResolver<\/span><span id=\"mrp4\" style=\"color: #00ffff;\">(<\/span><span id=\"niw:\" style=\"color: #00ffff;\">)<\/span><span id=\"z18d\" style=\"color: #00ffff;\">{<\/span>\r\n<span id=\"oyq6\" style=\"color: #ffffcc;\">  16:<\/span>        ManagerConnectionFactory factory <span id=\"g6cb\" style=\"color: #00ffff;\">=<\/span> <span id=\"x7s6\" style=\"color: #ffa500;\">new<\/span> <span id=\"vmcs\" style=\"color: #b2dfee;\">ManagerConnectionFactory<\/span><span id=\"lifb\" style=\"color: #00ffff;\">(<\/span>\r\n<span id=\"ubu1\" style=\"color: #ffffcc;\">  17:<\/span>                                <span id=\"cphk\" style=\"color: #00cd00;\">\"<\/span><span id=\"rv9.\" style=\"color: #00cd00;\">asterisk_server_url<\/span><span id=\"f:d8\" style=\"color: #00cd00;\">\"<\/span>, <span id=\"r3e_\" style=\"color: #00cd00;\">\"<\/span><span id=\"wk6i\" style=\"color: #00cd00;\">user<\/span><span id=\"ff.6\" style=\"color: #00cd00;\">\"<\/span>, <span id=\"b8jk\" style=\"color: #00cd00;\">\"<\/span><span id=\"mo4b\" style=\"color: #00cd00;\">password<\/span><span id=\"uz0h\" style=\"color: #00cd00;\">\"<\/span><span id=\"az33\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"rxss\" style=\"color: #ffffcc;\">  18:<\/span>        <span id=\"cjll\" style=\"color: #ffff66;\">this<\/span>.managerConnection <span id=\"ipaf\" style=\"color: #00ffff;\">=<\/span> factory.<span id=\"zv4i\" style=\"color: #b2dfee;\">createManagerConnection<\/span><span id=\"sg-:\" style=\"color: #00ffff;\">(<\/span><span id=\"s4az\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"js5e\" style=\"color: #ffffcc;\">  19:<\/span>        af<span id=\"utju\" style=\"color: #00ffff;\">=<\/span><span id=\"d7tr\" style=\"color: #ffa500;\">new<\/span> <span id=\"jbkn\" style=\"color: #b2dfee;\">AccountFinder<\/span><span id=\"k3.4\" style=\"color: #00ffff;\">(<\/span><span id=\"l:2-\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"v3_9\" style=\"color: #00cd00;\">  20:<\/span>    <span id=\"ohr3\" style=\"color: #00ffff;\">}<\/span>\r\n<span id=\"ye62\" style=\"color: #ffffcc;\">  21:<\/span>    <span id=\"bgxz\" style=\"color: #ffa500;\">public<\/span> <span id=\"a7zi\" style=\"color: #cc6600;\">void<\/span> <span id=\"qngk\" style=\"color: #b2dfee;\">run<\/span><span id=\"ycih\" style=\"color: #00ffff;\">(<\/span><span id=\"m4:4\" style=\"color: #00ffff;\">)<\/span> <span id=\"newz\" style=\"color: #ffa500;\">throws<\/span> IOException, AuthenticationFailedException,TimeoutException,\r\n                                                        InterruptedException, IllegalStateException\r\n<span id=\"w17y\" style=\"color: #ffffcc;\">  22:<\/span>    <span id=\"aygn\" style=\"color: #00ffff;\">{<\/span>\r\n<span id=\"t4nr\" style=\"color: #ffffcc;\">  23:<\/span>        managerConnection.<span id=\"jegv\" style=\"color: #b2dfee;\">addEventListener<\/span><span id=\"m45k\" style=\"color: #00ffff;\">(<\/span><span id=\"b1.n\" style=\"color: #ffff66;\">this<\/span><span id=\"k8rf\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"feaz\" style=\"color: #ffffcc;\">  24:<\/span>        managerConnection.<span id=\"w.gb\" style=\"color: #b2dfee;\">login<\/span><span id=\"zxns\" style=\"color: #00ffff;\">(<\/span><span id=\"c2y2\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"d13b\" style=\"color: #00cd00;\">  25:<\/span>        <span id=\"ii4l\" style=\"color: #ffa500;\">while<\/span><span id=\"p2y9\" style=\"color: #00ffff;\">(<\/span><span id=\"lzub\" style=\"color: #ffff66;\">true<\/span><span id=\"ym-5\" style=\"color: #00ffff;\">)<\/span>\r\n<span id=\"wrj1\" style=\"color: #ffffcc;\">  26:<\/span>            Thread.<span id=\"n-pt\" style=\"color: #b2dfee;\">sleep<\/span><span id=\"tz0t\" style=\"color: #00ffff;\">(<\/span><span id=\"op4e\" style=\"color: #cdcd00;\">60000<\/span><span id=\"j0w8\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"n2:j\" style=\"color: #ffffcc;\">  27:<\/span>    <span id=\"u.do\" style=\"color: #00ffff;\">}<\/span>\r\n<span id=\"svlw\" style=\"color: #ffffcc;\">  28:<\/span>    <span id=\"vzkx\" style=\"color: #ffa500;\">public<\/span> <span id=\"pg0z\" style=\"color: #cc6600;\">void<\/span> <span id=\"zvcl\" style=\"color: #b2dfee;\">onManagerEvent<\/span><span id=\"y4rh\" style=\"color: #00ffff;\">(<\/span>ManagerEvent event<span id=\"w72b\" style=\"color: #00ffff;\">)<\/span> <span id=\"sv99\" style=\"color: #00ffff;\">{<\/span>\r\n<span id=\"t3l_\" style=\"color: #ffffcc;\">  29:<\/span>        String event_name <span id=\"ghs8\" style=\"color: #00ffff;\">=<\/span> event.<span id=\"c-b4\" style=\"color: #b2dfee;\">getClass<\/span><span id=\"jw_q\" style=\"color: #00ffff;\">(<\/span><span id=\"dje5\" style=\"color: #00ffff;\">)<\/span>.<span id=\"k17l\" style=\"color: #b2dfee;\">getSimpleName<\/span><span id=\"g1x8\" style=\"color: #00ffff;\">(<\/span><span id=\"e97r\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"o:do\" style=\"color: #00cd00;\">  30:<\/span>        <span id=\"fs4l\" style=\"color: #ffa500;\">if<\/span><span id=\"w8lz\" style=\"color: #00ffff;\">(<\/span>event_name.<span id=\"t8w8\" style=\"color: #b2dfee;\">equals<\/span><span id=\"i4_9\" style=\"color: #00ffff;\">(<\/span><span id=\"o-ii\" style=\"color: #00cd00;\">\"<\/span><span id=\"n1_s\" style=\"color: #00cd00;\">DialEvent<\/span><span id=\"rk3q\" style=\"color: #00cd00;\">\"<\/span><span id=\"w4g0\" style=\"color: #00ffff;\">)<\/span><span id=\"exyh\" style=\"color: #00ffff;\">)<\/span><span id=\"j6o4\" style=\"color: #00ffff;\">{<\/span>\r\n<span id=\"u4sc\" style=\"color: #ffffcc;\">  31:<\/span>            DialEvent e<span id=\"o-5b\" style=\"color: #00ffff;\">=<\/span><span id=\"ukg:\" style=\"color: #00ffff;\">(<\/span>DialEvent<span id=\"qs06\" style=\"color: #00ffff;\">)<\/span>event;\r\n<span id=\"xu6-\" style=\"color: #ffffcc;\">  32:<\/span>            <\/span><\/span><span id=\"mp4_\"><span id=\"p69h\" style=\"color: #f5deb3;\"><span id=\"i01h0\"><span id=\"i01h1\"><span id=\"i01h2\"><span id=\"i01h3\"><span id=\"lb4h8\"><span id=\"lb4h9\">af.<span id=\"e6700\" style=\"color: #b2dfee;\">browserToSugarCRM<\/span><span id=\"vgxs\" style=\"color: #00ffff;\">(<\/span>e.<span id=\"gcgv\" style=\"color: #b2dfee;\">getCallerId<\/span><span id=\"ft-8\" style=\"color: #00ffff;\">(<\/span><span id=\"n6ro\" style=\"color: #00ffff;\">)<\/span><span id=\"h8:5\" style=\"color: #00ffff;\">)<\/span>;<\/span><\/span><\/span><\/span><\/span><\/span>\r\n<span id=\"rvhf\" style=\"color: #ffffcc;\">  33:<\/span>            \r\n<span id=\"xuhv\" style=\"color: #00cd00;\">  34:<\/span>        <span id=\"u-qe\" style=\"color: #00ffff;\">}<\/span>\r\n<span id=\"xjnw\" style=\"color: #ffffcc;\">  35:<\/span>    <span id=\"to6d\" style=\"color: #00ffff;\">}<\/span>\r\n<span id=\"jh7g\" style=\"color: #ffffcc;\">  36:<\/span>    <span id=\"i2.d\" style=\"color: #ffa500;\">public<\/span> <span id=\"h5k6\" style=\"color: #ffa500;\">static<\/span> <span id=\"w1ok\" style=\"color: #cc6600;\">void<\/span> <span id=\"km_g\" style=\"color: #b2dfee;\">main<\/span><span id=\"j5r2\" style=\"color: #00ffff;\">(<\/span>String[] args<span id=\"nnt8\" style=\"color: #00ffff;\">)<\/span> <span id=\"v7yq\" style=\"color: #ffa500;\">throws<\/span> Exception\r\n<span id=\"x78s\" style=\"color: #ffffcc;\">  37:<\/span>    <span id=\"noxl\" style=\"color: #00ffff;\">{<\/span>\r\n<span id=\"jpwm\" style=\"color: #ffffcc;\">  38:<\/span>        PhoneNumberResolver phoneNumberResolver <span id=\"pcuv\" style=\"color: #00ffff;\">=<\/span> <span id=\"nyl:\" style=\"color: #ffa500;\">new<\/span> <span id=\"pqqr\" style=\"color: #b2dfee;\">PhoneNumberResolver<\/span><span id=\"q5fd\" style=\"color: #00ffff;\">(<\/span><span id=\"qu9j\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"plef\" style=\"color: #00cd00;\">  49:<\/span>        phoneNumberResolver.<span id=\"nbn0\" style=\"color: #b2dfee;\">run<\/span><span id=\"ox1g\" style=\"color: #00ffff;\">(<\/span><span id=\"y8s6\" style=\"color: #00ffff;\">)<\/span>;\r\n<span id=\"thhz\" style=\"color: #ffffcc;\">  40:<\/span>    <span id=\"y55z\" style=\"color: #00ffff;\">}<\/span>\r\n<span id=\"o-bf\" style=\"color: #ffffcc;\">  41:<\/span><span id=\"vgtf\" style=\"color: #00ffff;\">}<\/span><\/span><\/span><\/pre>\n<p><span style=\"font-size: small;\"><br \/>\n<\/span><\/p>\n<h4 id=\"f9cq\">Conclusions<\/h4>\n<p><span style=\"font-size: small;\">This article should answer a lot of email from readers interested in the exposed mechanism. I&#8217;ll be writing more articles on Asterisk\/SugarCRM\u00a0 and SugarCRM\/CMS integration soon.<br \/>\nHasta la proxima.<\/span><\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p><span class=\"article_seperator\">\u00a0<\/span><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Opening a customer SugarCRM page in the browser on incoming calls Introduction Here comes the really interesting part, as this is what most readers have been asking for lately. The feature lots of people seem to be interested in is the possibility of , on an inbound asterisk call,\u00a0 opening\/redirecting the browser to the specific ..<\/p>\n<div class=\"clear-fix\"><\/div>\n<p><a href=\"http:\/\/symbioticindia.in\/docu\/2016\/05\/06\/sugarcrm-and-asterisk-integration-in-java-ii\/\" title=\"read more...\">Read more<\/a><\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[3,2],"tags":[],"class_list":["post-24","post","type-post","status-publish","format-standard","hentry","category-asterisk","category-sugarcrm"],"_links":{"self":[{"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/posts\/24","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/comments?post=24"}],"version-history":[{"count":1,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/posts\/24\/revisions"}],"predecessor-version":[{"id":25,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/posts\/24\/revisions\/25"}],"wp:attachment":[{"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/media?parent=24"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/categories?post=24"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/symbioticindia.in\/docu\/wp-json\/wp\/v2\/tags?post=24"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}