Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Index: src/main/resources/jersey-spring-applicationContext.xml
- ===================================================================
- --- src/main/resources/jersey-spring-applicationContext.xml (revision 312)
- +++ src/main/resources/jersey-spring-applicationContext.xml (revision 313)
- @@ -1,61 +0,0 @@
- -<?xml version="1.0" encoding="UTF-8"?>
- -<!--
- -
- - DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- -
- - Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
- -
- - The contents of this file are subject to the terms of either the GNU
- - General Public License Version 2 only ("GPL") or the Common Development
- - and Distribution License("CDDL") (collectively, the "License"). You
- - may not use this file except in compliance with the License. You can
- - obtain a copy of the License at
- - http://glassfish.java.net/public/CDDL+GPL_1_1.html
- - or packager/legal/LICENSE.txt. See the License for the specific
- - language governing permissions and limitations under the License.
- -
- - When distributing the software, include this License Header Notice in each
- - file and include the License file at packager/legal/LICENSE.txt.
- -
- - GPL Classpath Exception:
- - Oracle designates this particular file as subject to the "Classpath"
- - exception as provided by Oracle in the GPL Version 2 section of the License
- - file that accompanied this code.
- -
- - Modifications:
- - If applicable, add the following below the License Header, with the fields
- - enclosed by brackets [] replaced by your own identifying information:
- - "Portions Copyright [year] [name of copyright owner]"
- -
- - Contributor(s):
- - If you wish your version of this file to be governed by only the CDDL or
- - only the GPL Version 2, indicate your decision by adding "[Contributor]
- - elects to include this software in this distribution under the [CDDL or GPL
- - Version 2] license." If you don't indicate a single choice of license, a
- - recipient has the option to distribute your version of this file under
- - either the CDDL, the GPL Version 2 or to extend the choice of license to
- - its licensees as provided above. However, if you add GPL Version 2 code
- - and therefore, elected the GPL Version 2 license, then the option applies
- - only if the new code is made subject to such option by the copyright
- - holder.
- -
- --->
- -<beans xmlns="http://www.springframework.org/schema/beans"
- - xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- - xmlns:context="http://www.springframework.org/schema/context"
- - xsi:schemaLocation="http://www.springframework.org/schema/beans
- - http://www.springframework.org/schema/beans/spring-beans.xsd
- - http://www.springframework.org/schema/context
- - http://www.springframework.org/schema/context/spring-context.xsd"
- - >
- -
- - <bean class="org.springframework.beans.factory.config.CustomScopeConfigurer">
- - <property name="scopes">
- - <map>
- - <entry key="request">
- - <bean class="org.springframework.web.context.request.RequestScope"/>
- - </entry>
- - </map>
- - </property>
- - </bean>
- -</beans>
- \ No newline at end of file
- Index: src/main/java/org/glassfish/jersey/server/spring/SpringWebApplicationInitializer.java
- ===================================================================
- --- src/main/java/org/glassfish/jersey/server/spring/SpringWebApplicationInitializer.java (revision 312)
- +++ src/main/java/org/glassfish/jersey/server/spring/SpringWebApplicationInitializer.java (revision 313)
- @@ -1,72 +0,0 @@
- -/*
- - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
- - *
- - * Copyright (c) 2013 Oracle and/or its affiliates. All rights reserved.
- - *
- - * The contents of this file are subject to the terms of either the GNU
- - * General Public License Version 2 only ("GPL") or the Common Development
- - * and Distribution License("CDDL") (collectively, the "License"). You
- - * may not use this file except in compliance with the License. You can
- - * obtain a copy of the License at
- - * http://glassfish.java.net/public/CDDL+GPL_1_1.html
- - * or packager/legal/LICENSE.txt. See the License for the specific
- - * language governing permissions and limitations under the License.
- - *
- - * When distributing the software, include this License Header Notice in each
- - * file and include the License file at packager/legal/LICENSE.txt.
- - *
- - * GPL Classpath Exception:
- - * Oracle designates this particular file as subject to the "Classpath"
- - * exception as provided by Oracle in the GPL Version 2 section of the License
- - * file that accompanied this code.
- - *
- - * Modifications:
- - * If applicable, add the following below the License Header, with the fields
- - * enclosed by brackets [] replaced by your own identifying information:
- - * "Portions Copyright [year] [name of copyright owner]"
- - *
- - * Contributor(s):
- - * If you wish your version of this file to be governed by only the CDDL or
- - * only the GPL Version 2, indicate your decision by adding "[Contributor]
- - * elects to include this software in this distribution under the [CDDL or GPL
- - * Version 2] license." If you don't indicate a single choice of license, a
- - * recipient has the option to distribute your version of this file under
- - * either the CDDL, the GPL Version 2 or to extend the choice of license to
- - * its licensees as provided above. However, if you add GPL Version 2 code
- - * and therefore, elected the GPL Version 2 license, then the option applies
- - * only if the new code is made subject to such option by the copyright
- - * holder.
- - */
- -package org.glassfish.jersey.server.spring;
- -
- -import java.util.logging.Logger;
- -
- -import javax.servlet.ServletContext;
- -import javax.servlet.ServletException;
- -
- -import org.springframework.web.WebApplicationInitializer;
- -
- -/**
- - * Spring WebApplicationInitializer implementation initializes Spring context by
- - * adding a Spring ContextLoaderListener to the ServletContext.
- - *
- - * @author Marko Asplund (marko.asplund at yahoo.com)
- - */
- -public class SpringWebApplicationInitializer implements WebApplicationInitializer {
- -
- - private static final Logger LOGGER = Logger.getLogger(SpringWebApplicationInitializer.class.getName());
- -
- - private static final String PAR_NAME_CTX_CONFIG_LOCATION = "contextConfigLocation";
- -
- - @Override
- - public void onStartup(ServletContext sc) throws ServletException {
- - if(sc.getInitParameter(PAR_NAME_CTX_CONFIG_LOCATION) == null) {
- - LOGGER.config(LocalizationMessages.REGISTERING_CTX_LOADER_LISTENER());
- - sc.setInitParameter(PAR_NAME_CTX_CONFIG_LOCATION, "classpath:applicationContext.xml");
- - sc.addListener("org.springframework.web.context.ContextLoaderListener");
- - sc.addListener("org.springframework.web.context.request.RequestContextListener");
- - } else {
- - LOGGER.config(LocalizationMessages.SKIPPING_CTX_LODAER_LISTENER_REGISTRATION());
- - }
- - }
- -}
- Index: src/main/java/org/glassfish/jersey/server/spring/SpringComponentProvider.java
- ===================================================================
- --- src/main/java/org/glassfish/jersey/server/spring/SpringComponentProvider.java (revision 312)
- +++ src/main/java/org/glassfish/jersey/server/spring/SpringComponentProvider.java (revision 313)
- @@ -43,6 +43,7 @@
- import java.util.logging.Level;
- import java.util.logging.Logger;
- +import javax.servlet.ServletConfig;
- import javax.servlet.ServletContext;
- import org.glassfish.hk2.api.DynamicConfiguration;
- @@ -51,16 +52,18 @@
- import org.glassfish.hk2.utilities.ServiceLocatorUtilities;
- import org.glassfish.hk2.utilities.binding.ServiceBindingBuilder;
- import org.glassfish.jersey.internal.inject.Injections;
- -import org.glassfish.jersey.server.ApplicationHandler;
- import org.glassfish.jersey.server.spi.ComponentProvider;
- -
- import org.jvnet.hk2.spring.bridge.api.SpringBridge;
- import org.jvnet.hk2.spring.bridge.api.SpringIntoHK2Bridge;
- -
- +import org.springframework.beans.BeanUtils;
- import org.springframework.context.ApplicationContext;
- -import org.springframework.context.support.ClassPathXmlApplicationContext;
- +import org.springframework.core.env.ConfigurableEnvironment;
- import org.springframework.stereotype.Component;
- +import org.springframework.web.context.ConfigurableWebApplicationContext;
- +import org.springframework.web.context.ConfigurableWebEnvironment;
- +import org.springframework.web.context.WebApplicationContext;
- import org.springframework.web.context.support.WebApplicationContextUtils;
- +import org.springframework.web.context.support.XmlWebApplicationContext;
- /**
- * Custom ComponentProvider class.
- @@ -72,12 +75,9 @@
- public class SpringComponentProvider implements ComponentProvider {
- private static final Logger LOGGER = Logger.getLogger(SpringComponentProvider.class.getName());
- - private static final String DEFAULT_CONTEXT_CONFIG_LOCATION = "applicationContext.xml";
- - private static final String PARAM_CONTEXT_CONFIG_LOCATION = "contextConfigLocation";
- - private static final String PARAM_SPRING_CONTEXT = "contextConfig";
- private volatile ServiceLocator locator;
- - private volatile ApplicationContext ctx;
- + private volatile WebApplicationContext ctx;
- @Override
- public void initialize(ServiceLocator locator) {
- @@ -88,18 +88,36 @@
- }
- ServletContext sc = locator.getService(ServletContext.class);
- + ServletConfig config = locator.getService(ServletConfig.class);
- - if(sc != null) {
- - // servlet container
- - ctx = WebApplicationContextUtils.getWebApplicationContext(sc);
- - } else {
- - // non-servlet container
- - ctx = createSpringContext();
- - }
- - if(ctx == null) {
- - LOGGER.severe(LocalizationMessages.CTX_LOOKUP_FAILED());
- - return;
- - }
- + WebApplicationContext rootContext = WebApplicationContextUtils
- + .getRequiredWebApplicationContext(sc);
- +
- + WebApplicationContext wac = null;
- +
- + ConfigurableWebApplicationContext cwac = (ConfigurableWebApplicationContext) BeanUtils
- + .instantiateClass(XmlWebApplicationContext.class);
- +
- + cwac.setParent(rootContext);
- + cwac.setConfigLocation("/WEB-INF/spring/jaxrs/*.xml");
- +
- + cwac.setId("jaxrs-context");
- + cwac.setServletContext(sc);
- + cwac.setServletConfig(config);
- + cwac.setNamespace(config.getServletName());
- +
- + ConfigurableEnvironment env = cwac.getEnvironment();
- +
- + if (env instanceof ConfigurableWebEnvironment) {
- + ((ConfigurableWebEnvironment) env).initPropertySources(
- + sc, config);
- + }
- +
- + cwac.refresh();
- +
- + wac = cwac;
- + this.ctx = wac;
- +
- LOGGER.config(LocalizationMessages.CTX_LOOKUP_SUCESSFUL());
- // initialize HK2 spring-bridge
- @@ -146,24 +164,6 @@
- public void done() {
- }
- - private ApplicationContext createSpringContext() {
- - ApplicationHandler applicationHandler = locator.getService(ApplicationHandler.class);
- - ApplicationContext springContext = (ApplicationContext) applicationHandler.getConfiguration().getProperty(PARAM_SPRING_CONTEXT);
- - if (springContext == null) {
- - String contextConfigLocation = (String) applicationHandler.getConfiguration().getProperty(PARAM_CONTEXT_CONFIG_LOCATION);
- - springContext = createXmlSpringConfiguration(contextConfigLocation);
- - }
- - return springContext;
- - }
- -
- - private ApplicationContext createXmlSpringConfiguration(String contextConfigLocation) {
- - if (contextConfigLocation == null) {
- - contextConfigLocation = DEFAULT_CONTEXT_CONFIG_LOCATION;
- - }
- - return ctx = new ClassPathXmlApplicationContext(contextConfigLocation, "jersey-spring-applicationContext.xml");
- - }
- -
- -
- private static class SpringManagedBeanFactory implements Factory {
- private final ApplicationContext ctx;
- private final ServiceLocator locator;
- Index: src/main/java/org/glassfish/jersey/server/spring/AutowiredInjectResolver.java
- ===================================================================
- --- src/main/java/org/glassfish/jersey/server/spring/AutowiredInjectResolver.java (revision 312)
- +++ src/main/java/org/glassfish/jersey/server/spring/AutowiredInjectResolver.java (revision 313)
- @@ -40,12 +40,10 @@
- package org.glassfish.jersey.server.spring;
- import java.lang.reflect.AnnotatedElement;
- -import java.lang.reflect.ParameterizedType;
- -import java.lang.reflect.Type;
- -import java.util.ArrayList;
- -import java.util.Collections;
- +import java.lang.reflect.Constructor;
- +import java.lang.reflect.Field;
- import java.util.HashSet;
- -import java.util.Map;
- +import java.util.Set;
- import java.util.logging.Logger;
- import javax.inject.Singleton;
- @@ -53,15 +51,18 @@
- import org.glassfish.hk2.api.Injectee;
- import org.glassfish.hk2.api.InjectionResolver;
- import org.glassfish.hk2.api.ServiceHandle;
- -
- +import org.springframework.beans.factory.NoSuchBeanDefinitionException;
- import org.springframework.beans.factory.annotation.Autowired;
- import org.springframework.beans.factory.annotation.Qualifier;
- +import org.springframework.beans.factory.config.DependencyDescriptor;
- import org.springframework.context.ApplicationContext;
- +import org.springframework.core.MethodParameter;
- /**
- * HK2 injection resolver for Spring framework {@link Autowired} annotation injection.
- *
- * @author Marko Asplund (marko.asplund at yahoo.com)
- + * @author Vetle Leinonen-Roeim (vetle at roeim.net)
- */
- @Singleton
- public class AutowiredInjectResolver implements InjectionResolver<Autowired> {
- @@ -70,6 +71,7 @@
- /**
- * Create a new instance.
- + *
- * @param ctx Spring application context.
- */
- public AutowiredInjectResolver(ApplicationContext ctx) {
- @@ -86,42 +88,31 @@
- beanName = an.value();
- }
- }
- - return getBeanFromSpringContext(beanName, injectee.getRequiredType());
- + return getBeanFromSpringContext(beanName, injectee);
- }
- - private Object getBeanFromSpringContext(String beanName, Type beanType) {
- - Class<?> bt = getClassFromType(beanType);
- - if (beanName != null) {
- - return ctx.getBean(beanName, bt);
- + private Object getBeanFromSpringContext(String beanName, Injectee injectee) {
- + try {
- + DependencyDescriptor dependencyDescriptor = createSpringDependencyDescriptor(injectee);
- + Set<String> autowiredBeanNames = new HashSet<>(1);
- + autowiredBeanNames.add(beanName);
- + return ctx.getAutowireCapableBeanFactory().resolveDependency(dependencyDescriptor, null,
- + autowiredBeanNames, null);
- + } catch (NoSuchBeanDefinitionException e) {
- + LOGGER.warning(e.getMessage());
- + throw e;
- }
- - Map<String, ?> beans = ctx.getBeansOfType(bt);
- - if (beans == null || beans.size() < 1) {
- - LOGGER.warning(LocalizationMessages.NO_BEANS_FOUND_FOR_TYPE(beanType));
- - return null;
- - }
- -
- - if (beanType instanceof ParameterizedType) {
- - final Class<?> rawType = (Class<?>) ((ParameterizedType) beanType).getRawType();
- - if (rawType.isAssignableFrom(ArrayList.class)) {
- - return Collections.unmodifiableList(new ArrayList(beans.values()));
- - } else if (rawType.isAssignableFrom(HashSet.class)) {
- - return new HashSet<>(beans.values());
- - }
- - }
- -
- - return beans.values().iterator().next();
- }
- - private Class<?> getClassFromType(Type type) {
- - if (type instanceof Class) {
- - return (Class<?>) type;
- + private DependencyDescriptor createSpringDependencyDescriptor(final Injectee injectee) {
- + AnnotatedElement annotatedElement = injectee.getParent();
- + if (annotatedElement.getClass().isAssignableFrom(Field.class)) {
- + return new DependencyDescriptor((Field) annotatedElement,
- + !injectee.isOptional());
- + } else {
- + return new DependencyDescriptor(
- + new MethodParameter((Constructor) annotatedElement, injectee.getPosition()), !injectee.isOptional());
- }
- - if (type instanceof ParameterizedType) {
- - ParameterizedType pt = (ParameterizedType) type;
- -
- - return (Class<?>) pt.getActualTypeArguments()[0];
- - }
- - return null;
- }
- @Override
- Index: pom.xml
- ===================================================================
- --- pom.xml (revision 312)
- +++ pom.xml (revision 313)
- @@ -49,46 +49,45 @@
- <version>2.7</version>
- </parent>
- - <artifactId>jersey-spring3</artifactId>
- - <name>jersey-spring3</name>
- + <artifactId>jersey-spring4</artifactId>
- + <name>jersey-spring4</name>
- + <version>2.7-dynamowerk</version>
- <packaging>jar</packaging>
- <description>
- - Jersey extension module providing support for Spring 3 integration.
- + Jersey extension module providing support for Spring 4 integration.
- </description>
- <dependencies>
- <dependency>
- <groupId>org.glassfish.jersey.core</groupId>
- <artifactId>jersey-server</artifactId>
- - <version>${project.version}</version>
- + <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.glassfish.jersey.containers</groupId>
- <artifactId>jersey-container-servlet-core</artifactId>
- - <version>${project.version}</version>
- + <version>${project.parent.version}</version>
- </dependency>
- <dependency>
- <groupId>org.glassfish.jersey.test-framework.providers</groupId>
- <artifactId>jersey-test-framework-provider-grizzly2</artifactId>
- - <version>${project.version}</version>
- + <version>${project.parent.version}</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>commons-logging</groupId>
- <artifactId>commons-logging</artifactId>
- - <version>1.1.1</version>
- <scope>test</scope>
- </dependency>
- <dependency>
- <groupId>org.glassfish.hk2</groupId>
- <artifactId>hk2</artifactId>
- - <version>${hk2.version}</version>
- </dependency>
- <dependency>
- @@ -110,13 +109,13 @@
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-beans</artifactId>
- - <version>${spring3.version}</version>
- + <version>${spring4.version}</version>
- </dependency>
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-core</artifactId>
- - <version>${spring3.version}</version>
- + <version>${spring4.version}</version>
- <exclusions>
- <exclusion>
- <groupId>commons-logging</groupId>
- @@ -128,7 +127,7 @@
- <dependency>
- <groupId>org.springframework</groupId>
- <artifactId>spring-web</artifactId>
- - <version>${spring3.version}</version>
- + <version>${spring4.version}</version>
- <scope>compile</scope>
- </dependency>
- @@ -142,14 +141,14 @@
- <dependency>
- <groupId>org.glassfish.jersey.test-framework</groupId>
- <artifactId>jersey-test-framework-core</artifactId>
- - <version>${project.version}</version>
- + <version>${project.parent.version}</version>
- <scope>test</scope>
- </dependency>
- </dependencies>
- <properties>
- - <spring3.version>3.2.3.RELEASE</spring3.version>
- + <spring4.version>4.0.3.RELEASE</spring4.version>
- </properties>
- <build>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement