Browse Source

Polishing

(cherry picked from commit b559f15)
pull/618/head
Juergen Hoeller 12 years ago
parent
commit
d72ee809b7
  1. 16
      spring-expression/src/main/java/org/springframework/expression/TypedValue.java
  2. 67
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java

16
spring-expression/src/main/java/org/springframework/expression/TypedValue.java

@ -20,9 +20,9 @@ import org.springframework.core.convert.TypeDescriptor;
import org.springframework.util.ObjectUtils; import org.springframework.util.ObjectUtils;
/** /**
* Encapsulates an object and a type descriptor that describes it. * Encapsulates an object and a {@link TypeDescriptor} that describes it.
* The type descriptor can hold generic information that would not be * The type descriptor can contain generic declarations that would not
* accessible through a simple {@code getClass()} call on the object. * be accessible through a simple {@code getClass()} call on the object.
* *
* @author Andy Clement * @author Andy Clement
* @author Juergen Hoeller * @author Juergen Hoeller
@ -39,8 +39,8 @@ public class TypedValue {
/** /**
* Create a TypedValue for a simple object. The type descriptor is inferred * Create a {@link TypedValue} for a simple object. The {@link TypeDescriptor}
* from the object, so no generic information is preserved. * is inferred from the object, so no generic declarations are preserved.
* @param value the object value * @param value the object value
*/ */
public TypedValue(Object value) { public TypedValue(Object value) {
@ -49,7 +49,8 @@ public class TypedValue {
} }
/** /**
* Create a TypedValue for a particular value with a particular type descriptor. * Create a {@link TypedValue} for a particular value with a particular
* {@link TypeDescriptor} which may contain additional generic declarations.
* @param value the object value * @param value the object value
* @param typeDescriptor a type descriptor describing the type of the value * @param typeDescriptor a type descriptor describing the type of the value
*/ */
@ -80,9 +81,10 @@ public class TypedValue {
return false; return false;
} }
TypedValue otherTv = (TypedValue) other; TypedValue otherTv = (TypedValue) other;
// Avoid TypeDescriptor initialization if not necessary
return (ObjectUtils.nullSafeEquals(this.value, otherTv.value) && return (ObjectUtils.nullSafeEquals(this.value, otherTv.value) &&
((this.typeDescriptor == null && otherTv.typeDescriptor == null) || ((this.typeDescriptor == null && otherTv.typeDescriptor == null) ||
getTypeDescriptor().equals(otherTv.getTypeDescriptor()))); ObjectUtils.nullSafeEquals(getTypeDescriptor(), otherTv.getTypeDescriptor())));
} }
@Override @Override

67
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/support/AbstractSockJsService.java

@ -90,12 +90,22 @@ public abstract class AbstractSockJsService implements SockJsService {
/** /**
* A unique name for the service mainly for logging purposes. * A scheduler instance to use for scheduling heart-beat messages.
*/
public TaskScheduler getTaskScheduler() {
return this.taskScheduler;
}
/**
* Set a unique name for this service (mainly for logging purposes).
*/ */
public void setName(String name) { public void setName(String name) {
this.name = name; this.name = name;
} }
/**
* Return the unique name associated with this service.
*/
public String getName() { public String getName() {
return this.name; return this.name;
} }
@ -121,8 +131,7 @@ public abstract class AbstractSockJsService implements SockJsService {
} }
/** /**
* The URL to the SockJS JavaScript client library. * Return he URL to the SockJS JavaScript client library.
* @see #setSockJsClientLibraryUrl(String)
*/ */
public String getSockJsClientLibraryUrl() { public String getSockJsClientLibraryUrl() {
return this.clientLibraryUrl; return this.clientLibraryUrl;
@ -132,7 +141,7 @@ public abstract class AbstractSockJsService implements SockJsService {
* Streaming transports save responses on the client side and don't free * Streaming transports save responses on the client side and don't free
* memory used by delivered messages. Such transports need to recycle the * memory used by delivered messages. Such transports need to recycle the
* connection once in a while. This property sets a minimum number of bytes * connection once in a while. This property sets a minimum number of bytes
* that can be send over a single HTTP streaming request before it will be * that can be sent over a single HTTP streaming request before it will be
* closed. After that client will open a new request. Setting this value to * closed. After that client will open a new request. Setting this value to
* one effectively disables streaming and will make streaming transports to * one effectively disables streaming and will make streaming transports to
* behave like polling transports. * behave like polling transports.
@ -142,6 +151,10 @@ public abstract class AbstractSockJsService implements SockJsService {
this.streamBytesLimit = streamBytesLimit; this.streamBytesLimit = streamBytesLimit;
} }
/**
* Return the minimum number of bytes that can be sent over a single HTTP
* streaming request before it will be closed.
*/
public int getStreamBytesLimit() { public int getStreamBytesLimit() {
return this.streamBytesLimit; return this.streamBytesLimit;
} }
@ -168,32 +181,28 @@ public abstract class AbstractSockJsService implements SockJsService {
} }
/** /**
* Whether JSESSIONID cookie is required for the application to function. For * Return whether the JSESSIONID cookie is required for the application to function.
* more detail see {@link #setSessionCookieNeeded(boolean)}.
*/ */
public boolean isSessionCookieNeeded() { public boolean isSessionCookieNeeded() {
return this.sessionCookieNeeded; return this.sessionCookieNeeded;
} }
/** /**
* The amount of time in milliseconds when the server has not sent any * Specify the amount of time in milliseconds when the server has not sent
* messages and after which the server should send a heartbeat frame to the * any messages and after which the server should send a heartbeat frame
* client in order to keep the connection from breaking. * to the client in order to keep the connection from breaking.
* <p>The default value is 25,000 (25 seconds). * <p>The default value is 25,000 (25 seconds).
*/ */
public void setHeartbeatTime(long heartbeatTime) { public void setHeartbeatTime(long heartbeatTime) {
this.heartbeatTime = heartbeatTime; this.heartbeatTime = heartbeatTime;
} }
public long getHeartbeatTime() {
return this.heartbeatTime;
}
/** /**
* A scheduler instance to use for scheduling heart-beat messages. * Return the amount of time in milliseconds when the server has not sent
* any messages.
*/ */
public TaskScheduler getTaskScheduler() { public long getHeartbeatTime() {
return this.taskScheduler; return this.heartbeatTime;
} }
/** /**
@ -214,12 +223,12 @@ public abstract class AbstractSockJsService implements SockJsService {
} }
/** /**
* The number of server-to-client messages that a session can cache while waiting for * The number of server-to-client messages that a session can cache while waiting
* the next HTTP polling request from the client. All HTTP transports use this * for the next HTTP polling request from the client. All HTTP transports use this
* property since even streaming transports recycle HTTP requests periodically. * property since even streaming transports recycle HTTP requests periodically.
* <p>The amount of time between HTTP requests should be relatively brief and will not * <p>The amount of time between HTTP requests should be relatively brief and will
* exceed the allows disconnect delay (see * not exceed the allows disconnect delay (see {@link #setDisconnectDelay(long)});
* {@link #setDisconnectDelay(long)}), 5 seconds by default. * 5 seconds by default.
* <p>The default size is 100. * <p>The default size is 100.
*/ */
public void setHttpMessageCacheSize(int httpMessageCacheSize) { public void setHttpMessageCacheSize(int httpMessageCacheSize) {
@ -234,7 +243,7 @@ public abstract class AbstractSockJsService implements SockJsService {
} }
/** /**
* Some load balancers don't support WebSocket. This option can be used to * Some load balancers do not support WebSocket. This option can be used to
* disable the WebSocket transport on the server side. * disable the WebSocket transport on the server side.
* <p>The default value is "true". * <p>The default value is "true".
*/ */
@ -243,8 +252,7 @@ public abstract class AbstractSockJsService implements SockJsService {
} }
/** /**
* Whether WebSocket transport is enabled. * Return whether WebSocket transport is enabled.
* @see #setWebSocketEnabled(boolean)
*/ */
public boolean isWebSocketEnabled() { public boolean isWebSocketEnabled() {
return this.webSocketEnabled; return this.webSocketEnabled;
@ -252,9 +260,8 @@ public abstract class AbstractSockJsService implements SockJsService {
/** /**
* {@inheritDoc} * This method determines the SockJS path and handles SockJS static URLs.
* <p>This method determines the SockJS path and handles SockJS static URLs. Session * Session URLs and raw WebSocket requests are delegated to abstract methods.
* URLs and raw WebSocket requests are delegated to abstract methods.
*/ */
@Override @Override
public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response, public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response,
@ -271,7 +278,6 @@ public abstract class AbstractSockJsService implements SockJsService {
if (logger.isDebugEnabled()) { if (logger.isDebugEnabled()) {
logger.debug(request.getMethod() + " with SockJS path [" + sockJsPath + "]"); logger.debug(request.getMethod() + " with SockJS path [" + sockJsPath + "]");
} }
try { try {
request.getHeaders(); request.getHeaders();
} }
@ -309,7 +315,6 @@ public abstract class AbstractSockJsService implements SockJsService {
String serverId = pathSegments[0]; String serverId = pathSegments[0];
String sessionId = pathSegments[1]; String sessionId = pathSegments[1];
String transport = pathSegments[2]; String transport = pathSegments[2];
if (!validateRequest(serverId, sessionId, transport)) { if (!validateRequest(serverId, sessionId, transport)) {
response.setStatusCode(HttpStatus.NOT_FOUND); response.setStatusCode(HttpStatus.NOT_FOUND);
return; return;
@ -360,7 +365,6 @@ public abstract class AbstractSockJsService implements SockJsService {
protected void addCorsHeaders(ServerHttpRequest request, ServerHttpResponse response, HttpMethod... httpMethods) { protected void addCorsHeaders(ServerHttpRequest request, ServerHttpResponse response, HttpMethod... httpMethods) {
HttpHeaders requestHeaders = request.getHeaders(); HttpHeaders requestHeaders = request.getHeaders();
HttpHeaders responseHeaders = response.getHeaders(); HttpHeaders responseHeaders = response.getHeaders();
try { try {
// Perhaps a CORS Filter has already added this? // Perhaps a CORS Filter has already added this?
if (!CollectionUtils.isEmpty(responseHeaders.get("Access-Control-Allow-Origin"))) { if (!CollectionUtils.isEmpty(responseHeaders.get("Access-Control-Allow-Origin"))) {
@ -373,8 +377,7 @@ public abstract class AbstractSockJsService implements SockJsService {
} }
String origin = requestHeaders.getFirst("origin"); String origin = requestHeaders.getFirst("origin");
origin = ((origin == null) || origin.equals("null")) ? "*" : origin; origin = (origin == null || origin.equals("null") ? "*" : origin);
responseHeaders.add("Access-Control-Allow-Origin", origin); responseHeaders.add("Access-Control-Allow-Origin", origin);
responseHeaders.add("Access-Control-Allow-Credentials", "true"); responseHeaders.add("Access-Control-Allow-Credentials", "true");

Loading…
Cancel
Save