-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
CXF-8931: HttpClientHTTPConduit can't disable the http chunk mode
- Loading branch information
Showing
4 changed files
with
424 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
systests/transports/src/test/java/org/apache/cxf/systest/http/FileStore.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* Licensed to the Apache Software Foundation (ASF) under one | ||
* or more contributor license agreements. See the NOTICE file | ||
* distributed with this work for additional information | ||
* regarding copyright ownership. The ASF licenses this file | ||
* to you under the Apache License, Version 2.0 (the | ||
* "License"); you may not use this file except in compliance | ||
* with the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, | ||
* software distributed under the License is distributed on an | ||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
* KIND, either express or implied. See the License for the | ||
* specific language governing permissions and limitations | ||
* under the License. | ||
*/ | ||
|
||
package org.apache.cxf.systest.http; | ||
|
||
import java.util.Objects; | ||
import java.util.concurrent.ConcurrentHashMap; | ||
import java.util.concurrent.ConcurrentMap; | ||
import java.util.concurrent.ExecutorService; | ||
import java.util.concurrent.Executors; | ||
|
||
import jakarta.activation.DataHandler; | ||
import jakarta.ws.rs.Consumes; | ||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.QueryParam; | ||
import jakarta.ws.rs.container.AsyncResponse; | ||
import jakarta.ws.rs.container.Suspended; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.HttpHeaders; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.core.Response.Status; | ||
import jakarta.ws.rs.core.UriInfo; | ||
import org.apache.cxf.common.util.StringUtils; | ||
import org.apache.cxf.helpers.IOUtils; | ||
import org.apache.cxf.jaxrs.ext.multipart.Attachment; | ||
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody; | ||
|
||
@Path("/file-store") | ||
public class FileStore { | ||
private final ConcurrentMap<String, byte[]> store = new ConcurrentHashMap<>(); | ||
private final ExecutorService executor = Executors.newFixedThreadPool(2); | ||
@Context private HttpHeaders headers; | ||
|
||
@POST | ||
@Consumes("multipart/form-data") | ||
public void addBook(@QueryParam("chunked") boolean chunked, | ||
@Suspended final AsyncResponse response, @Context final UriInfo uri, final MultipartBody body) { | ||
|
||
String transferEncoding = headers.getHeaderString("Transfer-Encoding"); | ||
if (chunked != Objects.equals("chunked", transferEncoding)) { | ||
response.resume(Response.status(Status.EXPECTATION_FAILED).build()); | ||
return; | ||
} | ||
|
||
executor.submit(new Runnable() { | ||
public void run() { | ||
for (final Attachment attachment: body.getAllAttachments()) { | ||
final DataHandler handler = attachment.getDataHandler(); | ||
|
||
if (handler != null) { | ||
final String source = handler.getName(); | ||
if (StringUtils.isEmpty(source)) { | ||
response.resume(Response.status(Status.BAD_REQUEST).build()); | ||
return; | ||
} | ||
|
||
try { | ||
if (store.containsKey(source)) { | ||
response.resume(Response.status(Status.CONFLICT).build()); | ||
return; | ||
} | ||
|
||
final byte[] content = IOUtils.readBytesFromStream(handler.getInputStream()); | ||
if (store.putIfAbsent(source, content) != null) { | ||
response.resume(Response.status(Status.CONFLICT).build()); | ||
return; | ||
} | ||
} catch (final Exception ex) { | ||
response.resume(Response.serverError().build()); | ||
} | ||
|
||
if (response.isSuspended()) { | ||
response.resume(Response.created(uri.getRequestUriBuilder().path(source).build()) | ||
.build()); | ||
} | ||
} | ||
} | ||
|
||
if (response.isSuspended()) { | ||
response.resume(Response.status(Status.BAD_REQUEST).build()); | ||
} | ||
} | ||
}); | ||
} | ||
} |
Oops, something went wrong.