This project has retired. For details please refer to its Attic page.
RMINotifier xref
View Javadoc
1   /*
2    * Copyright 2001-2008 The Apache Software Foundation.
3    * 
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    * 
8    *      http://www.apache.org/licenses/LICENSE-2.0
9    * 
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   */
17  package org.apache.juddi.subscription.notify;
18  
19  import java.io.IOException;
20  import java.net.URI;
21  import java.net.URISyntaxException;
22  import java.rmi.NotBoundException;
23  import java.rmi.RemoteException;
24  import java.rmi.registry.LocateRegistry;
25  import java.rmi.registry.Registry;
26  
27  import org.apache.commons.logging.Log;
28  import org.apache.commons.logging.LogFactory;
29  import org.apache.juddi.api_v3.AccessPointType;
30  import org.apache.juddi.model.BindingTemplate;
31  import org.uddi.api_v3.DispositionReport;
32  import org.uddi.subr_v3.NotifySubscriptionListener;
33  import org.uddi.v3_service.DispositionReportFaultMessage;
34  import org.uddi.v3_service.UDDISubscriptionListenerPortType;
35  
36  public class RMINotifier implements Notifier {
37  	
38  	Log log = LogFactory.getLog(this.getClass());
39  	UDDISubscriptionListenerPortType  subscriptionListenerPort = null;
40  	
41  	public RMINotifier(BindingTemplate bindingTemplate) throws IOException, URISyntaxException, NotBoundException {
42  		super();
43  		if (!AccessPointType.END_POINT.toString().equalsIgnoreCase(bindingTemplate.getAccessPointType())) {
44  			log.error("rmi enpoints only support AccessPointType " + AccessPointType.END_POINT);
45  		}
46  		String accessPointUrl = bindingTemplate.getAccessPointUrl().toLowerCase();
47  		if (!accessPointUrl.startsWith("rmi")) {
48  			log.warn("rmi accessPointUrl for bindingTemplate " + bindingTemplate.getEntityKey() + 
49  					" should start with 'rmi'");
50  		}
51  		URI accessPointURI = new URI(accessPointUrl);
52  		String host = accessPointURI.getHost();
53  		int port = accessPointURI.getPort();
54  		String path = accessPointURI.getPath();
55  		log.debug("Connecting to " + host + ":" + port);
56  		Registry registry = LocateRegistry.getRegistry(host, port);
57  		subscriptionListenerPort = (UDDISubscriptionListenerPortType) registry.lookup(path);
58  	}
59  
60  	public DispositionReport notifySubscriptionListener(NotifySubscriptionListener body) throws DispositionReportFaultMessage, RemoteException {
61  		return subscriptionListenerPort.notifySubscriptionListener(body);
62  	}
63  }