With even it's even simpler I guess.

JLouis


2014-02-17 14:33 GMT+01:00 Romain Manni-Bucau <rmannibu...@gmail.com>:

> Hi Andy
>
> please revert it since it was the first version of the code we had in
> tomee jaxrs integration and needed to be refactored to match real
> needs. If your issue is with wadl generator please do something
> specific to wadlgenerator in configureFactory (if provider instanceof
> wadlgenerator replace cxf one or sthg like that)
>
>
>
> Romain Manni-Bucau
> Twitter: @rmannibucau
> Blog: http://rmannibucau.wordpress.com/
> LinkedIn: http://fr.linkedin.com/in/rmannibucau
> Github: https://github.com/rmannibucau
>
>
>
>
> ---------- Forwarded message ----------
> From:  <andygumbre...@apache.org>
> Date: 2014-02-17 14:12 GMT+01:00
> Subject: svn commit: r1568973 - in /tomee/tomee/trunk:
>
> server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
>
> tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ServerListener.java
> To: comm...@tomee.apache.org
>
>
> Author: andygumbrecht
> Date: Mon Feb 17 13:12:50 2014
> New Revision: 1568973
>
> URL: http://svn.apache.org/r1568973
> Log:
> Visit https://issues.apache.org/jira/browse/TOMEE-1126.
> Synchronization.
>
> Modified:
>
> tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
>
> tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ServerListener.java
>
> Modified:
> tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
> URL:
> http://svn.apache.org/viewvc/tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java?rev=1568973&r1=1568972&r2=1568973&view=diff
>
> ==============================================================================
> ---
> tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
> (original)
> +++
> tomee/tomee/trunk/server/openejb-cxf-rs/src/main/java/org/apache/openejb/server/cxf/rs/CxfRsHttpListener.java
> Mon Feb 17 13:12:50 2014
> @@ -79,7 +79,15 @@ import java.lang.annotation.Annotation;
>  import java.lang.reflect.Constructor;
>  import java.net.HttpURLConnection;
>  import java.net.URL;
> -import java.util.*;
> +import java.util.ArrayList;
> +import java.util.Arrays;
> +import java.util.Collection;
> +import java.util.Collections;
> +import java.util.HashMap;
> +import java.util.HashSet;
> +import java.util.List;
> +import java.util.Map;
> +import java.util.Set;
>  import java.util.concurrent.CopyOnWriteArrayList;
>  import java.util.logging.Level;
>  import java.util.regex.Pattern;
> @@ -120,7 +128,22 @@ public class CxfRsHttpListener implement
>          STATIC_CONTENT_TYPES.put("pdf", "application/pdf");
>          STATIC_CONTENT_TYPES.put("xsd", "application/xml");
>
> -        for (final ProviderInfo<RequestHandler> rh :
>
> org.apache.cxf.jaxrs.provider.ProviderFactory.getSharedInstance().getRequestHandlers())
> {
> +        final String clazz =
> SystemInstance.get().getProperty("openejb.cxf-rs.provider.classes",
> "default");
> +        final org.apache.cxf.jaxrs.provider.ProviderFactory factory =
> org.apache.cxf.jaxrs.provider.ProviderFactory.getSharedInstance();
> +
> +        if (!"default".equals(clazz)) {
> +
> +            final String[] classes = clazz.split(",");
> +            for (final String aClass : classes) {
> +                try {
> +
>
> factory.setUserProviders(Arrays.asList(Class.forName(clazz).newInstance()));
> +                } catch (final Exception e) {
> +                    LOGGER.warning("Failed to load class: " + clazz +
> " - " + e.getMessage());
> +                }
> +            }
> +        }
> +
> +        for (final ProviderInfo<RequestHandler> rh :
> factory.getRequestHandlers()) {
>              final RequestHandler provider = rh.getProvider();
>              if (WadlGenerator.class.isInstance(provider)) {
>                  final WadlGenerator wadlGenerator =
> WadlGenerator.class.cast(provider);
>
> Modified:
> tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ServerListener.java
> URL:
> http://svn.apache.org/viewvc/tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ServerListener.java?rev=1568973&r1=1568972&r2=1568973&view=diff
>
> ==============================================================================
> ---
> tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ServerListener.java
> (original)
> +++
> tomee/tomee/trunk/tomee/tomee-catalina/src/main/java/org/apache/tomee/catalina/ServerListener.java
> Mon Feb 17 13:12:50 2014
> @@ -31,6 +31,7 @@ import org.apache.tomee.loader.TomcatHel
>  import java.io.IOException;
>  import java.lang.reflect.Field;
>  import java.util.Properties;
> +import java.util.concurrent.atomic.AtomicBoolean;
>  import java.util.logging.Level;
>  import java.util.logging.Logger;
>
> @@ -39,96 +40,99 @@ import java.util.logging.Logger;
>  public class ServerListener implements LifecycleListener {
>      private static final Logger LOGGER =
> Logger.getLogger(ServerListener.class.getName());
>
> -    static private boolean listenerInstalled;
> +    static private final AtomicBoolean listenerInstalled = new
> AtomicBoolean(false);
>
> -    public void lifecycleEvent(LifecycleEvent event) {
> +    public void lifecycleEvent(final LifecycleEvent event) {
>          if (Lifecycle.BEFORE_INIT_EVENT.equals(event.getType()) &&
> StandardServer.class.isInstance(event.getSource())) {
>              installServerInfo();
>          }
>
> -        // only install once
> -        if (listenerInstalled ||
> !Lifecycle.AFTER_INIT_EVENT.equals(event.getType())) return;
> -        if (!(event.getSource() instanceof StandardServer)) return;
> +        synchronized (listenerInstalled) {
>
> -        try {
> -            final StandardServer server = (StandardServer)
> event.getSource();
> -
> -            TomcatHelper.setServer(server);
> -
> -            final Properties properties = new Properties();
> -            System.getProperties().setProperty("openejb.embedder.source",
> getClass().getSimpleName());
> -            properties.setProperty("openejb.embedder.source",
> getClass().getSimpleName());
> +            // only install once
> +            if (listenerInstalled.get() ||
> !Lifecycle.AFTER_INIT_EVENT.equals(event.getType())) return;
> +            if (!(event.getSource() instanceof StandardServer)) return;
>
> +            try {
> +                final StandardServer server = (StandardServer)
> event.getSource();
>
> -            // if SystemInstance is already initialized, then return
> -            if (SystemInstance.isInitialized()) {
> -                return;
> -            }
> -
> -            // set the openejb.loader property to tomcat-system
> -            properties.setProperty("openejb.loader", "tomcat-system");
> -
> -            // Get the value of catalina.home and set it to openejb.home
> -            String catalinaHome = System.getProperty("catalina.home");
> -            properties.setProperty("openejb.home", catalinaHome);
> +                TomcatHelper.setServer(server);
>
> -            //Sets system property for openejb.home
> -            System.setProperty("openejb.home", catalinaHome);
> +                final Properties properties = new Properties();
> +
> System.getProperties().setProperty("openejb.embedder.source",
> getClass().getSimpleName());
> +                properties.setProperty("openejb.embedder.source",
> getClass().getSimpleName());
>
> -            //get the value of catalina.base and set it to openejb.base
> -            String catalinaBase = System.getProperty("catalina.base");
> -            properties.setProperty("openejb.base", catalinaBase);
>
> -            //Sets system property for openejb.base
> -            System.setProperty("openejb.base", catalinaBase);
> +                // if SystemInstance is already initialized, then return
> +                if (SystemInstance.isInitialized()) {
> +                    return;
> +                }
>
> +                // set the openejb.loader property to tomcat-system
> +                properties.setProperty("openejb.loader", "tomcat-system");
>
> -            // System.setProperty("tomcat.version", "x.y.z.w");
> -            // System.setProperty("tomcat.built", "mmm dd yyyy hh:mm:ss");
> -            // set the System properties, tomcat.version, tomcat.built
> -            try {
> -                ClassLoader classLoader =
> ServerListener.class.getClassLoader();
> -                Properties tomcatServerInfo =
>
> IO.readProperties(classLoader.getResourceAsStream("org/apache/catalina/util/ServerInfo.properties"),
> new Properties());
> +                // Get the value of catalina.home and set it to
> openejb.home
> +                final String catalinaHome =
> System.getProperty("catalina.home");
> +                properties.setProperty("openejb.home", catalinaHome);
> +
> +                //Sets system property for openejb.home
> +                System.setProperty("openejb.home", catalinaHome);
> +
> +                //get the value of catalina.base and set it to
> openejb.base
> +                final String catalinaBase =
> System.getProperty("catalina.base");
> +                properties.setProperty("openejb.base", catalinaBase);
> +
> +                //Sets system property for openejb.base
> +                System.setProperty("openejb.base", catalinaBase);
> +
> +
> +                // System.setProperty("tomcat.version", "x.y.z.w");
> +                // System.setProperty("tomcat.built", "mmm dd yyyy
> hh:mm:ss");
> +                // set the System properties, tomcat.version, tomcat.built
> +                try {
> +                    final ClassLoader classLoader =
> ServerListener.class.getClassLoader();
> +                    final Properties tomcatServerInfo =
>
> IO.readProperties(classLoader.getResourceAsStream("org/apache/catalina/util/ServerInfo.properties"),
> new Properties());
> +
> +                    String serverNumber =
> tomcatServerInfo.getProperty("server.number");
> +                    if (serverNumber == null) {
> +                        // Tomcat5 only has server.info
> +                        final String serverInfo =
> tomcatServerInfo.getProperty("server.info");
> +                        if (serverInfo != null) {
> +                            final int slash = serverInfo.indexOf('/');
> +                            serverNumber = serverInfo.substring(slash +
> 1);
> +                        }
> +                    }
> +                    if (serverNumber != null) {
> +                        System.setProperty("tomcat.version",
> serverNumber);
> +                    }
>
> -                String serverNumber =
> tomcatServerInfo.getProperty("server.number");
> -                if (serverNumber == null) {
> -                    // Tomcat5 only has server.info
> -                    String serverInfo =
> tomcatServerInfo.getProperty("server.info");
> -                    if (serverInfo != null) {
> -                        int slash = serverInfo.indexOf('/');
> -                        serverNumber = serverInfo.substring(slash + 1);
> +                    final String serverBuilt =
> tomcatServerInfo.getProperty("server.built");
> +                    if (serverBuilt != null) {
> +                        System.setProperty("tomcat.built", serverBuilt);
>                      }
> -                }
> -                if (serverNumber != null) {
> -                    System.setProperty("tomcat.version", serverNumber);
> +                } catch (final Throwable e) {
> +                    // no-op
>                  }
>
> -                String serverBuilt =
> tomcatServerInfo.getProperty("server.built");
> -                if (serverBuilt != null) {
> -                    System.setProperty("tomcat.built", serverBuilt);
> +                // manage additional libraries
> +                try {
> +                    ProvisioningUtil.addAdditionalLibraries();
> +                } catch (final IOException e) {
> +                    // ignored
>                  }
> -            } catch (Throwable e) {
> -                // no-op
> -            }
>
> -            // manage additional libraries
> -            try {
> -                ProvisioningUtil.addAdditionalLibraries();
> -            } catch (IOException e) {
> -                // ignored
> -            }
> +                final TomcatLoader loader = new TomcatLoader();
> +                loader.init(properties);
>
> -            TomcatLoader loader = new TomcatLoader();
> -            loader.init(properties);
> -
> -            listenerInstalled = true;
> -        } catch (Exception e) {
> -            LOGGER.log(Level.SEVERE, "TomEE Listener can't start
> OpenEJB", e);
> -            // e.printStackTrace(System.err);
> +                listenerInstalled.set(true);
> +            } catch (final Exception e) {
> +                LOGGER.log(Level.SEVERE, "TomEE Listener can't start
> OpenEJB", e);
> +                // e.printStackTrace(System.err);
> +            }
>          }
>      }
>
> -    private void installServerInfo() {
> +    private synchronized void installServerInfo() {
>          if
> (SystemInstance.get().getOptions().get("tomee.keep-server-info",
> false)) {
>              return;
>          }
> @@ -146,7 +150,7 @@ public class ServerListener implements L
>              final String version = OpenEjbVersion.get().getVersion();
>              final String tomeeVersion = (Integer.parseInt("" +
> version.charAt(0)) - 3) + version.substring(1, version.length());
>              field.set(null, value.substring(0, slash) + " (TomEE)" +
> value.substring(slash) + " (" + tomeeVersion + ")");
> -        } catch (Exception e) {
> +        } catch (final Exception e) {
>              // no-op
>          } finally {
>              if (field != null) {
>



-- 
Jean-Louis

Reply via email to