Polishing

This commit is contained in:
Juergen Hoeller 2015-08-27 22:04:58 +02:00
parent 0c2b787cb5
commit 491adf1f2f
4 changed files with 23 additions and 22 deletions

View File

@ -55,11 +55,11 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
private static final String METHOD_HEAD = "HEAD";
/** Checking for Servlet 3.0+ HttpServletResponse.getStatus() */
private static final boolean responseGetStatusAvailable =
ClassUtils.hasMethod(HttpServletResponse.class, "getStatus");
private boolean notModified = false;
@ -184,7 +184,7 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
if (this.notModified && supportsNotModifiedStatus()) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}
if(response.getHeader(HEADER_LAST_MODIFIED) == null) {
if (response.getHeader(HEADER_LAST_MODIFIED) == null) {
response.setDateHeader(HEADER_LAST_MODIFIED, lastModifiedTimestamp);
}
}
@ -193,12 +193,6 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
return this.notModified;
}
private boolean isCompatibleWithConditionalRequests(HttpServletResponse response) {
return response == null
|| !responseGetStatusAvailable
|| HttpStatus.valueOf(response.getStatus()).is2xxSuccessful();
}
@SuppressWarnings("deprecation")
private boolean isTimestampNotModified(long lastModifiedTimestamp) {
long ifModifiedSince = -1;
@ -233,7 +227,7 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
if (this.notModified && supportsNotModifiedStatus()) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}
if(response.getHeader(HEADER_ETAG) == null) {
if (response.getHeader(HEADER_ETAG) == null) {
response.setHeader(HEADER_ETAG, etag);
}
}
@ -242,6 +236,14 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
return this.notModified;
}
private boolean isCompatibleWithConditionalRequests(HttpServletResponse response) {
if (response == null || !responseGetStatusAvailable) {
// Can't check response.getStatus() - let's assume we're good
return true;
}
return HttpStatus.valueOf(response.getStatus()).is2xxSuccessful();
}
private String addEtagPadding(String etag) {
if (!(etag.startsWith("\"") || etag.startsWith("W/\"")) || !etag.endsWith("\"")) {
etag = "\"" + etag + "\"";
@ -283,10 +285,10 @@ public class ServletWebRequest extends ServletRequestAttributes implements Nativ
if (this.notModified && supportsNotModifiedStatus()) {
response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
}
if(response.getHeader(HEADER_ETAG) == null) {
if (response.getHeader(HEADER_ETAG) == null) {
response.setHeader(HEADER_ETAG, etag);
}
if(response.getHeader(HEADER_LAST_MODIFIED) == null) {
if (response.getHeader(HEADER_LAST_MODIFIED) == null) {
response.setDateHeader(HEADER_LAST_MODIFIED, lastModifiedTimestamp);
}
}

View File

@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 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.
@ -75,7 +75,7 @@ public class WebSphereRequestUpgradeStrategy extends AbstractStandardUpgradeStra
HttpServletResponse response = getHttpServletResponse(httpResponse);
StringBuffer requestUrl = request.getRequestURL();
String path = request.getRequestURI(); // shouldn't matter
String path = request.getRequestURI(); // shouldn't matter
Map<String, String> pathParams = Collections.<String, String> emptyMap();
ServerEndpointRegistration endpointConfig = new ServerEndpointRegistration(path, endpoint);
@ -88,7 +88,7 @@ public class WebSphereRequestUpgradeStrategy extends AbstractStandardUpgradeStra
}
catch (Exception ex) {
throw new HandshakeFailureException(
"Servlet request failed to upgrade to WebSocket, uri=" + requestUrl, ex);
"Servlet request failed to upgrade to WebSocket for " + requestUrl, ex);
}
}

View File

@ -76,13 +76,13 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
private static final boolean undertowWsPresent = ClassUtils.isPresent(
"io.undertow.websockets.jsr.ServerWebSocketContainer", classLoader);
private static final boolean glassFishWsPresent = ClassUtils.isPresent(
private static final boolean glassfishWsPresent = ClassUtils.isPresent(
"org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler", classLoader);
private static final boolean webLogicWsPresent = ClassUtils.isPresent(
private static final boolean weblogicWsPresent = ClassUtils.isPresent(
"weblogic.websocket.tyrus.TyrusServletWriter", classLoader);
private static final boolean webSphereWsPresent = ClassUtils.isPresent(
private static final boolean websphereWsPresent = ClassUtils.isPresent(
"com.ibm.websphere.wsoc.WsWsocServerContainer", classLoader);
@ -125,13 +125,13 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
else if (undertowWsPresent) {
className = "org.springframework.web.socket.server.standard.UndertowRequestUpgradeStrategy";
}
else if (glassFishWsPresent) {
else if (glassfishWsPresent) {
className = "org.springframework.web.socket.server.standard.GlassFishRequestUpgradeStrategy";
}
else if (webLogicWsPresent) {
else if (weblogicWsPresent) {
className = "org.springframework.web.socket.server.standard.WebLogicRequestUpgradeStrategy";
}
else if (webSphereWsPresent) {
else if (websphereWsPresent) {
className = "org.springframework.web.socket.server.standard.WebSphereRequestUpgradeStrategy";
}
else {
@ -368,7 +368,7 @@ public abstract class AbstractHandshakeHandler implements HandshakeHandler, Life
/**
* Filter the list of requested WebSocket extensions.
* <p>As of 4.1 the default implementation of this method filters the list to
* <p>As of 4.1, the default implementation of this method filters the list to
* leave only extensions that are both requested and supported.
* @param request the current request
* @param requestedExtensions the list of extensions requested by the client

View File

@ -38,7 +38,6 @@ import org.springframework.web.socket.server.RequestUpgradeStrategy;
*/
public class DefaultHandshakeHandler extends AbstractHandshakeHandler implements ServletContextAware {
public DefaultHandshakeHandler() {
}