1 7 package org.exoplatform.services.wsrp.producer.impl; 8 9 import java.rmi.RemoteException ; 10 import org.apache.commons.lang.StringUtils; 11 import org.apache.commons.logging.Log; 12 import org.exoplatform.commons.utils.IdentifierUtil; 13 import org.exoplatform.services.log.LogService; 14 import org.exoplatform.services.wsrp.exceptions.Exception2Fault; 15 import org.exoplatform.services.wsrp.exceptions.Faults; 16 import org.exoplatform.services.wsrp.exceptions.WSRPException; 17 import org.exoplatform.services.wsrp.producer.PersistentStateManager; 18 import org.exoplatform.services.wsrp.producer.RegistrationOperationsInterface; 19 import org.exoplatform.services.wsrp.type.RegistrationContext; 20 import org.exoplatform.services.wsrp.type.RegistrationData; 21 import org.exoplatform.services.wsrp.type.RegistrationState; 22 import org.exoplatform.services.wsrp.type.ReturnAny; 23 24 25 29 public class RegistrationOperationsInterfaceImp 30 implements RegistrationOperationsInterface { 31 32 private Log log; 33 34 private PersistentStateManager stateManager; 35 36 public RegistrationOperationsInterfaceImp(PersistentStateManager stateManager, 37 LogService logService) { 38 this.stateManager = stateManager; 39 this.log = logService.getLog("org.exoplatform.services.wsrp"); 40 } 41 42 public RegistrationContext register(RegistrationData data) 43 throws RemoteException { 44 log.debug("Register method entered"); 45 String registrationHandle = null; 46 byte[] registrationState = null; 47 try { 48 validateRegistrationDatas(data); 49 registrationHandle = IdentifierUtil.generateUUID(data); 50 registrationState = stateManager.register(registrationHandle, data); } catch (WSRPException e) { 52 log.debug("Registration failed", e); 53 Exception2Fault.handleException(e); 54 } 55 RegistrationContext rC = new RegistrationContext(); 56 rC.setRegistrationHandle(registrationHandle); 57 rC.setRegistrationState(registrationState); 58 log.debug("Registration done with handle : " + registrationHandle); 59 return rC; 60 } 61 62 public RegistrationState modifyRegistration(RegistrationContext registrationContext, 63 RegistrationData data) 64 throws RemoteException { 65 log.debug("Modify registrion method entered"); 66 try { 67 if (!stateManager.isRegistered(registrationContext)) { 68 Exception2Fault.handleException(new WSRPException(Faults.INVALID_REGISTRATION_FAULT)); 69 } 70 } catch (WSRPException e) { 71 Exception2Fault.handleException(e); 72 } 73 74 String registrationHandle = registrationContext.getRegistrationHandle(); 75 try { 76 validateRegistrationDatas(data); 77 stateManager.register(registrationHandle, data); 78 } catch (WSRPException e) { 79 log.debug("Registration failed", e); 80 Exception2Fault.handleException(e); 81 } 82 83 return new RegistrationState(); } 85 86 public ReturnAny deregister(RegistrationContext registrationContext) 87 throws RemoteException { 88 log.debug("Deregister method entered"); 89 try { 90 if (!stateManager.isRegistered(registrationContext)) { 91 Exception2Fault.handleException(new WSRPException(Faults.INVALID_REGISTRATION_FAULT)); 92 } 93 } catch (WSRPException e) { 94 Exception2Fault.handleException(e); 95 } 96 try { 97 stateManager.deregister(registrationContext); 98 } catch (WSRPException e) { 99 log.debug("Registration failed", e); 100 Exception2Fault.handleException(e); 101 } 102 return new ReturnAny(); 103 } 104 105 private void validateRegistrationDatas(RegistrationData data) 106 throws WSRPException { 107 String consumerAgent = data.getConsumerAgent(); 108 String [] members = StringUtils.split(consumerAgent, "."); 109 if (!StringUtils.isNumeric(members[1])) { 110 throw new WSRPException(Faults.MISSING_PARAMETERS_FAULT); 111 } 112 if (!StringUtils.isNumeric(members[2])) { 113 throw new WSRPException(Faults.MISSING_PARAMETERS_FAULT); 114 } 115 } 116 117 } 118 | Popular Tags |