Polishing
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2014 the original author or authors.
|
||||
* Copyright 2002-2018 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.
|
||||
@@ -33,7 +33,7 @@ public class StringLiteral extends Literal {
|
||||
|
||||
|
||||
public StringLiteral(String payload, int pos, String value) {
|
||||
super(payload,pos);
|
||||
super(payload, pos);
|
||||
value = value.substring(1, value.length() - 1);
|
||||
this.value = new TypedValue(value.replaceAll("''", "'").replaceAll("\"\"", "\""));
|
||||
this.exitTypeDescriptor = "Ljava/lang/String";
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -132,9 +132,9 @@ public class SpelCompiler implements Opcodes {
|
||||
@Nullable
|
||||
private Class<? extends CompiledExpression> createExpressionClass(SpelNodeImpl expressionToCompile) {
|
||||
// Create class outline 'spel/ExNNN extends org.springframework.expression.spel.CompiledExpression'
|
||||
String clazzName = "spel/Ex" + getNextSuffix();
|
||||
String className = "spel/Ex" + getNextSuffix();
|
||||
ClassWriter cw = new ExpressionClassWriter();
|
||||
cw.visit(V1_5, ACC_PUBLIC, clazzName, null, "org/springframework/expression/spel/CompiledExpression", null);
|
||||
cw.visit(V1_5, ACC_PUBLIC, className, null, "org/springframework/expression/spel/CompiledExpression", null);
|
||||
|
||||
// Create default constructor
|
||||
MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, "<init>", "()V", null, null);
|
||||
@@ -152,7 +152,7 @@ public class SpelCompiler implements Opcodes {
|
||||
new String[ ]{"org/springframework/expression/EvaluationException"});
|
||||
mv.visitCode();
|
||||
|
||||
CodeFlow cf = new CodeFlow(clazzName, cw);
|
||||
CodeFlow cf = new CodeFlow(className, cw);
|
||||
|
||||
// Ask the expression AST to generate the body of the method
|
||||
try {
|
||||
@@ -181,7 +181,7 @@ public class SpelCompiler implements Opcodes {
|
||||
byte[] data = cw.toByteArray();
|
||||
// TODO need to make this conditionally occur based on a debug flag
|
||||
// dump(expressionToCompile.toStringAST(), clazzName, data);
|
||||
return loadClass(clazzName.replaceAll("/", "."), data);
|
||||
return loadClass(className.replaceAll("/", "."), data);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -256,12 +256,12 @@ public class SpelCompiler implements Opcodes {
|
||||
}
|
||||
|
||||
int getClassesDefinedCount() {
|
||||
return classesDefinedCount;
|
||||
return this.classesDefinedCount;
|
||||
}
|
||||
|
||||
public Class<?> defineClass(String name, byte[] bytes) {
|
||||
Class<?> clazz = super.defineClass(name, bytes, 0, bytes.length);
|
||||
classesDefinedCount++;
|
||||
this.classesDefinedCount++;
|
||||
return clazz;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -199,8 +199,8 @@ public class ServerSentEventHttpMessageWriter implements HttpMessageWriter<Objec
|
||||
@Nullable MediaType mediaType, ServerHttpRequest request, ServerHttpResponse response) {
|
||||
|
||||
if (this.encoder instanceof HttpMessageEncoder) {
|
||||
HttpMessageEncoder<?> httpEncoder = (HttpMessageEncoder<?>) this.encoder;
|
||||
return httpEncoder.getEncodeHints(actualType, elementType, mediaType, request, response);
|
||||
HttpMessageEncoder<?> encoder = (HttpMessageEncoder<?>) this.encoder;
|
||||
return encoder.getEncodeHints(actualType, elementType, mediaType, request, response);
|
||||
}
|
||||
return Collections.emptyMap();
|
||||
}
|
||||
|
||||
@@ -1,11 +1,11 @@
|
||||
/*
|
||||
* 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");
|
||||
* 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,
|
||||
@@ -63,13 +63,13 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
|
||||
private static final List<String> SAFE_METHODS = Arrays.asList("GET", "HEAD");
|
||||
|
||||
/**
|
||||
* Pattern matching ETag multiple field values in headers such as "If-Match", "If-None-Match"
|
||||
* Pattern matching ETag multiple field values in headers such as "If-Match", "If-None-Match".
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7232#section-2.3">Section 2.3 of RFC 7232</a>
|
||||
*/
|
||||
private static final Pattern ETAG_HEADER_VALUE_PATTERN = Pattern.compile("\\*|\\s*((W\\/)?(\"[^\"]*\"))\\s*,?");
|
||||
|
||||
/**
|
||||
* Date formats as specified in the HTTP RFC
|
||||
* Date formats as specified in the HTTP RFC.
|
||||
* @see <a href="https://tools.ietf.org/html/rfc7231#section-7.1.1.1">Section 7.1.1.1 of RFC 7231</a>
|
||||
*/
|
||||
private static final String[] DATE_FORMATS = new String[] {
|
||||
|
||||
@@ -310,10 +310,10 @@ public class DefaultServerWebExchange implements ServerWebExchange {
|
||||
}
|
||||
// We will perform this validation...
|
||||
etag = padEtagIfNecessary(etag);
|
||||
for (String clientETag : ifNoneMatch) {
|
||||
for (String clientEtag : ifNoneMatch) {
|
||||
// Compare weak/strong ETags as per https://tools.ietf.org/html/rfc7232#section-2.3
|
||||
if (StringUtils.hasLength(clientETag) &&
|
||||
clientETag.replaceFirst("^W/", "").equals(etag.replaceFirst("^W/", ""))) {
|
||||
if (StringUtils.hasLength(clientEtag) &&
|
||||
clientEtag.replaceFirst("^W/", "").equals(etag.replaceFirst("^W/", ""))) {
|
||||
this.notModified = true;
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -32,6 +32,8 @@ import org.springframework.mock.http.server.reactive.test.MockServerHttpRequest;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ServerSentEventHttpMessageReader}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
*/
|
||||
public class ServerSentEventHttpMessageReaderTests extends AbstractDataBufferAllocatingTestCase {
|
||||
@@ -42,24 +44,21 @@ public class ServerSentEventHttpMessageReaderTests extends AbstractDataBufferAll
|
||||
|
||||
@Test
|
||||
public void cantRead() {
|
||||
assertFalse(messageReader.canRead(ResolvableType.forClass(Object.class),
|
||||
new MediaType("foo", "bar")));
|
||||
assertFalse(messageReader.canRead(ResolvableType.forClass(Object.class), new MediaType("foo", "bar")));
|
||||
assertFalse(messageReader.canRead(ResolvableType.forClass(Object.class), null));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void canRead() {
|
||||
assertTrue(messageReader.canRead(ResolvableType.forClass(Object.class),
|
||||
new MediaType("text", "event-stream")));
|
||||
assertTrue(messageReader.canRead(ResolvableType.forClass(ServerSentEvent.class),
|
||||
new MediaType("foo", "bar")));
|
||||
assertTrue(messageReader.canRead(ResolvableType.forClass(Object.class), new MediaType("text", "event-stream")));
|
||||
assertTrue(messageReader.canRead(ResolvableType.forClass(ServerSentEvent.class), new MediaType("foo", "bar")));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void readServerSentEvents() {
|
||||
MockServerHttpRequest request = MockServerHttpRequest.post("/").body(
|
||||
"id:c42\nevent:foo\nretry:123\n:bla\n:bla bla\n:bla bla bla\ndata:bar\n\n" +
|
||||
"id:c43\nevent:bar\nretry:456\ndata:baz\n\n");
|
||||
"id:c43\nevent:bar\nretry:456\ndata:baz\n\n");
|
||||
|
||||
Flux<ServerSentEvent> events = this.messageReader
|
||||
.read(ResolvableType.forClassWithGenerics(ServerSentEvent.class, String.class),
|
||||
|
||||
@@ -41,6 +41,7 @@ import static org.springframework.core.ResolvableType.*;
|
||||
|
||||
/**
|
||||
* Unit tests for {@link ServerSentEventHttpMessageWriter}.
|
||||
*
|
||||
* @author Sebastien Deleuze
|
||||
* @author Rossen Stoyanchev
|
||||
*/
|
||||
@@ -48,14 +49,12 @@ public class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAll
|
||||
|
||||
private static final Map<String, Object> HINTS = Collections.emptyMap();
|
||||
|
||||
|
||||
private ServerSentEventHttpMessageWriter messageWriter =
|
||||
new ServerSentEventHttpMessageWriter(new Jackson2JsonEncoder());
|
||||
|
||||
|
||||
@Test
|
||||
public void canWrite() {
|
||||
|
||||
assertTrue(this.messageWriter.canWrite(forClass(Object.class), null));
|
||||
assertFalse(this.messageWriter.canWrite(forClass(Object.class), new MediaType("foo", "bar")));
|
||||
|
||||
@@ -69,7 +68,6 @@ public class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAll
|
||||
|
||||
@Test
|
||||
public void writeServerSentEvent() {
|
||||
|
||||
ServerSentEvent<?> event = ServerSentEvent.builder().data("bar").id("c42").event("foo")
|
||||
.comment("bla\nbla bla\nbla bla bla").retry(Duration.ofMillis(123L)).build();
|
||||
|
||||
@@ -134,7 +132,6 @@ public class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAll
|
||||
|
||||
@Test // SPR-14899
|
||||
public void writePojoWithPrettyPrint() {
|
||||
|
||||
ObjectMapper mapper = Jackson2ObjectMapperBuilder.json().indentOutput(true).build();
|
||||
this.messageWriter = new ServerSentEventHttpMessageWriter(new Jackson2JsonEncoder(mapper));
|
||||
|
||||
@@ -172,8 +169,8 @@ public class ServerSentEventHttpMessageWriterTests extends AbstractDataBufferAll
|
||||
testWrite(source, MediaType.TEXT_EVENT_STREAM, response, clazz);
|
||||
}
|
||||
|
||||
private <T> void testWrite(Publisher<T> source, MediaType mediaType, MockServerHttpResponse response,
|
||||
Class<T> clazz) {
|
||||
private <T> void testWrite(
|
||||
Publisher<T> source, MediaType mediaType, MockServerHttpResponse response, Class<T> clazz) {
|
||||
|
||||
this.messageWriter.write(source, forClass(clazz), mediaType, response, HINTS)
|
||||
.block(Duration.ofMillis(5000));
|
||||
|
||||
@@ -88,7 +88,7 @@ import org.springframework.web.servlet.handler.AbstractHandlerExceptionResolver;
|
||||
* </tr>
|
||||
* <tr class="altColor">
|
||||
* <td><p>MissingServletRequestParameterException</p></td>
|
||||
* <td><p>500 (SC_INTERNAL_SERVER_ERROR)</p></td>
|
||||
* <td><p>400 (SC_BAD_REQUEST)</p></td>
|
||||
* </tr>
|
||||
* <tr class="rowColor">
|
||||
* <td><p>ServletRequestBindingException</p></td>
|
||||
@@ -364,7 +364,8 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
/**
|
||||
* Handle the case when a {@link org.springframework.web.bind.WebDataBinder} conversion cannot occur.
|
||||
* <p>The default implementation sends an HTTP 500 error, and returns an empty {@code ModelAndView}.
|
||||
* Alternatively, a fallback view could be chosen, or the TypeMismatchException could be rethrown as-is.
|
||||
* Alternatively, a fallback view could be chosen, or the ConversionNotSupportedException could be
|
||||
* rethrown as-is.
|
||||
* @param ex the ConversionNotSupportedException to be handled
|
||||
* @param request current HTTP request
|
||||
* @param response current HTTP response
|
||||
@@ -401,7 +402,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
* Handle the case where a {@linkplain org.springframework.http.converter.HttpMessageConverter message converter}
|
||||
* cannot read from a HTTP request.
|
||||
* <p>The default implementation sends an HTTP 400 error, and returns an empty {@code ModelAndView}.
|
||||
* Alternatively, a fallback view could be chosen, or the HttpMediaTypeNotSupportedException could be
|
||||
* Alternatively, a fallback view could be chosen, or the HttpMessageNotReadableException could be
|
||||
* rethrown as-is.
|
||||
* @param ex the HttpMessageNotReadableException to be handled
|
||||
* @param request current HTTP request
|
||||
@@ -422,7 +423,7 @@ public class DefaultHandlerExceptionResolver extends AbstractHandlerExceptionRes
|
||||
* {@linkplain org.springframework.http.converter.HttpMessageConverter message converter}
|
||||
* cannot write to a HTTP request.
|
||||
* <p>The default implementation sends an HTTP 500 error, and returns an empty {@code ModelAndView}.
|
||||
* Alternatively, a fallback view could be chosen, or the HttpMediaTypeNotSupportedException could
|
||||
* Alternatively, a fallback view could be chosen, or the HttpMessageNotWritableException could
|
||||
* be rethrown as-is.
|
||||
* @param ex the HttpMessageNotWritableException to be handled
|
||||
* @param request current HTTP request
|
||||
|
||||
@@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -38,7 +38,7 @@ import org.springframework.web.util.TagUtils;
|
||||
import org.springframework.web.util.UriUtils;
|
||||
|
||||
/**
|
||||
* The {@code <url>} tag creates URLs. Modeled after the JSTL c:url tag with
|
||||
* The {@code <url>} tag creates URLs. Modeled after the JSTL {@code c:url} tag with
|
||||
* backwards compatibility in mind.
|
||||
*
|
||||
* <p>Enhancements to the JSTL functionality include:
|
||||
@@ -76,56 +76,56 @@ import org.springframework.web.util.UriUtils;
|
||||
* <caption>Attribute Summary</caption>
|
||||
* <thead>
|
||||
* <tr>
|
||||
* <th class="colFirst">Attribute</th>
|
||||
* <th class="colOne">Required?</th>
|
||||
* <th class="colOne">Runtime Expression?</th>
|
||||
* <th class="colLast">Description</th>
|
||||
* <th>Attribute</th>
|
||||
* <th>Required?</th>
|
||||
* <th>Runtime Expression?</th>
|
||||
* <th>Description</th>
|
||||
* </tr>
|
||||
* </thead>
|
||||
* <tbody>
|
||||
* <tr class="altColor">
|
||||
* <td>value</p></td>
|
||||
* <td>true</p></td>
|
||||
* <td>true</p></td>
|
||||
* <tr>
|
||||
* <td>value</td>
|
||||
* <td>true</td>
|
||||
* <td>true</td>
|
||||
* <td>The URL to build. This value can include template {placeholders} that are
|
||||
* replaced with the URL encoded value of the named parameter. Parameters
|
||||
* must be defined using the param tag inside the body of this tag.</p></td>
|
||||
* must be defined using the param tag inside the body of this tag.</td>
|
||||
* </tr>
|
||||
* <tr class="rowColor">
|
||||
* <td>context</p></td>
|
||||
* <td>false</p></td>
|
||||
* <td>true</p></td>
|
||||
* <tr>
|
||||
* <td>context</td>
|
||||
* <td>false</td>
|
||||
* <td>true</td>
|
||||
* <td>Specifies a remote application context path.
|
||||
* The default is the current application context path.</p></td>
|
||||
* The default is the current application context path.</td>
|
||||
* </tr>
|
||||
* <tr class="altColor">
|
||||
* <td>var</p></td>
|
||||
* <td>false</p></td>
|
||||
* <td>true</p></td>
|
||||
* <tr>
|
||||
* <td>var</td>
|
||||
* <td>false</td>
|
||||
* <td>true</td>
|
||||
* <td>The name of the variable to export the URL value to.
|
||||
* If not specified the URL is written as output.</p></td>
|
||||
* If not specified the URL is written as output.</td>
|
||||
* </tr>
|
||||
* <tr class="rowColor">
|
||||
* <td>scope</p></td>
|
||||
* <td>false</p></td>
|
||||
* <td>true</p></td>
|
||||
* <tr>
|
||||
* <td>scope</td>
|
||||
* <td>false</td>
|
||||
* <td>true</td>
|
||||
* <td>The scope for the var. 'application', 'session', 'request' and 'page'
|
||||
* scopes are supported. Defaults to page scope. This attribute has no
|
||||
* effect unless the var attribute is also defined.</p></td>
|
||||
* effect unless the var attribute is also defined.</td>
|
||||
* </tr>
|
||||
* <tr class="altColor">
|
||||
* <td>htmlEscape</p></td>
|
||||
* <td>false</p></td>
|
||||
* <td>true</p></td>
|
||||
* <tr>
|
||||
* <td>htmlEscape</td>
|
||||
* <td>false</td>
|
||||
* <td>true</td>
|
||||
* <td>Set HTML escaping for this tag, as a boolean value. Overrides the
|
||||
* default HTML escaping setting for the current page.</p></td>
|
||||
* default HTML escaping setting for the current page.</td>
|
||||
* </tr>
|
||||
* <tr class="rowColor">
|
||||
* <td>javaScriptEscape</p></td>
|
||||
* <td>false</p></td>
|
||||
* <td>true</p></td>
|
||||
* <tr>
|
||||
* <td>javaScriptEscape</td>
|
||||
* <td>false</td>
|
||||
* <td>true</td>
|
||||
* <td>Set JavaScript escaping for this tag, as a boolean value.
|
||||
* Default is false.</p></td>
|
||||
* Default is false.</td>
|
||||
* </tr>
|
||||
* </tbody>
|
||||
* </table>
|
||||
@@ -166,7 +166,7 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
|
||||
|
||||
|
||||
/**
|
||||
* Sets the value of the URL
|
||||
* Sets the value of the URL.
|
||||
*/
|
||||
public void setValue(String value) {
|
||||
if (value.contains(URL_TYPE_ABSOLUTE)) {
|
||||
@@ -245,7 +245,7 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
|
||||
if (this.var == null) {
|
||||
// print the url to the writer
|
||||
try {
|
||||
pageContext.getOut().print(url);
|
||||
this.pageContext.getOut().print(url);
|
||||
}
|
||||
catch (IOException ex) {
|
||||
throw new JspException(ex);
|
||||
@@ -253,7 +253,7 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
|
||||
}
|
||||
else {
|
||||
// store the url as a variable
|
||||
pageContext.setAttribute(var, url, scope);
|
||||
this.pageContext.setAttribute(this.var, url, this.scope);
|
||||
}
|
||||
return EVAL_PAGE;
|
||||
}
|
||||
@@ -265,8 +265,8 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
|
||||
*/
|
||||
String createUrl() throws JspException {
|
||||
Assert.state(this.value != null, "No value set");
|
||||
HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
|
||||
HttpServletResponse response = (HttpServletResponse) pageContext.getResponse();
|
||||
HttpServletRequest request = (HttpServletRequest) this.pageContext.getRequest();
|
||||
HttpServletResponse response = (HttpServletResponse) this.pageContext.getResponse();
|
||||
|
||||
StringBuilder url = new StringBuilder();
|
||||
if (this.type == UrlType.CONTEXT_RELATIVE) {
|
||||
@@ -317,7 +317,7 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
|
||||
protected String createQueryString(List<Param> params, Set<String> usedParams, boolean includeQueryStringDelimiter)
|
||||
throws JspException {
|
||||
|
||||
String encoding = pageContext.getResponse().getCharacterEncoding();
|
||||
String encoding = this.pageContext.getResponse().getCharacterEncoding();
|
||||
StringBuilder qs = new StringBuilder();
|
||||
for (Param param : params) {
|
||||
if (!usedParams.contains(param.getName()) && StringUtils.hasLength(param.getName())) {
|
||||
@@ -354,14 +354,15 @@ public class UrlTag extends HtmlEscapingAwareTag implements ParamAware {
|
||||
protected String replaceUriTemplateParams(String uri, List<Param> params, Set<String> usedParams)
|
||||
throws JspException {
|
||||
|
||||
String encoding = pageContext.getResponse().getCharacterEncoding();
|
||||
String encoding = this.pageContext.getResponse().getCharacterEncoding();
|
||||
for (Param param : params) {
|
||||
String template = URL_TEMPLATE_DELIMITER_PREFIX + param.getName() + URL_TEMPLATE_DELIMITER_SUFFIX;
|
||||
if (uri.contains(template)) {
|
||||
usedParams.add(param.getName());
|
||||
String value = param.getValue();
|
||||
try {
|
||||
uri = uri.replace(template, (value != null ? UriUtils.encodePath(value, encoding) : ""));
|
||||
uri = uri.replace(template,
|
||||
(value != null ? UriUtils.encodePath(value, encoding) : ""));
|
||||
}
|
||||
catch (UnsupportedCharsetException ex) {
|
||||
throw new JspException(ex);
|
||||
|
||||
@@ -68,7 +68,7 @@ public class SockJsUrlInfo {
|
||||
|
||||
public String getSessionId() {
|
||||
if (this.sessionId == null) {
|
||||
this.sessionId = getUuid().toString().replace("-","");
|
||||
this.sessionId = getUuid().toString().replace("-", "");
|
||||
}
|
||||
return this.sessionId;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user