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

(-)org/apache/naming/LookupJndiRef.java (+99 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
19
package org.apache.naming;
20
21
import javax.naming.Context;
22
import javax.naming.RefAddr;
23
import javax.naming.Reference;
24
import javax.naming.StringRefAddr;
25
26
/**
27
 * Represents a reference to lookup.
28
 */
29
30
public class LookupJndiRef
31
    extends Reference {
32
33
34
    // -------------------------------------------------------------- Constants
35
36
    /**
37
     * JNDI name for the lookup
38
     */
39
    public static final String LOOKUP_NAME = "lookup-name";
40
41
    
42
    /**
43
     * Default factory for this reference.
44
     */
45
    public static final String DEFAULT_FACTORY = 
46
        org.apache.naming.factory.Constants.DEFAULT_LOOKUP_JNDI_FACTORY;
47
48
    // ----------------------------------------------------------- Constructors
49
50
    public LookupJndiRef(String lookupName) {
51
        this("java.lang.Object",lookupName);
52
    }
53
    
54
55
    public LookupJndiRef(String resourceType, String lookupName) {
56
        this(resourceType,null,null,lookupName);
57
    }
58
59
60
    public LookupJndiRef(String resourceType, String factory,
61
                          String factoryLocation, String lookupName) {
62
        super(resourceType, factory, factoryLocation);
63
        if(lookupName != null && !lookupName.equals("")){
64
            RefAddr ref = new StringRefAddr(LOOKUP_NAME, lookupName);
65
            add(ref);
66
        }
67
    }
68
69
70
    // ----------------------------------------------------- Instance Variables
71
72
73
    // ------------------------------------------------------ Reference Methods
74
75
76
    /**
77
     * Retrieves the class name of the factory of the object to which this 
78
     * reference refers.
79
     */
80
    @Override
81
    public String getFactoryClassName() {
82
        String factory = super.getFactoryClassName();
83
        if (factory != null) {
84
            return factory;
85
        } else {
86
            factory = System.getProperty(Context.OBJECT_FACTORIES);
87
            if (factory != null) {
88
                return null;
89
            } else {
90
                return DEFAULT_FACTORY;
91
            }
92
        }
93
    }
94
95
96
    // ------------------------------------------------------------- Properties
97
98
99
}
0
  + native
100
  + native
(-)org/apache/naming/factory/LookupJndiFactory.java (+133 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
19
package org.apache.naming.factory;
20
21
import java.util.Hashtable;
22
23
import javax.naming.InitialContext;
24
import javax.naming.Name;
25
import javax.naming.Context;
26
import javax.naming.NamingException;
27
import javax.naming.Reference;
28
import javax.naming.RefAddr;
29
import javax.naming.spi.ObjectFactory;
30
31
import org.apache.naming.LookupJndiRef;
32
33
/**
34
 * Object factory for lookups. 
35
 */
36
37
public class LookupJndiFactory
38
    implements ObjectFactory {
39
40
41
    // ----------------------------------------------------------- Constructors
42
43
44
    // -------------------------------------------------------------- Constants
45
46
47
    // ----------------------------------------------------- Instance Variables
48
49
50
    // --------------------------------------------------------- Public Methods
51
52
53
    // -------------------------------------------------- ObjectFactory Methods
54
55
56
    /**
57
     * Create a new Resource env instance.
58
     * 
59
     * @param obj The reference object describing the DataSource
60
     */
61
    public Object getObjectInstance(Object obj, Name name, Context nameCtx,
62
                                    Hashtable<?,?> environment)
63
        throws Exception {
64
        
65
        String lookupName = null;
66
        if (obj instanceof LookupJndiRef) {
67
            Reference ref = (Reference) obj;
68
            ObjectFactory factory = null;
69
            RefAddr lookupNameRefAddr = ref.get(LookupJndiRef.LOOKUP_NAME);
70
            if(lookupNameRefAddr != null){
71
                lookupName = lookupNameRefAddr.getContent().toString();
72
            }
73
            RefAddr factoryRefAddr = ref.get(Constants.FACTORY);
74
            if (factoryRefAddr != null) {
75
                // Using the specified factory
76
                String factoryClassName = 
77
                    factoryRefAddr.getContent().toString();
78
                // Loading factory
79
                ClassLoader tcl = 
80
                    Thread.currentThread().getContextClassLoader();
81
                Class<?> factoryClass = null;
82
                if (tcl != null) {
83
                    try {
84
                        factoryClass = tcl.loadClass(factoryClassName);
85
                    } catch(ClassNotFoundException e) {
86
                        NamingException ex = new NamingException
87
                            ("Could not load jndi lookup factory class");
88
                        ex.initCause(e);
89
                        throw ex;
90
                    }
91
                } else {
92
                    try {
93
                        factoryClass = Class.forName(factoryClassName);
94
                    } catch(ClassNotFoundException e) {
95
                        NamingException ex = new NamingException
96
                            ("Could not load jndi lookup factory class");
97
                        ex.initCause(e);
98
                        throw ex;
99
                    }
100
                }
101
                if (factoryClass != null) {
102
                    try {
103
                        factory = (ObjectFactory) factoryClass.newInstance();
104
                    } catch(Throwable t) {
105
                        if (t instanceof NamingException)
106
                            throw (NamingException) t;
107
                        NamingException ex = new NamingException
108
                            ("Could not create jndi lookup factory instance");
109
                        ex.initCause(t);
110
                        throw ex;
111
                    }
112
                }
113
            }
114
            // Note: No defaults here
115
            if (factory != null) {
116
                return factory.getObjectInstance
117
                    (obj, name, nameCtx, environment);
118
            } else {
119
                if(lookupName == null){
120
                    throw new NamingException
121
                    ("Cannot create jndi lookup factory instance");                 
122
                }else{
123
                    return new InitialContext().lookup(lookupName);
124
                }
125
            }
126
        }
127
128
        return null;
129
130
    }
131
132
133
}
0
  + native
134
  + native
(-)org/apache/naming/factory/Constants.java (+4 lines)
Lines 53-58 Link Here
53
53
54
    public static final String OPENEJB_EJB_FACTORY = 
54
    public static final String OPENEJB_EJB_FACTORY = 
55
        Package + ".OpenEjbFactory";
55
        Package + ".OpenEjbFactory";
56
    
57
    public static final String DEFAULT_LOOKUP_JNDI_FACTORY =
58
        Package + ".LookupJndiFactory";
59
    
56
60
57
    public static final String OBJECT_FACTORIES = "";
61
    public static final String OBJECT_FACTORIES = "";
58
62
(-)org/apache/catalina/core/DefaultInstanceManager.java (-9 / +36 lines)
Lines 29-34 Link Here
29
import java.security.PrivilegedAction;
29
import java.security.PrivilegedAction;
30
import java.security.PrivilegedActionException;
30
import java.security.PrivilegedActionException;
31
import java.security.PrivilegedExceptionAction;
31
import java.security.PrivilegedExceptionAction;
32
import java.util.HashMap;
32
import java.util.Map;
33
import java.util.Map;
33
import java.util.Properties;
34
import java.util.Properties;
34
35
Lines 133-144 Link Here
133
134
134
    private Object newInstance(Object instance, Class<?> clazz) throws IllegalAccessException, InvocationTargetException, NamingException {
135
    private Object newInstance(Object instance, Class<?> clazz) throws IllegalAccessException, InvocationTargetException, NamingException {
135
        if (!ignoreAnnotations) {
136
        if (!ignoreAnnotations) {
136
            Map<String, String> injections = injectionMap.get(clazz.getName());
137
            Map<String, String> injections = getInjections(clazz);
137
            processAnnotations(instance, injections);
138
            processAnnotations(instance, injections);
138
            postConstruct(instance, clazz);
139
            postConstruct(instance, clazz);
139
        }
140
        }
140
        return instance;
141
        return instance;
141
    }
142
    }
143
    
144
    private Map<String, String> getInjections(Class<?> clazz){
145
        Class<?> temp = clazz;
146
        Map<String, String> injections = new HashMap<String, String>();
147
        do{
148
            Map<String, String> tempInjections = injectionMap.get(temp.getName());
149
            if(tempInjections != null){
150
                injections.putAll(tempInjections);
151
            }
152
            
153
            temp = temp.getSuperclass();
154
            
155
        }while(temp != Object.class);
156
        
157
        return injections;
158
    }
142
159
143
    @Override
160
    @Override
144
    public void destroyInstance(Object instance) throws IllegalAccessException, InvocationTargetException {
161
    public void destroyInstance(Object instance) throws IllegalAccessException, InvocationTargetException {
Lines 451-456 Link Here
451
            Object instance, Field field, String name, Class<?> clazz)
468
            Object instance, Field field, String name, Class<?> clazz)
452
            throws NamingException, IllegalAccessException {
469
            throws NamingException, IllegalAccessException {
453
470
471
        name = normalize(name);
454
        Object lookedupResource;
472
        Object lookedupResource;
455
        boolean accessibility;
473
        boolean accessibility;
456
474
Lines 485-490 Link Here
485
            Object instance, Method method, String name, Class<?> clazz)
503
            Object instance, Method method, String name, Class<?> clazz)
486
            throws NamingException, IllegalAccessException, InvocationTargetException {
504
            throws NamingException, IllegalAccessException, InvocationTargetException {
487
505
506
        name = normalize(name);
488
        if (!method.getName().startsWith("set")
507
        if (!method.getName().startsWith("set")
489
                || method.getName().length() < 4
508
                || method.getName().length() < 4
490
                || method.getParameterTypes().length != 1
509
                || method.getParameterTypes().length != 1
Lines 508-523 Link Here
508
        method.invoke(instance, lookedupResource);
527
        method.invoke(instance, lookedupResource);
509
        method.setAccessible(accessibility);
528
        method.setAccessible(accessibility);
510
    }
529
    }
530
    
531
    private static String normalize(String jndiName){
532
        if(jndiName != null && jndiName.startsWith("java:comp/env/")){
533
            return jndiName.substring(14);
534
        }
535
        return jndiName;
536
    }
537
    
511
538
512
        public static String getName(Method setter) {
539
    public static String getName(Method setter) {
513
            StringBuilder name = new StringBuilder(setter.getName());
540
        StringBuilder name = new StringBuilder(setter.getName());
514
541
515
            // remove 'set'
542
        // remove 'set'
516
            name.delete(0, 3);
543
        name.delete(0, 3);
517
544
518
            // lowercase first char
545
        // lowercase first char
519
            name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
546
        name.setCharAt(0, Character.toLowerCase(name.charAt(0)));
520
547
521
            return name.toString();
548
        return name.toString();
522
        }
549
    }
523
}
550
}
(-)org/apache/catalina/core/NamingContextListener.java (-193 / +229 lines)
Lines 54-65 Link Here
54
import org.apache.catalina.deploy.ContextService;
54
import org.apache.catalina.deploy.ContextService;
55
import org.apache.catalina.deploy.ContextTransaction;
55
import org.apache.catalina.deploy.ContextTransaction;
56
import org.apache.catalina.deploy.NamingResources;
56
import org.apache.catalina.deploy.NamingResources;
57
import org.apache.catalina.deploy.ResourceBase;
57
import org.apache.juli.logging.Log;
58
import org.apache.juli.logging.Log;
58
import org.apache.juli.logging.LogFactory;
59
import org.apache.juli.logging.LogFactory;
59
import org.apache.naming.ContextAccessController;
60
import org.apache.naming.ContextAccessController;
60
import org.apache.naming.ContextBindings;
61
import org.apache.naming.ContextBindings;
61
import org.apache.naming.EjbRef;
62
import org.apache.naming.EjbRef;
62
import org.apache.naming.HandlerRef;
63
import org.apache.naming.HandlerRef;
64
import org.apache.naming.LookupJndiRef;
63
import org.apache.naming.NamingContext;
65
import org.apache.naming.NamingContext;
64
import org.apache.naming.ResourceEnvRef;
66
import org.apache.naming.ResourceEnvRef;
65
import org.apache.naming.ResourceLinkRef;
67
import org.apache.naming.ResourceLinkRef;
Lines 738-754 Link Here
738
     */
740
     */
739
    public void addEjb(ContextEjb ejb) {
741
    public void addEjb(ContextEjb ejb) {
740
742
741
        // Create a reference to the EJB.
743
        Reference ref = lookForLookupRef(ejb);
742
        Reference ref = new EjbRef
744
        
743
            (ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink());
745
        if(ref == null){
744
        // Adding the additional parameters, if any
746
            // Create a reference to the EJB.
745
        Iterator<String> params = ejb.listProperties();
747
            ref = new EjbRef
746
        while (params.hasNext()) {
748
                (ejb.getType(), ejb.getHome(), ejb.getRemote(), ejb.getLink());
747
            String paramName = params.next();
749
            // Adding the additional parameters, if any
748
            String paramValue = (String) ejb.getProperty(paramName);
750
            Iterator<String> params = ejb.listProperties();
749
            StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
751
            while (params.hasNext()) {
750
            ref.add(refAddr);
752
                String paramName = params.next();
753
                String paramValue = (String) ejb.getProperty(paramName);
754
                StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
755
                ref.add(refAddr);
756
            }            
751
        }
757
        }
758
        
752
        try {
759
        try {
753
            createSubcontexts(envCtx, ejb.getName());
760
            createSubcontexts(envCtx, ejb.getName());
754
            envCtx.bind(ejb.getName(), ref);
761
            envCtx.bind(ejb.getName(), ref);
Lines 764-848 Link Here
764
     */
771
     */
765
    public void addEnvironment(ContextEnvironment env) {
772
    public void addEnvironment(ContextEnvironment env) {
766
773
767
        Object value = null;
774
        //Lets check that lookup exist
768
        // Instantiating a new instance of the correct object type, and
775
        Object value = lookForLookupRef(env);
769
        // initializing it.
776
        
770
        String type = env.getType();
777
        if(value == null){
771
        try {
778
            // Instantiating a new instance of the correct object type, and
772
            if (type.equals("java.lang.String")) {
779
            // initializing it.
773
                value = env.getValue();
780
            String type = env.getType();
774
            } else if (type.equals("java.lang.Byte")) {
781
            try {
775
                if (env.getValue() == null) {
782
                if (type.equals("java.lang.String")) {
776
                    value = new Byte((byte) 0);
783
                    value = env.getValue();
777
                } else {
784
                } else if (type.equals("java.lang.Byte")) {
778
                    value = Byte.decode(env.getValue());
785
                    if (env.getValue() == null) {
779
                }
786
                        value = new Byte((byte) 0);
780
            } else if (type.equals("java.lang.Short")) {
781
                if (env.getValue() == null) {
782
                    value = new Short((short) 0);
783
                } else {
784
                    value = Short.decode(env.getValue());
785
                }
786
            } else if (type.equals("java.lang.Integer")) {
787
                if (env.getValue() == null) {
788
                    value = new Integer(0);
789
                } else {
790
                    value = Integer.decode(env.getValue());
791
                }
792
            } else if (type.equals("java.lang.Long")) {
793
                if (env.getValue() == null) {
794
                    value = new Long(0);
795
                } else {
796
                    value = Long.decode(env.getValue());
797
                }
798
            } else if (type.equals("java.lang.Boolean")) {
799
                value = Boolean.valueOf(env.getValue());
800
            } else if (type.equals("java.lang.Double")) {
801
                if (env.getValue() == null) {
802
                    value = new Double(0);
803
                } else {
804
                    value = Double.valueOf(env.getValue());
805
                }
806
            } else if (type.equals("java.lang.Float")) {
807
                if (env.getValue() == null) {
808
                    value = new Float(0);
809
                } else {
810
                    value = Float.valueOf(env.getValue());
811
                }
812
            } else if (type.equals("java.lang.Character")) {
813
                if (env.getValue() == null) {
814
                    value = new Character((char) 0);
815
                } else {
816
                    if (env.getValue().length() == 1) {
817
                        value = new Character(env.getValue().charAt(0));
818
                    } else {
787
                    } else {
819
                        throw new IllegalArgumentException();
788
                        value = Byte.decode(env.getValue());
820
                    }
789
                    }
790
                } else if (type.equals("java.lang.Short")) {
791
                    if (env.getValue() == null) {
792
                        value = new Short((short) 0);
793
                    } else {
794
                        value = Short.decode(env.getValue());
795
                    }
796
                } else if (type.equals("java.lang.Integer")) {
797
                    if (env.getValue() == null) {
798
                        value = new Integer(0);
799
                    } else {
800
                        value = Integer.decode(env.getValue());
801
                    }
802
                } else if (type.equals("java.lang.Long")) {
803
                    if (env.getValue() == null) {
804
                        value = new Long(0);
805
                    } else {
806
                        value = Long.decode(env.getValue());
807
                    }
808
                } else if (type.equals("java.lang.Boolean")) {
809
                    value = Boolean.valueOf(env.getValue());
810
                } else if (type.equals("java.lang.Double")) {
811
                    if (env.getValue() == null) {
812
                        value = new Double(0);
813
                    } else {
814
                        value = Double.valueOf(env.getValue());
815
                    }
816
                } else if (type.equals("java.lang.Float")) {
817
                    if (env.getValue() == null) {
818
                        value = new Float(0);
819
                    } else {
820
                        value = Float.valueOf(env.getValue());
821
                    }
822
                } else if (type.equals("java.lang.Character")) {
823
                    if (env.getValue() == null) {
824
                        value = new Character((char) 0);
825
                    } else {
826
                        if (env.getValue().length() == 1) {
827
                            value = new Character(env.getValue().charAt(0));
828
                        } else {
829
                            throw new IllegalArgumentException();
830
                        }
831
                    }
832
                } else {
833
                    logger.error(sm.getString("naming.invalidEnvEntryType", env.getName()));
821
                }
834
                }
822
            } else {
835
            } catch (NumberFormatException e) {
823
                logger.error(sm.getString("naming.invalidEnvEntryType", env.getName()));
836
                logger.error(sm.getString("naming.invalidEnvEntryValue", env.getName()));
824
            }
837
            } catch (IllegalArgumentException e) {
825
        } catch (NumberFormatException e) {
838
                logger.error(sm.getString("naming.invalidEnvEntryValue", env.getName()));
826
            logger.error(sm.getString("naming.invalidEnvEntryValue", env.getName()));
839
            }           
827
        } catch (IllegalArgumentException e) {
828
            logger.error(sm.getString("naming.invalidEnvEntryValue", env.getName()));
829
        }
840
        }
830
841
        
831
        // Binding the object to the appropriate name
842
        // Binding the object to the appropriate name
832
        if (value != null) {
843
        try {
833
            try {
844
            if (logger.isDebugEnabled())
834
                if (logger.isDebugEnabled())
845
                logger.debug("  Adding environment entry " + env.getName());
835
                    logger.debug("  Adding environment entry " + env.getName());
846
            createSubcontexts(envCtx, env.getName());
836
                createSubcontexts(envCtx, env.getName());
847
            if(value != null){
837
                envCtx.bind(env.getName(), value);
848
                envCtx.bind(env.getName(), value);  
838
            } catch (NamingException e) {
839
                logger.error(sm.getString("naming.invalidEnvEntryValue", e));
840
            }
849
            }
850
        } catch (NamingException e) {
851
            logger.error(sm.getString("naming.invalidEnvEntryValue", e));
841
        }
852
        }
842
843
    }
853
    }
844
854
845
846
    /**
855
    /**
847
     * Set the specified local EJBs in the naming context.
856
     * Set the specified local EJBs in the naming context.
848
     */
857
     */
Lines 858-974 Link Here
858
     */
867
     */
859
    public void addService(ContextService service) {
868
    public void addService(ContextService service) {
860
869
861
        if (service.getWsdlfile() != null) {
870
        Reference ref = lookForLookupRef(service);
862
            URL wsdlURL = null;
871
        
872
        if(ref == null){
873
            if (service.getWsdlfile() != null) {
874
                URL wsdlURL = null;
863
875
864
            try {
865
                wsdlURL = new URL(service.getWsdlfile());
866
            } catch (MalformedURLException e) {
867
                // Ignore and carry on
868
            }
869
            if (wsdlURL == null) {
870
                try {
876
                try {
871
                    wsdlURL = ((Context) container).
877
                    wsdlURL = new URL(service.getWsdlfile());
872
                                                    getServletContext().
873
                                                    getResource(service.getWsdlfile());
874
                } catch (MalformedURLException e) {
878
                } catch (MalformedURLException e) {
875
                    // Ignore and carry on
879
                    // Ignore and carry on
876
                }
880
                }
877
            }
881
                if (wsdlURL == null) {
878
            if (wsdlURL == null) {
882
                    try {
879
                try {
883
                        wsdlURL = ((Context) container).
880
                    wsdlURL = ((Context) container).
884
                                                        getServletContext().
881
                                                    getServletContext().
885
                                                        getResource(service.getWsdlfile());
882
                                                    getResource("/" + service.getWsdlfile());
886
                    } catch (MalformedURLException e) {
883
                    logger.debug("  Changing service ref wsdl file for /" 
887
                        // Ignore and carry on
884
                                + service.getWsdlfile());
888
                    }
885
                } catch (MalformedURLException e) {
886
                    logger.error(sm.getString("naming.wsdlFailed", e));
887
                }
889
                }
890
                if (wsdlURL == null) {
891
                    try {
892
                        wsdlURL = ((Context) container).
893
                                                        getServletContext().
894
                                                        getResource("/" + service.getWsdlfile());
895
                        logger.debug("  Changing service ref wsdl file for /" 
896
                                    + service.getWsdlfile());
897
                    } catch (MalformedURLException e) {
898
                        logger.error(sm.getString("naming.wsdlFailed", e));
899
                    }
900
                }
901
                if (wsdlURL == null)
902
                    service.setWsdlfile(null);
903
                else
904
                    service.setWsdlfile(wsdlURL.toString());
888
            }
905
            }
889
            if (wsdlURL == null)
890
                service.setWsdlfile(null);
891
            else
892
                service.setWsdlfile(wsdlURL.toString());
893
        }
894
906
895
        if (service.getJaxrpcmappingfile() != null) {
907
            if (service.getJaxrpcmappingfile() != null) {
896
            URL jaxrpcURL = null;
908
                URL jaxrpcURL = null;
897
909
898
            try {
899
                jaxrpcURL = new URL(service.getJaxrpcmappingfile());
900
            } catch (MalformedURLException e) {
901
                // Ignore and carry on
902
            }
903
            if (jaxrpcURL == null) {
904
                try {
910
                try {
905
                    jaxrpcURL = ((Context) container).
911
                    jaxrpcURL = new URL(service.getJaxrpcmappingfile());
906
                                                    getServletContext().
907
                                                    getResource(service.getJaxrpcmappingfile());
908
                } catch (MalformedURLException e) {
912
                } catch (MalformedURLException e) {
909
                    // Ignore and carry on
913
                    // Ignore and carry on
910
                }
914
                }
911
            }
915
                if (jaxrpcURL == null) {
912
            if (jaxrpcURL == null) {
916
                    try {
913
                try {
917
                        jaxrpcURL = ((Context) container).
914
                    jaxrpcURL = ((Context) container).
918
                                                        getServletContext().
915
                                                    getServletContext().
919
                                                        getResource(service.getJaxrpcmappingfile());
916
                                                    getResource("/" + service.getJaxrpcmappingfile());
920
                    } catch (MalformedURLException e) {
917
                    logger.debug("  Changing service ref jaxrpc file for /" 
921
                        // Ignore and carry on
918
                                + service.getJaxrpcmappingfile());
922
                    }
919
                } catch (MalformedURLException e) {
920
                    logger.error(sm.getString("naming.wsdlFailed", e));
921
                }
923
                }
924
                if (jaxrpcURL == null) {
925
                    try {
926
                        jaxrpcURL = ((Context) container).
927
                                                        getServletContext().
928
                                                        getResource("/" + service.getJaxrpcmappingfile());
929
                        logger.debug("  Changing service ref jaxrpc file for /" 
930
                                    + service.getJaxrpcmappingfile());
931
                    } catch (MalformedURLException e) {
932
                        logger.error(sm.getString("naming.wsdlFailed", e));
933
                    }
934
                }
935
                if (jaxrpcURL == null)
936
                    service.setJaxrpcmappingfile(null);
937
                else
938
                    service.setJaxrpcmappingfile(jaxrpcURL.toString());
922
            }
939
            }
923
            if (jaxrpcURL == null)
924
                service.setJaxrpcmappingfile(null);
925
            else
926
                service.setJaxrpcmappingfile(jaxrpcURL.toString());
927
        }
928
940
929
        // Create a reference to the resource.
941
            // Create a reference to the resource.
930
        Reference ref = new ServiceRef
942
            ref = new ServiceRef
931
            (service.getName(), service.getType(), service.getServiceqname(),
943
                (service.getName(), service.getType(), service.getServiceqname(),
932
             service.getWsdlfile(), service.getJaxrpcmappingfile());
944
                 service.getWsdlfile(), service.getJaxrpcmappingfile());
933
        // Adding the additional port-component-ref, if any
945
            // Adding the additional port-component-ref, if any
934
        Iterator<String> portcomponent = service.getServiceendpoints();
946
            Iterator<String> portcomponent = service.getServiceendpoints();
935
        while (portcomponent.hasNext()) {
947
            while (portcomponent.hasNext()) {
936
            String serviceendpoint = portcomponent.next();
948
                String serviceendpoint = portcomponent.next();
937
            StringRefAddr refAddr = new StringRefAddr(ServiceRef.SERVICEENDPOINTINTERFACE, serviceendpoint);
949
                StringRefAddr refAddr = new StringRefAddr(ServiceRef.SERVICEENDPOINTINTERFACE, serviceendpoint);
938
            ref.add(refAddr);
950
                ref.add(refAddr);
939
            String portlink = service.getPortlink(serviceendpoint);
951
                String portlink = service.getPortlink(serviceendpoint);
940
            refAddr = new StringRefAddr(ServiceRef.PORTCOMPONENTLINK, portlink);
952
                refAddr = new StringRefAddr(ServiceRef.PORTCOMPONENTLINK, portlink);
941
            ref.add(refAddr);
953
                ref.add(refAddr);
942
        }
943
        // Adding the additional parameters, if any
944
        Iterator<String> handlers = service.getHandlers();
945
        while (handlers.hasNext()) {
946
            String handlername = handlers.next();
947
            ContextHandler handler = service.getHandler(handlername);
948
            HandlerRef handlerRef = new HandlerRef(handlername, handler.getHandlerclass());
949
            Iterator<String> localParts = handler.getLocalparts();
950
            while (localParts.hasNext()) {
951
                String localPart = localParts.next();
952
                String namespaceURI = handler.getNamespaceuri(localPart);
953
                handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_LOCALPART, localPart));
954
                handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_NAMESPACE, namespaceURI));
955
            }
954
            }
956
            Iterator<String> params = handler.listProperties();
955
            // Adding the additional parameters, if any
957
            while (params.hasNext()) {
956
            Iterator<String> handlers = service.getHandlers();
958
                String paramName = params.next();
957
            while (handlers.hasNext()) {
959
                String paramValue = (String) handler.getProperty(paramName);
958
                String handlername = handlers.next();
960
                handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PARAMNAME, paramName));
959
                ContextHandler handler = service.getHandler(handlername);
961
                handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PARAMVALUE, paramValue));
960
                HandlerRef handlerRef = new HandlerRef(handlername, handler.getHandlerclass());
962
            }
961
                Iterator<String> localParts = handler.getLocalparts();
963
            for (int i = 0; i < handler.getSoapRolesSize(); i++) {
962
                while (localParts.hasNext()) {
964
                handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_SOAPROLE, handler.getSoapRole(i)));
963
                    String localPart = localParts.next();
965
            }
964
                    String namespaceURI = handler.getNamespaceuri(localPart);
966
            for (int i = 0; i < handler.getPortNamesSize(); i++) {
965
                    handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_LOCALPART, localPart));
967
                handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PORTNAME, handler.getPortName(i)));
966
                    handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_NAMESPACE, namespaceURI));
968
            }
967
                }
969
            ((ServiceRef) ref).addHandler(handlerRef);
968
                Iterator<String> params = handler.listProperties();
969
                while (params.hasNext()) {
970
                    String paramName = params.next();
971
                    String paramValue = (String) handler.getProperty(paramName);
972
                    handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PARAMNAME, paramName));
973
                    handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PARAMVALUE, paramValue));
974
                }
975
                for (int i = 0; i < handler.getSoapRolesSize(); i++) {
976
                    handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_SOAPROLE, handler.getSoapRole(i)));
977
                }
978
                for (int i = 0; i < handler.getPortNamesSize(); i++) {
979
                    handlerRef.add(new StringRefAddr(HandlerRef.HANDLER_PORTNAME, handler.getPortName(i)));
980
                }
981
                ((ServiceRef) ref).addHandler(handlerRef);
982
            }            
970
        }
983
        }
971
984
        
972
        try {
985
        try {
973
            if (logger.isDebugEnabled()) {
986
            if (logger.isDebugEnabled()) {
974
                logger.debug("  Adding service ref " 
987
                logger.debug("  Adding service ref " 
Lines 988-1005 Link Here
988
     */
1001
     */
989
    public void addResource(ContextResource resource) {
1002
    public void addResource(ContextResource resource) {
990
1003
991
        // Create a reference to the resource.
1004
        Reference ref = lookForLookupRef(resource);
992
        Reference ref = new ResourceRef
1005
        if(ref == null){
993
            (resource.getType(), resource.getDescription(),
1006
            // Create a reference to the resource.
994
             resource.getScope(), resource.getAuth());
1007
            ref = new ResourceRef
995
        // Adding the additional parameters, if any
1008
                (resource.getType(), resource.getDescription(),
996
        Iterator<String> params = resource.listProperties();
1009
                 resource.getScope(), resource.getAuth());
997
        while (params.hasNext()) {
1010
            // Adding the additional parameters, if any
998
            String paramName = params.next();
1011
            Iterator<String> params = resource.listProperties();
999
            String paramValue = (String) resource.getProperty(paramName);
1012
            while (params.hasNext()) {
1000
            StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
1013
                String paramName = params.next();
1001
            ref.add(refAddr);
1014
                String paramValue = (String) resource.getProperty(paramName);
1015
                StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
1016
                ref.add(refAddr);
1017
            }            
1002
        }
1018
        }
1019
        
1003
        try {
1020
        try {
1004
            if (logger.isDebugEnabled()) {
1021
            if (logger.isDebugEnabled()) {
1005
                logger.debug("  Adding resource ref " 
1022
                logger.debug("  Adding resource ref " 
Lines 1030-1045 Link Here
1030
     */
1047
     */
1031
    public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {
1048
    public void addResourceEnvRef(ContextResourceEnvRef resourceEnvRef) {
1032
1049
1033
        // Create a reference to the resource env.
1050
        Reference ref = lookForLookupRef(resourceEnvRef);
1034
        Reference ref = new ResourceEnvRef(resourceEnvRef.getType());
1051
        
1035
        // Adding the additional parameters, if any
1052
        if(ref == null){
1036
        Iterator<String> params = resourceEnvRef.listProperties();
1053
            // Create a reference to the resource env.
1037
        while (params.hasNext()) {
1054
            ref = new ResourceEnvRef(resourceEnvRef.getType());
1038
            String paramName = params.next();
1055
            // Adding the additional parameters, if any
1039
            String paramValue = (String) resourceEnvRef.getProperty(paramName);
1056
            Iterator<String> params = resourceEnvRef.listProperties();
1040
            StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
1057
            while (params.hasNext()) {
1041
            ref.add(refAddr);
1058
                String paramName = params.next();
1059
                String paramValue = (String) resourceEnvRef.getProperty(paramName);
1060
                StringRefAddr refAddr = new StringRefAddr(paramName, paramValue);
1061
                ref.add(refAddr);
1062
            }            
1042
        }
1063
        }
1064
        
1043
        try {
1065
        try {
1044
            if (logger.isDebugEnabled())
1066
            if (logger.isDebugEnabled())
1045
                log.debug("  Adding resource env ref " + resourceEnvRef.getName());
1067
                log.debug("  Adding resource env ref " + resourceEnvRef.getName());
Lines 1209-1213 Link Here
1209
        }
1231
        }
1210
    }
1232
    }
1211
1233
1234
    
1235
    /**
1236
     * Gets look up reference from resource if exist.
1237
     * @param resourceBase resource base object
1238
     * @return lookup ref
1239
     */
1240
    private LookupJndiRef lookForLookupRef(ResourceBase resourceBase){
1241
        String lookupName = resourceBase.getLookupName();        
1242
        if((lookupName != null && !lookupName.equals(""))){
1243
            return new LookupJndiRef(lookupName);
1244
        }        
1245
        
1246
        return null;
1247
    }
1212
1248
1213
}
1249
}
(-)org/apache/catalina/deploy/ResourceBase.java (+13 lines)
Lines 43-48 Link Here
43
     * The description of this Context Element.
43
     * The description of this Context Element.
44
     */
44
     */
45
    private String description = null;
45
    private String description = null;
46
    
47
    /**
48
     * <lookup-name>
49
     */
50
    private String lookupName = null;    
46
51
47
    public String getDescription() {
52
    public String getDescription() {
48
        return (this.description);
53
        return (this.description);
Lines 141-146 Link Here
141
    void setNamingResources(NamingResources resources) {
146
    void setNamingResources(NamingResources resources) {
142
        this.resources = resources;
147
        this.resources = resources;
143
    }
148
    }
149
    
150
    public String getLookupName() {
151
        return lookupName;
152
    }
144
153
154
    public void setLookupName(String lookupName) {
155
        this.lookupName = lookupName;
156
    }    
145
157
158
146
}
159
}
(-)org/apache/catalina/deploy/WebXml.java (-8 / +8 lines)
Lines 888-894 Link Here
888
                        target.getTargetName());
888
                        target.getTargetName());
889
                sb.append("    </injection-target>\n");
889
                sb.append("    </injection-target>\n");
890
            }
890
            }
891
            // TODO lookup-name
891
            appendElement(sb, INDENT4, "lookup-name", envEntry.getLookupName());
892
            sb.append("  </env-entry>\n");
892
            sb.append("  </env-entry>\n");
893
        }
893
        }
894
        sb.append('\n');
894
        sb.append('\n');
Lines 910-916 Link Here
910
                        target.getTargetName());
910
                        target.getTargetName());
911
                sb.append("    </injection-target>\n");
911
                sb.append("    </injection-target>\n");
912
            }
912
            }
913
            // TODO lookup-name
913
            appendElement(sb, INDENT4, "lookup-name", ejbRef.getLookupName());
914
            sb.append("  </ejb-ref>\n");
914
            sb.append("  </ejb-ref>\n");
915
        }
915
        }
916
        sb.append('\n');
916
        sb.append('\n');
Lines 933-939 Link Here
933
                        target.getTargetName());
933
                        target.getTargetName());
934
                sb.append("    </injection-target>\n");
934
                sb.append("    </injection-target>\n");
935
            }
935
            }
936
            // TODO lookup-name
936
            appendElement(sb, INDENT4, "lookup-name", ejbLocalRef.getLookupName());
937
            sb.append("  </ejb-local-ref>\n");
937
            sb.append("  </ejb-local-ref>\n");
938
        }
938
        }
939
        sb.append('\n');
939
        sb.append('\n');
Lines 989-995 Link Here
989
                        target.getTargetName());
989
                        target.getTargetName());
990
                sb.append("    </injection-target>\n");
990
                sb.append("    </injection-target>\n");
991
            }
991
            }
992
            // TODO lookup-name
992
            appendElement(sb, INDENT4, "lookup-name", serviceRef.getLookupName());
993
            sb.append("  </service-ref>\n");
993
            sb.append("  </service-ref>\n");
994
        }
994
        }
995
        sb.append('\n');
995
        sb.append('\n');
Lines 1012-1018 Link Here
1012
                        target.getTargetName());
1012
                        target.getTargetName());
1013
                sb.append("    </injection-target>\n");
1013
                sb.append("    </injection-target>\n");
1014
            }
1014
            }
1015
            // TODO lookup-name
1015
            appendElement(sb, INDENT4, "lookup-name", resourceRef.getLookupName());
1016
            sb.append("  </resource-ref>\n");
1016
            sb.append("  </resource-ref>\n");
1017
        }
1017
        }
1018
        sb.append('\n');
1018
        sb.append('\n');
Lines 1035-1041 Link Here
1035
                        target.getTargetName());
1035
                        target.getTargetName());
1036
                sb.append("    </injection-target>\n");
1036
                sb.append("    </injection-target>\n");
1037
            }
1037
            }
1038
            // TODO lookup-name
1038
            appendElement(sb, INDENT4, "lookup-name", resourceEnvRef.getLookupName());
1039
            sb.append("  </resource-env-ref>\n");
1039
            sb.append("  </resource-env-ref>\n");
1040
        }
1040
        }
1041
        sb.append('\n');
1041
        sb.append('\n');
Lines 1060-1066 Link Here
1060
                        target.getTargetName());
1060
                        target.getTargetName());
1061
                sb.append("    </injection-target>\n");
1061
                sb.append("    </injection-target>\n");
1062
            }
1062
            }
1063
            // TODO lookup-name
1063
            appendElement(sb, INDENT4, "lookup-name", mdr.getLookupName());
1064
            sb.append("  </message-destination-ref>\n");
1064
            sb.append("  </message-destination-ref>\n");
1065
        }
1065
        }
1066
        sb.append('\n');
1066
        sb.append('\n');
Lines 1071-1077 Link Here
1071
            appendElement(sb, INDENT4, "display-name", md.getDisplayName());
1071
            appendElement(sb, INDENT4, "display-name", md.getDisplayName());
1072
            appendElement(sb, INDENT4, "message-destination-name",
1072
            appendElement(sb, INDENT4, "message-destination-name",
1073
                    md.getName());
1073
                    md.getName());
1074
            // TODO mapped-name
1074
            appendElement(sb, INDENT4, "lookup-name", md.getLookupName());
1075
            sb.append("  </message-destination>\n");
1075
            sb.append("  </message-destination>\n");
1076
        }
1076
        }
1077
        sb.append('\n');
1077
        sb.append('\n');
(-)org/apache/catalina/startup/WebRuleSet.java (-1 / +16 lines)
Lines 472-477 Link Here
472
                               "setLocal", 0);
472
                               "setLocal", 0);
473
        digester.addCallMethod(fullPrefix + "/ejb-local-ref/local-home",
473
        digester.addCallMethod(fullPrefix + "/ejb-local-ref/local-home",
474
                               "setHome", 0);
474
                               "setHome", 0);
475
        digester.addCallMethod(fullPrefix + "/ejb-local-ref/lookup-name",
476
                "setLookupName", 0);        
475
        configureInjectionRules(digester, "web-app/ejb-local-ref/");
477
        configureInjectionRules(digester, "web-app/ejb-local-ref/");
476
478
477
        //ejb-ref
479
        //ejb-ref
Lines 492-497 Link Here
492
                               "setHome", 0);
494
                               "setHome", 0);
493
        digester.addCallMethod(fullPrefix + "/ejb-ref/remote",
495
        digester.addCallMethod(fullPrefix + "/ejb-ref/remote",
494
                               "setRemote", 0);
496
                               "setRemote", 0);
497
        digester.addCallMethod(fullPrefix + "/ejb-ref/lookup-name",
498
                "setLookupName", 0);                        
495
        configureInjectionRules(digester, "web-app/ejb-ref/");
499
        configureInjectionRules(digester, "web-app/ejb-ref/");
496
500
497
        //env-entry
501
        //env-entry
Lines 508-513 Link Here
508
                               "setType", 0);
512
                               "setType", 0);
509
        digester.addCallMethod(fullPrefix + "/env-entry/env-entry-value",
513
        digester.addCallMethod(fullPrefix + "/env-entry/env-entry-value",
510
                               "setValue", 0);
514
                               "setValue", 0);
515
        digester.addCallMethod(fullPrefix + "/env-entry/lookup-name",
516
                "setLookupName", 0);                        
511
        configureInjectionRules(digester, "web-app/env-entry/");
517
        configureInjectionRules(digester, "web-app/env-entry/");
512
518
513
        //resource-env-ref
519
        //resource-env-ref
Lines 520-525 Link Here
520
                "setName", 0);
526
                "setName", 0);
521
        digester.addCallMethod(fullPrefix + "/resource-env-ref/resource-env-ref-type",
527
        digester.addCallMethod(fullPrefix + "/resource-env-ref/resource-env-ref-type",
522
                "setType", 0);
528
                "setType", 0);
529
        digester.addCallMethod(fullPrefix + "/resource-env-ref/lookup-name",
530
                "setLookupName", 0);                                
523
        configureInjectionRules(digester, "web-app/resource-env-ref/");
531
        configureInjectionRules(digester, "web-app/resource-env-ref/");
524
532
525
        //message-destination
533
        //message-destination
Lines 536-541 Link Here
536
                               "setLargeIcon", 0);
544
                               "setLargeIcon", 0);
537
        digester.addCallMethod(fullPrefix + "/message-destination/icon/small-icon",
545
        digester.addCallMethod(fullPrefix + "/message-destination/icon/small-icon",
538
                               "setSmallIcon", 0);
546
                               "setSmallIcon", 0);
547
        digester.addCallMethod(fullPrefix + "/message-destination/lookup-name",
548
                "setLookupName", 0);                                                        
539
        digester.addCallMethod(fullPrefix + "/message-destination/message-destination-name",
549
        digester.addCallMethod(fullPrefix + "/message-destination/message-destination-name",
540
                               "setName", 0);
550
                               "setName", 0);
541
551
Lines 555-561 Link Here
555
                               "setType", 0);
565
                               "setType", 0);
556
        digester.addCallMethod(fullPrefix + "/message-destination-ref/message-destination-usage",
566
        digester.addCallMethod(fullPrefix + "/message-destination-ref/message-destination-usage",
557
                               "setUsage", 0);
567
                               "setUsage", 0);
558
568
        digester.addCallMethod(fullPrefix + "/message-destination-ref/lookup-name",
569
                "setLookupName", 0);                                                
559
        configureInjectionRules(digester, "web-app/message-destination-ref/");
570
        configureInjectionRules(digester, "web-app/message-destination-ref/");
560
571
561
        //resource-ref
572
        //resource-ref
Lines 574-579 Link Here
574
                               "setScope", 0);
585
                               "setScope", 0);
575
        digester.addCallMethod(fullPrefix + "/resource-ref/res-type",
586
        digester.addCallMethod(fullPrefix + "/resource-ref/res-type",
576
                               "setType", 0);
587
                               "setType", 0);
588
        digester.addCallMethod(fullPrefix + "/resource-ref/lookup-name",
589
                "setLookupName", 0);                                                                
577
        configureInjectionRules(digester, "web-app/resource-ref/");
590
        configureInjectionRules(digester, "web-app/resource-ref/");
578
591
579
        //service-ref
592
        //service-ref
Lines 631-636 Link Here
631
                               "addSoapRole", 0);
644
                               "addSoapRole", 0);
632
        digester.addCallMethod(fullPrefix + "/service-ref/handler/port-name",
645
        digester.addCallMethod(fullPrefix + "/service-ref/handler/port-name",
633
                               "addPortName", 0);
646
                               "addPortName", 0);
647
        digester.addCallMethod(fullPrefix + "/service-ref/lookup-name",
648
                "setLookupName", 0);                                                        
634
        configureInjectionRules(digester, "web-app/service-ref/");
649
        configureInjectionRules(digester, "web-app/service-ref/");
635
650
636
651
(-)javax/ejb/EJB.java (+1 lines)
Lines 33-36 Link Here
33
   Class beanInterface() default java.lang.Object.class;
33
   Class beanInterface() default java.lang.Object.class;
34
   String beanName() default "";
34
   String beanName() default "";
35
   String mappedName() default "";
35
   String mappedName() default "";
36
   public String lookup() default "";
36
}
37
}
(-)javax/xml/ws/WebServiceRef.java (+1 lines)
Lines 34-37 Link Here
34
    public Class value() default java.lang.Object.class;
34
    public Class value() default java.lang.Object.class;
35
    public String wsdlLocation() default "";
35
    public String wsdlLocation() default "";
36
    public String mappedName() default "";
36
    public String mappedName() default "";
37
    public String lookup() default "";
37
}
38
}
(-)javax/annotation/Resource.java (-1 / +2 lines)
Lines 37-41 Link Here
37
    public AuthenticationType authenticationType() default AuthenticationType.CONTAINER;
37
    public AuthenticationType authenticationType() default AuthenticationType.CONTAINER;
38
    public boolean shareable() default true;
38
    public boolean shareable() default true;
39
    public String description() default "";
39
    public String description() default "";
40
    public String mappedName() default "";
40
    public String mappedName() default ""; 
41
    public String lookup() default "";
41
}
42
}

Return to bug 50019