Package org.vertx.java.core

Examples of org.vertx.java.core.MultiMap


   */
  @Override
  protected void handleRequest() {
    super.handleRequest();

    MultiMap headers = response.headers();
    if(request.method().equals("GET")) {
      response.setStatusCode(200);
      headers.add("Content-Type", "text/html; charset=UTF-8");
      headers.add("Connection", "keep-alive");
      headers.add("Transfer-Encoding", "chunked");
    }

    String body = "<html><body><script>var _ = function (msg) { parent.s._(msg, document); };</script>";
    for(int i = body.length() ; i < 256 ; i++) {
      body += " ";
    }
    headers.add("Content-Length", String.valueOf(body.length()));
    response.write(body);
  }
View Full Code Here


      super.handleRequest();
    } else {
      final Buffer buffer = new Buffer(0);
      final HttpServerResponse res = request.response();
      String origin = request.headers().get("ORIGIN");
      MultiMap resHeaders = res.headers();
      resHeaders.add("Content-Length", String.valueOf(1));
      resHeaders.add("Content-Type", "text/plain; charset=UTF-8");

      if (origin != null) {
        // https://developer.mozilla.org/En/HTTP_Access_Control
        resHeaders.add("Access-Control-Allow-Origin", origin);
        resHeaders.add("Access-Control-Allow-Credentials", "true");
      }

      request.dataHandler(new Handler<Buffer>() {
        public void handle(Buffer data) {
          buffer.appendBuffer(data);
View Full Code Here

  public void handle(ClientData clientData) {
    HttpServerRequest request = clientData.getRequest();
    Settings settings = manager.getSettings();

    // handle sync disconnect xhrs
    MultiMap params = clientData.getParams();
    if (params != null && params.get("disconnect") != null) {
      Transport transport = manager.transport(clientData.getId());
      if (transport != null && transport.isOpen()) {
        transport.onForcedDisconnect();
      } else {
        // this.store.publish('disconnect-force:' + data.id);
View Full Code Here

  public void handle(final ClientData clientData) {
    final HttpServerRequest request = clientData.getRequest();
    final Settings settings = manager.getSettings();

    log.trace("In handshake handler");
    MultiMap reqHeaders = request.headers();
    final MultiMap resHeaders = request.response().headers();
    String reqOrigin = reqHeaders.get("Origin");
    resHeaders.add("CONTENT_TYPE", "text/plain; charset=UTF-8");

    if (!this.verifyOrigin(reqOrigin)) {
      manager.writeError(request, 403, "handshake bad origin");
      return;
    }

    final HandshakeData handshakeData = new HandshakeData(clientData);

    if (reqOrigin != null) {
      // https://developer.mozilla.org/En/HTTP_Access_Control
      resHeaders.add("Access-Control-Allow-Origin", reqOrigin);
      resHeaders.add("Access-Control-Allow-Credentials", "true");
    }

    authorize(request, handshakeData, new AuthorizationCallback() {
      public void handle(Exception e, boolean isAuthorized) {
        if(e != null) {
          manager.writeError(request, e);
          return;
        }

        if(isAuthorized) {
          String id = UUID.randomUUID().toString();
          String result = id + ":"
              + (settings.isHeartbeats() ? settings.getHeartbeatTimeout() : "") + ":"
              + settings.getCloseTimeout() + ":"
              + settings.getTransports();

          request.response().setStatusCode(200);
          String jsonp = clientData.getParams().get("jsonp");
          if(jsonp != null) {
            result = "io.j[" + jsonp + "](\"" + result + "\");";
            resHeaders.add("Content-Type", "application/javascript");
          }
          request.response().end(result);

          manager.getHandshaken().put(id, handshakeData);
          // self.store.publish('handshake', id, newData || handshakeData);
View Full Code Here

//    String result = JsonUtils.stringify(encodedPacket);
    String result = Json.encode(encodedPacket);
    String data = (encodedPacket == null) ? "" : this.head + result + this.foot;

    this.response.setStatusCode(200);
    MultiMap headers = this.response.headers();
    headers.add("Content-Type", "text/javascript; charset=UTF-8");
    headers.add("Content-Length", String.valueOf(data.getBytes(Charset.forName("UTF-8")).length));
    headers.add("Connection", "Keep-Alive");
    headers.add("X-XSS-Protection", "0");
    response.write(data);
    log.debug(getName() + " writing " + data);
  }
View Full Code Here

    }

    public RubyHash getEnv(final HttpServerRequest request,
                           final RackInput input,
                           final boolean isSSL) throws IOException {
        MultiMap headers = request.headers();
        final RackEnvironmentHash env = new RackEnvironmentHash(runtime, headers, rackKeyMap);
        env.lazyPut(RACK_KEY.RACK_INPUT, input, false);
        env.lazyPut(RACK_KEY.RACK_ERRORS, errors, false);

        String pathInfo = request.path();

        String scriptName = "";
        String[] hostInfo = getHostInfo(request.headers().get(Const.HOST));

        env.lazyPut(RACK_KEY.REQUEST_METHOD, request.method(), true);
        env.lazyPut(RACK_KEY.SCRIPT_NAME, scriptName, false);
        env.lazyPut(RACK_KEY.PATH_INFO, pathInfo, false);
        env.lazyPut(RACK_KEY.QUERY_STRING, orEmpty(request.query()), false);
        env.lazyPut(RACK_KEY.SERVER_NAME, hostInfo[0], false);
        env.lazyPut(RACK_KEY.SERVER_PORT, hostInfo[1], true);
        env.lazyPut(RACK_KEY.HTTP_VERSION,
                request.version() == HttpVersion.HTTP_1_1 ? Const.HTTP_11 : Const.HTTP_10, true);
        env.lazyPut(RACK_KEY.CONTENT_TYPE, headers.get(HttpHeaders.Names.CONTENT_TYPE), true);
        env.lazyPut(RACK_KEY.REQUEST_URI, request.uri(), false);
        env.lazyPut(RACK_KEY.REMOTE_ADDR, getRemoteAddr(request), true);
        env.lazyPut(RACK_KEY.URL_SCHEME, isSSL ? Const.HTTPS : Const.HTTP, true);
        env.lazyPut(RACK_KEY.VERSION, rackVersion, false);
        env.lazyPut(RACK_KEY.MULTITHREAD, runtime.getTrue(), false);
View Full Code Here

    @Override
    public void handle(HttpClientResponse clientResponse) {
        delegate.handle(clientResponse);

        MultiMap headers = clientResponse.headers();
        for (String headerName : rewriteHeaders) {
            List<String> headerValues = headers.getAll(headerName);
            int size = headerValues.size();
            if (size > 0) {
                List<String> newHeaders = new ArrayList<String>(size);
                for (String headerValue : headerValues) {
                    String newValue = headerValue;
                    if (headerValue != null && headerValue.length() > 0) {
                        newValue = proxyMappingDetails.rewriteBackendUrl(headerValue);
                    }
                }
                LOG.info("Rewriting header " + headerName + " from: " + headerValues + " to: " + newHeaders);
                headers.set(headerName, newHeaders);
            }
        }
    }
View Full Code Here

        HTable table = new HTable(config, "Requests");
        Vertx vertx = VertxFactory.newVertx();
        vertx.createHttpServer().requestHandler((HttpServerRequest request) -> {
            System.out.println("A request has arrived on the server!");
            System.out.println(request.uri());
            MultiMap params = request.params();
            params.entries().stream().forEach((entry) -> {
                try {
                    System.out.println(entry.getKey() + "       " + entry.getValue());
                    Put p = new Put(Bytes.toBytes("row" + System.currentTimeMillis()));
                    p.add(Bytes.toBytes("Value"), Bytes.toBytes("col2"), Bytes.toBytes(request.uri()));
                    table.put(p);
View Full Code Here

TOP

Related Classes of org.vertx.java.core.MultiMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.