View | Details | Raw Unified | Return to bug 54448
Collapse All | Expand All

(-)java/org/apache/catalina/deploy/NamingResources.java (-23 / +1 lines)
Lines 1190-1196 Link Here
1190
                // No match - ignore this injection target
1190
                // No match - ignore this injection target
1191
                continue;
1191
                continue;
1192
            }
1192
            }
1193
            targetType = convertPrimitiveType(targetType);
1193
            targetType = Introspection.convertPrimitiveType(targetType);
1194
1194
1195
            if (typeClass == null) {
1195
            if (typeClass == null) {
1196
                // Need to find a common type amongst the injection targets
1196
                // Need to find a common type amongst the injection targets
Lines 1243-1268 Link Here
1243
        }
1243
        }
1244
        return null;
1244
        return null;
1245
    }
1245
    }
1246
1247
    private Class<?> convertPrimitiveType(Class<?> clazz) {
1248
        if (clazz.equals(char.class)) {
1249
            return Character.class;
1250
        } else if (clazz.equals(int.class)) {
1251
            return Integer.class;
1252
        } else if (clazz.equals(boolean.class)) {
1253
            return Boolean.class;
1254
        } else if (clazz.equals(double.class)) {
1255
            return Double.class;
1256
        } else if (clazz.equals(byte.class)) {
1257
            return Byte.class;
1258
        } else if (clazz.equals(short.class)) {
1259
            return Short.class;
1260
        } else if (clazz.equals(long.class)) {
1261
            return Long.class;
1262
        } else if (clazz.equals(float.class)) {
1263
            return Float.class;
1264
        } else {
1265
            return clazz;
1266
        }
1267
    }
1268
}
1246
}
(-)java/org/apache/catalina/startup/WebAnnotationSet.java (-8 / +8 lines)
Lines 265-271 Link Here
265
                    Resource annotation = field.getAnnotation(Resource.class);
265
                    Resource annotation = field.getAnnotation(Resource.class);
266
                    String defaultName =
266
                    String defaultName =
267
                            classClass.getName() + SEPARATOR + field.getName();
267
                            classClass.getName() + SEPARATOR + field.getName();
268
                    String defaultType = field.getType().getCanonicalName();
268
                    Class<?> defaultType = field.getType();
269
                    addResource(context, annotation, defaultName, defaultType);
269
                    addResource(context, annotation, defaultName, defaultType);
270
                }
270
                }
271
            }
271
            }
Lines 290-297 Link Here
290
                    String defaultName = classClass.getName() + SEPARATOR +
290
                    String defaultName = classClass.getName() + SEPARATOR +
291
                            Introspection.getPropertyName(method);
291
                            Introspection.getPropertyName(method);
292
292
293
                    String defaultType =
293
                    Class<?> defaultType =
294
                            (method.getParameterTypes()[0]).getCanonicalName();
294
                            (method.getParameterTypes()[0]);
295
                    addResource(context, annotation, defaultName, defaultType);
295
                    addResource(context, annotation, defaultName, defaultType);
296
                }
296
                }
297
            }
297
            }
Lines 309-315 Link Here
309
    }
309
    }
310
310
311
    protected static void addResource(Context context, Resource annotation,
311
    protected static void addResource(Context context, Resource annotation,
312
            String defaultName, String defaultType) {
312
            String defaultName, Class<?> defaultType) {
313
        String name = getName(annotation, defaultName);
313
        String name = getName(annotation, defaultName);
314
        String type = getType(annotation, defaultType);
314
        String type = getType(annotation, defaultType);
315
            
315
            
Lines 412-425 Link Here
412
    }
412
    }
413
413
414
414
415
    private static String getType(Resource annotation, String defaultType) {
415
    private static String getType(Resource annotation, Class<?> defaultType) {
416
        String type = annotation.type().getCanonicalName();
416
        Class<?> type = annotation.type();
417
        if (type == null || type.equals("java.lang.Object")) {
417
        if (type == null || type.equals(Object.class)) {
418
            if (defaultType != null) {
418
            if (defaultType != null) {
419
                type = defaultType;
419
                type = defaultType;
420
            }
420
            }
421
        }
421
        }
422
        return type;
422
        return Introspection.convertPrimitiveType(type).getCanonicalName();
423
    }
423
    }
424
424
425
425
(-)java/org/apache/catalina/util/Introspection.java (+30 lines)
Lines 153-156 Link Here
153
        }
153
        }
154
        return clazz;
154
        return clazz;
155
    }
155
    }
156
157
    /**
158
     * Converts the primitive type to its corresponding wrapper.
159
     * 
160
     * @param clazz
161
     *            Class that will be evaluated
162
     * @return if the parameter is a primitive type returns its wrapper;
163
     *         otherwise returns the same class
164
     */
165
    public static Class<?> convertPrimitiveType(Class<?> clazz) {
166
        if (clazz.equals(char.class)) {
167
            return Character.class;
168
        } else if (clazz.equals(int.class)) {
169
            return Integer.class;
170
        } else if (clazz.equals(boolean.class)) {
171
            return Boolean.class;
172
        } else if (clazz.equals(double.class)) {
173
            return Double.class;
174
        } else if (clazz.equals(byte.class)) {
175
            return Byte.class;
176
        } else if (clazz.equals(short.class)) {
177
            return Short.class;
178
        } else if (clazz.equals(long.class)) {
179
            return Long.class;
180
        } else if (clazz.equals(float.class)) {
181
            return Float.class;
182
        } else {
183
            return clazz;
184
        }
185
    }
156
}
186
}
(-)test/org/apache/catalina/startup/TestContextConfig.java (+19 lines)
Lines 126-131 Link Here
126
        assertPageContains("/test/testServlet", "postConstruct1()");
126
        assertPageContains("/test/testServlet", "postConstruct1()");
127
    }
127
    }
128
128
129
    @Test
130
    public void testBug54448() throws Exception {
131
        Tomcat tomcat = getTomcatInstance();
132
133
        File appDir = new File("test/webapp-3.0-fragments");
134
        Context context = tomcat.addWebapp(null, "/test",
135
                appDir.getAbsolutePath());
136
137
        Tomcat.addServlet(context, "TestServlet",
138
                "org.apache.catalina.startup.TesterServletWithAnnotations");
139
        context.addServletMapping("/testServlet", "TestServlet");
140
141
        tomcat.enableNaming();
142
143
        tomcat.start();
144
145
        assertPageContains("/test/testServlet", "envEntry: 1");
146
    }
147
129
    private static class CustomDefaultServletSCI
148
    private static class CustomDefaultServletSCI
130
            implements ServletContainerInitializer {
149
            implements ServletContainerInitializer {
131
150
(-)test/org/apache/catalina/startup/TesterServletWithAnnotations.java (+42 lines)
Line 0 Link Here
1
/*
2
 * Licensed to the Apache Software Foundation (ASF) under one or more
3
 * contributor license agreements.  See the NOTICE file distributed with
4
 * this work for additional information regarding copyright ownership.
5
 * The ASF licenses this file to You under the Apache License, Version 2.0
6
 * (the "License"); you may not use this file except in compliance with
7
 * the License.  You may obtain a copy of the License at
8
 *
9
 *      http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 */
17
18
package org.apache.catalina.startup;
19
20
import java.io.IOException;
21
22
import javax.annotation.Resource;
23
import javax.servlet.ServletException;
24
import javax.servlet.http.HttpServlet;
25
import javax.servlet.http.HttpServletRequest;
26
import javax.servlet.http.HttpServletResponse;
27
28
public class TesterServletWithAnnotations extends HttpServlet {
29
30
    private static final long serialVersionUID = 1L;
31
32
    @Resource(mappedName = "1")
33
    private int envEntry;
34
35
    @Override
36
    protected void doGet(HttpServletRequest req, HttpServletResponse resp)
37
            throws ServletException, IOException {
38
        resp.setContentType("text/plain");
39
        resp.getWriter().print("envEntry: " + envEntry);
40
    }
41
}
42
native

Return to bug 54448