flink-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sihuazhou <...@git.apache.org>
Subject [GitHub] flink pull request #6189: [FLINK-9599][rest] RestClient supports FileUploads...
Date Thu, 21 Jun 2018 04:48:48 GMT
Github user sihuazhou commented on a diff in the pull request:

    https://github.com/apache/flink/pull/6189#discussion_r197008798
  
    --- Diff: flink-runtime/src/main/java/org/apache/flink/runtime/rest/AbstractHandler.java
---
    @@ -103,77 +102,68 @@ protected void respondAsLeader(ChannelHandlerContext ctx, RoutedRequest
routedRe
     				return;
     			}
     
    -			ByteBuf msgContent = ((FullHttpRequest) httpRequest).content();
    -
    -			R request;
    -			if (isFileUpload()) {
    -				final Path path = ctx.channel().attr(FileUploadHandler.UPLOADED_FILE).get();
    -				if (path == null) {
    -					HandlerUtils.sendErrorResponse(
    -						ctx,
    -						httpRequest,
    -						new ErrorResponseBody("Client did not upload a file."),
    -						HttpResponseStatus.BAD_REQUEST,
    -						responseHeaders);
    -					return;
    -				}
    -				//noinspection unchecked
    -				request = (R) new FileUpload(path);
    -			} else if (msgContent.capacity() == 0) {
    -				try {
    -					request = MAPPER.readValue("{}", untypedResponseMessageHeaders.getRequestClass());
    -				} catch (JsonParseException | JsonMappingException je) {
    -					log.error("Request did not conform to expected format.", je);
    -					HandlerUtils.sendErrorResponse(
    -						ctx,
    -						httpRequest,
    -						new ErrorResponseBody("Bad request received."),
    -						HttpResponseStatus.BAD_REQUEST,
    -						responseHeaders);
    -					return;
    +			final ByteBuf msgContent = ((FullHttpRequest) httpRequest).content();
    +
    +			try (FileUploads uploadedFiles = FileUploadHandler.getMultipartFileUploads(ctx)) {
    +
    +				R request;
    +				if (msgContent.capacity() == 0) {
    +					try {
    +						request = MAPPER.readValue("{}", untypedResponseMessageHeaders.getRequestClass());
    +					} catch (JsonParseException | JsonMappingException je) {
    +						log.error("Request did not conform to expected format.", je);
    +						HandlerUtils.sendErrorResponse(
    +							ctx,
    +							httpRequest,
    +							new ErrorResponseBody("Bad request received."),
    +							HttpResponseStatus.BAD_REQUEST,
    +							responseHeaders);
    +						return;
    +					}
    +				} else {
    +					try {
    +						ByteBufInputStream in = new ByteBufInputStream(msgContent);
    --- End diff --
    
    I would suggest to use try-with-resource to make sure to close `in`.


---

Mime
View raw message