openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject svn commit: r1765895 - in /openwebbeans/microwave/trunk: microwave-arquillian/src/main/java/org/apache/microwave/arquillian/ microwave-core/src/main/java/org/apache/microwave/ microwave-core/src/main/java/org/apache/microwave/cxf/ microwave-core/src/ma...
Date Thu, 20 Oct 2016 22:19:50 GMT
Author: rmannibucau
Date: Thu Oct 20 22:19:49 2016
New Revision: 1765895

URL: http://svn.apache.org/viewvc?rev=1765895&view=rev
Log:
avoid double 'scanning' - just jar finding, allows DefaultServlet to be used

Added:
    openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/tomcat/TomcatAutoInitializer.java
Modified:
    openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveConfiguration.java
    openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java
    openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/cxf/CxfCdiAutoSetup.java
    openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/openwebbeans/BundleMetadataDiscovery.java
    openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/tomcat/CDIInstanceManager.java
    openwebbeans/microwave/trunk/microwave-core/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
    openwebbeans/microwave/trunk/microwave-core/src/test/java/org/apache/microwave/MicrowaveTest.java
    openwebbeans/microwave/trunk/microwave-core/src/test/java/org/superbiz/app/Endpoint.java
    openwebbeans/microwave/trunk/microwave-gradle-plugin/src/main/java/org/apache/microwave/gradle/MicrowaveExtension.java
    openwebbeans/microwave/trunk/microwave-gradle-plugin/src/main/java/org/apache/microwave/gradle/MicrowaveTask.java
    openwebbeans/microwave/trunk/microwave-maven-plugin/src/main/java/org/apache/microwave/maven/MicrowaveRunMojo.java

Modified: openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveConfiguration.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveConfiguration.java?rev=1765895&r1=1765894&r2=1765895&view=diff
==============================================================================
--- openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveConfiguration.java
(original)
+++ openwebbeans/microwave/trunk/microwave-arquillian/src/main/java/org/apache/microwave/arquillian/MicrowaveConfiguration.java
Thu Oct 20 22:19:49 2016
@@ -71,6 +71,8 @@ public class MicrowaveConfiguration impl
     private String loginConfig;
     private String securityConstraints;
     private String realm;
+    private boolean tomcatScanning = true;
+    private boolean tomcatAutoSetup = true;
 
     @Override
     public void validate() throws ConfigurationException {
@@ -193,6 +195,30 @@ public class MicrowaveConfiguration impl
         return builder;
     }
 
+    public String getCxfServletParams() {
+        return cxfServletParams;
+    }
+
+    public void setCxfServletParams(final String cxfServletParams) {
+        this.cxfServletParams = cxfServletParams;
+    }
+
+    public boolean isTomcatScanning() {
+        return tomcatScanning;
+    }
+
+    public void setTomcatScanning(final boolean tomcatScanning) {
+        this.tomcatScanning = tomcatScanning;
+    }
+
+    public boolean isTomcatAutoSetup() {
+        return tomcatAutoSetup;
+    }
+
+    public void setTomcatAutoSetup(final boolean tomcatAutoSetup) {
+        this.tomcatAutoSetup = tomcatAutoSetup;
+    }
+
     public int getHttpPort() {
         return httpPort;
     }

Modified: openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java?rev=1765895&r1=1765894&r2=1765895&view=diff
==============================================================================
--- openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java
(original)
+++ openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/Microwave.java
Thu Oct 20 22:19:49 2016
@@ -51,6 +51,7 @@ import org.apache.microwave.runner.cli.C
 import org.apache.microwave.tomcat.CDIInstanceManager;
 import org.apache.microwave.tomcat.OWBJarScanner;
 import org.apache.microwave.tomcat.ProvidedLoader;
+import org.apache.microwave.tomcat.TomcatAutoInitializer;
 import org.apache.tomcat.util.descriptor.web.LoginConfig;
 import org.apache.tomcat.util.descriptor.web.SecurityCollection;
 import org.apache.tomcat.util.descriptor.web.SecurityConstraint;
@@ -197,6 +198,7 @@ public class Microwave implements AutoCl
             try {
                 new OWBAutoSetup().onStartup(c, ctx1);
                 new CxfCdiAutoSetup().onStartup(c, ctx1);
+                new TomcatAutoInitializer().onStartup(c, ctx1);
             } finally {
                 ctx.getServletContext().removeAttribute("microwave.configuration");
             }
@@ -686,6 +688,9 @@ public class Microwave implements AutoCl
         @CliOption(name = "tomcat-scanning", description = "Should Tomcat scanning be used
(@HandleTypes, @WebXXX)")
         private boolean tomcatScanning = true;
 
+        @CliOption(name = "tomcat-default-setup", description = "Add default servlet")
+        private boolean tomcatAutoSetup = true;
+
         public Builder() { // load defaults
             loadFrom("microwave.properties");
         }
@@ -1231,6 +1236,14 @@ public class Microwave implements AutoCl
         public int getActivePort() {
             return isSkipHttp() ? getHttpsPort() : getHttpPort();
         }
+
+        public boolean isTomcatAutoSetup() {
+            return tomcatAutoSetup;
+        }
+
+        public void setTomcatAutoSetup(final boolean tomcatAutoSetup) {
+            this.tomcatAutoSetup = tomcatAutoSetup;
+        }
     }
 
     public static class LoginConfigBuilder {

Modified: openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/cxf/CxfCdiAutoSetup.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/cxf/CxfCdiAutoSetup.java?rev=1765895&r1=1765894&r2=1765895&view=diff
==============================================================================
--- openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/cxf/CxfCdiAutoSetup.java
(original)
+++ openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/cxf/CxfCdiAutoSetup.java
Thu Oct 20 22:19:49 2016
@@ -35,135 +35,108 @@ import org.apache.johnzon.jaxrs.JsrProvi
 import org.apache.microwave.Microwave;
 import org.apache.microwave.logging.tomcat.LogFacade;
 
+import javax.servlet.DispatcherType;
+import javax.servlet.Filter;
+import javax.servlet.FilterChain;
+import javax.servlet.FilterConfig;
+import javax.servlet.FilterRegistration;
 import javax.servlet.ServletConfig;
 import javax.servlet.ServletContainerInitializer;
 import javax.servlet.ServletContext;
 import javax.servlet.ServletException;
-import javax.servlet.ServletRegistration;
+import javax.servlet.ServletRequest;
+import javax.servlet.ServletResponse;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletRequestWrapper;
 import javax.ws.rs.core.Application;
+import java.io.IOException;
 import java.lang.reflect.Method;
 import java.lang.reflect.ParameterizedType;
 import java.lang.reflect.Type;
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.EnumSet;
+import java.util.Enumeration;
 import java.util.List;
+import java.util.Optional;
 import java.util.Set;
+import java.util.stream.Stream;
 
 import static java.util.Arrays.asList;
 import static java.util.Optional.ofNullable;
 
+// this look a bit complicated but it just:
+// - wraps cxf in a filter to support plain resources when not conflicting with application
path
+// - logs resources
 public class CxfCdiAutoSetup implements ServletContainerInitializer {
+    private static final String NAME = "cxf-cdi";
+
     @Override
     public void onStartup(final Set<Class<?>> c, final ServletContext ctx) throws
ServletException {
         final Microwave.Builder builder = Microwave.Builder.class.cast(ctx.getAttribute("microwave.configuration"));
-        final ServletRegistration.Dynamic jaxrs = ctx.addServlet("cxf-cdi", new CXFCdiServlet()
{
+        final MicrowaveCXFCdiServlet delegate = new MicrowaveCXFCdiServlet(!builder.isJaxrsProviderSetup());
+        final FilterRegistration.Dynamic jaxrs = ctx.addFilter(NAME, new Filter() {
+            private final String servletPath = builder.getJaxrsMapping().endsWith("/*") ?
+                    builder.getJaxrsMapping().substring(0, builder.getJaxrsMapping().length()
- 2) : builder.getJaxrsMapping();
+
             @Override
-            protected void loadBus(final ServletConfig servletConfig) {
-                super.loadBus(servletConfig);
-                if (!builder.isJaxrsProviderSetup()) {
-                    return;
-                }
+            public void init(final FilterConfig filterConfig) throws ServletException {
+                delegate.init(new ServletConfig() {
+                    @Override
+                    public String getServletName() {
+                        return NAME;
+                    }
 
-                final List<DelegateProvider<?>> providers = asList(new JohnzonProvider<>(),
new JsrProvider());
+                    @Override
+                    public ServletContext getServletContext() {
+                        return filterConfig.getServletContext();
+                    }
 
-                // client
-                if (bus.getProperty("org.apache.cxf.jaxrs.bus.providers") == null) {
-                    bus.setProperty("skip.default.json.provider.registration", "true");
-                    bus.setProperty("org.apache.cxf.jaxrs.bus.providers", providers);
-                }
+                    @Override
+                    public String getInitParameter(final String name) {
+                        return filterConfig.getInitParameter(name);
+                    }
 
-                // server
-                getDestinationRegistryFromBus().getDestinations()
-                        .forEach(d -> {
-                            final ChainInitiationObserver observer = ChainInitiationObserver.class.cast(d.getMessageObserver());
-                            final ServerProviderFactory providerFactory = ServerProviderFactory.class.cast(observer.getEndpoint().get(ServerProviderFactory.class.getName()));
-                            providerFactory.setUserProviders(providers);
-                        });
+                    @Override
+                    public Enumeration<String> getInitParameterNames() {
+                        return filterConfig.getInitParameterNames();
+                    }
+                });
             }
 
             @Override
-            public void init(final ServletConfig sc) throws ServletException {
-                super.init(sc);
-
-                // just logging the endpoints
-                final LogFacade log = new LogFacade(CxfCdiAutoSetup.class.getName());
-                final DestinationRegistry registry = getDestinationRegistryFromBus();
-                registry.getDestinations().stream()
-                        .filter(ServletDestination.class::isInstance)
-                        .map(ServletDestination.class::cast)
-                        .forEach(sd -> {
-                            final Endpoint endpoint = ChainInitiationObserver.class.cast(sd.getMessageObserver()).getEndpoint();
-                            final ApplicationInfo app = ApplicationInfo.class.cast(endpoint.get(Application.class.getName()));
-                            final JAXRSServiceFactoryBean sfb = JAXRSServiceFactoryBean.class.cast(endpoint.get(JAXRSServiceFactoryBean.class.getName()));
-
-                            final List<Logs.LogResourceEndpointInfo> resourcesToLog
= new ArrayList<>();
-                            int classSize = 0;
-                            int addressSize = 0;
-
-                            final String base = sd.getEndpointInfo().getAddress();
-                            final List<ClassResourceInfo> resources = sfb.getClassResourceInfo();
-                            for (final ClassResourceInfo info : resources) {
-                                if (info.getResourceClass() == null) { // possible?
-                                    continue;
-                                }
-
-                                final String address = Logs.singleSlash(base, info.getURITemplate().getValue());
-
-                                final String clazz = info.getResourceClass().getName();
-                                classSize = Math.max(classSize, clazz.length());
-                                addressSize = Math.max(addressSize, address.length());
-
-                                int methodSize = 7;
-                                int methodStrSize = 0;
-
-                                final List<Logs.LogOperationEndpointInfo> toLog = new
ArrayList<>();
-
-                                final MethodDispatcher md = info.getMethodDispatcher();
-                                for (final OperationResourceInfo ori : md.getOperationResourceInfos())
{
-                                    final String httpMethod = ori.getHttpMethod();
-                                    final String currentAddress = Logs.singleSlash(address,
ori.getURITemplate().getValue());
-                                    final String methodToStr = Logs.toSimpleString(ori.getMethodToInvoke());
-                                    toLog.add(new Logs.LogOperationEndpointInfo(httpMethod,
currentAddress, methodToStr));
-
-                                    if (httpMethod != null) {
-                                        methodSize = Math.max(methodSize, httpMethod.length());
-                                    }
-                                    addressSize = Math.max(addressSize, currentAddress.length());
-                                    methodStrSize = Math.max(methodStrSize, methodToStr.length());
-                                }
-
-                                Collections.sort(toLog);
+            public void doFilter(final ServletRequest request, final ServletResponse response,
final FilterChain chain) throws IOException, ServletException {
+                if (!HttpServletRequest.class.isInstance(request)) {
+                    chain.doFilter(request, response);
+                    return;
+                }
+                final HttpServletRequest http = HttpServletRequest.class.cast(request);
+                final String path = http.getRequestURI().substring(http.getContextPath().length());
+                final Optional<String> app = Stream.of(delegate.prefixes).filter(path::startsWith).findAny();
+                if (app.isPresent()) {
+                    delegate.service(new HttpServletRequestWrapper(http) { // fake servlet
pathInfo and path
+                        @Override
+                        public String getPathInfo() {
+                            return path;
+                        }
 
-                                resourcesToLog.add(new Logs.LogResourceEndpointInfo(address,
clazz, toLog, methodSize, methodStrSize));
-                            }
+                        @Override
+                        public String getServletPath() {
+                            return servletPath;
+                        }
+                    }, response);
+                } else {
+                    chain.doFilter(request, response);
+                }
+            }
 
-                            // effective logging
-                            log.info("REST Application: " + endpoint.getEndpointInfo().getAddress()
+ " -> "
-                                    + ofNullable(app).map(ApplicationInfo::getResourceClass).map(Class::getName).orElse(""));
-
-                            Collections.sort(resourcesToLog);
-                            final int fClassSize = classSize;
-                            final int fAddressSize = addressSize;
-                            resourcesToLog.forEach(resource -> {
-                                log.info("     Service URI: "
-                                        + Logs.forceLength(resource.address, fAddressSize,
true) + " -> "
-                                        + Logs.forceLength(resource.classname, fClassSize,
true));
-
-                                resource.operations.forEach(info -> {
-                                    log.info("          "
-                                            + Logs.forceLength(info.http, resource.methodSize,
false) + " "
-                                            + Logs.forceLength(info.address, fAddressSize,
true) + " ->      "
-                                            + Logs.forceLength(info.method, resource.methodStrSize,
true));
-                                });
-                                resource.operations.clear();
-                            });
-                            resourcesToLog.clear();
-                        });
+            @Override
+            public void destroy() {
+                delegate.destroy();
             }
         });
-        jaxrs.setLoadOnStartup(1);
         jaxrs.setAsyncSupported(true);
-        jaxrs.addMapping(builder.getJaxrsMapping());
+        jaxrs.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, builder.getJaxrsMapping());
         ofNullable(builder.getCxfServletParams()).ifPresent(m -> m.forEach(jaxrs::setInitParameter));
     }
 
@@ -332,4 +305,118 @@ public class CxfCdiAutoSetup implements
         }
     }
 
+    private static class MicrowaveCXFCdiServlet extends CXFCdiServlet {
+        private final boolean noProviderSetup;
+        private String[] prefixes;
+
+        private MicrowaveCXFCdiServlet(final boolean noProviderSetup) {
+            this.noProviderSetup = noProviderSetup;
+        }
+
+        @Override
+        protected void loadBus(final ServletConfig servletConfig) {
+            super.loadBus(servletConfig);
+            if (noProviderSetup) {
+                return;
+            }
+
+            final List<DelegateProvider<?>> providers = asList(new JohnzonProvider<>(),
new JsrProvider());
+
+            // client
+            if (bus.getProperty("org.apache.cxf.jaxrs.bus.providers") == null) {
+                bus.setProperty("skip.default.json.provider.registration", "true");
+                bus.setProperty("org.apache.cxf.jaxrs.bus.providers", providers);
+            }
+
+            // server
+            getDestinationRegistryFromBus().getDestinations()
+                    .forEach(d -> {
+                        final ChainInitiationObserver observer = ChainInitiationObserver.class.cast(d.getMessageObserver());
+                        final ServerProviderFactory providerFactory = ServerProviderFactory.class.cast(observer.getEndpoint().get(ServerProviderFactory.class.getName()));
+                        providerFactory.setUserProviders(providers);
+                    });
+        }
+
+        @Override
+        public void init(final ServletConfig sc) throws ServletException {
+            super.init(sc);
+
+            // just logging the endpoints
+            final LogFacade log = new LogFacade(CxfCdiAutoSetup.class.getName());
+            final DestinationRegistry registry = getDestinationRegistryFromBus();
+            prefixes = registry.getDestinations().stream()
+                    .filter(ServletDestination.class::isInstance)
+                    .map(ServletDestination.class::cast)
+                    .map(sd -> {
+                        final Endpoint endpoint = ChainInitiationObserver.class.cast(sd.getMessageObserver()).getEndpoint();
+                        final ApplicationInfo app = ApplicationInfo.class.cast(endpoint.get(Application.class.getName()));
+                        final JAXRSServiceFactoryBean sfb = JAXRSServiceFactoryBean.class.cast(endpoint.get(JAXRSServiceFactoryBean.class.getName()));
+
+                        final List<Logs.LogResourceEndpointInfo> resourcesToLog = new
ArrayList<>();
+                        int classSize = 0;
+                        int addressSize = 0;
+
+                        final String base = sd.getEndpointInfo().getAddress();
+                        final List<ClassResourceInfo> resources = sfb.getClassResourceInfo();
+                        for (final ClassResourceInfo info : resources) {
+                            if (info.getResourceClass() == null) { // possible?
+                                continue;
+                            }
+
+                            final String address = Logs.singleSlash(base, info.getURITemplate().getValue());
+
+                            final String clazz = info.getResourceClass().getName();
+                            classSize = Math.max(classSize, clazz.length());
+                            addressSize = Math.max(addressSize, address.length());
+
+                            int methodSize = 7;
+                            int methodStrSize = 0;
+
+                            final List<Logs.LogOperationEndpointInfo> toLog = new ArrayList<>();
+
+                            final MethodDispatcher md = info.getMethodDispatcher();
+                            for (final OperationResourceInfo ori : md.getOperationResourceInfos())
{
+                                final String httpMethod = ori.getHttpMethod();
+                                final String currentAddress = Logs.singleSlash(address, ori.getURITemplate().getValue());
+                                final String methodToStr = Logs.toSimpleString(ori.getMethodToInvoke());
+                                toLog.add(new Logs.LogOperationEndpointInfo(httpMethod, currentAddress,
methodToStr));
+
+                                if (httpMethod != null) {
+                                    methodSize = Math.max(methodSize, httpMethod.length());
+                                }
+                                addressSize = Math.max(addressSize, currentAddress.length());
+                                methodStrSize = Math.max(methodStrSize, methodToStr.length());
+                            }
+
+                            Collections.sort(toLog);
+
+                            resourcesToLog.add(new Logs.LogResourceEndpointInfo(address,
clazz, toLog, methodSize, methodStrSize));
+                        }
+
+                        // effective logging
+                        log.info("REST Application: " + endpoint.getEndpointInfo().getAddress()
+ " -> "
+                                + ofNullable(app).map(ApplicationInfo::getResourceClass).map(Class::getName).orElse(""));
+
+                        Collections.sort(resourcesToLog);
+                        final int fClassSize = classSize;
+                        final int fAddressSize = addressSize;
+                        resourcesToLog.forEach(resource -> {
+                            log.info("     Service URI: "
+                                    + Logs.forceLength(resource.address, fAddressSize, true)
+ " -> "
+                                    + Logs.forceLength(resource.classname, fClassSize, true));
+
+                            resource.operations.forEach(info -> {
+                                log.info("          "
+                                        + Logs.forceLength(info.http, resource.methodSize,
false) + " "
+                                        + Logs.forceLength(info.address, fAddressSize, true)
+ " ->      "
+                                        + Logs.forceLength(info.method, resource.methodStrSize,
true));
+                            });
+                            resource.operations.clear();
+                        });
+                        resourcesToLog.clear();
+
+                        return base;
+                    }).toArray(String[]::new);
+        }
+    }
 }

Modified: openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/openwebbeans/BundleMetadataDiscovery.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/openwebbeans/BundleMetadataDiscovery.java?rev=1765895&r1=1765894&r2=1765895&view=diff
==============================================================================
--- openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/openwebbeans/BundleMetadataDiscovery.java
(original)
+++ openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/openwebbeans/BundleMetadataDiscovery.java
Thu Oct 20 22:19:49 2016
@@ -37,6 +37,14 @@ public class BundleMetadataDiscovery ext
     }
 
     @Override
+    public void scan() {
+        if (finder != null) {
+            return;
+        }
+        super.scan();
+    }
+
+    @Override
     protected AnnotationFinder initFinder() {
         if (finder != null) {
             return finder;

Modified: openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/tomcat/CDIInstanceManager.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/tomcat/CDIInstanceManager.java?rev=1765895&r1=1765894&r2=1765895&view=diff
==============================================================================
--- openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/tomcat/CDIInstanceManager.java
(original)
+++ openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/tomcat/CDIInstanceManager.java
Thu Oct 20 22:19:49 2016
@@ -58,7 +58,7 @@ public class CDIInstanceManager implemen
 
     @Override
     public void newInstance(final Object o) throws IllegalAccessException, InvocationTargetException,
NamingException {
-        if (WebBeansConfigurationListener.class.isInstance(o)) {
+        if (WebBeansConfigurationListener.class.isInstance(o) || o.getClass().getName().startsWith("org.apache.catalina.servlets."))
{
             return;
         }
 

Added: openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/tomcat/TomcatAutoInitializer.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/tomcat/TomcatAutoInitializer.java?rev=1765895&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/tomcat/TomcatAutoInitializer.java
(added)
+++ openwebbeans/microwave/trunk/microwave-core/src/main/java/org/apache/microwave/tomcat/TomcatAutoInitializer.java
Thu Oct 20 22:19:49 2016
@@ -0,0 +1,46 @@
+/*
+ * 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.microwave.tomcat;
+
+import org.apache.catalina.servlets.DefaultServlet;
+import org.apache.microwave.Microwave;
+
+import javax.servlet.ServletContainerInitializer;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import javax.servlet.ServletRegistration;
+import java.util.Set;
+
+public class TomcatAutoInitializer implements ServletContainerInitializer {
+    @Override
+    public void onStartup(final Set<Class<?>> c, final ServletContext ctx) throws
ServletException {
+        final Microwave.Builder builder = Microwave.Builder.class.cast(ctx.getAttribute("microwave.configuration"));
+        if (!builder.isTomcatAutoSetup()) {
+            return;
+        }
+
+        final ServletRegistration.Dynamic def = ctx.addServlet("default", DefaultServlet.class);
+        def.setInitParameter("listings", "false");
+        def.setInitParameter("debug", "0");
+        def.setLoadOnStartup(1);
+        def.addMapping("/");
+
+        // TODO: mimetypes
+    }
+}

Modified: openwebbeans/microwave/trunk/microwave-core/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-core/src/main/resources/META-INF/openwebbeans/openwebbeans.properties?rev=1765895&r1=1765894&r2=1765895&view=diff
==============================================================================
--- openwebbeans/microwave/trunk/microwave-core/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
(original)
+++ openwebbeans/microwave/trunk/microwave-core/src/main/resources/META-INF/openwebbeans/openwebbeans.properties
Thu Oct 20 22:19:49 2016
@@ -91,5 +91,9 @@ org.apache.webbeans.scanExclusionPaths=\
         /stax,\
         /xmlschema,\
         /lombok,\
+        /javaee-api,\
+        /classworlds-,\
+        /wagon-,\
+        /ziplock-,\
         /microwave-gradle-plugin, \
         /microwave-maven-plugin

Modified: openwebbeans/microwave/trunk/microwave-core/src/test/java/org/apache/microwave/MicrowaveTest.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-core/src/test/java/org/apache/microwave/MicrowaveTest.java?rev=1765895&r1=1765894&r2=1765895&view=diff
==============================================================================
--- openwebbeans/microwave/trunk/microwave-core/src/test/java/org/apache/microwave/MicrowaveTest.java
(original)
+++ openwebbeans/microwave/trunk/microwave-core/src/test/java/org/apache/microwave/MicrowaveTest.java
Thu Oct 20 22:19:49 2016
@@ -26,9 +26,11 @@ import org.superbiz.app.RsApp;
 
 import java.io.File;
 import java.io.FileOutputStream;
+import java.io.FileWriter;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.OutputStream;
+import java.io.Writer;
 import java.net.URL;
 import java.util.stream.Stream;
 
@@ -62,9 +64,17 @@ public class MicrowaveTest {
                 fail();
             }
         });
+        try (final Writer indexHtml = new FileWriter(new File(root, "index.html"))) {
+            indexHtml.write("hello");
+        } catch (final IOException e) {
+            fail(e.getMessage());
+        }
         try (final Microwave microwave = new Microwave(new Microwave.Builder().randomHttpPort()).start())
{
             microwave.deployWebapp("", root);
+            assertEquals("hello", IOUtils.toString(new URL("http://localhost:" + microwave.getConfiguration().getHttpPort()
+ "/index.html")));
             assertEquals("simple", IOUtils.toString(new URL("http://localhost:" + microwave.getConfiguration().getHttpPort()
+ "/api/test")));
+            assertEquals("simplepathinfo", IOUtils.toString(new URL("http://localhost:" +
microwave.getConfiguration().getHttpPort()
+                    + "/api/test?checkcustom=pathinfo#is=fine")));
             assertEquals("simple", IOUtils.toString(new URL("http://localhost:" + microwave.getConfiguration().getHttpPort()
+ "/api/other")));
             assertEquals("simplefiltertrue", IOUtils.toString(new URL("http://localhost:"
+ microwave.getConfiguration().getHttpPort() + "/filter")));
             assertEquals("filtertrue", IOUtils.toString(new URL("http://localhost:" + microwave.getConfiguration().getHttpPort()
+ "/other")));

Modified: openwebbeans/microwave/trunk/microwave-core/src/test/java/org/superbiz/app/Endpoint.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-core/src/test/java/org/superbiz/app/Endpoint.java?rev=1765895&r1=1765894&r2=1765895&view=diff
==============================================================================
--- openwebbeans/microwave/trunk/microwave-core/src/test/java/org/superbiz/app/Endpoint.java
(original)
+++ openwebbeans/microwave/trunk/microwave-core/src/test/java/org/superbiz/app/Endpoint.java
Thu Oct 20 22:19:49 2016
@@ -23,8 +23,11 @@ import javax.inject.Inject;
 import javax.ws.rs.GET;
 import javax.ws.rs.Path;
 import javax.ws.rs.Produces;
+import javax.ws.rs.QueryParam;
 import javax.ws.rs.core.MediaType;
 
+import static java.util.Optional.ofNullable;
+
 @Path("test")
 @ApplicationScoped
 public class Endpoint {
@@ -33,8 +36,8 @@ public class Endpoint {
 
     @GET
     @Produces(MediaType.TEXT_PLAIN)
-    public String simple() {
-        return Boolean.parseBoolean(injectable.injected()) ? "simple" : "fail";
+    public String simple(@QueryParam("checkcustom") final String query) {
+        return Boolean.parseBoolean(injectable.injected()) ? "simple" + ofNullable(query).orElse("")
: "fail";
     }
 
     @GET

Modified: openwebbeans/microwave/trunk/microwave-gradle-plugin/src/main/java/org/apache/microwave/gradle/MicrowaveExtension.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-gradle-plugin/src/main/java/org/apache/microwave/gradle/MicrowaveExtension.java?rev=1765895&r1=1765894&r2=1765895&view=diff
==============================================================================
--- openwebbeans/microwave/trunk/microwave-gradle-plugin/src/main/java/org/apache/microwave/gradle/MicrowaveExtension.java
(original)
+++ openwebbeans/microwave/trunk/microwave-gradle-plugin/src/main/java/org/apache/microwave/gradle/MicrowaveExtension.java
Thu Oct 20 22:19:49 2016
@@ -53,6 +53,7 @@ public class MicrowaveExtension {
     private Map<String, String> cxfServletParams;
     private boolean http2;
     private boolean tomcatScanning = true;
+    private boolean tomcatAutoSetup = true;
     private String tempDir;
     private boolean webResourceCached = true;
     private String conf;
@@ -358,4 +359,12 @@ public class MicrowaveExtension {
     public void setSkip(final boolean skip) {
         this.skip = skip;
     }
+
+    public boolean isTomcatAutoSetup() {
+        return tomcatAutoSetup;
+    }
+
+    public void setTomcatAutoSetup(final boolean tomcatAutoSetup) {
+        this.tomcatAutoSetup = tomcatAutoSetup;
+    }
 }

Modified: openwebbeans/microwave/trunk/microwave-gradle-plugin/src/main/java/org/apache/microwave/gradle/MicrowaveTask.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-gradle-plugin/src/main/java/org/apache/microwave/gradle/MicrowaveTask.java?rev=1765895&r1=1765894&r2=1765895&view=diff
==============================================================================
--- openwebbeans/microwave/trunk/microwave-gradle-plugin/src/main/java/org/apache/microwave/gradle/MicrowaveTask.java
(original)
+++ openwebbeans/microwave/trunk/microwave-gradle-plugin/src/main/java/org/apache/microwave/gradle/MicrowaveTask.java
Thu Oct 20 22:19:49 2016
@@ -189,6 +189,10 @@ public class MicrowaveTask extends Defau
 
     @Input
     @Optional
+    private boolean tomcatAutoSetup = true;
+
+    @Input
+    @Optional
     private List<File> modules;
 
     @Input
@@ -775,4 +779,12 @@ public class MicrowaveTask extends Defau
     public void setWebapp(final File webapp) {
         this.webapp = webapp;
     }
+
+    public boolean isTomcatAutoSetup() {
+        return tomcatAutoSetup;
+    }
+
+    public void setTomcatAutoSetup(final boolean tomcatAutoSetup) {
+        this.tomcatAutoSetup = tomcatAutoSetup;
+    }
 }

Modified: openwebbeans/microwave/trunk/microwave-maven-plugin/src/main/java/org/apache/microwave/maven/MicrowaveRunMojo.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/microwave-maven-plugin/src/main/java/org/apache/microwave/maven/MicrowaveRunMojo.java?rev=1765895&r1=1765894&r2=1765895&view=diff
==============================================================================
--- openwebbeans/microwave/trunk/microwave-maven-plugin/src/main/java/org/apache/microwave/maven/MicrowaveRunMojo.java
(original)
+++ openwebbeans/microwave/trunk/microwave-maven-plugin/src/main/java/org/apache/microwave/maven/MicrowaveRunMojo.java
Thu Oct 20 22:19:49 2016
@@ -85,6 +85,9 @@ public class MicrowaveRunMojo extends Ab
     @Parameter(property = "microwave.tomcatScanning", defaultValue = "true")
     private boolean tomcatScanning;
 
+    @Parameter(property = "microwave.tomcatAutoSetup", defaultValue = "true")
+    private boolean tomcatAutoSetup;
+
     @Parameter(property = "microwave.skipHttp")
     private boolean skipHttp;
 



Mime
View raw message