Polishing
This commit is contained in:
parent
777085bbfc
commit
3c726aa6c1
|
@ -36,7 +36,6 @@ import org.springframework.util.concurrent.SettableListenableFuture;
|
||||||
*/
|
*/
|
||||||
public class MockAsyncClientHttpRequest extends MockClientHttpRequest implements AsyncClientHttpRequest {
|
public class MockAsyncClientHttpRequest extends MockClientHttpRequest implements AsyncClientHttpRequest {
|
||||||
|
|
||||||
|
|
||||||
public MockAsyncClientHttpRequest() {
|
public MockAsyncClientHttpRequest() {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -44,6 +43,7 @@ public class MockAsyncClientHttpRequest extends MockClientHttpRequest implements
|
||||||
super(httpMethod, uri);
|
super(httpMethod, uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ListenableFuture<ClientHttpResponse> executeAsync() throws IOException {
|
public ListenableFuture<ClientHttpResponse> executeAsync() throws IOException {
|
||||||
SettableListenableFuture<ClientHttpResponse> future = new SettableListenableFuture<ClientHttpResponse>();
|
SettableListenableFuture<ClientHttpResponse> future = new SettableListenableFuture<ClientHttpResponse>();
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.web.servlet.view.groovy;
|
package org.springframework.web.servlet.view.groovy;
|
||||||
|
|
||||||
import groovy.text.markup.MarkupTemplateEngine;
|
import groovy.text.markup.MarkupTemplateEngine;
|
||||||
|
@ -23,15 +24,16 @@ import groovy.text.markup.MarkupTemplateEngine;
|
||||||
* Detected and used by GroovyMarkupView.
|
* Detected and used by GroovyMarkupView.
|
||||||
*
|
*
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
* @see GroovyMarkupConfigurer
|
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
|
* @see GroovyMarkupConfigurer
|
||||||
*/
|
*/
|
||||||
public interface GroovyMarkupConfig {
|
public interface GroovyMarkupConfig {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the Groovy MarkupTemplateEngine for the current web application context.
|
* Return the Groovy {@link MarkupTemplateEngine} for the current
|
||||||
* May be unique to one servlet, or shared in the root context.
|
* web application context. May be unique to one servlet, or shared
|
||||||
* @return the Groovy Template engine
|
* in the root context.
|
||||||
|
* @return the Groovy MarkupTemplateEngine engine
|
||||||
*/
|
*/
|
||||||
MarkupTemplateEngine getTemplateEngine();
|
MarkupTemplateEngine getTemplateEngine();
|
||||||
|
|
||||||
|
|
|
@ -13,6 +13,7 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.web.servlet.view.groovy;
|
package org.springframework.web.servlet.view.groovy;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
@ -26,7 +27,6 @@ import groovy.text.markup.MarkupTemplateEngine;
|
||||||
import groovy.text.markup.TemplateConfiguration;
|
import groovy.text.markup.TemplateConfiguration;
|
||||||
import groovy.text.markup.TemplateResolver;
|
import groovy.text.markup.TemplateResolver;
|
||||||
|
|
||||||
import org.springframework.beans.BeansException;
|
|
||||||
import org.springframework.beans.factory.InitializingBean;
|
import org.springframework.beans.factory.InitializingBean;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
|
@ -55,9 +55,9 @@ import org.springframework.util.StringUtils;
|
||||||
*
|
*
|
||||||
* By default this bean will create a {@link MarkupTemplateEngine} with:
|
* By default this bean will create a {@link MarkupTemplateEngine} with:
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>a parent ClassLoader for loading Groovy templates with their references
|
* <li>a parent ClassLoader for loading Groovy templates with their references
|
||||||
* <li>the default configuration in the base class {@link TemplateConfiguration}
|
* <li>the default configuration in the base class {@link TemplateConfiguration}
|
||||||
* <li>a {@link groovy.text.markup.TemplateResolver} for resolving template files
|
* <li>a {@link groovy.text.markup.TemplateResolver} for resolving template files
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* You can provide the {@link MarkupTemplateEngine} instance directly to this bean
|
* You can provide the {@link MarkupTemplateEngine} instance directly to this bean
|
||||||
|
@ -78,7 +78,6 @@ import org.springframework.util.StringUtils;
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
*
|
|
||||||
* @see GroovyMarkupView
|
* @see GroovyMarkupView
|
||||||
* @see <a href="http://beta.groovy-lang.org/docs/groovy-2.3.2/html/documentation/markup-template-engine.html">
|
* @see <a href="http://beta.groovy-lang.org/docs/groovy-2.3.2/html/documentation/markup-template-engine.html">
|
||||||
* Groovy Markup Template engine documentation</a>
|
* Groovy Markup Template engine documentation</a>
|
||||||
|
@ -119,15 +118,12 @@ public class GroovyMarkupConfigurer extends TemplateConfiguration
|
||||||
this.templateEngine = templateEngine;
|
this.templateEngine = templateEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
public MarkupTemplateEngine getTemplateEngine() {
|
public MarkupTemplateEngine getTemplateEngine() {
|
||||||
return templateEngine;
|
return templateEngine;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
|
public void setApplicationContext(ApplicationContext applicationContext) {
|
||||||
this.applicationContext = applicationContext;
|
this.applicationContext = applicationContext;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -161,8 +157,8 @@ public class GroovyMarkupConfigurer extends TemplateConfiguration
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a parent classloader for Groovy to use as parent classloader when
|
* Create a parent ClassLoader for Groovy to use as parent ClassLoader
|
||||||
* loading and compiling templates.
|
* when loading and compiling templates.
|
||||||
*/
|
*/
|
||||||
protected ClassLoader createTemplateClassLoader() throws IOException {
|
protected ClassLoader createTemplateClassLoader() throws IOException {
|
||||||
String[] paths = StringUtils.commaDelimitedListToStringArray(getResourceLoaderPath());
|
String[] paths = StringUtils.commaDelimitedListToStringArray(getResourceLoaderPath());
|
||||||
|
@ -183,20 +179,11 @@ public class GroovyMarkupConfigurer extends TemplateConfiguration
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Resolve a template from the given template path.
|
* Resolve a template from the given template path.
|
||||||
*
|
* <p>The default implementation uses the Locale associated with the current request,
|
||||||
* <p>The default implementation uses the Locale associated with the current
|
* as obtained through {@link org.springframework.context.i18n.LocaleContextHolder LocaleContextHolder},
|
||||||
* request, as obtained through
|
* to find the template file. Effectively the locale configured at the engine level is ignored.
|
||||||
* {@link org.springframework.context.i18n.LocaleContextHolder LocaleContextHolder},
|
|
||||||
* to find the template file. Effectively the locale configured at the engine
|
|
||||||
* level is ignored.
|
|
||||||
*
|
|
||||||
* @see LocaleContextHolder
|
* @see LocaleContextHolder
|
||||||
* @see #setLocale(java.util.Locale)
|
* @see #setLocale
|
||||||
*
|
|
||||||
* @param classLoader
|
|
||||||
* @param templatePath
|
|
||||||
* @return
|
|
||||||
* @throws IOException
|
|
||||||
*/
|
*/
|
||||||
protected URL resolveTemplate(ClassLoader classLoader, String templatePath) throws IOException {
|
protected URL resolveTemplate(ClassLoader classLoader, String templatePath) throws IOException {
|
||||||
MarkupTemplateEngine.TemplateResource resource = MarkupTemplateEngine.TemplateResource.parse(templatePath);
|
MarkupTemplateEngine.TemplateResource resource = MarkupTemplateEngine.TemplateResource.parse(templatePath);
|
||||||
|
@ -233,4 +220,5 @@ public class GroovyMarkupConfigurer extends TemplateConfiguration
|
||||||
return GroovyMarkupConfigurer.this.resolveTemplate(this.classLoader, templatePath);
|
return GroovyMarkupConfigurer.this.resolveTemplate(this.classLoader, templatePath);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -13,13 +13,13 @@
|
||||||
* See the License for the specific language governing permissions and
|
* See the License for the specific language governing permissions and
|
||||||
* limitations under the License.
|
* limitations under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package org.springframework.web.servlet.view.groovy;
|
package org.springframework.web.servlet.view.groovy;
|
||||||
|
|
||||||
import java.io.BufferedWriter;
|
import java.io.BufferedWriter;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.util.Locale;
|
import java.util.Locale;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
@ -43,7 +43,6 @@ import org.springframework.web.util.NestedServletException;
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
*
|
|
||||||
* @see GroovyMarkupViewResolver
|
* @see GroovyMarkupViewResolver
|
||||||
* @see GroovyMarkupConfigurer
|
* @see GroovyMarkupConfigurer
|
||||||
* @see <a href="http://beta.groovy-lang.org/docs/groovy-2.3.2/html/documentation/markup-template-engine.html">
|
* @see <a href="http://beta.groovy-lang.org/docs/groovy-2.3.2/html/documentation/markup-template-engine.html">
|
||||||
|
@ -56,20 +55,15 @@ public class GroovyMarkupView extends AbstractTemplateView {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the MarkupTemplateEngine to use in this view.
|
* Set the MarkupTemplateEngine to use in this view.
|
||||||
*
|
|
||||||
* <p>If not set, the engine is auto-detected by looking up up a single
|
* <p>If not set, the engine is auto-detected by looking up up a single
|
||||||
* {@link GroovyMarkupConfig} bean in the web application context and using
|
* {@link GroovyMarkupConfig} bean in the web application context and using
|
||||||
* it to obtain the configured {@code MarkupTemplateEngine} instance.
|
* it to obtain the configured {@code MarkupTemplateEngine} instance.
|
||||||
*
|
|
||||||
* @see GroovyMarkupConfig
|
* @see GroovyMarkupConfig
|
||||||
*/
|
*/
|
||||||
public void setTemplateEngine(MarkupTemplateEngine engine) {
|
public void setTemplateEngine(MarkupTemplateEngine engine) {
|
||||||
this.engine = engine;
|
this.engine = engine;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
|
||||||
* {@inheritDoc}
|
|
||||||
*/
|
|
||||||
@Override
|
@Override
|
||||||
public boolean checkResource(Locale locale) throws Exception {
|
public boolean checkResource(Locale locale) throws Exception {
|
||||||
try {
|
try {
|
||||||
|
@ -86,7 +80,6 @@ public class GroovyMarkupView extends AbstractTemplateView {
|
||||||
* If no {@link #setTemplateEngine(MarkupTemplateEngine) templateEngine} has
|
* If no {@link #setTemplateEngine(MarkupTemplateEngine) templateEngine} has
|
||||||
* been manually set, this method looks up a {@link GroovyMarkupConfig} bean
|
* been manually set, this method looks up a {@link GroovyMarkupConfig} bean
|
||||||
* by type and uses it to obtain the Groovy Markup template engine.
|
* by type and uses it to obtain the Groovy Markup template engine.
|
||||||
*
|
|
||||||
* @see GroovyMarkupConfig
|
* @see GroovyMarkupConfig
|
||||||
* @see #setTemplateEngine(groovy.text.markup.MarkupTemplateEngine)
|
* @see #setTemplateEngine(groovy.text.markup.MarkupTemplateEngine)
|
||||||
*/
|
*/
|
||||||
|
@ -99,7 +92,7 @@ public class GroovyMarkupView extends AbstractTemplateView {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Auto-detect a MarkupTemplateEngine via the ApplicationContext.
|
* Autodetect a MarkupTemplateEngine via the ApplicationContext.
|
||||||
* Called if a MarkupTemplateEngine has not been manually configured.
|
* Called if a MarkupTemplateEngine has not been manually configured.
|
||||||
*/
|
*/
|
||||||
protected MarkupTemplateEngine autodetectMarkupTemplateEngine() throws BeansException {
|
protected MarkupTemplateEngine autodetectMarkupTemplateEngine() throws BeansException {
|
||||||
|
@ -108,13 +101,13 @@ public class GroovyMarkupView extends AbstractTemplateView {
|
||||||
GroovyMarkupConfig.class, true, false).getTemplateEngine();
|
GroovyMarkupConfig.class, true, false).getTemplateEngine();
|
||||||
}
|
}
|
||||||
catch (NoSuchBeanDefinitionException ex) {
|
catch (NoSuchBeanDefinitionException ex) {
|
||||||
throw new ApplicationContextException(
|
throw new ApplicationContextException("Expected a single GroovyMarkupConfig bean in the current " +
|
||||||
"Expected a single GroovyMarkupConfig bean in the current Servlet web application context " +
|
"Servlet web application context or the parent root context: GroovyMarkupConfigurer is " +
|
||||||
"or the parent root context: GroovyMarkupConfigurer is the usual implementation. " +
|
"the usual implementation. This bean may have any name.", ex);
|
||||||
"This bean may have any name.", ex);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderMergedTemplateModel(Map<String, Object> model,
|
protected void renderMergedTemplateModel(Map<String, Object> model,
|
||||||
HttpServletRequest request, HttpServletResponse response) throws Exception {
|
HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||||
|
@ -132,10 +125,9 @@ public class GroovyMarkupView extends AbstractTemplateView {
|
||||||
return this.engine.createTemplateByPath(viewUrl);
|
return this.engine.createTemplateByPath(viewUrl);
|
||||||
}
|
}
|
||||||
catch (ClassNotFoundException ex) {
|
catch (ClassNotFoundException ex) {
|
||||||
Throwable cause = ex.getCause() != null ? ex.getCause() : ex;
|
Throwable cause = (ex.getCause() != null ? ex.getCause() : ex);
|
||||||
throw new NestedServletException(
|
throw new NestedServletException("Could not find class while rendering Groovy Markup view with name '" +
|
||||||
"Could not find class while rendering Groovy Markup view with name '" +
|
getUrl() + "': " + ex.getMessage() + "'", cause);
|
||||||
getUrl() + "': " + ex.getMessage() + "'", cause);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -34,17 +34,15 @@ import org.springframework.web.servlet.view.AbstractTemplateViewResolver;
|
||||||
* View object if a template is actually found.
|
* View object if a template is actually found.
|
||||||
*
|
*
|
||||||
* @author Brian Clozel
|
* @author Brian Clozel
|
||||||
* @see GroovyMarkupConfigurer
|
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
|
* @see GroovyMarkupConfigurer
|
||||||
*/
|
*/
|
||||||
public class GroovyMarkupViewResolver extends AbstractTemplateViewResolver {
|
public class GroovyMarkupViewResolver extends AbstractTemplateViewResolver {
|
||||||
|
|
||||||
|
|
||||||
public GroovyMarkupViewResolver() {
|
public GroovyMarkupViewResolver() {
|
||||||
this.setViewClass(requiredViewClass());
|
setViewClass(requiredViewClass());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected Class<?> requiredViewClass() {
|
protected Class<?> requiredViewClass() {
|
||||||
return GroovyMarkupView.class;
|
return GroovyMarkupView.class;
|
||||||
|
@ -58,4 +56,4 @@ public class GroovyMarkupViewResolver extends AbstractTemplateViewResolver {
|
||||||
return viewName + "_" + locale;
|
return viewName + "_" + locale;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,13 +16,14 @@
|
||||||
|
|
||||||
package org.springframework.web.socket.config.annotation;
|
package org.springframework.web.socket.config.annotation;
|
||||||
|
|
||||||
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.springframework.beans.factory.config.CustomScopeConfigurer;
|
import org.springframework.beans.factory.config.CustomScopeConfigurer;
|
||||||
import org.springframework.context.annotation.Bean;
|
import org.springframework.context.annotation.Bean;
|
||||||
import org.springframework.messaging.simp.SimpSessionScope;
|
import org.springframework.messaging.simp.SimpSessionScope;
|
||||||
|
|
||||||
import java.util.Collections;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
* Bean configuration for a "websocket" scope, bound to {@link SimpSessionScope}.
|
||||||
*
|
*
|
||||||
* @author Rossen Stoyanchev
|
* @author Rossen Stoyanchev
|
||||||
* @since 4.1
|
* @since 4.1
|
||||||
|
|
Loading…
Reference in New Issue