1 24 package fr.dyade.aaa.jndi2.soap; 25 26 import fr.dyade.aaa.jndi2.client.NamingContextImpl; 27 import fr.dyade.aaa.jndi2.client.Trace; 28 29 import org.apache.soap.Constants; 30 import org.apache.soap.Fault; 31 import org.apache.soap.SOAPException; 32 import org.apache.soap.encoding.soapenc.BeanSerializer; 33 import org.apache.soap.rpc.Call; 34 import org.apache.soap.rpc.Parameter; 35 import org.apache.soap.rpc.Response; 36 import org.apache.soap.server.DeploymentDescriptor; 37 import org.apache.soap.server.ServiceManagerClient; 38 39 import java.net.MalformedURLException ; 40 import java.net.URL ; 41 import java.util.Vector ; 42 import java.util.Hashtable ; 43 import java.util.Map ; 44 45 import javax.naming.Context ; 46 import javax.naming.NamingEnumeration ; 47 import javax.naming.NamingException ; 48 49 import org.objectweb.util.monolog.api.BasicLevel; 50 import org.objectweb.util.monolog.api.Logger; 51 52 53 58 public class SoapExt_NamingContextImpl extends NamingContextImpl 59 { 60 61 private URL serviceUrl; 62 63 private Call bindCall = null; 64 65 private Call rebindCall = null; 66 67 private Call lookupCall = null; 68 69 private Call unbindCall = null; 70 71 72 83 public SoapExt_NamingContextImpl(String soapHost, int soapPort, 84 String jndiHost, int jndiPort) 85 throws NamingException 86 { 87 super(); 88 89 try { 91 serviceUrl = new URL ("http://" + soapHost + ":" + soapPort 92 + "/soap/servlet/rpcrouter"); 93 } 94 catch (MalformedURLException exc) {} 95 96 if (Trace.logger.isLoggable(BasicLevel.DEBUG)) 98 Trace.logger.log(BasicLevel.DEBUG, "Starting the SOAP service on host " 99 + soapHost 100 + " listening on port " 101 + soapPort); 102 try { 103 ServiceManagerClient smc = new ServiceManagerClient(serviceUrl); 104 smc.deploy(getDeploymentDescriptor()); 105 } 106 catch (Exception exc) { 107 NamingException nEx = 108 new NamingException ("Could not deploy the SOAP service"); 109 nEx.setRootCause(exc); 110 throw nEx; 111 } 112 113 if (Trace.logger.isLoggable(BasicLevel.DEBUG)) 114 Trace.logger.log(BasicLevel.DEBUG, "SOAP service deployed."); 115 116 Call initCall = new Call(); 118 initCall.setTargetObjectURI("urn:JndiService"); 119 initCall.setMethodName("init"); 120 121 Vector params = new Vector (); 122 params.add(new Parameter("jndiHost", String .class, jndiHost, null)); 123 params.add(new Parameter("jndiPort", Integer .class, 124 new Integer (jndiPort), null)); 125 initCall.setParams(params); 126 127 try { 128 Response resp = initCall.invoke(serviceUrl,""); 129 } 130 catch (Exception exc) {} 131 132 if (Trace.logger.isLoggable(BasicLevel.DEBUG)) 133 Trace.logger.log(BasicLevel.DEBUG, "SOAP service initialized."); 134 } 135 136 137 143 public void bind(String name, Object obj) throws NamingException 144 { 145 if (Trace.logger.isLoggable(BasicLevel.DEBUG)) 146 Trace.logger.log(BasicLevel.DEBUG, "SoapExt_NamingContextImpl.bind(" 147 + name + ',' + obj + ')'); 148 149 if (bindCall == null) { 151 bindCall = new Call(); 152 bindCall.setTargetObjectURI("urn:JndiService"); 153 bindCall.setMethodName("bind"); 154 bindCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); 155 } 156 157 Hashtable codedObj = SoapObjectHelper.soapCode(obj); 159 160 Vector params = new Vector (); 161 params.add(new Parameter("name", String .class, name, null)); 162 params.add(new Parameter("map", Hashtable .class, codedObj, null)); 163 164 bindCall.setParams(params); 165 166 try { 167 Response resp = bindCall.invoke(serviceUrl,""); 168 169 if (resp.generatedFault ()) { 171 throw new NamingException ("The SOAP service failed to process" 172 + " the call: " 173 + resp.getFault().getFaultString()); 174 } 175 } 176 catch (SOAPException exc) { 177 throw new NamingException ("The SOAP call failed: " + exc.getMessage()); 178 } 179 } 180 181 187 public void rebind(String name, Object obj) throws NamingException 188 { 189 if (Trace.logger.isLoggable(BasicLevel.DEBUG)) 190 Trace.logger.log(BasicLevel.DEBUG, "SoapExt_NamingContextImpl.rebind(" 191 + name + ',' + obj + ')'); 192 193 if (rebindCall == null) { 195 rebindCall = new Call(); 196 rebindCall.setTargetObjectURI("urn:JndiService"); 197 rebindCall.setMethodName("rebind"); 198 rebindCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); 199 } 200 201 Hashtable codedObj = SoapObjectHelper.soapCode(obj); 203 204 Vector params = new Vector (); 205 params.add(new Parameter("name", String .class, name, null)); 206 params.add(new Parameter("map", Hashtable .class, codedObj, null)); 207 208 rebindCall.setParams(params); 209 210 try { 211 Response resp = rebindCall.invoke(serviceUrl,""); 212 213 if (resp.generatedFault ()) { 215 throw new NamingException ("The SOAP service failed to process" 216 + " the call: " 217 + resp.getFault().getFaultString()); 218 } 219 } 220 catch (SOAPException exc) { 221 throw new NamingException ("The SOAP call failed: " + exc.getMessage()); 222 } 223 } 224 225 231 public Object lookup(String name) throws NamingException 232 { 233 if (Trace.logger.isLoggable(BasicLevel.DEBUG)) 234 Trace.logger.log(BasicLevel.DEBUG, "SoapExt_NamingContextImpl.lookup(" 235 + name + ')'); 236 237 if (lookupCall == null) { 239 lookupCall = new Call(); 240 lookupCall.setTargetObjectURI("urn:JndiService"); 241 lookupCall.setMethodName("lookup"); 242 lookupCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); 243 } 244 245 Vector params = new Vector (); 246 params.add(new Parameter("name", String .class, name, null)); 247 248 lookupCall.setParams(params); 249 250 Response resp = null; 251 try { 252 resp = lookupCall.invoke(serviceUrl,""); 253 254 if (resp.generatedFault ()) { 256 throw new NamingException ("The SOAP service failed to process" 257 + " the call: " 258 + resp.getFault().getFaultString()); 259 } 260 } 261 catch (SOAPException exc) { 262 throw new NamingException ("The SOAP call failed: " + exc.getMessage()); 263 } 264 265 Map codedObj = (Map ) resp.getReturnValue().getValue(); 266 return SoapObjectHelper.soapDecode((Hashtable ) codedObj); 267 } 268 269 274 public void unbind(String name) throws NamingException 275 { 276 if (Trace.logger.isLoggable(BasicLevel.DEBUG)) 277 Trace.logger.log(BasicLevel.DEBUG, "SoapExt_NamingContextImpl.unbind(" 278 + name + ')'); 279 280 if (unbindCall == null) { 282 unbindCall = new Call(); 283 unbindCall.setTargetObjectURI("urn:JndiService"); 284 unbindCall.setMethodName("unbind"); 285 unbindCall.setEncodingStyleURI(Constants.NS_URI_SOAP_ENC); 286 } 287 288 Vector params = new Vector (); 289 params.add(new Parameter("name", String .class, name, null)); 290 291 unbindCall.setParams(params); 292 293 Response resp = null; 294 try { 295 resp = unbindCall.invoke(serviceUrl,""); 296 297 if (resp.generatedFault ()) { 299 throw new NamingException ("The SOAP service failed to process" 300 + " the call: " 301 + resp.getFault().getFaultString()); 302 } 303 } 304 catch (SOAPException exc) { 305 throw new NamingException ("The SOAP call failed: " + exc.getMessage()); 306 } 307 } 308 309 314 public NamingEnumeration list(String name) throws NamingException 315 { 316 throw new NamingException ("Method not implemented."); 317 } 318 319 324 public NamingEnumeration listBindings(String name) throws NamingException 325 { 326 throw new NamingException ("Method not implemented."); 327 } 328 329 334 public Context createSubcontext(String name) throws NamingException 335 { 336 throw new NamingException ("Method not implemented."); 337 } 338 339 344 public void destroySubcontext(String name) throws NamingException 345 { 346 throw new NamingException ("Method not implemented."); 347 } 348 349 350 354 private DeploymentDescriptor getDeploymentDescriptor() 355 { 356 DeploymentDescriptor dd = new DeploymentDescriptor(); 357 358 dd.setID("urn:JndiService"); 359 360 dd.setProviderType(DeploymentDescriptor.PROVIDER_JAVA); 361 dd.setProviderClass("fr.dyade.aaa.jndi2.soap.JndiSoapService"); 362 dd.setScope(DeploymentDescriptor.SCOPE_APPLICATION); 363 364 String [] methods = {"init", "bind", "rebind", "lookup", "unbind"}; 365 dd.setMethods(methods); 366 367 String [] listener = {"org.apache.soap.server.DOMFaultListener"}; 368 dd.setFaultListener(listener); 369 370 return dd; 371 } 372 } 373 | Popular Tags |