Java Code Examples for io.vertx.core.http.HttpHeaders#headers()

The following examples show how to use io.vertx.core.http.HttpHeaders#headers() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpRequestImpl.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Override
public MultiMap headers() {
  if (headers == null) {
    headers = HttpHeaders.headers();
  }
  return headers;
}
 
Example 2
Source File: HttpRequestImpl.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
@Override
public MultiMap queryParams() {
  if (params == null) {
    params = HttpHeaders.headers();
  }
  if (params.isEmpty()) {
    int idx = uri.indexOf('?');
    if (idx >= 0) {
      QueryStringDecoder dec = new QueryStringDecoder(uri);
      dec.parameters().forEach((name, value) -> params.add(name, value));
      uri = uri.substring(0, idx);
    }
  }
  return params;
}
 
Example 3
Source File: ServiceResponse.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
public ServiceResponse(JsonObject json) {
  init();
  ServiceResponseConverter.fromJson(json, this);
  JsonObject hdrs = json.getJsonObject("headers", null);
  if (hdrs != null) {
    headers = HttpHeaders.headers();
    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());
    }
  }
}
 
Example 4
Source File: ServiceRequest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
public ServiceRequest(JsonObject json) {
  init();
  ServiceRequestConverter.fromJson(json, this);
  JsonObject hdrs = json.getJsonObject("headers", null);
  if (hdrs != null) {
    headers = HttpHeaders.headers();
    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());
    }
  }
}
 
Example 5
Source File: FaviconHandlerImpl.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
/**
 * Instantiate a new Icon
 *
 * @param buffer buffer containing the image data for this icon.
 */
private Icon(Buffer buffer) {
  headers = HttpHeaders.headers();
  body = buffer;

  headers.add(CONTENT_TYPE, "image/x-icon");
  headers.add(CONTENT_LENGTH, Integer.toString(buffer.length()));
  headers.add(CACHE_CONTROL, "public, max-age=" + maxAgeSeconds);
}
 
Example 6
Source File: OperationResponse.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
public OperationResponse(JsonObject json) {
  init();
  OperationResponseConverter.fromJson(json, this);
  JsonObject hdrs = json.getJsonObject("headers", null);
  if (hdrs != null) {
    headers = HttpHeaders.headers();
    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());
    }
  }
}
 
Example 7
Source File: OperationRequest.java    From vertx-web with Apache License 2.0 5 votes vote down vote up
public OperationRequest(JsonObject json) {
  init();
  OperationRequestConverter.fromJson(json, this);
  JsonObject hdrs = json.getJsonObject("headers", null);
  if (hdrs != null) {
    headers = HttpHeaders.headers();
    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());
    }
  }
}
 
Example 8
Source File: WebClientSessionAware.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
protected MultiMap headers() {
  if (headers == null) {
    headers = HttpHeaders.headers();
  }
  return headers;
}
 
Example 9
Source File: EventBusBridgeImpl.java    From vertx-web with Apache License 2.0 4 votes vote down vote up
private void checkAndSend(boolean send, String address, Object body,
                          JsonObject headers,
                          SockJSSocket sock,
                          String replyAddress,
                          Message awaitingReply) {
  SockInfo info = sockInfos.get(sock);
  if (replyAddress != null && !checkMaxHandlers(sock, info)) {
    return;
  }
  Handler<AsyncResult<Message<Object>>> replyHandler;
  if (replyAddress != null) {
    replyHandler = result -> {
      if (result.succeeded()) {
        Message message = result.result();
        // Note we don't check outbound matches for replies
        // Replies are always let through if the original message
        // was approved

        // Now - the reply message might itself be waiting for a reply - which would be inbound -so we need
        // to add the message to the messages awaiting reply so it can be let through
        checkAddAccceptedReplyAddress(message);
        deliverMessage(sock, replyAddress, message);
      } else {
        ReplyException cause = (ReplyException) result.cause();
        JsonObject envelope =
          new JsonObject()
            .put("type", "err")
            .put("address", replyAddress)
            .put("failureCode", cause.failureCode())
            .put("failureType", cause.failureType().name())
            .put("message", cause.getMessage());
        sock.write(buffer(envelope.encode()));
      }
      info.handlerCount--;
    };
  } else {
    replyHandler = null;
  }
  if (log.isDebugEnabled()) {
    log.debug("Forwarding message to address " + address + " on event bus");
  }
  MultiMap mHeaders;
  if (headers != null) {
    mHeaders = HttpHeaders.headers();
    headers.forEach(entry -> mHeaders.add(entry.getKey(), entry.getValue().toString()));
  } else {
    mHeaders = null;
  }
  if (send) {
    if (awaitingReply != null) {
      if (replyAddress != null) {
        awaitingReply.replyAndRequest(body, new DeliveryOptions().setSendTimeout(replyTimeout).setHeaders(mHeaders), replyHandler);
      } else {
        awaitingReply.reply(body, new DeliveryOptions().setSendTimeout(replyTimeout).setHeaders(mHeaders));
      }
    } else {
      if (replyAddress != null) {
        eb.request(address, body, new DeliveryOptions().setSendTimeout(replyTimeout).setHeaders(mHeaders), replyHandler);
      } else {
        eb.send(address, body, new DeliveryOptions().setSendTimeout(replyTimeout).setHeaders(mHeaders));
      }
    }
    if (replyAddress != null) {
      info.handlerCount++;
    }
  } else {
    eb.publish(address, body, new DeliveryOptions().setHeaders(mHeaders));
  }
}