1 package fr.paris.lutece.plugins.bandeaugra.service; 2 3 import fr.paris.lutece.portal.service.spring.SpringContextService; 4 import fr.paris.lutece.portal.service.util.AppLogService; 5 import fr.paris.lutece.portal.service.util.AppPropertiesService; 6 import fr.paris.lutece.util.httpaccess.HttpAccess; 7 import fr.paris.lutece.util.httpaccess.HttpAccessException; 8 import fr.paris.lutece.util.signrequest.HeaderHashAuthenticator; 9 10 public class RemoteSiteBandeauClientService 11 { 12 private static RemoteSiteBandeauClientService _singleton; 13 private static final String PROPERTY_BANDEAU_MY_APPS_URL = "beadeaugra.myappsWsUrl"; 14 private static final String PROPERTY_BANDEAU_MY_FAVORITES = "beadeaugra.myfavoritesWsUrl"; 15 16 private static final String PROPERTY_BANDEAU_NOTIFICATIONS_URL = "beadeaugra.notificationsWsUrl"; 17 private static final String BEAN_AUTHENTICATOR = "bandeaugra.requestAuthenticator"; 18 private String _strNotificationsUrl; 19 private String _strMyappsUrl; 20 private String _strMyFavoritesUrl; 21 private HeaderHashAuthenticator _authenticator = null; 22 23 public static RemoteSiteBandeauClientService getInstance( ) 24 { 25 if( _singleton == null ) 26 { 27 28 _singleton=new RemoteSiteBandeauClientService(); 29 _singleton. _strNotificationsUrl=AppPropertiesService.getProperty( PROPERTY_BANDEAU_NOTIFICATIONS_URL ); 30 _singleton. _strMyappsUrl=AppPropertiesService.getProperty( PROPERTY_BANDEAU_MY_APPS_URL ); 31 _singleton. _strMyFavoritesUrl=AppPropertiesService.getProperty( PROPERTY_BANDEAU_MY_FAVORITES ); 32 _singleton._authenticator= SpringContextService.getBean( BEAN_AUTHENTICATOR ); 33 } 34 return _singleton; 35 } 36 37 public String getMyApps( String strGuid ) 38 { 39 return callBannerWS( _strMyappsUrl,strGuid ); 40 } 41 42 public String getNotifications( String strGuid ) 43 { 44 return callBannerWS( _strNotificationsUrl, strGuid ); 45 } 46 47 public String getMyFavorites(String strGuid) 48 { 49 return callBannerWS( _strMyFavoritesUrl,strGuid ); 50 } 51 52 53 private String callBannerWS( String strWsUrl, String strGuid ) 54 { 55 String strResponse = null; 56 try 57 { 58 HttpAccess httpAccess = new HttpAccess( ); 59 strResponse = httpAccess.doGet( strWsUrl+strGuid, _authenticator, null ); 60 61 } 62 catch ( HttpAccessException e ) 63 { 64 String strError = "Error connecting to '" + strWsUrl+strGuid + "' : "; 65 AppLogService.error( strError + e.getMessage( ), e ); 66 67 } 68 69 return strResponse; 70 71 72 } 73 74 75 76 77 }