This project has retired. For details please refer to its Attic page.
RMITransport xref
View Javadoc
1   /*
2    * Copyright 2001-2009 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.v3.client.transport;
18  
19  import java.net.URI;
20  import java.util.Properties;
21  
22  import javax.naming.InitialContext;
23  import javax.naming.NamingException;
24  
25  import org.apache.commons.configuration.ConfigurationException;
26  import org.apache.commons.logging.Log;
27  import org.apache.commons.logging.LogFactory;
28  import org.apache.juddi.v3.client.config.Property;
29  import org.apache.juddi.v3.client.config.UDDIClient;
30  import org.apache.juddi.v3.client.config.UDDIClientContainer;
31  import org.apache.juddi.v3_service.JUDDIApiPortType;
32  import org.uddi.v3_service.UDDICustodyTransferPortType;
33  import org.uddi.v3_service.UDDIInquiryPortType;
34  import org.uddi.v3_service.UDDIPublicationPortType;
35  import org.uddi.v3_service.UDDISecurityPortType;
36  import org.uddi.v3_service.UDDISubscriptionListenerPortType;
37  import org.uddi.v3_service.UDDISubscriptionPortType;
38  
39  
40  public class RMITransport extends Transport {
41  
42  	InitialContext context = null;
43  	private Log logger = LogFactory.getLog(this.getClass());
44  	private String nodeName = null;
45  	private String clientName = null;
46  	
47  	public RMITransport() {
48  		super();
49  		this.nodeName = Transport.DEFAULT_NODE_NAME;
50  	}
51  	
52  	public RMITransport(String nodeName) throws NamingException, ConfigurationException {
53  		super();
54  		this.nodeName = nodeName;
55  		initContext();
56  	}
57  	
58  	public RMITransport(String clientName, String nodeName) throws NamingException, ConfigurationException {
59  		super();
60  		this.nodeName = nodeName;
61  		this.clientName = clientName;
62  		initContext();
63  	}
64  	
65  	private void initContext() throws NamingException, ConfigurationException {
66  		Properties env = new Properties();
67  		UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
68  		String factoryInitial = client.getClientConfig().getHomeNode().getFactoryInitial();
69  		String factoryURLPkgs = client.getClientConfig().getHomeNode().getFactoryURLPkgs();
70  		String factoryNamingProvider = client.getClientConfig().getHomeNode().getFactoryNamingProvider();
71          if (factoryInitial!=null && !"".equals(factoryInitial)) env.setProperty(Property.UDDI_PROXY_FACTORY_INITIAL, factoryInitial);
72          if (factoryURLPkgs!=null && !"".equals(factoryURLPkgs)) env.setProperty(Property.UDDI_PROXY_FACTORY_URL_PKS, factoryURLPkgs);
73          if (factoryNamingProvider!=null && !"".equals(factoryNamingProvider)) env.setProperty(Property.UDDI_PROXY_PROVIDER_URL, factoryNamingProvider);
74      	logger.debug("Initial Context using env=" + env.toString());
75      	context = new InitialContext(env);
76  	}
77  
78  	private UDDIInquiryPortType inquiryService = null;
79  	private UDDISecurityPortType securityService = null;
80  	private UDDIPublicationPortType publishService = null;
81  	private UDDISubscriptionPortType subscriptionService = null;
82  	private UDDISubscriptionListenerPortType subscriptionListenerService = null;
83  	private UDDICustodyTransferPortType custodyTransferService = null;
84  	private JUDDIApiPortType publisherService = null;
85  	
86  
87  	public UDDIInquiryPortType getUDDIInquiryService(String endpointURL) throws TransportException {
88  		if (inquiryService==null) {
89  			try {
90  				if (endpointURL==null) {
91  					UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
92  					endpointURL = client.getClientConfig().getUDDINode(nodeName).getInquiryUrl();
93  				}
94  				URI endpointURI = new URI(endpointURL);
95  		    	String service    = endpointURI.getPath();
96  		    	logger.debug("Looking up service=" + service);
97  		    	Object requestHandler = context.lookup(service);
98  		    	inquiryService = (UDDIInquiryPortType) requestHandler;
99  			} catch (Exception e) {
100 				throw new TransportException(e.getMessage(), e);
101 			}
102 		}
103 		return inquiryService;
104 	}
105 	
106 	public UDDISecurityPortType getUDDISecurityService(String endpointURL) throws TransportException {
107 		if (securityService==null) {
108 			try {
109 				if (endpointURL==null) {
110 					UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
111 					endpointURL = client.getClientConfig().getUDDINode(nodeName).getSecurityUrl();
112 				}
113 				URI endpointURI = new URI(endpointURL);
114 		    	String service    = endpointURI.getPath();
115 		    	logger.debug("Looking up service=" + service);
116 		    	Object requestHandler = context.lookup(service);
117 				securityService = (UDDISecurityPortType) requestHandler;
118 			} catch (Exception e) {
119 				throw new TransportException(e.getMessage(), e);
120 			}
121 		}
122 		return securityService;
123 	}
124 	
125 	public UDDIPublicationPortType getUDDIPublishService(String endpointURL) throws TransportException {
126 		if (publishService==null) {
127 			try {
128 				if (endpointURL==null) {
129 					UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
130 					endpointURL = client.getClientConfig().getUDDINode(nodeName).getPublishUrl();
131 				}
132 				URI endpointURI = new URI(endpointURL);
133 		    	String service    = endpointURI.getPath();
134 		    	logger.debug("Looking up service=" + service);
135 		    	Object requestHandler = context.lookup(service);
136 				publishService = (UDDIPublicationPortType) requestHandler;
137 			} catch (Exception e) {
138 				throw new TransportException(e.getMessage(), e);
139 			}
140 		}
141 		return publishService;
142 	}
143 	
144 	public UDDISubscriptionPortType getUDDISubscriptionService(String endpointURL) throws TransportException {
145 		if (subscriptionService==null) {
146 			try {
147 				if (endpointURL==null) {
148 					UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
149 					endpointURL = client.getClientConfig().getUDDINode(nodeName).getSubscriptionUrl();
150 				}
151 				URI endpointURI = new URI(endpointURL);
152 		    	String service    = endpointURI.getPath();
153 		    	logger.debug("Looking up service=" + service);
154 		    	Object requestHandler = context.lookup(service);
155 		    	subscriptionService = (UDDISubscriptionPortType) requestHandler;
156 			} catch (Exception e) {
157 				throw new TransportException(e.getMessage(), e);
158 			}
159 		}
160 		return subscriptionService;
161 	}
162 	
163 	public UDDISubscriptionListenerPortType getUDDISubscriptionListenerService(String endpointURL) throws TransportException {
164 		if (subscriptionListenerService==null) {
165 			try {
166 				if (endpointURL==null) {
167 					UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
168 					endpointURL = client.getClientConfig().getUDDINode(nodeName).getSubscriptionListenerUrl();
169 				}
170 				URI endpointURI = new URI(endpointURL);
171 		    	String service    = endpointURI.getPath();
172 		    	logger.debug("Looking up service=" + service);
173 		    	Object requestHandler = context.lookup(service);
174 		    	subscriptionListenerService = (UDDISubscriptionListenerPortType)  requestHandler;
175 			} catch (Exception e) {
176 				throw new TransportException(e.getMessage(), e);
177 			}
178 		}
179 		return subscriptionListenerService;
180 	}
181 	
182 	public UDDICustodyTransferPortType getUDDICustodyTransferService(String endpointURL) throws TransportException {
183 		if (custodyTransferService==null) {
184 			try {
185 				if (endpointURL==null) {
186 					UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
187 					endpointURL = client.getClientConfig().getUDDINode(nodeName).getCustodyTransferUrl();
188 				}
189 				URI endpointURI = new URI(endpointURL);
190 		    	String service    = endpointURI.getPath();
191 		    	logger.debug("Looking up service=" + service);
192 		    	Object requestHandler = context.lookup(service);
193 		    	custodyTransferService = (UDDICustodyTransferPortType)  requestHandler;
194 			} catch (Exception e) {
195 				throw new TransportException(e.getMessage(), e);
196 			}
197 		}
198 		return custodyTransferService;
199 	}
200 	
201 	public JUDDIApiPortType getJUDDIApiService(String endpointURL) throws TransportException {
202 		if (publisherService==null) {
203 			try {
204 				if (endpointURL==null) {
205 					UDDIClient client = UDDIClientContainer.getUDDIClient(clientName);
206 					endpointURL = client.getClientConfig().getUDDINode(nodeName).getJuddiApiUrl();
207 				}
208 				URI endpointURI = new URI(endpointURL);
209 		    	String service    = endpointURI.getPath();
210 		    	logger.debug("Looking up service=" + service);
211 		    	Object requestHandler = context.lookup(service);
212 		    	publisherService = (JUDDIApiPortType)  requestHandler;
213 			} catch (Exception e) {
214 				throw new TransportException(e.getMessage(), e);
215 			}
216 		}
217 		return publisherService;
218 	}
219 
220 }