OpenLiberty / open-liberty-tools

Open Liberty Tools are lightweight tools for developing, assembling, and deploying apps to Open Liberty.
http://openliberty.io
Eclipse Public License 1.0
52 stars 40 forks source link

Incorrect context root used to launch browser when EAR deployment assembly is modified #18

Open rajivsen opened 7 years ago

rajivsen commented 7 years ago

The incorrect context root used to launch the browser when using Run on Server on a Servlet that is contained in a web module that is referenced in an EAR deployment assembly with the non default archive name.

Steps to reproduce:

Create a liberty server
Create a new web project that is added to an EAR
Open the EAR deployment assembly properties page and modify the Deploy Path for the web project so that it has a different name. Apply the change and close.
Create a servlet in the web project and do a Run on Server action on it.

Result: Context root not found. Notice that in the server console log the web application is deployed and started and the context root matches the archive name in the deployment assembly. According to JEE spec this is the correct default context root.

From the JEE7 spec APPLICATION ASSEMBLY - 8.4.1 Assembling a Java EE Application section: The context root is a relative name in the web namespace for the application. Each web module must be given a distinct and nonoverlapping name for its context root. The web modules will be assigned a complete name in the namespace of the web server at deployment time. If there is only one web module in the Java EE application, the context root may be the empty string. If no deployment descriptor is included in the application package, the context root of the web module will be the module name. See the Servlet specification for detailed requirements of context root naming.

rajivsen commented 7 years ago

The commit with PR #19 caused a test case failure in JEEContextRoot_EAR_NoDD_CRinWebXML. Erin found the root of the problem:

If that method returns null then it looks in the IBM extended web xml file. But now it is not returning null so it does not look there.

`if (contextRoot == null) { // Returns the context root from ibm-web-ext.xml file (XML, not XMI)
contextRoot = DeploymentDescriptorHelper.getContextRootFromExtXml(DeploymentDescriptorHelper.getComponentRoot(webModule.getProject())); }

if (contextRoot == null) { // Returns the context root from ibm-web-ext.xmi file (XMI, not XML) contextRoot = DeploymentDescriptorHelper.getContextRootFromExtXmi(DeploymentDescriptorHelper.getComponentRoot(webModule.getProject())); } `

The context root set in ibm-web-ext.xmi should take precedence. The logic added in PR #19 should probably be last in the order of precedence for context resolution.