You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-dev@axis.apache.org by sc...@apache.org on 2007/02/07 02:30:52 UTC

svn commit: r504405 - in /webservices/axis2/trunk/java/modules: jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/ jaxws/src/org/apache/axis2/jaxws/runtime/ jaxws/src/org/apache/axis2/jaxws/runtime/description/ jaxws/src/org/apache/axis2/jaxws/runti...

Author: scheu
Date: Tue Feb  6 17:30:50 2007
New Revision: 504405

URL: http://svn.apache.org/viewvc?view=rev&rev=504405
Log:
AXIS2-1800
Contributor:Rich Scheuerle
@Resource detection caching that also demonstrates *RuntimeDescription proof of concept for JAXWS.  
I also added a Resource Injection test

Added:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/OperationRuntimeDescription.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/OperationRuntimeDescriptionFactory.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/ResourceInjectionServiceRuntimeDescription.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/ResourceInjectionServiceRuntimeDescriptionFactory.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/OperationRuntimeDescriptionBuilder.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/OperationRuntimeDescriptionImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/ResourceInjectionServiceRuntimeDescriptionBuilder.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/ResourceInjectionServiceRuntimeDescriptionImpl.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/OperationRuntimeDescription.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceRuntimeDescription.java
Modified:
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/PDElement.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/injection/impl/WebServiceContextInjectorImpl.java
    webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/lifecycle/impl/EndpointLifecycleManagerImpl.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultsServiceTests.java
    webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/faultsservice/FaultsServiceSoapBindingImpl.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/OperationDescription.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceDescription.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java
    webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/PDElement.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/PDElement.java?view=diff&rev=504405&r1=504404&r2=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/PDElement.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/marshaller/impl/alt/PDElement.java Tue Feb  6 17:30:50 2007
@@ -33,12 +33,12 @@
  */
 public class PDElement {
     private ParameterDescription param;
-    private Object value;
+    private Object elementValue;
     
-    public PDElement(ParameterDescription param, Object value) {
+    public PDElement(ParameterDescription param, Object elementValue) {
         super();
         this.param = param;
-        this.value = value;
+        this.elementValue = elementValue;
     }
 
     public ParameterDescription getParam() {
@@ -46,7 +46,8 @@
     }
 
     public Object getElementValue() {
-        return value;
+       
+        return elementValue;
     }
     
 }

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/OperationRuntimeDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/OperationRuntimeDescription.java?view=auto&rev=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/OperationRuntimeDescription.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/OperationRuntimeDescription.java Tue Feb  6 17:30:50 2007
@@ -0,0 +1,23 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.jaxws.runtime.description;
+import javax.xml.bind.annotation.XmlRootElement;
+
+
+public interface OperationRuntimeDescription extends org.apache.axis2.jaxws.description.OperationRuntimeDescription {
+   
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/OperationRuntimeDescriptionFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/OperationRuntimeDescriptionFactory.java?view=auto&rev=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/OperationRuntimeDescriptionFactory.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/OperationRuntimeDescriptionFactory.java Tue Feb  6 17:30:50 2007
@@ -0,0 +1,42 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.jaxws.runtime.description;
+
+import org.apache.axis2.jaxws.description.OperationDescription;
+import org.apache.axis2.jaxws.runtime.description.impl.OperationRuntimeDescriptionBuilder;
+
+public class OperationRuntimeDescriptionFactory {
+
+    /**
+     * intentionally private
+     */
+    private OperationRuntimeDescriptionFactory() {}
+
+    /**
+     * Get or create OperationRuntimeDescription
+     * @param opDesc
+     * @return OperationRuntimeDescription
+     */
+    public static OperationRuntimeDescription get(OperationDescription opDesc) {
+        OperationRuntimeDescription opRTDesc = (OperationRuntimeDescription) opDesc.getOperationRuntimeDesc("JAXWS");
+        if (opRTDesc == null) {
+            opRTDesc = OperationRuntimeDescriptionBuilder.create(opDesc);
+            opDesc.setOperationRuntimeDesc(opRTDesc);
+        }
+        return opRTDesc;
+    }
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/ResourceInjectionServiceRuntimeDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/ResourceInjectionServiceRuntimeDescription.java?view=auto&rev=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/ResourceInjectionServiceRuntimeDescription.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/ResourceInjectionServiceRuntimeDescription.java Tue Feb  6 17:30:50 2007
@@ -0,0 +1,31 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.jaxws.runtime.description;
+
+import org.apache.axis2.jaxws.description.ServiceRuntimeDescription;
+
+
+/**
+ * Used to cache @Resource injection information
+ */
+public interface ResourceInjectionServiceRuntimeDescription extends ServiceRuntimeDescription {
+   /**
+    * @return true if @Resource is found on any Field or Method of the 
+    * Implementation class
+    */
+    boolean hasResourceAnnotation();
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/ResourceInjectionServiceRuntimeDescriptionFactory.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/ResourceInjectionServiceRuntimeDescriptionFactory.java?view=auto&rev=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/ResourceInjectionServiceRuntimeDescriptionFactory.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/ResourceInjectionServiceRuntimeDescriptionFactory.java Tue Feb  6 17:30:50 2007
@@ -0,0 +1,49 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.jaxws.runtime.description;
+
+import org.apache.axis2.jaxws.description.OperationDescription;
+import org.apache.axis2.jaxws.description.ServiceDescription;
+import org.apache.axis2.jaxws.runtime.description.impl.OperationRuntimeDescriptionBuilder;
+import org.apache.axis2.jaxws.runtime.description.impl.ResourceInjectionServiceRuntimeDescriptionBuilder;
+
+public class ResourceInjectionServiceRuntimeDescriptionFactory {
+
+    /**
+     * intentionally private
+     */
+    private ResourceInjectionServiceRuntimeDescriptionFactory() {}
+
+    /**
+     * Get or create ResourceInjectionServiceRuntimeDescription
+     * @param serviceDesc
+     * @param implClass
+     * @return OperationRuntimeDescription
+     */
+    public static ResourceInjectionServiceRuntimeDescription get(ServiceDescription serviceDesc, Class implClass) {
+        String key = ResourceInjectionServiceRuntimeDescriptionBuilder.getKey(implClass);
+        ResourceInjectionServiceRuntimeDescription  risrDesc = 
+            (ResourceInjectionServiceRuntimeDescription ) 
+                serviceDesc.getServiceRuntimeDesc(key);
+        
+        if (risrDesc == null) {
+            risrDesc = ResourceInjectionServiceRuntimeDescriptionBuilder.create(serviceDesc, implClass);
+            serviceDesc.setServiceRuntimeDesc(risrDesc);
+        }
+        return risrDesc;
+    }
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/OperationRuntimeDescriptionBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/OperationRuntimeDescriptionBuilder.java?view=auto&rev=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/OperationRuntimeDescriptionBuilder.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/OperationRuntimeDescriptionBuilder.java Tue Feb  6 17:30:50 2007
@@ -0,0 +1,38 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.jaxws.runtime.description.impl;
+
+import org.apache.axis2.jaxws.description.OperationDescription;
+import org.apache.axis2.jaxws.runtime.description.OperationRuntimeDescription;
+
+public class OperationRuntimeDescriptionBuilder {
+
+    /**
+     * Intentionally Private
+     */
+    private OperationRuntimeDescriptionBuilder() { }
+
+    /**
+     * create
+     * @param opDesc
+     * @return
+     */
+    static public OperationRuntimeDescription create(OperationDescription opDesc) {
+        OperationRuntimeDescriptionImpl ordi = new OperationRuntimeDescriptionImpl("JAXWS", opDesc);
+        return ordi;
+    }
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/OperationRuntimeDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/OperationRuntimeDescriptionImpl.java?view=auto&rev=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/OperationRuntimeDescriptionImpl.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/OperationRuntimeDescriptionImpl.java Tue Feb  6 17:30:50 2007
@@ -0,0 +1,46 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.jaxws.runtime.description.impl;
+
+import org.apache.axis2.jaxws.description.OperationDescription;
+import org.apache.axis2.jaxws.runtime.description.OperationRuntimeDescription;
+
+/**
+ *
+ *
+ */
+public class OperationRuntimeDescriptionImpl implements OperationRuntimeDescription {
+
+    OperationDescription opDesc;
+    String name;
+    
+    /**
+     * @param name
+     * @param opDesc
+     */
+    OperationRuntimeDescriptionImpl(String name, OperationDescription opDesc) {
+       this.opDesc = opDesc;
+       this.name =name;
+    }
+    public OperationDescription getOperationDescription() {
+       return opDesc;
+    }
+    public String getKey() {
+        return name;
+    }
+
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/ResourceInjectionServiceRuntimeDescriptionBuilder.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/ResourceInjectionServiceRuntimeDescriptionBuilder.java?view=auto&rev=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/ResourceInjectionServiceRuntimeDescriptionBuilder.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/ResourceInjectionServiceRuntimeDescriptionBuilder.java Tue Feb  6 17:30:50 2007
@@ -0,0 +1,134 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.jaxws.runtime.description.impl;
+
+import java.lang.reflect.Field;
+import java.lang.reflect.Method;
+import java.security.PrivilegedAction;
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.annotation.Resource;
+
+import org.apache.axis2.java.security.AccessController;
+import org.apache.axis2.jaxws.description.ServiceDescription;
+import org.apache.axis2.jaxws.runtime.description.ResourceInjectionServiceRuntimeDescription;
+
+public class ResourceInjectionServiceRuntimeDescriptionBuilder {
+
+    /**
+     * Intentionally Private
+     */
+    private ResourceInjectionServiceRuntimeDescriptionBuilder() { }
+
+    /**
+     * create
+     * @param opDesc
+     * @param implClassName
+     * @return
+     */
+    static public ResourceInjectionServiceRuntimeDescription create(ServiceDescription serviceDesc, 
+                Class implClass) {
+        ResourceInjectionServiceRuntimeDescriptionImpl desc = 
+            new ResourceInjectionServiceRuntimeDescriptionImpl(getKey(implClass), serviceDesc);
+        boolean value = hasResourceAnnotation(implClass);
+        desc.setResourceAnnotation(value);
+        return desc;
+    }
+    
+    static public String getKey(Class implClass) {
+        return "Resource Injection:" + implClass.getCanonicalName();
+    }
+    
+    /**
+     * @param implClass
+     * @return true if Field or Method has a @Resource annotation 
+     */
+    static private boolean hasResourceAnnotation(Class implClass) {
+        // Getting this information is expensive, but fortunately is cached.
+        List<Field> fields =  getFields(implClass);
+        for (Field field:fields) {
+            if (field.getAnnotation(Resource.class) != null) {
+                return true;
+            }
+        }
+        List<Method> methods = getMethods(implClass);
+        for (Method method:methods) {
+            if (method.getAnnotation(Resource.class) != null) {
+                return true;
+            }
+        }
+        return false;
+        
+    }
+    
+    /**
+     * Gets all of the fields in this class and the super classes
+     * @param beanClass
+     * @return
+     */
+    static private List<Field> getFields(final Class beanClass) {
+        // This class must remain private due to Java 2 Security concerns
+        List<Field> fields;
+        fields = (List<Field>) AccessController.doPrivileged(
+                new PrivilegedAction() {
+                    public Object run() {
+                        List<Field> fields = new ArrayList<Field>();
+                        Class cls = beanClass;
+                        while(cls != null) {
+                            Field[] fieldArray = cls.getDeclaredFields();
+                            for (Field field:fieldArray) {
+                                fields.add(field);
+                            }
+                            cls = cls.getSuperclass();
+                        }
+                        return fields; 
+                    }
+                }
+        );
+        
+        return fields;
+    }
+    
+    /**
+     * Gets all of the fields in this class and the super classes
+     * @param beanClass
+     * @return
+     */
+    static private List<Method> getMethods(final Class beanClass) {
+        // This class must remain private due to Java 2 Security concerns
+        List<Method> methods;
+        methods = (List<Method>) AccessController.doPrivileged(
+                new PrivilegedAction() {
+                    public Object run() {
+                        List<Method> methods = new ArrayList<Method>();
+                        Class cls = beanClass;
+                        while(cls != null) {
+                            Method[] methodArray = cls.getDeclaredMethods();
+                            for (Method method:methodArray) {
+                                methods.add(method);
+                            }
+                            cls = cls.getSuperclass();
+                        }
+                        return methods; 
+                    }
+                }
+        );
+        
+        return methods;
+    }
+}

Added: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/ResourceInjectionServiceRuntimeDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/ResourceInjectionServiceRuntimeDescriptionImpl.java?view=auto&rev=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/ResourceInjectionServiceRuntimeDescriptionImpl.java (added)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/runtime/description/impl/ResourceInjectionServiceRuntimeDescriptionImpl.java Tue Feb  6 17:30:50 2007
@@ -0,0 +1,37 @@
+package org.apache.axis2.jaxws.runtime.description.impl;
+
+import org.apache.axis2.jaxws.description.ServiceDescription;
+import org.apache.axis2.jaxws.runtime.description.ResourceInjectionServiceRuntimeDescription;
+
+public class ResourceInjectionServiceRuntimeDescriptionImpl implements
+        ResourceInjectionServiceRuntimeDescription {
+
+    private ServiceDescription serviceDesc;
+    private String key; 
+    private boolean _hasResourceAnnotation;
+    
+    protected ResourceInjectionServiceRuntimeDescriptionImpl(String key,
+                ServiceDescription serviceDesc) {
+        this.serviceDesc = serviceDesc;
+        this.key = key;
+    }
+
+    public boolean hasResourceAnnotation() {
+        return _hasResourceAnnotation;
+    }
+
+    public ServiceDescription getServiceDescription() {
+        return serviceDesc;
+    }
+
+    public String getKey() {
+        return key;
+    }
+
+    /** Called by Builder code
+     * @param value
+     */
+    void setResourceAnnotation(boolean value) {
+        _hasResourceAnnotation = value;
+    }
+}

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/injection/impl/WebServiceContextInjectorImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/injection/impl/WebServiceContextInjectorImpl.java?view=diff&rev=504405&r1=504404&r2=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/injection/impl/WebServiceContextInjectorImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/injection/impl/WebServiceContextInjectorImpl.java Tue Feb  6 17:30:50 2007
@@ -251,6 +251,34 @@
         return fields;
     }
     
+    /**
+     * Gets all of the fields in this class and the super classes
+     * @param beanClass
+     * @return
+     */
+    static private List<Method> getMethods(final Class beanClass) {
+        // This class must remain private due to Java 2 Security concerns
+        List<Method> methods;
+        methods = (List<Method>) AccessController.doPrivileged(
+                new PrivilegedAction() {
+                    public Object run() {
+                        List<Method> methods = new ArrayList<Method>();
+                        Class cls = beanClass;
+                        while(cls != null) {
+                            Method[] methodArray = cls.getDeclaredMethods();
+                            for (Method method:methodArray) {
+                                methods.add(method);
+                            }
+                            cls = cls.getSuperclass();
+                        }
+                        return methods; 
+                    }
+                }
+        );
+        
+        return methods;
+    }
+    
 	/*
 	 * Search for Method with @Resource Annotation
 	 */
@@ -258,7 +286,7 @@
 		if(bean == null){
 			return null;
 		}
-		Method[] methods = bean.getDeclaredMethods();
+		List<Method> methods = getMethods(bean);
 		for(Method method:methods){
 			Annotation[] annotations = method.getAnnotations();
 			for(Annotation an:annotations){

Modified: webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/lifecycle/impl/EndpointLifecycleManagerImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/lifecycle/impl/EndpointLifecycleManagerImpl.java?view=diff&rev=504405&r1=504404&r2=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/lifecycle/impl/EndpointLifecycleManagerImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/src/org/apache/axis2/jaxws/server/endpoint/lifecycle/impl/EndpointLifecycleManagerImpl.java Tue Feb  6 17:30:50 2007
@@ -32,8 +32,11 @@
 import org.apache.axis2.jaxws.context.factory.MessageContextFactory;
 import org.apache.axis2.jaxws.context.utils.ContextUitls;
 import org.apache.axis2.jaxws.core.MessageContext;
+import org.apache.axis2.jaxws.description.ServiceDescription;
 import org.apache.axis2.jaxws.handler.SoapMessageContext;
 import org.apache.axis2.jaxws.i18n.Messages;
+import org.apache.axis2.jaxws.runtime.description.ResourceInjectionServiceRuntimeDescription;
+import org.apache.axis2.jaxws.runtime.description.ResourceInjectionServiceRuntimeDescriptionFactory;
 import org.apache.axis2.jaxws.server.endpoint.injection.ResourceInjector;
 import org.apache.axis2.jaxws.server.endpoint.injection.WebServiceContextInjector;
 import org.apache.axis2.jaxws.server.endpoint.injection.factory.ResourceInjectionFactory;
@@ -93,7 +96,7 @@
             //Add MessageContext for this request.
             wsContext.setSoapMessageContext(soapMessageContext);
             //inject WebServiceContext
-            injectWebServiceContext(wsContext, serviceimpl);
+            injectWebServiceContext(mc, wsContext, serviceimpl);
             //InvokePostConstruct
             invokePostConstruct();
             serviceContext.setProperty(WEBSERVICE_MESSAGE_CONTEXT, wsContext);
@@ -226,9 +229,24 @@
 		return soapMessageContext;
 	 }
 	 
-	private void injectWebServiceContext(WebServiceContext wsContext, Object serviceInstance) throws ResourceInjectionException{
-	   ResourceInjector ri =ResourceInjectionFactory.createResourceInjector(WebServiceContext.class);
-	   ri.inject(wsContext, serviceInstance);
+	private void injectWebServiceContext(MessageContext mc, WebServiceContext wsContext, Object serviceInstance) throws ResourceInjectionException{
+       
+       // See if we have cached information about resource injection for this service and class
+       boolean tryInjection = true;
+       ServiceDescription serviceDesc = mc.getServiceDescription();
+       if (serviceDesc != null) {
+           ResourceInjectionServiceRuntimeDescription risrDesc = 
+               ResourceInjectionServiceRuntimeDescriptionFactory.get(serviceDesc, serviceInstance.getClass());
+           // If there are no @Resource annotations then don't bother with resource injection
+           if (risrDesc != null && !risrDesc.hasResourceAnnotation()) {
+               tryInjection = false;
+           }
+       }
+           
+       if (tryInjection) {
+           ResourceInjector ri =ResourceInjectionFactory.createResourceInjector(WebServiceContext.class);
+           ri.inject(wsContext, serviceInstance);
+       }
 		   
 	}
 	   

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultsServiceTests.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultsServiceTests.java?view=diff&rev=504405&r1=504404&r2=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultsServiceTests.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/FaultsServiceTests.java Tue Feb  6 17:30:50 2007
@@ -402,4 +402,16 @@
         assertTrue(soapFault != null);
         assertTrue(soapFault.getFaultString().equals("This is a WebServiceException"));
     }
+    
+    /**
+     * Tests Resource injection
+     */
+    public void testResourceInjection() throws Exception {
+        FaultsServicePortType proxy = getProxy();
+        
+        float total = proxy.getQuote("INJECTION");
+        
+        // If resource injection occurred properly, then the a value of 1234567 is expected
+        assertTrue("Resource Injection Failed", total == 1234567);
+    }
 }

Modified: webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/faultsservice/FaultsServiceSoapBindingImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/faultsservice/FaultsServiceSoapBindingImpl.java?view=diff&rev=504405&r1=504404&r2=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/faultsservice/FaultsServiceSoapBindingImpl.java (original)
+++ webservices/axis2/trunk/java/modules/jaxws/test/org/apache/axis2/jaxws/sample/faultsservice/FaultsServiceSoapBindingImpl.java Tue Feb  6 17:30:50 2007
@@ -13,6 +13,9 @@
 
 package org.apache.axis2.jaxws.sample.faultsservice;
 
+import javax.annotation.PostConstruct;
+import javax.annotation.PreDestroy;
+import javax.annotation.Resource;
 import javax.jws.WebService;
 import javax.xml.namespace.QName;
 import javax.xml.soap.Detail;
@@ -22,6 +25,7 @@
 import javax.xml.soap.SOAPFactory;
 import javax.xml.soap.SOAPFault;
 import javax.xml.ws.Holder;
+import javax.xml.ws.WebServiceContext;
 import javax.xml.ws.WebServiceException;
 import javax.xml.ws.soap.SOAPFaultException;
 
@@ -44,6 +48,9 @@
 
 public class FaultsServiceSoapBindingImpl implements FaultsServicePortType {
 
+    private WebServiceContext ctx = null;
+    private boolean init = false;
+    
     /**
      * Throws wrapper exceptions for fault beans
      */
@@ -70,6 +77,12 @@
             BaseFault bf = new BaseFault();
             bf.setA(400);
             throw new BaseFault_Exception("Server throws BaseFault_Exception", bf);
+        } else if (tickerSymbol.equals("INJECTION")) {
+           if (ctx != null && init) {
+               // Only return this value if the context is injected and 
+               // the initialization method is invoked
+               return 1234567; 
+           }
         }
         return 100;
     }
@@ -169,5 +182,26 @@
         SOAPBody body = env.addBody();
         soapFault = body.addFault();
         return soapFault;
+    }
+    
+    @PostConstruct
+    public void initialize(){
+        //Called after resource injection and before a method is called.
+        System.out.println("Calling PostConstruct to Initialize");
+        this.init = true;
+    }
+    
+    @PreDestroy
+    public void distructor(){
+        //Called before the scope of request or session or application ends.
+        
+        System.out.println("Calling PreDestroy ");
+        
+    }
+    @Resource
+    private void setCtx(WebServiceContext ctx) {
+        // The setter is private.  This should not matter because the engine
+        // should still make it accessible.
+        this.ctx = ctx;
     }
 }

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/OperationDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/OperationDescription.java?view=diff&rev=504405&r1=504404&r2=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/OperationDescription.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/OperationDescription.java Tue Feb  6 17:30:50 2007
@@ -145,4 +145,7 @@
     public javax.jws.soap.SOAPBinding.Style getSoapBindingStyle();
     public javax.jws.soap.SOAPBinding.Use getSoapBindingUse();
 
+    public OperationRuntimeDescription getOperationRuntimeDesc(String name);
+    public void setOperationRuntimeDesc(OperationRuntimeDescription ord);
+    
 }

Added: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/OperationRuntimeDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/OperationRuntimeDescription.java?view=auto&rev=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/OperationRuntimeDescription.java (added)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/OperationRuntimeDescription.java Tue Feb  6 17:30:50 2007
@@ -0,0 +1,41 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.jaxws.description;
+
+/**
+ * A OperationRuntimeDescription object contains immutable data that is needed during the 
+ * runtime (i.e. to cache marshal and demarshal information).  The 
+ * OperationRuntimeDescription object must be immutable so that it can safely accessed by 
+ * multiple theads without synchronization.
+ *  
+ * It cannot be used to store information that may not be available in different threads/
+ * classloaders (i.e. it cannot have references to Class objects)
+ * 
+ * The actual OperationRuntimeDescription objects are accessed via the key.
+ */
+public interface OperationRuntimeDescription {
+    
+   /**
+    * @return OperationDesc parent
+    */
+    public OperationDescription getOperationDescription();
+   
+   /**
+    * @return String (i.e. JAXWS)
+    */
+    public String getKey();
+}

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceDescription.java?view=diff&rev=504405&r1=504404&r2=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceDescription.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceDescription.java Tue Feb  6 17:30:50 2007
@@ -74,5 +74,8 @@
      * @return
      */
     public List<QName> getPorts();
+    
+    public ServiceRuntimeDescription getServiceRuntimeDesc(String name);
+    public void setServiceRuntimeDesc(ServiceRuntimeDescription ord);
 
 }

Added: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceRuntimeDescription.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceRuntimeDescription.java?view=auto&rev=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceRuntimeDescription.java (added)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/ServiceRuntimeDescription.java Tue Feb  6 17:30:50 2007
@@ -0,0 +1,40 @@
+/*
+ * Copyright 2004,2005 The Apache Software Foundation.
+ * Copyright 2006 International Business Machines Corp.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.axis2.jaxws.description;
+
+/**
+ * A ServiceRuntimeDescription object contains immutable data that is needed during the 
+ * runtime (i.e. to detect @Resource injection).  
+ * The ServiceRuntimeDescription must be immutable so that it can safely accessed by 
+ * multiple theads without synchronization.  
+ * It cannot be used to store information that may not be available in different threads/
+ * classloaders (i.e. it cannot have references to Class objects)
+ * 
+ * The actual ServiceRuntimeDescription objects are accessed via the key.
+ */
+public interface ServiceRuntimeDescription {
+    
+   /**
+    * @return OperationDesc parent
+    */
+    public ServiceDescription getServiceDescription();
+   
+   /**
+    * @return String 
+    */
+    public String getKey();
+}

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java?view=diff&rev=504405&r1=504404&r2=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/OperationDescriptionImpl.java Tue Feb  6 17:30:50 2007
@@ -23,8 +23,10 @@
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
+import java.util.Map;
 import java.util.concurrent.Future;
 
 import javax.jws.Oneway;
@@ -49,6 +51,7 @@
 import org.apache.axis2.jaxws.description.OperationDescription;
 import org.apache.axis2.jaxws.description.OperationDescriptionJava;
 import org.apache.axis2.jaxws.description.OperationDescriptionWSDL;
+import org.apache.axis2.jaxws.description.OperationRuntimeDescription;
 import org.apache.axis2.jaxws.description.ParameterDescription;
 import org.apache.axis2.jaxws.description.ParameterDescriptionJava;
 import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
@@ -147,6 +150,9 @@
     private Boolean             webResultHeader;
     private Method serviceImplMethod;
     private boolean serviceImplMethodFound = false;
+    
+    // RUNTIME INFORMATION
+    Map<String, OperationRuntimeDescription> runtimeDescMap = Collections.synchronizedMap(new HashMap<String, OperationRuntimeDescription>());
 
     OperationDescriptionImpl(Method method, EndpointInterfaceDescription parent) {
         // TODO: Look for WebMethod anno; get name and action off of it
@@ -1382,6 +1388,16 @@
     		type = pd.getParameterActualType().getName();
     	}
     	return type;
+    }
+
+    public OperationRuntimeDescription getOperationRuntimeDesc(String name) {
+        // TODO Add toString support
+        return runtimeDescMap.get(name);
+    }
+
+    public void setOperationRuntimeDesc(OperationRuntimeDescription ord) {
+        // TODO Add toString support
+        runtimeDescMap.put(ord.getKey(), ord);
     }
     
     public String toString() {

Modified: webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java
URL: http://svn.apache.org/viewvc/webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java?view=diff&rev=504405&r1=504404&r2=504405
==============================================================================
--- webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java (original)
+++ webservices/axis2/trunk/java/modules/metadata/src/org/apache/axis2/jaxws/description/impl/ServiceDescriptionImpl.java Tue Feb  6 17:30:50 2007
@@ -21,6 +21,7 @@
 import java.net.URL;
 import java.net.UnknownHostException;
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Hashtable;
@@ -46,6 +47,7 @@
 import org.apache.axis2.jaxws.description.ServiceDescription;
 import org.apache.axis2.jaxws.description.ServiceDescriptionJava;
 import org.apache.axis2.jaxws.description.ServiceDescriptionWSDL;
+import org.apache.axis2.jaxws.description.ServiceRuntimeDescription;
 import org.apache.axis2.jaxws.description.builder.DescriptionBuilderComposite;
 import org.apache.axis2.jaxws.description.builder.MDQConstants;
 import org.apache.axis2.jaxws.description.builder.MethodDescriptionComposite;
@@ -83,6 +85,10 @@
     private DescriptionBuilderComposite	composite = null;
     private boolean isServerSide = false;
     
+//  RUNTIME INFORMATION
+    Map<String, ServiceRuntimeDescription> runtimeDescMap = Collections.synchronizedMap(new HashMap<String, ServiceRuntimeDescription>());
+
+    
     /**
      * This is (currently) the client-side-only constructor
      * Construct a service description hierachy based on WSDL (may be null), the Service class, and 
@@ -1071,6 +1077,16 @@
             }
         }
         return portsUsingAddress;
+    }
+    
+    public ServiceRuntimeDescription getServiceRuntimeDesc(String name) {
+        // TODO Add toString support
+        return runtimeDescMap.get(name);
+    }
+
+    public void setServiceRuntimeDesc(ServiceRuntimeDescription srd) {
+        // TODO Add toString support
+        runtimeDescMap.put(srd.getKey(), srd);
     }
     
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org