Propchange:
openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/JettySecurityService.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/JettyUtil.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/JettyUtil.java?rev=1858225&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/JettyUtil.java
(added)
+++
openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/JettyUtil.java
Fri Apr 26 20:15:55 2019
@@ -0,0 +1,87 @@
+/*
+ * 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.webbeans.web.jetty9;
+
+import javax.enterprise.context.spi.CreationalContext;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.Producer;
+
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.container.BeanManagerImpl;
+import org.apache.webbeans.inject.OWBInjector;
+
+/**
+ * Helper class for assisting injection.
+ */
+public class JettyUtil
+{
+ public static Object inject(Object object, ClassLoader loader)
+ {
+ ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(loader);
+ CreationalContext<?> context = null;
+ try
+ {
+ BeanManager beanManager =
WebBeansContext.currentInstance().getBeanManagerImpl();
+ context = beanManager.createCreationalContext(null);
+ OWBInjector.inject(beanManager, object, context);
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(oldLoader);
+ }
+ return new Instance(object, context);
+ }
+
+ public static void destroy(Object injectorInstance, ClassLoader loader)
+ {
+ Instance instance = (JettyUtil.Instance) injectorInstance;
+ ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
+ Thread.currentThread().setContextClassLoader(loader);
+ try
+ {
+ BeanManagerImpl beanManager =
WebBeansContext.currentInstance().getBeanManagerImpl();
+ Producer producer =
beanManager.getProducerForJavaEeComponent(instance.object.getClass());
+ if (producer != null)
+ {
+ producer.dispose(instance.object);
+ }
+ else if (instance.context != null)
+ {
+ instance.context.release();
+ }
+ }
+ finally
+ {
+ Thread.currentThread().setContextClassLoader(oldLoader);
+ }
+ }
+
+ private static final class Instance
+ {
+ private Object object;
+ private CreationalContext<?> context;
+
+ private Instance(Object object, CreationalContext<?> context)
+ {
+ this.object = object;
+ this.context = context;
+ }
+ }
+}
Propchange:
openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/JettyUtil.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/JettyWebPlugin.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/JettyWebPlugin.java?rev=1858225&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/JettyWebPlugin.java
(added)
+++
openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/JettyWebPlugin.java
Fri Apr 26 20:15:55 2019
@@ -0,0 +1,132 @@
+/*
+ * 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.webbeans.web.jetty9;
+
+import java.util.EventListener;
+
+import javax.servlet.Filter;
+import javax.servlet.Servlet;
+import javax.servlet.ServletContextAttributeListener;
+import javax.servlet.ServletContextListener;
+import javax.servlet.ServletRequestAttributeListener;
+import javax.servlet.ServletRequestListener;
+import javax.servlet.http.HttpSessionActivationListener;
+import javax.servlet.http.HttpSessionAttributeListener;
+import javax.servlet.http.HttpSessionBindingListener;
+import javax.servlet.http.HttpSessionListener;
+
+import org.apache.webbeans.exception.WebBeansConfigurationException;
+import org.apache.webbeans.spi.SecurityService;
+import org.apache.webbeans.spi.plugins.AbstractOwbPlugin;
+
+/**
+ * Jetty plugin for OWB.
+ */
+public class JettyWebPlugin extends AbstractOwbPlugin
+{
+ //Security service implementation.
+ private final JettySecurityService securityService = new
JettySecurityService();
+
+ /**
+ * Default constructor.
+ */
+ public JettyWebPlugin()
+ {
+
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public <T> T getSupportedService(Class<T> serviceClass)
+ {
+ if(serviceClass.equals(SecurityService.class))
+ {
+ return serviceClass.cast(this.securityService);
+ }
+
+ return null;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public void isManagedBean(Class<?> clazz)
+ {
+ if (isServletSpecClass(clazz))
+ {
+ throw new WebBeansConfigurationException("Given class : " +
clazz.getName() + " is not managed bean");
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean supportsJavaEeComponentInjections(Class<?> clazz)
+ {
+ if (isServletSpecClass(clazz))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+ private boolean isServletSpecClass(Class<?> clazz)
+ {
+ if (Servlet.class.isAssignableFrom(clazz) ||
+ Filter.class.isAssignableFrom(clazz))
+ {
+ return true;
+ }
+
+ if (EventListener.class.isAssignableFrom(clazz))
+ {
+ return ServletContextListener.class.isAssignableFrom(clazz) ||
+
ServletContextAttributeListener.class.isAssignableFrom(clazz) ||
+
HttpSessionActivationListener.class.isAssignableFrom(clazz) ||
+ HttpSessionAttributeListener.class.isAssignableFrom(clazz)
||
+ HttpSessionBindingListener.class.isAssignableFrom(clazz) ||
+ HttpSessionListener.class.isAssignableFrom(clazz) ||
+ ServletRequestListener.class.isAssignableFrom(clazz) ||
+
ServletRequestAttributeListener.class.isAssignableFrom(clazz);
+ }
+ return false;
+ }
+
+
+ /**
+ * {@inheritDoc}
+ */
+ @Override
+ public boolean supportService(Class<?> serviceClass)
+ {
+ if (serviceClass.equals(SecurityService.class))
+ {
+ return true;
+ }
+
+ return false;
+ }
+
+}
Propchange:
openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/JettyWebPlugin.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/OwbConfiguration.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/OwbConfiguration.java?rev=1858225&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/OwbConfiguration.java
(added)
+++
openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/OwbConfiguration.java
Fri Apr 26 20:15:55 2019
@@ -0,0 +1,133 @@
+/*
+ * 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.webbeans.web.jetty9;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.EventListener;
+
+import javax.servlet.ServletContext;
+import javax.servlet.ServletException;
+
+import org.eclipse.jetty.server.handler.ContextHandler;
+import org.eclipse.jetty.servlet.ServletContextHandler;
+import org.eclipse.jetty.util.DecoratedObjectFactory;
+import org.eclipse.jetty.webapp.ClasspathPattern;
+import org.eclipse.jetty.webapp.Configuration;
+import org.eclipse.jetty.webapp.WebAppContext;
+
+/**
+ * A Jetty module configurator for use in embedded mode or a Jetty module.
+ */
+public class OwbConfiguration implements Configuration
+{
+ private static final String LISTENER_CLASS_NAME =
"org.apache.webbeans.servlet.WebBeansConfigurationListener";
+
+ static void addOwb(WebAppContext ctx) throws ServletException
+ {
+ URL url = getBeansXml(ctx.getServletContext());
+ if (url != null)
+ {
+ //Registering ELResolver with JSP container
+ System.setProperty("org.apache.webbeans.application.jsp", "true");
+ addOwbListeners((ServletContextHandler.Context)
ctx.getServletContext());
+ addOwbFilters(ctx.getServletContext());
+ DecoratedObjectFactory decObjFact = ctx.getObjectFactory();
+ decObjFact.addDecorator(new JettyDecorator(ctx.getClassLoader()));
+ }
+ }
+
+ private static void addOwbListeners(ServletContextHandler.Context context)
throws ServletException
+ {
+ for (EventListener eventListener :
context.getContextHandler().getEventListeners())
+ {
+ if
(eventListener.getClass().getName().equals(LISTENER_CLASS_NAME))
+ {
+ return;
+ }
+ }
+ context.addListener(LISTENER_CLASS_NAME);
+ }
+
+ private static void addOwbFilters(ContextHandler.Context context)
+ {
+ // we currently add all other filters via web-fragment.xml
+ }
+
+ private static URL getBeansXml(ServletContext ctx) throws ServletException
+ {
+ try
+ {
+ URL url = ctx.getResource("/WEB-INF/beans.xml");
+ if (url == null)
+ {
+ url = ctx.getResource("/WEB-INF/classes/META-INF/beans.xml");
+ }
+ return url;
+ }
+ catch (MalformedURLException e)
+ {
+ throw new ServletException(e);
+ }
+ }
+
+ @Override
+ public void preConfigure(WebAppContext ctx) throws Exception
+ {
+ final ClasspathPattern classpathPattern =
ctx.getServerClasspathPattern();
+ classpathPattern.add("-org.eclipse.jetty.util.Decorator");
+ classpathPattern.add("-org.eclipse.jetty.util.DecoratedObjectFactory");
+
classpathPattern.add("-org.eclipse.jetty.server.handler.ContextHandler");
+
classpathPattern.add("-org.eclipse.jetty.servlet.ServletContextHandler$Context");
+
classpathPattern.add("-org.eclipse.jetty.servlet.ServletContextHandler");
+ classpathPattern.add("-org.eclipse.jetty.webapp.WebAppContext");
+ }
+
+ @Override
+ public void configure(WebAppContext ctx) throws Exception
+ {
+ addOwb(ctx);
+ }
+
+ @Override
+ public void postConfigure(WebAppContext ctx) throws Exception
+ {
+
+ }
+
+ @Override
+ public void deconfigure(WebAppContext ctx) throws Exception
+ {
+
+ }
+
+ @Override
+ public void destroy(WebAppContext ctx) throws Exception
+ {
+
+ }
+
+ @Override
+ public void cloneConfigure(WebAppContext template, WebAppContext ctx)
throws Exception
+ {
+
+ }
+
+
+}
Propchange:
openwebbeans/trunk/webbeans-jetty9/src/main/java/org/apache/webbeans/web/jetty9/OwbConfiguration.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openwebbeans/trunk/webbeans-jetty9/src/main/resources/META-INF/services/org.apache.webbeans.spi.plugins.OpenWebBeansPlugin
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jetty9/src/main/resources/META-INF/services/org.apache.webbeans.spi.plugins.OpenWebBeansPlugin?rev=1858225&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-jetty9/src/main/resources/META-INF/services/org.apache.webbeans.spi.plugins.OpenWebBeansPlugin
(added)
+++
openwebbeans/trunk/webbeans-jetty9/src/main/resources/META-INF/services/org.apache.webbeans.spi.plugins.OpenWebBeansPlugin
Fri Apr 26 20:15:55 2019
@@ -0,0 +1,17 @@
+# 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.
+org.apache.webbeans.web.jetty9.JettyWebPlugin
Added:
openwebbeans/trunk/webbeans-jetty9/src/main/resources/META-INF/web-fragment.xml
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jetty9/src/main/resources/META-INF/web-fragment.xml?rev=1858225&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-jetty9/src/main/resources/META-INF/web-fragment.xml
(added)
+++
openwebbeans/trunk/webbeans-jetty9/src/main/resources/META-INF/web-fragment.xml
Fri Apr 26 20:15:55 2019
@@ -0,0 +1,36 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ 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.
+-->
+<web-fragment metadata-complete="true" version="3.0"
+ xmlns="http://java.sun.com/xml/ns/javaee"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-fragment_3_0.xsd">
+ <name>OwbTomcat7</name>
+ <ordering>
+ <before>others</before>
+ </ordering>
+ <filter>
+ <icon/>
+ <filter-name>OwbSecurityFilter</filter-name>
+
<filter-class>org.apache.webbeans.web.jetty9.JettySecurityFilter</filter-class>
+ </filter>
+ <filter-mapping>
+ <filter-name>OwbSecurityFilter</filter-name>
+ <url-pattern>*</url-pattern>
+ <dispatcher>REQUEST</dispatcher>
+ </filter-mapping>
+</web-fragment>
Propchange:
openwebbeans/trunk/webbeans-jetty9/src/main/resources/META-INF/web-fragment.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added: openwebbeans/trunk/webbeans-jetty9/src/site/site.xml
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jetty9/src/site/site.xml?rev=1858225&view=auto
==============================================================================
--- openwebbeans/trunk/webbeans-jetty9/src/site/site.xml (added)
+++ openwebbeans/trunk/webbeans-jetty9/src/site/site.xml Fri Apr 26 20:15:55
2019
@@ -0,0 +1,47 @@
+<?xml version="1.0"?>
+<!--
+ 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.
+-->
+
+<project name="OpenWebBeans">
+ <bannerLeft>
+ <name>Apache OpenWebBeans</name>
+
<src>http://openwebbeans.apache.org/owb/images/logos/openwebbeans_hor.png</src>
+ <href>http://openwebbeans.apache.org</href>
+ </bannerLeft>
+
+ <bannerRight>
+ <name>Apache Banner</name>
+ <src>http://www.apache.org/images/asf-logo.gif</src>
+ <href>http://www.apache.org</href>
+ </bannerRight>
+
+ <publishDate format="dd MMM yyyy" />
+ <version position="left"/>
+
+ <body>
+ <breadcrumbs>
+ <item name="Apache" href="http://www.apache.org"/>
+ <item name="OpenWebBeans" href="http://openwebbeans.apache.org"/>
+ <item name="OWB-Jetty-9"
href="http://openwebbeans.apache.org/${project.version}/openwebbeans-jetty9"/>
+ </breadcrumbs>
+
+ <menu ref="reports"/>
+ </body>
+</project>
+
Propchange: openwebbeans/trunk/webbeans-jetty9/src/site/site.xml
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/JettyNormalScopeProxyFactoryTest.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/JettyNormalScopeProxyFactoryTest.java?rev=1858225&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/JettyNormalScopeProxyFactoryTest.java
(added)
+++
openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/JettyNormalScopeProxyFactoryTest.java
Fri Apr 26 20:15:55 2019
@@ -0,0 +1,202 @@
+/*
+ * 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.webbeans.web.jetty9.test;
+
+import java.io.*;
+import java.lang.reflect.Method;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import javax.enterprise.context.RequestScoped;
+import javax.enterprise.context.SessionScoped;
+import javax.enterprise.inject.spi.BeanManager;
+import javax.enterprise.inject.spi.CDI;
+import javax.servlet.ServletRequestEvent;
+import javax.servlet.http.HttpSession;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.webbeans.config.WebBeansContext;
+import org.apache.webbeans.spi.ContextsService;
+import org.apache.webbeans.web.jetty9.OwbConfiguration;
+import org.eclipse.jetty.server.*;
+import org.eclipse.jetty.server.session.*;
+import org.eclipse.jetty.webapp.Configuration;
+import org.eclipse.jetty.webapp.WebAppContext;
+import org.junit.Test;
+
+import static java.util.Arrays.asList;
+import static org.junit.Assert.assertEquals;
+
+public class JettyNormalScopeProxyFactoryTest
+{
+ private static final Logger log =
Logger.getLogger(JettyNormalScopeProxyFactoryTest.class.getName());
+
+ @Test
+ public void checkDeserialisation() throws Exception
+ {
+ final File base = dir(new
File("target/JettyNormalScopeProxyFactoryTest-" + System.nanoTime()));
+ final File war = createWar(dir(new File(base, "test")),
MyWrapper.class, MySessionScoped.class);
+
+ String sessionId = null;
+ FileSessionDataStore sessionDataStore = new FileSessionDataStore();
+ sessionDataStore.setStoreDir(new File(base, "sessions"));
+ for (final String expected : asList("init", "new"))
+ {
+ final Server jetty = new Server(0);
+ Configuration.ClassList classList =
Configuration.ClassList.serverDefault(jetty);
+ classList.addBefore(
+ "org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
+ "org.eclipse.jetty.annotations.AnnotationConfiguration",
+ OwbConfiguration.class.getName()
+ );
+ WebAppContext ctx = new WebAppContext();
+ ctx.setWar(war.getAbsolutePath());
+ ctx.setContextPath("/test");
+ ctx.setLogUrlOnStart(true);
+ ctx.setConfigurationClasses(classList);
+ SessionIdManager idmanager = new DefaultSessionIdManager(jetty);
+ jetty.setSessionIdManager(idmanager);
+ final SessionHandler sessionHandler = new SessionHandler();
+ final SessionCache sessionCache = new
DefaultSessionCache(sessionHandler);
+ sessionCache.setSessionDataStore(sessionDataStore);
+ sessionCache.setEvictionPolicy(900);
+ sessionHandler.setSessionCache(sessionCache);
+ ctx.setSessionHandler(sessionHandler);
+ jetty.setHandler(ctx);
+
+ jetty.start();
+
+ try
+ {
+ Thread thread = Thread.currentThread();
+ ClassLoader old = thread.getContextClassLoader();
+ final ClassLoader webappLoader = ctx.getClassLoader();
+ thread.setContextClassLoader(webappLoader);
+ try
+ {
+ // we don't want test type but webapp one...even if named
the same
+ final Class<?> webapptype =
webappLoader.loadClass(MySessionScoped.class.getName());
+ final Method setValue = webapptype.getMethod("setValue",
String.class);
+ final Method getValue = webapptype.getMethod("getValue");
+
+ final Class<?> wrapperType =
webappLoader.loadClass(MyWrapper.class.getName());
+ final Method m = wrapperType.getMethod("getProxy");
+
+ final BeanManager bm = CDI.current().getBeanManager();
+
+ HttpChannel channel = new
HttpChannel(jetty.getConnectors()[0], new HttpConfiguration(), null, null)
+ {
+ @Override
+ public Server getServer()
+ {
+ return jetty;
+ }
+ };
+ Request request = new Request(channel, null);
+ request.setPathInfo("/test");
+ request.setContext(ctx.getServletContext());
+ request.setRequestedSessionId(sessionId);
+ request.setSessionHandler(ctx.getSessionHandler());
+ if (sessionId != null) {
+ // need to load the session into the request because
we have a fake request
+
request.setSession(ctx.getSessionHandler().getSession(sessionId));
+ }
+
+ final ContextsService contextsService =
WebBeansContext.currentInstance().getContextsService();
+ final ServletRequestEvent startParameter = new
ServletRequestEvent(ctx.getServletContext(), request);
+ contextsService.startContext(RequestScoped.class,
startParameter);
+
+ final HttpSession session = request.getSession();
+ if (request.getSession() != null)
+ {
+ contextsService.startContext(SessionScoped.class,
request.getSession());
+ }
+
+ {
+ //final Object bean =
bm.getReference(bm.resolve(bm.getBeans(webapptype)), webapptype, null);
+ final Object bean =
m.invoke(bm.getReference(bm.resolve(bm.getBeans(wrapperType)), wrapperType,
null));
+ assertEquals(expected, getValue.invoke(bean));
+ setValue.invoke(bean, "new");
+ assertEquals("new", getValue.invoke(bean));
+ }
+
+ sessionId = session.getId();
+ contextsService.endContext(RequestScoped.class,
startParameter);
+
+ // don't do to not destroy the instance
+ // contextsService.endContext(SessionScoped.class,
request.getSession());
+ }
+ catch (AssertionError e)
+ {
+ throw e;
+ }
+ catch (Exception e)
+ {
+ log.log(Level.SEVERE, "Exception during test execution",
e);
+// throw e;
+ }
+ finally
+ {
+ thread.setContextClassLoader(old);
+ }
+ }
+ finally
+ {
+ try
+ {
+ jetty.stop();
+ }
+ catch (Exception e)
+ {
+ log.log(Level.SEVERE, "This _might_ happen on Java9
currently. I hope it gets soon fixed.", e);
+ }
+
+ }
+ }
+ }
+
+ private static File createWar(final File test, final Class<?>... classes)
throws IOException
+ {
+ for (final Class<?> clazz : classes)
+ {
+ final String name = clazz.getName().replace('.', '/') + ".class";
+ final InputStream is =
Thread.currentThread().getContextClassLoader().getResourceAsStream(name);
+ if (is == null)
+ {
+ throw new IllegalArgumentException(name);
+ }
+ final File out = new File(test, "WEB-INF/classes/" + name);
+ dir(out.getParentFile());
+ final OutputStream os = new FileOutputStream(out);
+ IOUtils.copy(is, os);
+ is.close();
+ os.close();
+ }
+ final Writer w = new FileWriter(new File(test, "WEB-INF/beans.xml"));
+ w.write("<beans />");
+ w.close();
+ return test;
+ }
+
+ private static File dir(final File file)
+ {
+ file.mkdirs();
+ return file;
+ }
+}
Propchange:
openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/JettyNormalScopeProxyFactoryTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/MySessionScoped.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/MySessionScoped.java?rev=1858225&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/MySessionScoped.java
(added)
+++
openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/MySessionScoped.java
Fri Apr 26 20:15:55 2019
@@ -0,0 +1,39 @@
+/*
+ * 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.webbeans.web.jetty9.test;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+
+@SessionScoped
+public class MySessionScoped implements Serializable
+{
+ private String value = "init";
+
+ public String getValue()
+ {
+ return value;
+ }
+
+ public void setValue(final String value)
+ {
+ this.value = value;
+ }
+}
Propchange:
openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/MySessionScoped.java
------------------------------------------------------------------------------
svn:eol-style = native
Added:
openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/MyWrapper.java
URL:
http://svn.apache.org/viewvc/openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/MyWrapper.java?rev=1858225&view=auto
==============================================================================
---
openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/MyWrapper.java
(added)
+++
openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/MyWrapper.java
Fri Apr 26 20:15:55 2019
@@ -0,0 +1,35 @@
+/*
+ * 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.webbeans.web.jetty9.test;
+
+import java.io.Serializable;
+
+import javax.enterprise.context.SessionScoped;
+import javax.inject.Inject;
+
+@SessionScoped
+public class MyWrapper implements Serializable {
+ @Inject
+ private MySessionScoped proxy;
+
+ public MySessionScoped getProxy()
+ {
+ return proxy;
+ }
+}
Propchange:
openwebbeans/trunk/webbeans-jetty9/src/test/java/org/apache/webbeans/web/jetty9/test/MyWrapper.java
------------------------------------------------------------------------------
svn:eol-style = native