Polish error messages in ServletServerContainerFactoryBean

Issue: SPR-14367
This commit is contained in:
Sam Brannen 2016-06-22 19:30:23 +02:00
parent fd9d518c36
commit 7f16bdaf74
1 changed files with 10 additions and 3 deletions

View File

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2016 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.
@ -40,6 +40,7 @@ import org.springframework.web.context.ServletContextAware;
* to customize the properties of the (one and only) {@code ServerContainer} instance. * to customize the properties of the (one and only) {@code ServerContainer} instance.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @author Sam Brannen
* @since 4.0 * @since 4.0
*/ */
public class ServletServerContainerFactoryBean public class ServletServerContainerFactoryBean
@ -53,6 +54,8 @@ public class ServletServerContainerFactoryBean
private Integer maxBinaryMessageBufferSize; private Integer maxBinaryMessageBufferSize;
private ServletContext servletContext;
private ServerContainer serverContainer; private ServerContainer serverContainer;
@ -90,14 +93,18 @@ public class ServletServerContainerFactoryBean
@Override @Override
public void setServletContext(ServletContext servletContext) { public void setServletContext(ServletContext servletContext) {
this.serverContainer = (ServerContainer) servletContext.getAttribute("javax.websocket.server.ServerContainer"); this.servletContext = servletContext;
} }
@Override @Override
public void afterPropertiesSet() { public void afterPropertiesSet() {
Assert.state(this.serverContainer != null, Assert.state(this.servletContext != null,
"A ServletContext is required to access the javax.websocket.server.ServerContainer instance"); "A ServletContext is required to access the javax.websocket.server.ServerContainer instance");
this.serverContainer = (ServerContainer) this.servletContext.getAttribute(
"javax.websocket.server.ServerContainer");
Assert.state(this.serverContainer != null,
"Attribute 'javax.websocket.server.ServerContainer' not found in ServletContext");
if (this.asyncSendTimeout != null) { if (this.asyncSendTimeout != null) {
this.serverContainer.setAsyncSendTimeout(this.asyncSendTimeout); this.serverContainer.setAsyncSendTimeout(this.asyncSendTimeout);