Browse Source

Polishing

pull/1723/head
Juergen Hoeller 8 years ago
parent
commit
1f12214b45
  1. 5
      spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java
  2. 92
      spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java
  3. 56
      spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java
  4. 10
      spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java
  5. 33
      spring-web/src/main/java/org/springframework/http/MediaType.java
  6. 3
      spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java
  7. 103
      spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServerEndpointRegistration.java

5
spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java

@ -151,11 +151,6 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
this.beanFactory.setParentBeanFactory(getInternalParentBeanFactory()); this.beanFactory.setParentBeanFactory(getInternalParentBeanFactory());
} }
@Override
public void setId(String id) {
super.setId(id);
}
/** /**
* Set whether it should be allowed to override bean definitions by registering * Set whether it should be allowed to override bean definitions by registering
* a different definition with the same name, automatically replacing the former. * a different definition with the same name, automatically replacing the former.

92
spring-expression/src/main/java/org/springframework/expression/spel/ast/Indexer.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -103,21 +103,20 @@ public class Indexer extends SpelNodeImpl {
@Override @Override
protected ValueRef getValueRef(ExpressionState state) throws EvaluationException { protected ValueRef getValueRef(ExpressionState state) throws EvaluationException {
TypedValue context = state.getActiveContextObject(); TypedValue context = state.getActiveContextObject();
Object targetObject = context.getValue(); Object target = context.getValue();
TypeDescriptor targetDescriptor = context.getTypeDescriptor(); TypeDescriptor targetDescriptor = context.getTypeDescriptor();
TypedValue indexValue = null; TypedValue indexValue;
Object index = null; Object index;
// This first part of the if clause prevents a 'double dereference' of // This first part of the if clause prevents a 'double dereference' of the property (SPR-5847)
// the property (SPR-5847) if (target instanceof Map && (this.children[0] instanceof PropertyOrFieldReference)) {
if (targetObject instanceof Map && (this.children[0] instanceof PropertyOrFieldReference)) {
PropertyOrFieldReference reference = (PropertyOrFieldReference) this.children[0]; PropertyOrFieldReference reference = (PropertyOrFieldReference) this.children[0];
index = reference.getName(); index = reference.getName();
indexValue = new TypedValue(index); indexValue = new TypedValue(index);
} }
else { else {
// In case the map key is unqualified, we want it evaluated against // In case the map key is unqualified, we want it evaluated against the root object
// the root object so temporarily push that on whilst evaluating the key // so temporarily push that on whilst evaluating the key
try { try {
state.pushActiveContextObject(state.getRootContextObject()); state.pushActiveContextObject(state.getRootContextObject());
indexValue = this.children[0].getValueInternal(state); indexValue = this.children[0].getValueInternal(state);
@ -128,52 +127,53 @@ public class Indexer extends SpelNodeImpl {
} }
} }
// Raise a proper exception in case of a null target
if (target == null) {
throw new SpelEvaluationException(getStartPosition(), SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE);
}
// Indexing into a Map // Indexing into a Map
if (targetObject instanceof Map) { if (target instanceof Map) {
Object key = index; Object key = index;
if (targetDescriptor.getMapKeyTypeDescriptor() != null) { if (targetDescriptor.getMapKeyTypeDescriptor() != null) {
key = state.convertValue(key, targetDescriptor.getMapKeyTypeDescriptor()); key = state.convertValue(key, targetDescriptor.getMapKeyTypeDescriptor());
} }
this.indexedType = IndexedType.MAP; this.indexedType = IndexedType.MAP;
return new MapIndexingValueRef(state.getTypeConverter(), (Map<?, ?>) targetObject, key, targetDescriptor); return new MapIndexingValueRef(state.getTypeConverter(), (Map<?, ?>) target, key, targetDescriptor);
}
if (targetObject == null) {
throw new SpelEvaluationException(getStartPosition(), SpelMessage.CANNOT_INDEX_INTO_NULL_VALUE);
} }
// if the object is something that looks indexable by an integer, // If the object is something that looks indexable by an integer,
// attempt to treat the index value as a number // attempt to treat the index value as a number
if (targetObject.getClass().isArray() || targetObject instanceof Collection || targetObject instanceof String) { if (target.getClass().isArray() || target instanceof Collection || target instanceof String) {
int idx = (Integer) state.convertValue(index, TypeDescriptor.valueOf(Integer.class)); int idx = (Integer) state.convertValue(index, TypeDescriptor.valueOf(Integer.class));
if (targetObject.getClass().isArray()) { if (target.getClass().isArray()) {
this.indexedType = IndexedType.ARRAY; this.indexedType = IndexedType.ARRAY;
return new ArrayIndexingValueRef(state.getTypeConverter(), targetObject, idx, targetDescriptor); return new ArrayIndexingValueRef(state.getTypeConverter(), target, idx, targetDescriptor);
} }
else if (targetObject instanceof Collection) { else if (target instanceof Collection) {
if (targetObject instanceof List) { if (target instanceof List) {
this.indexedType = IndexedType.LIST; this.indexedType = IndexedType.LIST;
} }
return new CollectionIndexingValueRef((Collection<?>) targetObject, idx, targetDescriptor, return new CollectionIndexingValueRef((Collection<?>) target, idx, targetDescriptor,
state.getTypeConverter(), state.getConfiguration().isAutoGrowCollections(), state.getTypeConverter(), state.getConfiguration().isAutoGrowCollections(),
state.getConfiguration().getMaximumAutoGrowSize()); state.getConfiguration().getMaximumAutoGrowSize());
} }
else { else {
this.indexedType = IndexedType.STRING; this.indexedType = IndexedType.STRING;
return new StringIndexingLValue((String) targetObject, idx, targetDescriptor); return new StringIndexingLValue((String) target, idx, targetDescriptor);
} }
} }
// Try and treat the index value as a property of the context object // Try and treat the index value as a property of the context object
// TODO could call the conversion service to convert the value to a String // TODO: could call the conversion service to convert the value to a String
if (String.class == indexValue.getTypeDescriptor().getType()) { if (String.class == indexValue.getTypeDescriptor().getType()) {
this.indexedType = IndexedType.OBJECT; this.indexedType = IndexedType.OBJECT;
return new PropertyIndexingValueRef(targetObject, (String) indexValue.getValue(), return new PropertyIndexingValueRef(
state.getEvaluationContext(), targetDescriptor); target, (String) index, state.getEvaluationContext(), targetDescriptor);
} }
throw new SpelEvaluationException(getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, throw new SpelEvaluationException(
targetDescriptor.toString()); getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, targetDescriptor);
} }
@Override @Override
@ -188,12 +188,10 @@ public class Indexer extends SpelNodeImpl {
return (this.children[0] instanceof PropertyOrFieldReference || this.children[0].isCompilable()); return (this.children[0] instanceof PropertyOrFieldReference || this.children[0].isCompilable());
} }
else if (this.indexedType == IndexedType.OBJECT) { else if (this.indexedType == IndexedType.OBJECT) {
// If the string name is changing the accessor is clearly going to change (so compilation is not possible) // If the string name is changing the accessor is clearly going to change (so no compilation possible)
if (this.cachedReadAccessor != null && return (this.cachedReadAccessor != null &&
(this.cachedReadAccessor instanceof ReflectivePropertyAccessor.OptimalPropertyAccessor) && this.cachedReadAccessor instanceof ReflectivePropertyAccessor.OptimalPropertyAccessor &&
(getChild(0) instanceof StringLiteral)) { getChild(0) instanceof StringLiteral);
return true;
}
} }
return false; return false;
} }
@ -271,7 +269,8 @@ public class Indexer extends SpelNodeImpl {
this.children[0].generateCode(mv, cf); this.children[0].generateCode(mv, cf);
cf.exitCompilationScope(); cf.exitCompilationScope();
} }
mv.visitMethodInsn(INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true); mv.visitMethodInsn(
INVOKEINTERFACE, "java/util/Map", "get", "(Ljava/lang/Object;)Ljava/lang/Object;", true);
} }
else if (this.indexedType == IndexedType.OBJECT) { else if (this.indexedType == IndexedType.OBJECT) {
@ -526,8 +525,9 @@ public class Indexer extends SpelNodeImpl {
private final TypeDescriptor targetObjectTypeDescriptor; private final TypeDescriptor targetObjectTypeDescriptor;
public PropertyIndexingValueRef(Object targetObject, String value, EvaluationContext evaluationContext, public PropertyIndexingValueRef(Object targetObject, String value,
TypeDescriptor targetObjectTypeDescriptor) { EvaluationContext evaluationContext, TypeDescriptor targetObjectTypeDescriptor) {
this.targetObject = targetObject; this.targetObject = targetObject;
this.name = value; this.name = value;
this.evaluationContext = evaluationContext; this.evaluationContext = evaluationContext;
@ -569,11 +569,11 @@ public class Indexer extends SpelNodeImpl {
} }
} }
catch (AccessException ex) { catch (AccessException ex) {
throw new SpelEvaluationException(getStartPosition(), ex, SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, throw new SpelEvaluationException(getStartPosition(), ex,
this.targetObjectTypeDescriptor.toString()); SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, this.targetObjectTypeDescriptor.toString());
} }
throw new SpelEvaluationException(getStartPosition(), SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, throw new SpelEvaluationException(getStartPosition(),
this.targetObjectTypeDescriptor.toString()); SpelMessage.INDEXING_NOT_SUPPORTED_FOR_TYPE, this.targetObjectTypeDescriptor.toString());
} }
@Override @Override
@ -629,11 +629,12 @@ public class Indexer extends SpelNodeImpl {
private final int maximumSize; private final int maximumSize;
public CollectionIndexingValueRef(Collection collection, int index, TypeDescriptor collectionEntryTypeDescriptor, public CollectionIndexingValueRef(Collection collection, int index, TypeDescriptor collectionEntryDescriptor,
TypeConverter typeConverter, boolean growCollection, int maximumSize) { TypeConverter typeConverter, boolean growCollection, int maximumSize) {
this.collection = collection; this.collection = collection;
this.index = index; this.index = index;
this.collectionEntryDescriptor = collectionEntryTypeDescriptor; this.collectionEntryDescriptor = collectionEntryDescriptor;
this.typeConverter = typeConverter; this.typeConverter = typeConverter;
this.growCollection = growCollection; this.growCollection = growCollection;
this.maximumSize = maximumSize; this.maximumSize = maximumSize;
@ -684,13 +685,14 @@ public class Indexer extends SpelNodeImpl {
throw new SpelEvaluationException(getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION); throw new SpelEvaluationException(getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION);
} }
if (this.collectionEntryDescriptor.getElementTypeDescriptor() == null) { if (this.collectionEntryDescriptor.getElementTypeDescriptor() == null) {
throw new SpelEvaluationException(getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION_UNKNOWN_ELEMENT_TYPE); throw new SpelEvaluationException(
getStartPosition(), SpelMessage.UNABLE_TO_GROW_COLLECTION_UNKNOWN_ELEMENT_TYPE);
} }
TypeDescriptor elementType = this.collectionEntryDescriptor.getElementTypeDescriptor(); TypeDescriptor elementType = this.collectionEntryDescriptor.getElementTypeDescriptor();
try { try {
int newElements = this.index - this.collection.size(); int newElements = this.index - this.collection.size();
while (newElements >= 0) { while (newElements >= 0) {
(this.collection).add(elementType.getType().newInstance()); this.collection.add(elementType.getType().newInstance());
newElements--; newElements--;
} }
} }

56
spring-orm-hibernate5/src/main/java/org/springframework/orm/hibernate5/HibernateTemplate.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -66,12 +66,14 @@ import org.springframework.util.ReflectionUtils;
* always be configured as bean in the application context, in the first case * always be configured as bean in the application context, in the first case
* given to the service directly, in the second case to the prepared template. * given to the service directly, in the second case to the prepared template.
* *
* <p><b>NOTE: Hibernate access code can also be coded in plain Hibernate style. * <p><b>NOTE: Hibernate access code can also be coded against the native Hibernate
* Hence, for newly started projects, consider adopting the standard Hibernate * {@link Session}. Hence, for newly started projects, consider adopting the standard
* style of coding data access objects instead, based on * Hibernate style of coding against {@link SessionFactory#getCurrentSession()}.</b>
* {@link SessionFactory#getCurrentSession()}. * Alternatively, use {@link #execute(HibernateCallback)} with Java 8 lambda code blocks
* This HibernateTemplate primarily exists as a migration helper for Hibernate 3 * against the callback-provided {@code Session} which results in elegant code as well,
* based data access code, to benefit from bug fixes in Hibernate 5.x.</b> * decoupled from the Hibernate Session lifecycle. The remaining operations on this
* HibernateTemplate primarily exist as a migration helper for older Hibernate 3.x/4.x
* data access code in existing applications.</b>
* *
* @author Juergen Hoeller * @author Juergen Hoeller
* @since 4.2 * @since 4.2
@ -1169,59 +1171,59 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
} }
/** /**
* Prepare the given Query object, applying cache settings and/or * Prepare the given Criteria object, applying cache settings and/or
* a transaction timeout. * a transaction timeout.
* @param queryObject the Query object to prepare * @param criteria the Criteria object to prepare
* @see #setCacheQueries * @see #setCacheQueries
* @see #setQueryCacheRegion * @see #setQueryCacheRegion
*/ */
@SuppressWarnings({"rawtypes", "deprecation"}) protected void prepareCriteria(Criteria criteria) {
protected void prepareQuery(org.hibernate.Query queryObject) {
if (isCacheQueries()) { if (isCacheQueries()) {
queryObject.setCacheable(true); criteria.setCacheable(true);
if (getQueryCacheRegion() != null) { if (getQueryCacheRegion() != null) {
queryObject.setCacheRegion(getQueryCacheRegion()); criteria.setCacheRegion(getQueryCacheRegion());
} }
} }
if (getFetchSize() > 0) { if (getFetchSize() > 0) {
queryObject.setFetchSize(getFetchSize()); criteria.setFetchSize(getFetchSize());
} }
if (getMaxResults() > 0) { if (getMaxResults() > 0) {
queryObject.setMaxResults(getMaxResults()); criteria.setMaxResults(getMaxResults());
} }
SessionHolder sessionHolder = SessionHolder sessionHolder =
(SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory()); (SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
if (sessionHolder != null && sessionHolder.hasTimeout()) { if (sessionHolder != null && sessionHolder.hasTimeout()) {
queryObject.setTimeout(sessionHolder.getTimeToLiveInSeconds()); criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds());
} }
} }
/** /**
* Prepare the given Criteria object, applying cache settings and/or * Prepare the given Query object, applying cache settings and/or
* a transaction timeout. * a transaction timeout.
* @param criteria the Criteria object to prepare * @param queryObject the Query object to prepare
* @see #setCacheQueries * @see #setCacheQueries
* @see #setQueryCacheRegion * @see #setQueryCacheRegion
*/ */
protected void prepareCriteria(Criteria criteria) { @SuppressWarnings({"rawtypes", "deprecation"})
protected void prepareQuery(org.hibernate.Query queryObject) {
if (isCacheQueries()) { if (isCacheQueries()) {
criteria.setCacheable(true); queryObject.setCacheable(true);
if (getQueryCacheRegion() != null) { if (getQueryCacheRegion() != null) {
criteria.setCacheRegion(getQueryCacheRegion()); queryObject.setCacheRegion(getQueryCacheRegion());
} }
} }
if (getFetchSize() > 0) { if (getFetchSize() > 0) {
criteria.setFetchSize(getFetchSize()); queryObject.setFetchSize(getFetchSize());
} }
if (getMaxResults() > 0) { if (getMaxResults() > 0) {
criteria.setMaxResults(getMaxResults()); queryObject.setMaxResults(getMaxResults());
} }
SessionHolder sessionHolder = SessionHolder sessionHolder =
(SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory()); (SessionHolder) TransactionSynchronizationManager.getResource(getSessionFactory());
if (sessionHolder != null && sessionHolder.hasTimeout()) { if (sessionHolder != null && sessionHolder.hasTimeout()) {
criteria.setTimeout(sessionHolder.getTimeToLiveInSeconds()); queryObject.setTimeout(sessionHolder.getTimeToLiveInSeconds());
} }
} }
@ -1285,12 +1287,12 @@ public class HibernateTemplate implements HibernateOperations, InitializingBean
// If return value is a Query or Criteria, apply transaction timeout. // If return value is a Query or Criteria, apply transaction timeout.
// Applies to createQuery, getNamedQuery, createCriteria. // Applies to createQuery, getNamedQuery, createCriteria.
if (retVal instanceof org.hibernate.Query) {
prepareQuery(((org.hibernate.Query) retVal));
}
if (retVal instanceof Criteria) { if (retVal instanceof Criteria) {
prepareCriteria(((Criteria) retVal)); prepareCriteria(((Criteria) retVal));
} }
else if (retVal instanceof org.hibernate.Query) {
prepareQuery(((org.hibernate.Query) retVal));
}
return retVal; return retVal;
} }

10
spring-test/src/main/java/org/springframework/test/web/servlet/htmlunit/HtmlUnitRequestBuilder.java

@ -506,16 +506,6 @@ final class HtmlUnitRequestBuilder implements RequestBuilder, Mergeable {
} }
return session; return session;
} }
@Override
public HttpSession getSession() {
return super.getSession();
}
@Override
public void setSession(HttpSession session) {
super.setSession(session);
}
} }

33
spring-web/src/main/java/org/springframework/http/MediaType.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -43,7 +43,8 @@ import org.springframework.util.comparator.CompoundComparator;
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sebastien Deleuze * @author Sebastien Deleuze
* @since 3.0 * @since 3.0
* @see <a href="http://tools.ietf.org/html/rfc7231#section-3.1.1.1">HTTP 1.1: Semantics and Content, section 3.1.1.1</a> * @see <a href="http://tools.ietf.org/html/rfc7231#section-3.1.1.1">
* HTTP 1.1: Semantics and Content, section 3.1.1.1</a>
*/ */
public class MediaType extends MimeType implements Serializable { public class MediaType extends MimeType implements Serializable {
@ -99,7 +100,7 @@ public class MediaType extends MimeType implements Serializable {
/** /**
* A String equivalent of {@link MediaType#APPLICATION_JSON_UTF8}. * A String equivalent of {@link MediaType#APPLICATION_JSON_UTF8}.
*/ */
public final static String APPLICATION_JSON_UTF8_VALUE = APPLICATION_JSON_VALUE + ";charset=UTF-8"; public final static String APPLICATION_JSON_UTF8_VALUE = "application/json;charset=UTF-8";
/** /**
* Public constant media type for {@code application/octet-stream}. * Public constant media type for {@code application/octet-stream}.
@ -250,7 +251,6 @@ public class MediaType extends MimeType implements Serializable {
*/ */
public final static String TEXT_XML_VALUE = "text/xml"; public final static String TEXT_XML_VALUE = "text/xml";
private static final String PARAM_QUALITY_FACTOR = "q"; private static final String PARAM_QUALITY_FACTOR = "q";
@ -376,28 +376,6 @@ public class MediaType extends MimeType implements Serializable {
return (qualityFactory != null ? Double.parseDouble(unquote(qualityFactory)) : 1D); return (qualityFactory != null ? Double.parseDouble(unquote(qualityFactory)) : 1D);
} }
/**
* Indicate whether this {@code MediaType} includes the given media type.
* <p>For instance, {@code text/*} includes {@code text/plain} and {@code text/html}, and {@code application/*+xml}
* includes {@code application/soap+xml}, etc. This method is <b>not</b> symmetric.
* @param other the reference media type with which to compare
* @return {@code true} if this media type includes the given media type; {@code false} otherwise
*/
public boolean includes(MediaType other) {
return super.includes(other);
}
/**
* Indicate whether this {@code MediaType} is compatible with the given media type.
* <p>For instance, {@code text/*} is compatible with {@code text/plain}, {@code text/html}, and vice versa.
* In effect, this method is similar to {@link #includes(MediaType)}, except that it <b>is</b> symmetric.
* @param other the reference media type with which to compare
* @return {@code true} if this media type is compatible with the given media type; {@code false} otherwise
*/
public boolean isCompatibleWith(MediaType other) {
return super.isCompatibleWith(other);
}
/** /**
* Return a replica of this instance with the quality value of the given MediaType. * Return a replica of this instance with the quality value of the given MediaType.
* @return the same instance if the given MediaType doesn't have a quality value, or a new one otherwise * @return the same instance if the given MediaType doesn't have a quality value, or a new one otherwise
@ -624,7 +602,8 @@ public class MediaType extends MimeType implements Serializable {
else { else {
int paramsSize1 = mediaType1.getParameters().size(); int paramsSize1 = mediaType1.getParameters().size();
int paramsSize2 = mediaType2.getParameters().size(); int paramsSize2 = mediaType2.getParameters().size();
return (paramsSize2 < paramsSize1 ? -1 : (paramsSize2 == paramsSize1 ? 0 : 1)); // audio/basic;level=1 < audio/basic // audio/basic;level=1 < audio/basic
return (paramsSize2 < paramsSize1 ? -1 : (paramsSize2 == paramsSize1 ? 0 : 1));
} }
} }
} }

3
spring-webmvc/src/main/java/org/springframework/web/servlet/handler/HandlerMappingIntrospector.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2017 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -76,6 +76,7 @@ public class HandlerMappingIntrospector
* Constructor that detects the configured {@code HandlerMapping}s in the * Constructor that detects the configured {@code HandlerMapping}s in the
* given {@code ApplicationContext} or falls back on * given {@code ApplicationContext} or falls back on
* "DispatcherServlet.properties" like the {@code DispatcherServlet}. * "DispatcherServlet.properties" like the {@code DispatcherServlet}.
* @deprecated as of 4.3.12, in favor of {@link #setApplicationContext}
*/ */
@Deprecated @Deprecated
public HandlerMappingIntrospector(ApplicationContext context) { public HandlerMappingIntrospector(ApplicationContext context) {

103
spring-websocket/src/main/java/org/springframework/web/socket/server/standard/ServerEndpointRegistration.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2018 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -35,7 +35,7 @@ import org.springframework.web.socket.handler.BeanCreatingHandlerProvider;
/** /**
* An implementation of {@link javax.websocket.server.ServerEndpointConfig} for use in * An implementation of {@link javax.websocket.server.ServerEndpointConfig} for use in
* Spring applications. A {@link ServerEndpointRegistration} bean is detected by * Spring-based applications. A {@link ServerEndpointRegistration} bean is detected by
* {@link ServerEndpointExporter} and registered with a Java WebSocket runtime at startup. * {@link ServerEndpointExporter} and registered with a Java WebSocket runtime at startup.
* *
* <p>Class constructors accept a singleton {@link javax.websocket.Endpoint} instance * <p>Class constructors accept a singleton {@link javax.websocket.Endpoint} instance
@ -44,10 +44,11 @@ import org.springframework.web.socket.handler.BeanCreatingHandlerProvider;
* each client WebSocket connection. * each client WebSocket connection.
* *
* <p>This class also extends * <p>This class also extends
* {@link javax.websocket.server.ServerEndpointConfig.Configurator} to make it easier to * {@link javax.websocket.server.ServerEndpointConfig.Configurator} to make it easier
* override methods for customizing the handshake process. * to override methods for customizing the handshake process.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Juergen Hoeller
* @since 4.0 * @since 4.0
* @see ServerEndpointExporter * @see ServerEndpointExporter
*/ */
@ -56,50 +57,52 @@ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurato
private final String path; private final String path;
private final BeanCreatingHandlerProvider<Endpoint> endpointProvider;
private final Endpoint endpoint; private final Endpoint endpoint;
private List<Class<? extends Encoder>> encoders = new ArrayList<Class<? extends Encoder>>(); private final BeanCreatingHandlerProvider<Endpoint> endpointProvider;
private List<String> subprotocols = new ArrayList<String>(0);
private List<Class<? extends Decoder>> decoders = new ArrayList<Class<? extends Decoder>>(); private List<Extension> extensions = new ArrayList<Extension>(0);
private List<String> protocols = new ArrayList<String>(); private List<Class<? extends Encoder>> encoders = new ArrayList<Class<? extends Encoder>>(0);
private List<Extension> extensions = new ArrayList<Extension>(); private List<Class<? extends Decoder>> decoders = new ArrayList<Class<? extends Decoder>>(0);
private final Map<String, Object> userProperties = new HashMap<String, Object>(); private final Map<String, Object> userProperties = new HashMap<String, Object>(4);
/** /**
* Create a new {@link ServerEndpointRegistration} instance from an * Create a new {@link ServerEndpointRegistration} instance from an
* {@code javax.websocket.Endpoint} class. * {@code javax.websocket.Endpoint} instance.
* @param path the endpoint path * @param path the endpoint path
* @param endpointClass the endpoint class * @param endpoint the endpoint instance
*/ */
public ServerEndpointRegistration(String path, Class<? extends Endpoint> endpointClass) { public ServerEndpointRegistration(String path, Endpoint endpoint) {
Assert.hasText(path, "path must not be empty"); Assert.hasText(path, "Path must not be empty");
Assert.notNull(endpointClass, "endpointClass must not be null"); Assert.notNull(endpoint, "Endpoint must not be null");
this.path = path; this.path = path;
this.endpointProvider = new BeanCreatingHandlerProvider<Endpoint>(endpointClass); this.endpoint = endpoint;
this.endpoint = null; this.endpointProvider = null;
} }
/** /**
* Create a new {@link ServerEndpointRegistration} instance from an * Create a new {@link ServerEndpointRegistration} instance from an
* {@code javax.websocket.Endpoint} instance. * {@code javax.websocket.Endpoint} class.
* @param path the endpoint path * @param path the endpoint path
* @param endpoint the endpoint instance * @param endpointClass the endpoint class
*/ */
public ServerEndpointRegistration(String path, Endpoint endpoint) { public ServerEndpointRegistration(String path, Class<? extends Endpoint> endpointClass) {
Assert.hasText(path, "path must not be empty"); Assert.hasText(path, "Path must not be empty");
Assert.notNull(endpoint, "endpoint must not be null"); Assert.notNull(endpointClass, "Endpoint Class must not be null");
this.path = path; this.path = path;
this.endpointProvider = null; this.endpoint = null;
this.endpoint = endpoint; this.endpointProvider = new BeanCreatingHandlerProvider<Endpoint>(endpointClass);
} }
// ServerEndpointConfig implementation
@Override @Override
public String getPath() { public String getPath() {
return this.path; return this.path;
@ -114,13 +117,13 @@ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurato
return (this.endpoint != null) ? this.endpoint : this.endpointProvider.getHandler(); return (this.endpoint != null) ? this.endpoint : this.endpointProvider.getHandler();
} }
public void setSubprotocols(List<String> protocols) { public void setSubprotocols(List<String> subprotocols) {
this.protocols = protocols; this.subprotocols = subprotocols;
} }
@Override @Override
public List<String> getSubprotocols() { public List<String> getSubprotocols() {
return this.protocols; return this.subprotocols;
} }
public void setExtensions(List<Extension> extensions) { public void setExtensions(List<Extension> extensions) {
@ -132,16 +135,6 @@ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurato
return this.extensions; return this.extensions;
} }
public void setUserProperties(Map<String, Object> userProperties) {
this.userProperties.clear();
this.userProperties.putAll(userProperties);
}
@Override
public Map<String, Object> getUserProperties() {
return this.userProperties;
}
public void setEncoders(List<Class<? extends Encoder>> encoders) { public void setEncoders(List<Class<? extends Encoder>> encoders) {
this.encoders = encoders; this.encoders = encoders;
} }
@ -160,20 +153,23 @@ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurato
return this.decoders; return this.decoders;
} }
public void setUserProperties(Map<String, Object> userProperties) {
this.userProperties.clear();
this.userProperties.putAll(userProperties);
}
@Override @Override
public Configurator getConfigurator() { public Map<String, Object> getUserProperties() {
return this; return this.userProperties;
} }
@Override @Override
public void setBeanFactory(BeanFactory beanFactory) { public Configurator getConfigurator() {
if (this.endpointProvider != null) { return this;
this.endpointProvider.setBeanFactory(beanFactory);
}
} }
// Implementations of ServerEndpointConfig.Configurator // ServerEndpointConfig.Configurator implementation
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
@Override @Override
@ -186,24 +182,19 @@ public class ServerEndpointRegistration extends ServerEndpointConfig.Configurato
super.modifyHandshake(this, request, response); super.modifyHandshake(this, request, response);
} }
@Override
public boolean checkOrigin(String originHeaderValue) {
return super.checkOrigin(originHeaderValue);
}
@Override // Remaining methods
public String getNegotiatedSubprotocol(List<String> supported, List<String> requested) {
return super.getNegotiatedSubprotocol(supported, requested);
}
@Override @Override
public List<Extension> getNegotiatedExtensions(List<Extension> installed, List<Extension> requested) { public void setBeanFactory(BeanFactory beanFactory) {
return super.getNegotiatedExtensions(installed, requested); if (this.endpointProvider != null) {
this.endpointProvider.setBeanFactory(beanFactory);
}
} }
@Override @Override
public String toString() { public String toString() {
return "ServerEndpointRegistration for path '" + getPath() + "': " + getEndpointClass(); return "ServerEndpointRegistration for path '" + getPath() + "': " + getEndpointClass();
} }
} }

Loading…
Cancel
Save