Package org.jwebsocket.kit

Examples of org.jwebsocket.kit.RequestHeader


    super(null);
    request = aRequest;
    response = aResponse;
    // TODO: Overhaul this hardcoded reference! See TokenServer class!
    setBoolean("org.jWebSocket.tokenserver.isTS", true);
    RequestHeader lHeader = new RequestHeader();
    lHeader.put("prot", "json");
    setHeader(lHeader);
  }
View Full Code Here


    if (lFlashBridgeReq != null) {
      mLog.warn("TCPEngine returned policy file response ('" + new String(lBA, "US-ASCII") + "'), check for FlashBridge plug-in.");
      return null;
    }

    RequestHeader lHeader = new RequestHeader();
    Map<String, String> lArgs = new FastMap<String, String>();
    String lPath = (String) lRespMap.get("path");

    // isolate search string
    String lSearchString = "";
    if (lPath != null) {
      int lPos = lPath.indexOf(JWebSocketCommonConstants.PATHARG_SEPARATOR);
      if (lPos >= 0) {
        lSearchString = lPath.substring(lPos + 1);
        if (lSearchString.length() > 0) {
          String[] lArgsArray = lSearchString.split(JWebSocketCommonConstants.ARGARG_SEPARATOR);
          for (int i = 0; i < lArgsArray.length; i++) {
            String[] lKeyValuePair = lArgsArray[i].split(JWebSocketCommonConstants.KEYVAL_SEPARATOR, 2);
            if (lKeyValuePair.length == 2) {
              lArgs.put(lKeyValuePair[0], lKeyValuePair[1]);
              if (mLog.isDebugEnabled()) {
                mLog.debug("arg" + i + ": " + lKeyValuePair[0] + "=" + lKeyValuePair[1]);
              }
            }
          }
        }
      }
    }

    if (mLog.isDebugEnabled()) {
      mLog.debug("Handshake flushed.");
    }

    // set default sub protocol if none passed
    if (lArgs.get("prot") == null) {
      lArgs.put("prot", JWebSocketCommonConstants.SUB_PROT_DEFAULT);
    }

    lHeader.put("host", lRespMap.get("host"));
    lHeader.put("origin", lRespMap.get("origin"));
    lHeader.put("location", lRespMap.get("location"));

    lHeader.put("path", lRespMap.get("path"));
    lHeader.put("searchString", lSearchString);
    lHeader.put("args", lArgs);

    return lHeader;
  }
View Full Code Here

          Socket lClientSocket = mServerSocket.accept();
          boolean lTCPNoDelay = lClientSocket.getTcpNoDelay();
          lClientSocket.setTcpNoDelay(true);
          try {
            // process handshake to parse header data
            RequestHeader lHeader = processHandshake(lClientSocket);
            if (lHeader != null) {
              // set socket timeout to given amount of milliseconds
              // use tcp engine's timeout as default and
              // check system's min and max timeout ranges
              int lSessionTimeout = lHeader.getTimeout(getSessionTimeout());
              /* min and max range removed since 0.9.0.0602, see config documentation
              if (lSessionTimeout > JWebSocketServerConstants.MAX_TIMEOUT) {
              lSessionTimeout = JWebSocketServerConstants.MAX_TIMEOUT;
              } else if (lSessionTimeout < JWebSocketServerConstants.MIN_TIMEOUT) {
              lSessionTimeout = JWebSocketServerConstants.MIN_TIMEOUT;
View Full Code Here

     * @param ctx the channel handler context
     * @param req the http request object
     */
    private WebSocketConnector initializeConnector(ChannelHandlerContext ctx, HttpRequest req) {

        RequestHeader header = getRequestHeader(req);
        int lSessionTimeout = header.getTimeout(JWebSocketCommonConstants.DEFAULT_TIMEOUT);
        if (lSessionTimeout > 0) {
            ctx.getChannel().getConfig().setConnectTimeoutMillis(lSessionTimeout);
        }
        // create connector
        WebSocketConnector theConnector = new NettyConnector(engine, this);
View Full Code Here

     *
     * @param req the http request header
     * @return the request header
     */
    private RequestHeader getRequestHeader(HttpRequest req) {
        RequestHeader header = new RequestHeader();
        FastMap<String, String> args = new FastMap<String, String>();
        String searchString = "";
        String path = req.getUri();

        // isolate search string
        int pos = path.indexOf(JWebSocketCommonConstants.PATHARG_SEPARATOR);
        if (pos >= 0) {
            searchString = path.substring(pos + 1);
            if (searchString.length() > 0) {
                String[] lArgs = searchString.split(JWebSocketCommonConstants.ARGARG_SEPARATOR);
                for (int i = 0; i < lArgs.length; i++) {
                    String[] lKeyValuePair = lArgs[i].split(JWebSocketCommonConstants.KEYVAL_SEPARATOR, 2);
                    if (lKeyValuePair.length == 2) {
                        args.put(lKeyValuePair[0], lKeyValuePair[1]);
                        if (log.isDebugEnabled()) {
                            log.debug("arg" + i + ": " + lKeyValuePair[0] + "=" + lKeyValuePair[1]);
                        }
                    }
                }
            }
        }
        // set default sub protocol if none passed
        if (args.get("prot") == null) {
            args.put("prot", JWebSocketCommonConstants.SUB_PROT_DEFAULT);
        }
        header.put(ARGS, args);
        header.put(ORIGIN, req.getHeader(HttpHeaders.Names.ORIGIN));
        header.put(LOCATION, getWebSocketLocation(req));
        header.put(PATH, req.getUri());

        header.put(SEARCH_STRING, searchString);
        header.put(HOST, req.getHeader(HttpHeaders.Names.HOST));
        return header;
    }
View Full Code Here

  @Override
  public void processPacket(WebSocketEngine aEngine, WebSocketConnector aConnector, WebSocketPacket aDataPacket) {
    if (log.isDebugEnabled()) {
      log.debug("Processing data packet '" + aDataPacket.getUTF8() + "'...");
    }
    RequestHeader lHeader = aConnector.getHeader();
    String lSubProt = (lHeader != null ? lHeader.getSubProtocol(null) : null);

    // the custom server here answers with a simple echo packet.
    // this section can be used as an example for your own protol handling.
    if (lSubProt != null && lSubProt.equals(JWebSocketCommonConstants.SUB_PROT_CUSTOM)) {
      // send a modified echo packet back to sender.
View Full Code Here

TOP

Related Classes of org.jwebsocket.kit.RequestHeader

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.