1 23 package com.sun.enterprise.tools.common; 24 25 import java.io.File ; 26 import java.io.FileInputStream ; 27 import java.io.Serializable ; 28 import com.sun.enterprise.tools.common.dd.webservice.Webservices; 29 import com.sun.enterprise.tools.common.dd.webservice.PortComponentType; 30 import com.sun.enterprise.tools.common.dd.webservice.WebserviceDescriptionType; 31 import com.sun.enterprise.tools.common.dd.webservice.ServiceImplBeanType; 32 import com.sun.enterprise.admin.wsmgmt.repository.spi.WebServiceInfoProvider; 33 import com.sun.enterprise.admin.wsmgmt.repository.spi.RepositoryException; 34 import com.sun.appserv.management.ext.wsmgmt.WebServiceEndpointInfo; 35 import com.sun.appserv.management.ext.wsmgmt.WebServiceEndpointInfoImpl; 36 37 import com.sun.enterprise.tools.common.dd.ejb.SunEjbJar; 38 import com.sun.enterprise.tools.common.dd.ejb.EnterpriseBeans; 39 import com.sun.enterprise.tools.common.dd.ejb.Ejb; 40 import com.sun.enterprise.tools.common.dd.WebserviceEndpoint; 41 42 import com.sun.enterprise.tools.common.dd.webapp.SunWebApp; 43 import com.sun.enterprise.tools.common.dd.webapp.Servlet; 44 45 import java.util.ArrayList ; 46 import java.util.List ; 47 import java.util.Map ; 48 import java.util.HashMap ; 49 import java.io.FileNotFoundException ; 50 import com.sun.enterprise.admin.mbeans.J2EEModule; 51 52 import org.netbeans.modules.schema2beans.Schema2BeansException; 53 import com.sun.enterprise.config.ConfigContext; 54 import com.sun.enterprise.config.serverbeans.ApplicationHelper; 55 import com.sun.enterprise.config.serverbeans.WebModule; 56 import com.sun.enterprise.config.ConfigBean; 57 import com.sun.enterprise.admin.server.core.AdminService; 58 59 69 public class AppServWebServiceInfoProvider implements WebServiceInfoProvider { 70 71 76 public String getProviderID() { 77 return PROVIDER_ID; 78 } 79 80 90 public List getWebServiceInfo(String moduleInfo, Map propMap) 91 throws RepositoryException { 92 String moduleType = null,appId =null, bundleName = null, 93 webservices = null, bundleRoot = null; 94 if (propMap != null) { 95 moduleType = (String ) 96 propMap.get(WebServiceInfoProvider.MOD_TYPE_PROP_NAME); 97 appId = (String ) 98 propMap.get(WebServiceInfoProvider.APP_ID_PROP_NAME); 99 bundleName = (String ) propMap.get( 100 WebServiceInfoProvider.BUNDLE_NAME_PROP_NAME); 101 webservices = (String ) propMap.get( 102 WebServiceInfoProvider.WS_XML_LOCATION_PROP_NAME); 103 bundleRoot = (String ) 104 propMap.get(WebServiceInfoProvider.BUNDLE_ROOT_LOCATION_PROP_NAME); 105 } 106 107 if ( (moduleType==null) || (appId==null) 109 || (webservices==null) || (bundleRoot==null) ) { 110 throw new IllegalArgumentException (); 111 } 112 113 return getWebServiceInfoInternal(moduleInfo, appId, 114 bundleName, webservices, bundleRoot, propMap); 115 } 116 117 135 private List getWebServiceInfoInternal(String moduleInfo, 136 String appId, String bundleName, String 137 webservices, String bundleRoot, Map propMap) 138 throws RepositoryException { 139 140 FileInputStream in = null; 142 try { 143 in = new FileInputStream (webservices); 144 } catch(FileNotFoundException fne) { 145 throw new RepositoryException(fne); 146 } 147 Webservices webServices = null; 148 webServices = Webservices.createGraph(in); 149 150 boolean isAppStandAloneModule = (bundleName==null) ? true : false; 152 153 WebserviceDescriptionType[] wsdts = 155 webServices.getWebserviceDescription(); 156 157 ArrayList aList = new ArrayList (); 158 String uri = null, implName = null, implType = null, implClass = null; 159 Map wsWebMap = null, wsEjbMap = null; 160 161 for (int wsCnt =0; wsCnt < wsdts.length; wsCnt++) { 163 WebserviceDescriptionType wsdt = wsdts[wsCnt]; 164 165 String wsdl = null; 166 String wsdlFile = null; 167 String mappingFileName = null; 168 String mapping = null; 169 if (wsdt != null) { 170 wsdl = bundleRoot + File.separator + wsdt.getWsdlFile(); 171 String mapFile = wsdt.getJaxrpcMappingFile(); 172 if (mapFile == null) { 173 mappingFileName = null; 174 } else { 175 mappingFileName = bundleRoot + File.separator + mapFile; 176 } 177 } 178 179 J2EEModule j2eeModule = new J2EEModule(); 180 try { 181 if (mappingFileName != null) { 182 mapping = j2eeModule.getStringForDDxml(mappingFileName); 183 } 184 } catch (Exception e ) { 185 } 187 188 try { 189 if(wsdl != null) { 190 wsdlFile = j2eeModule.getStringForDDxml(wsdl); 191 } 192 } catch (Exception e ) { 193 } 195 196 PortComponentType pts[] = wsdt.getPortComponent(); 198 for (int portCnt =0; portCnt < pts.length; portCnt++) { 199 PortComponentType pt = pts[portCnt]; 200 ServiceImplBeanType beanType = pt.getServiceImplBean(); 201 202 WebServiceDescrInfo wsDescrInfo = null; 203 implName = beanType.getServletLink(); 204 if ( implName != null) { 205 implType = "SERVLET"; 206 207 if (wsWebMap == null) { 209 wsWebMap = getWebServiceInfoForWebModule(moduleInfo, 210 appId, bundleName, webservices); 211 } 212 213 if (wsWebMap != null) { 215 wsDescrInfo = (WebServiceDescrInfo) wsWebMap.get( 216 (String )pt.getPortComponentName()); 217 } 218 } else { 219 implName = beanType.getEjbLink(); 220 if ( implName != null) { 221 implType = "EJB"; 222 223 if (wsEjbMap == null) { 225 wsEjbMap = getWebServiceInfoForEjbModule( 226 moduleInfo, appId, bundleName, webservices); 227 } 228 229 if ( wsEjbMap != null) { 231 wsDescrInfo = (WebServiceDescrInfo)wsEjbMap.get( 232 (String )pt.getPortComponentName()); 233 } 234 } else { 235 } 237 } 238 if (wsDescrInfo != null) { 239 uri = wsDescrInfo.getUri(); 240 implClass = wsDescrInfo.getImplClass(); 241 } 242 243 final String wsFile = (String ) propMap.get( 244 WebServiceInfoProvider.WS_XML_PROP_NAME); 245 246 WebServiceEndpointInfoImpl wsInfo = new 248 WebServiceEndpointInfoImpl(pt.getPortComponentName(), 249 uri, appId, bundleName, isAppStandAloneModule, 250 wsdlFile, mapping, wsFile,implType,implName, 251 implClass, wsDescrInfo.isSecure()); 252 253 wsInfo.putField( 254 WebServiceEndpointInfo.SUN_WEB_XML_KEY, (Serializable )propMap.get( 255 WebServiceInfoProvider.SUN_WEB_XML_PROP_NAME)); 256 257 wsInfo.putField( 258 WebServiceEndpointInfo.WEB_XML_KEY, (Serializable )propMap.get( 259 WebServiceInfoProvider.WEB_XML_PROP_NAME)); 260 261 wsInfo.putField( 262 WebServiceEndpointInfo.SUN_EJB_XML_KEY, (Serializable )propMap.get( 263 WebServiceInfoProvider.SUN_EJB_JAR_XML_PROP_NAME)); 264 265 wsInfo.putField( 266 WebServiceEndpointInfo.EJB_XML_KEY, (Serializable )propMap.get( 267 WebServiceInfoProvider.EJB_JAR_XML_PROP_NAME)); 268 269 wsInfo.putField( 270 WebServiceEndpointInfo.APPLICATION_XML_KEY, (Serializable )propMap.get( 271 WebServiceInfoProvider.APPLICATION_XML_PROP_NAME)); 272 273 wsInfo.putField( 274 WebServiceEndpointInfo.MAPPING_FILE_LOCATION_KEY, 275 (Serializable )mappingFileName); 276 277 wsInfo.putField( 278 WebServiceEndpointInfo.WSDL_FILE_LOCATION_KEY, 279 (Serializable )wsdl); 280 281 aList.add(wsInfo); 283 } 284 } 285 return aList; 286 } 287 288 298 private Map getWebServiceInfoForWebModule(String moduleInfo, 299 String appId, String bundleName, String webservices) 300 throws RepositoryException { 301 302 FileInputStream in = null; 304 try { 305 in = new FileInputStream (moduleInfo); 306 } catch(FileNotFoundException fne) { 307 throw new RepositoryException (fne); 308 } 309 SunWebApp sunWebApp = null; 310 try { 311 sunWebApp = SunWebApp.createGraph(in); 312 } catch (Schema2BeansException sce) { 313 throw new RepositoryException (sce); 314 } 315 316 boolean isAppStandAloneModule = (bundleName==null) ? true : false; 318 319 Servlet[] sLets = sunWebApp.getServlet(); 321 322 Map wsMap = new HashMap (); 323 for (int sCnt =0; sCnt < sLets.length; sCnt++) { 324 Servlet sLet = sLets[sCnt]; 325 326 WebserviceEndpoint[] webSvcEps = sLet.getWebserviceEndpoint(); 328 329 for ( int wsCnt = 0; wsCnt < webSvcEps.length; wsCnt++) { 330 WebserviceEndpoint webSvc = webSvcEps[wsCnt]; 331 332 String ctxRoot = sunWebApp.getContextRoot(); 334 String uriInConfig = getUriInDomainConfig(appId); 335 if (uriInConfig != null) { 336 ctxRoot = uriInConfig; 337 } 338 String uri; 339 String wsUri = webSvc.getEndpointAddressUri(); 340 if ((wsUri != null) && (wsUri.length() > 0) 341 && (wsUri.charAt(0) != '/')) { 342 wsUri = "/" + wsUri; 343 } 344 345 if (ctxRoot != null) { 347 uri = ctxRoot + wsUri; 348 } else { 349 uri = wsUri; 350 } 351 352 boolean isSec = false; 353 String trans = webSvc.getTransportGuarantee(); 354 if (( trans != null) && ("NONE".equals(trans) == false)) { 355 isSec = true; 356 } else if ((webSvc.getLoginConfig() != null) || 357 (webSvc.getMessageSecurityBinding() != null)) { 358 isSec = true; 359 } 360 WebServiceDescrInfo wsdInfo = 362 new WebServiceDescrInfo(webSvc.getPortComponentName(), 363 uri, webSvc.getServletImplClass(),isSec); 364 365 wsMap.put(wsdInfo.getName(),wsdInfo); 366 } 367 } 368 369 return wsMap; 370 } 371 372 380 private WebserviceDescriptionType getWSDT(String webservicesXML, 381 String pcName) { 382 383 FileInputStream fis = null; 384 try { 385 fis = new FileInputStream (new File (webservicesXML)); 386 Webservices ws = Webservices.createGraph(fis); 387 WebserviceDescriptionType[] wsdt = ws.getWebserviceDescription(); 388 for (int i=0; i<wsdt.length; i++) { 389 PortComponentType[] pct = wsdt[i].getPortComponent(); 390 for (int j=0; j<pct.length; j++) { 391 String name = pct[j].getPortComponentName(); 392 if (pcName.equals(name)) { 393 return wsdt[i]; 394 } 395 } 396 } 397 } catch (Exception e) { 398 } finally { 399 if (fis != null) { 400 try { 401 fis.close(); 402 } catch (Exception e) { } 403 } 404 } 405 return null; 406 } 407 408 409 419 private Map getWebServiceInfoForEjbModule(String moduleInfo,String appId, 420 String bundleName, String webservices) 421 throws RepositoryException { 422 423 FileInputStream in = null; 425 try { 426 in = new FileInputStream (moduleInfo); 427 } catch(FileNotFoundException fne) { 428 throw new RepositoryException (fne); 429 } 430 SunEjbJar sunEjbJar = null; 431 try { 432 sunEjbJar = SunEjbJar.createGraph(in); 433 } catch (Schema2BeansException sce) { 434 throw new RepositoryException (sce); 435 } 436 437 boolean isAppStandAloneModule = (bundleName==null) ? true : false; 439 440 EnterpriseBeans eBeans = sunEjbJar.getEnterpriseBeans(); 442 Ejb[] ejbs = eBeans.getEjb(); 443 HashMap wsMap = new HashMap (); 444 445 for (int ejbCnt =0; ejbCnt < ejbs.length; ejbCnt++) { 446 Ejb ejb = ejbs[ejbCnt]; 447 448 WebserviceEndpoint[] webSvcEps = ejb.getWebserviceEndpoint(); 450 451 for ( int wsCnt = 0; wsCnt < webSvcEps.length; wsCnt++) { 452 WebserviceEndpoint webSvc = webSvcEps[wsCnt]; 453 454 boolean isSec = false; 455 String trans = webSvc.getTransportGuarantee(); 456 if (( trans != null) && ("NONE".equals(trans) == false)) { 457 isSec = true; 458 } else if ((webSvc.getLoginConfig() != null) || 459 (webSvc.getMessageSecurityBinding() != null)) { 460 isSec = true; 461 } 462 WebServiceDescrInfo wsdInfo = new 464 WebServiceDescrInfo(webSvc.getPortComponentName(), 465 webSvc.getEndpointAddressUri(), 466 webSvc.getTieClass(), isSec); 467 468 wsMap.put(wsdInfo.getName(),wsdInfo); 469 } 470 } 471 472 return wsMap; 473 } 474 475 private String getUriInDomainConfig(String appId) { 476 ConfigContext configCtx = AdminService.getAdminService(). 477 getAdminContext().getAdminConfigContext(); 478 ConfigBean cb = null; 479 480 try { 481 cb = ApplicationHelper.findApplication(configCtx, appId); 482 } catch( Exception e) { 483 return null; 487 } 488 489 if (cb instanceof WebModule) { 490 return ((WebModule)cb).getContextRoot(); 491 } else { 492 return null; 493 } 494 495 } 496 497 500 class WebServiceDescrInfo { 501 502 WebServiceDescrInfo (String cName, String URI, String iClass, boolean 503 isSec) { 504 505 compName = cName; 506 uri = URI; 507 implClass = iClass; 508 isSecure = isSec; 509 } 510 511 String getName () { 512 return compName; 513 } 514 515 String getUri() { 516 return uri; 517 } 518 519 String getImplClass() { 520 return implClass; 521 } 522 523 boolean isSecure() { 524 return isSecure; 525 } 526 527 private String compName; 528 private String uri; 529 private String implClass; 530 private boolean isSecure; 531 } 532 533 534 public static final String PROVIDER_ID = 535 "com.sun.enterprise.tools.common.AppServWebServiceInfoProvider"; 536 } 537 | Popular Tags |