1 17 package org.alfresco.webservice.util; 18 19 import java.io.InputStream ; 20 import java.util.Properties ; 21 22 import javax.xml.rpc.ServiceException ; 23 24 import org.alfresco.webservice.accesscontrol.AccessControlServiceLocator; 25 import org.alfresco.webservice.accesscontrol.AccessControlServiceSoapBindingStub; 26 import org.alfresco.webservice.action.ActionServiceLocator; 27 import org.alfresco.webservice.action.ActionServiceSoapBindingStub; 28 import org.alfresco.webservice.administration.AdministrationServiceLocator; 29 import org.alfresco.webservice.administration.AdministrationServiceSoapBindingStub; 30 import org.alfresco.webservice.authentication.AuthenticationServiceLocator; 31 import org.alfresco.webservice.authentication.AuthenticationServiceSoapBindingStub; 32 import org.alfresco.webservice.authoring.AuthoringServiceLocator; 33 import org.alfresco.webservice.authoring.AuthoringServiceSoapBindingStub; 34 import org.alfresco.webservice.classification.ClassificationServiceLocator; 35 import org.alfresco.webservice.classification.ClassificationServiceSoapBindingStub; 36 import org.alfresco.webservice.content.ContentServiceLocator; 37 import org.alfresco.webservice.content.ContentServiceSoapBindingStub; 38 import org.alfresco.webservice.repository.RepositoryServiceLocator; 39 import org.alfresco.webservice.repository.RepositoryServiceSoapBindingStub; 40 import org.apache.commons.logging.Log; 41 import org.apache.commons.logging.LogFactory; 42 43 import com.sun.org.apache.bcel.internal.util.ClassLoader; 44 45 50 public final class WebServiceFactory 51 { 52 53 private static Log logger = LogFactory.getLog(WebServiceFactory.class); 54 55 56 private static final String PROPERTY_FILE_NAME = "alfresco/webserviceclient.properties"; 57 private static final String REPO_LOCATION = "repository.location"; 58 59 60 private static final String DEFAULT_ENDPOINT_ADDRESS = "http://localhost:8080"; 61 62 63 private static final String AUTHENTICATION_SERVICE_ADDRESS = "/alfresco/api/AuthenticationService"; 64 private static final String REPOSITORY_SERVICE_ADDRESS = "/alfresco/api/RepositoryService"; 65 private static final String CONTENT_SERVICE_ADDRESS = "/alfresco/api/ContentService"; 66 private static final String AUTHORING_SERVICE_ADDRESS = "/alfresco/api/AuthoringService"; 67 private static final String CLASSIFICATION_SERVICE_ADDRESS = "/alfresco/api/ClassificationService"; 68 private static final String ACTION_SERVICE_ADDRESS = "/alfresco/api/ActionService"; 69 private static final String ACCESS_CONTROL_ADDRESS = "/alfresco/api/AccessControlService"; 70 private static final String ADMINISTRATION_ADDRESS = "/alfresco/api/AdministrationService"; 71 72 73 private static AuthenticationServiceSoapBindingStub authenticationService = null; 74 private static RepositoryServiceSoapBindingStub repositoryService = null; 75 private static ContentServiceSoapBindingStub contentService = null; 76 private static AuthoringServiceSoapBindingStub authoringService = null; 77 private static ClassificationServiceSoapBindingStub classificationService = null; 78 private static ActionServiceSoapBindingStub actionService = null; 79 private static AccessControlServiceSoapBindingStub accessControlService = null; 80 private static AdministrationServiceSoapBindingStub administrationService = null; 81 82 87 public static AuthenticationServiceSoapBindingStub getAuthenticationService() 88 { 89 if (authenticationService == null) 90 { 91 try 92 { 93 AuthenticationServiceLocator locator = new AuthenticationServiceLocator(); 95 locator.setAuthenticationServiceEndpointAddress(getEndpointAddress() + AUTHENTICATION_SERVICE_ADDRESS); 96 authenticationService = (AuthenticationServiceSoapBindingStub)locator.getAuthenticationService(); 97 } 98 catch (ServiceException jre) 99 { 100 if (logger.isDebugEnabled() == true) 101 { 102 if (jre.getLinkedCause() != null) 103 { 104 jre.getLinkedCause().printStackTrace(); 105 } 106 } 107 108 throw new WebServiceException("Error creating authentication service: " + jre.getMessage(), jre); 109 } 110 111 authenticationService.setTimeout(60000); 113 } 114 115 return authenticationService; 116 } 117 118 123 public static RepositoryServiceSoapBindingStub getRepositoryService() 124 { 125 if (repositoryService == null) 126 { 127 try 128 { 129 RepositoryServiceLocator locator = new RepositoryServiceLocator(AuthenticationUtils.getEngineConfiguration()); 131 locator.setRepositoryServiceEndpointAddress(getEndpointAddress() + REPOSITORY_SERVICE_ADDRESS); 132 repositoryService = (RepositoryServiceSoapBindingStub)locator.getRepositoryService(); 133 } 134 catch (ServiceException jre) 135 { 136 if (logger.isDebugEnabled() == true) 137 { 138 if (jre.getLinkedCause() != null) 139 { 140 jre.getLinkedCause().printStackTrace(); 141 } 142 } 143 144 throw new WebServiceException("Error creating repositoryService service: " + jre.getMessage(), jre); 145 } 146 147 repositoryService.setTimeout(60000); 149 } 150 151 return repositoryService; 152 } 153 154 159 public static AuthoringServiceSoapBindingStub getAuthoringService() 160 { 161 if (authoringService == null) 162 { 163 try 164 { 165 AuthoringServiceLocator locator = new AuthoringServiceLocator(AuthenticationUtils.getEngineConfiguration()); 167 locator.setAuthoringServiceEndpointAddress(getEndpointAddress() + AUTHORING_SERVICE_ADDRESS); 168 authoringService = (AuthoringServiceSoapBindingStub)locator.getAuthoringService(); 169 } 170 catch (ServiceException jre) 171 { 172 if (logger.isDebugEnabled() == true) 173 { 174 if (jre.getLinkedCause() != null) 175 { 176 jre.getLinkedCause().printStackTrace(); 177 } 178 } 179 180 throw new WebServiceException("Error creating authoring service: " + jre.getMessage(), jre); 181 } 182 183 authoringService.setTimeout(60000); 185 } 186 187 return authoringService; 188 } 189 190 195 public static ClassificationServiceSoapBindingStub getClassificationService() 196 { 197 if (classificationService == null) 198 { 199 try 200 { 201 ClassificationServiceLocator locator = new ClassificationServiceLocator(AuthenticationUtils.getEngineConfiguration()); 203 locator.setClassificationServiceEndpointAddress(getEndpointAddress() + CLASSIFICATION_SERVICE_ADDRESS); 204 classificationService = (ClassificationServiceSoapBindingStub)locator.getClassificationService(); 205 } 206 catch (ServiceException jre) 207 { 208 if (logger.isDebugEnabled() == true) 209 { 210 if (jre.getLinkedCause() != null) 211 { 212 jre.getLinkedCause().printStackTrace(); 213 } 214 } 215 216 throw new WebServiceException("Error creating classification service: " + jre.getMessage(), jre); 217 } 218 219 classificationService.setTimeout(60000); 221 } 222 223 return classificationService; 224 } 225 226 231 public static ActionServiceSoapBindingStub getActionService() 232 { 233 if (actionService == null) 234 { 235 try 236 { 237 ActionServiceLocator locator = new ActionServiceLocator(AuthenticationUtils.getEngineConfiguration()); 239 locator.setActionServiceEndpointAddress(getEndpointAddress() + ACTION_SERVICE_ADDRESS); 240 actionService = (ActionServiceSoapBindingStub)locator.getActionService(); 241 } 242 catch (ServiceException jre) 243 { 244 if (logger.isDebugEnabled() == true) 245 { 246 if (jre.getLinkedCause() != null) 247 { 248 jre.getLinkedCause().printStackTrace(); 249 } 250 } 251 252 throw new WebServiceException("Error creating action service: " + jre.getMessage(), jre); 253 } 254 255 actionService.setTimeout(60000); 257 } 258 259 return actionService; 260 } 261 262 267 public static ContentServiceSoapBindingStub getContentService() 268 { 269 if (contentService == null) 270 { 271 try 272 { 273 ContentServiceLocator locator = new ContentServiceLocator(AuthenticationUtils.getEngineConfiguration()); 275 locator.setContentServiceEndpointAddress(getEndpointAddress() + CONTENT_SERVICE_ADDRESS); 276 contentService = (ContentServiceSoapBindingStub)locator.getContentService(); 277 } 278 catch (ServiceException jre) 279 { 280 if (logger.isDebugEnabled() == true) 281 { 282 if (jre.getLinkedCause() != null) 283 { 284 jre.getLinkedCause().printStackTrace(); 285 } 286 } 287 288 throw new WebServiceException("Error creating content service: " + jre.getMessage(), jre); 289 } 290 291 contentService.setTimeout(60000); 293 } 294 295 return contentService; 296 } 297 298 303 public static AccessControlServiceSoapBindingStub getAccessControlService() 304 { 305 if (accessControlService == null) 306 { 307 try 308 { 309 AccessControlServiceLocator locator = new AccessControlServiceLocator(AuthenticationUtils.getEngineConfiguration()); 311 locator.setAccessControlServiceEndpointAddress(getEndpointAddress() + ACCESS_CONTROL_ADDRESS); 312 accessControlService = (AccessControlServiceSoapBindingStub)locator.getAccessControlService(); 313 } 314 catch (ServiceException jre) 315 { 316 if (logger.isDebugEnabled() == true) 317 { 318 if (jre.getLinkedCause() != null) 319 { 320 jre.getLinkedCause().printStackTrace(); 321 } 322 } 323 324 throw new WebServiceException("Error creating access control service: " + jre.getMessage(), jre); 325 } 326 327 accessControlService.setTimeout(60000); 329 } 330 331 return accessControlService; 332 } 333 334 339 public static AdministrationServiceSoapBindingStub getAdministrationService() 340 { 341 if (administrationService == null) 342 { 343 try 344 { 345 AdministrationServiceLocator locator = new AdministrationServiceLocator(AuthenticationUtils.getEngineConfiguration()); 347 locator.setAdministrationServiceEndpointAddress(getEndpointAddress() + ADMINISTRATION_ADDRESS); 348 administrationService = (AdministrationServiceSoapBindingStub)locator.getAdministrationService(); 349 } 350 catch (ServiceException jre) 351 { 352 if (logger.isDebugEnabled() == true) 353 { 354 if (jre.getLinkedCause() != null) 355 { 356 jre.getLinkedCause().printStackTrace(); 357 } 358 } 359 360 throw new WebServiceException("Error creating administration service: " + jre.getMessage(), jre); 361 } 362 363 administrationService.setTimeout(60000); 365 } 366 367 return administrationService; 368 } 369 370 375 private static String getEndpointAddress() 376 { 377 String endPoint = DEFAULT_ENDPOINT_ADDRESS; 378 379 InputStream is = ClassLoader.getSystemResourceAsStream(PROPERTY_FILE_NAME); 380 if (is != null) 381 { 382 Properties props = new Properties (); 383 try 384 { 385 props.load(is); 386 endPoint = props.getProperty(REPO_LOCATION); 387 } 388 catch (Exception e) 389 { 390 if (logger.isDebugEnabled() == true) 392 { 393 logger.debug("Unable to file web service client proerties file. Using default."); 394 } 395 } 396 } 397 398 return endPoint; 399 } 400 } 401 | Popular Tags |