Author: rmannibucau
Date: Thu Jul 26 12:50:16 2012
New Revision: 1365969

URL: http://svn.apache.org/viewvc?rev=1365969&view=rev
Log:
http://people.apache.org/~rmannibucau/tomee-maven-plugin/plugin-info.html 
deployment properties are always passed to portdata and a hook is added to be 
able to specify a user specific configurator by endpoint

Added:
    
openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/EndpointConfigurator.java
    
openejb/trunk/openejb/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/CustomEndpointConfiguratorTest.java
Modified:
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/WsBuilder.java
    
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/PortData.java
    
openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ConfigureCxfSecurity.java
    
openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbEndpoint.java

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/WsBuilder.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/WsBuilder.java?rev=1365969&r1=1365968&r2=1365969&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/WsBuilder.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/assembler/classic/WsBuilder.java
 Thu Jul 26 12:50:16 2012
@@ -49,9 +49,7 @@ public class WsBuilder {
         portData.setLocation(port.location);
 
         portData.setSecure("WS-SECURITY".equals(port.authMethod));
-        if (portData.isSecure()) {
-           portData.setSecurityProperties(port.properties);
-       }
+        portData.setProperties(port.properties);
 
         return portData;
     }

Modified: 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/PortData.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/PortData.java?rev=1365969&r1=1365968&r2=1365969&view=diff
==============================================================================
--- 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/PortData.java
 (original)
+++ 
openejb/trunk/openejb/container/openejb-core/src/main/java/org/apache/openejb/core/webservices/PortData.java
 Thu Jul 26 12:50:16 2012
@@ -39,7 +39,7 @@ public class PortData implements PortInf
     private QName wsdlService;
     private String location;
     private boolean secure;
-    private Properties securityProperties;
+    private Properties properties;
 
     public String getPortId() {
         return portId;
@@ -129,12 +129,12 @@ public class PortData implements PortInf
         return secure;
     }
 
-    public Properties getSecurityProperties() {
-        return securityProperties;
+    public Properties getProperties() {
+        return properties;
     }
 
-    public void setSecurityProperties(Properties securityProperties) {
-        this.securityProperties = securityProperties;
+    public void setProperties(Properties properties) {
+        this.properties = properties;
     }
     
     

Modified: 
openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ConfigureCxfSecurity.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ConfigureCxfSecurity.java?rev=1365969&r1=1365968&r2=1365969&view=diff
==============================================================================
--- 
openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ConfigureCxfSecurity.java
 (original)
+++ 
openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ConfigureCxfSecurity.java
 Thu Jul 26 12:50:16 2012
@@ -21,6 +21,7 @@ import org.apache.cxf.binding.soap.saaj.
 import org.apache.cxf.endpoint.Endpoint;
 import org.apache.cxf.ws.security.wss4j.WSS4JInInterceptor;
 import org.apache.cxf.ws.security.wss4j.WSS4JOutInterceptor;
+import org.apache.openejb.core.webservices.PortData;
 import org.apache.openejb.util.LogCategory;
 import org.apache.openejb.util.Logger;
 
@@ -42,8 +43,9 @@ public class ConfigureCxfSecurity {
             new OpenEJBLoginValidator());
     }};
 
-    public static final void setupWSS4JChain(Endpoint endpoint, Properties 
inProps) {
+    private static final String OPENEJB_ENDPOINT_CONFIGURATOR = 
"openejb.endpoint.configurator";
 
+    public static final void setupWSS4JChain(Endpoint endpoint, Properties 
inProps) {
         final Map<String, Object> in = getPropsFromProperties(inProps, 
"wss4j.in.");
         final Map<String, Object> out = getPropsFromProperties(inProps, 
"wss4j.out.");
         if (!in.containsKey(WSS4JInInterceptor.VALIDATOR_MAP)) {
@@ -114,8 +116,24 @@ public class ConfigureCxfSecurity {
 
     }
 
-    public static final void configure(Endpoint endpoint, Properties p) {
-        setupWSS4JChain(endpoint, p);
+    public static final void configure(Endpoint endpoint, PortData port) {
+        final Properties p = port.getProperties();
+        if (p != null && p.containsKey(OPENEJB_ENDPOINT_CONFIGURATOR)) {
+            final String classname = 
p.getProperty(OPENEJB_ENDPOINT_CONFIGURATOR);
+            try {
+                final EndpointConfigurator configurator = 
(EndpointConfigurator) 
Thread.currentThread().getContextClassLoader().loadClass(classname).newInstance();
+                configurator.configure(endpoint, p);
+            } catch (Exception e) {
+                LOGGER.error("can't configure endpoint " + endpoint + " with 
configurator " + classname + ", using default config", e);
+                if (port.isSecure()) {
+                    setupWSS4JChain(endpoint, p);
+                }
+            }
+        } else {
+            if (port.isSecure()) {
+                setupWSS4JChain(endpoint, p);
+            }
+        }
     }
 
     /**

Added: 
openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/EndpointConfigurator.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/EndpointConfigurator.java?rev=1365969&view=auto
==============================================================================
--- 
openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/EndpointConfigurator.java
 (added)
+++ 
openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/EndpointConfigurator.java
 Thu Jul 26 12:50:16 2012
@@ -0,0 +1,25 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb.server.cxf;
+
+import org.apache.cxf.endpoint.Endpoint;
+
+import java.util.Properties;
+
+public interface EndpointConfigurator {
+    void configure(Endpoint endpoint, Properties inProps);
+}

Modified: 
openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbEndpoint.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbEndpoint.java?rev=1365969&r1=1365968&r2=1365969&view=diff
==============================================================================
--- 
openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbEndpoint.java
 (original)
+++ 
openejb/trunk/openejb/server/openejb-cxf/src/main/java/org/apache/openejb/server/cxf/ejb/EjbEndpoint.java
 Thu Jul 26 12:50:16 2012
@@ -90,9 +90,7 @@ public class EjbEndpoint extends CxfEndp
         }
 
         // Install WSS4J interceptor
-        if (port.isSecure()) {
-            ConfigureCxfSecurity.configure(endpoint, 
port.getSecurityProperties());
-        }
+        ConfigureCxfSecurity.configure(endpoint, port);
 
     }
 

Added: 
openejb/trunk/openejb/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/CustomEndpointConfiguratorTest.java
URL: 
http://svn.apache.org/viewvc/openejb/trunk/openejb/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/CustomEndpointConfiguratorTest.java?rev=1365969&view=auto
==============================================================================
--- 
openejb/trunk/openejb/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/CustomEndpointConfiguratorTest.java
 (added)
+++ 
openejb/trunk/openejb/server/openejb-cxf/src/test/java/org/apache/openejb/server/cxf/CustomEndpointConfiguratorTest.java
 Thu Jul 26 12:50:16 2012
@@ -0,0 +1,86 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.openejb.server.cxf;
+
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.openejb.OpenEjbContainer;
+import org.apache.openejb.config.EjbModule;
+import org.apache.openejb.jee.EjbJar;
+import org.apache.openejb.jee.Empty;
+import org.apache.openejb.jee.SingletonBean;
+import org.apache.openejb.jee.oejb3.EjbDeployment;
+import org.apache.openejb.jee.oejb3.OpenejbJar;
+import org.apache.openejb.junit.ApplicationComposer;
+import org.apache.openejb.junit.Configuration;
+import org.apache.openejb.junit.Module;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+import javax.ejb.LocalBean;
+import javax.ejb.Singleton;
+import javax.jws.WebService;
+import java.util.Properties;
+
+import static org.junit.Assert.assertTrue;
+
+@RunWith(ApplicationComposer.class)
+public class CustomEndpointConfiguratorTest {
+    @Configuration
+    public Properties configuration() {
+        return new Properties() {{
+            setProperty(OpenEjbContainer.OPENEJB_EMBEDDED_REMOTABLE, "true");
+        }};
+    }
+
+    @Module
+    public EjbModule module() {
+        final EjbModule module = new EjbModule(new EjbJar());
+        module.setOpenejbJar(new OpenejbJar());
+
+        final SingletonBean bean = new SingletonBean(MyWebservice.class);
+        bean.setLocalBean(new Empty());
+
+        final EjbDeployment deployment = new EjbDeployment(bean);
+        
deployment.getProperties().setProperty("openejb.endpoint.configurator", 
CustomConfigurator.class.getName());
+
+        module.getOpenejbJar().addEjbDeployment(deployment);
+        module.getEjbJar().addEnterpriseBean(bean);
+
+        return module;
+    }
+
+    @Test
+    public void checkConfiguratorWasCalled() {
+        assertTrue(CustomConfigurator.ok);
+    }
+
+    @LocalBean
+    @Singleton
+    @WebService
+    public static class MyWebservice {
+        // not needed for this test
+    }
+
+    public static class CustomConfigurator implements EndpointConfigurator {
+        public static boolean ok = false;
+
+        @Override
+        public void configure(final Endpoint endpoint, final Properties 
inProps) {
+            ok = true;
+        }
+    }
+}


Reply via email to