Author: xcoulon
Date: 2012-02-10 05:24:46 -0500 (Fri, 10 Feb 2012)
New Revision: 38592
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/JaxrsEndpointModuleArtifact.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/JaxrsPathModuleArtifactAdapter.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/WSTesterClientDelegate.java
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/WSTesterLaunchableAdapterDelegate.java
Removed:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/JaxrsPathModuleArtifactAdapter.java
Modified:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/META-INF/MANIFEST.MF
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml
Log:
Open - Hook up WS Tester to the JAX-RS tooling
https://issues.jboss.org/browse/JBIDE-10609
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/META-INF/MANIFEST.MF
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/META-INF/MANIFEST.MF 2012-02-10 09:43:28
UTC (rev 38591)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/META-INF/MANIFEST.MF 2012-02-10 10:24:46
UTC (rev 38592)
@@ -34,7 +34,8 @@
org.eclipse.core.commands;bundle-version="3.6.0",
org.eclipse.ltk.core.refactoring;bundle-version="3.5.200",
org.eclipse.wst.validation;bundle-version="1.2.300",
- org.eclipse.wst.server.core
+ org.eclipse.wst.server.core,
+ org.eclipse.debug.core;bundle-version="3.7.0"
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-ClassPath: .
Modified: trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml
===================================================================
--- trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml 2012-02-10 09:43:28 UTC (rev
38591)
+++ trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/plugin.xml 2012-02-10 10:24:46 UTC (rev
38592)
@@ -320,7 +320,7 @@
<extension point="org.eclipse.wst.server.core.moduleArtifactAdapters">
<moduleArtifactAdapter
id="org.jboss.tools.ws.jaxrs.ui.jaxrsartifactadapter"
-
class="org.jboss.tools.ws.jaxrs.ui.internal.utils.JaxrsPathModuleArtifactAdapter">
+
class="org.jboss.tools.ws.jaxrs.ui.internal.launcher.JaxrsPathModuleArtifactAdapter">
<enablement>
<with variable="selection">
<adapt
type="org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateElement"/>
@@ -328,4 +328,20 @@
</enablement>
</moduleArtifactAdapter>
</extension>
+ <extension
+ point="org.eclipse.wst.server.core.clients">
+ <client
+
class="org.jboss.tools.ws.jaxrs.ui.internal.launcher.WSTesterClientDelegate"
+ id="org.jboss.tools.ws.jaxrs.ui.wsTesterClient">
+ </client>
+ </extension>
+ <extension
+ point="org.eclipse.wst.server.core.launchableAdapters">
+ <launchableAdapter
+
class="org.jboss.tools.ws.jaxrs.ui.internal.launcher.WSTesterLaunchableAdapterDelegate"
+ id="org.jboss.tools.ws.jaxrs.ui.wsTesterLaunchableAdapter"
+ priority="20"
+ typeIds="*">
+ </launchableAdapter>
+ </extension>
</plugin>
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/JaxrsEndpointModuleArtifact.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/JaxrsEndpointModuleArtifact.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/JaxrsEndpointModuleArtifact.java 2012-02-10
10:24:46 UTC (rev 38592)
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Xavier Coulon - Initial API and implementation
+ ******************************************************************************/
+
+package org.jboss.tools.ws.jaxrs.ui.internal.launcher;
+
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IModuleArtifact;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpoint;
+
+/**
+ * Module Artifact that carries the JAX-RS Endpoint deployed on a server.
+ *
+ * @author Xavier Coulon
+ *
+ */
+public class JaxrsEndpointModuleArtifact implements IModuleArtifact {
+
+ /** the module.*/
+ private final IModule module;
+
+ /** the JAX-RS Endpoint that should be called.*/
+ private final IJaxrsEndpoint endpoint;
+
+ /**
+ * Full constructor.
+ * @param module
+ * @param endpoint
+ */
+ public JaxrsEndpointModuleArtifact(final IModule module, final IJaxrsEndpoint endpoint)
{
+ this.module = module;
+ this.endpoint = endpoint;
+ }
+
+ @Override
+ public IModule getModule() {
+ return module;
+ }
+
+ public IJaxrsEndpoint getEndpoint() {
+ return endpoint;
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/JaxrsEndpointModuleArtifact.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Copied:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/JaxrsPathModuleArtifactAdapter.java
(from rev 38525,
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/JaxrsPathModuleArtifactAdapter.java)
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/JaxrsPathModuleArtifactAdapter.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/JaxrsPathModuleArtifactAdapter.java 2012-02-10
10:24:46 UTC (rev 38592)
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ ******************************************************************************/
+
+package org.jboss.tools.ws.jaxrs.ui.internal.launcher;
+
+import org.eclipse.core.resources.IProject;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IModuleArtifact;
+import org.eclipse.wst.server.core.ServerUtil;
+import org.eclipse.wst.server.core.model.ModuleArtifactAdapterDelegate;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpoint;
+import org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateElement;
+
+/**
+ * This class adapts {@link UriPathTemplateElement} into WebResources that Eclipse
Run|Debug On Server functionallity
+ * can handle.
+ *
+ * This allows you to use the Run As functionality on the JAX-RS node elements which
represent a path.
+ *
+ * @author max
+ * @author Xavier Coulon
+ *
+ */
+public class JaxrsPathModuleArtifactAdapter extends ModuleArtifactAdapterDelegate {
+
+ /**
+ * Returns a JaxrsEndpointModuleArtifact if the given obj is an UriPathTemplateElement,
null otherwise.
+ */
+ @Override
+ public IModuleArtifact getModuleArtifact(Object obj) {
+ if (obj instanceof UriPathTemplateElement) {
+ UriPathTemplateElement element = (UriPathTemplateElement) obj;
+ final IJaxrsEndpoint endpoint = element.getEndpoint();
+ if (endpoint != null) {
+ IProject project = endpoint.getJavaProject().getProject();
+ IModule module = ServerUtil.getModule(project);
+ return new JaxrsEndpointModuleArtifact(module, endpoint);
+ }
+ }
+
+ return null;
+ }
+
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/JaxrsPathModuleArtifactAdapter.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/WSTesterClientDelegate.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/WSTesterClientDelegate.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/WSTesterClientDelegate.java 2012-02-10
10:24:46 UTC (rev 38592)
@@ -0,0 +1,109 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.ui.internal.launcher;
+
+import java.lang.reflect.Method;
+
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.eclipse.debug.core.ILaunch;
+import org.eclipse.ui.IViewPart;
+import org.eclipse.ui.IWorkbench;
+import org.eclipse.ui.IWorkbenchPage;
+import org.eclipse.ui.IWorkbenchWindow;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.wst.server.core.IModule;
+import org.eclipse.wst.server.core.IServer;
+import org.eclipse.wst.server.core.ServerUtil;
+import org.eclipse.wst.server.core.model.ClientDelegate;
+import org.jboss.tools.ws.jaxrs.core.metamodel.IJaxrsEndpoint;
+import org.jboss.tools.ws.jaxrs.ui.JBossJaxrsUIPlugin;
+import org.jboss.tools.ws.jaxrs.ui.internal.utils.Logger;
+
+/**
+ * Custom client for the "Run as>Run as Server" launcher, that redirects the
call to the WSTester instead of the Web
+ * Browser.
+ *
+ * @author Xavier Coulon
+ *
+ */
+public class WSTesterClientDelegate extends ClientDelegate {
+
+ /**
+ * Returns true if the given launchable is a JaxrsEndpointModuleArtifact, false
otherwise
+ */
+ @Override
+ public boolean supports(IServer server, Object launchable, String launchMode) {
+ if (launchable instanceof JaxrsEndpointModuleArtifact) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
+ * Opens the WS Tester with the appropriate params.
+ */
+ public IStatus launch(IServer server, Object launchable, String launchMode, ILaunch
launch) {
+ if (launchable instanceof JaxrsEndpointModuleArtifact) {
+ JaxrsEndpointModuleArtifact artifact = (JaxrsEndpointModuleArtifact) launchable;
+ final IJaxrsEndpoint endpoint = artifact.getEndpoint();
+ final IModule module = artifact.getModule();
+ String endpointUri = computeEndpointURI(module, endpoint);
+ // Now we call the WS Tester through Reflection so there's no direct plug-in
dependency
+ IWorkbench wb = PlatformUI.getWorkbench();
+ IWorkbenchWindow win = wb.getActiveWorkbenchWindow();
+ IWorkbenchPage page = win.getActivePage();
+ String id = "org.jboss.tools.ws.ui.tester.views.TestWSView"; //$NON-NLS-1$
+ try {
+ IViewPart part = page.showView(id);
+ if (part != null
+ &&
part.getClass().getName().equalsIgnoreCase("org.jboss.tools.ws.ui.views.JAXRSWSTestView2"))
{ //$NON-NLS-1$
+ Class<?> c = part.getClass();
+ Class<?> parmtypes[] = new Class[2];
+ parmtypes[0] = String.class;
+ parmtypes[1] = String.class;
+ Method setURL = c.getDeclaredMethod("setJAXRS", parmtypes); //$NON-NLS-1$
+ if (setURL != null) {
+ Object arglist[] = new Object[2];
+ arglist[0] = endpointUri;
+ arglist[1] = endpoint.getHttpMethod().getHttpVerb();
+ setURL.invoke(part, arglist);
+ }
+ }
+ } catch (Exception e) {
+ Logger.error("Failed to open WS Tester", e);
+ return new Status(IStatus.ERROR, JBossJaxrsUIPlugin.PLUGIN_ID, "Failed to launch
WS Tester", e);
+ }
+ }
+ return Status.OK_STATUS;
+ }
+
+ /**
+ * Creates the endpoint URI from the endpoint, by looking at the servers on which the
module is deployed.
+ *
+ * @param element
+ * @return
+ */
+ private String computeEndpointURI(final IModule module, final IJaxrsEndpoint endpoint)
{
+ String uriPathTemplate = endpoint.getUriPathTemplate();
+ IPath path = new Path(module.getName()).append(uriPathTemplate);
+ // check to see if this project has been deployed...
+ IServer[] servers = ServerUtil.getServersByModule(module, null);
+ if (servers == null || servers.length == 0) {
+ return "http://[domain]:[port]/" + path.toPortableString(); //$NON-NLS-1$
+ }
+ // if it's been deployed, we can grab the domain and web port
+ String domain = servers[0].getHost();
+ String webport =
servers[0].getAttribute("org.jboss.ide.eclipse.as.core.server.webPort",
"8080");//$NON-NLS-1$ //$NON-NLS-2$
+ return "http://" + domain + ':' + webport + "/" +
path.toPortableString(); //$NON-NLS-1$
+
+ }
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/WSTesterClientDelegate.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Added:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/WSTesterLaunchableAdapterDelegate.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/WSTesterLaunchableAdapterDelegate.java
(rev 0)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/WSTesterLaunchableAdapterDelegate.java 2012-02-10
10:24:46 UTC (rev 38592)
@@ -0,0 +1,30 @@
+/*******************************************************************************
+ * Copyright (c) 2008 Red Hat, Inc.
+ * Distributed under license by Red Hat, Inc. All rights reserved.
+ * This program is made available under the terms of the
+ * Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at
http://www.eclipse.org/legal/epl-v10.html
+ *
+ ******************************************************************************/
+package org.jboss.tools.ws.jaxrs.ui.internal.launcher;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.wst.server.core.IModuleArtifact;
+import org.eclipse.wst.server.core.IServer;
+
+public class WSTesterLaunchableAdapterDelegate extends
org.eclipse.wst.server.core.model.LaunchableAdapterDelegate {
+
+ public WSTesterLaunchableAdapterDelegate() {
+ }
+
+ /**
+ * Returns the given moduleArtifact if it is an JaxrsEndpointModuleArtifact, null
otherwise.
+ */
+ @Override
+ public Object getLaunchable(IServer server, IModuleArtifact moduleArtifact) throws
CoreException {
+ if (moduleArtifact instanceof JaxrsEndpointModuleArtifact) {
+ return moduleArtifact;
+ }
+ return null;
+ }
+}
Property changes on:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/launcher/WSTesterLaunchableAdapterDelegate.java
___________________________________________________________________
Added: svn:mime-type
+ text/plain
Deleted:
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/JaxrsPathModuleArtifactAdapter.java
===================================================================
---
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/JaxrsPathModuleArtifactAdapter.java 2012-02-10
09:43:28 UTC (rev 38591)
+++
trunk/ws/plugins/org.jboss.tools.ws.jaxrs.ui/src/org/jboss/tools/ws/jaxrs/ui/internal/utils/JaxrsPathModuleArtifactAdapter.java 2012-02-10
10:24:46 UTC (rev 38592)
@@ -1,49 +0,0 @@
-package org.jboss.tools.ws.jaxrs.ui.internal.utils;
-
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.runtime.Path;
-import org.eclipse.wst.server.core.IModule;
-import org.eclipse.wst.server.core.IModuleArtifact;
-import org.eclipse.wst.server.core.ServerUtil;
-import org.eclipse.wst.server.core.model.ModuleArtifactAdapterDelegate;
-import org.eclipse.wst.server.core.util.WebResource;
-import org.jboss.tools.ws.jaxrs.ui.cnf.UriPathTemplateElement;
-
-/**
- * This class adapts {@link UriPathTemplateElement} into WebResources that Eclipse
Run|Debug On Server functionallity can handle.
- *
- * This allows you to use the Run As functionality on the JAX-RS node elements which
represent a path.
- *
- * @TODO currently only shows up for paths without "{" in them.
- * @author max
- *
- */
-public class JaxrsPathModuleArtifactAdapter extends ModuleArtifactAdapterDelegate {
-
- @Override
- public IModuleArtifact getModuleArtifact(Object obj) {
- if (obj instanceof UriPathTemplateElement) {
- UriPathTemplateElement element = (UriPathTemplateElement) obj;
-
- //TODO: NPE check this
- IProject project = element.getEndpoint().getJavaProject().getProject();
-
- IModule module = ServerUtil.getModule(project);
-
- if(plainUrl(element)) {
- Path path = new Path(element.getEndpoint().getUriPathTemplate());
- //TODO: need to take possible @Application context path into consideration!
- return new WebResource(module, path); //$NON-NLS-1$
- }
- }
-
- return null;
- }
-
- // @return true when the path is directly viewable in a browser and its a GET request.
- private boolean plainUrl(UriPathTemplateElement element) {
- //TODO: NPE check this
- return
element.getEndpoint().getHttpMethod().getHttpVerb().equalsIgnoreCase("GET")
&& !element.getEndpoint().getUriPathTemplate().contains("{");
- }
-
-}