use of org.apache.tomcat.util.buf.MessageBytes in project tomcat by apache.
the class ApplicationHttpRequest method mergeParameters.
// ------------------------------------------------------ Private Methods
/**
* Merge the parameters from the saved query parameter string (if any), and
* the parameters already present on this request (if any), such that the
* parameter values from the query string show up first if there are
* duplicate parameter names.
*/
private void mergeParameters() {
if ((queryParamString == null) || (queryParamString.length() < 1)) {
return;
}
// Parse the query string from the dispatch target
Parameters paramParser = new Parameters();
MessageBytes queryMB = MessageBytes.newInstance();
queryMB.setString(queryParamString);
// TODO
// - Should only use body encoding if useBodyEncodingForURI is true
// - Otherwise, should use URIEncoding
// - The problem is that the connector is not available...
// - To add to the fun, the URI default changed in Servlet 4.0 to UTF-8
String encoding = getCharacterEncoding();
Charset charset = null;
if (encoding != null) {
try {
charset = B2CConverter.getCharset(encoding);
queryMB.setCharset(charset);
} catch (UnsupportedEncodingException e) {
// Fall-back to default (ISO-8859-1)
charset = StandardCharsets.ISO_8859_1;
}
}
paramParser.setQuery(queryMB);
paramParser.setQueryStringCharset(charset);
paramParser.handleQueryParameters();
// Insert the additional parameters from the dispatch target
Enumeration<String> dispParamNames = paramParser.getParameterNames();
while (dispParamNames.hasMoreElements()) {
String dispParamName = dispParamNames.nextElement();
String[] dispParamValues = paramParser.getParameterValues(dispParamName);
String[] originalValues = parameters.get(dispParamName);
if (originalValues == null) {
parameters.put(dispParamName, dispParamValues);
continue;
}
parameters.put(dispParamName, mergeValues(dispParamValues, originalValues));
}
}
use of org.apache.tomcat.util.buf.MessageBytes in project tomcat by apache.
the class ApplicationPushBuilder method push.
@Override
public void push() {
if (path == null) {
throw new IllegalStateException(sm.getString("pushBuilder.noPath"));
}
org.apache.coyote.Request pushTarget = new org.apache.coyote.Request();
pushTarget.method().setString(method);
// The next three are implied by the Javadoc getPath()
pushTarget.serverName().setString(baseRequest.getServerName());
pushTarget.setServerPort(baseRequest.getServerPort());
pushTarget.scheme().setString(baseRequest.getScheme());
// Copy headers
for (Map.Entry<String, List<String>> header : headers.entrySet()) {
for (String value : header.getValue()) {
pushTarget.getMimeHeaders().addValue(header.getKey()).setString(value);
}
}
// Path and query string
int queryIndex = path.indexOf('?');
String pushPath;
String pushQueryString = null;
if (queryIndex > -1) {
pushPath = path.substring(0, queryIndex);
if (queryIndex + 1 < path.length()) {
pushQueryString = path.substring(queryIndex + 1);
}
} else {
pushPath = path;
}
// Session ID (do this before setting the path since it may change it)
if (sessionId != null) {
if (addSessionPathParameter) {
pushPath = pushPath + ";" + sessionPathParameterName + "=" + sessionId;
pushTarget.addPathParameter(sessionPathParameterName, sessionId);
}
if (addSessionCookie) {
String sessionCookieHeader = sessionCookieName + "=" + sessionId;
MessageBytes mb = pushTarget.getMimeHeaders().getValue("cookie");
if (mb == null) {
mb = pushTarget.getMimeHeaders().addValue("cookie");
mb.setString(sessionCookieHeader);
} else {
mb.setString(mb.getString() + ";" + sessionCookieHeader);
}
}
}
// Undecoded path - just %nn encoded
pushTarget.requestURI().setString(pushPath);
pushTarget.decodedURI().setString(decode(pushPath, catalinaRequest.getConnector().getURICharset()));
// Query string
if (pushQueryString == null && queryString != null) {
pushTarget.queryString().setString(queryString);
} else if (pushQueryString != null && queryString == null) {
pushTarget.queryString().setString(pushQueryString);
} else if (pushQueryString != null && queryString != null) {
pushTarget.queryString().setString(pushQueryString + "&" + queryString);
}
// Authorization
if (userName != null) {
pushTarget.getRemoteUser().setString(userName);
pushTarget.setRemoteUserNeedsAuthorization(true);
}
coyoteRequest.action(ActionCode.PUSH_REQUEST, pushTarget);
// Reset for next call to this method
path = null;
headers.remove("if-none-match");
headers.remove("if-modified-since");
}
use of org.apache.tomcat.util.buf.MessageBytes in project tomcat by apache.
the class HealthCheckValve method invoke.
@Override
public void invoke(Request request, Response response) throws IOException, ServletException {
MessageBytes urlMB = context ? request.getRequestPathMB() : request.getDecodedRequestURIMB();
if (urlMB.equals(path)) {
response.setContentType("application/json");
if (!checkContainersAvailable || isAvailable(getContainer())) {
response.getOutputStream().print(UP);
} else {
response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
response.getOutputStream().print(DOWN);
}
} else {
getNext().invoke(request, response);
}
}
Aggregations