You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openwebbeans.apache.org by rm...@apache.org on 2016/11/13 09:34:10 UTC
svn commit: r1769479 [3/16] - in /openwebbeans/microwave/trunk: ./
meecrowave-arquillian/ meecrowave-arquillian/src/
meecrowave-arquillian/src/main/ meecrowave-arquillian/src/main/java/
meecrowave-arquillian/src/main/java/org/ meecrowave-arquillian/src...
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/CxfCdiAutoSetup.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,428 @@
+/*
+ * 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.meecrowave.cxf;
+
+import org.apache.cxf.cdi.CXFCdiServlet;
+import org.apache.cxf.common.util.ReflectionUtil;
+import org.apache.cxf.endpoint.Endpoint;
+import org.apache.cxf.jaxrs.JAXRSServiceFactoryBean;
+import org.apache.cxf.jaxrs.model.ApplicationInfo;
+import org.apache.cxf.jaxrs.model.ClassResourceInfo;
+import org.apache.cxf.jaxrs.model.MethodDispatcher;
+import org.apache.cxf.jaxrs.model.OperationResourceInfo;
+import org.apache.cxf.jaxrs.model.ProviderInfo;
+import org.apache.cxf.jaxrs.provider.ProviderFactory;
+import org.apache.cxf.jaxrs.provider.ServerProviderFactory;
+import org.apache.cxf.transport.ChainInitiationObserver;
+import org.apache.cxf.transport.http.DestinationRegistry;
+import org.apache.cxf.transport.servlet.ServletDestination;
+import org.apache.meecrowave.Meecrowave;
+import org.apache.meecrowave.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.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.Field;
+import java.lang.reflect.Method;
+import java.lang.reflect.ParameterizedType;
+import java.lang.reflect.Type;
+import java.util.ArrayList;
+import java.util.Collection;
+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.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 Meecrowave.Builder builder = Meecrowave.Builder.class.cast(ctx.getAttribute("meecrowave.configuration"));
+ final MeecrowaveCXFCdiServlet delegate = new MeecrowaveCXFCdiServlet();
+ 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
+ public void init(final FilterConfig filterConfig) throws ServletException {
+ delegate.init(new ServletConfig() {
+ @Override
+ public String getServletName() {
+ return NAME;
+ }
+
+ @Override
+ public ServletContext getServletContext() {
+ return filterConfig.getServletContext();
+ }
+
+ @Override
+ public String getInitParameter(final String name) {
+ return filterConfig.getInitParameter(name);
+ }
+
+ @Override
+ public Enumeration<String> getInitParameterNames() {
+ return filterConfig.getInitParameterNames();
+ }
+ });
+ }
+
+ @Override
+ 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;
+ }
+
+ @Override
+ public String getServletPath() {
+ return servletPath;
+ }
+ }, response);
+ } else {
+ chain.doFilter(request, response);
+ }
+ }
+
+ @Override
+ public void destroy() {
+ delegate.destroy();
+ }
+ });
+ jaxrs.setAsyncSupported(true);
+ jaxrs.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), true, builder.getJaxrsMapping());
+ ofNullable(builder.getCxfServletParams()).ifPresent(m -> m.forEach(jaxrs::setInitParameter));
+ }
+
+ private static class Logs {
+ private Logs() {
+ // no-op
+ }
+
+ private static String forceLength(final String httpMethod, final int l, final boolean right) {
+ final String http;
+ if (httpMethod == null) { // subresourcelocator implies null http method
+ http = "";
+ } else {
+ http = httpMethod;
+ }
+
+ final StringBuilder builder = new StringBuilder();
+ if (!right) {
+ for (int i = 0; i < l - http.length(); i++) {
+ builder.append(" ");
+ }
+ }
+ builder.append(http);
+ if (right) {
+ for (int i = 0; i < l - http.length(); i++) {
+ builder.append(" ");
+ }
+ }
+ return builder.toString();
+ }
+
+ private static String toSimpleString(final Method mtd) {
+ try {
+ final StringBuilder sb = new StringBuilder();
+ final Type[] typeparms = mtd.getTypeParameters();
+ if (typeparms.length > 0) {
+ boolean first = true;
+ sb.append("<");
+ for (Type typeparm : typeparms) {
+ if (!first) {
+ sb.append(",");
+ }
+ sb.append(name(typeparm));
+ first = false;
+ }
+ sb.append("> ");
+ }
+
+ final Type genRetType = mtd.getGenericReturnType();
+ sb.append(name(genRetType)).append(" ");
+ sb.append(mtd.getName()).append("(");
+ final Type[] params = mtd.getGenericParameterTypes();
+ for (int j = 0; j < params.length; j++) {
+ sb.append(name(params[j]));
+ if (j < (params.length - 1)) {
+ sb.append(", ");
+ }
+ }
+ sb.append(")");
+ final Type[] exceptions = mtd.getGenericExceptionTypes();
+ if (exceptions.length > 0) {
+ sb.append(" throws ");
+ for (int k = 0; k < exceptions.length; k++) {
+ sb.append(name(exceptions[k]));
+ if (k < (exceptions.length - 1)) {
+ sb.append(",");
+ }
+ }
+ }
+ return sb.toString();
+ } catch (final Exception e) {
+ return "<" + e + ">";
+ }
+ }
+
+ private static String name(final Type type) {
+ if (type instanceof Class<?>) {
+ return ((Class) type).getSimpleName().replace("java.lang.", "").replace("java.util", "");
+ } else if (type instanceof ParameterizedType) {
+ final ParameterizedType pt = (ParameterizedType) type;
+ final StringBuilder builder = new StringBuilder();
+ builder.append(name(pt.getRawType()));
+ final Type[] args = pt.getActualTypeArguments();
+ if (args != null) {
+ builder.append("<");
+ for (int i = 0; i < args.length; i++) {
+ builder.append(name(args[i]));
+ if (i < args.length - 1) {
+ builder.append(", ");
+ }
+ }
+ builder.append(">");
+ }
+ return builder.toString();
+ }
+ return type.toString();
+ }
+
+ private static String singleSlash(final String address, final String value) {
+ if (address.endsWith("/") && value.startsWith("/")) {
+ return address + value.substring(1);
+ }
+ if (!address.endsWith("/") && !value.startsWith("/")) {
+ return address + '/' + value;
+ }
+ return address + value;
+ }
+
+ private static class LogOperationEndpointInfo implements Comparable<LogOperationEndpointInfo> {
+ private final String http;
+ private final String address;
+ private final String method;
+
+ private LogOperationEndpointInfo(final String http, final String address, final String method) {
+ this.address = address;
+ this.method = method;
+
+ if (http != null) {
+ this.http = http;
+ } else { // can happen with subresource locators
+ this.http = "";
+ }
+ }
+
+ @Override
+ public int compareTo(final LogOperationEndpointInfo o) {
+ int compare = http.compareTo(o.http);
+ if (compare != 0) {
+ return compare;
+ }
+
+ compare = address.compareTo(o.address);
+ if (compare != 0) {
+ return compare;
+ }
+
+ return method.compareTo(o.method);
+ }
+ }
+
+ private static class LogResourceEndpointInfo implements Comparable<LogResourceEndpointInfo> {
+ private final String address;
+ private final String classname;
+ private final List<LogOperationEndpointInfo> operations;
+ private final int methodSize;
+ private final int methodStrSize;
+
+ private LogResourceEndpointInfo(final String address, final String classname,
+ final List<LogOperationEndpointInfo> operations,
+ final int methodSize, final int methodStrSize) {
+ this.address = address;
+ this.classname = classname;
+ this.operations = operations;
+ this.methodSize = methodSize;
+ this.methodStrSize = methodStrSize;
+ }
+
+ @Override
+ public int compareTo(final LogResourceEndpointInfo o) {
+ final int compare = address.compareTo(o.address);
+ if (compare != 0) {
+ return compare;
+ }
+ return classname.compareTo(o.classname);
+ }
+ }
+ }
+
+ private static class MeecrowaveCXFCdiServlet extends CXFCdiServlet {
+ private String[] prefixes;
+
+ @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 = uproxyName(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).map(CxfCdiAutoSetup::uproxyName).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();
+
+ // log @Providers
+ if (Meecrowave.Builder.class.cast(sc.getServletContext().getAttribute("meecrowave.configuration")).isJaxrsLogProviders()) {
+ final ServerProviderFactory spf = ServerProviderFactory.class.cast(endpoint.get(ServerProviderFactory.class.getName()));
+ dump(log, spf, "MessageBodyReaders", "messageReaders");
+ dump(log, spf, "MessageBodyWriters", "messageWriters");
+ }
+
+ return base;
+ }).toArray(String[]::new);
+ }
+
+ private void dump(final LogFacade log, final ServerProviderFactory spf, final String description, final String fieldName) {
+ final Field field = ReflectionUtil.getDeclaredField(ProviderFactory.class, fieldName);
+ if (!field.isAccessible()) {
+ field.setAccessible(true);
+ }
+ try {
+ final Collection<ProviderInfo<?>> providers = Collection.class.cast(field.get(spf));
+ log.info(" " + description);
+ providers.stream().map(ProviderInfo::getProvider).forEach(o -> {
+ try {
+ log.info(" - " + o);
+ } catch (final RuntimeException re) {
+ // no-op: maybe cdi context is not active
+ }
+ });
+ } catch (IllegalAccessException e) {
+ // ignore, not that a big deal
+ }
+ }
+ }
+
+ private static String uproxyName(final String clazz) {
+ if (clazz.contains("$$")) {
+ return clazz.substring(0, clazz.indexOf("$$"));
+ }
+ return clazz;
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/cxf/MeecrowaveBus.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,152 @@
+package org.apache.meecrowave.cxf;
+
+import org.apache.cxf.Bus;
+import org.apache.cxf.bus.extension.ExtensionManagerBus;
+import org.apache.cxf.common.util.ClassUnwrapper;
+import org.apache.cxf.feature.Feature;
+import org.apache.cxf.interceptor.Interceptor;
+import org.apache.cxf.message.Message;
+import org.apache.johnzon.jaxrs.JsrProvider;
+import org.apache.johnzon.jaxrs.jsonb.jaxrs.JsonbJaxrsProvider;
+import org.apache.meecrowave.Meecrowave;
+
+import javax.enterprise.context.ApplicationScoped;
+import javax.inject.Inject;
+import javax.inject.Named;
+import javax.servlet.ServletContext;
+import java.util.Collection;
+import java.util.List;
+import java.util.Map;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+
+import static java.util.Arrays.asList;
+import static java.util.Optional.ofNullable;
+
+@Named("cxf")
+@ApplicationScoped
+public class MeecrowaveBus implements Bus {
+ private final Bus delegate = new ExtensionManagerBus();
+
+ protected MeecrowaveBus() {
+ // no-op: for proxies
+ }
+
+ @Inject
+ public MeecrowaveBus(final ServletContext context) {
+ setProperty(ClassUnwrapper.class.getName(), (ClassUnwrapper) o -> {
+ final Class<?> aClass = o.getClass();
+ if (aClass.getName().contains("$$")) {
+ return aClass.getSuperclass();
+ }
+ return aClass;
+ });
+
+ final Meecrowave.Builder builder = Meecrowave.Builder.class.cast(context.getAttribute("meecrowave.configuration"));
+ if (builder.isJaxrsProviderSetup()) {
+ final List<Object> providers =
+ ofNullable(builder.getJaxrsDefaultProviders())
+ .map(s -> Stream.of(s.split(" *, *"))
+ .map(name -> {
+ try {
+ return Thread.currentThread().getContextClassLoader().loadClass(s).newInstance();
+ } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
+ throw new IllegalArgumentException(name + " can't be created");
+ }
+ })
+ .collect(Collectors.<Object>toList()))
+ .orElseGet(() -> asList(/*new JohnzonProvider<>(),*/ new JsonbJaxrsProvider(), new JsrProvider()));
+
+ // client
+ if (getProperty("org.apache.cxf.jaxrs.bus.providers") == null) {
+ setProperty("skip.default.json.provider.registration", "true");
+ setProperty("org.apache.cxf.jaxrs.bus.providers", providers);
+ }
+ }
+ }
+
+ @Override
+ public <T> T getExtension(final Class<T> extensionType) {
+ return delegate.getExtension(extensionType);
+ }
+
+ @Override
+ public <T> void setExtension(final T extension, final Class<T> extensionType) {
+ delegate.setExtension(extension, extensionType);
+ }
+
+ @Override
+ public boolean hasExtensionByName(final String name) {
+ return delegate.hasExtensionByName(name);
+ }
+
+ @Override
+ public String getId() {
+ return delegate.getId();
+ }
+
+ @Override
+ public void setId(final String i) {
+ delegate.setId(i);
+ }
+
+ @Override
+ public void shutdown(final boolean wait) {
+ delegate.shutdown(wait);
+ }
+
+ @Override
+ public void setProperty(final String s, final Object o) {
+ delegate.setProperty(s, o);
+ }
+
+ @Override
+ public Object getProperty(final String s) {
+ return delegate.getProperty(s);
+ }
+
+ @Override
+ public void setProperties(final Map<String, Object> properties) {
+ delegate.setProperties(properties);
+ }
+
+ @Override
+ public Map<String, Object> getProperties() {
+ return delegate.getProperties();
+ }
+
+ @Override
+ public Collection<Feature> getFeatures() {
+ return delegate.getFeatures();
+ }
+
+ @Override
+ public void setFeatures(final Collection<? extends Feature> features) {
+ delegate.setFeatures(features);
+ }
+
+ @Override
+ public BusState getState() {
+ return delegate.getState();
+ }
+
+ @Override
+ public List<Interceptor<? extends Message>> getInInterceptors() {
+ return delegate.getInInterceptors();
+ }
+
+ @Override
+ public List<Interceptor<? extends Message>> getOutInterceptors() {
+ return delegate.getOutInterceptors();
+ }
+
+ @Override
+ public List<Interceptor<? extends Message>> getInFaultInterceptors() {
+ return delegate.getInFaultInterceptors();
+ }
+
+ @Override
+ public List<Interceptor<? extends Message>> getOutFaultInterceptors() {
+ return delegate.getOutFaultInterceptors();
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/io/IO.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/io/IO.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/io/IO.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/io/IO.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,92 @@
+/*
+ * 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.meecrowave.io;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.nio.charset.StandardCharsets;
+import java.util.stream.Stream;
+
+import static java.util.Optional.ofNullable;
+
+public final class IO {
+ private IO() {
+ // no-op
+ }
+
+ public static void delete(final File dir) {
+ if (!dir.exists()) {
+ return;
+ }
+
+ if (dir.isFile()) {
+ retryDelete(dir);
+ return;
+ }
+
+ Stream.of(ofNullable(dir.listFiles()).orElseGet(() -> new File[0]))
+ .forEach(f -> {
+ if (f.isFile()) {
+ retryDelete(f);
+ } else {
+ delete(f);
+ }
+ });
+ retryDelete(dir);
+ }
+
+ private static void retryDelete(final File f) {
+ for (int i = 0; i < 3; i++) {
+ if (f.exists() && !f.delete()) {
+ System.gc(); // win
+ try {
+ Thread.sleep(50);
+ } catch (final InterruptedException e) {
+ Thread.interrupted();
+ }
+ continue;
+ }
+ return;
+ }
+ throw new IllegalStateException("Can't delete " + f);
+ }
+
+ public static void copy(final InputStream is, final OutputStream os) throws IOException {
+ byte[] buffer = new byte[16384];
+ int count;
+ while (-1 != (count = is.read(buffer))) {
+ os.write(buffer, 0, count);
+ }
+ }
+
+ public static String toString(final InputStream stream) throws IOException {
+ final ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ copy(stream, baos);
+ return new String(baos.toByteArray(), StandardCharsets.UTF_8);
+ }
+
+ public static void mkdirs(final File d) {
+ if (!d.isDirectory() && !d.mkdirs()) {
+ throw new IllegalStateException(d + " can't be created");
+ }
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/jul/Log4j2Logger.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/jul/Log4j2Logger.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/jul/Log4j2Logger.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/jul/Log4j2Logger.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,113 @@
+/*
+ * 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.meecrowave.logging.jul;
+
+import org.apache.cxf.common.logging.AbstractDelegatingLogger;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+import org.apache.logging.log4j.simple.SimpleLogger;
+import org.apache.logging.log4j.status.StatusLogger;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.LogRecord;
+
+public class Log4j2Logger extends AbstractDelegatingLogger {
+ private static final Map<Level, org.apache.logging.log4j.Level> TO_LOG4J = new HashMap<>();
+
+ private final Logger log;
+
+ static {
+ //older versions of log4j don't have TRACE, use debug
+ org.apache.logging.log4j.Level t = org.apache.logging.log4j.Level.DEBUG;
+
+ TO_LOG4J.put(Level.ALL, org.apache.logging.log4j.Level.ALL);
+ TO_LOG4J.put(Level.SEVERE, org.apache.logging.log4j.Level.ERROR);
+ TO_LOG4J.put(Level.WARNING, org.apache.logging.log4j.Level.WARN);
+ TO_LOG4J.put(Level.INFO, org.apache.logging.log4j.Level.INFO);
+ TO_LOG4J.put(Level.CONFIG, org.apache.logging.log4j.Level.DEBUG);
+ TO_LOG4J.put(Level.FINE, org.apache.logging.log4j.Level.DEBUG);
+ TO_LOG4J.put(Level.FINER, org.apache.logging.log4j.Level.TRACE);
+ TO_LOG4J.put(Level.FINEST, org.apache.logging.log4j.Level.TRACE);
+ TO_LOG4J.put(Level.OFF, org.apache.logging.log4j.Level.OFF);
+ }
+
+ public Log4j2Logger(final String name, final String resourceBundleName) {
+ super(name, resourceBundleName);
+ log = LogManager.getLogger(name);
+ }
+
+ @Override
+ public void setLevel(final Level newLevel) throws SecurityException {
+ if (org.apache.logging.log4j.core.Logger.class.isInstance(log)) {
+ org.apache.logging.log4j.core.Logger.class.cast(log).setLevel(TO_LOG4J.get(newLevel));
+ } else if (StatusLogger.class.isInstance(log)) {
+ StatusLogger.class.cast(log).setLevel(TO_LOG4J.get(newLevel));
+ } else if (SimpleLogger.class.isInstance(log)) {
+ SimpleLogger.class.cast(log).setLevel(TO_LOG4J.get(newLevel));
+ } // else ExtendedLoggerWrapper: ignore for now. we could do reflection if we need it
+ }
+
+ public Level getLevel() {
+ final org.apache.logging.log4j.Level l = log.getLevel();
+ if (l != null) {
+ return fromL4J(l);
+ }
+ return null;
+ }
+
+ protected void internalLogFormatted(final String msg, final LogRecord record) {
+ log.log(TO_LOG4J.get(record.getLevel()), msg, record.getThrown());
+ }
+
+
+ private Level fromL4J(final org.apache.logging.log4j.Level l) {
+ Level l2 = null;
+ switch (l.getStandardLevel()) {
+ case ALL:
+ l2 = Level.ALL;
+ break;
+ case FATAL:
+ l2 = Level.SEVERE;
+ break;
+ case ERROR:
+ l2 = Level.SEVERE;
+ break;
+ case WARN:
+ l2 = Level.WARNING;
+ break;
+ case INFO:
+ l2 = Level.INFO;
+ break;
+ case DEBUG:
+ l2 = Level.FINE;
+ break;
+ case OFF:
+ l2 = Level.OFF;
+ break;
+ case TRACE:
+ l2 = Level.FINEST;
+ break;
+ default:
+ l2 = Level.FINE;
+ }
+ return l2;
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/MeecrowaveLog4j2ConfigurationFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/MeecrowaveLog4j2ConfigurationFactory.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/MeecrowaveLog4j2ConfigurationFactory.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/MeecrowaveLog4j2ConfigurationFactory.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,42 @@
+/*
+ * 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.meecrowave.logging.log4j2;
+
+import org.apache.logging.log4j.core.LoggerContext;
+import org.apache.logging.log4j.core.config.Configuration;
+import org.apache.logging.log4j.core.config.ConfigurationSource;
+import org.apache.logging.log4j.core.config.Order;
+import org.apache.logging.log4j.core.config.plugins.Plugin;
+import org.apache.logging.log4j.core.config.xml.XmlConfigurationFactory;
+
+@Order(100)
+@Plugin(name = "MeecrowaveConfigurationFactory", category = "ConfigurationFactory")
+public class MeecrowaveLog4j2ConfigurationFactory extends XmlConfigurationFactory {
+ private static final String[] TYPES = {".xml"/*override*/, ".meecrowave-logging" /*our default*/, "*"};
+
+ @Override
+ public String[] getSupportedTypes() {
+ return TYPES;
+ }
+
+ @Override
+ public Configuration getConfiguration(final LoggerContext loggerContext, final ConfigurationSource source) {
+ return super.getConfiguration(loggerContext, source);
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/MeecrowaveLogEventFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/MeecrowaveLogEventFactory.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/MeecrowaveLogEventFactory.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/log4j2/MeecrowaveLogEventFactory.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,70 @@
+/*
+ * 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.meecrowave.logging.log4j2;
+
+import org.apache.logging.log4j.Level;
+import org.apache.logging.log4j.Marker;
+import org.apache.logging.log4j.core.LogEvent;
+import org.apache.logging.log4j.core.config.Property;
+import org.apache.logging.log4j.core.impl.DefaultLogEventFactory;
+import org.apache.logging.log4j.core.impl.Log4jLogEvent;
+import org.apache.logging.log4j.message.Message;
+
+import java.util.List;
+
+public class MeecrowaveLogEventFactory extends DefaultLogEventFactory {
+ @Override
+ public LogEvent createEvent(final String loggerName, final Marker marker, final String fqcn,
+ final Level level, final Message data, final List<Property> properties,
+ final Throwable t) {
+ return new MeecrowaveLog4jLogEvent(loggerName, marker, fqcn, level, data, properties, t);
+ }
+
+ public static class MeecrowaveLog4jLogEvent extends Log4jLogEvent {
+ private StackTraceElement source;
+
+ public MeecrowaveLog4jLogEvent(final String loggerName, final Marker marker, final String fqcn, final Level level,
+ final Message data, final List<Property> properties, final Throwable t) {
+ super(loggerName, marker, fqcn, level, data, properties, t);
+ }
+
+ @Override
+ public StackTraceElement getSource() { // this doesn't work OOTB and no config available
+ if (source != null) {
+ return source;
+ }
+ if (getLoggerFqcn() == null || !isIncludeLocation()) {
+ return null;
+ }
+
+ final StackTraceElement[] stackTrace = new Throwable().getStackTrace();
+ for (int i = stackTrace.length - 1; i > 0; i--) {
+ final String className = stackTrace[i].getClassName();
+ if (getLoggerFqcn().equals(className) && stackTrace.length > i + 1) {
+ source = stackTrace[i + 1];
+ if (i + 3 < stackTrace.length && stackTrace[i + 2].getClassName().equals("org.apache.meecrowave.logging.tomcat.LogFacade")) {
+ source = stackTrace[i + 3];
+ }
+ break;
+ }
+ }
+ return source;
+ }
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/openwebbeans/Log4j2LoggerFactory.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/openwebbeans/Log4j2LoggerFactory.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/openwebbeans/Log4j2LoggerFactory.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/openwebbeans/Log4j2LoggerFactory.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,38 @@
+/*
+ * 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.meecrowave.logging.openwebbeans;
+
+import org.apache.meecrowave.logging.jul.Log4j2Logger;
+import org.apache.webbeans.logger.WebBeansLoggerFactory;
+
+import java.util.Locale;
+import java.util.ResourceBundle;
+import java.util.logging.Logger;
+
+public class Log4j2LoggerFactory implements WebBeansLoggerFactory {
+ @Override
+ public Logger getLogger(final Class<?> clazz, final Locale desiredLocale) {
+ return new Log4j2Logger(clazz.getName(), ResourceBundle.getBundle("openwebbeans/Messages", desiredLocale).toString());
+ }
+
+ @Override
+ public Logger getLogger(final Class<?> clazz) {
+ return new Log4j2Logger(clazz.getName(), "openwebbeans/Messages");
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/JULLog.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/JULLog.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/JULLog.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/JULLog.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,179 @@
+/*
+ * 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.meecrowave.logging.tomcat;
+
+import org.apache.juli.logging.Log;
+
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Formatter;
+import java.util.logging.Handler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+// copied from tomcat to allow our routing logic
+public class JULLog implements Log {
+ private final Logger logger;
+
+ private static final String SIMPLE_FMT = "java.util.logging.SimpleFormatter";
+ private static final String SIMPLE_CFG = "org.apache.juli.JdkLoggerConfig"; //doesn't exist
+ private static final String FORMATTER = "org.apache.juli.formatter";
+
+ static {
+ if (System.getProperty("java.util.logging.config.class") == null &&
+ System.getProperty("java.util.logging.config.file") == null) {
+ try {
+ Class.forName(SIMPLE_CFG).newInstance();
+ } catch (final Throwable t) {
+ // no-op
+ }
+ try {
+ final Formatter fmt = (Formatter) Class.forName(System.getProperty(FORMATTER, SIMPLE_FMT)).newInstance();
+ Logger root = Logger.getLogger("");
+ for (Handler handler : root.getHandlers()) {
+ if (handler instanceof ConsoleHandler) {
+ handler.setFormatter(fmt);
+ }
+ }
+ } catch (final Throwable t) {
+ // maybe it wasn't included - the ugly default will be used.
+ }
+
+ }
+ }
+
+ public JULLog(final String name) {
+ logger = Logger.getLogger(name);
+ }
+
+ @Override
+ public final boolean isErrorEnabled() {
+ return logger.isLoggable(Level.SEVERE);
+ }
+
+ @Override
+ public final boolean isWarnEnabled() {
+ return logger.isLoggable(Level.WARNING);
+ }
+
+ @Override
+ public final boolean isInfoEnabled() {
+ return logger.isLoggable(Level.INFO);
+ }
+
+ @Override
+ public final boolean isDebugEnabled() {
+ return logger.isLoggable(Level.FINE);
+ }
+
+ @Override
+ public final boolean isFatalEnabled() {
+ return logger.isLoggable(Level.SEVERE);
+ }
+
+ @Override
+ public final boolean isTraceEnabled() {
+ return logger.isLoggable(Level.FINER);
+ }
+
+ @Override
+ public final void debug(final Object message) {
+ log(Level.FINE, String.valueOf(message), null);
+ }
+
+ @Override
+ public final void debug(final Object message, final Throwable t) {
+ log(Level.FINE, String.valueOf(message), t);
+ }
+
+ @Override
+ public final void trace(final Object message) {
+ log(Level.FINER, String.valueOf(message), null);
+ }
+
+ @Override
+ public final void trace(final Object message, final Throwable t) {
+ log(Level.FINER, String.valueOf(message), t);
+ }
+
+ @Override
+ public final void info(final Object message) {
+ log(Level.INFO, String.valueOf(message), null);
+ }
+
+ @Override
+ public final void info(final Object message, final Throwable t) {
+ log(Level.INFO, String.valueOf(message), t);
+ }
+
+ @Override
+ public final void warn(final Object message) {
+ log(Level.WARNING, String.valueOf(message), null);
+ }
+
+ @Override
+ public final void warn(final Object message, final Throwable t) {
+ log(Level.WARNING, String.valueOf(message), t);
+ }
+
+ @Override
+ public final void error(final Object message) {
+ log(Level.SEVERE, String.valueOf(message), null);
+ }
+
+ @Override
+ public final void error(final Object message, final Throwable t) {
+ log(Level.SEVERE, String.valueOf(message), t);
+ }
+
+ @Override
+ public final void fatal(final Object message) {
+ log(Level.SEVERE, String.valueOf(message), null);
+ }
+
+ @Override
+ public final void fatal(final Object message, final Throwable t) {
+ log(Level.SEVERE, String.valueOf(message), t);
+ }
+
+ // from commons logging. This would be my number one reason why java.util.logging
+ // is bad - design by committee can be really bad ! The impact on performance of
+ // using java.util.logging - and the ugliness if you need to wrap it - is far
+ // worse than the unfriendly and uncommon default format for logs.
+
+ private void log(final Level level, final String msg, final Throwable ex) {
+ if (logger.isLoggable(level)) {
+ // Hack (?) to get the stack trace.
+ Throwable dummyException = new Throwable();
+ StackTraceElement locations[] = dummyException.getStackTrace();
+ // Caller will be the third element
+ String cname = "unknown";
+ String method = "unknown";
+ if (locations != null && locations.length > 2) {
+ StackTraceElement caller = locations[2];
+ cname = caller.getClassName();
+ method = caller.getMethodName();
+ }
+ if (ex == null) {
+ logger.logp(level, cname, method, msg);
+ } else {
+ logger.logp(level, cname, method, msg, ex);
+ }
+ }
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/Log4j2Log.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/Log4j2Log.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/Log4j2Log.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/Log4j2Log.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,121 @@
+/*
+ * 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.meecrowave.logging.tomcat;
+
+import org.apache.juli.logging.Log;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+public class Log4j2Log implements Log {
+ private final Logger delegate;
+
+ public Log4j2Log(final String name) {
+ delegate = LogManager.getLogger(name);
+ }
+
+ @Override
+ public boolean isDebugEnabled() {
+ return delegate.isDebugEnabled();
+ }
+
+ @Override
+ public boolean isErrorEnabled() {
+ return delegate.isErrorEnabled();
+ }
+
+ @Override
+ public boolean isFatalEnabled() {
+ return delegate.isFatalEnabled();
+ }
+
+ @Override
+ public boolean isInfoEnabled() {
+ return delegate.isInfoEnabled();
+ }
+
+ @Override
+ public boolean isTraceEnabled() {
+ return delegate.isTraceEnabled();
+ }
+
+ @Override
+ public boolean isWarnEnabled() {
+ return delegate.isWarnEnabled();
+ }
+
+ @Override
+ public void trace(final Object message) {
+ delegate.trace(message);
+ }
+
+ @Override
+ public void trace(final Object message, final Throwable t) {
+ delegate.trace(message, t);
+ }
+
+ @Override
+ public void debug(final Object message) {
+ delegate.debug(message);
+ }
+
+ @Override
+ public void debug(final Object message, final Throwable t) {
+ delegate.debug(message, t);
+ }
+
+ @Override
+ public void info(final Object message) {
+ delegate.info(message);
+ }
+
+ @Override
+ public void info(final Object message, final Throwable t) {
+ delegate.info(message, t);
+ }
+
+ @Override
+ public void warn(final Object message) {
+ delegate.warn(message);
+ }
+
+ @Override
+ public void warn(final Object message, final Throwable t) {
+ delegate.warn(message, t);
+ }
+
+ @Override
+ public void error(final Object message) {
+ delegate.error(message);
+ }
+
+ @Override
+ public void error(final Object message, final Throwable t) {
+ delegate.error(message, t);
+ }
+
+ @Override
+ public void fatal(final Object message) {
+ delegate.fatal(message);
+ }
+
+ @Override
+ public void fatal(final Object message, final Throwable t) {
+ delegate.fatal(message, t);
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/LogFacade.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/LogFacade.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/LogFacade.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/logging/tomcat/LogFacade.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,125 @@
+/*
+ * 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.meecrowave.logging.tomcat;
+
+import org.apache.juli.logging.Log;
+
+public class LogFacade implements Log {
+ private final Log delegate;
+
+ public LogFacade() { // for the spi
+ this.delegate = null;
+ }
+
+ public LogFacade(final String name) {
+ // should be read per launch and not once per JVM
+ this.delegate = "org.apache.meecrowave.logging.tomcat.Log4j2Log".equals(System.getProperty("org.apache.tomcat.Logger", "jul")) ?
+ new Log4j2Log(name) : new JULLog(name);
+ }
+
+ @Override
+ public boolean isDebugEnabled() {
+ return delegate.isDebugEnabled();
+ }
+
+ @Override
+ public boolean isErrorEnabled() {
+ return delegate.isErrorEnabled();
+ }
+
+ @Override
+ public boolean isFatalEnabled() {
+ return delegate.isFatalEnabled();
+ }
+
+ @Override
+ public boolean isInfoEnabled() {
+ return delegate.isInfoEnabled();
+ }
+
+ @Override
+ public boolean isTraceEnabled() {
+ return delegate.isTraceEnabled();
+ }
+
+ @Override
+ public boolean isWarnEnabled() {
+ return delegate.isWarnEnabled();
+ }
+
+ @Override
+ public void trace(final Object message) {
+ delegate.trace(message);
+ }
+
+ @Override
+ public void trace(final Object message, final Throwable t) {
+ delegate.trace(message, t);
+ }
+
+ @Override
+ public void debug(final Object message) {
+ delegate.debug(message);
+ }
+
+ @Override
+ public void debug(final Object message, final Throwable t) {
+ delegate.debug(message, t);
+ }
+
+ @Override
+ public void info(final Object message) {
+ delegate.info(message);
+ }
+
+ @Override
+ public void info(final Object message, final Throwable t) {
+ delegate.info(message, t);
+ }
+
+ @Override
+ public void warn(final Object message) {
+ delegate.warn(message);
+ }
+
+ @Override
+ public void warn(final Object message, final Throwable t) {
+ delegate.warn(message, t);
+ }
+
+ @Override
+ public void error(final Object message) {
+ delegate.error(message);
+ }
+
+ @Override
+ public void error(final Object message, final Throwable t) {
+ delegate.error(message, t);
+ }
+
+ @Override
+ public void fatal(final Object message) {
+ delegate.fatal(message);
+ }
+
+ @Override
+ public void fatal(final Object message, final Throwable t) {
+ delegate.fatal(message, t);
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnowClassesFilter.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnowClassesFilter.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnowClassesFilter.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnowClassesFilter.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,194 @@
+/*
+ * 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.meecrowave.openwebbeans;
+
+import org.apache.xbean.finder.filter.Filter;
+
+import java.util.HashSet;
+import java.util.Set;
+
+public class KnowClassesFilter implements Filter { // one easy and efficient solution for fatjars
+ private static final String[] EMPTY_ARRAY = new String[0];
+
+ // this has to be configured from the root config
+ private final String[] forced = EMPTY_ARRAY;
+ private final String[] skipped = EMPTY_ARRAY;
+
+ private final Filter delegateAccept;
+ private final Filter delegateSkip;
+
+ public KnowClassesFilter() {
+ final Set<String> excluded = new HashSet<>();
+ excluded.add("com.codehale.metrics");
+ excluded.add("com.ctc.wstx");
+ excluded.add("com.datastax.driver.core");
+ excluded.add("com.fasterxml.jackson.annotation");
+ excluded.add("com.fasterxml.jackson.core");
+ excluded.add("com.fasterxml.jackson.databind");
+ excluded.add("com.fasterxml.jackson.dataformat");
+ excluded.add("com.fasterxml.jackson.module");
+ excluded.add("com.google.common");
+ excluded.add("com.google.thirdparty");
+ excluded.add("com.ibm.wsdl");
+ excluded.add("com.jcraft.jsch");
+ excluded.add("com.kenai.jffi");
+ excluded.add("com.kenai.jnr");
+ excluded.add("com.sun.istack");
+ excluded.add("com.sun.xml.bind");
+ excluded.add("com.sun.xml.messaging.saaj");
+ excluded.add("com.sun.xml.txw2");
+ excluded.add("io.jsonwebtoken");
+ excluded.add("io.netty");
+ excluded.add("io.swagger.annotations");
+ excluded.add("io.swagger.config");
+ excluded.add("io.swagger.converter");
+ excluded.add("io.swagger.core");
+ excluded.add("io.swagger.jackson");
+ excluded.add("io.swagger.jaxrs");
+ excluded.add("io.swagger.model");
+ excluded.add("io.swagger.models");
+ excluded.add("io.swagger.util");
+ excluded.add("javax");
+ excluded.add("jnr");
+ excluded.add("junit");
+ excluded.add("net.sf.ehcache");
+ excluded.add("net.shibboleth.utilities.java.support");
+ excluded.add("org.aeonbits.owner");
+ excluded.add("org.apache.activemq");
+ excluded.add("org.apache.bval");
+ excluded.add("org.apache.catalina");
+ excluded.add("org.apache.camel");
+ excluded.add("org.apache.commons.beanutils");
+ excluded.add("org.apache.commons.cli");
+ excluded.add("org.apache.commons.codec");
+ excluded.add("org.apache.commons.collections");
+ excluded.add("org.apache.commons.dbcp2");
+ excluded.add("org.apache.commons.digester");
+ excluded.add("org.apache.commons.io");
+ excluded.add("org.apache.commons.lang");
+ excluded.add("org.apache.commons.lang3");
+ excluded.add("org.apache.commons.logging");
+ excluded.add("org.apache.commons.pool2");
+ excluded.add("org.apache.coyote");
+ excluded.add("org.apache.cxf");
+ excluded.add("org.apache.geronimo.javamail");
+ excluded.add("org.apache.geronimo.mail");
+ excluded.add("org.apache.geronimo.osgi");
+ excluded.add("org.apache.http");
+ excluded.add("org.apache.jcp");
+ excluded.add("org.apache.johnzon");
+ excluded.add("org.apache.juli");
+ excluded.add("org.apache.logging.log4j.core");
+ excluded.add("org.apache.logging.log4j.util");
+ excluded.add("org.apache.logging.slf4j");
+ excluded.add("org.apache.meecrowave");
+ excluded.add("org.apache.myfaces");
+ excluded.add("org.apache.naming");
+ excluded.add("org.apache.neethi");
+ excluded.add("org.apache.openejb");
+ excluded.add("org.apache.oro");
+ excluded.add("org.apache.tomcat");
+ excluded.add("org.apache.tomee");
+ excluded.add("org.apache.velocity");
+ excluded.add("org.apache.webbeans");
+ excluded.add("org.apache.ws");
+ excluded.add("org.apache.wss4j");
+ excluded.add("org.apache.xbean");
+ excluded.add("org.apache.xml");
+ excluded.add("org.apache.xml.resolver");
+ excluded.add("org.bouncycastle");
+ excluded.add("org.codehaus.stax2");
+ excluded.add("org.codehaus.swizzle.Grep");
+ excluded.add("org.codehaus.swizzle.Lexer");
+ excluded.add("org.cryptacular");
+ excluded.add("org.eclipse.jdt.core");
+ excluded.add("org.eclipse.jdt.internal");
+ excluded.add("org.fusesource.hawtbuf");
+ excluded.add("org.hamcrest");
+ excluded.add("org.hsqldb");
+ excluded.add("org.jasypt");
+ excluded.add("org.jboss.marshalling");
+ excluded.add("org.joda.time");
+ excluded.add("org.jose4j");
+ excluded.add("org.junit");
+ excluded.add("org.jvnet.mimepull");
+ excluded.add("org.metatype.sxc");
+ excluded.add("org.objectweb.asm");
+ excluded.add("org.objectweb.howl");
+ excluded.add("org.openejb");
+ excluded.add("org.opensaml");
+ excluded.add("org.slf4j");
+ excluded.add("org.swizzle");
+ excluded.add("org.terracotta.context");
+ excluded.add("org.terracotta.entity");
+ excluded.add("org.terracotta.modules.ehcache");
+ excluded.add("org.terracotta.statistics");
+ excluded.add("org.yaml.snakeyaml");
+ excluded.add("serp");
+
+ final Set<String> included = new HashSet<>();
+ included.add("org.apache.camel.cdi");
+ included.add("org.apache.myfaces.cdi");
+ // included.add("org.apache.myfaces.application.cdi");
+ included.add("org.apache.myfaces.flow.cdi");
+
+ delegateSkip = new OptimizedExclusionFilter(excluded);
+ delegateAccept = new OptimizedExclusionFilter(included);
+ }
+
+ @Override
+ public boolean accept(final String name) {
+ if (forced != null && startsWith(forced, name)) {
+ return true;
+ }
+ if (skipped != null && startsWith(skipped, name)) {
+ return false;
+ }
+ return delegateAccept.accept(name) || !delegateSkip.accept(name);
+ }
+
+ private static boolean startsWith(final String[] array, String name) {
+ for (final String prefix : array) {
+ if (name.startsWith(prefix)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+ private static class OptimizedExclusionFilter implements Filter {
+ private final Set<String> included;
+
+ private OptimizedExclusionFilter(final Set<String> exclusions) {
+ included = exclusions;
+ }
+
+ @Override
+ public boolean accept(final String name) {
+ int dot = name.indexOf('.');
+ while (dot > 0) {
+ if (included.contains(name.substring(0, dot))) {
+ return true;
+ }
+ dot = name.indexOf('.', dot + 1);
+ }
+ return included.contains(name);
+ }
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownJarsFilter.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownJarsFilter.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownJarsFilter.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/KnownJarsFilter.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,304 @@
+/*
+ * 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.meecrowave.openwebbeans;
+
+import org.apache.tomcat.JarScanFilter;
+import org.apache.tomcat.JarScanType;
+
+import java.util.Collection;
+import java.util.HashSet;
+
+public class KnownJarsFilter implements JarScanFilter {
+ private final Collection<String> forceIncludes = new HashSet<String>() {{
+ add("cxf-integration-cdi");
+ }};
+
+ private final Collection<String> excludes = new HashSet<String>() {{
+ add("tools.jar");
+ add("bootstrap.jar");
+ add("ApacheJMeter");
+ add("XmlSchema-");
+ add("activation-");
+ add("activeio-");
+ add("activemq-");
+ add("aether-");
+ add("akka-actor-");
+ add("akka-cluster-");
+ add("akka-remote-");
+ add("antlr-");
+ add("aopalliance-");
+ add("args4j-");
+ add("arquillian-core.jar");
+ add("arquillian-testng.jar");
+ add("arquillian-junit.jar");
+ add("arquillian-transaction.jar");
+ add("arquillian-common");
+ add("arquillian-config-");
+ add("arquillian-core-api-");
+ add("arquillian-core-impl-base");
+ add("arquillian-core-spi-");
+ add("arquillian-container-");
+ add("arquillian-junit-");
+ add("arquillian-test-api");
+ add("arquillian-test-impl-base");
+ add("arquillian-test-spi");
+ add("arquillian-tomee-");
+ add("asciidoctorj-");
+ add("asm-");
+ add("avalon-framework-");
+ add("axis-");
+ add("axis2-");
+ add("batchee-jbatch");
+ add("bcprov-");
+ add("bootstrap.jar");
+ add("bval-core");
+ add("bval-jsr");
+ add("c3p0-");
+ add("cassandra-driver-core");
+ add("catalina-");
+ add("catalina.jar");
+ add("cglib-");
+ add("charsets.jar");
+ add("commons-beanutils");
+ add("commons-cli-");
+ add("commons-codec-");
+ add("commons-collections-");
+ add("commons-configuration-");
+ add("commons-dbcp");
+ add("commons-dbcp-all-1.3-");
+ add("commons-digester-");
+ add("commons-discovery-");
+ add("commons-httpclient-");
+ add("commons-io-");
+ add("commons-jcs-core-");
+ add("commons-lang-");
+ add("commons-lang3-");
+ add("commons-logging-");
+ add("commons-logging-api-");
+ add("commons-net-");
+ add("commons-pool-");
+ add("commons-pool2-");
+ add("cryptacular-");
+ add("cssparser-");
+ add("cxf-");
+ add("deploy.jar");
+ add("derby-");
+ add("derbyclient-");
+ add("derbynet-");
+ add("dom4j");
+ add("ecj-");
+ add("el-api");
+ add("eclipselink-");
+ add("ehcache-");
+ add("FastInfoset");
+ add("jce.jar");
+ add("jfr.jar");
+ add("jfxrt.jar");
+ add("jna-");
+ add("jnr-");
+ add("johnzon-");
+ add("json-simple-");
+ add("fusemq-leveldb-");
+ add("geronimo-");
+ add("google-");
+ add("gragent.jar");
+ add("groovy-");
+ add("gson-");
+ add("guava-");
+ add("guice-");
+ add("h2-");
+ add("hamcrest-");
+ add("hawtbuf-");
+ add("hawtdispatch-");
+ add("hawtjni-runtime");
+ add("hibernate-");
+ add("howl-");
+ add("hsqldb-");
+ add("htmlunit-");
+ add("httpclient-");
+ add("httpcore-");
+ add("icu4j-");
+ add("idb-");
+ add("idea_rt.jar");
+ add("istack-commons-runtime-");
+ add("jackson-annotations-");
+ add("jackson-core-");
+ add("jackson-databind-");
+ add("jackson-mapper-asl-");
+ add("jackson-module-jaxb-annotations-");
+ add("janino-");
+ add("jansi-");
+ add("jasper.jar");
+ add("jasper-el.jar");
+ add("jasypt-");
+ add("java-atk-wrapper");
+ add("java-support-");
+ add("javaee-");
+ add("javaee-api");
+ add("javassist-");
+ add("javaws.jar");
+ add("javax.");
+ add("jaxb-");
+ add("jaxp-");
+ add("jbake-");
+ add("jboss-");
+ add("jbossall-");
+ add("jbosscx-");
+ add("jbossjts-");
+ add("jbosssx-");
+ add("jcommander-");
+ add("jersey-");
+ add("jettison-");
+ add("jetty-");
+ add("jline");
+ add("jmdns-");
+ add("joda-time-");
+ add("johnzon-");
+ add("jruby-");
+ add("jsoup-");
+ add("jsonb-api");
+ add("jsp-api");
+ add("jsr299-");
+ add("jsr311-");
+ add("jsse.jar");
+ add("jul-to-slf4j-");
+ add("juli-");
+ add("junit-");
+ add("kahadb-");
+ add("kotlin-runtime");
+ add("leveldb");
+ add("log4j-");
+ add("logkit-");
+ add("lucene-analyzers-");
+ add("lucene-core-");
+ add("management-agent.jar");
+ add("maven-");
+ add("mbean-annotation-api-");
+ add("meecrowave-maven-");
+ add("meecrowave-gradle-");
+ add("mimepull-");
+ add("mina-");
+ add("mqtt-client-");
+ add("myfaces-api");
+ add("myfaces-impl");
+ add("mysql-connector-java-");
+ add("neethi-");
+ add("nekohtml-");
+ add("netty-");
+ add("openjpa-");
+ add("openmdx-");
+ add("opensaml-");
+ add("openwebbeans-");
+ add("openws-");
+ add("ops4j-");
+ add("org.eclipse.");
+ add("org.junit.");
+ add("org.osgi.core-");
+ add("orient-commons-");
+ add("orientdb-core-");
+ add("orientdb-nativeos-");
+ add("oro-");
+ add("pax-url");
+ add("PDFBox");
+ add("plexus-");
+ add("plugin.jar");
+ add("poi-");
+ add("quartz-2");
+ add("quartz-openejb-");
+ add("resources.jar");
+ add("rmock-");
+ add("rt.jar");
+ add("saaj-");
+ add("sac-");
+ add("scala-library-");
+ add("scalatest");
+ add("scannotation-");
+ add("serializer-");
+ add("serp-");
+ add("servlet-api-");
+ add("sisu-inject");
+ add("sisu-guice");
+ add("shrinkwrap-");
+ add("slf4j-");
+ add("smack-");
+ add("smackx-");
+ add("snappy-");
+ add("spring-");
+ add("sshd-");
+ add("stax-api-");
+ add("stax2-api-");
+ add("sunec.jar");
+ add("surefire-");
+ add("swizzle-");
+ add("sxc-");
+ add("testng-");
+ add("tomcat-annotations");
+ add("tomcat-api");
+ add("tomcat-catalina");
+ add("tomcat-coyote");
+ add("tomcat-dbcp");
+ add("tomcat-el");
+ add("tomcat-i18n");
+ add("tomcat-jasper");
+ add("tomcat-jaspic");
+ add("tomcat-jdbc");
+ add("tomcat-jni");
+ add("tomcat-jsp");
+ add("tomcat-juli");
+ add("tomcat-tribes");
+ add("tomcat-servlet");
+ add("tomcat-spdy");
+ add("tomcat-util");
+ add("tomcat-websocket-api");
+ add("tomee-");
+ add("tools.jar");
+ add("twitter4j-");
+ add("velocity-");
+ add("wagon-");
+ add("webbeans-ee");
+ add("webbeans-ejb");
+ add("webbeans-impl");
+ add("webbeans-spi");
+ add("websocket-api");
+ add("woodstox-core-asl-");
+ add("ws-commons-util-");
+ add("wsdl4j-");
+ add("wss4j-");
+ add("wstx-asl-");
+ add("xalan-");
+ add("xbean-");
+ add("xercesImpl-");
+ add("xml-apis-");
+ add("xml-resolver-");
+ add("xmlbeans-");
+ add("xmlrpc-");
+ add("xmlschema-");
+ add("xmlsec-");
+ add("xmltooling-");
+ add("xmlunit-");
+ add("ziplock-");
+ add("zipfs.jar");
+ }};
+
+ @Override
+ public boolean check(final JarScanType jarScanType, final String jarName) {
+ return forceIncludes.stream().filter(jarName::startsWith).findAny().isPresent()
+ || !excludes.stream().filter(jarName::startsWith).findAny().isPresent();
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveBeansExtension.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveBeansExtension.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveBeansExtension.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveBeansExtension.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,34 @@
+/*
+ * 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.meecrowave.openwebbeans;
+
+import org.apache.meecrowave.cxf.MeecrowaveBus;
+
+import javax.enterprise.event.Observes;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.BeforeBeanDiscovery;
+import javax.enterprise.inject.spi.Extension;
+import java.util.stream.Stream;
+
+public class MeecrowaveBeansExtension implements Extension {
+ void addBeansFromJava(@Observes final BeforeBeanDiscovery bbd, final BeanManager bm) {
+ // stream not really needed but here for the pattern in case we need other beans
+ Stream.of(MeecrowaveBus.class).forEach(type -> bbd.addAnnotatedType(bm.createAnnotatedType(type)));
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveSecurityService.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveSecurityService.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveSecurityService.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/MeecrowaveSecurityService.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,50 @@
+/*
+ * 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.meecrowave.openwebbeans;
+
+import org.apache.webbeans.corespi.security.SimpleSecurityService;
+
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.CDI;
+import javax.servlet.http.HttpServletRequest;
+import java.security.Principal;
+
+public class MeecrowaveSecurityService extends SimpleSecurityService {
+ @Override // reason of that class
+ public Principal getCurrentPrincipal() {
+ return new MeecrowavePrincipal();
+ }
+
+ // ensure it is contextual
+ private static class MeecrowavePrincipal implements Principal {
+ @Override
+ public String getName() {
+ return unwrap().getName();
+ }
+
+ private Principal unwrap() {
+ final BeanManager beanManager = CDI.current().getBeanManager();
+ return HttpServletRequest.class.cast(
+ beanManager.getReference(
+ beanManager.resolve(beanManager.getBeans(HttpServletRequest.class)), HttpServletRequest.class,
+ beanManager.createCreationalContext(null)))
+ .getUserPrincipal();
+ }
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBAutoSetup.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBAutoSetup.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBAutoSetup.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBAutoSetup.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,43 @@
+/*
+ * 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.meecrowave.openwebbeans;
+
+import org.apache.meecrowave.Meecrowave;
+import org.apache.webbeans.servlet.WebBeansConfigurationListener;
+import org.apache.webbeans.web.context.WebConversationFilter;
+
+import javax.servlet.DispatcherType;
+import javax.servlet.FilterRegistration;
+import javax.servlet.ServletContainerInitializer;
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+import java.util.EnumSet;
+import java.util.Set;
+
+public class OWBAutoSetup implements ServletContainerInitializer {
+ @Override
+ public void onStartup(final Set<Class<?>> c, final ServletContext ctx) throws ServletException {
+ final Meecrowave.Builder builder = Meecrowave.Builder.class.cast(ctx.getAttribute("meecrowave.configuration"));
+ if (builder.isCdiConversation()) {
+ final FilterRegistration.Dynamic filter = ctx.addFilter("owb-conversation", WebConversationFilter.class);
+ filter.addMappingForUrlPatterns(EnumSet.allOf(DispatcherType.class), false, "/*");
+ }
+ ctx.addListener(WebBeansConfigurationListener.class);
+ }
+}
Added: openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java
URL: http://svn.apache.org/viewvc/openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java?rev=1769479&view=auto
==============================================================================
--- openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java (added)
+++ openwebbeans/microwave/trunk/meecrowave-core/src/main/java/org/apache/meecrowave/openwebbeans/OWBTomcatWebScannerService.java Sun Nov 13 09:34:07 2016
@@ -0,0 +1,139 @@
+/*
+ * 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.meecrowave.openwebbeans;
+
+import org.apache.meecrowave.logging.tomcat.LogFacade;
+import org.apache.tomcat.JarScanFilter;
+import org.apache.webbeans.web.scanner.WebScannerService;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.HashSet;
+import java.util.Set;
+
+import static java.util.Optional.of;
+import static java.util.Optional.ofNullable;
+import static org.apache.tomcat.JarScanType.PLUGGABILITY;
+
+public class OWBTomcatWebScannerService extends WebScannerService {
+ private final LogFacade logger = new LogFacade(OWBTomcatWebScannerService.class.getName());
+
+ private JarScanFilter filter;
+ private String jreBase;
+
+ // just for logging (== temp)
+ private final Set<String> urls = new HashSet<>();
+ private String docBase;
+ private String shared;
+
+ @Override
+ public void scan() {
+ if (finder != null) {
+ return;
+ }
+ super.scan();
+ if (!urls.isEmpty()) {
+ logger.info("OpenWebBeans scanning:");
+ final String m2 = new File(System.getProperty("user.home", "."), ".m2/repository").getAbsolutePath();
+ final String base = ofNullable(docBase).orElse("$$$");
+ final String sharedBase = ofNullable(shared).orElse("$$$");
+ urls.stream().map(u -> {
+ String shownValue = u
+ // protocol
+ .replace("file://", "")
+ .replace("file:", "")
+ .replace("jar:", "")
+ // URL suffix
+ .replace("!/META-INF/beans.xml", "")
+ .replace("!/", "")
+ // beans.xml
+ .replace("META-INF/beans.xml", "");
+
+ // try to make it shorter
+ if (shownValue.startsWith(m2)) {
+ shownValue = "${maven}/" + shownValue.substring(shownValue.replace(File.separatorChar, '/').lastIndexOf('/') + 1);
+ } else if (shownValue.startsWith(base)) {
+ shownValue = "${app}" + shownValue.replace(base, "");
+ } else if (sharedBase != null && shownValue.startsWith(sharedBase)) {
+ shownValue = "${shared}" + shownValue.replace(sharedBase, "");
+ }
+
+ return shownValue;
+ }).sorted().forEach(v -> logger.info(" " + v));
+ }
+ urls.clear(); // no more needed
+ filter = null;
+ docBase = null;
+ shared = null;
+ }
+
+ @Override
+ protected void filterExcludedJars(final Set<URL> classPathUrls) {
+ if (filter == null) {
+ filter = new KnownJarsFilter();
+ }
+
+ String jreBaseTmp;
+ try {
+ jreBaseTmp = new File(System.getProperty("java.home")).toURI().toURL().toExternalForm();
+ } catch (MalformedURLException e) {
+ jreBaseTmp = System.getProperty("java.home");
+ }
+ jreBase = jreBaseTmp;
+
+ super.filterExcludedJars(classPathUrls);
+ }
+
+ @Override
+ protected int isExcludedJar(final String path) {
+ if (path.startsWith(jreBase) || (path.startsWith("jar:") && path.indexOf(jreBase) == 4)) {
+ return jreBase.length();
+ }
+
+ final int filenameIdx = path.replace(File.separatorChar, '/').replace("!/", "").lastIndexOf('/') + 1;
+ if (filenameIdx < 0 || filenameIdx >= path.length()) { // unlikely
+ return -1;
+ }
+
+ return filter.check(PLUGGABILITY, path.substring(filenameIdx)) ? -1 : (path.indexOf(".jar") - 1);
+ }
+
+ public void setFilter(final JarScanFilter filter) {
+ this.filter = filter;
+ }
+
+ @Override
+ protected void addWebBeansXmlLocation(final URL beanArchiveUrl) {
+ final String url = beanArchiveUrl.toExternalForm();
+ if (urls.add(of(url)
+ .map(s -> s.startsWith("jar:") && s.endsWith("!/META-INF/beans.xml") ? s.substring("jar:".length(), s.length() - "!/META-INF/beans.xml".length()) : s)
+ .get())) {
+ super.doAddWebBeansXmlLocation(beanArchiveUrl);
+ }
+ }
+
+ public void setShared(final String shared) {
+ this.shared = ofNullable(shared).map(File::new).filter(File::isDirectory).map(File::getAbsolutePath).orElse(null);
+ }
+
+ public void setDocBase(final String docBase) {
+ this.docBase = docBase;
+ }
+}