-
Notifications
You must be signed in to change notification settings - Fork 351
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Fixed caching of content_type Signed-off-by: jansupol <jan.supol@oracle.com>
- Loading branch information
Showing
6 changed files
with
93 additions
and
13 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
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
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
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
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
52 changes: 52 additions & 0 deletions
52
...rc/test/java/org/glassfish/jersey/tests/e2e/common/message/internal/ReaderWriterTest.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,52 @@ | ||
/* | ||
* Copyright (c) 2012, 2023 Oracle and/or its affiliates. All rights reserved. | ||
* | ||
* This program and the accompanying materials are made available under the | ||
* terms of the Eclipse Public License v. 2.0, which is available at | ||
* http://www.eclipse.org/legal/epl-2.0. | ||
* | ||
* This Source Code may also be made available under the following Secondary | ||
* Licenses when the conditions for such availability set forth in the | ||
* Eclipse Public License v. 2.0 are satisfied: GNU General Public License, | ||
* version 2 with the GNU Classpath Exception, which is available at | ||
* https://www.gnu.org/software/classpath/license.html. | ||
* | ||
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 | ||
*/ | ||
|
||
package org.glassfish.jersey.tests.e2e.common.message.internal; | ||
|
||
import org.glassfish.jersey.message.internal.ReaderWriter; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.ws.rs.core.MediaType; | ||
import java.io.ByteArrayInputStream; | ||
import java.io.IOException; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
public class ReaderWriterTest { | ||
@Test | ||
public void testToNeverAskToReadZeroBytes() throws IOException { | ||
// Unnamed app server bug test | ||
int size = ((ReaderWriter.BUFFER_SIZE + 1000) / 10) * 10; | ||
StringBuilder sb = new StringBuilder(size); | ||
String shortMsg = "0123456789"; | ||
while (sb.length() < size) { | ||
sb.append(shortMsg); | ||
} | ||
|
||
ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(sb.toString().getBytes(StandardCharsets.UTF_8)) { | ||
@Override | ||
public synchronized int read(byte[] b, int off, int len) { | ||
if (len == 0) { | ||
return -1; // simulate the bug | ||
} | ||
return super.read(b, off, len); | ||
} | ||
}; | ||
|
||
String read = ReaderWriter.readFromAsString(byteArrayInputStream, MediaType.TEXT_HTML_TYPE); | ||
Assertions.assertEquals(size, read.length()); | ||
} | ||
} |