Separate Multicast tests from Unicast; @Ignore Multicast tests; improve regex escaping on SI prefix.

This commit is contained in:
Gary Russell
2010-02-11 19:40:13 +00:00
parent 0798aad75c
commit d7b03c6959
12 changed files with 368 additions and 77 deletions

View File

@@ -38,9 +38,9 @@ public abstract class AbstractInternetProtocolSendingMessageHandler implements M
protected int soReceiveBufferSize = -1;
protected int soSendBufferSize = -1;
protected volatile int soSendBufferSize = -1;
protected int soTimeout = -1;
protected volatile int soTimeout = -1;
public AbstractInternetProtocolSendingMessageHandler(String host, int port) {

View File

@@ -26,6 +26,7 @@ import org.springframework.integration.adapter.MessageMappingException;
import org.springframework.integration.core.Message;
import org.springframework.integration.core.MessageHeaders;
import org.springframework.integration.ip.IpHeaders;
import org.springframework.integration.ip.util.RegexUtils;
import org.springframework.integration.message.InboundMessageMapper;
import org.springframework.integration.message.MessageBuilder;
import org.springframework.integration.message.MessageHandlingException;
@@ -65,8 +66,10 @@ public class DatagramPacketMessageMapper implements InboundMessageMapper<Datagra
private boolean lengthCheck = false;
private static Pattern udpHeadersPattern =
Pattern.compile("\\" + IpHeaders.ACK_ADDRESS + "=" + "([^;]*);\\" +
MessageHeaders.ID + "=" + "([^;]*);");
Pattern.compile(RegexUtils.escapeRegExSpecials(IpHeaders.ACK_ADDRESS) +
"=" + "([^;]*);" +
RegexUtils.escapeRegExSpecials(MessageHeaders.ID) +
"=" + "([^;]*);");
public void setCharset(String charset) {
@@ -208,7 +211,7 @@ public class DatagramPacketMessageMapper implements InboundMessageMapper<Datagra
}
/**
* Peeks at data in he buffer to see if starts with the prefix.
* Peeks at data in the buffer to see if starts with the prefix.
* @param buffer
* @param prefix
* @return

View File

@@ -53,7 +53,7 @@ import org.springframework.util.Assert;
public class UnicastSendingMessageHandler extends
AbstractInternetProtocolSendingMessageHandler implements Runnable {
private final DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper();
protected final DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper();
protected volatile DatagramSocket socket;
@@ -188,7 +188,7 @@ public class UnicastSendingMessageHandler extends
logger.debug("Sent packet for message id " + message.getHeaders().getId());
if (this.waitForAck) {
if (!countdownLatch.await(this.ackTimeout, TimeUnit.MILLISECONDS)) {
throw new MessagingException(message, "Failed to received UDP Ack in " + ackTimeout + " millis");
throw new MessagingException(message, "Failed to receive UDP Ack in " + ackTimeout + " millis");
}
}
}
@@ -238,6 +238,9 @@ public class UnicastSendingMessageHandler extends
public void run() {
Exception fatalException = null;
try {
if (logger.isDebugEnabled()) {
logger.debug("Listening for acks on port: " + ackPort);
}
this.ackSocket = new DatagramSocket(this.ackPort);
if (this.soReceiveBufferSize > 0) {
ackSocket.setReceiveBufferSize(this.soReceiveBufferSize);

View File

@@ -0,0 +1,45 @@
/*
* Copyright 2002-2010 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.integration.ip.util;
/**
* Regular Expression Utilities.
*
* @author Gary Russell
*
*/
public abstract class RegexUtils {
/**
* Escapes (precedes with \) any characters in the parameter in the set<br/><br/>
* <code>.$[]^*+{}()\?|</code><br/><br/>
* Used to escape a string that is used as a regular expression pattern, to remove
* the special meaning of these characters.
* @param stringToEscape The string to escape.
* @return The escaped string.
*/
public static String escapeRegExSpecials(String stringToEscape) {
// In the following, we look for all the specials and any we find
// are escaped in the output string, allowing that string to
// be used as a pattern containing the literal specials.
String out = stringToEscape.replaceAll(
"(\\.|\\$|\\[|\\]|\\^|\\*|\\+|\\{|\\}|\\(|\\)|\\\\|\\?|\\|)",
"\\\\$1");
return out;
}
}