Last active
August 29, 2015 14:15
-
-
Save mgajdos/290ee69a85447bc05af7 to your computer and use it in GitHub Desktop.
PR #143 Patch
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
diff --git a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderClientSide.java b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderClientSide.java | |
index 49fa175..e91d4d0 100644 | |
--- a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderClientSide.java | |
+++ b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderClientSide.java | |
@@ -137,6 +137,7 @@ public class MultiPartReaderClientSide implements MessageBodyReader<MultiPart> { | |
if (properties.getBufferThreshold() != MultiPartProperties.BUFFER_THRESHOLD_MEMORY_ONLY) { | |
// Validate - this checks whether it's possible to create temp files in currently set temp directory. | |
try { | |
+ //noinspection ResultOfMethodCallIgnored | |
File.createTempFile("MIME", null, tempDir != null ? new File(tempDir) : null).delete(); | |
} catch (final IOException ioe) { | |
LOGGER.log(Level.WARNING, LocalizationMessages.TEMP_FILE_CANNOT_BE_CREATED(properties.getBufferThreshold()), ioe); | |
@@ -192,55 +193,56 @@ public class MultiPartReaderClientSide implements MessageBodyReader<MultiPart> { | |
MediaType mediaType, | |
final MultivaluedMap<String, String> headers, | |
final InputStream stream) throws IOException, MIMEParsingException { | |
- mediaType = unquoteMediaTypeParameters(mediaType, "boundary"); | |
+ mediaType = unquoteMediaTypeParameters(mediaType, "boundary"); | |
+ | |
final MIMEMessage mimeMessage = new MIMEMessage(stream, | |
mediaType.getParameters().get("boundary"), | |
mimeConfig); | |
- boolean formData = MediaTypes.typeEqual(mediaType, MediaType.MULTIPART_FORM_DATA_TYPE); | |
- MultiPart multiPart = formData ? new FormDataMultiPart() : new MultiPart(); | |
+ final boolean formData = MediaTypes.typeEqual(mediaType, MediaType.MULTIPART_FORM_DATA_TYPE); | |
+ final MultiPart multiPart = formData ? new FormDataMultiPart() : new MultiPart(); | |
final MessageBodyWorkers workers = messageBodyWorkers.get(); | |
multiPart.setMessageBodyWorkers(workers); | |
- MultivaluedMap<String, String> multiPartHeaders = multiPart.getHeaders(); | |
- for (Map.Entry<String, List<String>> entry : headers.entrySet()) { | |
- List<String> values = entry.getValue(); | |
+ final MultivaluedMap<String, String> multiPartHeaders = multiPart.getHeaders(); | |
+ for (final Map.Entry<String, List<String>> entry : headers.entrySet()) { | |
+ final List<String> values = entry.getValue(); | |
- for (String value : values) { | |
+ for (final String value : values) { | |
multiPartHeaders.add(entry.getKey(), value); | |
} | |
} | |
- boolean fileNameFix; | |
+ final boolean fileNameFix; | |
if (!formData) { | |
multiPart.setMediaType(mediaType); | |
fileNameFix = false; | |
} else { | |
// see if the User-Agent header corresponds to some version of MS Internet Explorer | |
// if so, need to set fileNameFix to true to handle issue http://java.net/jira/browse/JERSEY-759 | |
- String userAgent = headers.getFirst(HttpHeaders.USER_AGENT); | |
+ final String userAgent = headers.getFirst(HttpHeaders.USER_AGENT); | |
fileNameFix = userAgent != null && userAgent.contains(" MSIE "); | |
} | |
- for (MIMEPart mimePart : mimeMessage.getAttachments()) { | |
- BodyPart bodyPart = formData ? new FormDataBodyPart(fileNameFix) : new BodyPart(); | |
+ for (final MIMEPart mimePart : mimeMessage.getAttachments()) { | |
+ final BodyPart bodyPart = formData ? new FormDataBodyPart(fileNameFix) : new BodyPart(); | |
// Configure providers. | |
bodyPart.setMessageBodyWorkers(workers); | |
// Copy headers. | |
- for (Header header : mimePart.getAllHeaders()) { | |
+ for (final Header header : mimePart.getAllHeaders()) { | |
bodyPart.getHeaders().add(header.getName(), header.getValue()); | |
} | |
try { | |
- String contentType = bodyPart.getHeaders().getFirst("Content-Type"); | |
+ final String contentType = bodyPart.getHeaders().getFirst("Content-Type"); | |
if (contentType != null) | |
bodyPart.setMediaType(MediaType.valueOf(contentType)); | |
bodyPart.getContentDisposition(); | |
- } catch (IllegalArgumentException ex) { | |
+ } catch (final IllegalArgumentException ex) { | |
throw new BadRequestException(ex); | |
} | |
@@ -253,13 +255,13 @@ public class MultiPartReaderClientSide implements MessageBodyReader<MultiPart> { | |
return multiPart; | |
} | |
- | |
+ | |
protected static MediaType unquoteMediaTypeParameters(final MediaType mediaType, final String... parameters) { | |
- if (parameters == null || parameters.length == 0) { | |
+ if (parameters == null || parameters.length == 0) { | |
return mediaType; | |
} | |
- final Map<String, String> unquotedParams = new HashMap<String, String>(mediaType.getParameters()); | |
+ final Map<String, String> unquotedParams = new HashMap<>(mediaType.getParameters()); | |
for (final String parameterName : parameters) { | |
String parameterValue = mediaType.getParameters().get(parameterName); | |
diff --git a/pom.xml b/pom.xml | |
index 0871e27..7eda260 100644 | |
--- a/pom.xml | |
+++ b/pom.xml | |
@@ -1486,13 +1486,6 @@ | |
<artifactId>jmh-generator-annprocess</artifactId> | |
<version>${jmh.version}</version> | |
</dependency> | |
- <!-- For testing multipart support with another http client --> | |
- <dependency> | |
- <groupId>org.apache.cxf</groupId> | |
- <artifactId>cxf-rt-rs-client</artifactId> | |
- <version>${apache.cxf.client.version}</version> | |
- <scope>test</scope> | |
- </dependency> | |
</dependencies> | |
</dependencyManagement> | |
@@ -1574,6 +1567,5 @@ | |
<validation.api.version>1.1.0.Final</validation.api.version> | |
<weld.version>2.2.8.Final</weld.version> | |
<xerces.version>2.11.0</xerces.version> | |
- <apache.cxf.client.version>3.0.3</apache.cxf.client.version> | |
</properties> | |
</project> | |
diff --git a/tests/integration/jersey-2776/pom.xml b/tests/integration/jersey-2776/pom.xml | |
index 8687bfe..5d1ba74 100644 | |
--- a/tests/integration/jersey-2776/pom.xml | |
+++ b/tests/integration/jersey-2776/pom.xml | |
@@ -1,85 +1,104 @@ | |
<?xml version="1.0" encoding="UTF-8"?> | |
-<!-- DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. Copyright (c) | |
- 2011-2015 Oracle and/or its affiliates. All rights reserved. The contents | |
- of this file are subject to the terms of either the GNU General Public License | |
- Version 2 only ("GPL") or the Common Development and Distribution License("CDDL") | |
- (collectively, the "License"). You may not use this file except in compliance | |
- with the License. You can obtain a copy of the License at http://glassfish.java.net/public/CDDL+GPL_1_1.html | |
- or packager/legal/LICENSE.txt. See the License for the specific language | |
- governing permissions and limitations under the License. When distributing | |
- the software, include this License Header Notice in each file and include | |
- the License file at packager/legal/LICENSE.txt. GPL Classpath Exception: | |
- Oracle designates this particular file as subject to the "Classpath" exception | |
- as provided by Oracle in the GPL Version 2 section of the License file that | |
- accompanied this code. Modifications: If applicable, add the following below | |
- the License Header, with the fields enclosed by brackets [] replaced by your | |
- own identifying information: "Portions Copyright [year] [name of copyright | |
- owner]" Contributor(s): If you wish your version of this file to be governed | |
- by only the CDDL or only the GPL Version 2, indicate your decision by adding | |
- "[Contributor] elects to include this software in this distribution under | |
- the [CDDL or GPL Version 2] license." If you don't indicate a single choice | |
- of license, a recipient has the option to distribute your version of this | |
- file under either the CDDL, the GPL Version 2 or to extend the choice of | |
- license to its licensees as provided above. However, if you add GPL Version | |
- 2 code and therefore, elected the GPL Version 2 license, then the option | |
- applies only if the new code is made subject to such option by the copyright | |
- holder. --> | |
+<!-- | |
+ | |
+ DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
+ | |
+ Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. | |
+ | |
+ The contents of this file are subject to the terms of either the GNU | |
+ General Public License Version 2 only ("GPL") or the Common Development | |
+ and Distribution License("CDDL") (collectively, the "License"). You | |
+ may not use this file except in compliance with the License. You can | |
+ obtain a copy of the License at | |
+ http://glassfish.java.net/public/CDDL+GPL_1_1.html | |
+ or packager/legal/LICENSE.txt. See the License for the specific | |
+ language governing permissions and limitations under the License. | |
+ | |
+ When distributing the software, include this License Header Notice in each | |
+ file and include the License file at packager/legal/LICENSE.txt. | |
+ | |
+ GPL Classpath Exception: | |
+ Oracle designates this particular file as subject to the "Classpath" | |
+ exception as provided by Oracle in the GPL Version 2 section of the License | |
+ file that accompanied this code. | |
+ | |
+ Modifications: | |
+ If applicable, add the following below the License Header, with the fields | |
+ enclosed by brackets [] replaced by your own identifying information: | |
+ "Portions Copyright [year] [name of copyright owner]" | |
+ | |
+ Contributor(s): | |
+ If you wish your version of this file to be governed by only the CDDL or | |
+ only the GPL Version 2, indicate your decision by adding "[Contributor] | |
+ elects to include this software in this distribution under the [CDDL or GPL | |
+ Version 2] license." If you don't indicate a single choice of license, a | |
+ recipient has the option to distribute your version of this file under | |
+ either the CDDL, the GPL Version 2 or to extend the choice of license to | |
+ its licensees as provided above. However, if you add GPL Version 2 code | |
+ and therefore, elected the GPL Version 2 license, then the option applies | |
+ only if the new code is made subject to such option by the copyright | |
+ holder. | |
+ | |
+--> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
- <modelVersion>4.0.0</modelVersion> | |
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
+ <modelVersion>4.0.0</modelVersion> | |
- <parent> | |
- <groupId>org.glassfish.jersey.tests.integration</groupId> | |
- <artifactId>project</artifactId> | |
- <version>2.16-SNAPSHOT</version> | |
- </parent> | |
+ <parent> | |
+ <groupId>org.glassfish.jersey.tests.integration</groupId> | |
+ <artifactId>project</artifactId> | |
+ <version>2.17-SNAPSHOT</version> | |
+ </parent> | |
- <artifactId>jersey-2776</artifactId> | |
- <packaging>war</packaging> | |
- <name>jersey-tests-integration-jersey-2776</name> | |
+ <artifactId>jersey-2776</artifactId> | |
+ <packaging>war</packaging> | |
+ <name>jersey-tests-integration-jersey-2776</name> | |
- <description> | |
- This test is to verify that multipart support (server side) works even if apache cxf's RuntimeDelegateImpl | |
- is used instead of the RuntimeDelegateImpl shipped with jersey. | |
+ <description> | |
+ This test is to verify that multipart support (server side) works even if apache CXF's RuntimeDelegateImpl is used instead | |
+ of the RuntimeDelegateImpl shipped with Jersey. | |
</description> | |
- <dependencies> | |
- <!-- The order of these imports are important as it's the first dependency | |
- that has a javax.ws.rs.ext.RuntimeDelegate in the services that will be used. --> | |
- <dependency> | |
- <groupId>org.apache.cxf</groupId> | |
- <artifactId>cxf-rt-rs-client</artifactId> | |
- <scope>test</scope> | |
- </dependency> | |
- <dependency> | |
- <groupId>org.glassfish.jersey.containers</groupId> | |
- <artifactId>jersey-container-servlet-core</artifactId> | |
- </dependency> | |
- <dependency> | |
- <groupId>org.glassfish.jersey.media</groupId> | |
- <artifactId>jersey-media-multipart</artifactId> | |
- </dependency> | |
- <dependency> | |
- <groupId>org.glassfish.jersey.test-framework.providers</groupId> | |
- <artifactId>jersey-test-framework-provider-jetty</artifactId> | |
- </dependency> | |
- </dependencies> | |
+ <dependencies> | |
+ <!-- For testing multipart support with another http client --> | |
+ <!-- The order of these imports are important as it's the first dependency that has a javax.ws.rs.ext.RuntimeDelegate in | |
+ the services that will be used. --> | |
+ <dependency> | |
+ <groupId>org.apache.cxf</groupId> | |
+ <artifactId>cxf-rt-rs-client</artifactId> | |
+ <version>3.0.3</version> | |
+ <scope>test</scope> | |
+ </dependency> | |
+ | |
+ <dependency> | |
+ <groupId>org.glassfish.jersey.containers</groupId> | |
+ <artifactId>jersey-container-servlet-core</artifactId> | |
+ </dependency> | |
+ <dependency> | |
+ <groupId>org.glassfish.jersey.media</groupId> | |
+ <artifactId>jersey-media-multipart</artifactId> | |
+ </dependency> | |
+ <dependency> | |
+ <groupId>org.glassfish.jersey.test-framework.providers</groupId> | |
+ <artifactId>jersey-test-framework-provider-jetty</artifactId> | |
+ </dependency> | |
+ </dependencies> | |
- <build> | |
- <plugins> | |
- <plugin> | |
- <groupId>org.apache.maven.plugins</groupId> | |
- <artifactId>maven-compiler-plugin</artifactId> | |
- </plugin> | |
- <plugin> | |
- <groupId>org.apache.maven.plugins</groupId> | |
- <artifactId>maven-failsafe-plugin</artifactId> | |
- </plugin> | |
- <plugin> | |
- <groupId>org.mortbay.jetty</groupId> | |
- <artifactId>jetty-maven-plugin</artifactId> | |
- </plugin> | |
- </plugins> | |
- </build> | |
+ <build> | |
+ <plugins> | |
+ <plugin> | |
+ <groupId>org.apache.maven.plugins</groupId> | |
+ <artifactId>maven-compiler-plugin</artifactId> | |
+ </plugin> | |
+ <plugin> | |
+ <groupId>org.apache.maven.plugins</groupId> | |
+ <artifactId>maven-failsafe-plugin</artifactId> | |
+ </plugin> | |
+ <plugin> | |
+ <groupId>org.mortbay.jetty</groupId> | |
+ <artifactId>jetty-maven-plugin</artifactId> | |
+ </plugin> | |
+ </plugins> | |
+ </build> | |
</project> | |
diff --git a/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestApplication.java b/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestApplication.java | |
index 93e6a4b..7346bad 100644 | |
--- a/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestApplication.java | |
+++ b/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestApplication.java | |
@@ -1,32 +1,38 @@ | |
/* | |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
- * Copyright (c) 2012-2014 Oracle and/or its affiliates. All rights reserved. | |
+ * | |
+ * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. | |
+ * | |
* The contents of this file are subject to the terms of either the GNU | |
* General Public License Version 2 only ("GPL") or the Common Development | |
- * and Distribution License("CDDL") (collectively, the "License"). You | |
- * may not use this file except in compliance with the License. You can | |
+ * and Distribution License("CDDL") (collectively, the "License"). You | |
+ * may not use this file except in compliance with the License. You can | |
* obtain a copy of the License at | |
* http://glassfish.java.net/public/CDDL+GPL_1_1.html | |
- * or packager/legal/LICENSE.txt. See the License for the specific | |
+ * or packager/legal/LICENSE.txt. See the License for the specific | |
* language governing permissions and limitations under the License. | |
+ * | |
* When distributing the software, include this License Header Notice in each | |
* file and include the License file at packager/legal/LICENSE.txt. | |
+ * | |
* GPL Classpath Exception: | |
* Oracle designates this particular file as subject to the "Classpath" | |
* exception as provided by Oracle in the GPL Version 2 section of the License | |
* file that accompanied this code. | |
+ * | |
* Modifications: | |
* If applicable, add the following below the License Header, with the fields | |
* enclosed by brackets [] replaced by your own identifying information: | |
* "Portions Copyright [year] [name of copyright owner]" | |
+ * | |
* Contributor(s): | |
* If you wish your version of this file to be governed by only the CDDL or | |
* only the GPL Version 2, indicate your decision by adding "[Contributor] | |
* elects to include this software in this distribution under the [CDDL or GPL | |
- * Version 2] license." If you don't indicate a single choice of license, a | |
+ * Version 2] license." If you don't indicate a single choice of license, a | |
* recipient has the option to distribute your version of this file under | |
* either the CDDL, the GPL Version 2 or to extend the choice of license to | |
- * its licensees as provided above. However, if you add GPL Version 2 code | |
+ * its licensees as provided above. However, if you add GPL Version 2 code | |
* and therefore, elected the GPL Version 2 license, then the option applies | |
* only if the new code is made subject to such option by the copyright | |
* holder. | |
@@ -39,9 +45,9 @@ import org.glassfish.jersey.server.ResourceConfig; | |
/** | |
* Jersey application. | |
*/ | |
-public class TestApplication extends ResourceConfig{ | |
+public class TestApplication extends ResourceConfig { | |
- public TestApplication(){ | |
+ public TestApplication() { | |
register(TestResource.class); | |
register(MultiPartFeature.class); | |
} | |
diff --git a/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestResource.java b/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestResource.java | |
index 59eaf5f..6f0bcb2 100644 | |
--- a/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestResource.java | |
+++ b/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestResource.java | |
@@ -1,32 +1,38 @@ | |
/* | |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
- * Copyright (c) 2012-2014 Oracle and/or its affiliates. All rights reserved. | |
+ * | |
+ * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. | |
+ * | |
* The contents of this file are subject to the terms of either the GNU | |
* General Public License Version 2 only ("GPL") or the Common Development | |
- * and Distribution License("CDDL") (collectively, the "License"). You | |
- * may not use this file except in compliance with the License. You can | |
+ * and Distribution License("CDDL") (collectively, the "License"). You | |
+ * may not use this file except in compliance with the License. You can | |
* obtain a copy of the License at | |
* http://glassfish.java.net/public/CDDL+GPL_1_1.html | |
- * or packager/legal/LICENSE.txt. See the License for the specific | |
+ * or packager/legal/LICENSE.txt. See the License for the specific | |
* language governing permissions and limitations under the License. | |
+ * | |
* When distributing the software, include this License Header Notice in each | |
* file and include the License file at packager/legal/LICENSE.txt. | |
+ * | |
* GPL Classpath Exception: | |
* Oracle designates this particular file as subject to the "Classpath" | |
* exception as provided by Oracle in the GPL Version 2 section of the License | |
* file that accompanied this code. | |
+ * | |
* Modifications: | |
* If applicable, add the following below the License Header, with the fields | |
* enclosed by brackets [] replaced by your own identifying information: | |
* "Portions Copyright [year] [name of copyright owner]" | |
+ * | |
* Contributor(s): | |
* If you wish your version of this file to be governed by only the CDDL or | |
* only the GPL Version 2, indicate your decision by adding "[Contributor] | |
* elects to include this software in this distribution under the [CDDL or GPL | |
- * Version 2] license." If you don't indicate a single choice of license, a | |
+ * Version 2] license." If you don't indicate a single choice of license, a | |
* recipient has the option to distribute your version of this file under | |
* either the CDDL, the GPL Version 2 or to extend the choice of license to | |
- * its licensees as provided above. However, if you add GPL Version 2 code | |
+ * its licensees as provided above. However, if you add GPL Version 2 code | |
* and therefore, elected the GPL Version 2 license, then the option applies | |
* only if the new code is made subject to such option by the copyright | |
* holder. | |
@@ -43,12 +49,12 @@ import org.glassfish.jersey.media.multipart.FormDataBodyPart; | |
import org.glassfish.jersey.media.multipart.FormDataParam; | |
@Path("/files") | |
-public class TestResource{ | |
+public class TestResource { | |
@POST | |
@Consumes(MediaType.MULTIPART_FORM_DATA) | |
@Produces(MediaType.TEXT_PLAIN) | |
- public String uploadDocument(@FormDataParam("file_path") FormDataBodyPart body){ | |
+ public String uploadDocument(@FormDataParam("file_path") final FormDataBodyPart body) { | |
return body.getValueAs(String.class); | |
} | |
} | |
diff --git a/tests/integration/jersey-2776/src/test/java/org/glassfish/jersey/tests/integration/jersey2776/Jersey2776ITCase.java b/tests/integration/jersey-2776/src/test/java/org/glassfish/jersey/tests/integration/jersey2776/Jersey2776ITCase.java | |
index c7bf999..f05ad1a 100644 | |
--- a/tests/integration/jersey-2776/src/test/java/org/glassfish/jersey/tests/integration/jersey2776/Jersey2776ITCase.java | |
+++ b/tests/integration/jersey-2776/src/test/java/org/glassfish/jersey/tests/integration/jersey2776/Jersey2776ITCase.java | |
@@ -1,41 +1,44 @@ | |
/* | |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER. | |
- * Copyright (c) 2012-2014 Oracle and/or its affiliates. All rights reserved. | |
+ * | |
+ * Copyright (c) 2015 Oracle and/or its affiliates. All rights reserved. | |
+ * | |
* The contents of this file are subject to the terms of either the GNU | |
* General Public License Version 2 only ("GPL") or the Common Development | |
- * and Distribution License("CDDL") (collectively, the "License"). You | |
- * may not use this file except in compliance with the License. You can | |
+ * and Distribution License("CDDL") (collectively, the "License"). You | |
+ * may not use this file except in compliance with the License. You can | |
* obtain a copy of the License at | |
* http://glassfish.java.net/public/CDDL+GPL_1_1.html | |
- * or packager/legal/LICENSE.txt. See the License for the specific | |
+ * or packager/legal/LICENSE.txt. See the License for the specific | |
* language governing permissions and limitations under the License. | |
+ * | |
* When distributing the software, include this License Header Notice in each | |
* file and include the License file at packager/legal/LICENSE.txt. | |
+ * | |
* GPL Classpath Exception: | |
* Oracle designates this particular file as subject to the "Classpath" | |
* exception as provided by Oracle in the GPL Version 2 section of the License | |
* file that accompanied this code. | |
+ * | |
* Modifications: | |
* If applicable, add the following below the License Header, with the fields | |
* enclosed by brackets [] replaced by your own identifying information: | |
* "Portions Copyright [year] [name of copyright owner]" | |
+ * | |
* Contributor(s): | |
* If you wish your version of this file to be governed by only the CDDL or | |
* only the GPL Version 2, indicate your decision by adding "[Contributor] | |
* elects to include this software in this distribution under the [CDDL or GPL | |
- * Version 2] license." If you don't indicate a single choice of license, a | |
+ * Version 2] license." If you don't indicate a single choice of license, a | |
* recipient has the option to distribute your version of this file under | |
* either the CDDL, the GPL Version 2 or to extend the choice of license to | |
- * its licensees as provided above. However, if you add GPL Version 2 code | |
+ * its licensees as provided above. However, if you add GPL Version 2 code | |
* and therefore, elected the GPL Version 2 license, then the option applies | |
* only if the new code is made subject to such option by the copyright | |
* holder. | |
*/ | |
package org.glassfish.jersey.tests.integration.jersey2776; | |
-import static org.hamcrest.CoreMatchers.equalTo; | |
-import static org.junit.Assert.assertThat; | |
- | |
import java.nio.charset.StandardCharsets; | |
import javax.ws.rs.Consumes; | |
@@ -45,28 +48,32 @@ import javax.ws.rs.Produces; | |
import javax.ws.rs.core.Application; | |
import javax.ws.rs.core.MediaType; | |
+import org.glassfish.jersey.media.multipart.internal.MultiPartReaderClientSide; | |
+import org.glassfish.jersey.test.JerseyTest; | |
+ | |
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; | |
import org.apache.cxf.jaxrs.ext.multipart.Attachment; | |
import org.apache.cxf.jaxrs.ext.multipart.AttachmentBuilder; | |
import org.apache.cxf.jaxrs.ext.multipart.ContentDisposition; | |
import org.apache.cxf.jaxrs.ext.multipart.MultipartBody; | |
-import org.glassfish.jersey.media.multipart.internal.MultiPartReaderClientSide; | |
-import org.glassfish.jersey.test.JerseyTest; | |
import org.junit.Test; | |
+import static org.hamcrest.CoreMatchers.equalTo; | |
+import static org.junit.Assert.assertThat; | |
/** | |
* Code under test: {@link MultiPartReaderClientSide} (unquoteMediaTypeParameters) | |
+ * | |
* @author Jonatan Jönsson (jontejj at gmail.com) | |
*/ | |
-public class Jersey2776ITCase extends JerseyTest{ | |
+public class Jersey2776ITCase extends JerseyTest { | |
@Override | |
- protected Application configure(){ | |
+ protected Application configure() { | |
return new TestApplication(); | |
} | |
@Path("/files") | |
- public interface ApacheCxfMultipartClient{ | |
+ public interface ApacheCxfMultipartClient { | |
@POST | |
@Consumes(MediaType.MULTIPART_FORM_DATA) | |
@@ -75,18 +82,20 @@ public class Jersey2776ITCase extends JerseyTest{ | |
} | |
@Test | |
- public void testThatMultipartServerSupportsBoundaryQuotesEvenWithInterferingRuntimeDelegate(){ | |
- JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); | |
+ public void testThatMultipartServerSupportsBoundaryQuotesEvenWithInterferingRuntimeDelegate() { | |
+ final JAXRSClientFactoryBean bean = new JAXRSClientFactoryBean(); | |
bean.setAddress(getBaseUri().toString()); | |
bean.setServiceClass(ApacheCxfMultipartClient.class); | |
- ApacheCxfMultipartClient cxfClient = bean.create(ApacheCxfMultipartClient.class); | |
+ final ApacheCxfMultipartClient cxfClient = bean.create(ApacheCxfMultipartClient.class); | |
- String originalContent = "abc"; | |
- byte[] content = originalContent.getBytes(StandardCharsets.US_ASCII); | |
- Attachment fileAttachment = new AttachmentBuilder().object(content) | |
- .contentDisposition(new ContentDisposition("form-data; filename=\"abc-file\"; name=\"file_path\"")).build(); | |
+ final String originalContent = "abc"; | |
+ final byte[] content = originalContent.getBytes(StandardCharsets.US_ASCII); | |
+ final Attachment fileAttachment = new AttachmentBuilder() | |
+ .object(content) | |
+ .contentDisposition(new ContentDisposition("form-data; filename=\"abc-file\"; name=\"file_path\"")) | |
+ .build(); | |
- String fileContentReturnedFromServer = cxfClient.uploadDocument(new MultipartBody(fileAttachment)); | |
+ final String fileContentReturnedFromServer = cxfClient.uploadDocument(new MultipartBody(fileAttachment)); | |
assertThat(fileContentReturnedFromServer, equalTo(originalContent)); | |
} | |
} |
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
diff --git a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderClientSide.java b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderClientSide.java | |
index e91d4d0..4fcc261 100644 | |
--- a/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderClientSide.java | |
+++ b/media/multipart/src/main/java/org/glassfish/jersey/media/multipart/internal/MultiPartReaderClientSide.java | |
@@ -262,13 +262,12 @@ public class MultiPartReaderClientSide implements MessageBodyReader<MultiPart> { | |
} | |
final Map<String, String> unquotedParams = new HashMap<>(mediaType.getParameters()); | |
+ for (final String parameter : parameters) { | |
+ String value = mediaType.getParameters().get(parameter); | |
- for (final String parameterName : parameters) { | |
- String parameterValue = mediaType.getParameters().get(parameterName); | |
- | |
- if (parameterValue.startsWith("\"")) { | |
- parameterValue = parameterValue.substring(1, parameterValue.length() - 1); | |
- unquotedParams.put(parameterName, parameterValue); | |
+ if (value != null && value.startsWith("\"")) { | |
+ value = value.substring(1, value.length() - 1); | |
+ unquotedParams.put(parameter, value); | |
} | |
} | |
diff --git a/tests/integration/jersey-2776/pom.xml b/tests/integration/jersey-2776/pom.xml | |
index 5d1ba74..e113aef 100644 | |
--- a/tests/integration/jersey-2776/pom.xml | |
+++ b/tests/integration/jersey-2776/pom.xml | |
@@ -72,15 +72,17 @@ | |
<dependency> | |
<groupId>org.glassfish.jersey.containers</groupId> | |
- <artifactId>jersey-container-servlet-core</artifactId> | |
+ <artifactId>jersey-container-servlet</artifactId> | |
</dependency> | |
<dependency> | |
<groupId>org.glassfish.jersey.media</groupId> | |
<artifactId>jersey-media-multipart</artifactId> | |
</dependency> | |
+ | |
<dependency> | |
<groupId>org.glassfish.jersey.test-framework.providers</groupId> | |
- <artifactId>jersey-test-framework-provider-jetty</artifactId> | |
+ <artifactId>jersey-test-framework-provider-external</artifactId> | |
+ <scope>test</scope> | |
</dependency> | |
</dependencies> | |
diff --git a/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestApplication.java b/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestApplication.java | |
index 7346bad..368acca 100644 | |
--- a/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestApplication.java | |
+++ b/tests/integration/jersey-2776/src/main/java/org/glassfish/jersey/tests/integration/jersey2776/TestApplication.java | |
@@ -39,12 +39,15 @@ | |
*/ | |
package org.glassfish.jersey.tests.integration.jersey2776; | |
+import javax.ws.rs.ApplicationPath; | |
+ | |
import org.glassfish.jersey.media.multipart.MultiPartFeature; | |
import org.glassfish.jersey.server.ResourceConfig; | |
/** | |
* Jersey application. | |
*/ | |
+@ApplicationPath("/") | |
public class TestApplication extends ResourceConfig { | |
public TestApplication() { | |
diff --git a/tests/integration/jersey-2776/src/test/java/org/glassfish/jersey/tests/integration/jersey2776/Jersey2776ITCase.java b/tests/integration/jersey-2776/src/test/java/org/glassfish/jersey/tests/integration/jersey2776/Jersey2776ITCase.java | |
index f05ad1a..676875c 100644 | |
--- a/tests/integration/jersey-2776/src/test/java/org/glassfish/jersey/tests/integration/jersey2776/Jersey2776ITCase.java | |
+++ b/tests/integration/jersey-2776/src/test/java/org/glassfish/jersey/tests/integration/jersey2776/Jersey2776ITCase.java | |
@@ -50,6 +50,9 @@ import javax.ws.rs.core.MediaType; | |
import org.glassfish.jersey.media.multipart.internal.MultiPartReaderClientSide; | |
import org.glassfish.jersey.test.JerseyTest; | |
+import org.glassfish.jersey.test.external.ExternalTestContainerFactory; | |
+import org.glassfish.jersey.test.spi.TestContainerException; | |
+import org.glassfish.jersey.test.spi.TestContainerFactory; | |
import org.apache.cxf.jaxrs.client.JAXRSClientFactoryBean; | |
import org.apache.cxf.jaxrs.ext.multipart.Attachment; | |
@@ -72,6 +75,11 @@ public class Jersey2776ITCase extends JerseyTest { | |
return new TestApplication(); | |
} | |
+ @Override | |
+ protected TestContainerFactory getTestContainerFactory() throws TestContainerException { | |
+ return new ExternalTestContainerFactory(); | |
+ } | |
+ | |
@Path("/files") | |
public interface ApacheCxfMultipartClient { | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment