{
if ((event instanceof HttpInboundServletRewrite) && DispatchType.isRequest().evaluate(event, context))
{
HttpInboundServletRewrite in = (HttpInboundServletRewrite) event;
QueryStringBuilder query = QueryStringBuilder.createNew();
query.addParameters(in.getInboundAddress().getQuery());
String token = query.decode().getParameter(tokenName);
if (token != null)
{
String decoded = encodingStrategy.decode(token);
if (checksumStrategy.checksumValid(decoded))
{
decoded = checksumStrategy.removeChecksum(decoded);
query.removeParameter(tokenName);
QueryStringBuilder queryParams = QueryStringBuilder.createFromEncoded(decoded);
RewriteWrappedRequest request = RewriteWrappedRequest.getCurrentInstance(in.getRequest());
for (Entry<String, List<String>> param : queryParams.getParameterMap().entrySet()) {
for (String value : param.getValue()) {
Maps.addArrayValue(request.getModifiableParameters(), param.getKey(), value);
}
}
}
else if (onfailure != null)
{
onfailure.perform(event, context);
}
}
else if (!query.isEmpty() && inboundCorrection)
{
in.redirectTemporary(in.getAddress().getPathAndQuery());
}
}
else if (event instanceof HttpOutboundServletRewrite)
{
HttpOutboundServletRewrite out = (HttpOutboundServletRewrite) event;
String outboundURL = out.getOutboundAddress().toString();
URLBuilder url = URLBuilder.createFrom(outboundURL);
url.getQueryStringBuilder().removeParameter(tokenName);
QueryStringBuilder newQuery = QueryStringBuilder.createNew();
for (String param : excludedParams) {
newQuery.addParameter(param, url.getQueryStringBuilder().removeParameter(param).toArray(new String[] {}));
}
if (!params.isEmpty())
{
for (String param : url.getQueryStringBuilder().getParameterNames())
{
if (!params.contains(param))
{
newQuery.addParameter(param,
url.getQueryStringBuilder().removeParameter(param).toArray(new String[] {}));
}
}
}
if (outboundURL.contains("?") && (outboundURL.startsWith(out.getContextPath()) || outboundURL.startsWith("/")))
{
if (!url.getQueryStringBuilder().isEmpty())
{
String encoded = checksumStrategy.embedChecksum(url.getQueryStringBuilder().toQueryString());
encoded = encodingStrategy.encode(encoded);
newQuery.addParameter(tokenName, encoded);
out.setOutboundAddress(AddressBuilder.create(url.toPath() + newQuery.toQueryString()));
}
}
}
}