-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
316 additions
and
54 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 was deleted.
Oops, something went wrong.
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,148 @@ | ||
package org.samples; | ||
|
||
import jakarta.servlet.http.HttpServletResponse; | ||
import org.samples.required.ActionCode; | ||
import org.samples.required.ClientAbortException; | ||
import org.samples.required.Parameters; | ||
import org.samples.required.RequestBase; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.security.InvalidParameterException; | ||
|
||
|
||
public class Request extends RequestBase { | ||
|
||
public void doParseParameters() { | ||
if (parametersParsed) { | ||
return; | ||
} | ||
parametersParsed = true; | ||
|
||
|
||
Parameters parameters = coyoteRequest.getParameters(); | ||
|
||
// Set this every time in case limit has been changed via JMX | ||
int maxParameterCount = getMaxParameterCount(); | ||
if (parts != null && maxParameterCount > 0) { | ||
maxParameterCount -= parts.size(); | ||
} | ||
parameters.setLimit(maxParameterCount); | ||
|
||
// getCharacterEncoding() may have been overridden to search for | ||
// hidden form field containing request encoding | ||
Charset charset = getCharset(); | ||
|
||
boolean useBodyEncodingForURI = connector.getUseBodyEncodingForURI(); | ||
parameters.setCharset(charset); | ||
if (useBodyEncodingForURI) { | ||
parameters.setQueryStringCharset(charset); | ||
} | ||
// Note: If !useBodyEncodingForURI, the query string encoding is | ||
// that set towards the start of CoyoteAdapter.service() | ||
|
||
parameters.handleQueryParameters(); | ||
|
||
if (usingInputStream || usingReader) { | ||
return; | ||
} | ||
|
||
String contentType = getContentType(); | ||
if (contentType == null) { | ||
contentType = ""; | ||
} | ||
int semicolon = contentType.indexOf(';'); | ||
if (semicolon >= 0) { | ||
contentType = contentType.substring(0, semicolon).trim(); | ||
} else { | ||
contentType = contentType.trim(); | ||
} | ||
|
||
if ("multipart/form-data".equals(contentType)) { | ||
parseParts(); | ||
if (partsParseException instanceof IllegalStateException) { | ||
parametersParseException = (IllegalStateException) partsParseException; | ||
} else if (partsParseException != null) { | ||
parametersParseException = new InvalidParameterException(partsParseException.getMessage()); | ||
} | ||
return; | ||
} | ||
|
||
if (!getConnector().isParseBodyMethod(getMethod())) { | ||
return; | ||
} | ||
|
||
if (!("application/x-www-form-urlencoded".equals(contentType))) { | ||
return; | ||
} | ||
|
||
int len = getContentLength(); | ||
|
||
if (len > 0) { | ||
int maxPostSize = connector.getMaxPostSize(); | ||
if ((maxPostSize >= 0) && (len > maxPostSize)) { | ||
String message = sm.getString("coyoteRequest.postTooLarge"); | ||
Context context = getContext(); | ||
if (context != null && context.getLogger().isDebugEnabled()) { | ||
context.getLogger().debug(message); | ||
} | ||
checkSwallowInput(); | ||
parametersParseException = | ||
new ClientAbortException(message, HttpServletResponse.SC_REQUEST_ENTITY_TOO_LARGE); | ||
return; | ||
} | ||
byte[] formData = null; | ||
if (len < CACHED_POST_LEN) { | ||
if (postData == null) { | ||
postData = new byte[CACHED_POST_LEN]; | ||
} | ||
formData = postData; | ||
} else { | ||
formData = new byte[len]; | ||
} | ||
try { | ||
readPostBodyFully(formData, len); | ||
} catch (IOException e) { | ||
// Client disconnect | ||
Context context = getContext(); | ||
if (context != null && context.getLogger().isDebugEnabled()) { | ||
context.getLogger().debug(sm.getString("coyoteRequest.parseParameters"), e); | ||
} | ||
response.getCoyoteResponse().action(ActionCode.CLOSE_NOW, null); | ||
if (e instanceof ClientAbortException) { | ||
parametersParseException = new InvalidParameterException(e.getMessage()); | ||
} else { | ||
parametersParseException = new ClientAbortException(e); | ||
} | ||
return; | ||
} | ||
parameters.processParameters(formData, 0, len); | ||
} else if ("chunked".equalsIgnoreCase(coyoteRequest.getHeader("transfer-encoding"))) { | ||
byte[] formData = null; | ||
try { | ||
formData = readChunkedPostBody(); | ||
} catch (IllegalStateException ise) { | ||
parametersParseException = ise; | ||
return; | ||
} catch (IOException e) { | ||
// Client disconnect | ||
Context context = getContext(); | ||
if (context != null && context.getLogger().isDebugEnabled()) { | ||
context.getLogger().debug(sm.getString("coyoteRequest.parseParameters"), e); | ||
} | ||
response.getCoyoteResponse().action(ActionCode.CLOSE_NOW, null); | ||
if (e instanceof ClientAbortException) { | ||
parametersParseException = new InvalidParameterException(); | ||
} else { | ||
parametersParseException = new InvalidParameterException(); | ||
} | ||
return; | ||
} | ||
if (formData != null) { | ||
parameters.processParameters(formData, 0, formData.length); | ||
} | ||
} | ||
} | ||
|
||
|
||
} |
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,5 @@ | ||
package org.samples.required; | ||
|
||
public class ActionCode { | ||
public static final Object CLOSE_NOW = null; | ||
} |
13 changes: 13 additions & 0 deletions
13
src/main/java/org/samples/required/ClientAbortException.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,13 @@ | ||
package org.samples.required; | ||
|
||
import java.io.IOException; | ||
|
||
public class ClientAbortException extends IOException { | ||
public ClientAbortException(String message, int scRequestEntityTooLarge) { | ||
|
||
} | ||
|
||
public ClientAbortException(IOException e) { | ||
|
||
} | ||
} |
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,56 @@ | ||
package org.samples.required; | ||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
|
||
public class Parameters { | ||
public void setLimit(int maxParameterCount) { | ||
} | ||
|
||
public boolean getUseBodyEncodingForURI() { | ||
return false; | ||
} | ||
public boolean isParseBodyMethod(Object method){ | ||
return false; | ||
} | ||
|
||
public void setCharset(Charset charset) { | ||
} | ||
|
||
public void setQueryStringCharset(Charset charset) { | ||
} | ||
|
||
public void handleQueryParameters() { | ||
} | ||
|
||
public int getMaxPostSize() { | ||
return 0; | ||
} | ||
|
||
public String getString(String s) { | ||
return null; | ||
} | ||
|
||
public Parameters getLogger() { | ||
return null; | ||
} | ||
|
||
public boolean isDebugEnabled() { | ||
return false; | ||
} | ||
|
||
public void debug(String message) { | ||
} | ||
|
||
public void processParameters(byte[] formData, int i, int length) { | ||
} | ||
|
||
public void debug(String string, IOException e) { | ||
} | ||
|
||
public Parameters getCoyoteResponse() { | ||
return null; | ||
} | ||
|
||
public void action(Object closeNow, Object o) { | ||
} | ||
} |
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,88 @@ | ||
package org.samples.required; | ||
|
||
import jakarta.servlet.http.Part; | ||
import org.samples.Request; | ||
|
||
import java.io.IOException; | ||
import java.nio.charset.Charset; | ||
import java.util.Collection; | ||
|
||
public class RequestBase { | ||
/** | ||
* Post data buffer. | ||
*/ | ||
protected static final int CACHED_POST_LEN = 8192; | ||
protected Parameters response; | ||
protected Request coyoteRequest; | ||
protected Parameters sm; | ||
/** | ||
* Using stream flag. | ||
*/ | ||
protected boolean usingInputStream = false; | ||
protected boolean usingReader = false; | ||
protected boolean parametersParsed = false; | ||
protected byte[] postData = null; | ||
protected Exception parametersParseException = null; | ||
/** | ||
* The parts, if any, uploaded with this request. | ||
*/ | ||
protected Collection<Part> parts = null; | ||
/** | ||
* The exception thrown, if any when parsing the parts. | ||
*/ | ||
protected Exception partsParseException = null; | ||
protected Parameters connector; | ||
|
||
protected byte[] readChunkedPostBody() throws IOException { | ||
return new byte[0]; | ||
} | ||
|
||
protected String getHeader(String s) { | ||
return null; | ||
} | ||
|
||
protected void checkSwallowInput() { | ||
|
||
} | ||
|
||
protected void readPostBodyFully(byte[] formData, int len) throws IOException { | ||
} | ||
|
||
protected int getContentLength() { | ||
return 0; | ||
} | ||
|
||
protected Object getMethod() { | ||
return null; | ||
} | ||
|
||
protected Context getContext() { | ||
return null; | ||
} | ||
|
||
protected Parameters getConnector() { | ||
return null; | ||
} | ||
|
||
protected void parseParts() { | ||
} | ||
|
||
protected String getContentType() { | ||
return null; | ||
} | ||
|
||
protected Charset getCharset() { | ||
return null; | ||
} | ||
|
||
protected int getMaxParameterCount() { | ||
return 0; | ||
} | ||
|
||
protected Parameters getParameters() { | ||
return null; | ||
} | ||
|
||
public static class Context extends Parameters { | ||
} | ||
} |
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 was deleted.
Oops, something went wrong.
1 change: 0 additions & 1 deletion
1
src/test/java/org/samples/SampleTests.testWithApprovalTests.approved.txt
This file was deleted.
Oops, something went wrong.