1 17 package org.apache.servicemix.wsn.jbi; 18 19 import javax.jbi.JBIException; 20 import javax.jbi.component.ComponentContext; 21 import javax.jbi.servicedesc.ServiceEndpoint; 22 import javax.xml.bind.JAXBException; 23 import javax.xml.namespace.QName ; 24 25 import org.apache.servicemix.wsn.client.AbstractWSAClient; 26 import org.apache.servicemix.wsn.client.NotificationBroker; 27 import org.apache.servicemix.wsn.client.Subscription; 28 import org.apache.servicemix.wsn.component.WSNLifeCycle; 29 import org.apache.servicemix.wsn.jaxws.InvalidTopicExpressionFault; 30 import org.apache.servicemix.wsn.jaxws.PublisherRegistrationFailedFault; 31 import org.apache.servicemix.wsn.jaxws.PublisherRegistrationRejectedFault; 32 import org.apache.servicemix.wsn.jaxws.ResourceUnknownFault; 33 import org.apache.servicemix.wsn.jaxws.TopicNotSupportedFault; 34 import org.apache.servicemix.wsn.jms.JmsPublisher; 35 import org.oasis_open.docs.wsn.br_2.PublisherRegistrationFailedFaultType; 36 import org.oasis_open.docs.wsn.br_2.RegisterPublisher; 37 38 public class JbiPublisher extends JmsPublisher { 39 40 private WSNLifeCycle lifeCycle; 41 private ServiceEndpoint endpoint; 42 private String notificationBrokerAddress; 43 44 public JbiPublisher(String name) { 45 super(name); 46 } 47 48 public String getNotificationBrokerAddress() { 49 return notificationBrokerAddress; 50 } 51 52 public void setNotificationBrokerAddress(String notificationBrokerAddress) { 53 this.notificationBrokerAddress = notificationBrokerAddress; 54 } 55 56 @Override 57 protected Object startSubscription() { 58 Subscription subscription = null; 59 try { 60 NotificationBroker broker = new NotificationBroker(getContext()); 61 broker.setResolver(AbstractWSAClient.resolveWSA(publisherReference)); 62 subscription = broker.subscribe(AbstractWSAClient.createWSA(notificationBrokerAddress), 63 "noTopic", null); 64 } catch (JBIException e) { 65 e.printStackTrace(); 67 } catch (JAXBException e) { 68 e.printStackTrace(); 70 } 71 return subscription; 72 } 73 74 @Override 75 protected void destroySubscription(Object subscription) { 76 try { 77 ((Subscription) subscription).unsubscribe(); 78 } catch (JBIException e) { 79 e.printStackTrace(); 81 } 82 } 83 84 @Override 85 protected void validatePublisher(RegisterPublisher registerPublisherRequest) throws InvalidTopicExpressionFault, PublisherRegistrationFailedFault, PublisherRegistrationRejectedFault, ResourceUnknownFault, TopicNotSupportedFault { 86 super.validatePublisher(registerPublisherRequest); 87 String [] parts = split(publisherReference.getAddress().getValue()); 88 endpoint = getContext().getEndpoint(new QName (parts[0], parts[1]), parts[2]); 89 if (endpoint == null) { 90 PublisherRegistrationFailedFaultType fault = new PublisherRegistrationFailedFaultType(); 91 throw new PublisherRegistrationFailedFault("Unable to resolve consumer reference endpoint", fault); 92 } 93 } 94 95 protected String [] split(String uri) { 96 char sep; 97 if (uri.indexOf('/') > 0) { 98 sep = '/'; 99 } else { 100 sep = ':'; 101 } 102 int idx1 = uri.lastIndexOf(sep); 103 int idx2 = uri.lastIndexOf(sep, idx1 - 1); 104 String epName = uri.substring(idx1 + 1); 105 String svcName = uri.substring(idx2 + 1, idx1); 106 String nsUri = uri.substring(0, idx2); 107 return new String [] { nsUri, svcName, epName }; 108 } 109 110 public ComponentContext getContext() { 111 return lifeCycle.getContext(); 112 } 113 114 public WSNLifeCycle getLifeCycle() { 115 return lifeCycle; 116 } 117 118 public void setLifeCycle(WSNLifeCycle lifeCycle) { 119 this.lifeCycle = lifeCycle; 120 } 121 122 } 123 | Popular Tags |