Browse Source

Polishing

pull/618/head
Juergen Hoeller 12 years ago
parent
commit
31a251e44a
  1. 29
      spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java
  2. 11
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/AbstractSockJsMessageCodec.java
  3. 16
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsMessageCodec.java
  4. 8
      spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpReceivingTransportHandler.java

29
spring-jdbc/src/main/java/org/springframework/jdbc/support/SQLExceptionSubclassTranslator.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2012 the original author or authors. * Copyright 2002-2014 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.
@ -45,9 +45,8 @@ import org.springframework.jdbc.BadSqlGrammarException;
* {@link SQLExceptionTranslator} implementation which analyzes the specific * {@link SQLExceptionTranslator} implementation which analyzes the specific
* {@link java.sql.SQLException} subclass thrown by the JDBC driver. * {@link java.sql.SQLException} subclass thrown by the JDBC driver.
* *
* <p>This is only available with JDBC 4.0 and later drivers when using Java 6 or later. * <p>Falls back to a standard {@link SQLStateSQLExceptionTranslator} if the JDBC
* Falls back to a standard {@link SQLStateSQLExceptionTranslator} if the JDBC driver * driver does not actually expose JDBC 4 compliant {@code SQLException} subclasses.
* does not actually expose JDBC 4 compliant {@code SQLException} subclasses.
* *
* @author Thomas Risberg * @author Thomas Risberg
* @author Juergen Hoeller * @author Juergen Hoeller
@ -65,22 +64,22 @@ public class SQLExceptionSubclassTranslator extends AbstractFallbackSQLException
@Override @Override
protected DataAccessException doTranslate(String task, String sql, SQLException ex) { protected DataAccessException doTranslate(String task, String sql, SQLException ex) {
if (ex instanceof SQLTransientException) { if (ex instanceof SQLTransientException) {
if (ex instanceof SQLTransactionRollbackException) {
return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
}
if (ex instanceof SQLTransientConnectionException) { if (ex instanceof SQLTransientConnectionException) {
return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex); return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
} }
if (ex instanceof SQLTimeoutException) { else if (ex instanceof SQLTransactionRollbackException) {
return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
}
else if (ex instanceof SQLTimeoutException) {
return new QueryTimeoutException(buildMessage(task, sql, ex), ex); return new QueryTimeoutException(buildMessage(task, sql, ex), ex);
} }
} }
else if (ex instanceof SQLNonTransientException) { else if (ex instanceof SQLNonTransientException) {
if (ex instanceof SQLDataException) { if (ex instanceof SQLNonTransientConnectionException) {
return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
} }
else if (ex instanceof SQLFeatureNotSupportedException) { else if (ex instanceof SQLDataException) {
return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex); return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
} }
else if (ex instanceof SQLIntegrityConstraintViolationException) { else if (ex instanceof SQLIntegrityConstraintViolationException) {
return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex); return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
@ -88,12 +87,12 @@ public class SQLExceptionSubclassTranslator extends AbstractFallbackSQLException
else if (ex instanceof SQLInvalidAuthorizationSpecException) { else if (ex instanceof SQLInvalidAuthorizationSpecException) {
return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex); return new PermissionDeniedDataAccessException(buildMessage(task, sql, ex), ex);
} }
else if (ex instanceof SQLNonTransientConnectionException) {
return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
}
else if (ex instanceof SQLSyntaxErrorException) { else if (ex instanceof SQLSyntaxErrorException) {
return new BadSqlGrammarException(task, sql, ex); return new BadSqlGrammarException(task, sql, ex);
} }
else if (ex instanceof SQLFeatureNotSupportedException) {
return new InvalidDataAccessApiUsageException(buildMessage(task, sql, ex), ex);
}
} }
else if (ex instanceof SQLRecoverableException) { else if (ex instanceof SQLRecoverableException) {
return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex); return new RecoverableDataAccessException(buildMessage(task, sql, ex), ex);

11
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/AbstractSockJsMessageCodec.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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.
@ -27,9 +27,8 @@ import org.springframework.util.Assert;
*/ */
public abstract class AbstractSockJsMessageCodec implements SockJsMessageCodec { public abstract class AbstractSockJsMessageCodec implements SockJsMessageCodec {
@Override @Override
public String encode(String[] messages) { public String encode(String... messages) {
Assert.notNull(messages, "messages must not be null"); Assert.notNull(messages, "messages must not be null");
StringBuilder sb = new StringBuilder(); StringBuilder sb = new StringBuilder();
sb.append("a["); sb.append("a[");
@ -76,9 +75,9 @@ public abstract class AbstractSockJsMessageCodec implements SockJsMessageCodec {
* See `escapable_by_server` variable in the SockJS protocol test suite. * See `escapable_by_server` variable in the SockJS protocol test suite.
*/ */
private boolean isSockJsSpecialChar(char ch) { private boolean isSockJsSpecialChar(char ch) {
return (ch >= '\u0000' && ch <= '\u001F') || (ch >= '\u200C' && ch <= '\u200F') return (ch >= '\u0000' && ch <= '\u001F') || (ch >= '\u200C' && ch <= '\u200F') ||
|| (ch >= '\u2028' && ch <= '\u202F') || (ch >= '\u2060' && ch <= '\u206F') (ch >= '\u2028' && ch <= '\u202F') || (ch >= '\u2060' && ch <= '\u206F') ||
|| (ch >= '\uFFF0' && ch <= '\uFFFF') || (ch >= '\uD800' && ch <= '\uDFFF'); (ch >= '\uFFF0' && ch <= '\uFFFF') || (ch >= '\uD800' && ch <= '\uDFFF');
} }
} }

16
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/frame/SockJsMessageCodec.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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.
@ -20,10 +20,10 @@ import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
/** /**
* Encode and decode messages to and from a SockJS message frame, essentially an array of * Encode and decode messages to and from a SockJS message frame,
* JSON-encoded messages. For example: * essentially an array of JSON-encoded messages. For example:
* *
* <pre> * <pre class="code">
* a["message1","message2"] * a["message1","message2"]
* </pre> * </pre>
* *
@ -38,14 +38,14 @@ public interface SockJsMessageCodec {
* rules. See the "JSON Unicode Encoding" section of SockJS protocol (i.e. the * rules. See the "JSON Unicode Encoding" section of SockJS protocol (i.e. the
* protocol test suite). * protocol test suite).
* @param messages the messages to encode * @param messages the messages to encode
* @return the content for a SockJS message frame, never {@code null} * @return the content for a SockJS message frame (never {@code null})
*/ */
String encode(String[] messages); String encode(String... messages);
/** /**
* Decode the given SockJS message frame. * Decode the given SockJS message frame.
* @param content the SockJS message frame * @param content the SockJS message frame
* @return an array of messages or {@code null} * @return an array of messages, or {@code null} if none
* @throws IOException if the content could not be parsed * @throws IOException if the content could not be parsed
*/ */
String[] decode(String content) throws IOException; String[] decode(String content) throws IOException;
@ -53,7 +53,7 @@ public interface SockJsMessageCodec {
/** /**
* Decode the given SockJS message frame. * Decode the given SockJS message frame.
* @param content the SockJS message frame * @param content the SockJS message frame
* @return an array of messages or {@code null} * @return an array of messages, or {@code null} if none
* @throws IOException if the content could not be parsed * @throws IOException if the content could not be parsed
*/ */
String[] decodeInputStream(InputStream content) throws IOException; String[] decodeInputStream(InputStream content) throws IOException;

8
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/handler/JsonpReceivingTransportHandler.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2013 the original author or authors. * Copyright 2002-2014 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.
@ -55,7 +55,7 @@ public class JsonpReceivingTransportHandler extends AbstractHttpReceivingTranspo
try { try {
response.getBody().write("ok".getBytes("UTF-8")); response.getBody().write("ok".getBytes("UTF-8"));
} }
catch(IOException ex) { catch (IOException ex) {
throw new SockJsException("Failed to write to the response body", sockJsSession.getId(), ex); throw new SockJsException("Failed to write to the response body", sockJsSession.getId(), ex);
} }
} }
@ -64,10 +64,10 @@ public class JsonpReceivingTransportHandler extends AbstractHttpReceivingTranspo
protected String[] readMessages(ServerHttpRequest request) throws IOException { protected String[] readMessages(ServerHttpRequest request) throws IOException {
SockJsMessageCodec messageCodec = getServiceConfig().getMessageCodec(); SockJsMessageCodec messageCodec = getServiceConfig().getMessageCodec();
MediaType contentType = request.getHeaders().getContentType(); MediaType contentType = request.getHeaders().getContentType();
if ((contentType != null) && MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) { if (contentType != null && MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) {
MultiValueMap<String, String> map = this.formConverter.read(null, request); MultiValueMap<String, String> map = this.formConverter.read(null, request);
String d = map.getFirst("d"); String d = map.getFirst("d");
return (StringUtils.hasText(d)) ? messageCodec.decode(d) : null; return (StringUtils.hasText(d) ? messageCodec.decode(d) : null);
} }
else { else {
return messageCodec.decodeInputStream(request.getBody()); return messageCodec.decodeInputStream(request.getBody());

Loading…
Cancel
Save