Skip to content
This repository was archived by the owner on Mar 20, 2021. It is now read-only.

Commit 4e3e2b4

Browse files
committed
[2.3.x] Incremental changes to Mapper/MappingData to support changes in the Servlet 4.0 specification.
1 parent da7314a commit 4e3e2b4

File tree

2 files changed

+48
-13
lines changed

2 files changed

+48
-13
lines changed

modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/Mapper.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -457,7 +457,7 @@ public void addWrapper(String hostName, String contextPath, String path,
457457
* @param contextPath Context path this wrapper belongs to
458458
* @param path Wrapper mapping
459459
* @param wrapper Wrapper object
460-
* @param jspWildCard
460+
* @param jspWildCard jsp wildcard
461461
*/
462462
public void addWrapper(String hostName, String contextPath, String path,
463463
Object wrapper, boolean jspWildCard) {
@@ -471,7 +471,7 @@ public void addWrapper(String hostName, String contextPath, String path,
471471
* @param contextPath Context path this wrapper belongs to
472472
* @param path Wrapper mapping
473473
* @param wrapper Wrapper object
474-
* @param jspWildCard
474+
* @param jspWildCard jsp wildcard
475475
* @param servletName servlet name or null if unknown
476476
*/
477477
public void addWrapper(String hostName, String contextPath, String path,
@@ -1042,7 +1042,7 @@ private void internalMap(CharChunk host, CharChunk uri,
10421042
boolean found = false;
10431043
*/
10441044
while (pos >= 0) {
1045-
if (uri.startsWith(contexts[pos].name)) {
1045+
if (contexts != null && uri.startsWith(contexts[pos].name)) {
10461046
length = contexts[pos].name.length();
10471047
if (uri.getLength() == length) {
10481048
found = true;
@@ -1063,7 +1063,7 @@ private void internalMap(CharChunk host, CharChunk uri,
10631063
uri.setEnd(uriEnd);
10641064

10651065
if (!found) {
1066-
if ("".equals(contexts[0].name)) {
1066+
if (contexts != null && "".equals(contexts[0].name)) {
10671067
ctx = contexts[0];
10681068
// START GlassFish 1024
10691069
} else if (hosts[hostPos].defaultContexts[0] != null) {
@@ -1129,6 +1129,7 @@ private void internalMapWrapper(Context context, CharChunk path,
11291129
mappingData.requestPath.setString("");
11301130
mappingData.wrapperPath.setString("");
11311131
mappingData.pathInfo.setString("/");
1132+
mappingData.mappingType = MappingData.CONTEXT_ROOT;
11321133
}
11331134
}
11341135

@@ -1272,6 +1273,7 @@ private void internalMapWrapper(Context context, CharChunk path,
12721273
path.getEnd());
12731274
mappingData.requestPath.setString(pathStr);
12741275
mappingData.wrapperPath.setString(pathStr);
1276+
mappingData.mappingType = MappingData.DEFAULT;
12751277
}
12761278
}
12771279
}
@@ -1326,6 +1328,7 @@ private void internalMapWrapper(Context context, CharChunk path,
13261328
(path.getBuffer(), path.getStart(), path.getEnd());
13271329
mappingData.wrapperPath.setChars
13281330
(path.getBuffer(), path.getStart(), path.getEnd());
1331+
mappingData.mappingType = MappingData.DEFAULT;
13291332
}
13301333
// Redirection to a folder
13311334
char[] buf = path.getBuffer();
@@ -1392,6 +1395,7 @@ private void internalMapWrapper(Context context, CharChunk path,
13921395
mappingData.wrapperPath.setString(wrappers[pos].name);
13931396
mappingData.wrapper = wrappers[pos].object;
13941397
mappingData.servletName = wrappers[pos].servletName;
1398+
mappingData.mappingType = MappingData.EXACT;
13951399
}
13961400
}
13971401

@@ -1443,6 +1447,7 @@ private void internalMapWrapper(Context context, CharChunk path,
14431447
mappingData.wrapper = wrappers[pos].object;
14441448
mappingData.servletName = wrappers[pos].servletName;
14451449
mappingData.jspWildCard = wrappers[pos].jspWildCard;
1450+
mappingData.mappingType = MappingData.PATH;
14461451
}
14471452
}
14481453
}
@@ -1483,6 +1488,7 @@ private void internalMapWrapper(Context context, CharChunk path,
14831488
(buf, servletPath, pathEnd);
14841489
mappingData.wrapper = wrappers[pos].object;
14851490
mappingData.servletName = wrappers[pos].servletName;
1491+
mappingData.mappingType = MappingData.EXTENSION;
14861492
}
14871493
path.setStart(servletPath);
14881494
path.setEnd(pathEnd);
@@ -1492,7 +1498,7 @@ private void internalMapWrapper(Context context, CharChunk path,
14921498

14931499

14941500
/**
1495-
* Find a map elemnt given its name in a sorted array of map elements.
1501+
* Find a map element given its name in a sorted array of map elements.
14961502
* This will return the index for the closest inferior or equal item in the
14971503
* given array.
14981504
*/
@@ -1502,7 +1508,7 @@ private static int find(MapElement[] map, CharChunk name) {
15021508

15031509

15041510
/**
1505-
* Find a map elemnt given its name in a sorted array of map elements.
1511+
* Find a map element given its name in a sorted array of map elements.
15061512
* This will return the index for the closest inferior or equal item in the
15071513
* given array.
15081514
*/
@@ -1547,11 +1553,11 @@ private static int find(MapElement[] map, CharChunk name,
15471553
}
15481554

15491555

1550-
/**
1551-
* Find a map element given its name in a sorted array of map elements.
1552-
* This will return the index for the closest inferior or equal item in the
1553-
* given array.
1554-
*/
1556+
// /**
1557+
// * Find a map element given its name in a sorted array of map elements.
1558+
// * This will return the index for the closest inferior or equal item in the
1559+
// * given array.
1560+
// */
15551561
// private static int findIgnoreCase(MapElement[] map, String name) {
15561562
// CharChunk cc = new CharChunk();
15571563
// char[] chars = name.toCharArray();

modules/http-server/src/main/java/org/glassfish/grizzly/http/server/util/MappingData.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 2010-2015 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 2010-2017 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -66,6 +66,16 @@
6666
* @author Remy Maucherat
6767
*/
6868
public class MappingData {
69+
70+
public static final byte CONTEXT_ROOT = 0x1;
71+
public static final byte DEFAULT = 0x2;
72+
public static final byte EXACT = 0x4;
73+
public static final byte EXTENSION = 0x8;
74+
public static final byte IMPLICIT = 0x10;
75+
public static final byte PATH = 0x20;
76+
public static final byte UNKNOWN = 0x40;
77+
78+
public byte mappingType = UNKNOWN;
6979
public Object host = null;
7080
public Object context = null;
7181
public Object wrapper = null;
@@ -83,6 +93,7 @@ public class MappingData {
8393
public final DataChunk tmpMapperDC = DataChunk.newInstance();
8494

8595
public void recycle() {
96+
mappingType = UNKNOWN;
8697
host = null;
8798
context = null;
8899
wrapper = null;
@@ -110,6 +121,24 @@ public String toString() {
110121
sb.append("\nwrapperPath: ").append(wrapperPath);
111122
sb.append("\npathInfo: ").append(pathInfo);
112123
sb.append("\nredirectPath: ").append(redirectPath);
124+
sb.append("\nmappingType: ").append(getMappingDescription());
113125
return sb.toString();
114126
}
127+
128+
129+
// -------------------------------------------------------- Private Methods
130+
131+
132+
private String getMappingDescription() {
133+
switch (mappingType) {
134+
case CONTEXT_ROOT: return "context";
135+
case DEFAULT: return "default";
136+
case EXACT: return "exact";
137+
case EXTENSION: return "extension";
138+
case IMPLICIT: return "implicit";
139+
case PATH: return "path";
140+
default: return "unknown";
141+
}
142+
}
143+
115144
}

0 commit comments

Comments
 (0)