1 19 package org.netbeans.modules.websvc.core.jaxws.actions; 20 21 import java.io.IOException ; 22 import java.net.HttpURLConnection ; 23 import java.net.MalformedURLException ; 24 import java.net.URL ; 25 import java.net.URLConnection ; 26 import java.text.MessageFormat ; 27 import java.util.Map ; 28 import org.netbeans.api.project.FileOwnerQuery; 29 import org.netbeans.api.project.Project; 30 import org.netbeans.modules.j2ee.deployment.devmodules.api.Deployment; 31 import org.netbeans.modules.j2ee.deployment.devmodules.api.J2eePlatform; 32 import org.netbeans.modules.websvc.jaxws.api.JAXWSSupport; 33 import org.netbeans.modules.websvc.jaxws.api.JaxWsTesterCookie; 34 import org.openide.DialogDisplayer; 35 import org.openide.ErrorManager; 36 import org.openide.NotifyDescriptor; 37 import org.openide.awt.HtmlBrowser; 38 import org.openide.awt.StatusDisplayer; 39 import org.openide.filesystems.FileObject; 40 import org.openide.util.RequestProcessor; 41 import org.openide.util.actions.CookieAction; 42 import org.openide.util.HelpCtx; 43 import org.openide.util.NbBundle; 44 import org.openide.nodes.Node; 45 46 public class WsTesterPageAction extends CookieAction { 47 public String getName() { 48 return NbBundle.getMessage(WsTesterPageAction.class, "LBL_TesterPageAction"); 49 } 50 51 public HelpCtx getHelpCtx() { 52 return HelpCtx.DEFAULT_HELP; 53 } 54 55 protected int mode() { 56 return MODE_EXACTLY_ONE; 57 } 58 59 protected Class [] cookieClasses() { 60 return new Class [] {JaxWsTesterCookie.class}; 61 } 62 63 protected boolean asynchronous() { 64 return false; 65 } 66 67 protected void performAction(Node[] activatedNodes) { 68 JaxWsTesterCookie cookie = 69 activatedNodes[0].getCookie(JaxWsTesterCookie.class); 70 String wsdlURL = cookie.getTesterPageURL(); 71 try { 72 final URL url = new URL (wsdlURL); 73 if (url!=null) { 74 RequestProcessor.getDefault().post(new Runnable () { 75 public void run() { 76 boolean connectionOK=false; 77 try { 78 URLConnection connection = url.openConnection(); 79 if (connection instanceof HttpURLConnection ) { 80 HttpURLConnection httpConnection = (HttpURLConnection )connection; 81 try { 82 httpConnection.setRequestMethod("GET"); httpConnection.connect(); 84 if (HttpURLConnection.HTTP_OK == httpConnection.getResponseCode()) 85 connectionOK=true; 86 } catch (java.net.ConnectException ex) { 87 } finally { 89 if (httpConnection!=null) 90 httpConnection.disconnect(); 91 } 92 } 93 94 } catch (IOException ex) { 95 ErrorManager.getDefault().notify(ex); 96 } 97 if (connectionOK) { 98 HtmlBrowser.URLDisplayer.getDefault().showURL(url); 99 } else { 100 DialogDisplayer.getDefault().notify( 101 new NotifyDescriptor.Message( 102 NbBundle.getMessage(WsTesterPageAction.class,"MSG_UNABLE_TO_OPEN_TEST_PAGE",url), 103 NotifyDescriptor.WARNING_MESSAGE)); 104 } 105 } 106 107 }); 108 } 109 } catch (MalformedURLException ex) { 110 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(WsTesterPageAction.class, 111 "TXT_TesterPageUrl", wsdlURL)); } 113 } 114 115 protected boolean enable(Node[] activatedNodes) { 116 if (activatedNodes==null || activatedNodes.length==0) return false; 117 FileObject srcRoot = (FileObject)activatedNodes[0].getLookup().lookup(FileObject.class); 118 if (srcRoot!=null) { 119 Project project = FileOwnerQuery.getOwner(srcRoot); 120 if (project!=null) { 121 return isTesterPageSupported(project); 122 } 123 } 124 return false; 125 } 126 127 private boolean isTesterPageSupported(Project project) { 128 JAXWSSupport wss = JAXWSSupport.getJAXWSSupport(project.getProjectDirectory()); 129 if (wss != null) { 130 Map properties = wss.getAntProjectHelper().getStandardPropertyEvaluator().getProperties(); 131 String serverInstance = (String )properties.get("j2ee.server.instance"); if (serverInstance != null) { 133 J2eePlatform j2eePlatform = Deployment.getDefault().getJ2eePlatform(serverInstance); 134 if (j2eePlatform != null) { 135 return j2eePlatform.isToolSupported("jaxws-tester"); } 137 } 138 } 139 return false; 140 } 141 142 143 } 144 | Popular Tags |