diff options
author | kchan | 2007-06-11 23:57:15 +0000 |
---|---|---|
committer | kchan | 2007-06-11 23:57:15 +0000 |
commit | 2da8732de87fdebe813441866f020ebf7cdf8220 (patch) | |
tree | be53898847a150f5dbc77418f64be5577201f819 /axis2/bundles/org.eclipse.jst.ws.axis2.core | |
parent | ca3f070d24c293f3f820f46bf97128df0859de04 (diff) | |
download | webtools.webservices-2da8732de87fdebe813441866f020ebf7cdf8220.tar.gz webtools.webservices-2da8732de87fdebe813441866f020ebf7cdf8220.tar.xz webtools.webservices-2da8732de87fdebe813441866f020ebf7cdf8220.zip |
[177421] Merge web.xml when adding Axis2 facet instead of overwritting.
Diffstat (limited to 'axis2/bundles/org.eclipse.jst.ws.axis2.core')
4 files changed, 306 insertions, 23 deletions
diff --git a/axis2/bundles/org.eclipse.jst.ws.axis2.core/plugin.xml b/axis2/bundles/org.eclipse.jst.ws.axis2.core/plugin.xml index 4c3d1434f..69a6d641b 100644 --- a/axis2/bundles/org.eclipse.jst.ws.axis2.core/plugin.xml +++ b/axis2/bundles/org.eclipse.jst.ws.axis2.core/plugin.xml @@ -15,7 +15,7 @@ <project-facet-version facet="axis2.core" version="1.1"> <constraint> - <requires facet="jst.web" version="2.2,2.3,2.4"/> + <requires facet="jst.web" version="2.2,2.3,2.4,2.5"/> </constraint> <action type="INSTALL"> <delegate class="org.eclipse.jst.ws.axis2.facet.deligate.Axis2CoreFacetInstallDelegate"/> diff --git a/axis2/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/core/utils/FacetContainerUtils.java b/axis2/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/core/utils/FacetContainerUtils.java index a013c6a57..971bd4417 100644 --- a/axis2/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/core/utils/FacetContainerUtils.java +++ b/axis2/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/core/utils/FacetContainerUtils.java @@ -13,14 +13,17 @@ * facet to the framework for 168766 * 20070426 183046 sandakith@wso2.com - Lahiru Sandakith * 20070510 172926 sandakith@wso2.com - Lahiru Sandakith, Fix 172926 Use Util Classes + * 20070606 177421 sandakith@wso2.com - fix web.xml wiped out when Axis2 facet *******************************************************************************/ package org.eclipse.jst.ws.axis2.core.utils; import java.io.File; import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.IPath; +import org.eclipse.jst.ws.axis2.core.plugin.WebServiceAxis2CorePlugin; import org.eclipse.jst.ws.axis2.core.plugin.messages.Axis2CoreUIMessages; -import org.eclipse.jst.ws.axis2.core.utils.Axis2CoreUtils; +import org.eclipse.jst.ws.axis2.facet.messages.Axis2FacetUIMessages; import org.eclipse.jst.ws.internal.common.J2EEUtils; public class FacetContainerUtils { @@ -43,26 +46,47 @@ public class FacetContainerUtils { return webContainerDirString; } + public static String pathToWebProjectContainerWEBINF(String project) { + IPath workspaceDirectory = ResourcesPlugin.getWorkspace().getRoot().getLocation(); + String projectString = replaceEscapecharactors(project.toString()); + IPath webContainerWEBINF = J2EEUtils.getWebInfPath( + ResourcesPlugin.getWorkspace().getRoot().getProject( + getProjectNameFromFramewokNameString(projectString))); + return workspaceDirectory.append(webContainerWEBINF).toOSString(); + } + + public static String pathToWebProjectContainerMETAINF(String project) { + String containerDirectory = pathToWebProjectContainer(project); + String webContainerMETAINF = Axis2FacetUIMessages.DIR_META_INF; + String webContainerMETAINFString = Axis2CoreUtils.addAnotherNodeToPath( + containerDirectory, + webContainerMETAINF); + return webContainerMETAINFString; + } + + public static String pathToWebProjectContainerAxis2Web(String project) { + String containerDirectory = pathToWebProjectContainer(project); + String webContainerAxis2Web = Axis2FacetUIMessages.DIR_AXIS2_WEB; + String webContainerAxis2WebString = Axis2CoreUtils.addAnotherNodeToPath( + containerDirectory, + webContainerAxis2Web); + return webContainerAxis2WebString; + } public static String pathToWebProjectContainerLib(String project){ - - String workspaceDirectory = ResourcesPlugin.getWorkspace().getRoot() - .getLocation().toOSString(); - - String webContainerWEBINF = J2EEUtils.getWebInfPath( - ResourcesPlugin.getWorkspace().getRoot().getProject( - getProjectNameFromFramewokNameString(project))).toOSString(); - - String webContainerWEBINFString = Axis2CoreUtils.addAnotherNodeToPath( - workspaceDirectory, - webContainerWEBINF); + String webContainerWEBINFString = pathToWebProjectContainerWEBINF(project); return Axis2CoreUtils.addAnotherNodeToPath( webContainerWEBINFString, Axis2CoreUIMessages.DIR_LIB); } - + public static String pathToWebProjectContainerWebXML(String project){ + String webContainerWEBINFString = pathToWebProjectContainerWEBINF(project); + return Axis2CoreUtils.addAnotherNodeToPath( + webContainerWEBINFString, + "web.xml"); + } //Fix for the windows build not working private static String replaceEscapecharactors(String vulnarableString){ @@ -79,7 +103,6 @@ public class FacetContainerUtils { }else{ return frameworkProjectString.split(getSplitCharactors())[1]; } - } @@ -92,6 +115,16 @@ public class FacetContainerUtils { } } + public static String pathToAxis2CoreFacetTempDirectory(String project){ + // + String pluginAxis2CoreTempDir = WebServiceAxis2CorePlugin + .getInstance().getStateLocation().toOSString(); + String projectString = replaceEscapecharactors(project); + return FileUtils.addAnotherNodeToPath(pluginAxis2CoreTempDir, projectString); + + + } + private static String getSplitCharactors(){ //Windows check (because from inside wtp in return I received a hard coded path) if (File.separatorChar == '\\'){ @@ -111,4 +144,6 @@ public class FacetContainerUtils { return FileUtils.addNodesToURL(Axis2CoreUIMessages.LOCAL_SERVER_PORT, deployedWSDLURLParts)+"?wsdl"; } + + } diff --git a/axis2/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/facet/commands/Axis2WebservicesServerCommand.java b/axis2/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/facet/commands/Axis2WebservicesServerCommand.java index 481e42887..83f5fe15e 100644 --- a/axis2/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/facet/commands/Axis2WebservicesServerCommand.java +++ b/axis2/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/facet/commands/Axis2WebservicesServerCommand.java @@ -14,6 +14,7 @@ * 20070426 183046 sandakith@wso2.com - Lahiru Sandakith * 20070501 180284 sandakith@wso2.com - Lahiru Sandakith * 20070523 174876 sandakith@wso2.com - Lahiru Sandakith, Persist Preferences inside Framework + * 20070606 177421 sandakith@wso2.com - fix web.xml wiped out when Axis2 facet *******************************************************************************/ package org.eclipse.jst.ws.axis2.facet.commands; @@ -22,6 +23,7 @@ import java.io.FileNotFoundException; import java.io.IOException; import org.eclipse.core.commands.ExecutionException; +import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.IAdaptable; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.IStatus; @@ -41,10 +43,10 @@ import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; public class Axis2WebservicesServerCommand extends AbstractDataModelOperation { - String project; + IProject project; Axis2EmitterContext context; - public Axis2WebservicesServerCommand(String project){ + public Axis2WebservicesServerCommand(IProject project){ context = WebServiceAxis2CorePlugin.getDefault().getAxisEmitterContext(); this.project = project; } @@ -54,8 +56,8 @@ AbstractDataModelOperation { return Status.OK_STATUS; } - public IStatus exexuteOverrride(IProgressMonitor monitor) { - //Copy the axis2 libs in to this client project + public IStatus executeOverride(IProgressMonitor monitor) { + //Copy the axis2 facet in to this project IStatus status =null; String runtimeLocation = null; ContentCopyUtils contentCopyUtils = new ContentCopyUtils(); @@ -78,17 +80,26 @@ AbstractDataModelOperation { } catch (Exception e) { return handleExceptionStatus(e); } + status = contentCopyUtils.copyDirectoryRecursivelyIntoWorkspace( runtimeLocation, - FacetContainerUtils.pathToWebProjectContainer(project), + FacetContainerUtils.pathToWebProjectContainer(project.toString()), monitor ); - status = Status.OK_STATUS; - //clean up tempory files + + + //Merge web.xml Files + MergeWEBXMLCommand mergeWebXMLCommand = new MergeWEBXMLCommand(); + mergeWebXMLCommand.setExtraAxis2TagsAdded(false); + mergeWebXMLCommand.setServerProject(project); + mergeWebXMLCommand.exexuteOverride(monitor); + + //clean up tempery files File tempFacetDirectory = new File(runtimeLocation); if (tempFacetDirectory.exists() && context.isAxis2ServerPathRepresentsWar()) { FileUtils.deleteDir(tempFacetDirectory); } + status = Status.OK_STATUS; return status; } @@ -101,7 +112,7 @@ AbstractDataModelOperation { private IStatus handleExceptionStatus(Exception e){ IStatus status = null; - status = new Status(1,project,1,Axis2CoreUIMessages.ERROR_SERVER_IS_NOT_SET,e); + status = new Status(1,project.toString(),1,Axis2CoreUIMessages.ERROR_SERVER_IS_NOT_SET,e); cleanupIfFacetStatusFailed(Axis2CoreUtils.tempAxis2Directory()); return status; } diff --git a/axis2/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/facet/commands/MergeWEBXMLCommand.java b/axis2/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/facet/commands/MergeWEBXMLCommand.java new file mode 100644 index 000000000..d7efd9ecd --- /dev/null +++ b/axis2/bundles/org.eclipse.jst.ws.axis2.core/src/org/eclipse/jst/ws/axis2/facet/commands/MergeWEBXMLCommand.java @@ -0,0 +1,237 @@ +/******************************************************************************* + * Copyright (c) 2003, 2006 WSO2 Inc, IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are 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: + * IBM Corporation - initial API and implementation + * WSO2 Inc. - modified and fix web.xml wiped out when Axis2 facet + * yyyymmdd bug Email and other contact information + * -------- -------- ----------------------------------------------------------- + * 20060515 115225 sengpl@ca.ibm.com - Seng Phung-Lu + * 20070606 177421 sandakith@wso2.com - fix web.xml wiped out when Axis2 facet + *******************************************************************************/ +package org.eclipse.jst.ws.axis2.facet.commands; + + +import java.util.List; +import java.util.Map; +import java.util.Properties; + +import org.eclipse.core.resources.IProject; +import org.eclipse.core.runtime.IAdaptable; +import org.eclipse.core.runtime.IProgressMonitor; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.Status; +import org.eclipse.jst.j2ee.model.IModelProvider; +import org.eclipse.jst.j2ee.model.ModelProviderManager; +import org.eclipse.jst.j2ee.webapplication.ErrorCodeErrorPage; +import org.eclipse.jst.j2ee.webapplication.Servlet; +import org.eclipse.jst.j2ee.webapplication.ServletMapping; +import org.eclipse.jst.j2ee.webapplication.ServletType; +import org.eclipse.jst.j2ee.webapplication.WebApp; +import org.eclipse.jst.j2ee.webapplication.WebapplicationFactory; +import org.eclipse.jst.javaee.core.DisplayName; +import org.eclipse.jst.javaee.core.JavaeeFactory; +import org.eclipse.jst.javaee.core.UrlPatternType; +import org.eclipse.jst.javaee.web.WebFactory; +import org.eclipse.wst.command.internal.env.core.common.StatusUtils; +import org.eclipse.wst.common.environment.IEnvironment; +import org.eclipse.wst.common.frameworks.datamodel.AbstractDataModelOperation; + +public class MergeWEBXMLCommand extends AbstractDataModelOperation { + + private IProject serverProject; + private boolean extraAxis2TagsAdded = false; + + public MergeWEBXMLCommand( ) { + } + + public IStatus execute( IProgressMonitor monitor, IAdaptable adaptable ){ + return Status.OK_STATUS; + } + + public IStatus exexuteOverride( IProgressMonitor monitor){ + IEnvironment environment = getEnvironment(); + if (serverProject != null) { + IStatus status = null; + status = mergeWebXML(getAxisServletDescriptor()); + if (status.getSeverity() == Status.ERROR) { + environment.getStatusHandler().reportError(status); + return status; + } + status = mergeWebXML(getAdmintServletDescriptor()); + if (status.getSeverity() == Status.ERROR) { + environment.getStatusHandler().reportError(status); + return status; + } + } + return Status.OK_STATUS; + } + + private IStatus mergeWebXML(final ServletDescriptor servletDescriptor){ + IStatus status = Status.OK_STATUS; + final IModelProvider provider = ModelProviderManager.getModelProvider(serverProject); + provider.modify(new Runnable(){ + public void run() { + Object object = provider.getModelObject(); + if (object instanceof org.eclipse.jst.javaee.web.WebApp){ + org.eclipse.jst.javaee.web.WebApp javaeeWebApp = + (org.eclipse.jst.javaee.web.WebApp) object; + addJavaeeServlet(serverProject, servletDescriptor, javaeeWebApp); + } + if (object instanceof org.eclipse.jst.j2ee.webapplication.WebApp){ + WebApp webApp = (WebApp) object; + addServlet(serverProject, servletDescriptor, webApp); + } + } + + }, null); + return status; + } + + private ServletDescriptor getAxisServletDescriptor() { + + ServletDescriptor sd = new ServletDescriptor(); + sd._name = "AxisServlet"; //$NON-NLS-1$ + sd._displayName = "Apache-Axis Servlet"; //$NON-NLS-1$ + sd._className = "org.apache.axis2.transport.http.AxisServlet"; //$NON-NLS-1$ + sd._mappings = new String[] { "/servlet/AxisServlet", //$NON-NLS-1$ + "*.jws", //$NON-NLS-1$ + "/services/*" }; //$NON-NLS-1$ + //sd._loadOnStartup = new Integer(1); + return sd; + } + + private ServletDescriptor getAdmintServletDescriptor() { + ServletDescriptor sd = new ServletDescriptor(); + sd._name = "AxisAdminServlet"; //$NON-NLS-1$ + sd._displayName = "Apache-Axis Admin Servlet Web Admin"; //$NON-NLS-1$ + sd._className = "org.apache.axis2.transport.http.AxisAdminServlet"; //$NON-NLS-1$ + sd._mappings = new String[] { "/axis2-admin/*" }; //$NON-NLS-1$ + sd._loadOnStartup = new Integer(100); + return sd; + } + + public IStatus addServlet(IProject webProject, ServletDescriptor servletDescriptor, + WebApp webapp) { + try { + List theServlets = webapp.getServlets(); + for (int i = 0; i < theServlets.size(); i++) { + Servlet aServlet = (Servlet) theServlets.get(i); + if (aServlet.getServletName().equals(servletDescriptor._name)) { + return Status.OK_STATUS; + } + } + + WebapplicationFactory factory = WebapplicationFactory.eINSTANCE; + + Servlet servlet = factory.createServlet(); + ServletType servletType = factory.createServletType(); + servlet.setWebType(servletType); + servlet.setServletName(servletDescriptor._name); + servletType.setClassName(servletDescriptor._className); + if(servletDescriptor._displayName != null){ + servlet.setDisplayName(servletDescriptor._displayName); + } + if(servletDescriptor._loadOnStartup != null){ + servlet.setLoadOnStartup(servletDescriptor._loadOnStartup); + } + if(servletDescriptor._params != null){ + Properties properties = servlet.getParamsAsProperties(); + properties.putAll(servletDescriptor._params); + } + webapp.getServlets().add(servlet); + + if(servletDescriptor._mappings != null){ + for(int i=0; i<servletDescriptor._mappings.length; i++){ + ServletMapping servletMapping = factory.createServletMapping(); + servletMapping.setServlet(servlet); + servletMapping.setUrlPattern(servletDescriptor._mappings[i]); + webapp.getServletMappings().add(servletMapping); + } + } + + if (!extraAxis2TagsAdded) { + //add the welcome file list + webapp.getFileList().addFileNamed("/axis2-web/index.jsp"); + + //add the error pages + ErrorCodeErrorPage errorPage404 = factory.createErrorCodeErrorPage(); + errorPage404.setErrorCode("404"); + errorPage404.setLocation("/axis2-web/Error/error404.jsp"); + webapp.getErrorPages().add(errorPage404); + + ErrorCodeErrorPage errorPage500 = factory.createErrorCodeErrorPage(); + errorPage500.setErrorCode("500"); + errorPage500.setLocation("/axis2-web/Error/error500.jsp"); + webapp.getErrorPages().add(errorPage500); + extraAxis2TagsAdded = true; + } + + return Status.OK_STATUS; + } catch (Exception e) { + + return StatusUtils.errorStatus( + "MSG_ERROR_UPDATE_WEB_XML", + e); + } + } + + private void addJavaeeServlet(IProject webProject, ServletDescriptor servletDescriptor, + org.eclipse.jst.javaee.web.WebApp webapp) { + List theServlets = webapp.getServlets(); + for (int i = 0; i < theServlets.size(); i++) { + org.eclipse.jst.javaee.web.Servlet aServlet = + (org.eclipse.jst.javaee.web.Servlet) theServlets.get(i); + if (aServlet.getServletName().equals(servletDescriptor._name)) { + return; + } + } + WebFactory factory = WebFactory.eINSTANCE; + org.eclipse.jst.javaee.web.Servlet servlet = factory.createServlet(); + servlet.setServletName(servletDescriptor._name); + servlet.setServletClass(servletDescriptor._className); + if(servletDescriptor._displayName != null){ + DisplayName displayNameObj = JavaeeFactory.eINSTANCE.createDisplayName(); + displayNameObj.setValue(servletDescriptor._displayName); + servlet.getDisplayNames().add(displayNameObj); + } + if(servletDescriptor._loadOnStartup != null){ + servlet.setLoadOnStartup(servletDescriptor._loadOnStartup); + } + webapp.getServlets().add(servlet); + if(servletDescriptor._mappings != null){ + for(int i=0; i<servletDescriptor._mappings.length; i++){ + org.eclipse.jst.javaee.web.ServletMapping servletMapping = + factory.createServletMapping(); + servletMapping.setServletName(servlet.getServletName()); + UrlPatternType url = JavaeeFactory.eINSTANCE.createUrlPatternType(); + url.setValue(servletDescriptor._mappings[i]); + servletMapping.getUrlPatterns().add(url); + webapp.getServletMappings().add(servletMapping); + } + } + } + + + public void setServerProject(IProject serverProject) { + this.serverProject = serverProject; + } + + public void setExtraAxis2TagsAdded(boolean flag) { + this.extraAxis2TagsAdded = flag; + } + + public class ServletDescriptor { + String _name; + String _className; + String _displayName; + Map _params; + String[] _mappings; + Integer _loadOnStartup; + } + +} |