/** * Create a multi-map implementation with case insensitive keys, for instance it can be used to hold some HTTP headers. * * @return the multi-map */ static MultiMap caseInsensitiveMultiMap() { return new CaseInsensitiveHeaders(); }
private MultiMap attributes() { // Create it lazily if (attributes == null) { attributes = new CaseInsensitiveHeaders(); } return attributes; }
@Override public MultiMap headers() { // Lazily decode headers if (headers == null) { headers = new CaseInsensitiveHeaders(); } return headers; }
@Override public MultiMap formAttributes() { synchronized (conn) { // Create it lazily if (attributes == null) { attributes = new CaseInsensitiveHeaders(); } return attributes; } }
private void checkHeaders() { if (headers == null) { headers = new CaseInsensitiveHeaders(); } }
@Override public MultiMap headers() { // Lazily decode headers if (headers == null) { // The message has been read from the wire if (headersPos != 0) { decodeHeaders(); } if (headers == null) { headers = new CaseInsensitiveHeaders(); } } return headers; }
protected MultiMap newMultiMap() { return new CaseInsensitiveHeaders(); }
static MultiMap params(String uri) { QueryStringDecoder queryStringDecoder = new QueryStringDecoder(uri); Map<String, List<String>> prms = queryStringDecoder.parameters(); MultiMap params = new CaseInsensitiveHeaders(); if (!prms.isEmpty()) { for (Map.Entry<String, List<String>> entry: prms.entrySet()) { params.add(entry.getKey(), entry.getValue()); } } return params; }
/** * Create a delivery options from JSON * * @param json the JSON */ public DeliveryOptions(JsonObject json) { this.timeout = json.getLong("timeout", DEFAULT_TIMEOUT); this.codecName = json.getString("codecName", null); JsonObject hdrs = json.getJsonObject("headers", null); if (hdrs != null) { headers = new CaseInsensitiveHeaders(); for (Map.Entry<String, Object> entry: hdrs) { if (!(entry.getValue() instanceof String)) { throw new IllegalStateException("Invalid type for message header value " + entry.getValue().getClass()); } headers.set(entry.getKey(), (String)entry.getValue()); } } this.localOnly = json.getBoolean("localOnly", DEFAULT_LOCAL_ONLY); }
protected MessageImpl(MessageImpl<U, V> other) { this.bus = other.bus; this.address = other.address; this.replyAddress = other.replyAddress; this.messageCodec = other.messageCodec; if (other.headers != null) { List<Map.Entry<String, String>> entries = other.headers.entries(); this.headers = new CaseInsensitiveHeaders(); for (Map.Entry<String, String> entry: entries) { this.headers.add(entry.getKey(), entry.getValue()); } } if (other.sentBody != null) { this.sentBody = other.sentBody; this.receivedBody = messageCodec.transform(other.sentBody); } this.send = other.send; }
@Test(expected = NullPointerException.class) public void testGetAllNPE() throws Exception { new CaseInsensitiveHeaders().getAll(null); }
@Test(expected = NullPointerException.class) public void testSetIterableNPE() throws Exception { new CaseInsensitiveHeaders().set("name", (Iterable<String>) null); }
@Test(expected = NullPointerException.class) public void testRemoveNPE() throws Exception { new CaseInsensitiveHeaders().remove(null); }
@Test(expected = NullPointerException.class) public void testGetNPE() { new CaseInsensitiveHeaders().get(null); }
private void decodeHeaders() { int length = wireBuffer.getInt(headersPos); if (length != 4) { headersPos += 4; int numHeaders = wireBuffer.getInt(headersPos); headersPos += 4; headers = new CaseInsensitiveHeaders(); for (int i = 0; i < numHeaders; i++) { int keyLength = wireBuffer.getInt(headersPos); headersPos += 4; byte[] bytes = wireBuffer.getBytes(headersPos, headersPos + keyLength); String key = new String(bytes, CharsetUtil.UTF_8); headersPos += keyLength; int valLength = wireBuffer.getInt(headersPos); headersPos += 4; bytes = wireBuffer.getBytes(headersPos, headersPos + valLength); String val = new String(bytes, CharsetUtil.UTF_8); headersPos += valLength; headers.add(key, val); } } headersPos = 0; }
@Override void handleEnd(MultiMap trailers) { if (conn.metrics != null) { if (request.exceptionOccurred != null) { conn.metrics.requestReset(request.metric()); } else { conn.metrics.responseEnd(request.metric(), response); } } responseEnded = true; // Should use a shared immutable object for CaseInsensitiveHeaders ? if (trailers == null) { trailers = new CaseInsensitiveHeaders(); } response.handleEnd(trailers); }
private void checkHeaders() { if (headers == null) { headers = new CaseInsensitiveHeaders(); } }
@Override public MultiMap headers() { // Lazily decode headers if (headers == null) { headers = new CaseInsensitiveHeaders(); } return headers; }
@Test public void testHeadersCopiedAfterSend() throws Exception { MultiMap headers = new CaseInsensitiveHeaders(); headers.add("foo", "bar"); vertx.eventBus().consumer(ADDRESS1).handler(msg -> { assertNotSame(headers, msg.headers()); assertEquals("bar", msg.headers().get("foo")); testComplete(); }); vertx.eventBus().send(ADDRESS1, "foo", new DeliveryOptions().setHeaders(headers)); headers.remove("foo"); await(); }
@Test public void testRemoveHashColl() { MultiMap mm = newMultiMap(); String name1 = this.sameHash1; String name2 = this.sameHash2; String name3 = "RZ"; mm.add(name1, "value1"); mm.add(name2, "value2"); mm.add(name3, "value3"); mm.add(name1, "value4"); mm.add(name2, "value5"); mm.add(name3, "value6"); assertEquals(3, mm.size()); mm.remove(name1); mm.remove(name2); assertEquals(1, mm.size()); mm = new CaseInsensitiveHeaders(); name1 = this.sameBucket1; name2 = this.sameBucket2; mm.add(name1, "value1"); mm.add(name2, "value2"); assertEquals(2, mm.size()); mm.remove(name1); mm.remove(name2); assertTrue("not empty", mm.isEmpty()); }