1 19 20 package org.netbeans.modules.j2ee.clientproject.wsclient; 21 22 import static org.netbeans.modules.websvc.api.client.WebServicesClientConstants.*; 23 import java.io.IOException ; 24 import java.net.InetAddress ; 25 import java.net.URI ; 26 import java.net.URISyntaxException ; 27 import java.net.UnknownHostException ; 28 import java.util.ArrayList ; 29 import java.util.Arrays ; 30 import java.util.HashSet ; 31 import java.util.Iterator ; 32 import java.util.List ; 33 import java.util.Set ; 34 import org.netbeans.api.project.Project; 35 import org.netbeans.api.project.ProjectManager; 36 import org.netbeans.api.project.ui.OpenProjects; 37 import org.netbeans.modules.j2ee.clientproject.AppClientProject; 38 import org.netbeans.modules.j2ee.clientproject.AppClientProjectType; 39 import org.netbeans.modules.j2ee.clientproject.AppClientProvider; 40 import org.netbeans.modules.j2ee.clientproject.ui.customizer.AppClientProjectProperties; 41 import org.netbeans.modules.j2ee.dd.api.client.DDProvider; 42 import org.netbeans.modules.j2ee.dd.api.common.NameAlreadyUsedException; 43 import org.netbeans.modules.j2ee.dd.api.common.PortComponentRef; 44 import org.netbeans.modules.j2ee.dd.api.common.RootInterface; 45 import org.netbeans.modules.j2ee.dd.api.common.ServiceRef; 46 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eeModule; 47 import org.netbeans.modules.websvc.api.client.ClientStubDescriptor; 48 import org.netbeans.modules.websvc.api.client.WsCompileClientEditorSupport; 49 import org.netbeans.modules.websvc.spi.client.WebServicesClientSupportImpl; 50 import org.netbeans.spi.project.support.ant.AntProjectHelper; 51 import org.netbeans.spi.project.support.ant.EditableProperties; 52 import org.netbeans.spi.project.support.ant.PropertyUtils; 53 import org.netbeans.spi.project.support.ant.ReferenceHelper; 54 import org.openide.DialogDisplayer; 55 import org.openide.ErrorManager; 56 import org.openide.NotifyDescriptor; 57 import org.openide.filesystems.FileObject; 58 import org.openide.filesystems.FileUtil; 59 import org.openide.util.NbBundle; 60 import org.w3c.dom.Document ; 61 import org.w3c.dom.Element ; 62 import org.w3c.dom.Node ; 63 import org.w3c.dom.NodeList ; 64 65 70 public class AppClientProjectWebServicesClientSupport implements WebServicesClientSupportImpl{ 71 72 private final AppClientProject project; 73 private final AntProjectHelper helper; 74 private final ReferenceHelper referenceHelper; 75 private String proxyHost,proxyPort; 76 77 public static final String WSDL_FOLDER = "wsdl"; 79 80 public AppClientProjectWebServicesClientSupport(AppClientProject project, AntProjectHelper helper, ReferenceHelper referenceHelper) { 81 this.project = project; 82 this.helper = helper; 83 this.referenceHelper = referenceHelper; 84 } 85 86 public AntProjectHelper getAntProjectHelper() { 87 return helper; 88 } 89 90 public ReferenceHelper getReferenceHelper(){ 91 return referenceHelper; 92 } 93 94 public void addServiceClient(String serviceName, String packageName, String sourceUrl, FileObject configFile, ClientStubDescriptor stubDescriptor) { 96 this.addServiceClient(serviceName, packageName, sourceUrl, configFile, stubDescriptor, null); 97 } 98 99 public void addServiceClient(String serviceName, String packageName, String sourceUrl, FileObject configFile, ClientStubDescriptor stubDescriptor, String [] wscompileFeatures) { 101 boolean needsSave = false; 107 boolean modifiedProjectProperties = false; 108 boolean modifiedPrivateProperties = false; 109 110 113 Element data = helper.getPrimaryConfigurationData(true); 114 Document doc = data.getOwnerDocument(); 115 NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS); 116 Element clientElements = null; 117 118 if(nodes.getLength() == 0) { 119 clientElements = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENTS); 122 NodeList srcRoots = data.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, "source-roots"); assert srcRoots.getLength() == 1 : "Invalid project.xml."; data.insertBefore(clientElements, srcRoots.item(0)); 125 } else { 126 clientElements = (Element ) nodes.item(0); 127 } 128 129 131 boolean serviceAlreadyAdded = false; 132 NodeList clientNameList = clientElements.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 133 for(int i = 0; i < clientNameList.getLength(); i++ ) { 134 Element clientNameElement = (Element ) clientNameList.item(i); 135 NodeList nl = clientNameElement.getChildNodes(); 136 if(nl.getLength() >= 1) { 137 Node n = nl.item(0); 138 if(n.getNodeType() == Node.TEXT_NODE) { 139 if(serviceName.equalsIgnoreCase(n.getNodeValue())) { 140 serviceAlreadyAdded = true; 141 142 } 146 } 147 } 148 } 149 150 152 if(!serviceAlreadyAdded) { 153 Element clientElement = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT); 154 clientElements.appendChild(clientElement); 155 Element clientElementName = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 156 clientElement.appendChild(clientElementName); 157 clientElementName.appendChild(doc.createTextNode(serviceName)); 158 Element clientElementStubType = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_STUB_TYPE); 159 clientElement.appendChild(clientElementStubType); 160 clientElementStubType.appendChild(doc.createTextNode(stubDescriptor.getName())); 161 Element clientElementSourceUrl = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL); 162 clientElement.appendChild(clientElementSourceUrl); 163 clientElementSourceUrl.appendChild(doc.createTextNode(sourceUrl)); 164 helper.putPrimaryConfigurationData(data, true); 165 needsSave = true; 166 } 167 168 EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 169 EditableProperties privateProperties = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 170 { 172 String featurePropertyName = "wscompile.client." + serviceName + ".features"; String defaultFeatures = "wsi, strict"; if(stubDescriptor instanceof JAXRPCClientStubDescriptor) { 175 JAXRPCClientStubDescriptor stubDesc = (JAXRPCClientStubDescriptor) stubDescriptor; 176 if (wscompileFeatures!=null) stubDesc.setDefaultFeatures(wscompileFeatures); 177 defaultFeatures = stubDesc.getDefaultFeaturesAsArgument(); 178 } else { 179 } 181 String oldFeatures = projectProperties.getProperty(featurePropertyName); 182 if(!defaultFeatures.equals(oldFeatures)) { 183 projectProperties.put(featurePropertyName, defaultFeatures); 184 modifiedProjectProperties = true; 185 } 186 } 187 188 { 190 String packagePropertyName = "wscompile.client." + serviceName + ".package"; String oldPackageName = projectProperties.getProperty(packagePropertyName); 192 if(!packageName.equals(oldPackageName)) { 193 projectProperties.put(packagePropertyName, packageName); 194 modifiedProjectProperties = true; 195 } 196 } 197 198 if (proxyHost!=null && proxyHost.length()>0) { 201 boolean modif = addJVMProxyOptions(projectProperties,proxyHost,proxyPort); 202 if (modif) modifiedProjectProperties = true; 203 String proxyProperty = "wscompile.client." + serviceName + ".proxy"; String oldProxyProperty = privateProperties.getProperty(proxyProperty); 205 if(!proxyProperty.equals(oldProxyProperty)) { 206 privateProperties.put(proxyProperty, proxyHost+':'+(proxyPort==null?"8080":proxyPort)); modifiedPrivateProperties = true; 208 } 209 } 210 211 if(modifiedProjectProperties) { 212 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties); 213 needsSave = true; 214 } 215 if(modifiedPrivateProperties) { 216 helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, privateProperties); 217 needsSave = true; 218 } 219 220 if(updateWsCompileProperties(serviceName)) { 223 needsSave = true; 224 } 225 226 if(needsSave) { 229 try { 230 ProjectManager.getDefault().saveProject(project); 231 } catch(IOException ex) { 232 NotifyDescriptor desc = new NotifyDescriptor.Message( 233 NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientAdd", serviceName, ex.getMessage()), NotifyDescriptor.ERROR_MESSAGE); 235 DialogDisplayer.getDefault().notify(desc); 236 } 237 } 238 } 239 240 public void addInfrastructure(String implBeanClass, FileObject pkg) { 241 } 243 244 public FileObject getDeploymentDescriptor() { 245 FileObject webInfFo = project.getAPICar().getMetaInf(); 246 if (webInfFo==null) { 247 if (isProjectOpened()) { 248 DialogDisplayer.getDefault().notify( 249 new NotifyDescriptor.Message(NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_WebInfCorrupted"), NotifyDescriptor.ERROR_MESSAGE)); 251 } 252 return null; 253 } 254 return webInfFo.getFileObject(AppClientProvider.FILE_DD); 255 } 256 257 private FileObject getFileObject(String propname) { 258 String prop = helper.getStandardPropertyEvaluator().getProperty(propname); 259 if (prop != null) { 260 return helper.resolveFileObject(prop); 261 } else { 262 return null; 263 } 264 } 265 266 private boolean updateWsCompileProperties(String serviceName) { 267 279 boolean globalPropertiesChanged = false; 280 281 EditableProperties globalProperties = PropertyUtils.getGlobalProperties(); 282 if(globalProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) { 283 globalProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); 285 try { 286 PropertyUtils.putGlobalProperties(globalProperties); 287 } catch(IOException ex) { 288 NotifyDescriptor desc = new NotifyDescriptor.Message( 289 NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_ErrorSavingGlobalProperties", serviceName, ex.getMessage()), NotifyDescriptor.ERROR_MESSAGE); 291 DialogDisplayer.getDefault().notify(desc); 292 } 293 294 globalPropertiesChanged = true; 295 } 296 297 298 boolean projectPropertiesChanged = false; 299 EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 300 301 { Set <String > wscJars = new HashSet <String >(); 303 boolean newWscJars = false; 304 String wscClientClasspath = projectProperties.getProperty(WSCOMPILE_CLASSPATH); 305 if(wscClientClasspath != null) { 306 String [] libs = PropertyUtils.tokenizePath(wscClientClasspath); 307 for(int i = 0; i < libs.length; i++) { 308 wscJars.add(libs[i]); 309 } 310 } 311 312 for(int i = 0; i < WSCOMPILE_JARS.length; i++) { 313 if(!wscJars.contains(WSCOMPILE_JARS[i])) { 314 wscJars.add(WSCOMPILE_JARS[i]); 315 newWscJars = true; 316 } 317 } 318 319 if(newWscJars) { 320 StringBuffer newClasspathBuf = new StringBuffer (256); 321 for(Iterator iter = wscJars.iterator(); iter.hasNext(); ) { 322 newClasspathBuf.append(iter.next().toString()); 323 if(iter.hasNext()) { 324 newClasspathBuf.append(':'); 325 } 326 } 327 projectProperties.put(WSCOMPILE_CLASSPATH, newClasspathBuf.toString()); 328 projectPropertiesChanged = true; 329 } 330 } 331 332 if(projectProperties.getProperty(WSCOMPILE_TOOLS_CLASSPATH) == null) { 334 projectProperties.setProperty(WSCOMPILE_TOOLS_CLASSPATH, "${java.home}\\..\\lib\\tools.jar"); projectPropertiesChanged = true; 336 } 337 338 if(projectPropertiesChanged) { 339 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, projectProperties); 340 } 341 342 return globalPropertiesChanged || projectPropertiesChanged; 343 } 344 345 public void removeServiceClient(String serviceName) { 346 boolean needsSave = false; 350 boolean needsSave1 = false; 351 352 354 String featureProperty = "wscompile.client." + serviceName + ".features"; String packageProperty = "wscompile.client." + serviceName + ".package"; String proxyProperty = "wscompile.client." + serviceName + ".proxy"; 358 EditableProperties ep = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 359 EditableProperties ep1 = helper.getProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH); 360 361 if(ep.getProperty(featureProperty) != null) { 362 ep.remove(featureProperty); 363 needsSave = true; 364 } 365 366 if(ep.getProperty(packageProperty) != null) { 367 ep.remove(packageProperty); 368 needsSave = true; 369 } 370 371 if(ep1.getProperty(proxyProperty) != null) { 372 ep1.remove(proxyProperty); 373 needsSave1 = true; 374 } 375 376 if(needsSave) { 377 helper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH, ep); 378 } 379 380 if(needsSave1) { 381 helper.putProperties(AntProjectHelper.PRIVATE_PROPERTIES_PATH, ep1); 382 } 383 384 386 Element data = helper.getPrimaryConfigurationData(true); 387 NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS); 388 Element clientElements = null; 389 390 393 if(nodes.getLength() >= 1) { 394 clientElements = (Element ) nodes.item(0); 395 NodeList clientNameList = clientElements.getElementsByTagNameNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 396 for(int i = 0; i < clientNameList.getLength(); i++ ) { 397 Element clientNameElement = (Element ) clientNameList.item(i); 398 NodeList nl = clientNameElement.getChildNodes(); 399 if(nl.getLength() == 1) { 400 Node n = nl.item(0); 401 if(n.getNodeType() == Node.TEXT_NODE) { 402 if(serviceName.equalsIgnoreCase(n.getNodeValue())) { 403 Node serviceNode = clientNameElement.getParentNode(); 405 clientElements.removeChild(serviceNode); 406 helper.putPrimaryConfigurationData(data, true); 407 needsSave = true; 408 } 409 } 410 } 411 } 412 } 413 414 if(needsSave || needsSave1) { 417 try { 418 ProjectManager.getDefault().saveProject(project); 419 } catch(IOException ex) { 420 NotifyDescriptor desc = new NotifyDescriptor.Message( 421 NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientRemove", serviceName, ex.getMessage()), NotifyDescriptor.ERROR_MESSAGE); 423 DialogDisplayer.getDefault().notify(desc); 424 } 425 } 426 } 427 428 public FileObject getWsdlFolder(boolean create) throws IOException { 429 String metaInfStr = helper.getStandardPropertyEvaluator().getProperty(AppClientProjectProperties.META_INF); 430 String wsdlFolderStr = metaInfStr + '/' + WSDL_FOLDER; FileObject wsdlFolder = project.getProjectDirectory().getFileObject(wsdlFolderStr); 432 if (wsdlFolder == null && create) { 433 wsdlFolder = FileUtil.createFolder(project.getProjectDirectory(), wsdlFolderStr); 434 } 435 436 return wsdlFolder; 437 } 438 439 public List <ClientStubDescriptor> getStubDescriptors() { 440 ArrayList <ClientStubDescriptor> stubs = new ArrayList <ClientStubDescriptor>(2); 441 String version = project.getCarModule().getJ2eePlatformVersion(); 442 if(J2eeModule.J2EE_14.equals(version)) { 443 stubs.add(jsr109ClientStub); 444 } 445 stubs.add(jaxrpcClientStub); 446 return stubs; 447 } 448 449 private boolean isProjectOpened() { 450 Project[] projects = OpenProjects.getDefault().getOpenProjects(); 451 for (int i = 0; i < projects.length; i++) { 452 if (projects[i].equals(project)) 453 return true; 454 } 455 return false; 456 } 457 458 466 private static final String [] WSCOMPILE_CLIENT_FEATURES = { 467 "datahandleronly", "explicitcontext", "jaxbenumtype", "nodatabinding", "noencodedtypes", "nomultirefs", "norpcstructures", "novalidation", "resolveidref", "searchschema", "serializeinterfaces", "strict", "wsi", "unwrap", "donotoverride", "donotunwrap", }; 488 489 private static final List allClientFeatures = Arrays.asList(WSCOMPILE_CLIENT_FEATURES); 490 491 private static final String [] WSCOMPILE_KEY_CLIENT_FEATURES = { 492 "wsi", "strict", "norpcstructures", "unwrap", "donotunwrap", "donotoverride", "datahandleronly", "nodatabinding", "novalidation", "searchschema", }; 503 504 private static final List importantClientFeatures = Arrays.asList(WSCOMPILE_KEY_CLIENT_FEATURES); 505 506 public List <WsCompileClientEditorSupport.ServiceSettings> getServiceClients() { 507 List <WsCompileClientEditorSupport.ServiceSettings> serviceNames = new ArrayList <WsCompileClientEditorSupport.ServiceSettings>(); 508 509 Element data = helper.getPrimaryConfigurationData(true); 510 NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS); 511 EditableProperties projectProperties = helper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 512 513 if(nodes.getLength() != 0) { 514 Element clientElements = (Element ) nodes.item(0); 515 NodeList clientNameList = clientElements.getElementsByTagNameNS( 516 AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 517 for(int i = 0; i < clientNameList.getLength(); i++ ) { 518 Element clientNameElement = (Element ) clientNameList.item(i); 519 NodeList nl = clientNameElement.getChildNodes(); 520 if(nl.getLength() == 1) { 521 Node n = nl.item(0); 522 if(n.getNodeType() == Node.TEXT_NODE) { 523 String serviceName = n.getNodeValue(); 524 String currentFeatures = projectProperties.getProperty("wscompile.client." + serviceName + ".features"); 525 if(currentFeatures == null) { 526 currentFeatures = "wsi, strict"; } 535 boolean propVerbose = "true".equalsIgnoreCase( projectProperties.getProperty("wscompile.client." + serviceName + ".verbose")); boolean propDebug = "true".equalsIgnoreCase( projectProperties.getProperty("wscompile.client." + serviceName + ".debug")); boolean propPrintStackTrace = "true".equalsIgnoreCase( projectProperties.getProperty("wscompile.client." + serviceName + ".xPrintStackTrace")); boolean propExtensible = "true".equalsIgnoreCase( projectProperties.getProperty("wscompile.client." + serviceName + ".xSerializable")); boolean propOptimize = "true".equalsIgnoreCase( projectProperties.getProperty("wscompile.client." + serviceName + ".optimize")); boolean[] options = new boolean[] { propVerbose,propDebug,propPrintStackTrace,propExtensible,propOptimize 547 }; 548 ClientStubDescriptor stubType = getClientStubDescriptor(clientNameElement.getParentNode()); 549 WsCompileClientEditorSupport.ServiceSettings settings = new WsCompileClientEditorSupport.ServiceSettings( 550 serviceName, stubType, options, currentFeatures, allClientFeatures, importantClientFeatures); 551 serviceNames.add(settings); 552 } else { 553 } 555 } else { 556 } 558 } 559 } 560 561 return serviceNames; 562 } 563 564 private ClientStubDescriptor getClientStubDescriptor(Node parentNode) { 565 ClientStubDescriptor result = null; 566 567 if(parentNode instanceof Element ) { 568 Element parentElement = (Element ) parentNode; 569 NodeList clientNameList = parentElement.getElementsByTagNameNS( 570 AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_STUB_TYPE); 571 if(clientNameList.getLength() == 1) { 572 Element clientStubElement = (Element ) clientNameList.item(0); 573 NodeList nl = clientStubElement.getChildNodes(); 574 if(nl.getLength() == 1) { 575 Node n = nl.item(0); 576 if(n.getNodeType() == Node.TEXT_NODE) { 577 String stubName = n.getNodeValue(); 578 if(ClientStubDescriptor.JSR109_CLIENT_STUB.equals(stubName)) { 579 result = jsr109ClientStub; 580 } else if(ClientStubDescriptor.JAXRPC_CLIENT_STUB.equals(stubName)) { 581 result = jaxrpcClientStub; 582 } 583 } 584 } 585 } 586 } 587 588 return result; 589 } 590 591 public String getWsdlSource(String serviceName) { 592 Element data = helper.getPrimaryConfigurationData(true); 593 String wsdlSource = null; 594 595 Element clientElement = getWebServiceClientNode(data, serviceName); 596 if(clientElement != null) { 597 NodeList fromWsdlList = clientElement.getElementsByTagNameNS( 598 AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL); 599 if(fromWsdlList.getLength() == 1) { 600 Element fromWsdlElement = (Element ) fromWsdlList.item(0); 601 NodeList nl = fromWsdlElement.getChildNodes(); 602 if(nl.getLength() == 1) { 603 Node n = nl.item(0); 604 if(n.getNodeType() == Node.TEXT_NODE) { 605 wsdlSource = n.getNodeValue(); 606 } 607 } 608 } 609 } 610 611 return wsdlSource; 612 } 613 614 public void setWsdlSource(String serviceName, String wsdlSource) { 615 Element data = helper.getPrimaryConfigurationData(true); 616 Document doc = data.getOwnerDocument(); 617 boolean needsSave = false; 618 619 Element clientElement = getWebServiceClientNode(data, serviceName); 620 if(clientElement != null) { 621 NodeList fromWsdlList = clientElement.getElementsByTagNameNS( 622 AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL); 623 if(fromWsdlList.getLength() > 0) { 624 Element fromWsdlElement = (Element ) fromWsdlList.item(0); 625 NodeList nl = fromWsdlElement.getChildNodes(); 626 if(nl.getLength() > 0) { 627 Node n = nl.item(0); 628 n.setNodeValue(wsdlSource); 629 } else { 630 fromWsdlElement.appendChild(doc.createTextNode(wsdlSource)); 631 } 632 } else { 633 Element clientElementSourceUrl = doc.createElementNS(AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, CLIENT_SOURCE_URL); 634 clientElement.appendChild(clientElementSourceUrl); 635 clientElementSourceUrl.appendChild(doc.createTextNode(wsdlSource)); 636 } 637 638 needsSave = true; 639 } 640 641 if(needsSave) { 643 try { 644 ProjectManager.getDefault().saveProject(project); 645 } catch(IOException ex) { 646 NotifyDescriptor desc = new NotifyDescriptor.Message( 647 NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"MSG_ErrorSavingOnWSClientAdd", serviceName, ex.getMessage()), NotifyDescriptor.ERROR_MESSAGE); 649 DialogDisplayer.getDefault().notify(desc); 650 } 651 } 652 } 653 654 private Element getWebServiceClientNode(Element data, String serviceName) { 655 Element clientElement = null; 656 NodeList nodes = data.getElementsByTagName(WEB_SERVICE_CLIENTS); 657 658 if(nodes.getLength() != 0) { 659 Element clientElements = (Element ) nodes.item(0); 660 NodeList clientNameList = clientElements.getElementsByTagNameNS( 661 AppClientProjectType.PROJECT_CONFIGURATION_NAMESPACE, WEB_SERVICE_CLIENT_NAME); 662 for(int i = 0; i < clientNameList.getLength(); i++ ) { 663 Element clientNameElement = (Element ) clientNameList.item(i); 664 NodeList nl = clientNameElement.getChildNodes(); 665 if(nl.getLength() == 1) { 666 Node n = nl.item(0); 667 if(n.getNodeType() == Node.TEXT_NODE) { 668 String name = n.getNodeValue(); 669 if(serviceName.equals(name)) { 670 Node node = clientNameElement.getParentNode(); 671 clientElement = (node instanceof Element ) ? (Element ) node : null; 672 break; 673 } 674 } else { 675 } 677 } 678 } 679 } 680 681 return clientElement; 682 } 683 684 private static final JAXRPCClientStubDescriptor jsr109ClientStub = new JAXRPCClientStubDescriptor( 686 ClientStubDescriptor.JSR109_CLIENT_STUB, 687 NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"LBL_JSR109ClientStub"), 688 new String [] { "wsi", "strict" }); 690 private static final JAXRPCClientStubDescriptor jaxrpcClientStub = new JAXRPCClientStubDescriptor( 691 ClientStubDescriptor.JAXRPC_CLIENT_STUB, 692 NbBundle.getMessage(AppClientProjectWebServicesClientSupport.class,"LBL_JAXRPCStaticClientStub"), 693 new String [] { "wsi", "strict" }); 695 public void addServiceClientReference(String serviceName, String fqServiceName, String relativeWsdlPath, String relativeMappingPath, String [] portSEIInfo) { 696 697 FileObject ddFO = getDeploymentDescriptor(); 698 699 if (ddFO != null) { 701 702 try { 703 RootInterface rootDD = DDProvider.getDefault().getDDRoot(ddFO); 704 705 ServiceRef serviceRef = (ServiceRef) rootDD.findBeanByName("ServiceRef", "ServiceRefName", serviceName); if(serviceRef == null) { 707 serviceRef = (ServiceRef) rootDD.addBean("ServiceRef", new String [] { 709 "ServiceRefName", "ServiceInterface", "WsdlFile", "JaxrpcMappingFile" }, 714 new String [] { 715 serviceName, 717 fqServiceName, 719 relativeWsdlPath, 721 relativeMappingPath 723 }, 724 "ServiceRefName"); } else { 726 serviceRef.setServiceInterface(fqServiceName); 727 serviceRef.setWsdlFile(new URI (relativeWsdlPath)); 728 serviceRef.setJaxrpcMappingFile(relativeMappingPath); 729 } 730 731 PortComponentRef [] portRefArray = new PortComponentRef [portSEIInfo.length]; 732 for (int pi = 0; pi < portRefArray.length; pi++) { 733 portRefArray[pi] = (PortComponentRef) serviceRef.createBean("PortComponentRef"); portRefArray[pi].setServiceEndpointInterface(portSEIInfo[pi]); } 736 serviceRef.setPortComponentRef(portRefArray); 737 rootDD.write(ddFO); 738 739 } catch (IOException ex) { 740 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 742 } catch (NameAlreadyUsedException ex) { 743 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 745 } catch (URISyntaxException ex) { 746 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 748 } catch (ClassNotFoundException ex) { 749 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, ex); 751 } 752 753 } 754 755 } 756 757 759 private static class JAXRPCClientStubDescriptor extends ClientStubDescriptor { 760 761 private String [] defaultFeatures; 762 763 public JAXRPCClientStubDescriptor(String name, String displayName, String [] defaultFeatures) { 764 super(name, displayName); 765 766 this.defaultFeatures = defaultFeatures; 767 } 768 769 public String [] getDefaultFeatures() { 770 return defaultFeatures; 771 } 772 773 public String getDefaultFeaturesAsArgument() { 774 StringBuffer buf = new StringBuffer (defaultFeatures.length*32); 775 for(int i = 0; i < defaultFeatures.length; i++) { 776 if(i > 0) { 777 buf.append(','); } 779 780 buf.append(defaultFeatures[i]); 781 } 782 return buf.toString(); 783 } 784 785 void setDefaultFeatures(String [] defaultFeatures) { 786 this.defaultFeatures=defaultFeatures; 787 } 788 } 789 790 public void setProxyJVMOptions(String proxyHost, String proxyPort) { 791 this.proxyHost=proxyHost; 792 this.proxyPort=proxyPort; 793 } 794 795 private static final String PROXY_HOST_OPTION="-Dhttp.proxyHost"; private static final String PROXY_PORT_OPTION="-Dhttp.proxyPort"; private static final String NON_PROXY_HOSTS_OPTION="-Dhttp.nonProxyHosts"; 799 private boolean addJVMProxyOptions(EditableProperties prop, String proxyHost, String proxyPort) { 800 String jvmOptions = prop.getProperty(AppClientProjectProperties.RUN_JVM_ARGS); 801 boolean modif=false; 802 String localHosts = "localhost"; try { 804 localHosts = InetAddress.getLocalHost().getCanonicalHostName(); 805 } catch (UnknownHostException ex) {} 806 if (!"localhost".equals(localHosts)) localHosts='\"'+localHosts+"|localhost\""; if (jvmOptions==null || jvmOptions.length()==0) { 808 jvmOptions = PROXY_HOST_OPTION+'='+proxyHost+ 809 ' '+PROXY_PORT_OPTION+'='+proxyPort+ 810 ' '+NON_PROXY_HOSTS_OPTION+'='+localHosts; 811 modif=true; 812 } else { 813 if (jvmOptions.indexOf(PROXY_HOST_OPTION)<0) { 814 jvmOptions+=' '+PROXY_HOST_OPTION+'='+proxyHost; 815 modif=true; 816 } 817 if (jvmOptions.indexOf(PROXY_PORT_OPTION)<0) { 818 jvmOptions+=' '+PROXY_PORT_OPTION+'='+proxyPort; 819 modif=true; 820 } 821 if (jvmOptions.indexOf(NON_PROXY_HOSTS_OPTION)<0) { 822 jvmOptions+=' '+NON_PROXY_HOSTS_OPTION+'='+localHosts; 823 modif=true; 824 } 825 } 826 if (modif) prop.setProperty(AppClientProjectProperties.RUN_JVM_ARGS,jvmOptions); 827 return modif; 828 } 829 830 public String getServiceRefName(String serviceName) { 831 return null; 833 } 834 835 } 836 | Popular Tags |