List of usage examples for io.netty.buffer ByteBuf toString
public abstract String toString(Charset charset);
From source file:org.waarp.ftp.core.data.handler.DataNetworkHandler.java
License:Open Source License
/** * Write a simple message (like LIST) and wait for it * /*from www.j av a2 s . co m*/ * @param message * @return True if the message is correctly written */ public boolean writeMessage(String message) { DataBlock dataBlock = new DataBlock(); dataBlock.setEOF(true); ByteBuf buffer = Unpooled.wrappedBuffer(message.getBytes(WaarpStringUtils.UTF8)); dataBlock.setBlock(buffer); ChannelFuture future; logger.debug("Will write: " + buffer.toString(WaarpStringUtils.UTF8)); try { future = dataChannel.writeAndFlush(dataBlock); future.await(FtpConfiguration.DATATIMEOUTCON); } catch (InterruptedException e) { logger.debug("Interrupted", e); return false; } logger.debug("Write result: " + future.isSuccess(), future.cause()); return future.isSuccess(); }
From source file:org.waarp.ftp.core.data.handler.FtpDataTypeCodec.java
License:Open Source License
/** * //from w w w .ja va2 s . co m * @param ByteBuf * @return the ByteBuf * @throws Exception */ protected ByteBuf decode(ByteBuf ByteBuf) throws Exception { return Unpooled.copiedBuffer(ByteBuf.toString(type.charset), charsetName); }
From source file:org.waarp.ftp.core.data.handler.FtpDataTypeCodec.java
License:Open Source License
/** * // w ww. j a v a 2s . c om * @param ByteBuf * @return the encoded buffer * @throws Exception */ protected ByteBuf encode(ByteBuf ByteBuf) throws Exception { String chString = ByteBuf.toString(charsetName); return Unpooled.copiedBuffer(chString, type.charset); }
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 va 2 s . c o m*/ } 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.kernel.rest.DataModelRestMethodHandler.java
License:Open Source License
public Object getBody(HttpRestHandler handler, ByteBuf body, RestArgument arguments, RestArgument result) throws HttpIncorrectRequestException { // get the Json equivalent of the Body ObjectNode node = null;/*from www . jav a 2s. c o m*/ try { String json = body.toString(WaarpStringUtils.UTF8); node = JsonHandler.getFromString(json); } catch (UnsupportedCharsetException e) { logger.warn("Error", e); throw new HttpIncorrectRequestException(e); } if (node != null) { arguments.getBody().setAll(node); } return node; }
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 av a2 s.co 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.HttpSslHandler.java
License:Open Source License
private void getParams() { if (request.method() == HttpMethod.GET) { params = null;//from www . j a v a 2s .c o m } 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.HttpFormattedHandler.java
License:Open Source License
@Override protected void channelRead0(ChannelHandlerContext ctx, FullHttpRequest msg) throws Exception { isCurrentRequestXml = false;//w w w.j ava 2s. c o 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.handler.HttpRestAbstractR66Handler.java
License:Open Source License
@Override public Object getBody(HttpRestHandler handler, ByteBuf body, RestArgument arguments, RestArgument result) throws HttpIncorrectRequestException { JsonPacket packet = null;/*from www. ja va 2 s. c o m*/ try { String json = body.toString(WaarpStringUtils.UTF8); packet = JsonPacket.createFromBuffer(json); } catch (JsonParseException e) { logger.warn("Error: " + body.toString(WaarpStringUtils.UTF8), e); throw new HttpIncorrectRequestException(e); } catch (JsonMappingException e) { logger.warn("Error", e); throw new HttpIncorrectRequestException(e); } catch (IOException e) { logger.warn("Error", e); throw new HttpIncorrectRequestException(e); } catch (UnsupportedCharsetException e) { logger.warn("Error", e); throw new HttpIncorrectRequestException(e); } return packet; }