use of io.fabric8.gateway.handlers.detecting.protocol.Ascii in project fabric8 by jboss-fuse.
the class StompFrame method headerMap.
public Map<Ascii, Ascii> headerMap(Set<Ascii> reversedHeaderHandling) {
if (headerMap == null) {
headerMap = new HashMap<Ascii, Ascii>();
for (HeaderEntry HeaderEntry : headerList) {
final Ascii key = HeaderEntry.getKey();
Ascii old = headerMap.put(key, HeaderEntry.getValue());
if (old != null && !reversedHeaderHandling.contains(key)) {
headerMap.put(key, old);
}
}
headerList = null;
}
return headerMap;
}
use of io.fabric8.gateway.handlers.detecting.protocol.Ascii in project strimzi by strimzi.
the class TopicSerializationTest method testErrorInTopicName.
@Test
public void testErrorInTopicName() {
Map<String, String> data = new HashMap<>();
data.put(TopicSerialization.CM_KEY_REPLICAS, "1");
data.put(TopicSerialization.CM_KEY_PARTITIONS, "1");
data.put(TopicSerialization.CM_KEY_CONFIG, "{}");
data.put(TopicSerialization.CM_KEY_NAME, "An invalid topic name!");
ConfigMap cm = new ConfigMapBuilder().editOrNewMetadata().withName("foo").endMetadata().withData(data).build();
try {
TopicSerialization.fromConfigMap(cm);
fail("Should throw");
} catch (InvalidConfigMapException e) {
assertEquals("ConfigMap's 'data' section has invalid 'name' key: Topic name \"An invalid topic name!\" is illegal, it contains a character other than ASCII alphanumerics, '.', '_' and '-'", e.getMessage());
}
}
use of io.fabric8.gateway.handlers.detecting.protocol.Ascii in project fabric8 by jboss-fuse.
the class StompProtocolDecoder method read_headers.
private Action<StompFrame> read_headers(final StompFrame frame) {
final Ascii[] contentLengthValue = new Ascii[1];
final ArrayList<StompFrame.HeaderEntry> headers = new ArrayList<StompFrame.HeaderEntry>(10);
return new Action<StompFrame>() {
public StompFrame apply() throws IOException {
Buffer line = readUntil((byte) '\n', protocol.maxHeaderLength, "The maximum header length was exceeded");
while (line != null) {
line = chomp(line);
if (line.length() > 0) {
if (protocol.maxHeaders != -1 && headers.size() > protocol.maxHeaders) {
throw new IOException("The maximum number of headers was exceeded");
}
try {
int seperatorIndex = indexOf(line, COLON_BYTE);
if (seperatorIndex < 0) {
throw new IOException("Header line missing separator [" + Ascii.ascii(line) + "]");
}
Buffer name = line.getBuffer(0, seperatorIndex);
if (trim) {
name = trim(name);
}
Buffer value = line.getBuffer(seperatorIndex + 1, line.length());
if (trim) {
value = trim(value);
}
StompFrame.HeaderEntry entry = new StompFrame.HeaderEntry(Ascii.ascii(name), Ascii.ascii(value));
if (entry.key.equals(CONTENT_LENGTH)) {
contentLengthValue[0] = entry.value;
}
headers.add(entry);
} catch (Exception e) {
throw new IOException("Unable to parser header line [" + line + "]");
}
} else {
frame.setHeaders(headers);
Ascii contentLength = contentLengthValue[0];
if (contentLength != null) {
// Bless the client, he's telling us how much data to read in.
int length = 0;
try {
length = Integer.parseInt(contentLength.toString());
} catch (NumberFormatException e) {
throw new IOException("Specified content-length is not a valid integer");
}
if (protocol.maxDataLength != -1 && length > protocol.maxDataLength) {
throw new IOException("The maximum data length was exceeded");
}
nextDecodeAction = read_binary_body(frame, length);
} else {
nextDecodeAction = read_text_body(frame);
}
return nextDecodeAction.apply();
}
line = readUntil((byte) '\n', protocol.maxHeaderLength, "The maximum header length was exceeded");
}
return null;
}
};
}
Aggregations