1 17 package org.apache.servicemix.wsn; 18 19 import java.math.BigInteger ; 20 import java.util.List ; 21 22 import javax.jws.Oneway; 23 import javax.jws.WebMethod; 24 import javax.jws.WebParam; 25 import javax.jws.WebResult; 26 import javax.jws.WebService; 27 28 import org.apache.commons.logging.Log; 29 import org.apache.commons.logging.LogFactory; 30 import org.oasis_open.docs.wsn.b_2.CreatePullPoint; 31 import org.oasis_open.docs.wsn.b_2.DestroyPullPoint; 32 import org.oasis_open.docs.wsn.b_2.DestroyPullPointResponse; 33 import org.oasis_open.docs.wsn.b_2.GetMessages; 34 import org.oasis_open.docs.wsn.b_2.GetMessagesResponse; 35 import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType; 36 import org.oasis_open.docs.wsn.b_2.Notify; 37 import org.oasis_open.docs.wsn.b_2.UnableToDestroyPullPointFaultType; 38 import org.apache.servicemix.wsn.jaxws.NotificationConsumer; 39 import org.apache.servicemix.wsn.jaxws.PullPoint; 40 import org.apache.servicemix.wsn.jaxws.ResourceUnknownFault; 41 import org.apache.servicemix.wsn.jaxws.UnableToCreatePullPointFault; 42 import org.apache.servicemix.wsn.jaxws.UnableToDestroyPullPointFault; 43 44 @WebService(endpointInterface = "org.apache.servicemix.wsn.PullPointConsumer") 45 public abstract class AbstractPullPoint extends AbstractEndpoint 46 implements PullPoint, NotificationConsumer { 47 48 private static Log log = LogFactory.getLog(AbstractPullPoint.class); 49 50 protected AbstractCreatePullPoint createPullPoint; 51 52 public AbstractPullPoint(String name) { 53 super(name); 54 } 55 56 60 @WebMethod(operationName = "Notify") 61 @Oneway 62 public void notify( 63 @WebParam(name = "Notify", targetNamespace = "http://docs.oasis-open.org/wsn/b-1", partName = "Notify") 64 Notify notify) { 65 66 log.debug("Notify"); 67 for (NotificationMessageHolderType messageHolder : notify.getNotificationMessage()) { 68 store(messageHolder); 69 } 70 } 71 72 79 @WebMethod(operationName = "GetMessages") 80 @WebResult(name = "GetMessagesResponse", targetNamespace = "http://docs.oasis-open.org/wsn/b-1", partName = "GetMessagesResponse") 81 public GetMessagesResponse getMessages( 82 @WebParam(name = "GetMessages", targetNamespace = "http://docs.oasis-open.org/wsn/b-1", partName = "GetMessagesRequest") 83 GetMessages getMessagesRequest) 84 throws ResourceUnknownFault { 85 86 log.debug("GetMessages"); 87 BigInteger max = getMessagesRequest.getMaximumNumber(); 88 List <NotificationMessageHolderType> messages = getMessages(max != null ? max.intValue() : 0); 89 GetMessagesResponse response = new GetMessagesResponse(); 90 response.getNotificationMessage().addAll(messages); 91 return response; 92 } 93 94 101 @WebMethod(operationName = "DestroyPullPoint") 102 @WebResult(name = "DestroyPullPointResponse", targetNamespace = "http://docs.oasis-open.org/wsn/b-2", partName = "DestroyPullPointResponse") 103 public DestroyPullPointResponse destroyPullPoint( 104 @WebParam(name = "DestroyPullPoint", targetNamespace = "http://docs.oasis-open.org/wsn/b-2", partName = "DestroyPullPointRequest") 105 DestroyPullPoint destroyPullPointRequest) 106 throws UnableToDestroyPullPointFault { 107 108 log.debug("Destroy"); 109 createPullPoint.destroyPullPoint(getAddress()); 110 return new DestroyPullPointResponse(); 111 } 112 113 public void create(CreatePullPoint createPullPointRequest) throws UnableToCreatePullPointFault { 114 } 115 116 protected abstract void store(NotificationMessageHolderType messageHolder); 117 118 protected abstract List <NotificationMessageHolderType> getMessages(int max) throws ResourceUnknownFault; 119 120 protected void destroy() throws UnableToDestroyPullPointFault { 121 try { 122 unregister(); 123 } catch (EndpointRegistrationException e) { 124 UnableToDestroyPullPointFaultType fault = new UnableToDestroyPullPointFaultType(); 125 throw new UnableToDestroyPullPointFault("Error unregistering endpoint", fault, e); 126 } 127 } 128 129 protected String createAddress() { 130 return "http://servicemix.org/wsnotification/PullPoint/" + getName(); 131 } 132 133 public AbstractCreatePullPoint getCreatePullPoint() { 134 return createPullPoint; 135 } 136 137 public void setCreatePullPoint(AbstractCreatePullPoint createPullPoint) { 138 this.createPullPoint = createPullPoint; 139 } 140 } 141 | Popular Tags |