Example usage for io.netty.handler.codec.http HttpMethod POST

List of usage examples for io.netty.handler.codec.http HttpMethod POST

Introduction

In this page you can find the example usage for io.netty.handler.codec.http HttpMethod POST.

Prototype

HttpMethod POST

To view the source code for io.netty.handler.codec.http HttpMethod POST.

Click Source Link

Document

The POST method is used to request that the origin server accept the entity enclosed in the request as a new subordinate of the resource identified by the Request-URI in the Request-Line.

Usage

From source file:org.waarp.gateway.ftp.adminssl.HttpSslHandler.java

License:Open Source License

private void getParams() {
    if (request.method() == HttpMethod.GET) {
        params = null;//ww  w. j a v  a2s.com
    } else if (request.method() == HttpMethod.POST) {
        ByteBuf content = request.content();
        if (content.isReadable()) {
            String param = content.toString(WaarpStringUtils.UTF8);
            QueryStringDecoder queryStringDecoder2 = new QueryStringDecoder("/?" + param);
            params = queryStringDecoder2.parameters();
        } else {
            params = null;
        }
    }
}

From source file:org.waarp.gateway.ftp.adminssl.HttpSslHandler.java

License:Open Source License

private void checkAuthent(ChannelHandlerContext ctx) {
    newSession = true;//from   www  .ja  va2s. c om
    if (request.method() == HttpMethod.GET) {
        String logon = Logon();
        responseContent.append(logon);
        clearSession();
        writeResponse(ctx);
        return;
    } else if (request.method() == HttpMethod.POST) {
        getParams();
        if (params == null) {
            String logon = Logon();
            responseContent.append(logon);
            clearSession();
            writeResponse(ctx);
            return;
        }
    }
    boolean getMenu = false;
    if (params.containsKey("Logon")) {
        String name = null, password = null;
        List<String> values = null;
        if (!params.isEmpty()) {
            // get values
            if (params.containsKey("name")) {
                values = params.get("name");
                if (values != null) {
                    name = values.get(0);
                    if (name == null || name.length() == 0) {
                        getMenu = true;
                    }
                }
            } else {
                getMenu = true;
            }
            // search the nb param
            if ((!getMenu) && params.containsKey("passwd")) {
                values = params.get("passwd");
                if (values != null) {
                    password = values.get(0);
                    if (password == null || password.length() == 0) {
                        getMenu = true;
                    } else {
                        getMenu = false;
                    }
                } else {
                    getMenu = true;
                }
            } else {
                getMenu = true;
            }
        } else {
            getMenu = true;
        }
        if (!getMenu) {
            logger.debug("Name=" + name + " vs "
                    + name.equals(FileBasedConfiguration.fileBasedConfiguration.ADMINNAME) + " Passwd="
                    + password + " vs "
                    + FileBasedConfiguration.fileBasedConfiguration.checkPassword(password));
            if (name.equals(FileBasedConfiguration.fileBasedConfiguration.ADMINNAME)
                    && FileBasedConfiguration.fileBasedConfiguration.checkPassword(password)) {
                authentHttp.specialNoSessionAuth(FileBasedConfiguration.fileBasedConfiguration.HOST_ID);
            } else {
                getMenu = true;
            }
            if (!authentHttp.isIdentified()) {
                logger.debug("Still not authenticated: {}", authentHttp);
                getMenu = true;
            }
            // load DbSession
            if (this.dbSession == null) {
                try {
                    if (DbConstant.admin.isActive) {
                        this.dbSession = new DbSession(DbConstant.admin, false);
                        DbAdmin.nbHttpSession++;
                        this.isPrivateDbSession = true;
                    }
                } catch (WaarpDatabaseNoConnectionException e1) {
                    // Cannot connect so use default connection
                    logger.warn("Use default database connection");
                    this.dbSession = DbConstant.admin.session;
                }
            }
        }
    } else {
        getMenu = true;
    }
    if (getMenu) {
        String logon = Logon();
        responseContent.append(logon);
        clearSession();
        writeResponse(ctx);
    } else {
        String index = index();
        responseContent.append(index);
        clearSession();
        admin = new DefaultCookie(FTPSESSION,
                FileBasedConfiguration.fileBasedConfiguration.HOST_ID + Long.toHexString(random.nextLong()));
        sessions.put(admin.value(), this.authentHttp);
        if (this.isPrivateDbSession) {
            dbSessions.put(admin.value(), dbSession);
        }
        logger.debug("CreateSession: " + uriRequest + ":{}", admin);
        writeResponse(ctx);
    }
}

From source file:org.waarp.gateway.kernel.rest.HttpRestHandler.java

License:Open Source License

/**
 * Create the decoder//w  w  w .j a  va2  s  .  co  m
 * 
 * @throws HttpIncorrectRequestException
 */
protected void createDecoder() throws HttpIncorrectRequestException {
    HttpMethod method = request.method();
    if (!method.equals(HttpMethod.HEAD)) {
        // in order decoder allows to parse
        request.setMethod(HttpMethod.POST);
    }
    try {
        decoder = new HttpPostRequestDecoder(factory, request);
    } catch (ErrorDataDecoderException e1) {
        status = HttpResponseStatus.NOT_ACCEPTABLE;
        throw new HttpIncorrectRequestException(e1);
    } catch (Exception e1) {
        // GETDOWNLOAD Method: should not try to create a HttpPostRequestDecoder
        // So OK but stop here
        status = HttpResponseStatus.NOT_ACCEPTABLE;
        throw new HttpIncorrectRequestException(e1);
    }
}

From source file:org.waarp.openr66.protocol.http.adminssl.HttpResponsiveSslHandler.java

License:Open Source License

private String Spooled(boolean detailed) {
    // XXXSPOOLEDXXX
    if (request.method() == HttpMethod.POST) {
        getParams();/*from ww w  .j  av a  2s.  c  o  m*/
    }
    String spooled = REQUEST.Spooled.read(this);
    String uri = null;
    if (detailed) {
        uri = "SpooledDetailed.html";
    } else {
        uri = "Spooled.html";
    }
    QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.uri());
    params = queryStringDecoder.parameters();
    String name = null;
    if (params.containsKey("name")) {
        name = getTrimValue("name");
    }
    int istatus = 0;
    if (params.containsKey("status")) {
        String status = getTrimValue("status");
        try {
            istatus = Integer.parseInt(status);
        } catch (NumberFormatException e1) {
            istatus = 0;
        }
    }
    if (spooled.contains("XXXSPOOLEDXXX")) {
        if (name != null && !name.isEmpty()) {
            // name is specified
            uri = request.uri();
            if (istatus != 0) {
                uri += "&status=" + istatus;
            }
            StringBuilder builder = SpooledInformTask.buildSpooledUniqueTable(uri, name);
            return spooled.replace("XXXSPOOLEDXXX", builder.toString());
        } else {
            if (istatus != 0) {
                uri += "&status=" + istatus;
            }
            StringBuilder builder = SpooledInformTask.buildSpooledTable(detailed, istatus, uri);
            return spooled.replace("XXXSPOOLEDXXX", builder.toString());
        }
    }
    if (name != null && !name.isEmpty()) {
        // name is specified
        uri = request.uri();
        if (istatus != 0) {
            uri += "&status=" + istatus;
        }
        String builder = SpooledInformTask.buildSpooledUniqueJson(uri, name);
        return spooled.replace(XXXDATAJSONXXX, builder);
    } else {
        if (istatus != 0) {
            uri += "&status=" + istatus;
        }
        String builder = SpooledInformTask.buildSpooledJson(detailed, istatus, uri);
        return spooled.replace(XXXDATAJSONXXX, builder);
    }
}

From source file:org.waarp.openr66.protocol.http.adminssl.HttpResponsiveSslHandler.java

License:Open Source License

private void getParams() {
    if (request.method() == HttpMethod.GET) {
        params = null;/* w ww.  j  ava 2s . c  o m*/
    } else if (request.method() == HttpMethod.POST) {
        Map<String, List<String>> paramsOld = params;
        ByteBuf content = request.content();
        if (content.isReadable()) {
            String param = content.toString(WaarpStringUtils.UTF8);
            QueryStringDecoder queryStringDecoder2 = new QueryStringDecoder("/?" + param);
            params = queryStringDecoder2.parameters();
            if (params.containsKey(sREFRESH)) {
                List<String> parms = params.get("ACTION");
                if (parms != null) {
                    String parm = parms.get(0);
                    if ("Disabling".equalsIgnoreCase(parm)) {
                        setREFRESH(0);
                    } else {
                        String snb = getTrimValue(sREFRESH);
                        if (snb != null) {
                            try {
                                int old = getREFRESH();
                                setREFRESH(Integer.parseInt(snb) * 1000);
                                if (getREFRESH() < 0) {
                                    setREFRESH(old);
                                }
                            } catch (Exception e1) {
                            }
                        }
                    }
                }
                params = paramsOld;
                return;
            }
            if (params.containsKey(sLIMITROW)) {
                String snb = getTrimValue(sLIMITROW);
                if (snb != null) {
                    try {
                        int old = getLIMITROW();
                        setLIMITROW(Integer.parseInt(snb));
                        if (getLIMITROW() < 5) {
                            setLIMITROW(old);
                        }
                    } catch (Exception e1) {
                    }
                }
            }
        } else {
            params = null;
        }
    }
}

From source file:org.waarp.openr66.protocol.http.adminssl.HttpResponsiveSslHandler.java

License:Open Source License

private void checkAuthent(ChannelHandlerContext ctx) {
    newSession = true;//from  ww w  . j a  va  2s .c  om
    if (request.method() == HttpMethod.GET) {
        String logon = Logon();
        logon = logon.replaceAll(REPLACEMENT.XXXERRORMESGXXX.toString(), "");
        responseContent.append(logon);
        clearSession();
        writeResponse(ctx);
        return;
    } else if (request.method() == HttpMethod.POST) {
        getParams();
        if (params == null) {
            String logon = Logon();
            logon = logon.replaceAll(REPLACEMENT.XXXERRORMESGXXX.toString(),
                    Messages.getString("HttpSslHandler.EmptyLogin"));
            responseContent.append(logon);
            clearSession();
            writeResponse(ctx);
            return;
        }
    } else {
        sendError(ctx, HttpResponseStatus.METHOD_NOT_ALLOWED);
        return;
    }
    boolean getMenu = false;
    if (params.containsKey("Logon")) {
        String name = null, password = null;
        List<String> values = null;
        if (!params.isEmpty()) {
            // get values
            if (params.containsKey("name")) {
                values = params.get("name");
                if (values != null) {
                    name = values.get(0);
                    if (name == null || name.isEmpty()) {
                        getMenu = true;
                    }
                }
            } else {
                getMenu = true;
            }
            // search the nb param
            if ((!getMenu) && params.containsKey("passwd")) {
                values = params.get("passwd");
                if (values != null) {
                    password = values.get(0);
                    if (password == null || password.isEmpty()) {
                        getMenu = true;
                    } else {
                        getMenu = false;
                    }
                } else {
                    getMenu = true;
                }
            } else {
                getMenu = true;
            }
        } else {
            getMenu = true;
        }
        if (!getMenu) {
            logger.debug("Name? " + name.equals(Configuration.configuration.getADMINNAME()) + " Passwd? "
                    + Arrays.equals(password.getBytes(WaarpStringUtils.UTF8),
                            Configuration.configuration.getSERVERADMINKEY()));
            if (name.equals(Configuration.configuration.getADMINNAME())
                    && Arrays.equals(password.getBytes(WaarpStringUtils.UTF8),
                            Configuration.configuration.getSERVERADMINKEY())) {
                authentHttp.getAuth().specialNoSessionAuth(true, Configuration.configuration.getHOST_ID());
                authentHttp.setStatus(70);
            } else {
                try {
                    authentHttp.getAuth().connectionHttps(DbConstant.admin.getSession(), name,
                            FilesystemBasedDigest.passwdCrypt(password.getBytes(WaarpStringUtils.UTF8)));
                } catch (Reply530Exception e1) {
                    getMenu = true;
                } catch (Reply421Exception e1) {
                    getMenu = true;
                }
            }
            if (!authentHttp.isAuthenticated()) {
                authentHttp.setStatus(71);
                logger.debug("Still not authenticated: {}", authentHttp);
                getMenu = true;
            }
            logger.debug("Identified: " + authentHttp.getAuth().isIdentified() + ":"
                    + authentHttp.isAuthenticated());
        }
    } else {
        getMenu = true;
    }
    if (getMenu) {
        String logon = Logon();
        logon = logon.replaceAll(REPLACEMENT.XXXERRORMESGXXX.toString(),
                Messages.getString("HttpSslHandler.BadLogin"));
        responseContent.append(logon);
        clearSession();
        writeResponse(ctx);
    } else {
        // load DbSession
        if (this.dbSession != null) {
            clearSession();
            this.dbSession = null;
        }
        if (this.dbSession == null) {
            try {
                if (DbConstant.admin.isActive()) {
                    this.dbSession = new DbSession(DbConstant.admin, false);
                    DbAdmin.incHttpSession();
                    this.isPrivateDbSession = true;
                }
            } catch (WaarpDatabaseNoConnectionException e1) {
                // Cannot connect so use default connection
                logger.warn("Use default database connection");
                this.dbSession = DbConstant.admin.getSession();
            }
        }
        String index = index();
        responseContent.append(index);
        clearSession();
        admin = new DefaultCookie(R66SESSION + Configuration.configuration.getHOST_ID(),
                Configuration.configuration.getHOST_ID() + Long.toHexString(random.nextLong()));
        sessions.put(admin.value(), this.authentHttp);
        authentHttp.setStatus(72);
        if (this.isPrivateDbSession) {
            dbSessions.put(admin.value(), dbSession);
        }
        logger.debug("CreateSession: " + uriRequest + ":{}", admin);
        writeResponse(ctx);
    }
}

From source file:org.waarp.openr66.protocol.http.adminssl.HttpSslHandler.java

License:Open Source License

private void getParams() {
    if (request.method() == HttpMethod.GET) {
        params = null;/* ww w  .  j a  v a  2 s  .  c om*/
    } else if (request.method() == HttpMethod.POST) {
        ByteBuf content = request.content();
        if (content.isReadable()) {
            String param = content.toString(WaarpStringUtils.UTF8);
            QueryStringDecoder queryStringDecoder2 = new QueryStringDecoder("/?" + param);
            params = queryStringDecoder2.parameters();
            if (params.containsKey(sLIMITROW)) {
                String snb = getTrimValue(sLIMITROW);
                if (snb != null) {
                    try {
                        int old = getLIMITROW();
                        setLIMITROW(Integer.parseInt(snb));
                        if (getLIMITROW() < 5) {
                            setLIMITROW(old);
                        }
                    } catch (Exception e1) {
                    }
                }
            }
        } else {
            params = null;
        }
    }
}

From source file:org.waarp.openr66.protocol.http.adminssl.HttpSslHandler.java

License:Open Source License

private void checkAuthent(ChannelHandlerContext ctx) {
    newSession = true;/*  w ww.j a v  a2s.c o m*/
    if (request.method() == HttpMethod.GET) {
        String logon = Logon();
        logon = logon.replaceAll(REPLACEMENT.XXXERRORMESGXXX.toString(), "");
        responseContent.append(logon);
        clearSession();
        writeResponse(ctx);
        return;
    } else if (request.method() == HttpMethod.POST) {
        getParams();
        if (params == null) {
            String logon = Logon();
            logon = logon.replaceAll(REPLACEMENT.XXXERRORMESGXXX.toString(),
                    Messages.getString("HttpSslHandler.EmptyLogin"));
            responseContent.append(logon);
            clearSession();
            writeResponse(ctx);
            return;
        }
    }
    boolean getMenu = false;
    if (params.containsKey("Logon")) {
        String name = null, password = null;
        List<String> values = null;
        if (!params.isEmpty()) {
            // get values
            if (params.containsKey("name")) {
                values = params.get("name");
                if (values != null) {
                    name = values.get(0);
                    if (name == null || name.isEmpty()) {
                        getMenu = true;
                    }
                }
            } else {
                getMenu = true;
            }
            // search the nb param
            if ((!getMenu) && params.containsKey("passwd")) {
                values = params.get("passwd");
                if (values != null) {
                    password = values.get(0);
                    if (password == null || password.isEmpty()) {
                        getMenu = true;
                    } else {
                        getMenu = false;
                    }
                } else {
                    getMenu = true;
                }
            } else {
                getMenu = true;
            }
        } else {
            getMenu = true;
        }
        if (!getMenu) {
            logger.debug("Name? " + name.equals(Configuration.configuration.getADMINNAME()) + " Passwd? "
                    + Arrays.equals(password.getBytes(WaarpStringUtils.UTF8),
                            Configuration.configuration.getSERVERADMINKEY()));
            if (name.equals(Configuration.configuration.getADMINNAME())
                    && Arrays.equals(password.getBytes(WaarpStringUtils.UTF8),
                            Configuration.configuration.getSERVERADMINKEY())) {
                authentHttp.getAuth().specialNoSessionAuth(true, Configuration.configuration.getHOST_ID());
                authentHttp.setStatus(70);
            } else {
                try {
                    authentHttp.getAuth().connectionHttps(DbConstant.admin.getSession(), name,
                            FilesystemBasedDigest.passwdCrypt(password.getBytes(WaarpStringUtils.UTF8)));
                } catch (Reply530Exception e1) {
                    getMenu = true;
                } catch (Reply421Exception e1) {
                    getMenu = true;
                }
            }
            if (!authentHttp.isAuthenticated()) {
                authentHttp.setStatus(71);
                logger.debug("Still not authenticated: {}", authentHttp);
                getMenu = true;
            }
            logger.debug("Identified: " + authentHttp.getAuth().isIdentified() + ":"
                    + authentHttp.isAuthenticated());
        }
    } else {
        getMenu = true;
    }
    if (getMenu) {
        String logon = Logon();
        logon = logon.replaceAll(REPLACEMENT.XXXERRORMESGXXX.toString(),
                Messages.getString("HttpSslHandler.BadLogin"));
        responseContent.append(logon);
        clearSession();
        writeResponse(ctx);
    } else {
        // load DbSession
        if (this.dbSession != null) {
            clearSession();
            this.dbSession = null;
        }
        if (this.dbSession == null) {
            try {
                if (DbConstant.admin.isActive()) {
                    this.dbSession = new DbSession(DbConstant.admin, false);
                    DbAdmin.incHttpSession();
                    this.isPrivateDbSession = true;
                }
            } catch (WaarpDatabaseNoConnectionException e1) {
                // Cannot connect so use default connection
                logger.warn("Use default database connection");
                this.dbSession = DbConstant.admin.getSession();
            }
        }
        String index = index();
        responseContent.append(index);
        clearSession();
        admin = new DefaultCookie(R66SESSION + Configuration.configuration.getHOST_ID(),
                Configuration.configuration.getHOST_ID() + Long.toHexString(random.nextLong()));
        sessions.put(admin.value(), this.authentHttp);
        authentHttp.setStatus(72);
        if (this.isPrivateDbSession) {
            dbSessions.put(admin.value(), dbSession);
        }
        logger.debug("CreateSession: " + uriRequest + ":{}", admin);
        writeResponse(ctx);
    }
}

From source file:org.waarp.openr66.protocol.http.HttpFormattedHandler.java

License:Open Source License

@Override
protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception {
    isCurrentRequestXml = false;//from ww w . j  ava  2 s  .  co  m
    isCurrentRequestJson = false;
    status = HttpResponseStatus.OK;
    FullHttpRequest request = this.request = msg;
    QueryStringDecoder queryStringDecoder = new QueryStringDecoder(request.uri());
    uriRequest = queryStringDecoder.path();
    logger.debug("Msg: " + uriRequest);
    if (uriRequest.contains("gre/") || uriRequest.contains("img/") || uriRequest.contains("res/")
            || uriRequest.contains("favicon.ico")) {
        HttpWriteCacheEnable.writeFile(request, ctx, Configuration.configuration.getHttpBasePath() + uriRequest,
                "XYZR66NOSESSION");
        return;
    }
    /*try {
       if (DbConstant.admin.isActive) {
      this.dbSession = new DbSession(DbConstant.admin, false);
      DbAdmin.nbHttpSession++;
      this.isPrivateDbSession = true;
       }
    } catch (WaarpDatabaseNoConnectionException e1) {
       // Cannot connect so use default connection
       logger.warn("Use default database connection");
       this.dbSession = DbConstant.admin.session;
    }*/
    try {
        char cval = 'z';
        long nb = LIMITROW;
        // check the URI
        if (uriRequest.equalsIgnoreCase("/active")) {
            cval = '0';
        } else if (uriRequest.equalsIgnoreCase("/error")) {
            cval = '1';
        } else if (uriRequest.equalsIgnoreCase("/done")) {
            cval = '2';
        } else if (uriRequest.equalsIgnoreCase("/all")) {
            cval = '3';
        } else if (uriRequest.equalsIgnoreCase("/status")) {
            cval = '4';
        } else if (uriRequest.equalsIgnoreCase("/statusxml")) {
            cval = '5';
            nb = 0; // since it could be the default or setup by request
            isCurrentRequestXml = true;
        } else if (uriRequest.toLowerCase().startsWith("/spooled")) {
            cval = '6';
        } else if (uriRequest.equalsIgnoreCase("/statusjson")) {
            cval = '7';
            nb = 0; // since it could be the default or setup by request
            isCurrentRequestJson = true;
        }
        // Get the params according to get or post
        if (request.method() == HttpMethod.GET) {
            params = queryStringDecoder.parameters();
        } else if (request.method() == HttpMethod.POST) {
            ByteBuf content = request.content();
            if (content.isReadable()) {
                String param = content.toString(WaarpStringUtils.UTF8);
                queryStringDecoder = new QueryStringDecoder("/?" + param);
            } else {
                responseContent.append(REQUEST.index.readFileUnique(this));
                writeResponse(ctx);
                return;
            }
            params = queryStringDecoder.parameters();
        }
        boolean getMenu = (cval == 'z');
        boolean extraBoolean = false;
        if (!params.isEmpty()) {
            // if not uri, from get or post
            if (getMenu) {
                String info = getTrimValue(sINFO);
                if (info != null) {
                    getMenu = false;
                    cval = info.charAt(0);
                } else {
                    getMenu = true;
                }
            }
            // search the nb param
            String snb = getTrimValue(sNB);
            if (snb != null) {
                try {
                    nb = Long.parseLong(snb);
                } catch (Exception e1) {
                }
            }
            // search the detail param
            String sdetail = getTrimValue(sDETAIL);
            if (sdetail != null) {
                try {
                    if (Integer.parseInt(sdetail) > 0) {
                        extraBoolean = true;
                    }
                } catch (Exception e1) {
                }
            }
            String langarg = getTrimValue("setLng");
            if (langarg != null && !langarg.isEmpty()) {
                lang = langarg;
            }
        }
        if (getMenu) {
            responseContent.append(REQUEST.index.readFileUnique(this));
        } else {
            // Use value 0=Active 1=Error 2=Done 3=All
            switch (cval) {
            case '0':
                active(ctx, (int) nb);
                break;
            case '1':
                error(ctx, (int) nb);
                break;
            case '2':
                done(ctx, (int) nb);
                break;
            case '3':
                all(ctx, (int) nb);
                break;
            case '4':
                status(ctx, (int) nb);
                break;
            case '5':
                statusxml(ctx, nb, extraBoolean);
                break;
            case '6':
                String name = null;
                if (params.containsKey("name")) {
                    name = getTrimValue("name");
                }
                int istatus = 0;
                if (params.containsKey("status")) {
                    String status = getTrimValue("status");
                    try {
                        istatus = Integer.parseInt(status);
                    } catch (NumberFormatException e1) {
                        istatus = 0;
                    }
                }
                if (uriRequest.toLowerCase().startsWith("/spooleddetail")) {
                    extraBoolean = true;
                }
                spooled(ctx, extraBoolean, name, istatus);
                break;
            case '7':
                statusjson(ctx, nb, extraBoolean);
                break;
            default:
                responseContent.append(REQUEST.index.readFileUnique(this));
            }
        }
        writeResponse(ctx);
    } finally {
        if (this.isPrivateDbSession && dbSession != null) {
            dbSession.forceDisconnect();
            DbAdmin.decHttpSession();
            dbSession = null;
        }
    }
}

From source file:org.waarp.openr66.protocol.http.rest.test.HttpTestRestR66Client.java

License:Open Source License

/**
 * @param args//w ww . j  a  v  a  2s  .  c om
 */
@SuppressWarnings("unused")
public static void main(String[] args) {
    if (args.length > 2) {
        WaarpLoggerFactory.setDefaultFactory(new WaarpSlf4JLoggerFactory(WaarpLogLevel.DEBUG));
    } else {
        WaarpLoggerFactory.setDefaultFactory(new WaarpSlf4JLoggerFactory(null));
    }
    logger = WaarpLoggerFactory.getLogger(HttpTestRestR66Client.class);
    Configuration.configuration.setHOST_ID(hostid);
    if (args.length > 0) {
        NB = Integer.parseInt(args[0]);
        if (Configuration.configuration.getCLIENT_THREAD() < NB) {
            Configuration.configuration.setCLIENT_THREAD(NB + 1);
        }
        if (args.length > 1) {
            NBPERTHREAD = Integer.parseInt(args[1]);
        }
    }
    if (NB == 1 && NBPERTHREAD == 1) {
        DEBUG = true;
    }

    try {
        HttpTestR66PseudoMain.config = HttpTestR66PseudoMain.getTestConfiguration();
    } catch (CryptoException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
        return;
    } catch (IOException e2) {
        // TODO Auto-generated catch block
        e2.printStackTrace();
        return;
    }
    if (HttpTestR66PseudoMain.config.REST_ADDRESS != null) {
        host = HttpTestR66PseudoMain.config.REST_ADDRESS;
    }
    String filename = keydesfilename;
    Configuration.configuration.setCryptoFile(filename);
    File keyfile = new File(filename);
    Des des = new Des();
    try {
        des.setSecretKey(keyfile);
    } catch (CryptoException e) {
        logger.error("Unable to load CryptoKey from Config file");
        return;
    } catch (IOException e) {
        logger.error("Unable to load CryptoKey from Config file");
        return;
    }
    Configuration.configuration.setCryptoKey(des);
    HttpRestR66Handler.instantiateHandlers(HttpTestR66PseudoMain.config);
    // Configure the client.
    clientHelper = new HttpRestR66Client(baseURI, new HttpTestRestClientInitializer(null),
            Configuration.configuration.getCLIENT_THREAD(), Configuration.configuration.getTIMEOUTCON());
    logger.warn("ClientHelper created");
    try {
        try {
            long start = System.currentTimeMillis();
            for (int i = 0; i < NBPERTHREAD; i++) {
                options(null);
            }
            long stop = System.currentTimeMillis();
            long diff = stop - start == 0 ? 1 : stop - start;
            logger.warn("Options: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get());
        } catch (HttpInvalidAuthenticationException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        count.set(0);
        long start = System.currentTimeMillis();
        if (false) {
            for (RESTHANDLERS handler : HttpRestR66Handler.RESTHANDLERS.values()) {
                try {
                    deleteData(handler);
                } catch (HttpInvalidAuthenticationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        long stop = System.currentTimeMillis();
        long diff = stop - start == 0 ? 1 : stop - start;
        if (false) {
            logger.warn("Delete: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get());
        }
        count.set(0);
        start = System.currentTimeMillis();
        for (RestMethodHandler methodHandler : HttpTestR66PseudoMain.config.restHashMap.values()) {
            if (methodHandler instanceof DataModelRestMethodHandler<?>) {
                RESTHANDLERS handler = RESTHANDLERS.getRESTHANDLER(methodHandler.getPath());
                try {
                    multiDataRequests(handler);
                } catch (HttpInvalidAuthenticationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn("Create: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get());
        count.set(0);
        start = System.currentTimeMillis();
        for (RestMethodHandler methodHandler : HttpTestR66PseudoMain.config.restHashMap.values()) {
            if (methodHandler instanceof DataModelRestMethodHandler<?>) {
                RESTHANDLERS handler = RESTHANDLERS.getRESTHANDLER(methodHandler.getPath());
                try {
                    realAllData(handler);
                } catch (HttpInvalidAuthenticationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn("ReadAll: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get());

        count.set(0);
        start = System.currentTimeMillis();
        for (int i = 0; i < NBPERTHREAD; i++) {
            try {
                multiDataRequests(RESTHANDLERS.DbTaskRunner);
            } catch (HttpInvalidAuthenticationException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn(
                "CreateMultiple: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?" + count.get());

        count.set(0);
        start = System.currentTimeMillis();
        launchThreads();
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn("CreateMultipleThread: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD * NB + "=?"
                + count.get());

        // Set usefull item first
        if (RestConfiguration.CRUD.UPDATE.isValid(
                HttpTestR66PseudoMain.config.RESTHANDLERS_CRUD[RESTHANDLERS.DbHostConfiguration.ordinal()])) {
            String key = null, value = null;
            Channel channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT);
            if (channel != null) {
                String buz = null;
                if (HttpTestR66PseudoMain.config.REST_AUTHENTICATED) {
                    key = userAuthent;
                    value = keyAuthent;
                    // Need business
                    buz = "<business><businessid>hostas</businessid><businessid>hosta2</businessid><businessid>hostas2</businessid>"
                            + "<businessid>hosta</businessid><businessid>test</businessid><businessid>tests</businessid>"
                            + "<businessid>" + userAuthent + "</businessid></business>";
                } else {
                    // Need business
                    buz = "<business><businessid>hostas</businessid><businessid>hosta2</businessid><businessid>hostas2</businessid>"
                            + "<businessid>hosta</businessid><businessid>test</businessid><businessid>tests</businessid>"
                            + "<businessid>monadmin</businessid></business>";
                }
                ObjectNode node = JsonHandler.createObjectNode();
                node.put(DbHostConfiguration.Columns.BUSINESS.name(), buz);
                logger.warn("Send query: " + RESTHANDLERS.DbHostConfiguration.uri);
                RestFuture future = clientHelper.sendQuery(HttpTestR66PseudoMain.config, channel,
                        HttpMethod.PUT, host, RESTHANDLERS.DbHostConfiguration.uri + "/hosta", key, value, null,
                        JsonHandler.writeAsString(node));
                try {
                    future.await();
                } catch (InterruptedException e) {
                }
                WaarpSslUtility.closingSslChannel(channel);
            }
            // Need Hostzz
            channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT);
            if (channel != null) {
                AbstractDbData dbData;
                dbData = new DbHostAuth(null, hostid, address, HttpTestR66PseudoMain.config.REST_PORT, false,
                        hostkey.getBytes(), true, false);
                logger.warn("Send query: " + RESTHANDLERS.DbHostAuth.uri);
                RestFuture future = clientHelper.sendQuery(HttpTestR66PseudoMain.config, channel,
                        HttpMethod.POST, host, RESTHANDLERS.DbHostAuth.uri, key, value, null, dbData.asJson());
                try {
                    future.await();
                } catch (InterruptedException e) {
                }
                WaarpSslUtility.closingSslChannel(channel);
            }
        }

        // Other Command as actions
        count.set(0);
        start = System.currentTimeMillis();
        for (RestMethodHandler methodHandler : HttpTestR66PseudoMain.config.restHashMap.values()) {
            if (methodHandler instanceof DataModelRestMethodHandler<?>) {
                RESTHANDLERS handler = RESTHANDLERS.getRESTHANDLER(methodHandler.getPath());
                try {
                    action(handler);
                } catch (HttpInvalidAuthenticationException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
        }
        getStatus();
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn(
                "Commands: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD * NB + "=?" + count.get());

        count.set(0);
        start = System.currentTimeMillis();
        for (int i = 0; i < NBPERTHREAD; i++) {
            getStatus();
        }
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn("GetStatusMultiple: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD + "=?"
                + count.get());

        count.set(0);
        isStatus = true;
        start = System.currentTimeMillis();
        launchThreads();
        stop = System.currentTimeMillis();
        diff = stop - start == 0 ? 1 : stop - start;
        logger.warn("GetStatusMultipleThread: " + count.get() * 1000 / diff + " req/s " + NBPERTHREAD * NB
                + "=?" + count.get());

        // Clean
        if (RestConfiguration.CRUD.UPDATE.isValid(
                HttpTestR66PseudoMain.config.RESTHANDLERS_CRUD[RESTHANDLERS.DbHostConfiguration.ordinal()])) {
            String key = null, value = null;
            Channel channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT);
            if (channel != null) {
                if (HttpTestR66PseudoMain.config.REST_AUTHENTICATED) {
                    key = userAuthent;
                    value = keyAuthent;
                }
                // Reset business
                String buz = "<business><businessid>hostas</businessid><businessid>hosta2</businessid><businessid>hostas2</businessid>"
                        + "<businessid>hosta</businessid><businessid>test</businessid><businessid>tests</businessid></business>";
                ObjectNode node = JsonHandler.createObjectNode();
                node.put(DbHostConfiguration.Columns.BUSINESS.name(), buz);
                logger.warn("Send query: " + RESTHANDLERS.DbHostConfiguration.uri);
                RestFuture future = clientHelper.sendQuery(HttpTestR66PseudoMain.config, channel,
                        HttpMethod.PUT, host, RESTHANDLERS.DbHostConfiguration.uri + "/hosta", key, value, null,
                        JsonHandler.writeAsString(node));
                try {
                    future.await();
                } catch (InterruptedException e) {
                }
                WaarpSslUtility.closingSslChannel(channel);
            }
            // Remove Hostzz
            channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT);
            if (channel != null) {
                try {
                    RestFuture future = deleteData(channel, RESTHANDLERS.DbHostAuth);
                    try {
                        future.await();
                    } catch (InterruptedException e) {
                    }
                } catch (HttpInvalidAuthenticationException e1) {
                }
                WaarpSslUtility.closingSslChannel(channel);
            }
            // Shutdown
            channel = clientHelper.getChannel(host, HttpTestR66PseudoMain.config.REST_PORT);
            if (channel != null) {
                ShutdownOrBlockJsonPacket shutd = new ShutdownOrBlockJsonPacket();
                shutd.setRestartOrBlock(false);
                shutd.setShutdownOrBlock(true);
                shutd.setRequestUserPacket(LocalPacketFactory.SHUTDOWNPACKET);
                String pwd = "pwdhttp";
                byte[] bpwd = FilesystemBasedDigest.passwdCrypt(pwd.getBytes(WaarpStringUtils.UTF8));
                shutd.setKey(bpwd);
                logger.warn("Send query: " + RESTHANDLERS.Server.uri);
                RestFuture future = action(channel, HttpMethod.PUT, RESTHANDLERS.Server.uri, shutd);
                try {
                    future.await();
                } catch (InterruptedException e) {
                }
                WaarpSslUtility.closingSslChannel(channel);
            }
        }
        try {
            Thread.sleep(100);
        } catch (InterruptedException e1) {
        }
    } finally {
        logger.debug("ClientHelper closing");
        clientHelper.closeAll();
        logger.warn("ClientHelper closed");
    }
}