Skip to content

Commit

Permalink
Merge pull request #5811 from pnicolucci/4809-18004ServletPathForDefa…
Browse files Browse the repository at this point in the history
…ultMapping

4809 18004 servlet path for default mapping
  • Loading branch information
tevans78 authored Nov 20, 2018
2 parents 59c44a5 + 2da8544 commit 2dcb9f3
Show file tree
Hide file tree
Showing 19 changed files with 332 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ public Object match(IExtendedRequest req) {
// PK80340 Start
Object starTarget = defaultNode.getStarTarget();

if (WCCustomProperties.ENABLE_DEFAULT_SERVLET_REQUEST_PATH_ELEMENTS && (starTarget instanceof ServletWrapper) && ((ServletWrapper) starTarget).isDefaultServlet()) {
if (URIMatcher.SERVLET_PATH_FOR_DEFAULT_MAPPING && (starTarget instanceof ServletWrapper) && ((ServletWrapper) starTarget).isDefaultServlet()) {
dispatchContext.setPathElements(uri, null);
} else {
dispatchContext.setPathElements("", uri);
Expand Down
1 change: 1 addition & 0 deletions dev/com.ibm.ws.webcontainer.servlet.4.0_fat/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
<classpathentry kind="src" path="test-applications/TestGetMapping.war/src"/>
<classpathentry kind="src" path="test-applications/TestAddJspFile.war/src"/>
<classpathentry kind="src" path="test-applications/TestPushBuilderSecurity.war/src"/>
<classpathentry kind="src" path="test-applications/ServletPathDefaultMapping.war/src"/>
<classpathentry kind="con" path="aQute.bnd.classpath.container"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry kind="output" path="bin"/>
Expand Down
3 changes: 2 additions & 1 deletion dev/com.ibm.ws.webcontainer.servlet.4.0_fat/bnd.bnd
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ src: \
test-applications/TestGetMapping.war/src,\
test-applications/TestAddJspFile.war/src, \
test-applications/TestEncoding.war/src, \
test-applications/TestPushBuilderSecurity.war/src
test-applications/TestPushBuilderSecurity.war/src, \
test-applications/ServletPathDefaultMapping.war/src

fat.project: true

Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/*
* IBM Confidential
/*******************************************************************************
* Copyright (c) 2012, 2018 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
*
* OCO Source Materials
*
* Copyright IBM Corp. 2012, 2014
*
* The source code for this program is not published or otherwise divested
* of its trade secrets, irrespective of what has been deposited with the
* U.S. Copyright Office.
*/
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package com.ibm.ws.fat.wc;

import org.junit.BeforeClass;
Expand All @@ -25,6 +24,8 @@
import com.ibm.ws.fat.wc.tests.WCPushBuilderTest;
import com.ibm.ws.fat.wc.tests.WCServerTest;
import com.ibm.ws.fat.wc.tests.WCServletClarificationTest;
import com.ibm.ws.fat.wc.tests.WCServletPathForDefaultMappingDefault;
import com.ibm.ws.fat.wc.tests.WCServletPathForDefaultMappingFalse;
import com.ibm.ws.fat.wc.tests.WCTrailersTest;

/**
Expand All @@ -45,7 +46,7 @@
* "fat.test.mode=full" to the properties tab, then launch the
* build.
*
* Alternatively, for a comand line launch, add "-Dfat.test.mode=full".
* Alternatively, for a command line launch, add "-Dfat.test.mode=full".
*/
@RunWith(Suite.class)
@SuiteClasses({
Expand All @@ -58,7 +59,9 @@
WCEncodingTest.class,
WCTrailersTest.class,
// WCPushBuilderSecurityTest.class,
WCAddJspFileTest.class
WCAddJspFileTest.class,
WCServletPathForDefaultMappingDefault.class,
WCServletPathForDefaultMappingFalse.class
})
public class FATSuite {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*******************************************************************************
* Copyright (c) 2018 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
*******************************************************************************/
package com.ibm.ws.fat.wc.tests;

import java.util.logging.Logger;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.ibm.ws.fat.util.LoggingTest;
import com.ibm.ws.fat.util.SharedServer;
import com.ibm.ws.fat.wc.WCApplicationHelper;

import componenttest.custom.junit.runner.FATRunner;

/**
* This is a test class for the servlet-4.0 feature to test the behavior when servletPathForDefaultMapping
* is true. There is no need to set the property in the server.xml because the value is true by default
* for the servlet-4.0 feature.
*
*/
@RunWith(FATRunner.class)
public class WCServletPathForDefaultMappingDefault extends LoggingTest {

private static final Logger LOG = Logger.getLogger(WCServletPathForDefaultMappingDefault.class.getName());

@ClassRule
public static SharedServer SHARED_SERVER = new SharedServer("servlet40_ServletPathForDefaultMapping_Default");

@BeforeClass
public static void setUp() throws Exception {

LOG.info("Setup : add ServletPathDefaultMapping.war to the server if not already present.");

WCApplicationHelper.addWarToServerDropins(SHARED_SERVER.getLibertyServer(), "ServletPathDefaultMapping.war", false,
"servletpathdefaultmapping.war.servlets");

SHARED_SERVER.startIfNotStarted();

LOG.info("Setup : wait for message to indicate app has started");

SHARED_SERVER.getLibertyServer().waitForStringInLog("CWWKZ0001I.* ServletPathDefaultMapping", 10000);

LOG.info("Setup : complete, ready for Tests");

}

/**
* Test to ensure that the default behavior when using the servlet-4.0 feature is
* that a request to the default servlet will result in:
*
* servlet path = / + requestURI - context path
* path info = null
*
* @throws Exception
*/
@Test
public void testServletPathForDefaultMapping_Default() throws Exception {
this.verifyResponse("/ServletPathDefaultMapping", "ServletPath = / PathInfo = null");
}

/**
* Test to ensure that the default behavior when using the servlet-4.0 feature is
* that a request to the default servlet will result in:
*
* servlet path = / + requestURI - context path
* path info = null
*
* @throws Exception
*/
@Test
public void testServletPathForDefaultMapping_Default_2() throws Exception {
this.verifyResponse("/ServletPathDefaultMapping/index.html", "ServletPath = /index.html PathInfo = null");
}

/*
* (non-Javadoc)
*
* @see com.ibm.ws.fat.util.LoggingTest#getSharedServer()
*/
@Override
protected SharedServer getSharedServer() {
return SHARED_SERVER;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
/*******************************************************************************
* Copyright (c) 2018 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
*******************************************************************************/
package com.ibm.ws.fat.wc.tests;

import java.util.logging.Logger;

import org.junit.BeforeClass;
import org.junit.ClassRule;
import org.junit.Test;
import org.junit.runner.RunWith;

import com.ibm.ws.fat.util.LoggingTest;
import com.ibm.ws.fat.util.SharedServer;
import com.ibm.ws.fat.wc.WCApplicationHelper;

import componenttest.custom.junit.runner.FATRunner;

/**
* This is a test class for the servlet-4.0 feature to test the behavior when servletPathForDefaultMapping
* is false. Setting servletPathForDefaultMapping to false is the testing the non default behavior.
*
*/
@RunWith(FATRunner.class)
public class WCServletPathForDefaultMappingFalse extends LoggingTest {

private static final Logger LOG = Logger.getLogger(WCServletPathForDefaultMappingFalse.class.getName());

@ClassRule
public static SharedServer SHARED_SERVER = new SharedServer("servlet40_ServletPathForDefaultMapping_False");

@BeforeClass
public static void setUp() throws Exception {

LOG.info("Setup : add ServletPathDefaultMapping.war to the server if not already present.");

WCApplicationHelper.addWarToServerDropins(SHARED_SERVER.getLibertyServer(), "ServletPathDefaultMapping.war", false,
"servletpathdefaultmapping.war.servlets");

SHARED_SERVER.startIfNotStarted();

LOG.info("Setup : wait for message to indicate app has started");

SHARED_SERVER.getLibertyServer().waitForStringInLog("CWWKZ0001I.* ServletPathDefaultMapping", 10000);

LOG.info("Setup : complete, ready for Tests");

}

/**
* Test to ensure that if we set servletPathForDefaultMapping to false in the server.xml ( not the
* default value for the servlet-4.0 feature) then a request to the default servlet will result in:
*
* servlet path = "" (empty string)
* path info = / request URI - context path
*
* This is the incorrect behavior
* according to the servlet specification and that is why we're making it the non default behavior
* for the servlet-4.0 feature.
*
* @throws Exception
*/
@Test
public void testServletPathForDefaultMapping_False() throws Exception {
this.verifyResponse("/ServletPathDefaultMapping", "ServletPath = PathInfo = /");
}

/**
* Test to ensure that if we set servletPathForDefaultMapping to false in the server.xml ( not the
* default value for the servlet-4.0 feature) then a request to the default servlet will result in:
*
* servlet path = "" (empty string)
* path info = / request URI - context path
*
* This is the incorrect behavior
* according to the servlet specification and that is why we're making it the non default behavior
* for the servlet-4.0 feature.
*
* @throws Exception
*/
@Test
public void testServletPathForDefaultMapping_False_2() throws Exception {
this.verifyResponse("/ServletPathDefaultMapping/index.html", "ServletPath = PathInfo = /index.html");
}

/*
* (non-Javadoc)
*
* @see com.ibm.ws.fat.util.LoggingTest#getSharedServer()
*/
@Override
protected SharedServer getSharedServer() {
return SHARED_SERVER;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/apps
/dropins
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bootstrap.include=../testports.properties
osgi.console=7777
com.ibm.ws.logging.trace.specification=*=info:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:HttpTransport=all:HTTPChannel=all:TCPChannel=all:GenericBNF=all:com.ibm.ws.jsp*=all:com.ibm.ws.session.*=all:com.ibm.ws.runtime.update.internal*=all:ChannelFramework=all
com.ibm.ws.classloading.tcclLockWaitTimeMillis=60000
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<server description="Server for testing Webcontainer">

<include location="../fatTestPorts.xml"/>

<featureManager>
<feature>servlet-4.0</feature>
</featureManager>

<logging
traceSpecification="*=info=enabled:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:HttpTransport=all:HTTPChannel=all:TCPChannel=all:GenericBNF=all:com.ibm.ws.jsp*=all:com.ibm.ws.session.*=all:com.ibm.ws.runtime.update.internal*=all:ChannelFramework=all"
maxFileSize="20"
maxFiles="10"
traceFormat="BASIC"/>

</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
/apps
/dropins
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
bootstrap.include=../testports.properties
osgi.console=7777
com.ibm.ws.logging.trace.specification=*=info:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:HttpTransport=all:HTTPChannel=all:TCPChannel=all:GenericBNF=all:com.ibm.ws.jsp*=all:com.ibm.ws.session.*=all:com.ibm.ws.runtime.update.internal*=all:ChannelFramework=all
com.ibm.ws.classloading.tcclLockWaitTimeMillis=60000
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<server description="Server for testing Webcontainer">

<include location="../fatTestPorts.xml"/>

<featureManager>
<feature>servlet-4.0</feature>
</featureManager>

<logging
traceSpecification="*=info=enabled:com.ibm.ws.webcontainer*=all:com.ibm.wsspi.webcontainer*=all:HttpTransport=all:HTTPChannel=all:TCPChannel=all:GenericBNF=all:com.ibm.ws.jsp*=all:com.ibm.ws.session.*=all:com.ibm.ws.runtime.update.internal*=all:ChannelFramework=all"
maxFileSize="20"
maxFiles="10"
traceFormat="BASIC"/>

<webContainer servletPathForDefaultMapping="false"/>
</server>
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*******************************************************************************
* Copyright (c) 2018 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
*******************************************************************************/
package servletpathdefaultmapping.war.servlets;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
*
*/
@WebServlet("/")
public class ServletPathDefaultMappingServlet extends HttpServlet {

public ServletPathDefaultMappingServlet() {

}

@Override
protected void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
ServletOutputStream sos = res.getOutputStream();

sos.println("RequestURI = " + req.getRequestURI());
sos.println();
sos.println("ServletPath = " + req.getServletPath() + " PathInfo = " + req.getPathInfo());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -305,8 +305,8 @@

<!--com.ibm.ws.webcontainer.-->
<AD id="servletPathForDefaultMapping"
name="internal"
description="internal"
name="%servletPathForDefaultMapping.name"
description="%servletPathForDefaultMapping.desc"
required="false" type="String" default="" />

<!--com.ibm.ws.webcontainer.-->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ public void setMappings(List<String> list) {

public List<String> getMappings() {
// start PI23529
if(mappings == null && (WCCustomProperties.EMPTY_SERVLET_MAPPINGS || com.ibm.ws.webcontainer.osgi.WebContainer.getServletContainerSpecLevel() == WebContainer.SPEC_LEVEL_31 )){
if(mappings == null && (WCCustomProperties.EMPTY_SERVLET_MAPPINGS || com.ibm.ws.webcontainer.osgi.WebContainer.getServletContainerSpecLevel() >= WebContainer.SPEC_LEVEL_31 )){
return new ArrayList();
}
//end PI23529
Expand Down
Loading

0 comments on commit 2dcb9f3

Please sign in to comment.