language
stringclasses
1 value
owner
stringlengths
2
15
repo
stringlengths
2
21
sha
stringlengths
45
45
message
stringlengths
7
36.3k
path
stringlengths
1
199
patch
stringlengths
15
102k
is_multipart
bool
2 classes
Other
spring-projects
spring-framework
486b4101ec6675a53c1595350878a10857518331.json
Introduce MessageHeader accessor types A new type MessageHeaderAccesssor provides read/write access to MessageHeaders along with typed getter/setter methods along the lines of the existing MessageBuilder methods (internally MessageBuilder merely delegates to MessageHeaderAccessor). This class is extensible with sub-classes expected to provide typed getter/setter methods for specific categories of message headers. NativeMessageHeaderAccessor is one specific sub-class that further provides read/write access to headers from some external message source (e.g. STOMP headers). Native headers are stored in a separate MultiValueMap and kept under a specific key.
spring-websocket/src/main/java/org/springframework/web/messaging/service/method/MessageReturnValueHandler.java
@@ -21,7 +21,7 @@ import org.springframework.messaging.MessageChannel; import org.springframework.messaging.support.MessageBuilder; import org.springframework.util.Assert; -import org.springframework.web.messaging.support.PubSubHeaderAccesssor; +import org.springframework.web.messaging.support.WebMessageHeaderAccesssor; /** @@ -66,10 +66,10 @@ public void handleReturnValue(Object returnValue, MethodParameter returnType, Me return; } - PubSubHeaderAccesssor headers = PubSubHeaderAccesssor.wrap(message); + WebMessageHeaderAccesssor headers = WebMessageHeaderAccesssor.wrap(message); Assert.notNull(headers.getSubscriptionId(), "No subscription id: " + message); - PubSubHeaderAccesssor returnHeaders = PubSubHeaderAccesssor.wrap(returnMessage); + WebMessageHeaderAccesssor returnHeaders = WebMessageHeaderAccesssor.wrap(returnMessage); returnHeaders.setSessionId(headers.getSessionId()); returnHeaders.setSubscriptionId(headers.getSubscriptionId()); @@ -78,7 +78,7 @@ public void handleReturnValue(Object returnValue, MethodParameter returnType, Me } returnMessage = MessageBuilder.withPayload( - returnMessage.getPayload()).copyHeaders(returnHeaders.toHeaders()).build(); + returnMessage.getPayload()).copyHeaders(returnHeaders.toMap()).build(); this.clientChannel.send(returnMessage); }
true
Other
spring-projects
spring-framework
486b4101ec6675a53c1595350878a10857518331.json
Introduce MessageHeader accessor types A new type MessageHeaderAccesssor provides read/write access to MessageHeaders along with typed getter/setter methods along the lines of the existing MessageBuilder methods (internally MessageBuilder merely delegates to MessageHeaderAccessor). This class is extensible with sub-classes expected to provide typed getter/setter methods for specific categories of message headers. NativeMessageHeaderAccessor is one specific sub-class that further provides read/write access to headers from some external message source (e.g. STOMP headers). Native headers are stored in a separate MultiValueMap and kept under a specific key.
spring-websocket/src/main/java/org/springframework/web/messaging/stomp/support/StompHeaderAccessor.java
@@ -16,8 +16,8 @@ package org.springframework.web.messaging.stomp.support; +import java.util.Arrays; import java.util.Collections; -import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; @@ -26,26 +26,23 @@ import org.springframework.http.MediaType; import org.springframework.messaging.Message; import org.springframework.util.Assert; -import org.springframework.util.CollectionUtils; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.util.MultiValueMap; import org.springframework.util.StringUtils; import org.springframework.web.messaging.stomp.StompCommand; -import org.springframework.web.messaging.support.PubSubHeaderAccesssor; +import org.springframework.web.messaging.support.WebMessageHeaderAccesssor; /** * Can be used to prepare headers for a new STOMP message, or to access and/or modify * STOMP-specific headers of an existing message. * <p> * Use one of the static factory method in this class, then call getters and setters, and - * at the end if necessary call {@link #toHeaders()} to obtain the updated headers - * or call {@link #toStompMessageHeaders()} to obtain only the STOMP-specific headers. + * at the end if necessary call {@link #toMap()} to obtain the updated headers + * or call {@link #toNativeHeaderMap()} to obtain only the STOMP-specific headers. * * @author Rossen Stoyanchev * @since 4.0 */ -public class StompHeaderAccessor extends PubSubHeaderAccesssor { +public class StompHeaderAccessor extends WebMessageHeaderAccesssor { public static final String STOMP_ID = "id"; @@ -80,55 +77,40 @@ public class StompHeaderAccessor extends PubSubHeaderAccesssor { public static final String HEARTBEAT = "heart-beat"; - private static final String STOMP_HEADERS = "stompHeaders"; - private static final AtomicLong messageIdCounter = new AtomicLong(); - private final Map<String, String> headers; - - /** * A constructor for creating new STOMP message headers. - * This constructor is private. See factory methods in this sub-classes. */ private StompHeaderAccessor(StompCommand command, Map<String, List<String>> externalSourceHeaders) { super(command.getMessageType(), command, externalSourceHeaders); - this.headers = new HashMap<String, String>(4); - updateMessageHeaders(); + initWebMessageHeaders(); } - private void updateMessageHeaders() { - if (getExternalSourceHeaders().isEmpty()) { - return; - } - String destination = getHeaderValue(DESTINATION); + private void initWebMessageHeaders() { + String destination = getFirstNativeHeader(DESTINATION); if (destination != null) { super.setDestination(destination); } - String contentType = getHeaderValue(CONTENT_TYPE); + String contentType = getFirstNativeHeader(CONTENT_TYPE); if (contentType != null) { super.setContentType(MediaType.parseMediaType(contentType)); } if (StompCommand.SUBSCRIBE.equals(getStompCommand())) { - if (getHeaderValue(STOMP_ID) != null) { - super.setSubscriptionId(getHeaderValue(STOMP_ID)); + if (getFirstNativeHeader(STOMP_ID) != null) { + super.setSubscriptionId(getFirstNativeHeader(STOMP_ID)); } } } /** - * A constructor for accessing and modifying existing message headers. This - * constructor is protected. See factory methods in this class. + * A constructor for accessing and modifying existing message headers. */ - @SuppressWarnings("unchecked") private StompHeaderAccessor(Message<?> message) { super(message); - this.headers = (message.getHeaders() .get(STOMP_HEADERS) != null) ? - (Map<String, String>) message.getHeaders().get(STOMP_HEADERS) : new HashMap<String, String>(4); } - /** * Create {@link StompHeaderAccessor} for a new {@link Message}. */ @@ -152,53 +134,35 @@ public static StompHeaderAccessor wrap(Message<?> message) { /** - * Return the original, wrapped headers (i.e. unmodified) or a new Map including any - * updates made via setters. + * Return STOMP headers including original, wrapped STOMP headers (if any) plus + * additional header updates made through accessor methods. */ @Override - public Map<String, Object> toHeaders() { - Map<String, Object> result = super.toHeaders(); - if (isModified()) { - result.put(STOMP_HEADERS, this.headers); - } - return result; - } + public Map<String, List<String>> toNativeHeaderMap() { - @Override - public boolean isModified() { - return (super.isModified() || !this.headers.isEmpty()); - } - - /** - * Return STOMP headers and any custom headers that may have been sent by - * a remote endpoint, if this message originated from outside. - */ - public Map<String, List<String>> toStompMessageHeaders() { - - MultiValueMap<String, String> result = new LinkedMultiValueMap<String, String>(); - result.putAll(getExternalSourceHeaders()); - result.setAll(this.headers); + Map<String, List<String>> result = super.toNativeHeaderMap(); String destination = super.getDestination(); if (destination != null) { - result.set(DESTINATION, destination); + result.put(DESTINATION, Arrays.asList(destination)); } MediaType contentType = getContentType(); if (contentType != null) { - result.set(CONTENT_TYPE, contentType.toString()); + result.put(CONTENT_TYPE, Arrays.asList(contentType.toString())); } if (StompCommand.MESSAGE.equals(getStompCommand())) { String subscriptionId = getSubscriptionId(); if (subscriptionId != null) { - result.set(SUBSCRIPTION, subscriptionId); + result.put(SUBSCRIPTION, Arrays.asList(subscriptionId)); } else { logger.warn("STOMP MESSAGE frame should have a subscription: " + this.toString()); } if ((getMessageId() == null)) { - result.set(MESSAGE_ID, getSessionId() + "-" + messageIdCounter.getAndIncrement()); + String messageId = getSessionId() + "-" + messageIdCounter.getAndIncrement(); + result.put(MESSAGE_ID, Arrays.asList(messageId)); } } @@ -216,42 +180,37 @@ public StompCommand getStompCommand() { } public Set<String> getAcceptVersion() { - String rawValue = getHeaderValue(ACCEPT_VERSION); + String rawValue = getFirstNativeHeader(ACCEPT_VERSION); return (rawValue != null) ? StringUtils.commaDelimitedListToSet(rawValue) : Collections.<String>emptySet(); } - private String getHeaderValue(String headerName) { - List<String> values = getExternalSourceHeaders().get(headerName); - return !CollectionUtils.isEmpty(values) ? values.get(0) : this.headers.get(headerName); - } - public void setAcceptVersion(String acceptVersion) { - this.headers.put(ACCEPT_VERSION, acceptVersion); + setNativeHeader(ACCEPT_VERSION, acceptVersion); } public void setHost(String host) { - this.headers.put(HOST, host); + setNativeHeader(HOST, host); } public String getHost() { - return getHeaderValue(HOST); + return getFirstNativeHeader(HOST); } @Override public void setDestination(String destination) { super.setDestination(destination); - this.headers.put(DESTINATION, destination); + setNativeHeader(DESTINATION, destination); } @Override public void setDestinations(List<String> destinations) { Assert.isTrue((destinations != null) && (destinations.size() == 1), "STOMP allows one destination per message"); super.setDestinations(destinations); - this.headers.put(DESTINATION, destinations.get(0)); + setNativeHeader(DESTINATION, destinations.get(0)); } public long[] getHeartbeat() { - String rawValue = getHeaderValue(HEARTBEAT); + String rawValue = getFirstNativeHeader(HEARTBEAT); if (!StringUtils.hasText(rawValue)) { return null; } @@ -263,99 +222,91 @@ public long[] getHeartbeat() { public void setContentType(MediaType mediaType) { if (mediaType != null) { super.setContentType(mediaType); - this.headers.put(CONTENT_TYPE, mediaType.toString()); + setNativeHeader(CONTENT_TYPE, mediaType.toString()); } } public MediaType getContentType() { - String value = getHeaderValue(CONTENT_TYPE); + String value = getFirstNativeHeader(CONTENT_TYPE); return (value != null) ? MediaType.parseMediaType(value) : null; } public Integer getContentLength() { - String contentLength = getHeaderValue(CONTENT_LENGTH); + String contentLength = getFirstNativeHeader(CONTENT_LENGTH); return StringUtils.hasText(contentLength) ? new Integer(contentLength) : null; } public void setContentLength(int contentLength) { - this.headers.put(CONTENT_LENGTH, String.valueOf(contentLength)); + setNativeHeader(CONTENT_LENGTH, String.valueOf(contentLength)); } public void setHeartbeat(long cx, long cy) { - this.headers.put(HEARTBEAT, StringUtils.arrayToCommaDelimitedString(new Object[] {cx, cy})); + setNativeHeader(HEARTBEAT, StringUtils.arrayToCommaDelimitedString(new Object[] {cx, cy})); } public void setAck(String ack) { - this.headers.put(ACK, ack); + setNativeHeader(ACK, ack); } public String getAck() { - return getHeaderValue(ACK); + return getFirstNativeHeader(ACK); } public void setNack(String nack) { - this.headers.put(NACK, nack); + setNativeHeader(NACK, nack); } public String getNack() { - return getHeaderValue(NACK); + return getFirstNativeHeader(NACK); } public void setLogin(String login) { - this.headers.put(LOGIN, login); + setNativeHeader(LOGIN, login); } public String getLogin() { - return getHeaderValue(LOGIN); + return getFirstNativeHeader(LOGIN); } public void setPasscode(String passcode) { - this.headers.put(PASSCODE, passcode); + setNativeHeader(PASSCODE, passcode); } public String getPasscode() { - return getHeaderValue(PASSCODE); + return getFirstNativeHeader(PASSCODE); } public void setReceiptId(String receiptId) { - this.headers.put(RECEIPT_ID, receiptId); + setNativeHeader(RECEIPT_ID, receiptId); } public String getReceiptId() { - return getHeaderValue(RECEIPT_ID); + return getFirstNativeHeader(RECEIPT_ID); } public String getMessage() { - return getHeaderValue(MESSAGE); + return getFirstNativeHeader(MESSAGE); } public void setMessage(String content) { - this.headers.put(MESSAGE, content); + setNativeHeader(MESSAGE, content); } public String getMessageId() { - return getHeaderValue(MESSAGE_ID); + return getFirstNativeHeader(MESSAGE_ID); } public void setMessageId(String id) { - this.headers.put(MESSAGE_ID, id); + setNativeHeader(MESSAGE_ID, id); } public String getVersion() { - return getHeaderValue(VERSION); + return getFirstNativeHeader(VERSION); } public void setVersion(String version) { - this.headers.put(VERSION, version); - } - - @Override - public String toString() { - return "StompHeaders [" + "messageType=" + getMessageType() + ", protocolMessageType=" - + getProtocolMessageType() + ", destination=" + getDestination() - + ", subscriptionId=" + getSubscriptionId() + ", sessionId=" + getSessionId() - + ", externalSourceHeaders=" + getExternalSourceHeaders() + ", headers=" + this.headers + "]"; + setNativeHeader(VERSION, version); } }
true
Other
spring-projects
spring-framework
486b4101ec6675a53c1595350878a10857518331.json
Introduce MessageHeader accessor types A new type MessageHeaderAccesssor provides read/write access to MessageHeaders along with typed getter/setter methods along the lines of the existing MessageBuilder methods (internally MessageBuilder merely delegates to MessageHeaderAccessor). This class is extensible with sub-classes expected to provide typed getter/setter methods for specific categories of message headers. NativeMessageHeaderAccessor is one specific sub-class that further provides read/write access to headers from some external message source (e.g. STOMP headers). Native headers are stored in a separate MultiValueMap and kept under a specific key.
spring-websocket/src/main/java/org/springframework/web/messaging/stomp/support/StompMessageConverter.java
@@ -99,7 +99,7 @@ else if (stompContent instanceof byte[]){ byte[] payload = new byte[totalLength - payloadIndex]; System.arraycopy(byteContent, payloadIndex, payload, 0, totalLength - payloadIndex); - return MessageBuilder.withPayload(payload).copyHeaders(stompHeaders.toHeaders()).build(); + return MessageBuilder.withPayload(payload).copyHeaders(stompHeaders.toMap()).build(); } private int findIndexOfPayload(byte[] bytes) { @@ -146,7 +146,7 @@ public byte[] fromMessage(Message<?> message) { try { out.write(stompHeaders.getStompCommand().toString().getBytes("UTF-8")); out.write(LF); - for (Entry<String, List<String>> entry : stompHeaders.toStompMessageHeaders().entrySet()) { + for (Entry<String, List<String>> entry : stompHeaders.toNativeHeaderMap().entrySet()) { String key = entry.getKey(); key = replaceAllOutbound(key); for (String value : entry.getValue()) {
true
Other
spring-projects
spring-framework
486b4101ec6675a53c1595350878a10857518331.json
Introduce MessageHeader accessor types A new type MessageHeaderAccesssor provides read/write access to MessageHeaders along with typed getter/setter methods along the lines of the existing MessageBuilder methods (internally MessageBuilder merely delegates to MessageHeaderAccessor). This class is extensible with sub-classes expected to provide typed getter/setter methods for specific categories of message headers. NativeMessageHeaderAccessor is one specific sub-class that further provides read/write access to headers from some external message source (e.g. STOMP headers). Native headers are stored in a separate MultiValueMap and kept under a specific key.
spring-websocket/src/main/java/org/springframework/web/messaging/stomp/support/StompRelayPubSubMessageHandler.java
@@ -39,7 +39,7 @@ import org.springframework.web.messaging.converter.MessageConverter; import org.springframework.web.messaging.service.AbstractPubSubMessageHandler; import org.springframework.web.messaging.stomp.StompCommand; -import org.springframework.web.messaging.support.PubSubHeaderAccesssor; +import org.springframework.web.messaging.support.WebMessageHeaderAccesssor; import reactor.core.Environment; import reactor.core.Promise; @@ -120,7 +120,7 @@ public void start() { this.tcpClient = new TcpClient.Spec<String, String>(NettyTcpClient.class) .using(new Environment()) .codec(new DelimitedCodec<String, String>((byte) 0, true, StandardCodecs.STRING_CODEC)) - .connect("127.0.0.1", 61613) + .connect("127.0.0.1", 61616) .get(); StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.CONNECT); @@ -129,7 +129,7 @@ public void start() { headers.setPasscode("guest"); headers.setHeartbeat(0, 0); Message<?> message = MessageBuilder.withPayload( - new byte[0]).copyHeaders(headers.toStompMessageHeaders()).build(); + new byte[0]).copyHeaders(headers.toNativeHeaderMap()).build(); RelaySession session = new RelaySession(message, headers) { @Override @@ -206,7 +206,7 @@ public void handleDisconnect(Message<?> message) { @Override public void handleOther(Message<?> message) { - StompCommand command = (StompCommand) message.getHeaders().get(PubSubHeaderAccesssor.PROTOCOL_MESSAGE_TYPE); + StompCommand command = (StompCommand) message.getHeaders().get(WebMessageHeaderAccesssor.PROTOCOL_MESSAGE_TYPE); Assert.notNull(command, "Expected STOMP command: " + message.getHeaders()); forwardMessage(message, command); } @@ -326,7 +326,7 @@ private void sendError(String sessionId, String errorText) { StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.ERROR); headers.setSessionId(sessionId); headers.setMessage(errorText); - Message<?> errorMessage = MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toHeaders()).build(); + Message<?> errorMessage = MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toMap()).build(); sendMessageToClient(errorMessage); } @@ -372,7 +372,7 @@ private boolean forwardInternal(Message<?> message, StompHeaderAccessor headers, MediaType contentType = headers.getContentType(); byte[] payload = payloadConverter.convertToPayload(message.getPayload(), contentType); - Message<?> byteMessage = MessageBuilder.withPayload(payload).copyHeaders(headers.toHeaders()).build(); + Message<?> byteMessage = MessageBuilder.withPayload(payload).copyHeaders(headers.toMap()).build(); if (logger.isTraceEnabled()) { logger.trace("Forwarding message " + byteMessage);
true
Other
spring-projects
spring-framework
486b4101ec6675a53c1595350878a10857518331.json
Introduce MessageHeader accessor types A new type MessageHeaderAccesssor provides read/write access to MessageHeaders along with typed getter/setter methods along the lines of the existing MessageBuilder methods (internally MessageBuilder merely delegates to MessageHeaderAccessor). This class is extensible with sub-classes expected to provide typed getter/setter methods for specific categories of message headers. NativeMessageHeaderAccessor is one specific sub-class that further provides read/write access to headers from some external message source (e.g. STOMP headers). Native headers are stored in a separate MultiValueMap and kept under a specific key.
spring-websocket/src/main/java/org/springframework/web/messaging/stomp/support/StompWebSocketHandler.java
@@ -38,7 +38,7 @@ import org.springframework.web.messaging.converter.MessageConverter; import org.springframework.web.messaging.stomp.StompCommand; import org.springframework.web.messaging.stomp.StompConversionException; -import org.springframework.web.messaging.support.PubSubHeaderAccesssor; +import org.springframework.web.messaging.support.WebMessageHeaderAccesssor; import org.springframework.web.socket.CloseStatus; import org.springframework.web.socket.TextMessage; import org.springframework.web.socket.WebSocketSession; @@ -159,7 +159,7 @@ else if (acceptVersions.isEmpty()) { // TODO: security Message<?> connectedMessage = MessageBuilder.withPayload(EMPTY_PAYLOAD).copyHeaders( - connectedHeaders.toHeaders()).build(); + connectedHeaders.toMap()).build(); byte[] bytes = getStompMessageConverter().fromMessage(connectedMessage); session.sendMessage(new TextMessage(new String(bytes, Charset.forName("UTF-8")))); } @@ -195,7 +195,7 @@ protected void sendErrorMessage(WebSocketSession session, Throwable error) { StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.ERROR); headers.setMessage(error.getMessage()); - Message<?> message = MessageBuilder.withPayload(EMPTY_PAYLOAD).copyHeaders(headers.toHeaders()).build(); + Message<?> message = MessageBuilder.withPayload(EMPTY_PAYLOAD).copyHeaders(headers.toMap()).build(); byte[] bytes = this.stompMessageConverter.fromMessage(message); try { @@ -209,9 +209,9 @@ protected void sendErrorMessage(WebSocketSession session, Throwable error) { @Override public void afterConnectionClosed(WebSocketSession session, CloseStatus status) throws Exception { this.sessionInfos.remove(session.getId()); - PubSubHeaderAccesssor headers = PubSubHeaderAccesssor.create(MessageType.DISCONNECT); + WebMessageHeaderAccesssor headers = WebMessageHeaderAccesssor.create(MessageType.DISCONNECT); headers.setSessionId(session.getId()); - Message<?> message = MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toHeaders()).build(); + Message<?> message = MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toMap()).build(); this.outputChannel.send(message); } @@ -264,7 +264,7 @@ public void handleMessage(Message<?> message) { } try { - Message<?> byteMessage = MessageBuilder.withPayload(payload).copyHeaders(headers.toHeaders()).build(); + Message<?> byteMessage = MessageBuilder.withPayload(payload).copyHeaders(headers.toMap()).build(); byte[] bytes = getStompMessageConverter().fromMessage(byteMessage); session.sendMessage(new TextMessage(new String(bytes, Charset.forName("UTF-8")))); }
true
Other
spring-projects
spring-framework
486b4101ec6675a53c1595350878a10857518331.json
Introduce MessageHeader accessor types A new type MessageHeaderAccesssor provides read/write access to MessageHeaders along with typed getter/setter methods along the lines of the existing MessageBuilder methods (internally MessageBuilder merely delegates to MessageHeaderAccessor). This class is extensible with sub-classes expected to provide typed getter/setter methods for specific categories of message headers. NativeMessageHeaderAccessor is one specific sub-class that further provides read/write access to headers from some external message source (e.g. STOMP headers). Native headers are stored in a separate MultiValueMap and kept under a specific key.
spring-websocket/src/main/java/org/springframework/web/messaging/support/PubSubHeaderAccesssor.java
@@ -1,251 +0,0 @@ -/* - * Copyright 2002-2013 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 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.web.messaging.support; - -import java.util.Arrays; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.springframework.http.MediaType; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageHeaders; -import org.springframework.util.Assert; -import org.springframework.util.CollectionUtils; -import org.springframework.util.LinkedMultiValueMap; -import org.springframework.web.messaging.MessageType; - - -/** - * A base class for working with message headers in Web, messaging protocols that support - * the publish-subscribe message pattern. Provides uniform access to specific values - * common across protocols such as a destination, message type (publish, - * subscribe/unsubscribe), session id, and others. - * <p> - * This class can be used to prepare headers for a new pub-sub message, or to access - * and/or modify headers of an existing message. - * <p> - * Use one of the static factory method in this class, then call getters and setters, and - * at the end if necessary call {@link #toHeaders()} to obtain the updated headers. - * - * @author Rossen Stoyanchev - * @since 4.0 - */ -public class PubSubHeaderAccesssor { - - protected Log logger = LogFactory.getLog(getClass()); - - public static final String DESTINATIONS = "destinations"; - - public static final String CONTENT_TYPE = "contentType"; - - public static final String MESSAGE_TYPE = "messageType"; - - public static final String PROTOCOL_MESSAGE_TYPE = "protocolMessageType"; - - public static final String SESSION_ID = "sessionId"; - - public static final String SUBSCRIPTION_ID = "subscriptionId"; - - public static final String EXTERNAL_SOURCE_HEADERS = "extSourceHeaders"; - - - private static final Map<String, List<String>> emptyMultiValueMap = - Collections.unmodifiableMap(new LinkedMultiValueMap<String, String>(0)); - - - // wrapped read-only message headers - private final MessageHeaders originalHeaders; - - // header updates - private final Map<String, Object> headers = new HashMap<String, Object>(4); - - // saved headers from a message from a remote source - private final Map<String, List<String>> externalSourceHeaders; - - - - /** - * A constructor for creating new message headers. - * This constructor is protected. See factory methods in this and sub-classes. - */ - protected PubSubHeaderAccesssor(MessageType messageType, Object protocolMessageType, - Map<String, List<String>> externalSourceHeaders) { - - this.originalHeaders = null; - - Assert.notNull(messageType, "messageType is required"); - this.headers.put(MESSAGE_TYPE, messageType); - - if (protocolMessageType != null) { - this.headers.put(PROTOCOL_MESSAGE_TYPE, protocolMessageType); - } - - if (externalSourceHeaders == null) { - this.externalSourceHeaders = emptyMultiValueMap; - } - else { - this.externalSourceHeaders = Collections.unmodifiableMap(externalSourceHeaders); // TODO: list values must also be read-only - this.headers.put(EXTERNAL_SOURCE_HEADERS, this.externalSourceHeaders); - } - } - - /** - * A constructor for accessing and modifying existing message headers. This - * constructor is protected. See factory methods in this and sub-classes. - */ - @SuppressWarnings("unchecked") - protected PubSubHeaderAccesssor(Message<?> message) { - Assert.notNull(message, "message is required"); - this.originalHeaders = message.getHeaders(); - this.externalSourceHeaders = (this.originalHeaders.get(EXTERNAL_SOURCE_HEADERS) != null) ? - (Map<String, List<String>>) this.originalHeaders.get(EXTERNAL_SOURCE_HEADERS) : emptyMultiValueMap; - } - - - /** - * Create {@link PubSubHeaderAccesssor} for a new {@link Message} with - * {@link MessageType#MESSAGE}. - */ - public static PubSubHeaderAccesssor create() { - return new PubSubHeaderAccesssor(MessageType.MESSAGE, null, null); - } - - /** - * Create {@link PubSubHeaderAccesssor} for a new {@link Message} of a specific type. - */ - public static PubSubHeaderAccesssor create(MessageType messageType) { - return new PubSubHeaderAccesssor(messageType, null, null); - } - - /** - * Create {@link PubSubHeaderAccesssor} from the headers of an existing message. - */ - public static PubSubHeaderAccesssor wrap(Message<?> message) { - return new PubSubHeaderAccesssor(message); - } - - - /** - * Return the original, wrapped headers (i.e. unmodified) or a new Map including any - * updates made via setters. - */ - public Map<String, Object> toHeaders() { - if (!isModified()) { - return this.originalHeaders; - } - Map<String, Object> result = new HashMap<String, Object>(); - if (this.originalHeaders != null) { - result.putAll(this.originalHeaders); - } - result.putAll(this.headers); - return result; - } - - public boolean isModified() { - return ((this.originalHeaders == null) || !this.headers.isEmpty()); - } - - public MessageType getMessageType() { - return (MessageType) getHeaderValue(MESSAGE_TYPE); - } - - private Object getHeaderValue(String headerName) { - if (this.headers.get(headerName) != null) { - return this.headers.get(headerName); - } - else if ((this.originalHeaders != null) && (this.originalHeaders.get(headerName) != null)) { - return this.originalHeaders.get(headerName); - } - return null; - } - - protected void setProtocolMessageType(Object protocolMessageType) { - this.headers.put(PROTOCOL_MESSAGE_TYPE, protocolMessageType); - } - - protected Object getProtocolMessageType() { - return getHeaderValue(PROTOCOL_MESSAGE_TYPE); - } - - public void setDestination(String destination) { - Assert.notNull(destination, "destination is required"); - this.headers.put(DESTINATIONS, Arrays.asList(destination)); - } - - @SuppressWarnings("unchecked") - public String getDestination() { - List<String> destinations = (List<String>) getHeaderValue(DESTINATIONS); - return CollectionUtils.isEmpty(destinations) ? null : destinations.get(0); - } - - @SuppressWarnings("unchecked") - public List<String> getDestinations() { - List<String> destinations = (List<String>) getHeaderValue(DESTINATIONS); - return CollectionUtils.isEmpty(destinations) ? null : destinations; - } - - public void setDestinations(List<String> destinations) { - Assert.notNull(destinations, "destinations are required"); - this.headers.put(DESTINATIONS, destinations); - } - - public MediaType getContentType() { - return (MediaType) getHeaderValue(CONTENT_TYPE); - } - - public void setContentType(MediaType contentType) { - Assert.notNull(contentType, "contentType is required"); - this.headers.put(CONTENT_TYPE, contentType); - } - - public String getSubscriptionId() { - return (String) getHeaderValue(SUBSCRIPTION_ID); - } - - public void setSubscriptionId(String subscriptionId) { - this.headers.put(SUBSCRIPTION_ID, subscriptionId); - } - - public String getSessionId() { - return (String) getHeaderValue(SESSION_ID); - } - - public void setSessionId(String sessionId) { - this.headers.put(SESSION_ID, sessionId); - } - - /** - * Return a read-only map of headers originating from a message received by the - * application from an external source (e.g. from a remote WebSocket endpoint). The - * header names and values are exactly as they were, and are protocol specific but may - * also be custom application headers if the protocol allows that. - */ - public Map<String, List<String>> getExternalSourceHeaders() { - return this.externalSourceHeaders; - } - - @Override - public String toString() { - return "PubSubHeaders [originalHeaders=" + this.originalHeaders + ", headers=" - + this.headers + ", externalSourceHeaders=" + this.externalSourceHeaders + "]"; - } - -}
true
Other
spring-projects
spring-framework
486b4101ec6675a53c1595350878a10857518331.json
Introduce MessageHeader accessor types A new type MessageHeaderAccesssor provides read/write access to MessageHeaders along with typed getter/setter methods along the lines of the existing MessageBuilder methods (internally MessageBuilder merely delegates to MessageHeaderAccessor). This class is extensible with sub-classes expected to provide typed getter/setter methods for specific categories of message headers. NativeMessageHeaderAccessor is one specific sub-class that further provides read/write access to headers from some external message source (e.g. STOMP headers). Native headers are stored in a separate MultiValueMap and kept under a specific key.
spring-websocket/src/main/java/org/springframework/web/messaging/support/PubSubMessageBuilder.java
@@ -29,7 +29,7 @@ */ public class PubSubMessageBuilder<T> { - private final PubSubHeaderAccesssor headers = PubSubHeaderAccesssor.create(); + private final WebMessageHeaderAccesssor headers = WebMessageHeaderAccesssor.create(); private final T payload; @@ -67,11 +67,11 @@ public Message<T> build() { Message<?> message = MessageHolder.getMessage(); if (message != null) { - String sessionId = PubSubHeaderAccesssor.wrap(message).getSessionId(); + String sessionId = WebMessageHeaderAccesssor.wrap(message).getSessionId(); this.headers.setSessionId(sessionId); } - return MessageBuilder.withPayload(this.payload).copyHeaders(this.headers.toHeaders()).build(); + return MessageBuilder.withPayload(this.payload).copyHeaders(this.headers.toMap()).build(); } }
true
Other
spring-projects
spring-framework
486b4101ec6675a53c1595350878a10857518331.json
Introduce MessageHeader accessor types A new type MessageHeaderAccesssor provides read/write access to MessageHeaders along with typed getter/setter methods along the lines of the existing MessageBuilder methods (internally MessageBuilder merely delegates to MessageHeaderAccessor). This class is extensible with sub-classes expected to provide typed getter/setter methods for specific categories of message headers. NativeMessageHeaderAccessor is one specific sub-class that further provides read/write access to headers from some external message source (e.g. STOMP headers). Native headers are stored in a separate MultiValueMap and kept under a specific key.
spring-websocket/src/main/java/org/springframework/web/messaging/support/WebMessageHeaderAccesssor.java
@@ -0,0 +1,167 @@ +/* + * Copyright 2002-2013 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.web.messaging.support; + +import java.util.Arrays; +import java.util.List; +import java.util.Map; + +import org.springframework.http.MediaType; +import org.springframework.messaging.Message; +import org.springframework.messaging.support.NativeMessageHeaderAccessor; +import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; +import org.springframework.web.messaging.MessageType; + + +/** + * A base class for working with message headers in Web, messaging protocols that support + * the publish-subscribe message pattern. Provides uniform access to specific values + * common across protocols such as a destination, message type (publish, + * subscribe/unsubscribe), session id, and others. + * <p> + * Use one of the static factory method in this class, then call getters and setters, and + * at the end if necessary call {@link #toMap()} to obtain the updated headers. + * + * @author Rossen Stoyanchev + * @since 4.0 + */ +public class WebMessageHeaderAccesssor extends NativeMessageHeaderAccessor { + + public static final String DESTINATIONS = "destinations"; + + public static final String CONTENT_TYPE = "contentType"; + + public static final String MESSAGE_TYPE = "messageType"; + + public static final String PROTOCOL_MESSAGE_TYPE = "protocolMessageType"; + + public static final String SESSION_ID = "sessionId"; + + public static final String SUBSCRIPTION_ID = "subscriptionId"; + + + /** + * A constructor for creating new message headers. + * This constructor is protected. See factory methods in this and sub-classes. + */ + protected WebMessageHeaderAccesssor(MessageType messageType, Object protocolMessageType, + Map<String, List<String>> externalSourceHeaders) { + + super(externalSourceHeaders); + + Assert.notNull(messageType, "messageType is required"); + setHeader(MESSAGE_TYPE, messageType); + + if (protocolMessageType != null) { + setHeader(PROTOCOL_MESSAGE_TYPE, protocolMessageType); + } + } + + /** + * A constructor for accessing and modifying existing message headers. This + * constructor is protected. See factory methods in this and sub-classes. + */ + protected WebMessageHeaderAccesssor(Message<?> message) { + super(message); + Assert.notNull(message, "message is required"); + } + + + /** + * Create {@link WebMessageHeaderAccesssor} for a new {@link Message} with + * {@link MessageType#MESSAGE}. + */ + public static WebMessageHeaderAccesssor create() { + return new WebMessageHeaderAccesssor(MessageType.MESSAGE, null, null); + } + + /** + * Create {@link WebMessageHeaderAccesssor} for a new {@link Message} of a specific type. + */ + public static WebMessageHeaderAccesssor create(MessageType messageType) { + return new WebMessageHeaderAccesssor(messageType, null, null); + } + + /** + * Create {@link WebMessageHeaderAccesssor} from the headers of an existing message. + */ + public static WebMessageHeaderAccesssor wrap(Message<?> message) { + return new WebMessageHeaderAccesssor(message); + } + + + public MessageType getMessageType() { + return (MessageType) getHeader(MESSAGE_TYPE); + } + + protected void setProtocolMessageType(Object protocolMessageType) { + setHeader(PROTOCOL_MESSAGE_TYPE, protocolMessageType); + } + + protected Object getProtocolMessageType() { + return getHeader(PROTOCOL_MESSAGE_TYPE); + } + + public void setDestination(String destination) { + Assert.notNull(destination, "destination is required"); + setHeader(DESTINATIONS, Arrays.asList(destination)); + } + + @SuppressWarnings("unchecked") + public String getDestination() { + List<String> destinations = (List<String>) getHeader(DESTINATIONS); + return CollectionUtils.isEmpty(destinations) ? null : destinations.get(0); + } + + @SuppressWarnings("unchecked") + public List<String> getDestinations() { + List<String> destinations = (List<String>) getHeader(DESTINATIONS); + return CollectionUtils.isEmpty(destinations) ? null : destinations; + } + + public void setDestinations(List<String> destinations) { + Assert.notNull(destinations, "destinations are required"); + setHeader(DESTINATIONS, destinations); + } + + public MediaType getContentType() { + return (MediaType) getHeader(CONTENT_TYPE); + } + + public void setContentType(MediaType contentType) { + Assert.notNull(contentType, "contentType is required"); + setHeader(CONTENT_TYPE, contentType); + } + + public String getSubscriptionId() { + return (String) getHeader(SUBSCRIPTION_ID); + } + + public void setSubscriptionId(String subscriptionId) { + setHeader(SUBSCRIPTION_ID, subscriptionId); + } + + public String getSessionId() { + return (String) getHeader(SESSION_ID); + } + + public void setSessionId(String sessionId) { + setHeader(SESSION_ID, sessionId); + } + +}
true
Other
spring-projects
spring-framework
486b4101ec6675a53c1595350878a10857518331.json
Introduce MessageHeader accessor types A new type MessageHeaderAccesssor provides read/write access to MessageHeaders along with typed getter/setter methods along the lines of the existing MessageBuilder methods (internally MessageBuilder merely delegates to MessageHeaderAccessor). This class is extensible with sub-classes expected to provide typed getter/setter methods for specific categories of message headers. NativeMessageHeaderAccessor is one specific sub-class that further provides read/write access to headers from some external message source (e.g. STOMP headers). Native headers are stored in a separate MultiValueMap and kept under a specific key.
spring-websocket/src/test/java/org/springframework/web/messaging/stomp/support/StompMessageConverterTests.java
@@ -53,7 +53,7 @@ public void connectFrame() throws Exception { MessageHeaders headers = message.getHeaders(); StompHeaderAccessor stompHeaders = StompHeaderAccessor.wrap(message); - assertEquals(7, stompHeaders.toHeaders().size()); + assertEquals(7, stompHeaders.toMap().size()); assertEquals(Collections.singleton("1.1"), stompHeaders.getAcceptVersion()); assertEquals("github.org", stompHeaders.getHost()); @@ -84,7 +84,7 @@ public void connectWithEscapes() throws Exception { StompHeaderAccessor stompHeaders = StompHeaderAccessor.wrap(message); assertEquals(Collections.singleton("1.1"), stompHeaders.getAcceptVersion()); - assertEquals("st\nomp.gi:thu\\b.org", stompHeaders.getExternalSourceHeaders().get("ho:\ns\rt").get(0)); + assertEquals("st\nomp.gi:thu\\b.org", stompHeaders.toNativeHeaderMap().get("ho:\ns\rt").get(0)); String convertedBack = new String(this.converter.fromMessage(message), "UTF-8"); @@ -128,7 +128,7 @@ public void connectWithEscapesAndCR12() throws Exception { StompHeaderAccessor stompHeaders = StompHeaderAccessor.wrap(message); assertEquals(Collections.singleton("1.1"), stompHeaders.getAcceptVersion()); - assertEquals("st\nomp.gi:thu\\b.org", stompHeaders.getExternalSourceHeaders().get("ho:\ns\rt").get(0)); + assertEquals("st\nomp.gi:thu\\b.org", stompHeaders.toNativeHeaderMap().get("ho:\ns\rt").get(0)); String convertedBack = new String(this.converter.fromMessage(message), "UTF-8");
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-context/src/main/java/org/springframework/messaging/MessageChannel.java
@@ -23,8 +23,7 @@ * @author Mark Fisher * @since 4.0 */ -@SuppressWarnings("rawtypes") -public interface MessageChannel<M extends Message> { +public interface MessageChannel { /** * Send a {@link Message} to this channel. May throw a RuntimeException for @@ -39,7 +38,7 @@ * * @return whether or not the Message has been sent successfully */ - boolean send(M message); + boolean send(Message<?> message); /** * Send a message, blocking until either the message is accepted or the @@ -52,6 +51,6 @@ * <code>false</code> if the specified timeout period elapses or * the send is interrupted */ - boolean send(M message, long timeout); + boolean send(Message<?> message, long timeout); }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-context/src/main/java/org/springframework/messaging/MessageFactory.java
@@ -1,40 +0,0 @@ -/* - * Copyright 2002-2013 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 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.messaging; - -import java.util.Map; - - -/** - * A factory for creating messages, allowing for control of the concrete type of the message. - * - * @author Andy Wilkinson - * @since 4.0 - */ -public interface MessageFactory<M extends Message<?>> { - - /** - * Creates a new message with the given payload and headers - * - * @param payload The message payload - * @param headers The message headers - * @param <P> The payload's type - * - * @return the message - */ - <P> M createMessage(P payload, Map<String, Object> headers); -}
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-context/src/main/java/org/springframework/messaging/MessageHandler.java
@@ -24,11 +24,10 @@ * @author Iwein Fuld * @since 4.0 */ -@SuppressWarnings("rawtypes") -public interface MessageHandler<M extends Message> { +public interface MessageHandler { /** - * TODO: support exceptions? + * TODO: exceptions * * Handles the message if possible. If the handler cannot deal with the * message this will result in a <code>MessageRejectedException</code> e.g. @@ -47,6 +46,6 @@ * @throws org.springframework.integration.MessageDeliveryException when this handler failed to deliver the * reply related to the handling of the message */ - void handleMessage(M message) throws MessagingException; + void handleMessage(Message<?> message) throws MessagingException; }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-context/src/main/java/org/springframework/messaging/MessageHeaders.java
@@ -38,9 +38,6 @@ * IMPORTANT: MessageHeaders are immutable. Any mutating operation (e.g., put(..), putAll(..) etc.) * will result in {@link UnsupportedOperationException} * - * <p> - * TODO: update below instructions - * * <p>To create MessageHeaders instance use fluent MessageBuilder API * <pre> * MessageBuilder.withPayload("foo").setHeader("key1", "value1").setHeader("key2", "value2"); @@ -61,7 +58,7 @@ */ public class MessageHeaders implements Map<String, Object>, Serializable { - private static final long serialVersionUID = 8946067357652612145L; + private static final long serialVersionUID = -4615750558355702881L; private static final Log logger = LogFactory.getLog(MessageHeaders.class); @@ -77,6 +74,27 @@ public class MessageHeaders implements Map<String, Object>, Serializable { public static final String TIMESTAMP = "timestamp"; + public static final String CORRELATION_ID = "correlationId"; + + public static final String REPLY_CHANNEL = "replyChannel"; + + public static final String ERROR_CHANNEL = "errorChannel"; + + public static final String EXPIRATION_DATE = "expirationDate"; + + public static final String PRIORITY = "priority"; + + public static final String SEQUENCE_NUMBER = "sequenceNumber"; + + public static final String SEQUENCE_SIZE = "sequenceSize"; + + public static final String SEQUENCE_DETAILS = "sequenceDetails"; + + public static final String CONTENT_TYPE = "contentType"; + + public static final String POSTPROCESS_RESULT = "postProcessResult"; + + public static final List<String> HEADER_NAMES = Arrays.asList(ID, TIMESTAMP); @@ -103,6 +121,36 @@ public Long getTimestamp() { return this.get(TIMESTAMP, Long.class); } + public Long getExpirationDate() { + return this.get(EXPIRATION_DATE, Long.class); + } + + public Object getCorrelationId() { + return this.get(CORRELATION_ID); + } + + public Integer getSequenceNumber() { + Integer sequenceNumber = this.get(SEQUENCE_NUMBER, Integer.class); + return (sequenceNumber != null ? sequenceNumber : 0); + } + + public Integer getSequenceSize() { + Integer sequenceSize = this.get(SEQUENCE_SIZE, Integer.class); + return (sequenceSize != null ? sequenceSize : 0); + } + + public Integer getPriority() { + return this.get(PRIORITY, Integer.class); + } + + public Object getReplyChannel() { + return this.get(REPLY_CHANNEL); + } + + public Object getErrorChannel() { + return this.get(ERROR_CHANNEL); + } + @SuppressWarnings("unchecked") public <T> T get(Object key, Class<T> type) { Object value = this.headers.get(key);
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-context/src/main/java/org/springframework/messaging/PollableChannel.java
@@ -0,0 +1,46 @@ +/* + * Copyright 2002-2013 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.messaging; + + +/** + * Interface for Message Channels from which Messages may be actively received through polling. + * + * @author Mark Fisher + * @since 4.0 + */ +public interface PollableChannel extends MessageChannel { + + /** + * Receive a message from this channel, blocking indefinitely if necessary. + * + * @return the next available {@link Message} or <code>null</code> if interrupted + */ + Message<?> receive(); + + /** + * Receive a message from this channel, blocking until either a message is + * available or the specified timeout period elapses. + * + * @param timeout the timeout in milliseconds + * + * @return the next available {@link Message} or <code>null</code> if the + * specified timeout period elapses or the message reception is interrupted + */ + Message<?> receive(long timeout); + +}
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-context/src/main/java/org/springframework/messaging/SubscribableChannel.java
@@ -25,18 +25,16 @@ * @author Mark Fisher * @since 4.0 */ -@SuppressWarnings("rawtypes") -public interface SubscribableChannel<M extends Message, H extends MessageHandler<M>> - extends MessageChannel<M> { +public interface SubscribableChannel extends MessageChannel { /** * Register a {@link MessageHandler} as a subscriber to this channel. */ - boolean subscribe(H handler); + boolean subscribe(MessageHandler handler); /** * Remove a {@link MessageHandler} from the subscribers of this channel. */ - boolean unsubscribe(H handler); + boolean unsubscribe(MessageHandler handler); }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-context/src/main/java/org/springframework/messaging/support/ErrorMessage.java
@@ -5,7 +5,7 @@ * 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, @@ -18,21 +18,24 @@ import java.util.Map; -import org.springframework.messaging.MessageFactory; - - /** - * A {@link MessageFactory} that creates {@link GenericMessage GenericMessages}. + * A message implementation that accepts a {@link Throwable} payload. + * Once created this object is immutable. * - * @author Andy Wilkinson + * @author Mark Fisher + * @author Oleg Zhurakousky * @since 4.0 */ -public class GenericMessageFactory implements MessageFactory<GenericMessage<?>> { +public class ErrorMessage extends GenericMessage<Throwable> { + private static final long serialVersionUID = -5470210965279837728L; + + public ErrorMessage(Throwable payload) { + super(payload); + } - @Override - public <P> GenericMessage<P> createMessage(P payload, Map<String, Object> headers) { - return new GenericMessage<P>(payload, headers); + public ErrorMessage(Throwable payload, Map<String, Object> headers) { + super(payload, headers); } }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-context/src/main/java/org/springframework/messaging/support/MessageBuilder.java
@@ -1,5 +1,5 @@ /* - * Copyright 2002-2010 the original author or authors. + * Copyright 2002-2013 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. @@ -17,19 +17,25 @@ package org.springframework.messaging.support; import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Set; +import java.util.UUID; import org.springframework.messaging.Message; -import org.springframework.messaging.MessageFactory; +import org.springframework.messaging.MessageChannel; import org.springframework.messaging.MessageHeaders; import org.springframework.util.Assert; import org.springframework.util.PatternMatchUtils; import org.springframework.util.StringUtils; /** + * TODO + * * @author Arjen Poutsma * @author Mark Fisher * @author Oleg Zhurakousky @@ -44,46 +50,24 @@ private final Message<T> originalMessage; - @SuppressWarnings("rawtypes") - private static volatile MessageFactory messageFactory = null; - + private volatile boolean modified; /** - * A constructor with payload and an optional message to copy headers from. - * This is a private constructor to be invoked from the static factory methods only. - * - * @param payload the message payload, never {@code null} - * @param originalMessage a message to copy from or re-use if no changes are made, can - * be {@code null} + * Private constructor to be invoked from the static factory methods only. */ private MessageBuilder(T payload, Message<T> originalMessage) { - Assert.notNull(payload, "payload is required"); + Assert.notNull(payload, "payload must not be null"); this.payload = payload; this.originalMessage = originalMessage; if (originalMessage != null) { - this.headers.putAll(originalMessage.getHeaders()); + this.copyHeaders(originalMessage.getHeaders()); + this.modified = (!this.payload.equals(originalMessage.getPayload())); } } /** - * Private constructor to be invoked from the static factory methods only. - * - * @param payload the message payload, never {@code null} - * @param originalMessage a message to copy from or re-use if no changes are made, can - * be {@code null} - */ - private MessageBuilder(T payload, Map<String, Object> headers) { - Assert.notNull(payload, "payload is required"); - Assert.notNull(headers, "headers is required"); - this.payload = payload; - this.headers.putAll(headers); - this.originalMessage = null; - } - - /** - * Create a builder for a new {@link Message} instance pre-populated with all of the - * headers copied from the provided message. The payload of the provided Message will - * also be used as the payload for the new message. + * Create a builder for a new {@link Message} instance pre-populated with all of the headers copied from the + * provided message. The payload of the provided Message will also be used as the payload for the new message. * * @param message the Message from which the payload and all headers will be copied */ @@ -99,134 +83,252 @@ public static <T> MessageBuilder<T> fromMessage(Message<T> message) { * @param payload the payload for the new message */ public static <T> MessageBuilder<T> withPayload(T payload) { - MessageBuilder<T> builder = new MessageBuilder<T>(payload, (Message<T>) null); + MessageBuilder<T> builder = new MessageBuilder<T>(payload, null); return builder; } /** - * Set the value for the given header name. If the provided value is <code>null</code> - * the header will be removed. + * Set the value for the given header name. If the provided value is <code>null</code>, the header will be removed. */ public MessageBuilder<T> setHeader(String headerName, Object headerValue) { Assert.isTrue(!this.isReadOnly(headerName), "The '" + headerName + "' header is read-only."); - if (StringUtils.hasLength(headerName)) { - putOrRemove(headerName, headerValue); + if (StringUtils.hasLength(headerName) && !headerName.equals(MessageHeaders.ID) + && !headerName.equals(MessageHeaders.TIMESTAMP)) { + this.verifyType(headerName, headerValue); + if (headerValue == null) { + Object removedValue = this.headers.remove(headerName); + if (removedValue != null) { + this.modified = true; + } + } + else { + Object replacedValue = this.headers.put(headerName, headerValue); + if (!headerValue.equals(replacedValue)) { + this.modified = true; + } + } } return this; } - private boolean isReadOnly(String headerName) { - return MessageHeaders.ID.equals(headerName) || MessageHeaders.TIMESTAMP.equals(headerName); - } - - private void putOrRemove(String headerName, Object headerValue) { - if (headerValue == null) { - this.headers.remove(headerName); - } - else { - this.headers.put(headerName, headerValue); - } - } - /** - * Set the value for the given header name only if the header name is not already - * associated with a value. + * Set the value for the given header name only if the header name is not already associated with a value. */ public MessageBuilder<T> setHeaderIfAbsent(String headerName, Object headerValue) { if (this.headers.get(headerName) == null) { - putOrRemove(headerName, headerValue); + this.setHeader(headerName, headerValue); } return this; } /** - * Removes all headers provided via array of 'headerPatterns'. As the name suggests - * the array may contain simple matching patterns for header names. Supported pattern - * styles are: "xxx*", "*xxx", "*xxx*" and "xxx*yyy". + * Removes all headers provided via array of 'headerPatterns'. As the name suggests the array + * may contain simple matching patterns for header names. Supported pattern styles are: + * "xxx*", "*xxx", "*xxx*" and "xxx*yyy". + * + * @param headerPatterns */ public MessageBuilder<T> removeHeaders(String... headerPatterns) { - List<String> toRemove = new ArrayList<String>(); + List<String> headersToRemove = new ArrayList<String>(); for (String pattern : headerPatterns) { if (StringUtils.hasLength(pattern)){ if (pattern.contains("*")){ for (String headerName : this.headers.keySet()) { if (PatternMatchUtils.simpleMatch(pattern, headerName)){ - toRemove.add(headerName); + headersToRemove.add(headerName); } } } else { - toRemove.add(pattern); + headersToRemove.add(pattern); } } } - for (String headerName : toRemove) { - this.headers.remove(headerName); - putOrRemove(headerName, null); + for (String headerToRemove : headersToRemove) { + this.removeHeader(headerToRemove); } return this; } /** * Remove the value for the given header name. */ public MessageBuilder<T> removeHeader(String headerName) { - if (StringUtils.hasLength(headerName) && !isReadOnly(headerName)) { - this.headers.remove(headerName); + if (StringUtils.hasLength(headerName) && !headerName.equals(MessageHeaders.ID) + && !headerName.equals(MessageHeaders.TIMESTAMP)) { + Object removedValue = this.headers.remove(headerName); + if (removedValue != null) { + this.modified = true; + } } return this; } /** - * Copy the name-value pairs from the provided Map. This operation will overwrite any - * existing values. Use { {@link #copyHeadersIfAbsent(Map)} to avoid overwriting - * values. Note that the 'id' and 'timestamp' header values will never be overwritten. + * Copy the name-value pairs from the provided Map. This operation will overwrite any existing values. Use { + * {@link #copyHeadersIfAbsent(Map)} to avoid overwriting values. Note that the 'id' and 'timestamp' header values + * will never be overwritten. + * + * @see MessageHeaders#ID + * @see MessageHeaders#TIMESTAMP */ public MessageBuilder<T> copyHeaders(Map<String, ?> headersToCopy) { Set<String> keys = headersToCopy.keySet(); for (String key : keys) { if (!this.isReadOnly(key)) { - putOrRemove(key, headersToCopy.get(key)); + this.setHeader(key, headersToCopy.get(key)); } } return this; } /** - * Copy the name-value pairs from the provided Map. This operation will <em>not</em> - * overwrite any existing values. + * Copy the name-value pairs from the provided Map. This operation will <em>not</em> overwrite any existing values. */ public MessageBuilder<T> copyHeadersIfAbsent(Map<String, ?> headersToCopy) { Set<String> keys = headersToCopy.keySet(); for (String key : keys) { - if (!this.isReadOnly(key) && (this.headers.get(key) == null)) { - putOrRemove(key, headersToCopy.get(key)); + if (!this.isReadOnly(key)) { + this.setHeaderIfAbsent(key, headersToCopy.get(key)); } } return this; } - @SuppressWarnings("unchecked") - public Message<T> build() { - - if (this.originalMessage != null - && this.headers.equals(this.originalMessage.getHeaders()) - && this.payload.equals(this.originalMessage.getPayload())) { + public MessageBuilder<T> setExpirationDate(Long expirationDate) { + return this.setHeader(MessageHeaders.EXPIRATION_DATE, expirationDate); + } - return this.originalMessage; + public MessageBuilder<T> setExpirationDate(Date expirationDate) { + if (expirationDate != null) { + return this.setHeader(MessageHeaders.EXPIRATION_DATE, expirationDate.getTime()); + } + else { + return this.setHeader(MessageHeaders.EXPIRATION_DATE, null); } + } -// if (this.payload instanceof Throwable) { -// return (Message<T>) new ErrorMessage((Throwable) this.payload, this.headers); -// } + public MessageBuilder<T> setCorrelationId(Object correlationId) { + return this.setHeader(MessageHeaders.CORRELATION_ID, correlationId); + } - this.headers.remove(MessageHeaders.ID); - this.headers.remove(MessageHeaders.TIMESTAMP); + public MessageBuilder<T> pushSequenceDetails(Object correlationId, int sequenceNumber, int sequenceSize) { + Object incomingCorrelationId = headers.get(MessageHeaders.CORRELATION_ID); + @SuppressWarnings("unchecked") + List<List<Object>> incomingSequenceDetails = (List<List<Object>>) headers.get(MessageHeaders.SEQUENCE_DETAILS); + if (incomingCorrelationId != null) { + if (incomingSequenceDetails == null) { + incomingSequenceDetails = new ArrayList<List<Object>>(); + } + else { + incomingSequenceDetails = new ArrayList<List<Object>>(incomingSequenceDetails); + } + incomingSequenceDetails.add(Arrays.asList(incomingCorrelationId, + headers.get(MessageHeaders.SEQUENCE_NUMBER), headers.get(MessageHeaders.SEQUENCE_SIZE))); + incomingSequenceDetails = Collections.unmodifiableList(incomingSequenceDetails); + } + if (incomingSequenceDetails != null) { + setHeader(MessageHeaders.SEQUENCE_DETAILS, incomingSequenceDetails); + } + return setCorrelationId(correlationId).setSequenceNumber(sequenceNumber).setSequenceSize(sequenceSize); + } - if (messageFactory == null) { - return new GenericMessage<T>(this.payload, this.headers); + public MessageBuilder<T> popSequenceDetails() { + String key = MessageHeaders.SEQUENCE_DETAILS; + if (!headers.containsKey(key)) { + return this; + } + @SuppressWarnings("unchecked") + List<List<Object>> incomingSequenceDetails = new ArrayList<List<Object>>((List<List<Object>>) headers.get(key)); + List<Object> sequenceDetails = incomingSequenceDetails.remove(incomingSequenceDetails.size() - 1); + Assert.state(sequenceDetails.size() == 3, "Wrong sequence details (not created by MessageBuilder?): " + + sequenceDetails); + setCorrelationId(sequenceDetails.get(0)); + Integer sequenceNumber = (Integer) sequenceDetails.get(1); + Integer sequenceSize = (Integer) sequenceDetails.get(2); + if (sequenceNumber != null) { + setSequenceNumber(sequenceNumber); + } + if (sequenceSize != null) { + setSequenceSize(sequenceSize); + } + if (!incomingSequenceDetails.isEmpty()) { + headers.put(MessageHeaders.SEQUENCE_DETAILS, incomingSequenceDetails); } else { - return messageFactory.createMessage(payload, headers); + headers.remove(MessageHeaders.SEQUENCE_DETAILS); + } + return this; + } + + public MessageBuilder<T> setReplyChannel(MessageChannel replyChannel) { + return this.setHeader(MessageHeaders.REPLY_CHANNEL, replyChannel); + } + + public MessageBuilder<T> setReplyChannelName(String replyChannelName) { + return this.setHeader(MessageHeaders.REPLY_CHANNEL, replyChannelName); + } + + public MessageBuilder<T> setErrorChannel(MessageChannel errorChannel) { + return this.setHeader(MessageHeaders.ERROR_CHANNEL, errorChannel); + } + + public MessageBuilder<T> setErrorChannelName(String errorChannelName) { + return this.setHeader(MessageHeaders.ERROR_CHANNEL, errorChannelName); + } + + public MessageBuilder<T> setSequenceNumber(Integer sequenceNumber) { + return this.setHeader(MessageHeaders.SEQUENCE_NUMBER, sequenceNumber); + } + + public MessageBuilder<T> setSequenceSize(Integer sequenceSize) { + return this.setHeader(MessageHeaders.SEQUENCE_SIZE, sequenceSize); + } + + public MessageBuilder<T> setPriority(Integer priority) { + return this.setHeader(MessageHeaders.PRIORITY, priority); + } + + @SuppressWarnings("unchecked") + public Message<T> build() { + if (!this.modified && this.originalMessage != null) { + return this.originalMessage; + } + if (this.payload instanceof Throwable) { + return (Message<T>) new ErrorMessage((Throwable) this.payload, this.headers); + } + return new GenericMessage<T>(this.payload, this.headers); + } + + private boolean isReadOnly(String headerName) { + return MessageHeaders.ID.equals(headerName) || MessageHeaders.TIMESTAMP.equals(headerName); + } + + private void verifyType(String headerName, Object headerValue) { + if (headerName != null && headerValue != null) { + if (MessageHeaders.ID.equals(headerName)) { + Assert.isTrue(headerValue instanceof UUID, "The '" + headerName + "' header value must be a UUID."); + } + else if (MessageHeaders.TIMESTAMP.equals(headerName)) { + Assert.isTrue(headerValue instanceof Long, "The '" + headerName + "' header value must be a Long."); + } + else if (MessageHeaders.EXPIRATION_DATE.equals(headerName)) { + Assert.isTrue(headerValue instanceof Date || headerValue instanceof Long, "The '" + headerName + + "' header value must be a Date or Long."); + } + else if (MessageHeaders.ERROR_CHANNEL.equals(headerName) + || MessageHeaders.REPLY_CHANNEL.endsWith(headerName)) { + Assert.isTrue(headerValue instanceof MessageChannel || headerValue instanceof String, "The '" + + headerName + "' header value must be a MessageChannel or String."); + } + else if (MessageHeaders.SEQUENCE_NUMBER.equals(headerName) + || MessageHeaders.SEQUENCE_SIZE.equals(headerName)) { + Assert.isTrue(Integer.class.isAssignableFrom(headerValue.getClass()), "The '" + headerName + + "' header value must be an Integer."); + } + else if (MessageHeaders.PRIORITY.equals(headerName)) { + Assert.isTrue(Integer.class.isAssignableFrom(headerValue.getClass()), "The '" + headerName + + "' header value must be an Integer."); + } } }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/PubSubChannelRegistry.java
@@ -16,33 +16,29 @@ package org.springframework.web.messaging; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageHandler; import org.springframework.messaging.SubscribableChannel; /** * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public interface PubSubChannelRegistry<M extends Message, H extends MessageHandler<M>> { - +public interface PubSubChannelRegistry { /** * A channel for messaging arriving from clients. */ - SubscribableChannel<M, H> getClientInputChannel(); + SubscribableChannel getClientInputChannel(); /** * A channel for sending direct messages to a client. The client must be have * previously subscribed to the destination of the message. */ - SubscribableChannel<M, H> getClientOutputChannel(); + SubscribableChannel getClientOutputChannel(); /** * A channel for broadcasting messages through a message broker. */ - SubscribableChannel<M, H> getMessageBrokerChannel(); + SubscribableChannel getMessageBrokerChannel(); }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/service/AbstractPubSubMessageHandler.java
@@ -37,8 +37,7 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public abstract class AbstractPubSubMessageHandler<M extends Message> implements MessageHandler<M> { +public abstract class AbstractPubSubMessageHandler implements MessageHandler { protected final Log logger = LogFactory.getLog(getClass()); @@ -68,7 +67,7 @@ public void setDisallowedDestinations(String... patterns) { protected abstract Collection<MessageType> getSupportedMessageTypes(); - protected boolean canHandle(M message, MessageType messageType) { + protected boolean canHandle(Message<?> message, MessageType messageType) { if (!CollectionUtils.isEmpty(getSupportedMessageTypes())) { if (!getSupportedMessageTypes().contains(messageType)) { @@ -79,7 +78,7 @@ protected boolean canHandle(M message, MessageType messageType) { return isDestinationAllowed(message); } - protected boolean isDestinationAllowed(M message) { + protected boolean isDestinationAllowed(Message<?> message) { PubSubHeaderAccesssor headers = PubSubHeaderAccesssor.wrap(message); String destination = headers.getDestination(); @@ -115,7 +114,7 @@ protected boolean isDestinationAllowed(M message) { } @Override - public final void handleMessage(M message) throws MessagingException { + public final void handleMessage(Message<?> message) throws MessagingException { PubSubHeaderAccesssor headers = PubSubHeaderAccesssor.wrap(message); MessageType messageType = headers.getMessageType(); @@ -144,22 +143,22 @@ else if (MessageType.DISCONNECT.equals(messageType)) { } } - protected void handleConnect(M message) { + protected void handleConnect(Message<?> message) { } - protected void handlePublish(M message) { + protected void handlePublish(Message<?> message) { } - protected void handleSubscribe(M message) { + protected void handleSubscribe(Message<?> message) { } - protected void handleUnsubscribe(M message) { + protected void handleUnsubscribe(Message<?> message) { } - protected void handleDisconnect(M message) { + protected void handleDisconnect(Message<?> message) { } - protected void handleOther(M message) { + protected void handleOther(Message<?> message) { } }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/service/ReactorPubSubMessageHandler.java
@@ -44,10 +44,9 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public class ReactorPubSubMessageHandler<M extends Message> extends AbstractPubSubMessageHandler<M> { +public class ReactorPubSubMessageHandler extends AbstractPubSubMessageHandler { - private MessageChannel<M> clientChannel; + private MessageChannel clientChannel; private final Reactor reactor; @@ -56,7 +55,7 @@ private Map<String, List<Registration<?>>> subscriptionsBySession = new ConcurrentHashMap<String, List<Registration<?>>>(); - public ReactorPubSubMessageHandler(PubSubChannelRegistry<M, ?> registry, Reactor reactor) { + public ReactorPubSubMessageHandler(PubSubChannelRegistry registry, Reactor reactor) { Assert.notNull(reactor, "reactor is required"); this.clientChannel = registry.getClientOutputChannel(); this.reactor = reactor; @@ -73,7 +72,7 @@ protected Collection<MessageType> getSupportedMessageTypes() { } @Override - public void handleSubscribe(M message) { + public void handleSubscribe(Message<?> message) { if (logger.isDebugEnabled()) { logger.debug("Subscribe " + message); @@ -100,7 +99,7 @@ private String getPublishKey(String destination) { } @Override - public void handlePublish(M message) { + public void handlePublish(Message<?> message) { if (logger.isDebugEnabled()) { logger.debug("Message received: " + message); @@ -110,8 +109,7 @@ public void handlePublish(M message) { // Convert to byte[] payload before the fan-out PubSubHeaderAccesssor headers = PubSubHeaderAccesssor.wrap(message); byte[] payload = payloadConverter.convertToPayload(message.getPayload(), headers.getContentType()); - @SuppressWarnings("unchecked") - M m = (M) MessageBuilder.withPayload(payload).copyHeaders(message.getHeaders()).build(); + Message<?> m = MessageBuilder.withPayload(payload).copyHeaders(message.getHeaders()).build(); this.reactor.notify(getPublishKey(headers.getDestination()), Event.wrap(m)); } @@ -121,7 +119,7 @@ public void handlePublish(M message) { } @Override - public void handleDisconnect(M message) { + public void handleDisconnect(Message<?> message) { PubSubHeaderAccesssor headers = PubSubHeaderAccesssor.wrap(message); removeSubscriptions(headers.getSessionId()); } @@ -154,8 +152,8 @@ public void accept(Event<Message<?>> event) { PubSubHeaderAccesssor headers = PubSubHeaderAccesssor.wrap(sentMessage); headers.setSubscriptionId(this.subscriptionId); - @SuppressWarnings("unchecked") - M clientMessage = (M) MessageBuilder.withPayload(sentMessage.getPayload()).copyHeaders(headers.toHeaders()).build(); + Message<?> clientMessage = MessageBuilder.withPayload( + sentMessage.getPayload()).copyHeaders(headers.toHeaders()).build(); clientChannel.send(clientMessage); }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/service/method/AnnotationPubSubMessageHandler.java
@@ -54,11 +54,10 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public class AnnotationPubSubMessageHandler<M extends Message> extends AbstractPubSubMessageHandler<M> +public class AnnotationPubSubMessageHandler extends AbstractPubSubMessageHandler implements ApplicationContextAware, InitializingBean { - private PubSubChannelRegistry<M, ?> registry; + private PubSubChannelRegistry registry; private List<MessageConverter> messageConverters; @@ -73,12 +72,12 @@ private final Map<Class<?>, MessageExceptionHandlerMethodResolver> exceptionHandlerCache = new ConcurrentHashMap<Class<?>, MessageExceptionHandlerMethodResolver>(64); - private ArgumentResolverComposite<M> argumentResolvers = new ArgumentResolverComposite<M>(); + private ArgumentResolverComposite argumentResolvers = new ArgumentResolverComposite(); - private ReturnValueHandlerComposite<M> returnValueHandlers = new ReturnValueHandlerComposite<M>(); + private ReturnValueHandlerComposite returnValueHandlers = new ReturnValueHandlerComposite(); - public AnnotationPubSubMessageHandler(PubSubChannelRegistry<M, ?> registry) { + public AnnotationPubSubMessageHandler(PubSubChannelRegistry registry) { Assert.notNull(registry, "registry is required"); this.registry = registry; } @@ -102,10 +101,10 @@ public void afterPropertiesSet() { initHandlerMethods(); - this.argumentResolvers.addResolver(new MessageChannelArgumentResolver<M>(this.registry.getMessageBrokerChannel())); - this.argumentResolvers.addResolver(new MessageBodyArgumentResolver<M>(this.messageConverters)); + this.argumentResolvers.addResolver(new MessageChannelArgumentResolver(this.registry.getMessageBrokerChannel())); + this.argumentResolvers.addResolver(new MessageBodyArgumentResolver(this.messageConverters)); - this.returnValueHandlers.addHandler(new MessageReturnValueHandler<M>(this.registry.getClientOutputChannel())); + this.returnValueHandlers.addHandler(new MessageReturnValueHandler(this.registry.getClientOutputChannel())); } protected void initHandlerMethods() { @@ -139,9 +138,8 @@ protected void detectHandlerMethods(Object handler) { new UnsubscribeMappingInfoCreator(), this.unsubscribeMethods); } - @SuppressWarnings("unchecked") private <A extends Annotation> void initHandlerMethods(Object handler, Class<?> handlerType, - final Class<A> annotationType, MappingInfoCreator mappingInfoCreator, + final Class<A> annotationType, MappingInfoCreator<A> mappingInfoCreator, Map<MappingInfo, HandlerMethod> handlerMethods) { Set<Method> messageMethods = HandlerMethodSelector.selectMethods(handlerType, new MethodFilter() { @@ -171,21 +169,21 @@ protected HandlerMethod createHandlerMethod(Object handler, Method method) { } @Override - public void handlePublish(M message) { + public void handlePublish(Message<?> message) { handleMessageInternal(message, this.messageMethods); } @Override - public void handleSubscribe(M message) { + public void handleSubscribe(Message<?> message) { handleMessageInternal(message, this.subscribeMethods); } @Override - public void handleUnsubscribe(M message) { + public void handleUnsubscribe(Message<?> message) { handleMessageInternal(message, this.unsubscribeMethods); } - private void handleMessageInternal(final M message, Map<MappingInfo, HandlerMethod> handlerMethods) { + private void handleMessageInternal(final Message<?> message, Map<MappingInfo, HandlerMethod> handlerMethods) { PubSubHeaderAccesssor headers = PubSubHeaderAccesssor.wrap(message); String destination = headers.getDestination(); @@ -198,7 +196,7 @@ private void handleMessageInternal(final M message, Map<MappingInfo, HandlerMeth HandlerMethod handlerMethod = match.createWithResolvedBean(); // TODO: avoid re-creating invocableHandlerMethod - InvocableMessageHandlerMethod<M> invocableHandlerMethod = new InvocableMessageHandlerMethod<M>(handlerMethod); + InvocableMessageHandlerMethod invocableHandlerMethod = new InvocableMessageHandlerMethod(handlerMethod); invocableHandlerMethod.setMessageMethodArgumentResolvers(this.argumentResolvers); try { @@ -225,9 +223,9 @@ private void handleMessageInternal(final M message, Map<MappingInfo, HandlerMeth } } - private void invokeExceptionHandler(M message, HandlerMethod handlerMethod, Exception ex) { + private void invokeExceptionHandler(Message<?> message, HandlerMethod handlerMethod, Exception ex) { - InvocableMessageHandlerMethod<M> invocableHandlerMethod; + InvocableMessageHandlerMethod invocableHandlerMethod; Class<?> beanType = handlerMethod.getBeanType(); MessageExceptionHandlerMethodResolver resolver = this.exceptionHandlerCache.get(beanType); if (resolver == null) { @@ -241,7 +239,7 @@ private void invokeExceptionHandler(M message, HandlerMethod handlerMethod, Exce return; } - invocableHandlerMethod = new InvocableMessageHandlerMethod<M>(handlerMethod.getBean(), method); + invocableHandlerMethod = new InvocableMessageHandlerMethod(handlerMethod.getBean(), method); invocableHandlerMethod.setMessageMethodArgumentResolvers(this.argumentResolvers); try {
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/service/method/ArgumentResolver.java
@@ -27,8 +27,7 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public interface ArgumentResolver<M extends Message> { +public interface ArgumentResolver { /** * Whether the given {@linkplain MethodParameter method parameter} is @@ -54,6 +53,6 @@ * * @throws Exception in case of errors with the preparation of argument values */ - Object resolveArgument(MethodParameter parameter, M message) throws Exception; + Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception; }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/service/method/ArgumentResolverComposite.java
@@ -36,21 +36,20 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public class ArgumentResolverComposite<M extends Message> implements ArgumentResolver<M> { +public class ArgumentResolverComposite implements ArgumentResolver { protected final Log logger = LogFactory.getLog(getClass()); - private final List<ArgumentResolver<M>> argumentResolvers = new LinkedList<ArgumentResolver<M>>(); + private final List<ArgumentResolver> argumentResolvers = new LinkedList<ArgumentResolver>(); - private final Map<MethodParameter, ArgumentResolver<M>> argumentResolverCache = - new ConcurrentHashMap<MethodParameter, ArgumentResolver<M>>(256); + private final Map<MethodParameter, ArgumentResolver> argumentResolverCache = + new ConcurrentHashMap<MethodParameter, ArgumentResolver>(256); /** * Return a read-only list with the contained resolvers, or an empty list. */ - public List<ArgumentResolver<M>> getResolvers() { + public List<ArgumentResolver> getResolvers() { return Collections.unmodifiableList(this.argumentResolvers); } @@ -68,20 +67,20 @@ public boolean supportsParameter(MethodParameter parameter) { * @exception IllegalStateException if no suitable {@link ArgumentResolver} is found. */ @Override - public Object resolveArgument(MethodParameter parameter, M message) throws Exception { + public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { - ArgumentResolver<M> resolver = getArgumentResolver(parameter); + ArgumentResolver resolver = getArgumentResolver(parameter); Assert.notNull(resolver, "Unknown parameter type [" + parameter.getParameterType().getName() + "]"); return resolver.resolveArgument(parameter, message); } /** * Find a registered {@link ArgumentResolver} that supports the given method parameter. */ - private ArgumentResolver<M> getArgumentResolver(MethodParameter parameter) { - ArgumentResolver<M> result = this.argumentResolverCache.get(parameter); + private ArgumentResolver getArgumentResolver(MethodParameter parameter) { + ArgumentResolver result = this.argumentResolverCache.get(parameter); if (result == null) { - for (ArgumentResolver<M> resolver : this.argumentResolvers) { + for (ArgumentResolver resolver : this.argumentResolvers) { if (resolver.supportsParameter(parameter)) { result = resolver; this.argumentResolverCache.put(parameter, result); @@ -95,17 +94,17 @@ private ArgumentResolver<M> getArgumentResolver(MethodParameter parameter) { /** * Add the given {@link ArgumentResolver}. */ - public ArgumentResolverComposite<M> addResolver(ArgumentResolver<M> argumentResolver) { + public ArgumentResolverComposite addResolver(ArgumentResolver argumentResolver) { this.argumentResolvers.add(argumentResolver); return this; } /** * Add the given {@link ArgumentResolver}s. */ - public ArgumentResolverComposite<M> addResolvers(List<? extends ArgumentResolver<M>> argumentResolvers) { + public ArgumentResolverComposite addResolvers(List<? extends ArgumentResolver> argumentResolvers) { if (argumentResolvers != null) { - for (ArgumentResolver<M> resolver : argumentResolvers) { + for (ArgumentResolver resolver : argumentResolvers) { this.argumentResolvers.add(resolver); } }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/service/method/InvocableMessageHandlerMethod.java
@@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -44,10 +44,9 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public class InvocableMessageHandlerMethod<M extends Message> extends HandlerMethod { +public class InvocableMessageHandlerMethod extends HandlerMethod { - private ArgumentResolverComposite<M> argumentResolvers = new ArgumentResolverComposite<M>(); + private ArgumentResolverComposite argumentResolvers = new ArgumentResolverComposite(); private ParameterNameDiscoverer parameterNameDiscoverer = new LocalVariableTableParameterNameDiscoverer(); @@ -85,7 +84,7 @@ public InvocableMessageHandlerMethod(Object bean, String methodName, Class<?>... * Set {@link ArgumentResolver}s to use to use for resolving method * argument values. */ - public void setMessageMethodArgumentResolvers(ArgumentResolverComposite<M> argumentResolvers) { + public void setMessageMethodArgumentResolvers(ArgumentResolverComposite argumentResolvers) { this.argumentResolvers = argumentResolvers; } @@ -107,7 +106,7 @@ public void setParameterNameDiscoverer(ParameterNameDiscoverer parameterNameDisc * @exception Exception raised if no suitable argument resolver can be found, or the * method raised an exception */ - public final Object invoke(M message, Object... providedArgs) throws Exception { + public final Object invoke(Message<?> message, Object... providedArgs) throws Exception { Object[] args = getMethodArgumentValues(message, providedArgs); @@ -130,7 +129,7 @@ public final Object invoke(M message, Object... providedArgs) throws Exception { /** * Get the method argument values for the current request. */ - private Object[] getMethodArgumentValues(M message, Object... providedArgs) throws Exception { + private Object[] getMethodArgumentValues(Message<?> message, Object... providedArgs) throws Exception { MethodParameter[] parameters = getMethodParameters(); Object[] args = new Object[parameters.length];
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/service/method/MessageBodyArgumentResolver.java
@@ -32,8 +32,7 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public class MessageBodyArgumentResolver<M extends Message> implements ArgumentResolver<M> { +public class MessageBodyArgumentResolver implements ArgumentResolver { private final MessageConverter converter; @@ -48,7 +47,7 @@ public boolean supportsParameter(MethodParameter parameter) { } @Override - public Object resolveArgument(MethodParameter parameter, M message) throws Exception { + public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { Object arg = null;
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/service/method/MessageChannelArgumentResolver.java
@@ -26,13 +26,12 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public class MessageChannelArgumentResolver<M extends Message> implements ArgumentResolver<M> { +public class MessageChannelArgumentResolver implements ArgumentResolver { - private MessageChannel<M> messageBrokerChannel; + private MessageChannel messageBrokerChannel; - public MessageChannelArgumentResolver(MessageChannel<M> messageBrokerChannel) { + public MessageChannelArgumentResolver(MessageChannel messageBrokerChannel) { Assert.notNull(messageBrokerChannel, "messageBrokerChannel is required"); this.messageBrokerChannel = messageBrokerChannel; } @@ -43,7 +42,7 @@ public boolean supportsParameter(MethodParameter parameter) { } @Override - public Object resolveArgument(MethodParameter parameter, M message) throws Exception { + public Object resolveArgument(MethodParameter parameter, Message<?> message) throws Exception { return this.messageBrokerChannel; }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/service/method/MessageReturnValueHandler.java
@@ -16,8 +16,6 @@ package org.springframework.web.messaging.service.method; -import java.util.Map; - import org.springframework.core.MethodParameter; import org.springframework.messaging.Message; import org.springframework.messaging.MessageChannel; @@ -30,13 +28,12 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public class MessageReturnValueHandler<M extends Message> implements ReturnValueHandler<M> { +public class MessageReturnValueHandler implements ReturnValueHandler { - private MessageChannel<M> clientChannel; + private MessageChannel clientChannel; - public MessageReturnValueHandler(MessageChannel<M> clientChannel) { + public MessageReturnValueHandler(MessageChannel clientChannel) { Assert.notNull(clientChannel, "clientChannel is required"); this.clientChannel = clientChannel; } @@ -59,41 +56,31 @@ public boolean supportsReturnType(MethodParameter returnType) { } @Override - public void handleReturnValue(Object returnValue, MethodParameter returnType, M message) + public void handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message) throws Exception { Assert.notNull(this.clientChannel, "No clientChannel to send messages to"); - @SuppressWarnings("unchecked") - M returnMessage = (M) returnValue; - if (returnMessage == null) { + if (message == null) { return; } - returnMessage = processReturnMessage(returnMessage, message); - - this.clientChannel.send(returnMessage); - } - - protected M processReturnMessage(M returnMessage, M message) { - PubSubHeaderAccesssor headers = PubSubHeaderAccesssor.wrap(message); Assert.notNull(headers.getSubscriptionId(), "No subscription id: " + message); - PubSubHeaderAccesssor returnHeaders = PubSubHeaderAccesssor.wrap(returnMessage); + PubSubHeaderAccesssor returnHeaders = PubSubHeaderAccesssor.wrap(message); returnHeaders.setSessionId(headers.getSessionId()); returnHeaders.setSubscriptionId(headers.getSubscriptionId()); if (returnHeaders.getDestination() == null) { returnHeaders.setDestination(headers.getDestination()); } - return createMessage(returnMessage.getPayload(), returnHeaders.toHeaders()); - } + Message<?> returnMessage = MessageBuilder.withPayload( + message.getPayload()).copyHeaders(headers.toHeaders()).build(); + + this.clientChannel.send(returnMessage); + } - @SuppressWarnings("unchecked") - private M createMessage(Object payload, Map<String, Object> headers) { - return (M) MessageBuilder.withPayload(payload).copyHeaders(headers).build(); - } }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/service/method/ReturnValueHandler.java
@@ -27,8 +27,7 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public interface ReturnValueHandler<M extends Message> { +public interface ReturnValueHandler { /** * Whether the given {@linkplain MethodParameter method return type} is @@ -51,6 +50,6 @@ * @param message the message that caused this method to be called * @throws Exception if the return value handling results in an error */ - void handleReturnValue(Object returnValue, MethodParameter returnType, M message) throws Exception; + void handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message) throws Exception; }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/service/method/ReturnValueHandlerComposite.java
@@ -28,26 +28,25 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public class ReturnValueHandlerComposite<M extends Message> implements ReturnValueHandler<M> { +public class ReturnValueHandlerComposite implements ReturnValueHandler { - private final List<ReturnValueHandler<M>> returnValueHandlers = new ArrayList<ReturnValueHandler<M>>(); + private final List<ReturnValueHandler> returnValueHandlers = new ArrayList<ReturnValueHandler>(); /** * Add the given {@link ReturnValueHandler}. */ - public ReturnValueHandlerComposite<M> addHandler(ReturnValueHandler<M> returnValuehandler) { + public ReturnValueHandlerComposite addHandler(ReturnValueHandler returnValuehandler) { this.returnValueHandlers.add(returnValuehandler); return this; } /** * Add the given {@link ReturnValueHandler}s. */ - public ReturnValueHandlerComposite<M> addHandlers(List<? extends ReturnValueHandler<M>> handlers) { + public ReturnValueHandlerComposite addHandlers(List<? extends ReturnValueHandler> handlers) { if (handlers != null) { - for (ReturnValueHandler<M> handler : handlers) { + for (ReturnValueHandler handler : handlers) { this.returnValueHandlers.add(handler); } } @@ -59,8 +58,8 @@ public boolean supportsReturnType(MethodParameter returnType) { return getReturnValueHandler(returnType) != null; } - private ReturnValueHandler<M> getReturnValueHandler(MethodParameter returnType) { - for (ReturnValueHandler<M> handler : this.returnValueHandlers) { + private ReturnValueHandler getReturnValueHandler(MethodParameter returnType) { + for (ReturnValueHandler handler : this.returnValueHandlers) { if (handler.supportsReturnType(returnType)) { return handler; } @@ -69,10 +68,10 @@ private ReturnValueHandler<M> getReturnValueHandler(MethodParameter returnType) } @Override - public void handleReturnValue(Object returnValue, MethodParameter returnType, M message) + public void handleReturnValue(Object returnValue, MethodParameter returnType, Message<?> message) throws Exception { - ReturnValueHandler<M> handler = getReturnValueHandler(returnType); + ReturnValueHandler handler = getReturnValueHandler(returnType); Assert.notNull(handler, "Unknown return value type [" + returnType.getParameterType().getName() + "]"); handler.handleReturnValue(returnValue, returnType, message); }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/stomp/support/StompMessageConverter.java
@@ -35,8 +35,7 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public class StompMessageConverter<M extends Message> { +public class StompMessageConverter { private static final Charset STOMP_CHARSET = Charset.forName("UTF-8"); @@ -49,7 +48,7 @@ /** * @param stompContent a complete STOMP message (without the trailing 0x00) as byte[] or String. */ - public M toMessage(Object stompContent, String sessionId) { + public Message<?> toMessage(Object stompContent, String sessionId) { byte[] byteContent = null; if (stompContent instanceof String) { @@ -100,12 +99,7 @@ else if (stompContent instanceof byte[]){ byte[] payload = new byte[totalLength - payloadIndex]; System.arraycopy(byteContent, payloadIndex, payload, 0, totalLength - payloadIndex); - return createMessage(stompHeaders, payload); - } - - @SuppressWarnings("unchecked") - private M createMessage(StompHeaderAccessor stompHeaders, byte[] payload) { - return (M) MessageBuilder.withPayload(payload).copyHeaders(stompHeaders.toHeaders()).build(); + return MessageBuilder.withPayload(payload).copyHeaders(stompHeaders.toHeaders()).build(); } private int findIndexOfPayload(byte[] bytes) { @@ -135,7 +129,7 @@ private int findIndexOfPayload(byte[] bytes) { return index; } - public byte[] fromMessage(M message) { + public byte[] fromMessage(Message<?> message) { byte[] payload; if (message.getPayload() instanceof byte[]) {
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/stomp/support/StompRelayPubSubMessageHandler.java
@@ -55,15 +55,14 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public class StompRelayPubSubMessageHandler<M extends Message> extends AbstractPubSubMessageHandler<M> +public class StompRelayPubSubMessageHandler extends AbstractPubSubMessageHandler implements SmartLifecycle { private static final String STOMP_RELAY_SYSTEM_SESSION_ID = "stompRelaySystemSessionId"; - private MessageChannel<M> clientChannel; + private MessageChannel clientChannel; - private final StompMessageConverter<M> stompMessageConverter = new StompMessageConverter<M>(); + private final StompMessageConverter stompMessageConverter = new StompMessageConverter(); private MessageConverter payloadConverter; @@ -80,7 +79,7 @@ * @param clientChannel a channel for sending messages from the remote message broker * back to clients */ - public StompRelayPubSubMessageHandler(PubSubChannelRegistry<M, ?> registry) { + public StompRelayPubSubMessageHandler(PubSubChannelRegistry registry) { Assert.notNull(registry, "registry is required"); this.clientChannel = registry.getClientOutputChannel(); this.payloadConverter = new CompositeMessageConverter(null); @@ -129,12 +128,12 @@ public void start() { headers.setLogin("guest"); headers.setPasscode("guest"); headers.setHeartbeat(0, 0); - @SuppressWarnings("unchecked") - M message = (M) MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toStompMessageHeaders()).build(); + Message<?> message = MessageBuilder.withPayload( + new byte[0]).copyHeaders(headers.toStompMessageHeaders()).build(); RelaySession session = new RelaySession(message, headers) { @Override - protected void sendMessageToClient(M message) { + protected void sendMessageToClient(Message<?> message) { // TODO: check for ERROR frame (reconnect?) } }; @@ -166,7 +165,7 @@ public void stop(Runnable callback) { } @Override - public void handleConnect(M message) { + public void handleConnect(Message<?> message) { StompHeaderAccessor stompHeaders = StompHeaderAccessor.wrap(message); String sessionId = stompHeaders.getSessionId(); if (sessionId == null) { @@ -178,22 +177,22 @@ public void handleConnect(M message) { } @Override - public void handlePublish(M message) { + public void handlePublish(Message<?> message) { forwardMessage(message, StompCommand.SEND); } @Override - public void handleSubscribe(M message) { + public void handleSubscribe(Message<?> message) { forwardMessage(message, StompCommand.SUBSCRIBE); } @Override - public void handleUnsubscribe(M message) { + public void handleUnsubscribe(Message<?> message) { forwardMessage(message, StompCommand.UNSUBSCRIBE); } @Override - public void handleDisconnect(M message) { + public void handleDisconnect(Message<?> message) { StompHeaderAccessor stompHeaders = StompHeaderAccessor.wrap(message); if (stompHeaders.getStompCommand() != null) { forwardMessage(message, StompCommand.DISCONNECT); @@ -206,13 +205,13 @@ public void handleDisconnect(M message) { } @Override - public void handleOther(M message) { + public void handleOther(Message<?> message) { StompCommand command = (StompCommand) message.getHeaders().get(PubSubHeaderAccesssor.PROTOCOL_MESSAGE_TYPE); Assert.notNull(command, "Expected STOMP command: " + message.getHeaders()); forwardMessage(message, command); } - private void forwardMessage(M message, StompCommand command) { + private void forwardMessage(Message<?> message, StompCommand command) { StompHeaderAccessor headers = StompHeaderAccessor.wrap(message); headers.setStompCommandIfNotSet(command); @@ -249,14 +248,14 @@ private class RelaySession { private final Promise<TcpConnection<String, String>> promise; - private final BlockingQueue<M> messageQueue = new LinkedBlockingQueue<M>(50); + private final BlockingQueue<Message<?>> messageQueue = new LinkedBlockingQueue<Message<?>>(50); private final Object monitor = new Object(); private volatile boolean isConnected = false; - public RelaySession(final M message, final StompHeaderAccessor stompHeaders) { + public RelaySession(final Message<?> message, final StompHeaderAccessor stompHeaders) { Assert.notNull(message, "message is required"); Assert.notNull(stompHeaders, "stompHeaders is required"); @@ -297,7 +296,7 @@ private void readStompFrame(String stompFrame) { return; } - M message = stompMessageConverter.toMessage(stompFrame, this.sessionId); + Message<?> message = stompMessageConverter.toMessage(stompFrame, this.sessionId); if (logger.isTraceEnabled()) { logger.trace("Reading message " + message); } @@ -319,20 +318,19 @@ private void readStompFrame(String stompFrame) { sendMessageToClient(message); } - protected void sendMessageToClient(M message) { + protected void sendMessageToClient(Message<?> message) { clientChannel.send(message); } private void sendError(String sessionId, String errorText) { StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.ERROR); headers.setSessionId(sessionId); headers.setMessage(errorText); - @SuppressWarnings("unchecked") - M errorMessage = (M) MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toHeaders()).build(); + Message<?> errorMessage = MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toHeaders()).build(); sendMessageToClient(errorMessage); } - public void forward(M message, StompHeaderAccessor headers) { + public void forward(Message<?> message, StompHeaderAccessor headers) { if (!this.isConnected) { synchronized(this.monitor) { @@ -358,7 +356,7 @@ public void forward(M message, StompHeaderAccessor headers) { } private void flushMessages(TcpConnection<String, String> connection) { - List<M> messages = new ArrayList<M>(); + List<Message<?>> messages = new ArrayList<Message<?>>(); this.messageQueue.drainTo(messages); for (Message<?> message : messages) { StompHeaderAccessor headers = StompHeaderAccessor.wrap(message); @@ -374,8 +372,7 @@ private boolean forwardInternal(Message<?> message, StompHeaderAccessor headers, MediaType contentType = headers.getContentType(); byte[] payload = payloadConverter.convertToPayload(message.getPayload(), contentType); - @SuppressWarnings("unchecked") - M byteMessage = (M) MessageBuilder.withPayload(payload).copyHeaders(headers.toHeaders()).build(); + Message<?> byteMessage = MessageBuilder.withPayload(payload).copyHeaders(headers.toHeaders()).build(); if (logger.isTraceEnabled()) { logger.trace("Forwarding message " + byteMessage);
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/stomp/support/StompWebSocketHandler.java
@@ -51,24 +51,22 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public class StompWebSocketHandler<M extends Message> extends TextWebSocketHandlerAdapter - implements MessageHandler<M> { +public class StompWebSocketHandler extends TextWebSocketHandlerAdapter implements MessageHandler { private static final byte[] EMPTY_PAYLOAD = new byte[0]; private static Log logger = LogFactory.getLog(StompWebSocketHandler.class); - private MessageChannel<M> outputChannel; + private MessageChannel outputChannel; - private final StompMessageConverter<M> stompMessageConverter = new StompMessageConverter<M>(); + private final StompMessageConverter stompMessageConverter = new StompMessageConverter(); private final Map<String, SessionInfo> sessionInfos = new ConcurrentHashMap<String, SessionInfo>(); private MessageConverter payloadConverter = new CompositeMessageConverter(null); - public StompWebSocketHandler(PubSubChannelRegistry<M, ?> registry) { + public StompWebSocketHandler(PubSubChannelRegistry registry) { Assert.notNull(registry, "registry is required"); this.outputChannel = registry.getClientInputChannel(); } @@ -77,7 +75,7 @@ public void setMessageConverters(List<MessageConverter> converters) { this.payloadConverter = new CompositeMessageConverter(converters); } - public StompMessageConverter<M> getStompMessageConverter() { + public StompMessageConverter getStompMessageConverter() { return this.stompMessageConverter; } @@ -95,7 +93,7 @@ public void afterConnectionEstablished(WebSocketSession session) throws Exceptio protected void handleTextMessage(WebSocketSession session, TextMessage textMessage) { try { String payload = textMessage.getPayload(); - M message = this.stompMessageConverter.toMessage(payload, session.getId()); + Message<?> message = this.stompMessageConverter.toMessage(payload, session.getId()); // TODO: validate size limits // http://stomp.github.io/stomp-specification-1.2.html#Size_Limits @@ -138,7 +136,7 @@ else if (MessageType.DISCONNECT.equals(messageType)) { } } - protected void handleConnect(final WebSocketSession session, M message) throws IOException { + protected void handleConnect(final WebSocketSession session, Message<?> message) throws IOException { StompHeaderAccessor connectHeaders = StompHeaderAccessor.wrap(message); StompHeaderAccessor connectedHeaders = StompHeaderAccessor.create(StompCommand.CONNECTED); @@ -160,17 +158,16 @@ else if (acceptVersions.isEmpty()) { // TODO: security - @SuppressWarnings("unchecked") - M connectedMessage = (M) MessageBuilder.withPayload(EMPTY_PAYLOAD).copyHeaders( + Message<?> connectedMessage = MessageBuilder.withPayload(EMPTY_PAYLOAD).copyHeaders( connectedHeaders.toHeaders()).build(); byte[] bytes = getStompMessageConverter().fromMessage(connectedMessage); session.sendMessage(new TextMessage(new String(bytes, Charset.forName("UTF-8")))); } - protected void handlePublish(M stompMessage) { + protected void handlePublish(Message<?> stompMessage) { } - protected void handleSubscribe(M message) { + protected void handleSubscribe(Message<?> message) { // TODO: need a way to communicate back if subscription was successfully created or // not in which case an ERROR should be sent back and close the connection @@ -184,22 +181,21 @@ protected void handleSubscribe(M message) { sessionInfo.addSubscription(destination, headers.getSubscriptionId()); } - protected void handleUnsubscribe(M message) { + protected void handleUnsubscribe(Message<?> message) { // TODO: remove subscription } - protected void handleDisconnect(M stompMessage) { + protected void handleDisconnect(Message<?> stompMessage) { } protected void sendErrorMessage(WebSocketSession session, Throwable error) { StompHeaderAccessor headers = StompHeaderAccessor.create(StompCommand.ERROR); headers.setMessage(error.getMessage()); - @SuppressWarnings("unchecked") - M message = (M) MessageBuilder.withPayload(EMPTY_PAYLOAD).copyHeaders(headers.toHeaders()).build(); + Message<?> message = MessageBuilder.withPayload(EMPTY_PAYLOAD).copyHeaders(headers.toHeaders()).build(); byte[] bytes = this.stompMessageConverter.fromMessage(message); try { @@ -215,16 +211,15 @@ public void afterConnectionClosed(WebSocketSession session, CloseStatus status) this.sessionInfos.remove(session.getId()); PubSubHeaderAccesssor headers = PubSubHeaderAccesssor.create(MessageType.DISCONNECT); headers.setSessionId(session.getId()); - @SuppressWarnings("unchecked") - M message = (M) MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toHeaders()).build(); + Message<?> message = MessageBuilder.withPayload(new byte[0]).copyHeaders(headers.toHeaders()).build(); this.outputChannel.send(message); } /** * Handle STOMP messages going back out to WebSocket clients. */ @Override - public void handleMessage(M message) { + public void handleMessage(Message<?> message) { StompHeaderAccessor headers = StompHeaderAccessor.wrap(message); headers.setStompCommandIfNotSet(StompCommand.MESSAGE); @@ -269,8 +264,7 @@ public void handleMessage(M message) { } try { - @SuppressWarnings("unchecked") - M byteMessage = (M) MessageBuilder.withPayload(payload).copyHeaders(headers.toHeaders()).build(); + Message<?> byteMessage = MessageBuilder.withPayload(payload).copyHeaders(headers.toHeaders()).build(); byte[] bytes = getStompMessageConverter().fromMessage(byteMessage); session.sendMessage(new TextMessage(new String(bytes, Charset.forName("UTF-8")))); }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/support/AbstractPubSubChannelRegistry.java
@@ -17,8 +17,6 @@ package org.springframework.web.messaging.support; import org.springframework.beans.factory.InitializingBean; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageHandler; import org.springframework.messaging.SubscribableChannel; import org.springframework.util.Assert; import org.springframework.web.messaging.PubSubChannelRegistry; @@ -28,41 +26,39 @@ * @author Rossen Stoyanchev * @since 4.0 */ -@SuppressWarnings("rawtypes") -public class AbstractPubSubChannelRegistry<M extends Message, H extends MessageHandler<M>> - implements PubSubChannelRegistry<M, H>, InitializingBean { +public class AbstractPubSubChannelRegistry implements PubSubChannelRegistry, InitializingBean { - private SubscribableChannel<M, H> clientInputChannel; + private SubscribableChannel clientInputChannel; - private SubscribableChannel<M, H> clientOutputChannel; + private SubscribableChannel clientOutputChannel; - private SubscribableChannel<M, H> messageBrokerChannel; + private SubscribableChannel messageBrokerChannel; @Override - public SubscribableChannel<M, H> getClientInputChannel() { + public SubscribableChannel getClientInputChannel() { return this.clientInputChannel; } - public void setClientInputChannel(SubscribableChannel<M, H> channel) { + public void setClientInputChannel(SubscribableChannel channel) { this.clientInputChannel = channel; } @Override - public SubscribableChannel<M, H> getClientOutputChannel() { + public SubscribableChannel getClientOutputChannel() { return this.clientOutputChannel; } - public void setClientOutputChannel(SubscribableChannel<M, H> channel) { + public void setClientOutputChannel(SubscribableChannel channel) { this.clientOutputChannel = channel; } @Override - public SubscribableChannel<M, H> getMessageBrokerChannel() { + public SubscribableChannel getMessageBrokerChannel() { return this.messageBrokerChannel; } - public void setMessageBrokerChannel(SubscribableChannel<M, H> channel) { + public void setMessageBrokerChannel(SubscribableChannel channel) { this.messageBrokerChannel = channel; }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/support/ReactorMessageChannel.java
@@ -36,7 +36,7 @@ * @author Rossen Stoyanchev * @since 4.0 */ -public class ReactorMessageChannel implements SubscribableChannel<Message<?>, MessageHandler<Message<?>>> { +public class ReactorMessageChannel implements SubscribableChannel { private static Log logger = LogFactory.getLog(ReactorMessageChannel.class); @@ -47,8 +47,8 @@ public class ReactorMessageChannel implements SubscribableChannel<Message<?>, Me private String name = toString(); // TODO - private final Map<MessageHandler<Message<?>>, Registration<?>> registrations = - new HashMap<MessageHandler<Message<?>>, Registration<?>>(); + private final Map<MessageHandler, Registration<?>> registrations = + new HashMap<MessageHandler, Registration<?>>(); public ReactorMessageChannel(Reactor reactor) { @@ -78,7 +78,7 @@ public boolean send(Message<?> message, long timeout) { } @Override - public boolean subscribe(final MessageHandler<Message<?>> handler) { + public boolean subscribe(final MessageHandler handler) { if (this.registrations.containsKey(handler)) { logger.warn("Channel " + getName() + ", handler already subscribed " + handler); @@ -98,7 +98,7 @@ public boolean subscribe(final MessageHandler<Message<?>> handler) { } @Override - public boolean unsubscribe(MessageHandler<Message<?>> handler) { + public boolean unsubscribe(MessageHandler handler) { if (logger.isTraceEnabled()) { logger.trace("Channel " + getName() + ", removing subscription for handler " + handler); @@ -119,9 +119,9 @@ public boolean unsubscribe(MessageHandler<Message<?>> handler) { private static final class MessageHandlerConsumer implements Consumer<Event<Message<?>>> { - private final MessageHandler<Message<?>> handler; + private final MessageHandler handler; - private MessageHandlerConsumer(MessageHandler<Message<?>> handler) { + private MessageHandlerConsumer(MessageHandler handler) { this.handler = handler; }
true
Other
spring-projects
spring-framework
32cb2ca2e783da0af754e5a8cad4947d6a9d606a.json
Remove generic params from Message/MessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/support/ReactorPubSubChannelRegistry.java
@@ -16,8 +16,6 @@ package org.springframework.web.messaging.support; -import org.springframework.messaging.Message; -import org.springframework.messaging.MessageHandler; import org.springframework.util.Assert; import reactor.core.Reactor; @@ -27,7 +25,7 @@ * @author Rossen Stoyanchev * @since 4.0 */ -public class ReactorPubSubChannelRegistry extends AbstractPubSubChannelRegistry<Message<?>, MessageHandler<Message<?>>> { +public class ReactorPubSubChannelRegistry extends AbstractPubSubChannelRegistry { public ReactorPubSubChannelRegistry(Reactor reactor) {
true
Other
spring-projects
spring-framework
f7f66f2e5c18a614a7d741b5ca3d6a07cb49fd8e.json
Fix minor issue in ReactorMessageChannel
spring-websocket/src/main/java/org/springframework/web/messaging/support/ReactorMessageChannel.java
@@ -104,7 +104,7 @@ public boolean unsubscribe(MessageHandler<Message<?>> handler) { logger.trace("Channel " + getName() + ", removing subscription for handler " + handler); } - Registration<?> registration = this.registrations.get(handler); + Registration<?> registration = this.registrations.remove(handler); if (registration == null) { if (logger.isTraceEnabled()) { logger.trace("Channel " + getName() + ", no subscription for handler " + handler);
false
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
build.properties
@@ -17,13 +17,13 @@ spring.osgi.range="${spring.osgi.range.nq}" aj.osgi.range="[1.6.8, 2.0.0)" ## For GA releases -#release.type=release -#build.stamp=RELEASE +release.type=release +build.stamp=RELEASE ## For milestone releases #release.type=milestone #build.stamp=M1 ## For trunk development / ci builds -release.type=integration +#release.type=integration #build.stamp=BUILD-SNAPSHOT
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.aop/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-aop</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.asm/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-asm</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.aspects/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-aspects</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.beans/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-beans</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.context.support/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-context-support</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.context/pom.xml
@@ -6,12 +6,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-context</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.core/pom.xml
@@ -6,12 +6,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-core</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.expression/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-expression</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.instrument.tomcat/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-instrument-tomcat</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.instrument/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-instrument</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> </project>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.integration-tests/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-integration-tests</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies> <dependency>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.jdbc/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-jdbc</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies> <dependency>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.jms/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-jms</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.orm/pom.xml
@@ -6,12 +6,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-orm</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies> <dependency>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.oxm/pom.xml
@@ -6,12 +6,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-oxm</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.spring-library/pom.xml
@@ -14,7 +14,7 @@ <groupId>org.springframework</groupId> <artifactId>spring-library</artifactId> <packaging>libd</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <name>Spring Framework</name> <description>Spring is a layered Java/J2EE application platform, based on code published in Expert One-on-One J2EE Design and Development by Rod Johnson (Wrox, 2002). </description>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.spring-parent/pom.xml
@@ -14,7 +14,7 @@ <artifactId>spring-parent</artifactId> <packaging>pom</packaging> <name>Spring Framework - Parent</name> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <description>Spring Framework Parent</description> <scm> <url>https://fisheye.springframework.org/browse/spring-framework</url>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.test/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-test</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.transaction/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-tx</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.web.portlet/pom.xml
@@ -4,12 +4,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-webmvc-portlet</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.web.servlet/pom.xml
@@ -6,12 +6,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-webmvc</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <profiles>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.web.struts/pom.xml
@@ -6,12 +6,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-struts</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies> <dependency>
true
Other
spring-projects
spring-framework
ac107d0c2ae939c669ba086c2874d02790519b06.json
Release Spring Framework 3.1.0.RELEASE
org.springframework.web/pom.xml
@@ -5,12 +5,12 @@ <groupId>org.springframework</groupId> <artifactId>spring-web</artifactId> <packaging>jar</packaging> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> <parent> <groupId>org.springframework</groupId> <artifactId>spring-parent</artifactId> <relativePath>../org.springframework.spring-parent</relativePath> - <version>3.1.0.BUILD-SNAPSHOT</version> + <version>3.1.0.RELEASE</version> </parent> <dependencies>
true
Other
spring-projects
spring-framework
e9da8548483fcd725a89e1eb12471f622b89cd19.json
Fix typo in MVC reference documentation
spring-framework-reference/src/mvc.xml
@@ -3412,7 +3412,7 @@ background=/themes/cool/img/coolBg.jpg</programlisting> <filename>MultipartFile</filename> in the method parameters:</para> <programlisting language="java">@Controller -public class FileUpoadController { +public class FileUploadController { @RequestMapping(value = "/form", method = RequestMethod.POST) public String handleFormUpload(@RequestParam("name") String name, @@ -3440,7 +3440,7 @@ public class FileUpoadController { parameter:</para> <programlisting language="java">@Controller -public class FileUpoadController { +public class FileUploadController { @RequestMapping(value = "/form", method = RequestMethod.POST) public String handleFormUpload(@RequestParam("name") String name,
false
Other
spring-projects
spring-framework
34798a47ab71daf1d62eabf03ae5f708743d42c9.json
Fix warnings, polish Javadoc for @Validated et al.
org.springframework.context/src/main/java/org/springframework/validation/SmartValidator.java
@@ -26,19 +26,18 @@ public interface SmartValidator extends Validator { /** - * Validate the supplied <code>target</code> object, which must be - * of a {@link Class} for which the {@link #supports(Class)} method - * typically has (or would) return <code>true</code>. - * <p>The supplied {@link Errors errors} instance can be used to report - * any resulting validation errors. - * <p><b>This variant of <code>validate</code> supports validation hints, - * such as validation groups against a JSR-303 provider</b> (in this case, - * the provided hint objects need to be annotation arguments of type Class). - * <p>Note: Validation hints may get ignored by the actual target Validator, + * Validate the supplied {@code target} object, which must be of a {@link Class} for + * which the {@link #supports(Class)} method typically has (or would) return {@code true}. + * <p>The supplied {@link Errors errors} instance can be used to report any + * resulting validation errors. + * <p><b>This variant of {@code validate} supports validation hints, such as + * validation groups against a JSR-303 provider</b> (in this case, the provided hint + * objects need to be annotation arguments of type {@code Class}). + * <p>Note: Validation hints may get ignored by the actual target {@code Validator}, * in which case this method is supposed to be behave just like its regular * {@link #validate(Object, Errors)} sibling. - * @param target the object that is to be validated (can be <code>null</code>) - * @param errors contextual state about the validation process (never <code>null</code>) + * @param target the object that is to be validated (can be {@code null}) + * @param errors contextual state about the validation process (never {@code null}) * @param validationHints one or more hint objects to be passed to the validation engine * @see ValidationUtils */
true
Other
spring-projects
spring-framework
34798a47ab71daf1d62eabf03ae5f708743d42c9.json
Fix warnings, polish Javadoc for @Validated et al.
org.springframework.context/src/main/java/org/springframework/validation/annotation/Validated.java
@@ -58,6 +58,6 @@ * <p>Other {@link org.springframework.validation.SmartValidator} implementations may * support class arguments in other ways as well. */ - Class[] value() default {}; + Class<?>[] value() default {}; }
true
Other
spring-projects
spring-framework
34798a47ab71daf1d62eabf03ae5f708743d42c9.json
Fix warnings, polish Javadoc for @Validated et al.
org.springframework.context/src/main/java/org/springframework/validation/beanvalidation/MethodValidationPostProcessor.java
@@ -46,13 +46,15 @@ * * <p>Applicable methods have JSR-303 constraint annotations on their parameters * and/or on their return value (in the latter case specified at the method level, - * typically as inline annotation). + * typically as inline annotation), e.g.: * - * <p>E.g.: <code>public @NotNull Object myValidMethod(@NotNull String arg1, @Max(10) int arg2)</code> + * <pre class="code"> + * public @NotNull Object myValidMethod(@NotNull String arg1, @Max(10) int arg2) + * </pre> * * <p>Target classes with such annotated methods need to be annotated with Spring's * {@link Validated} annotation at the type level, for their methods to be searched for - * inline constraint annotations. Validation groups can be specified through {@link Validated} + * inline constraint annotations. Validation groups can be specified through {@code @Validated} * as well. By default, JSR-303 will validate against its default group only. * * <p>As of Spring 3.1, this functionality requires Hibernate Validator 4.2 or higher. @@ -64,6 +66,7 @@ * @see MethodValidationInterceptor * @see org.hibernate.validator.method.MethodValidator */ +@SuppressWarnings("serial") public class MethodValidationPostProcessor extends ProxyConfig implements BeanPostProcessor, BeanClassLoaderAware, Ordered, InitializingBean {
true
Other
spring-projects
spring-framework
909577082d7e4a74780bf32bf0c54a1370c76b1f.json
Add attributeDoesNotExist ModelResultMatcher Issue: SPR-10509
spring-test-mvc/src/main/java/org/springframework/test/web/servlet/result/ModelResultMatchers.java
@@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -87,6 +87,21 @@ public void match(MvcResult result) throws Exception { }; } + /** + * Assert the given model attributes do not exist + */ + public ResultMatcher attributeDoesNotExist(final String... names) { + return new ResultMatcher() { + @Override + public void match(MvcResult result) throws Exception { + ModelAndView mav = getModelAndView(result); + for (String name : names) { + assertTrue("Model attribute '" + name + "' exists", mav.getModel().get(name) == null); + } + } + }; + } + /** * Assert the given model attribute(s) have errors. */
true
Other
spring-projects
spring-framework
909577082d7e4a74780bf32bf0c54a1370c76b1f.json
Add attributeDoesNotExist ModelResultMatcher Issue: SPR-10509
spring-test-mvc/src/test/java/org/springframework/test/web/servlet/result/ModelResultMatchersTests.java
@@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -70,7 +70,17 @@ public void attributeExists_doesNotExist() throws Exception { this.matchers.attributeExists("bad").match(this.mvcResult); } - @Test + @Test + public void attributeDoesNotExist() throws Exception { + this.matchers.attributeDoesNotExist("bad").match(this.mvcResult); + } + + @Test(expected=AssertionError.class) + public void attributeDoesNotExist_doesExist() throws Exception { + this.matchers.attributeDoesNotExist("good").match(this.mvcResultWithError); + } + + @Test public void attribute_equal() throws Exception { this.matchers.attribute("good", is("good")).match(this.mvcResult); }
true
Other
spring-projects
spring-framework
1e90d029735e809a8ddb1c60f35e76083b1fe084.json
Fix issue with parsing x-forwarded-host header Issue: SPR-10701
spring-webmvc/src/main/java/org/springframework/web/servlet/support/ServletUriComponentsBuilder.java
@@ -94,9 +94,20 @@ public static ServletUriComponentsBuilder fromRequestUri(HttpServletRequest requ public static ServletUriComponentsBuilder fromRequest(HttpServletRequest request) { String scheme = request.getScheme(); int port = request.getServerPort(); - - String header = request.getHeader("X-Forwarded-Host"); - String host = StringUtils.hasText(header) ? header: request.getServerName(); + String host = request.getServerName(); + + String xForwardedHostHeader = request.getHeader("X-Forwarded-Host"); + + if (StringUtils.hasText(xForwardedHostHeader)) { + if (StringUtils.countOccurrencesOf(xForwardedHostHeader, ":") == 1) { + String[] hostAndPort = StringUtils.split(xForwardedHostHeader, ":"); + host = hostAndPort[0]; + port = Integer.parseInt(hostAndPort[1]); + } + else { + host = xForwardedHostHeader; + } + } ServletUriComponentsBuilder builder = new ServletUriComponentsBuilder(); builder.scheme(scheme);
true
Other
spring-projects
spring-framework
1e90d029735e809a8ddb1c60f35e76083b1fe084.json
Fix issue with parsing x-forwarded-host header Issue: SPR-10701
spring-webmvc/src/test/java/org/springframework/web/servlet/support/ServletUriComponentsBuilderTests.java
@@ -16,13 +16,14 @@ package org.springframework.web.servlet.support; -import static org.junit.Assert.assertEquals; - import org.junit.Before; import org.junit.Test; import org.springframework.mock.web.test.MockHttpServletRequest; import org.springframework.web.context.request.RequestContextHolder; import org.springframework.web.context.request.ServletRequestAttributes; +import org.springframework.web.util.UriComponents; + +import static org.junit.Assert.*; /** * @author Rossen Stoyanchev @@ -93,6 +94,19 @@ public void fromRequestWithForwardedHostHeader() { assertEquals("http://anotherHost/mvc-showcase/data/param?foo=123", result); } + // SPR-10701 + + @Test + public void fromRequestWithForwardedHostAndPortHeader() { + request.addHeader("X-Forwarded-Host", "webtest.foo.bar.com:443"); + request.setRequestURI("/mvc-showcase/data/param"); + request.setQueryString("foo=123"); + UriComponents result = ServletUriComponentsBuilder.fromRequest(request).build(); + + assertEquals("webtest.foo.bar.com", result.getHost()); + assertEquals(443, result.getPort()); + } + @Test public void fromContextPath() { request.setRequestURI("/mvc-showcase/data/param");
true
Other
spring-projects
spring-framework
ed996ab4b34fc68fa1e544136338725260b60d1b.json
Avoid re-retrieval of singleton bean instances Issue: SPR-10663
spring-beans/src/main/java/org/springframework/beans/factory/support/DefaultListableBeanFactory.java
@@ -471,12 +471,12 @@ public Map<String, Object> getBeansWithAnnotation(Class<? extends Annotation> an Map<String, Object> results = new LinkedHashMap<String, Object>(); for (String beanName : getBeanDefinitionNames()) { BeanDefinition beanDefinition = getBeanDefinition(beanName); - if (!beanDefinition.isAbstract() && (findAnnotationOnBean(beanName, annotationType) != null)) { + if (!beanDefinition.isAbstract() && findAnnotationOnBean(beanName, annotationType) != null) { results.put(beanName, getBean(beanName)); } } for (String beanName : getSingletonNames()) { - if (findAnnotationOnBean(beanName, annotationType) != null) { + if (!results.containsKey(beanName) && findAnnotationOnBean(beanName, annotationType) != null) { results.put(beanName, getBean(beanName)); } }
false
Other
spring-projects
spring-framework
4f871d444864d001a049e7817a84f1c59c70016f.json
Fix Jaxb2TypeScanner to scan for @XmlRegistry Update ClassPathJaxb2TypeScanner to scan for @XmlRegistry classes. Prior to this commit explicitly configured @XmlRegistry annotated classes were not registered with the JAXBContext when using the 'packagesToScan' property of the Jaxb2Unmarshaller. Issue: SPR-10714
spring-oxm/src/main/java/org/springframework/oxm/jaxb/ClassPathJaxb2TypeScanner.java
@@ -19,7 +19,9 @@ import java.io.IOException; import java.util.ArrayList; import java.util.List; + import javax.xml.bind.annotation.XmlEnum; +import javax.xml.bind.annotation.XmlRegistry; import javax.xml.bind.annotation.XmlRootElement; import javax.xml.bind.annotation.XmlSeeAlso; import javax.xml.bind.annotation.XmlType; @@ -42,6 +44,7 @@ * @author Arjen Poutsma * @author Juergen Hoeller * @author David Harrigan + * @author Biju Kunjummen * @since 3.1.1 * @see #scanPackages() */ @@ -50,8 +53,11 @@ class ClassPathJaxb2TypeScanner { private static final String RESOURCE_PATTERN = "/**/*.class"; private static final TypeFilter[] JAXB2_TYPE_FILTERS = new TypeFilter[] { - new AnnotationTypeFilter(XmlRootElement.class, false), new AnnotationTypeFilter(XmlType.class, false), - new AnnotationTypeFilter(XmlSeeAlso.class, false), new AnnotationTypeFilter(XmlEnum.class, false)}; + new AnnotationTypeFilter(XmlRootElement.class, false), + new AnnotationTypeFilter(XmlType.class, false), + new AnnotationTypeFilter(XmlSeeAlso.class, false), + new AnnotationTypeFilter(XmlEnum.class, false), + new AnnotationTypeFilter(XmlRegistry.class, false)}; private final ResourcePatternResolver resourcePatternResolver;
true
Other
spring-projects
spring-framework
4f871d444864d001a049e7817a84f1c59c70016f.json
Fix Jaxb2TypeScanner to scan for @XmlRegistry Update ClassPathJaxb2TypeScanner to scan for @XmlRegistry classes. Prior to this commit explicitly configured @XmlRegistry annotated classes were not registered with the JAXBContext when using the 'packagesToScan' property of the Jaxb2Unmarshaller. Issue: SPR-10714
spring-oxm/src/test/java/org/springframework/oxm/jaxb/Airplane.java
@@ -0,0 +1,35 @@ +/* + * Copyright 2002-2013 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 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package org.springframework.oxm.jaxb; + +import javax.xml.bind.annotation.XmlRootElement; + +@XmlRootElement +public class Airplane { + + private String name; + + + public String getName() { + return name; + } + + public void setName(String name) { + this.name = name; + } + +}
true
Other
spring-projects
spring-framework
4f871d444864d001a049e7817a84f1c59c70016f.json
Fix Jaxb2TypeScanner to scan for @XmlRegistry Update ClassPathJaxb2TypeScanner to scan for @XmlRegistry classes. Prior to this commit explicitly configured @XmlRegistry annotated classes were not registered with the JAXBContext when using the 'packagesToScan' property of the Jaxb2Unmarshaller. Issue: SPR-10714
spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2MarshallerTests.java
@@ -51,10 +51,15 @@ import org.xml.sax.ContentHandler; import org.xml.sax.Locator; -import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; + import static org.junit.Assert.*; +import static org.custommonkey.xmlunit.XMLAssert.assertXMLEqual; import static org.mockito.BDDMockito.*; +/** + * @author Arjen Poutsma + * @author Biju Kunjummen + */ public class Jaxb2MarshallerTests extends AbstractMarshallerTests { private static final String CONTEXT_PATH = "org.springframework.oxm.jaxb.test"; @@ -281,6 +286,21 @@ public void marshalAttachments() throws Exception { verify(mimeContainer, times(3)).addAttachment(isA(String.class), isA(DataHandler.class)); } + @Test + public void marshalAWrappedObjectHoldingAnXmlElementDeclElement() throws Exception { + // SPR-10714 + marshaller = new Jaxb2Marshaller(); + marshaller.setPackagesToScan(new String[] { "org.springframework.oxm.jaxb" }); + marshaller.afterPropertiesSet(); + Airplane airplane = new Airplane(); + airplane.setName("test"); + StringWriter writer = new StringWriter(); + Result result = new StreamResult(writer); + marshaller.marshal(airplane, result); + assertXMLEqual("Marshalling should use root Element", + writer.toString(), "<airplane><name>test</name></airplane>"); + } + @XmlRootElement @SuppressWarnings("unused") public static class DummyRootElement {
true
Other
spring-projects
spring-framework
4f871d444864d001a049e7817a84f1c59c70016f.json
Fix Jaxb2TypeScanner to scan for @XmlRegistry Update ClassPathJaxb2TypeScanner to scan for @XmlRegistry classes. Prior to this commit explicitly configured @XmlRegistry annotated classes were not registered with the JAXBContext when using the 'packagesToScan' property of the Jaxb2Unmarshaller. Issue: SPR-10714
spring-oxm/src/test/java/org/springframework/oxm/jaxb/Jaxb2UnmarshallerTests.java
@@ -39,6 +39,10 @@ import static org.junit.Assert.*; import static org.mockito.BDDMockito.*; +/** + * @author Arjen Poutsma + * @author Biju Kunjummen + */ public class Jaxb2UnmarshallerTests extends AbstractUnmarshallerTests { private static final String INPUT_STRING = "<tns:flights xmlns:tns=\"http://samples.springframework.org/flight\">" + @@ -104,6 +108,7 @@ protected void testFlight(Object o) { @Test @Override + @SuppressWarnings("unchecked") public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception { XMLInputFactory inputFactory = XMLInputFactory.newInstance(); XMLStreamReader streamReader = inputFactory.createXMLStreamReader(new StringReader(INPUT_STRING)); @@ -115,5 +120,18 @@ public void unmarshalPartialStaxSourceXmlStreamReader() throws Exception { testFlight(flight); } + @Test + @SuppressWarnings("unchecked") + public void unmarshalAnXmlReferingToAWrappedXmlElementDecl() throws Exception { + // SPR-10714 + unmarshaller = new Jaxb2Marshaller(); + unmarshaller.setPackagesToScan(new String[] { "org.springframework.oxm.jaxb" }); + unmarshaller.afterPropertiesSet(); + Source source = new StreamSource(new StringReader( + "<brand-airplane><name>test</name></brand-airplane>")); + JAXBElement<Airplane> airplane = (JAXBElement<Airplane>) unmarshaller.unmarshal(source); + assertEquals("Unmarshalling via explicit @XmlRegistry tag should return correct type", + "test", airplane.getValue().getName()); + } }
true
Other
spring-projects
spring-framework
4f871d444864d001a049e7817a84f1c59c70016f.json
Fix Jaxb2TypeScanner to scan for @XmlRegistry Update ClassPathJaxb2TypeScanner to scan for @XmlRegistry classes. Prior to this commit explicitly configured @XmlRegistry annotated classes were not registered with the JAXBContext when using the 'packagesToScan' property of the Jaxb2Unmarshaller. Issue: SPR-10714
spring-oxm/src/test/java/org/springframework/oxm/jaxb/XmlRegObjectFactory.java
@@ -0,0 +1,16 @@ + +package org.springframework.oxm.jaxb; + +import javax.xml.bind.JAXBElement; +import javax.xml.bind.annotation.XmlElementDecl; +import javax.xml.bind.annotation.XmlRegistry; +import javax.xml.namespace.QName; + +@XmlRegistry +public class XmlRegObjectFactory { + + @XmlElementDecl(name = "brand-airplane") + public JAXBElement<Airplane> createAirplane(Airplane airplane) { + return new JAXBElement<Airplane>(new QName("brand-airplane"), Airplane.class, null, airplane); + } +} \ No newline at end of file
true
Other
spring-projects
spring-framework
bc5246938d07820305167e581e7a8ece23ed265e.json
Fix ResourceHttpRequestHandler empty location log Fix ResourceHttpRequestHandler to only log warning when locations is empty. Issue: SPR-10780
spring-webmvc/src/main/java/org/springframework/web/servlet/resource/ResourceHttpRequestHandler.java
@@ -1,5 +1,5 @@ /* - * Copyright 2002-2012 the original author or authors. + * Copyright 2002-2013 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. @@ -34,6 +34,7 @@ import org.springframework.http.MediaType; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; +import org.springframework.util.CollectionUtils; import org.springframework.util.FileCopyUtils; import org.springframework.util.StringUtils; import org.springframework.web.HttpRequestHandler; @@ -95,7 +96,7 @@ public void setLocations(List<Resource> locations) { @Override public void afterPropertiesSet() throws Exception { - if (logger.isWarnEnabled()) { + if (logger.isWarnEnabled() && CollectionUtils.isEmpty(this.locations)) { logger.warn("Locations list is empty. No resources will be served"); } }
false
Other
spring-projects
spring-framework
eda60529375b1b4c420f682834e328473bb66bfe.json
Release version 4.0.0.M2
gradle.properties
@@ -1 +1 @@ -version=4.0.0.BUILD-SNAPSHOT +version=4.0.0.M2
false
Other
spring-projects
spring-framework
50333ca68ede797bf40623f95591fe6a2348edca.json
Add Java 7 instrumentation manifest attributes Update META-INF/MANIFEST.MF for spring-instrument to include necessary attributes for running under Java 7: Can-Redefine-Classes : true Can-Retransform-Classes: true Can-Set-Native-Method-Prefix : false (see http://docs.oracle.com/javase/7/docs/api/java/lang/instrument/ package-summary.html) Prior to this commit `InstrumentationSavingAgent.getInstrumentation(). addTransformer(t, true);` would fail under Java 7. Issue: SPR-10731
build.gradle
@@ -267,6 +267,9 @@ project("spring-instrument") { jar { manifest.attributes["Premain-Class"] = "org.springframework.instrument.InstrumentationSavingAgent" + manifest.attributes["Can-Redefine-Classes"] = "true" + manifest.attributes["Can-Retransform-Classes"] = "true" + manifest.attributes["Can-Set-Native-Method-Prefix"] = "false" } }
false
Other
spring-projects
spring-framework
4500bf7661493aa236510a4151cd58f7af66e9dd.json
Fix malformed Javadoc
spring-webmvc/src/main/java/org/springframework/web/servlet/tags/MessageTag.java
@@ -44,7 +44,7 @@ * message. Thus, this tag can also be used for HTML escaping of any texts. * * <p>Message arguments can be specified via the {@link #setArguments(Object) arguments} - * attribute or by using nested {@code &lt;spring:argument&gt;} tags. + * attribute or by using nested {@code <spring:argument>} tags. * * @author Rod Johnson * @author Juergen Hoeller
true
Other
spring-projects
spring-framework
4500bf7661493aa236510a4151cd58f7af66e9dd.json
Fix malformed Javadoc
spring-webmvc/src/main/java/org/springframework/web/servlet/tags/ThemeTag.java
@@ -31,7 +31,7 @@ * as default message. * * <p>Message arguments can be specified via the {@link #setArguments(Object) arguments} - * attribute or by using nested {@code &lt;spring:argument&gt;} tags. + * attribute or by using nested {@code <spring:argument>} tags. * * @author Jean-Pierre Pawlak * @author Juergen Hoeller
true
Other
spring-projects
spring-framework
915e93cc813508b6e7839d06b66d225fbb685ac7.json
Update TLD versions to 4.0
spring-webmvc/src/main/resources/META-INF/spring-form.tld
@@ -5,7 +5,7 @@ version="2.0"> <description>Spring Framework JSP Form Tag Library</description> - <tlib-version>3.0</tlib-version> + <tlib-version>4.0</tlib-version> <short-name>form</short-name> <uri>http://www.springframework.org/tags/form</uri>
true
Other
spring-projects
spring-framework
915e93cc813508b6e7839d06b66d225fbb685ac7.json
Update TLD versions to 4.0
spring-webmvc/src/main/resources/META-INF/spring.tld
@@ -5,7 +5,7 @@ version="2.0"> <description>Spring Framework JSP Tag Library</description> - <tlib-version>3.0</tlib-version> + <tlib-version>4.0</tlib-version> <short-name>spring</short-name> <uri>http://www.springframework.org/tags</uri>
true
Other
spring-projects
spring-framework
02949fc4a7248c0e329f688c3ae2a1a8eb048e6e.json
Fix failing tests
spring-messaging/src/main/java/org/springframework/messaging/simp/handler/AnnotationMethodMessageHandler.java
@@ -61,6 +61,7 @@ import org.springframework.stereotype.Controller; import org.springframework.util.Assert; import org.springframework.util.ClassUtils; +import org.springframework.util.CollectionUtils; import org.springframework.util.ReflectionUtils.MethodFilter; @@ -270,11 +271,12 @@ private void handleMessageInternal(final Message<?> message, Map<MappingInfo, Ha } private boolean checkDestinationPrefix(String destination) { - if ((destination != null) && (this.destinationPrefixes != null)) { - for (String prefix : this.destinationPrefixes) { - if (destination.startsWith(prefix)) { - return true; - } + if ((destination == null) || CollectionUtils.isEmpty(this.destinationPrefixes)) { + return true; + } + for (String prefix : this.destinationPrefixes) { + if (destination.startsWith(prefix)) { + return true; } } return false;
true
Other
spring-projects
spring-framework
02949fc4a7248c0e329f688c3ae2a1a8eb048e6e.json
Fix failing tests
spring-messaging/src/main/java/org/springframework/messaging/simp/handler/SimpleBrokerMessageHandler.java
@@ -28,6 +28,7 @@ import org.springframework.messaging.simp.SimpMessageType; import org.springframework.messaging.support.MessageBuilder; import org.springframework.util.Assert; +import org.springframework.util.CollectionUtils; import org.springframework.util.MultiValueMap; @@ -103,11 +104,12 @@ else if (SimpMessageType.DISCONNECT.equals(messageType)) { } private boolean checkDestinationPrefix(String destination) { - if ((destination != null) && (this.destinationPrefixes != null)) { - for (String prefix : this.destinationPrefixes) { - if (destination.startsWith(prefix)) { - return true; - } + if ((destination == null) || CollectionUtils.isEmpty(this.destinationPrefixes)) { + return true; + } + for (String prefix : this.destinationPrefixes) { + if (destination.startsWith(prefix)) { + return true; } } return false;
true
Other
spring-projects
spring-framework
02949fc4a7248c0e329f688c3ae2a1a8eb048e6e.json
Fix failing tests
spring-messaging/src/test/java/org/springframework/messaging/simp/handler/SimpleBrokerMessageHandlerTests.java
@@ -36,7 +36,7 @@ * @author Rossen Stoyanchev * @since 4.0 */ -public class SimpleBrokerWebMessageHandlerTests { +public class SimpleBrokerMessageHandlerTests { private SimpleBrokerMessageHandler messageHandler;
true
Other
spring-projects
spring-framework
f86a3283be6ddd209786a81cd892b16154105799.json
Add Java SE Javadoc links Issue: SPR-10587
build.gradle
@@ -79,6 +79,7 @@ configure(allprojects) { project -> } ext.javadocLinks = [ + "http://docs.oracle.com/javase/7/docs/api/", "http://docs.oracle.com/javaee/6/api/", "http://docs.oracle.com/cd/E13222_01/wls/docs90/javadocs/", // CommonJ "http://pic.dhe.ibm.com/infocenter/wasinfo/v7r0/topic/com.ibm.websphere.javadoc.doc/web/apidocs/",
false
Other
spring-projects
spring-framework
1a8f0d6a9e37d12b31a2fe7bc1fbc2c91700a08e.json
Resolve ${} placeholders in @ImportResource Update ConfigurationClassParser to resolve any ${} placeholders from @ImportResource values. Issue: SPR-10686
spring-context/src/main/java/org/springframework/context/annotation/ConfigurationClassParser.java
@@ -257,7 +257,8 @@ protected final SourceClass doProcessConfigurationClass( String[] resources = importResource.getStringArray("value"); Class<? extends BeanDefinitionReader> readerClass = importResource.getClass("reader"); for (String resource : resources) { - configClass.addImportedResource(resource, readerClass); + String resolvedResource = this.environment.resolveRequiredPlaceholders(resource); + configClass.addImportedResource(resolvedResource, readerClass); } }
true
Other
spring-projects
spring-framework
1a8f0d6a9e37d12b31a2fe7bc1fbc2c91700a08e.json
Resolve ${} placeholders in @ImportResource Update ConfigurationClassParser to resolve any ${} placeholders from @ImportResource values. Issue: SPR-10686
spring-context/src/test/java/org/springframework/context/annotation/configuration/ImportResourceTests.java
@@ -16,14 +16,17 @@ package org.springframework.context.annotation.configuration; +import java.util.Collections; + import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Before; + import static org.hamcrest.CoreMatchers.*; import static org.junit.Assert.*; + import org.junit.Ignore; import org.junit.Test; import org.springframework.tests.sample.beans.TestBean; - import org.springframework.aop.support.AopUtils; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; @@ -34,6 +37,8 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.ImportResource; +import org.springframework.core.env.MapPropertySource; +import org.springframework.core.env.PropertySource; /** * Integration tests for {@link ImportResource} support. @@ -178,4 +183,22 @@ public void testImportDifferentResourceTypes() { reader=XmlBeanDefinitionReader.class) static class SubResourceConfig extends ImportNonXmlResourceConfig { } + + @Test + public void importWithPlaceHolder() throws Exception { + AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); + PropertySource<?> propertySource = new MapPropertySource("test", + Collections.<String, Object> singletonMap("test", "springframework")); + ctx.getEnvironment().getPropertySources().addFirst(propertySource); + ctx.register(ImportXmlConfig.class); + ctx.refresh(); + assertTrue("did not contain xml-declared bean", ctx.containsBean("xmlDeclaredBean")); + } + + @Configuration + @ImportResource("classpath:org/${test}/context/annotation/configuration/ImportXmlConfig-context.xml") + static class ImportWithPlaceHolder { + } + + }
true
Other
spring-projects
spring-framework
7bab8796237a1104dd21413a3e96c311bab1889d.json
Fix issue with xpath assertions in Spring Test MVC Issue: SPR-10704
spring-test-mvc/src/main/java/org/springframework/test/util/XpathExpectationsHelper.java
@@ -16,9 +16,6 @@ package org.springframework.test.util; -import static org.springframework.test.util.AssertionErrors.*; -import static org.springframework.test.util.MatcherAssertionErrors.*; - import java.io.StringReader; import java.util.Collections; import java.util.Map; @@ -33,12 +30,16 @@ import javax.xml.xpath.XPathFactory; import org.hamcrest.Matcher; +import org.springframework.util.CollectionUtils; import org.springframework.util.xml.SimpleNamespaceContext; import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; import org.xml.sax.InputSource; +import static org.springframework.test.util.AssertionErrors.*; +import static org.springframework.test.util.MatcherAssertionErrors.*; + /** * A helper class for applying assertions via XPath expressions. * @@ -51,6 +52,8 @@ public class XpathExpectationsHelper { private final XPathExpression xpathExpression; + private final boolean hasNamespaces; + /** * Class constructor. @@ -66,6 +69,7 @@ public XpathExpectationsHelper(String expression, Map<String, String> namespaces this.expression = String.format(expression, args); this.xpathExpression = compileXpathExpression(this.expression, namespaces); + this.hasNamespaces = !CollectionUtils.isEmpty(namespaces); } private XPathExpression compileXpathExpression(String expression, Map<String, String> namespaces) @@ -104,7 +108,7 @@ public void assertNode(String content, final Matcher<? super Node> matcher) thro */ protected Document parseXmlString(String xml) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); + factory.setNamespaceAware(this.hasNamespaces); DocumentBuilder documentBuilder = factory.newDocumentBuilder(); InputSource inputSource = new InputSource(new StringReader(xml)); Document document = documentBuilder.parse(inputSource);
true
Other
spring-projects
spring-framework
7bab8796237a1104dd21413a3e96c311bab1889d.json
Fix issue with xpath assertions in Spring Test MVC Issue: SPR-10704
spring-test-mvc/src/test/java/org/springframework/test/web/servlet/samples/standalone/resultmatchers/XpathAssertionTests.java
@@ -16,17 +16,6 @@ package org.springframework.test.web.servlet.samples.standalone.resultmatchers; -import static org.hamcrest.Matchers.closeTo; -import static org.hamcrest.Matchers.equalTo; -import static org.hamcrest.Matchers.notNullValue; -import static org.hamcrest.Matchers.nullValue; -import static org.hamcrest.Matchers.startsWith; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.xpath; -import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; - import java.util.Arrays; import java.util.Collections; import java.util.List; @@ -47,6 +36,12 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.ResponseBody; +import static org.hamcrest.Matchers.*; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; +import static org.springframework.test.web.servlet.setup.MockMvcBuilders.*; +import static org.springframework.web.bind.annotation.RequestMethod.*; + /** * Examples of expectations on XML response content with XPath expressions. * @@ -57,7 +52,7 @@ */ public class XpathAssertionTests { - private static final Map<String, String> NS = + private static final Map<String, String> musicNamespace = Collections.singletonMap("ns", "http://example.org/music/people"); private MockMvc mockMvc; @@ -78,13 +73,13 @@ public void testExists() throws Exception { String performer = "/ns:people/performers/performer[%s]"; this.mockMvc.perform(get("/music/people")) - .andExpect(xpath(composer, NS, 1).exists()) - .andExpect(xpath(composer, NS, 2).exists()) - .andExpect(xpath(composer, NS, 3).exists()) - .andExpect(xpath(composer, NS, 4).exists()) - .andExpect(xpath(performer, NS, 1).exists()) - .andExpect(xpath(performer, NS, 2).exists()) - .andExpect(xpath(composer, NS, 1).node(notNullValue())); + .andExpect(xpath(composer, musicNamespace, 1).exists()) + .andExpect(xpath(composer, musicNamespace, 2).exists()) + .andExpect(xpath(composer, musicNamespace, 3).exists()) + .andExpect(xpath(composer, musicNamespace, 4).exists()) + .andExpect(xpath(performer, musicNamespace, 1).exists()) + .andExpect(xpath(performer, musicNamespace, 2).exists()) + .andExpect(xpath(composer, musicNamespace, 1).node(notNullValue())); } @Test @@ -94,11 +89,11 @@ public void testDoesNotExist() throws Exception { String performer = "/ns:people/performers/performer[%s]"; this.mockMvc.perform(get("/music/people")) - .andExpect(xpath(composer, NS, 0).doesNotExist()) - .andExpect(xpath(composer, NS, 5).doesNotExist()) - .andExpect(xpath(performer, NS, 0).doesNotExist()) - .andExpect(xpath(performer, NS, 3).doesNotExist()) - .andExpect(xpath(composer, NS, 0).node(nullValue())); + .andExpect(xpath(composer, musicNamespace, 0).doesNotExist()) + .andExpect(xpath(composer, musicNamespace, 5).doesNotExist()) + .andExpect(xpath(performer, musicNamespace, 0).doesNotExist()) + .andExpect(xpath(performer, musicNamespace, 3).doesNotExist()) + .andExpect(xpath(composer, musicNamespace, 0).node(nullValue())); } @Test @@ -108,15 +103,15 @@ public void testString() throws Exception { String performerName = "/ns:people/performers/performer[%s]/name"; this.mockMvc.perform(get("/music/people")) - .andExpect(xpath(composerName, NS, 1).string("Johann Sebastian Bach")) - .andExpect(xpath(composerName, NS, 2).string("Johannes Brahms")) - .andExpect(xpath(composerName, NS, 3).string("Edvard Grieg")) - .andExpect(xpath(composerName, NS, 4).string("Robert Schumann")) - .andExpect(xpath(performerName, NS, 1).string("Vladimir Ashkenazy")) - .andExpect(xpath(performerName, NS, 2).string("Yehudi Menuhin")) - .andExpect(xpath(composerName, NS, 1).string(equalTo("Johann Sebastian Bach"))) // Hamcrest.. - .andExpect(xpath(composerName, NS, 1).string(startsWith("Johann"))) - .andExpect(xpath(composerName, NS, 1).string(notNullValue())); + .andExpect(xpath(composerName, musicNamespace, 1).string("Johann Sebastian Bach")) + .andExpect(xpath(composerName, musicNamespace, 2).string("Johannes Brahms")) + .andExpect(xpath(composerName, musicNamespace, 3).string("Edvard Grieg")) + .andExpect(xpath(composerName, musicNamespace, 4).string("Robert Schumann")) + .andExpect(xpath(performerName, musicNamespace, 1).string("Vladimir Ashkenazy")) + .andExpect(xpath(performerName, musicNamespace, 2).string("Yehudi Menuhin")) + .andExpect(xpath(composerName, musicNamespace, 1).string(equalTo("Johann Sebastian Bach"))) // Hamcrest.. + .andExpect(xpath(composerName, musicNamespace, 1).string(startsWith("Johann"))) + .andExpect(xpath(composerName, musicNamespace, 1).string(notNullValue())); } @Test @@ -125,12 +120,12 @@ public void testNumber() throws Exception { String composerDouble = "/ns:people/composers/composer[%s]/someDouble"; this.mockMvc.perform(get("/music/people")) - .andExpect(xpath(composerDouble, NS, 1).number(21d)) - .andExpect(xpath(composerDouble, NS, 2).number(.0025)) - .andExpect(xpath(composerDouble, NS, 3).number(1.6035)) - .andExpect(xpath(composerDouble, NS, 4).number(Double.NaN)) - .andExpect(xpath(composerDouble, NS, 1).number(equalTo(21d))) // Hamcrest.. - .andExpect(xpath(composerDouble, NS, 3).number(closeTo(1.6, .01))); + .andExpect(xpath(composerDouble, musicNamespace, 1).number(21d)) + .andExpect(xpath(composerDouble, musicNamespace, 2).number(.0025)) + .andExpect(xpath(composerDouble, musicNamespace, 3).number(1.6035)) + .andExpect(xpath(composerDouble, musicNamespace, 4).number(Double.NaN)) + .andExpect(xpath(composerDouble, musicNamespace, 1).number(equalTo(21d))) // Hamcrest.. + .andExpect(xpath(composerDouble, musicNamespace, 3).number(closeTo(1.6, .01))); } @Test @@ -139,20 +134,36 @@ public void testBoolean() throws Exception { String performerBooleanValue = "/ns:people/performers/performer[%s]/someBoolean"; this.mockMvc.perform(get("/music/people")) - .andExpect(xpath(performerBooleanValue, NS, 1).booleanValue(false)) - .andExpect(xpath(performerBooleanValue, NS, 2).booleanValue(true)); + .andExpect(xpath(performerBooleanValue, musicNamespace, 1).booleanValue(false)) + .andExpect(xpath(performerBooleanValue, musicNamespace, 2).booleanValue(true)); } @Test public void testNodeCount() throws Exception { this.mockMvc.perform(get("/music/people")) - .andExpect(xpath("/ns:people/composers/composer", NS).nodeCount(4)) - .andExpect(xpath("/ns:people/performers/performer", NS).nodeCount(2)) - .andExpect(xpath("/ns:people/composers/composer", NS).nodeCount(equalTo(4))) // Hamcrest.. - .andExpect(xpath("/ns:people/performers/performer", NS).nodeCount(equalTo(2))); + .andExpect(xpath("/ns:people/composers/composer", musicNamespace).nodeCount(4)) + .andExpect(xpath("/ns:people/performers/performer", musicNamespace).nodeCount(2)) + .andExpect(xpath("/ns:people/composers/composer", musicNamespace).nodeCount(equalTo(4))) // Hamcrest.. + .andExpect(xpath("/ns:people/performers/performer", musicNamespace).nodeCount(equalTo(2))); + } + + // SPR-10704 + + @Test + public void testFeedWithLinefeedChars() throws Exception { + +// Map<String, String> namespace = Collections.singletonMap("ns", ""); + + standaloneSetup(new BlogFeedController()).build() + .perform(get("/blog.atom").accept(MediaType.APPLICATION_ATOM_XML)) + .andExpect(status().isOk()) + .andExpect(content().contentType(MediaType.APPLICATION_ATOM_XML)) + .andExpect(xpath("//feed/title").string("Test Feed")) + .andExpect(xpath("//feed/icon").string("http://www.example.com/favicon.ico")); } + @Controller private static class MusicController { @@ -203,4 +214,19 @@ public List<Person> getPerformers() { } } + + @Controller + public class BlogFeedController { + + @RequestMapping(value="/blog.atom", method = { GET, HEAD }) + @ResponseBody + public String listPublishedPosts() { + return "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n" + + "<feed xmlns=\"http://www.w3.org/2005/Atom\">\r\n" + + " <title>Test Feed</title>\r\n" + + " <icon>http://www.example.com/favicon.ico</icon>\r\n" + + "</feed>\r\n\r\n"; + } + } + }
true
Other
spring-projects
spring-framework
82ec06ad349426acf663f8edc22dd7716c4ff2cd.json
Fix bug in SockJS JsonpTransportHandler Issue: SPR-10621
spring-websocket/src/main/java/org/springframework/web/socket/sockjs/transport/JsonpTransportHandler.java
@@ -61,7 +61,8 @@ public void handleRequestInternal(ServerHttpRequest request, ServerHttpResponse @Override protected String[] readMessages(ServerHttpRequest request) throws IOException { - if (MediaType.APPLICATION_FORM_URLENCODED.equals(request.getHeaders().getContentType())) { + MediaType contentType = request.getHeaders().getContentType(); + if ((contentType != null) && MediaType.APPLICATION_FORM_URLENCODED.isCompatibleWith(contentType)) { MultiValueMap<String, String> map = this.formConverter.read(null, request); String d = map.getFirst("d"); return (StringUtils.hasText(d)) ? getObjectMapper().readValue(d, String[].class) : null;
true
Other
spring-projects
spring-framework
82ec06ad349426acf663f8edc22dd7716c4ff2cd.json
Fix bug in SockJS JsonpTransportHandler Issue: SPR-10621
spring-websocket/src/test/java/org/springframework/web/socket/sockjs/transport/HttpReceivingTransportHandlerTests.java
@@ -73,6 +73,18 @@ public void readMessagesJsonpFormEncoded() throws Exception { assertEquals("ok", this.servletResponse.getContentAsString()); } + // SPR-10621 + + @Test + public void readMessagesJsonpFormEncodedWithEncoding() throws Exception { + this.servletRequest.setContent("d=[\"x\"]".getBytes("UTF-8")); + this.servletRequest.setContentType("application/x-www-form-urlencoded;charset=UTF-8"); + handleRequest(new JsonpTransportHandler()); + + assertEquals(200, this.servletResponse.getStatus()); + assertEquals("ok", this.servletResponse.getContentAsString()); + } + @Test public void readMessagesBadContent() throws Exception { this.servletRequest.setContent("".getBytes("UTF-8"));
true
Other
spring-projects
spring-framework
2a15b5a89585c24203e32537b0306cff45076638.json
Enable asyncSupported flag in Spring Test MVC Also remove Servlet 3 bridge classes no longer needed since Spring Framework 4 compiles with the Servlet 3 API. That means applications may need to run tests with the Servlet 3 API jar although technically they don't have to run with that in production.
spring-test-mvc/src/main/java/org/springframework/test/web/servlet/request/MockAsyncContext.java
@@ -1,145 +0,0 @@ -/* - * Copyright 2002-2012 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 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.test.web.servlet.request; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import javax.servlet.AsyncContext; -import javax.servlet.AsyncEvent; -import javax.servlet.AsyncListener; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - -import org.springframework.beans.BeanUtils; -import org.springframework.mock.web.MockHttpServletRequest; -import org.springframework.mock.web.MockHttpServletResponse; -import org.springframework.web.util.WebUtils; - -/** - * Mock implementation of the {@link AsyncContext} interface. - * - * @author Rossen Stoyanchev - * @since 3.2 - */ -class MockAsyncContext implements AsyncContext { - - private final HttpServletRequest request; - - private final HttpServletResponse response; - - private final List<AsyncListener> listeners = new ArrayList<AsyncListener>(); - - private String dispatchedPath; - - private long timeout = 10 * 1000L; // 10 seconds is Tomcat's default - - - public MockAsyncContext(ServletRequest request, ServletResponse response) { - this.request = (HttpServletRequest) request; - this.response = (HttpServletResponse) response; - } - - @Override - public ServletRequest getRequest() { - return this.request; - } - - @Override - public ServletResponse getResponse() { - return this.response; - } - - @Override - public boolean hasOriginalRequestAndResponse() { - return (this.request instanceof MockHttpServletRequest) && (this.response instanceof MockHttpServletResponse); - } - - public String getDispatchedPath() { - return this.dispatchedPath; - } - - @Override - public void dispatch() { - dispatch(this.request.getRequestURI()); - } - - @Override - public void dispatch(String path) { - dispatch(null, path); - } - - @Override - public void dispatch(ServletContext context, String path) { - this.dispatchedPath = path; - } - - @Override - public void complete() { - Servlet3MockHttpServletRequest mockRequest = WebUtils.getNativeRequest(request, Servlet3MockHttpServletRequest.class); - if (mockRequest != null) { - mockRequest.setAsyncStarted(false); - } - for (AsyncListener listener : this.listeners) { - try { - listener.onComplete(new AsyncEvent(this, this.request, this.response)); - } - catch (IOException e) { - throw new IllegalStateException("AsyncListener failure", e); - } - } - } - - @Override - public void start(Runnable runnable) { - runnable.run(); - } - - public List<AsyncListener> getListeners() { - return this.listeners; - } - - @Override - public void addListener(AsyncListener listener) { - this.listeners.add(listener); - } - - @Override - public void addListener(AsyncListener listener, ServletRequest request, ServletResponse response) { - this.listeners.add(listener); - } - - @Override - public <T extends AsyncListener> T createListener(Class<T> clazz) throws ServletException { - return BeanUtils.instantiateClass(clazz); - } - - @Override - public long getTimeout() { - return this.timeout; - } - - @Override - public void setTimeout(long timeout) { - this.timeout = timeout; - } - -}
true
Other
spring-projects
spring-framework
2a15b5a89585c24203e32537b0306cff45076638.json
Enable asyncSupported flag in Spring Test MVC Also remove Servlet 3 bridge classes no longer needed since Spring Framework 4 compiles with the Servlet 3 API. That means applications may need to run tests with the Servlet 3 API jar although technically they don't have to run with that in production.
spring-test-mvc/src/main/java/org/springframework/test/web/servlet/request/MockHttpServletRequestBuilder.java
@@ -653,6 +653,8 @@ public final MockHttpServletRequest buildRequest(ServletContext servletContext) Assert.notNull(request, "Post-processor [" + postProcessor.getClass().getName() + "] returned null"); } + request.setAsyncSupported(true); + return request; }
true
Other
spring-projects
spring-framework
2a15b5a89585c24203e32537b0306cff45076638.json
Enable asyncSupported flag in Spring Test MVC Also remove Servlet 3 bridge classes no longer needed since Spring Framework 4 compiles with the Servlet 3 API. That means applications may need to run tests with the Servlet 3 API jar although technically they don't have to run with that in production.
spring-test-mvc/src/main/java/org/springframework/test/web/servlet/request/Servlet3MockHttpServletRequest.java
@@ -1,114 +0,0 @@ -/* - * Copyright 2002-2012 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 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.test.web.servlet.request; - -import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.AsyncContext; -import javax.servlet.DispatcherType; -import javax.servlet.ServletContext; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.Part; - -import org.springframework.mock.web.MockHttpServletRequest; - -/** - * A Servlet 3 sub-class of MockHttpServletRequest. - * - * @author Rossen Stoyanchev - * @since 3.2 - */ -class Servlet3MockHttpServletRequest extends MockHttpServletRequest { - - private boolean asyncStarted; - - private MockAsyncContext asyncContext; - - private Map<String, Part> parts = new HashMap<String, Part>(); - - - public Servlet3MockHttpServletRequest(ServletContext servletContext) { - super(servletContext); - } - - @Override - public boolean isAsyncSupported() { - return true; - } - - @Override - public AsyncContext startAsync() { - return startAsync(this, null); - } - - @Override - public AsyncContext startAsync(ServletRequest request, ServletResponse response) { - this.asyncStarted = true; - this.asyncContext = new MockAsyncContext(request, response); - return this.asyncContext; - } - - @Override - public AsyncContext getAsyncContext() { - return this.asyncContext; - } - - public void setAsyncContext(MockAsyncContext asyncContext) { - this.asyncContext = asyncContext; - } - - @Override - public DispatcherType getDispatcherType() { - return DispatcherType.REQUEST; - } - - @Override - public boolean isAsyncStarted() { - return this.asyncStarted; - } - - @Override - public void setAsyncStarted(boolean asyncStarted) { - this.asyncStarted = asyncStarted; - } - - @Override - public void addPart(Part part) { - this.parts.put(part.getName(), part); - } - - @Override - public Part getPart(String key) throws IOException, IllegalStateException, ServletException { - return this.parts.get(key); - } - - @Override - public Collection<Part> getParts() throws IOException, IllegalStateException, ServletException { - return this.parts.values(); - } - - @Override - public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { - throw new UnsupportedOperationException(); - } - -}
true
Other
spring-projects
spring-framework
2a15b5a89585c24203e32537b0306cff45076638.json
Enable asyncSupported flag in Spring Test MVC Also remove Servlet 3 bridge classes no longer needed since Spring Framework 4 compiles with the Servlet 3 API. That means applications may need to run tests with the Servlet 3 API jar although technically they don't have to run with that in production.
spring-test-mvc/src/main/java/org/springframework/test/web/servlet/request/Servlet3MockMultipartHttpServletRequest.java
@@ -1,109 +0,0 @@ -/* - * Copyright 2002-2012 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 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.test.web.servlet.request; - -import java.io.IOException; -import java.util.Collection; -import java.util.HashMap; -import java.util.Map; - -import javax.servlet.AsyncContext; -import javax.servlet.DispatcherType; -import javax.servlet.ServletException; -import javax.servlet.ServletRequest; -import javax.servlet.ServletResponse; -import javax.servlet.http.HttpServletResponse; -import javax.servlet.http.Part; - -import org.springframework.mock.web.MockMultipartHttpServletRequest; - -/** - * A Servlet 3 sub-class of MockMultipartHttpServletRequest. - * - * @author Rossen Stoyanchev - * @since 3.2 - */ -class Servlet3MockMultipartHttpServletRequest extends MockMultipartHttpServletRequest { - - private boolean asyncStarted; - - private MockAsyncContext asyncContext; - - private Map<String, Part> parts = new HashMap<String, Part>(); - - - @Override - public boolean isAsyncSupported() { - return true; - } - - @Override - public AsyncContext startAsync() { - return startAsync(this, null); - } - - @Override - public AsyncContext startAsync(ServletRequest request, ServletResponse response) { - this.asyncStarted = true; - this.asyncContext = new MockAsyncContext(request, response); - return this.asyncContext; - } - - @Override - public AsyncContext getAsyncContext() { - return this.asyncContext; - } - - public void setAsyncContext(MockAsyncContext asyncContext) { - this.asyncContext = asyncContext; - } - - @Override - public DispatcherType getDispatcherType() { - return DispatcherType.REQUEST; - } - - @Override - public boolean isAsyncStarted() { - return this.asyncStarted; - } - - @Override - public void setAsyncStarted(boolean asyncStarted) { - this.asyncStarted = asyncStarted; - } - - @Override - public void addPart(Part part) { - this.parts.put(part.getName(), part); - } - - @Override - public Part getPart(String key) throws IOException, IllegalStateException, ServletException { - return this.parts.get(key); - } - - @Override - public Collection<Part> getParts() throws IOException, IllegalStateException, ServletException { - return this.parts.values(); - } - - @Override - public boolean authenticate(HttpServletResponse response) throws IOException, ServletException { - throw new UnsupportedOperationException(); - } - -}
true
Other
spring-projects
spring-framework
2a15b5a89585c24203e32537b0306cff45076638.json
Enable asyncSupported flag in Spring Test MVC Also remove Servlet 3 bridge classes no longer needed since Spring Framework 4 compiles with the Servlet 3 API. That means applications may need to run tests with the Servlet 3 API jar although technically they don't have to run with that in production.
spring-test-mvc/src/main/java/org/springframework/test/web/servlet/setup/StandaloneMockMvcBuilder.java
@@ -47,6 +47,7 @@ import org.springframework.web.servlet.config.annotation.InterceptorRegistration; import org.springframework.web.servlet.config.annotation.InterceptorRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport; +import org.springframework.web.servlet.handler.AbstractHandlerMapping; import org.springframework.web.servlet.handler.MappedInterceptor; import org.springframework.web.servlet.i18n.AcceptHeaderLocaleResolver; import org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter; @@ -107,6 +108,8 @@ public class StandaloneMockMvcBuilder extends DefaultMockMvcBuilder<StandaloneMo private boolean useTrailingSlashPatternMatch = true; + private Boolean removeSemicolonContent; + /** * Protected constructor. Not intended for direct instantiation. @@ -274,6 +277,15 @@ public StandaloneMockMvcBuilder setUseTrailingSlashPatternMatch(boolean useTrail return this; } + /** + * Set if ";" (semicolon) content should be stripped from the request URI. The value, + * if provided, is in turn set on + * {@link AbstractHandlerMapping#setRemoveSemicolonContent(boolean)}. + */ + public void setRemoveSemicolonContent(boolean removeSemicolonContent) { + this.removeSemicolonContent = removeSemicolonContent; + } + @Override protected void initWebAppContext(WebApplicationContext cxt) { StubWebApplicationContext mockCxt = (StubWebApplicationContext) cxt; @@ -336,6 +348,10 @@ public RequestMappingHandlerMapping requestMappingHandlerMapping() { handlerMapping.setOrder(0); handlerMapping.setInterceptors(getInterceptors()); + if (removeSemicolonContent != null) { + handlerMapping.setRemoveSemicolonContent(removeSemicolonContent); + } + return handlerMapping; }
true
Other
spring-projects
spring-framework
860e56ea8447f30beb2edb7483485177e8c0c709.json
Fix minor issue in WebSocketHttpRequestHandler Issue: SPR-10721
spring-websocket/src/main/java/org/springframework/web/socket/server/support/WebSocketHttpRequestHandler.java
@@ -65,7 +65,7 @@ public WebSocketHttpRequestHandler( WebSocketHandler webSocketHandler, Handshake Assert.notNull(webSocketHandler, "webSocketHandler must not be null"); Assert.notNull(handshakeHandler, "handshakeHandler must not be null"); this.webSocketHandler = decorateWebSocketHandler(webSocketHandler); - this.handshakeHandler = new DefaultHandshakeHandler(); + this.handshakeHandler = handshakeHandler; }
false
Other
spring-projects
spring-framework
a109d6adc701e981eede518fd4b707b888ea4623.json
Set heartbeat to 0,0 on CONNECT to message broker
spring-messaging/src/main/java/org/springframework/messaging/simp/stomp/StompBrokerRelayMessageHandler.java
@@ -292,10 +292,36 @@ public void handleMessage(Message<?> message) { try { if ((destination == null) || supportsDestination(destination)) { + if (logger.isTraceEnabled()) { logger.trace("Processing message: " + message); } - handleInternal(message, messageType, sessionId); + + if (SimpMessageType.CONNECT.equals(messageType)) { + headers.setHeartbeat(0, 0); // TODO: disable for now + message = MessageBuilder.withPayloadAndHeaders(message.getPayload(), headers).build(); + RelaySession session = new RelaySession(sessionId); + this.relaySessions.put(sessionId, session); + session.open(message); + } + else if (SimpMessageType.DISCONNECT.equals(messageType)) { + RelaySession session = this.relaySessions.remove(sessionId); + if (session == null) { + if (logger.isTraceEnabled()) { + logger.trace("Session already removed, sessionId=" + sessionId); + } + return; + } + session.forward(message); + } + else { + RelaySession session = this.relaySessions.get(sessionId); + if (session == null) { + logger.warn("Session id=" + sessionId + " not found. Ignoring message: " + message); + return; + } + session.forward(message); + } } } catch (Throwable t) { @@ -312,32 +338,6 @@ protected boolean supportsDestination(String destination) { return false; } - protected void handleInternal(Message<?> message, SimpMessageType messageType, String sessionId) { - if (SimpMessageType.CONNECT.equals(messageType)) { - RelaySession session = new RelaySession(sessionId); - this.relaySessions.put(sessionId, session); - session.open(message); - } - else if (SimpMessageType.DISCONNECT.equals(messageType)) { - RelaySession session = this.relaySessions.remove(sessionId); - if (session == null) { - if (logger.isTraceEnabled()) { - logger.trace("Session already removed, sessionId=" + sessionId); - } - return; - } - session.forward(message); - } - else { - RelaySession session = this.relaySessions.get(sessionId); - if (session == null) { - logger.warn("Session id=" + sessionId + " not found. Ignoring message: " + message); - return; - } - session.forward(message); - } - } - private class RelaySession {
false
Other
spring-projects
spring-framework
6eea4ad68be1d049652911813ac62b0b92a2e72e.json
Upgrade websocket module to servlet api 3.1.0
build.gradle
@@ -493,7 +493,7 @@ project("spring-websocket") { compile(project(":spring-core")) compile(project(":spring-context")) compile(project(":spring-web")) - optional("javax.servlet:javax.servlet-api:3.1-b09") + optional("javax.servlet:javax.servlet-api:3.1.0") optional("javax.websocket:javax.websocket-api:1.0") optional("org.apache.tomcat:tomcat-websocket:8.0-SNAPSHOT") { exclude group: "org.apache.tomcat", module: "tomcat-websocket-api"
true
Other
spring-projects
spring-framework
6eea4ad68be1d049652911813ac62b0b92a2e72e.json
Upgrade websocket module to servlet api 3.1.0
spring-websocket/src/main/java/org/springframework/web/socket/server/support/GlassFishRequestUpgradeStrategy.java
@@ -37,6 +37,7 @@ import org.glassfish.tyrus.servlet.TyrusHttpUpgradeHandler; import org.glassfish.tyrus.websockets.Connection; import org.glassfish.tyrus.websockets.Version; +import org.glassfish.tyrus.websockets.WebSocketApplication; import org.glassfish.tyrus.websockets.WebSocketEngine; import org.glassfish.tyrus.websockets.WebSocketEngine.WebSocketHolderListener; import org.springframework.http.HttpHeaders; @@ -80,28 +81,28 @@ public void upgradeInternal(ServerHttpRequest request, ServerHttpResponse respon HttpServletResponse servletResponse = ((ServletServerHttpResponse) response).getServletResponse(); servletResponse = new AlreadyUpgradedResponseWrapper(servletResponse); - TyrusEndpoint tyrusEndpoint = createTyrusEndpoint(servletRequest, endpoint, selectedProtocol); + WebSocketApplication wsApp = createTyrusEndpoint(servletRequest, endpoint, selectedProtocol); WebSocketEngine engine = WebSocketEngine.getEngine(); try { - engine.register(tyrusEndpoint); + engine.register(wsApp); } catch (DeploymentException ex) { throw new HandshakeFailureException("Failed to deploy endpoint in GlassFish", ex); } try { - if (!performUpgrade(servletRequest, servletResponse, request.getHeaders(), tyrusEndpoint)) { + if (!performUpgrade(servletRequest, servletResponse, request.getHeaders(), wsApp)) { throw new HandshakeFailureException("Failed to upgrade HttpServletRequest"); } } finally { - engine.unregister(tyrusEndpoint); + engine.unregister(wsApp); } } private boolean performUpgrade(HttpServletRequest request, HttpServletResponse response, - HttpHeaders headers, TyrusEndpoint tyrusEndpoint) throws IOException { + HttpHeaders headers, WebSocketApplication wsApp) throws IOException { final TyrusHttpUpgradeHandler upgradeHandler; try { @@ -114,7 +115,7 @@ private boolean performUpgrade(HttpServletRequest request, HttpServletResponse r Connection connection = createConnection(upgradeHandler, response); RequestContext wsRequest = RequestContext.Builder.create() - .requestURI(URI.create(tyrusEndpoint.getPath())).requestPath(tyrusEndpoint.getPath()) + .requestURI(URI.create(wsApp.getPath())).requestPath(wsApp.getPath()) .connection(connection).secure(request.isSecure()).build(); for (String header : headers.keySet()) { @@ -129,7 +130,8 @@ public void onWebSocketHolder(WebSocketEngine.WebSocketHolder webSocketHolder) { }); } - private TyrusEndpoint createTyrusEndpoint(HttpServletRequest request, Endpoint endpoint, String selectedProtocol) { + private WebSocketApplication createTyrusEndpoint(HttpServletRequest request, + Endpoint endpoint, String selectedProtocol) { // Use randomized path String requestUri = request.getRequestURI();
true