io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.EndOfDataDecoderException Java Examples
The following examples show how to use
io.netty.handler.codec.http.multipart.HttpPostRequestDecoder.EndOfDataDecoderException.
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: HttpWsServer.java From zbus-server with MIT License | 6 votes |
private void handleUploadMessage(io.netty.handler.codec.http.HttpMessage httpMsg, Message uploadMessage) throws IOException{ if (httpMsg instanceof HttpContent) { HttpContent chunk = (HttpContent) httpMsg; decoder.offer(chunk); try { while (decoder.hasNext()) { InterfaceHttpData data = decoder.next(); if (data != null) { try { handleUploadFile(data, uploadMessage); } finally { data.release(); } } } } catch (EndOfDataDecoderException e1) { //ignore } if (chunk instanceof LastHttpContent) { resetUpload(); } } }
Example #2
Source File: HttpUploadServerHandler.java From netty4.0.27Learn with Apache License 2.0 | 6 votes |
/** * Example of reading request by chunk and getting values from chunk to chunk */ private void readHttpDataChunkByChunk() { try { while (decoder.hasNext()) { InterfaceHttpData data = decoder.next(); if (data != null) { try { // new value writeHttpData(data); } finally { data.release(); } } } } catch (EndOfDataDecoderException e1) { // end responseContent.append("\r\n\r\nEND OF CONTENT CHUNK BY CHUNK\r\n\r\n"); } }
Example #3
Source File: HttpPostStandardRequestDecoder.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * True if at current getStatus, there is an available decoded * InterfaceHttpData from the Body. * * This getMethod works for chunked and not chunked request. * * @return True if at current getStatus, there is a decoded InterfaceHttpData * @throws EndOfDataDecoderException * No more data will be available */ @Override public boolean hasNext() { checkDestroyed(); if (currentStatus == MultiPartStatus.EPILOGUE) { // OK except if end of list if (bodyListHttpDataRank >= bodyListHttpData.size()) { throw new EndOfDataDecoderException(); } } return !bodyListHttpData.isEmpty() && bodyListHttpDataRank < bodyListHttpData.size(); }
Example #4
Source File: HttpPostMultipartRequestDecoder.java From netty-4.1.22 with Apache License 2.0 | 5 votes |
/** * True if at current getStatus, there is an available decoded * InterfaceHttpData from the Body. * * This getMethod works for chunked and not chunked request. * * @return True if at current getStatus, there is a decoded InterfaceHttpData * @throws EndOfDataDecoderException * No more data will be available */ @Override public boolean hasNext() { checkDestroyed(); if (currentStatus == MultiPartStatus.EPILOGUE) { // OK except if end of list if (bodyListHttpDataRank >= bodyListHttpData.size()) { throw new EndOfDataDecoderException(); } } return !bodyListHttpData.isEmpty() && bodyListHttpDataRank < bodyListHttpData.size(); }
Example #5
Source File: WebRequestHandler.java From Summer with Apache License 2.0 | 5 votes |
private void doPost(ChannelHandlerContext ctx, SessionContext sctx) { WebRequest webRequest = getWebRequest(); JSONObject data = webRequest.getData(); try { while (postRequestDecoder.hasNext()) { InterfaceHttpData httpData = postRequestDecoder.next(); try { if (httpData.getHttpDataType() == HttpDataType.Attribute || httpData.getHttpDataType() == HttpDataType.InternalAttribute) { Attribute attribute = (Attribute) httpData; data.put(attribute.getName(), attribute.getValue()); } else if (httpData.getHttpDataType() == HttpDataType.FileUpload) { FileUpload fileUpload = (FileUpload) httpData; if (fileUpload.isCompleted()) { webRequest.getFileUploadMap().put(fileUpload.getName(), new WebFileUpload(fileUpload)); } else { log.error("fileUpload not complete name[{}]", fileUpload.getName()); } } } catch (Exception e) { log.error(e.getMessage(), e); } finally { postRequestDecoder.removeHttpDataFromClean(httpData); httpData.release(); } } } catch (EndOfDataDecoderException ignored) { } if (webRequest.isDynamic()) { doWork(ctx, sctx, webRequest); } else { doFile(ctx, sctx, webRequest); } }
Example #6
Source File: HttpPostStandardRequestDecoder.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
/** * True if at current getStatus, there is an available decoded * InterfaceHttpData from the Body. * * This getMethod works for chunked and not chunked request. * * @return True if at current getStatus, there is a decoded InterfaceHttpData * @throws EndOfDataDecoderException * No more data will be available */ @Override public boolean hasNext() { checkDestroyed(); if (currentStatus == MultiPartStatus.EPILOGUE) { // OK except if end of list if (bodyListHttpDataRank >= bodyListHttpData.size()) { throw new EndOfDataDecoderException(); } } return !bodyListHttpData.isEmpty() && bodyListHttpDataRank < bodyListHttpData.size(); }
Example #7
Source File: HttpPostMultipartRequestDecoder.java From netty4.0.27Learn with Apache License 2.0 | 5 votes |
/** * True if at current getStatus, there is an available decoded * InterfaceHttpData from the Body. * * This getMethod works for chunked and not chunked request. * * @return True if at current getStatus, there is a decoded InterfaceHttpData * @throws EndOfDataDecoderException * No more data will be available */ @Override public boolean hasNext() { checkDestroyed(); if (currentStatus == MultiPartStatus.EPILOGUE) { // OK except if end of list if (bodyListHttpDataRank >= bodyListHttpData.size()) { throw new EndOfDataDecoderException(); } } return !bodyListHttpData.isEmpty() && bodyListHttpDataRank < bodyListHttpData.size(); }
Example #8
Source File: UploadHandler.java From blynk-server with GNU General Public License v3.0 | 5 votes |
private String finishUpload() throws Exception { String pathTo = null; try { while (decoder.hasNext()) { InterfaceHttpData data = decoder.next(); if (data != null) { if (data instanceof DiskFileUpload) { DiskFileUpload diskFileUpload = (DiskFileUpload) data; Path tmpFile = diskFileUpload.getFile().toPath(); String uploadedFilename = diskFileUpload.getFilename(); String extension = ""; if (uploadedFilename.contains(".")) { extension = uploadedFilename.substring(uploadedFilename.lastIndexOf("."), uploadedFilename.length()); } String finalName = tmpFile.getFileName().toString() + extension; //this is just to make it work on team city. Path staticPath = Paths.get(staticFolderPath, uploadFolder); if (!Files.exists(staticPath)) { Files.createDirectories(staticPath); } Files.move(tmpFile, Paths.get(staticFolderPath, uploadFolder, finalName), StandardCopyOption.REPLACE_EXISTING); pathTo = uploadFolder + finalName; } } } } catch (EndOfDataDecoderException endOfData) { //ignore. that's fine. } finally { // destroy the decoder to release all resources decoder.destroy(); decoder = null; } return pathTo; }