@Override
public UrlRewriteStepStatus process( UrlRewriteContext context ) throws Exception {
//TODO: Need some way to get a reference to the keystore service and the encryption key in particular.
Template currUrl = context.getCurrentUrl();
Builder newUrl = new Builder( currUrl );
Map<String,Query> map = newUrl.getQuery();
Query query = map.remove( ENCRYPTED_PARAMETER_NAME );
if( query != null ) {
String value = query.getFirstValue().getPattern();
value = decode( value );
StringTokenizer outerParser = new StringTokenizer( value, "&" );
while( outerParser.hasMoreTokens() ) {
String pair = outerParser.nextToken();
StringTokenizer innerParser = new StringTokenizer( pair, "=" );
if( innerParser.hasMoreTokens() ) {
String paramName = innerParser.nextToken();
if( innerParser.hasMoreTokens() ) {
String paramValue = innerParser.nextToken();
// Need to remove from the clear parameters any param name in the encoded params.
// If we don't then someone could override something in the encoded param.
map.remove( paramName );
newUrl.addQuery( paramName, "", paramValue );
} else {
newUrl.addQuery( paramName, "", null );
}
}
}
context.setCurrentUrl( newUrl.build() );
context.getParameters().resolve( "gateway.name" );
}
return UrlRewriteStepStatus.SUCCESS;
}