1 17 package org.apache.servicemix.wsn; 18 19 import java.util.List ; 20 21 import javax.jws.WebMethod; 22 import javax.jws.WebParam; 23 import javax.jws.WebResult; 24 import javax.jws.WebService; 25 26 import org.oasis_open.docs.wsn.b_2.InvalidTopicExpressionFaultType; 27 import org.oasis_open.docs.wsn.b_2.NotificationMessageHolderType; 28 import org.oasis_open.docs.wsn.b_2.TopicExpressionType; 29 import org.oasis_open.docs.wsn.br_2.DestroyRegistration; 30 import org.oasis_open.docs.wsn.br_2.DestroyRegistrationResponse; 31 import org.oasis_open.docs.wsn.br_2.PublisherRegistrationFailedFaultType; 32 import org.oasis_open.docs.wsn.br_2.RegisterPublisher; 33 import org.oasis_open.docs.wsn.br_2.ResourceNotDestroyedFaultType; 34 import org.apache.servicemix.wsn.jaxws.InvalidTopicExpressionFault; 35 import org.apache.servicemix.wsn.jaxws.PublisherRegistrationFailedFault; 36 import org.apache.servicemix.wsn.jaxws.PublisherRegistrationManager; 37 import org.apache.servicemix.wsn.jaxws.PublisherRegistrationRejectedFault; 38 import org.apache.servicemix.wsn.jaxws.ResourceNotDestroyedFault; 39 import org.apache.servicemix.wsn.jaxws.ResourceUnknownFault; 40 import org.apache.servicemix.wsn.jaxws.TopicNotSupportedFault; 41 import org.w3._2005._08.addressing.EndpointReferenceType; 42 43 @WebService(endpointInterface = "org.apache.servicemix.wsn.jaxws.PublisherRegistrationManager") 44 public abstract class AbstractPublisher extends AbstractEndpoint 45 implements PublisherRegistrationManager { 46 47 protected EndpointReferenceType publisherReference; 48 protected boolean demand; 49 protected List <TopicExpressionType> topic; 50 51 public AbstractPublisher(String name) { 52 super(name); 53 } 54 55 63 @WebMethod(operationName = "DestroyRegistration") 64 @WebResult(name = "DestroyRegistrationResponse", targetNamespace = "http://docs.oasis-open.org/wsn/br-2", partName = "DestroyRegistrationResponse") 65 public DestroyRegistrationResponse destroyRegistration( 66 @WebParam(name = "DestroyRegistration", targetNamespace = "http://docs.oasis-open.org/wsn/br-2", partName = "DestroyRegistrationRequest") 67 DestroyRegistration destroyRegistrationRequest) 68 throws ResourceNotDestroyedFault, ResourceUnknownFault { 69 70 destroy(); 71 return new DestroyRegistrationResponse(); 72 } 73 74 public abstract void notify(NotificationMessageHolderType messageHolder); 75 76 protected void destroy() throws ResourceNotDestroyedFault { 77 try { 78 unregister(); 79 } catch (EndpointRegistrationException e) { 80 ResourceNotDestroyedFaultType fault = new ResourceNotDestroyedFaultType(); 81 throw new ResourceNotDestroyedFault("Error unregistering endpoint", fault, e); 82 } 83 } 84 85 protected String createAddress() { 86 return "http://servicemix.org/wsnotification/Publisher/" + getName(); 87 } 88 89 public void create(RegisterPublisher registerPublisherRequest) throws InvalidTopicExpressionFault, PublisherRegistrationFailedFault, PublisherRegistrationRejectedFault, ResourceUnknownFault, TopicNotSupportedFault { 90 validatePublisher(registerPublisherRequest); 91 start(); 92 } 93 94 protected void validatePublisher(RegisterPublisher registerPublisherRequest) throws InvalidTopicExpressionFault, PublisherRegistrationFailedFault, PublisherRegistrationRejectedFault, ResourceUnknownFault, TopicNotSupportedFault { 95 publisherReference = registerPublisherRequest.getPublisherReference(); 97 topic = registerPublisherRequest.getTopic(); 99 demand = registerPublisherRequest.isDemand() != null ? registerPublisherRequest.isDemand().booleanValue() : false; 101 if (publisherReference == null) { 103 PublisherRegistrationFailedFaultType fault = new PublisherRegistrationFailedFaultType(); 104 throw new PublisherRegistrationFailedFault("Invalid PublisherReference: null", fault); 105 } 106 if (demand) { 107 if (topic == null || topic.size() == 0) { 108 InvalidTopicExpressionFaultType fault = new InvalidTopicExpressionFaultType(); 109 throw new InvalidTopicExpressionFault("Must specify at least one topic for demand-based publishing", fault); 110 } 111 } 112 } 113 114 protected abstract void start() throws PublisherRegistrationFailedFault; 115 } 116 | Popular Tags |