parent
8854c33bf7
commit
5f58cd3b79
|
|
@ -54,6 +54,7 @@ import org.springframework.core.io.DescriptiveResource;
|
|||
import org.springframework.core.io.Resource;
|
||||
import org.springframework.core.io.support.EncodedResource;
|
||||
import org.springframework.core.io.support.ResourcePatternUtils;
|
||||
import org.springframework.util.ObjectUtils;
|
||||
|
||||
/**
|
||||
* A Groovy-based reader for Spring bean definitions: like a Groovy builder,
|
||||
|
|
@ -269,10 +270,9 @@ public class GroovyBeanDefinitionReader extends AbstractBeanDefinitionReader imp
|
|||
try {
|
||||
Closure callable = null;
|
||||
Collection constructorArgs = null;
|
||||
if (args != null && args.length > 0) {
|
||||
if (!ObjectUtils.isEmpty(args)) {
|
||||
int index = args.length;
|
||||
Object lastArg = args[index-1];
|
||||
|
||||
if (lastArg instanceof Closure) {
|
||||
callable = (Closure) lastArg;
|
||||
index--;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -45,6 +45,7 @@ public abstract class FreeMarkerTemplateUtils {
|
|||
*/
|
||||
public static String processTemplateIntoString(Template template, Object model)
|
||||
throws IOException, TemplateException {
|
||||
|
||||
StringWriter result = new StringWriter();
|
||||
template.process(model, result);
|
||||
return result.toString();
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -63,6 +63,7 @@ public class SpringTemplateLoader implements TemplateLoader {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public Object findTemplateSource(String name) throws IOException {
|
||||
if (logger.isDebugEnabled()) {
|
||||
|
|
@ -86,7 +87,6 @@ public class SpringTemplateLoader implements TemplateLoader {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public long getLastModified(Object templateSource) {
|
||||
Resource resource = (Resource) templateSource;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,14 +16,15 @@
|
|||
|
||||
package org.springframework.context.annotation;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.factory.FactoryBean;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.beans.factory.annotation.Value;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Test case cornering the bug initially raised with SPR-8762, in which a
|
||||
* NullPointerException would be raised if a FactoryBean-returning @Bean method also
|
||||
|
|
@ -33,47 +34,55 @@ import org.springframework.context.ApplicationContext;
|
|||
* @since 3.1
|
||||
*/
|
||||
public class ConfigurationWithFactoryBeanAndParametersTests {
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
ApplicationContext ctx = new AnnotationConfigApplicationContext(Config.class, Bar.class);
|
||||
assertNotNull(ctx.getBean(Bar.class).foo);
|
||||
}
|
||||
}
|
||||
|
||||
@Configuration
|
||||
class Config {
|
||||
@Bean
|
||||
public FactoryBean<Foo> fb(@Value("42") String answer) {
|
||||
return new FooFactoryBean();
|
||||
}
|
||||
}
|
||||
|
||||
class Foo {
|
||||
}
|
||||
@Configuration
|
||||
static class Config {
|
||||
|
||||
class Bar {
|
||||
Foo foo;
|
||||
|
||||
@Autowired
|
||||
public Bar(Foo foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
}
|
||||
|
||||
class FooFactoryBean implements FactoryBean<Foo> {
|
||||
|
||||
@Override
|
||||
public Foo getObject() {
|
||||
return new Foo();
|
||||
@Bean
|
||||
public FactoryBean<Foo> fb(@Value("42") String answer) {
|
||||
return new FooFactoryBean();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Foo> getObjectType() {
|
||||
return Foo.class;
|
||||
|
||||
static class Foo {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
|
||||
static class Bar {
|
||||
|
||||
Foo foo;
|
||||
|
||||
@Autowired
|
||||
public Bar(Foo foo) {
|
||||
this.foo = foo;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static class FooFactoryBean implements FactoryBean<Foo> {
|
||||
|
||||
@Override
|
||||
public Foo getObject() {
|
||||
return new Foo();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Class<Foo> getObjectType() {
|
||||
return Foo.class;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isSingleton() {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2013 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,16 +16,19 @@
|
|||
|
||||
package org.springframework.context.groovy;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.GenericGroovyApplicationContext;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* @author Jeff Brown
|
||||
* @author Juergen Hoeller
|
||||
*/
|
||||
public class GroovyApplicationContextTests extends TestCase {
|
||||
public class GroovyApplicationContextTests {
|
||||
|
||||
@Test
|
||||
public void testLoadingConfigFile() {
|
||||
GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext(
|
||||
"org/springframework/context/groovy/applicationContext.groovy");
|
||||
|
|
@ -35,6 +38,7 @@ public class GroovyApplicationContextTests extends TestCase {
|
|||
assertEquals("Grails", framework);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadingMultipleConfigFiles() {
|
||||
GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext(
|
||||
"org/springframework/context/groovy/applicationContext2.groovy",
|
||||
|
|
@ -49,6 +53,7 @@ public class GroovyApplicationContextTests extends TestCase {
|
|||
assertEquals("SpringSource", company);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadingMultipleConfigFilesWithRelativeClass() {
|
||||
GenericGroovyApplicationContext ctx = new GenericGroovyApplicationContext();
|
||||
ctx.load(GroovyApplicationContextTests.class, "applicationContext2.groovy", "applicationContext.groovy");
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@
|
|||
* 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
|
||||
* 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,
|
||||
|
|
@ -16,32 +16,33 @@
|
|||
|
||||
package org.springframework.messaging.simp.user;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.simp.SimpMessageHeaderAccessor;
|
||||
import org.springframework.messaging.simp.SimpMessageType;
|
||||
import org.springframework.util.Assert;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import java.security.Principal;
|
||||
import java.util.Collections;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A default implementation of {@link UserDestinationResolver} that relies
|
||||
* on the {@link org.springframework.messaging.simp.user.UserSessionRegistry}
|
||||
* provided to the constructor to find the sessionIds associated with a user
|
||||
* and then uses the sessionId to make the target destination unique.
|
||||
* <p>
|
||||
* When a user attempts to subscribe to "/user/queue/position-updates", the
|
||||
*
|
||||
* <p>When a user attempts to subscribe to "/user/queue/position-updates", the
|
||||
* "/user" prefix is removed and a unique suffix added, resulting in something
|
||||
* like "/queue/position-updates-useri9oqdfzo" where the suffix is based on the
|
||||
* user's session and ensures it does not collide with any other users attempting
|
||||
* to subscribe to "/user/queue/position-updates".
|
||||
* <p>
|
||||
* When a message is sent to a user with a destination such as
|
||||
*
|
||||
* <p>When a message is sent to a user with a destination such as
|
||||
* "/user/{username}/queue/position-updates", the "/user/{username}" prefix is
|
||||
* removed and the suffix added, resulting in something like
|
||||
* "/queue/position-updates-useri9oqdfzo".
|
||||
|
|
@ -69,6 +70,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver {
|
|||
this.userSessionRegistry = userSessionRegistry;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* The prefix used to identify user destinations. Any destinations that do not
|
||||
* start with the given prefix are not be resolved.
|
||||
|
|
@ -99,35 +101,30 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver {
|
|||
|
||||
@Override
|
||||
public UserDestinationResult resolveDestination(Message<?> message) {
|
||||
|
||||
SimpMessageHeaderAccessor headers = SimpMessageHeaderAccessor.wrap(message);
|
||||
DestinationInfo info = parseUserDestination(headers);
|
||||
if (info == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Set<String> targetDestinations = new HashSet<String>();
|
||||
for (String sessionId : info.getSessionIds()) {
|
||||
targetDestinations.add(getTargetDestination(
|
||||
headers.getDestination(), info.getDestinationWithoutPrefix(), sessionId, info.getUser()));
|
||||
}
|
||||
|
||||
return new UserDestinationResult(headers.getDestination(),
|
||||
targetDestinations, info.getSubscribeDestination(), info.getUser());
|
||||
}
|
||||
|
||||
private DestinationInfo parseUserDestination(SimpMessageHeaderAccessor headers) {
|
||||
|
||||
String destination = headers.getDestination();
|
||||
Principal principal = headers.getUser();
|
||||
SimpMessageType messageType = headers.getMessageType();
|
||||
|
||||
String destinationWithoutPrefix;
|
||||
String subscribeDestination;
|
||||
String user;
|
||||
Set<String> sessionIds;
|
||||
|
||||
Principal principal = headers.getUser();
|
||||
SimpMessageType messageType = headers.getMessageType();
|
||||
|
||||
if (SimpMessageType.SUBSCRIBE.equals(messageType) || SimpMessageType.UNSUBSCRIBE.equals(messageType)) {
|
||||
if (!checkDestination(destination, this.destinationPrefix)) {
|
||||
return null;
|
||||
|
|
@ -185,7 +182,6 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver {
|
|||
/**
|
||||
* Return the target destination to use. Provided as input are the original source
|
||||
* destination, as well as the same destination with the target prefix removed.
|
||||
*
|
||||
* @param sourceDestination the source destination from the input message
|
||||
* @param sourceDestinationWithoutPrefix the source destination with the target prefix removed
|
||||
* @param sessionId an active user session id
|
||||
|
|
@ -209,8 +205,7 @@ public class DefaultUserDestinationResolver implements UserDestinationResolver {
|
|||
|
||||
private final Set<String> sessionIds;
|
||||
|
||||
|
||||
private DestinationInfo(String destinationWithoutPrefix, String subscribeDestination, String user,
|
||||
public DestinationInfo(String destinationWithoutPrefix, String subscribeDestination, String user,
|
||||
Set<String> sessionIds) {
|
||||
|
||||
this.user = user;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
/*
|
||||
* Copyright 2002-2012 the original author or authors.
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -36,11 +36,13 @@ public abstract class AbstractHandlerMethodAdapter extends WebContentGenerator i
|
|||
|
||||
private int order = Ordered.LOWEST_PRECEDENCE;
|
||||
|
||||
|
||||
public AbstractHandlerMethodAdapter() {
|
||||
// no restriction of HTTP methods by default
|
||||
super(false);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Specify the order value for this HandlerAdapter bean.
|
||||
* <p>Default value is {@code Integer.MAX_VALUE}, meaning that it's non-ordered.
|
||||
|
|
@ -55,51 +57,49 @@ public abstract class AbstractHandlerMethodAdapter extends WebContentGenerator i
|
|||
return this.order;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* {@inheritDoc} <p>This implementation expects the handler to be an {@link HandlerMethod}.
|
||||
*
|
||||
* This implementation expects the handler to be an {@link HandlerMethod}.
|
||||
* @param handler the handler instance to check
|
||||
* @return whether or not this adapter can adapt the given handler
|
||||
*/
|
||||
@Override
|
||||
public final boolean supports(Object handler) {
|
||||
return handler instanceof HandlerMethod && supportsInternal((HandlerMethod) handler);
|
||||
return (handler instanceof HandlerMethod && supportsInternal((HandlerMethod) handler));
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a handler method, return whether or not this adapter can support it.
|
||||
*
|
||||
* @param handlerMethod the handler method to check
|
||||
* @return whether or not this adapter can adapt the given method
|
||||
*/
|
||||
protected abstract boolean supportsInternal(HandlerMethod handlerMethod);
|
||||
|
||||
/**
|
||||
* {@inheritDoc} <p>This implementation expects the handler to be an {@link HandlerMethod}.
|
||||
* This implementation expects the handler to be an {@link HandlerMethod}.
|
||||
*/
|
||||
@Override
|
||||
public final ModelAndView handle(HttpServletRequest request, HttpServletResponse response, Object handler)
|
||||
throws Exception {
|
||||
|
||||
return handleInternal(request, response, (HandlerMethod) handler);
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the given handler method to handle the request.
|
||||
*
|
||||
* @param request current HTTP request
|
||||
* @param response current HTTP response
|
||||
* @param handlerMethod handler method to use. This object must have previously been passed to the
|
||||
* {@link #supportsInternal(HandlerMethod)} this interface, which must have returned {@code true}.
|
||||
* @return ModelAndView object with the name of the view and the required model data, or {@code null} if
|
||||
* the request has been handled directly
|
||||
* @return ModelAndView object with the name of the view and the required model data,
|
||||
* or {@code null} if the request has been handled directly
|
||||
* @throws Exception in case of errors
|
||||
*/
|
||||
protected abstract ModelAndView handleInternal(HttpServletRequest request,
|
||||
HttpServletResponse response,
|
||||
HandlerMethod handlerMethod) throws Exception;
|
||||
HttpServletResponse response, HandlerMethod handlerMethod) throws Exception;
|
||||
|
||||
/**
|
||||
* {@inheritDoc} <p>This implementation expects the handler to be an {@link HandlerMethod}.
|
||||
* This implementation expects the handler to be an {@link HandlerMethod}.
|
||||
*/
|
||||
@Override
|
||||
public final long getLastModified(HttpServletRequest request, Object handler) {
|
||||
|
|
@ -108,10 +108,10 @@ public abstract class AbstractHandlerMethodAdapter extends WebContentGenerator i
|
|||
|
||||
/**
|
||||
* Same contract as for {@link javax.servlet.http.HttpServlet#getLastModified(HttpServletRequest)}.
|
||||
*
|
||||
* @param request current HTTP request
|
||||
* @param handlerMethod handler method to use
|
||||
* @return the lastModified value for the given handler
|
||||
*/
|
||||
protected abstract long getLastModifiedInternal(HttpServletRequest request, HandlerMethod handlerMethod);
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue