1 19 20 package org.netbeans.modules.java.j2seproject.jaxws; 21 22 import java.io.IOException ; 23 import java.net.InetAddress ; 24 import java.net.UnknownHostException ; 25 import org.netbeans.api.java.classpath.ClassPath; 26 import org.netbeans.api.project.ProjectManager; 27 import org.netbeans.api.project.libraries.Library; 28 import org.netbeans.api.project.libraries.LibraryManager; 29 import org.netbeans.modules.java.j2seproject.J2SEProject; 30 import org.netbeans.modules.java.j2seproject.SourceRoots; 31 import org.netbeans.modules.java.j2seproject.UpdateHelper; 32 import org.netbeans.modules.java.j2seproject.ui.customizer.J2SEProjectProperties; 33 import org.netbeans.modules.websvc.spi.jaxws.client.ProjectJAXWSClientSupport; 34 import org.netbeans.spi.java.classpath.support.ClassPathSupport; 35 import org.netbeans.spi.java.project.classpath.ProjectClassPathExtender; 36 import org.netbeans.spi.project.support.ant.AntProjectHelper; 37 import org.netbeans.spi.project.support.ant.EditableProperties; 38 import org.openide.DialogDisplayer; 39 import org.openide.ErrorManager; 40 import org.openide.NotifyDescriptor; 41 import org.openide.filesystems.FileObject; 42 import org.openide.filesystems.FileUtil; 43 import org.openide.util.NbBundle; 44 45 49 public class J2SEProjectJAXWSClientSupport extends ProjectJAXWSClientSupport { 50 private J2SEProject project; 51 private UpdateHelper updateHelper; 52 private static final String WSDL_FOLDER = "wsdl"; 54 private static final String KEY_PROXY_HOST = "http.proxyHost"; 56 private static final String KEY_PROXY_PORT = "http.proxyPort"; 58 private static final String KEY_NON_PROXY_HOSTS = "http.nonProxyHosts"; 60 private static final String KEY_HTTPS_PROXY_HOST = "https.proxyHost"; 62 private static final String KEY_HTTPS_PROXY_PORT = "https.proxyPort"; 64 private static final String KEY_HTTPS_NON_PROXY_HOSTS = "https.nonProxyHosts"; 66 private static final String HTTP_PROXY_HOST_OPTION="-Dhttp.proxyHost"; private static final String HTTP_PROXY_PORT_OPTION="-Dhttp.proxyPort"; private static final String HTTP_NON_PROXY_HOSTS_OPTION="-Dhttp.nonProxyHosts"; private static final String HTTPS_PROXY_HOST_OPTION="-Dhttps.proxyHost"; private static final String HTTPS_PROXY_PORT_OPTION="-Dhttps.proxyPort"; private static final String HTTPS_NON_PROXY_HOSTS_OPTION="-Dhttps.nonProxyHosts"; 73 74 public J2SEProjectJAXWSClientSupport(J2SEProject project, UpdateHelper updateHelper) { 75 super(project); 76 this.project=project; 77 this.updateHelper=updateHelper; 78 } 79 80 public FileObject getWsdlFolder(boolean create) throws IOException { 81 EditableProperties ep = updateHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 82 String metaInfStr = ep.getProperty("meta.inf.dir"); String wsdlFolderStr = metaInfStr + "/" + WSDL_FOLDER; FileObject wsdlFolder = project.getProjectDirectory().getFileObject(wsdlFolderStr); 85 if (wsdlFolder == null && create) { 86 wsdlFolder = FileUtil.createFolder(project.getProjectDirectory(), wsdlFolderStr); 87 } 88 return wsdlFolder; 89 } 90 91 public String addServiceClient(String clientName, String wsdlUrl, String packageName, boolean isJsr109) { 92 93 96 FileObject fo = project.findJaxWsFileObject(); 98 if (fo==null) { 99 try { 100 project.createJaxWsFileObject(); 101 } catch (IOException ex) { 102 ErrorManager.getDefault().notify(ex); 103 } 104 } 105 106 String serviceIdeName = super.addServiceClient(clientName, wsdlUrl, packageName, false); 108 109 if (serviceIdeName!=null) addJVMProxyOptions(clientName); 111 112 return serviceIdeName; 113 } 114 115 protected void addJaxWs20Library() { 116 ClassPath classPath = null; 117 SourceRoots srcRoots = project.getSourceRoots(); 118 if (srcRoots!=null && srcRoots.getRoots().length>0) { 119 FileObject srcRoot = srcRoots.getRoots()[0]; 120 ClassPath compileClassPath = ClassPath.getClassPath(srcRoot,ClassPath.COMPILE); 121 ClassPath bootClassPath = ClassPath.getClassPath(srcRoot,ClassPath.BOOT); 122 classPath = ClassPathSupport.createProxyClassPath(new ClassPath[]{compileClassPath, bootClassPath}); 123 } 124 FileObject webServiceClass=null; 125 if (classPath!=null) { 126 webServiceClass = classPath.findResource("javax/jws/WebService.class"); } 128 if (webServiceClass==null) { 129 ProjectClassPathExtender pce = (ProjectClassPathExtender)project.getLookup().lookup(ProjectClassPathExtender.class); 131 Library jaxwslib = LibraryManager.getDefault().getLibrary("jaxws20"); if ((pce!=null) && (jaxwslib != null)) { 133 try { 134 pce.addLibrary(jaxwslib); 135 } catch (IOException ex) { 136 ErrorManager.getDefault().log(ex.getMessage()); 137 } 138 FileObject wscompileFO=null; 139 if (classPath!=null) { 140 wscompileFO = classPath.findResource("com/sun/xml/rpc/tools/ant/Wscompile.class"); } 142 if (wscompileFO!=null) { 143 NotifyDescriptor desc = new NotifyDescriptor.Message( 144 NbBundle.getMessage(J2SEProjectJAXWSClientSupport.class,"MSG_RemoveJAX-RPC"), NotifyDescriptor.WARNING_MESSAGE); 146 DialogDisplayer.getDefault().notify(desc); 147 } 148 } 149 } 150 } 151 152 private void addJVMProxyOptions(final String clientName) { 153 final String proxyHost = System.getProperty(KEY_PROXY_HOST); 154 if (proxyHost!=null && proxyHost.length()>0) { 155 ProjectManager.mutex().writeAccess ( new Runnable () { 156 public void run() { 157 boolean modif=false; 158 String proxyPort = System.getProperty(KEY_PROXY_PORT); 159 if (proxyPort==null || proxyPort.length()==0) proxyPort="8080"; String localHosts =""; 161 localHosts = getDefaultNonProxyHosts(); 162 163 EditableProperties ep = updateHelper.getProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH); 164 String jvmOptions = ep.getProperty(J2SEProjectProperties.RUN_JVM_ARGS); 165 if (jvmOptions==null || jvmOptions.length()==0) { 166 jvmOptions = HTTP_PROXY_HOST_OPTION+"="+proxyHost+ " "+HTTP_PROXY_PORT_OPTION+"="+proxyPort+ " "+HTTP_NON_PROXY_HOSTS_OPTION+"="+localHosts+ " "+HTTPS_PROXY_HOST_OPTION+"="+proxyHost+ " "+HTTPS_PROXY_PORT_OPTION+"="+proxyPort+ " "+HTTPS_NON_PROXY_HOSTS_OPTION+"="+localHosts; modif=true; 173 } else { 174 if (jvmOptions.indexOf(HTTP_PROXY_HOST_OPTION)<0) { 175 jvmOptions+=" "+HTTP_PROXY_HOST_OPTION+"="+proxyHost; modif=true; 177 } 178 if (jvmOptions.indexOf(HTTP_PROXY_PORT_OPTION)<0) { 179 jvmOptions+=" "+HTTP_PROXY_PORT_OPTION+"="+proxyPort; modif=true; 181 } 182 if (jvmOptions.indexOf(HTTP_NON_PROXY_HOSTS_OPTION)<0) { 183 jvmOptions+=" "+HTTP_NON_PROXY_HOSTS_OPTION+"="+localHosts; modif=true; 185 } 186 if (jvmOptions.indexOf(HTTPS_PROXY_HOST_OPTION)<0) { 187 jvmOptions+=" "+HTTPS_PROXY_HOST_OPTION+"="+proxyHost; modif=true; 189 } 190 if (jvmOptions.indexOf(HTTPS_PROXY_PORT_OPTION)<0) { 191 jvmOptions+=" "+HTTPS_PROXY_PORT_OPTION+"="+proxyPort; modif=true; 193 } 194 if (jvmOptions.indexOf(HTTPS_NON_PROXY_HOSTS_OPTION)<0) { 195 jvmOptions+=" "+HTTPS_NON_PROXY_HOSTS_OPTION+"="+localHosts; modif=true; 197 } 198 } 199 if (modif) { 200 ep.setProperty(J2SEProjectProperties.RUN_JVM_ARGS,jvmOptions); 201 updateHelper.putProperties(AntProjectHelper.PROJECT_PROPERTIES_PATH,ep); 202 try { 203 ProjectManager.getDefault().saveProject(project); 204 } catch(IOException ex) { 205 NotifyDescriptor desc = new NotifyDescriptor.Message( 206 NbBundle.getMessage(J2SEProjectJAXWSClientSupport.class,"MSG_ErrorSavingOnWSClientAdd", clientName, ex.getLocalizedMessage()), NotifyDescriptor.ERROR_MESSAGE); 208 DialogDisplayer.getDefault().notify(desc); 209 } 210 } 211 } 212 }); 213 214 } 215 } 216 217 221 private String getDefaultNonProxyHosts() { 222 String nonProxy = "localhost|127.0.0.1"; String localhost = ""; try { 225 localhost = InetAddress.getLocalHost().getHostName(); 226 if (!localhost.equals("localhost")) { nonProxy = nonProxy + "|" + localhost; } else { 229 } 232 } catch (UnknownHostException e) { 233 } 238 try { 239 String localhost2 = InetAddress.getLocalHost().getCanonicalHostName(); 240 if (!localhost2.equals("localhost") && !localhost2.equals(localhost)) { nonProxy = nonProxy + "|" + localhost2; } else { 243 } 246 } catch (UnknownHostException e) { 247 } 252 return nonProxy; 253 } 254 255 256 } 257 | Popular Tags |