use of org.webpieces.router.impl.routeinvoker.PortAndIsSecure in project webpieces by deanhiller.
the class ReverseRoutes method routeToUrl.
// for redirects
public UrlInfo routeToUrl(RouteId routeId, Method method, Map<String, Object> args, RequestContext ctx, HttpPort requestedPort) {
ReversableRouter routeMeta = get(routeId);
if (routeMeta == null)
throw new IllegalReturnValueException("Route=" + routeId + " returned from method='" + method + "' was not added in the RouterModules");
MatchInfo matchInfo = routeMeta.getMatchInfo();
if (!matchInfo.matchesMethod(HttpMethod.GET))
throw new IllegalReturnValueException("method='" + method + "' is trying to redirect to routeid=" + routeId + " but that route is not a GET method route and must be");
Map<String, String> keysToValues = reverseTranslator.formMap(method, matchInfo.getPathParamNames(), args);
Set<String> keySet = keysToValues.keySet();
List<String> argNames = matchInfo.getPathParamNames();
if (keySet.size() != argNames.size()) {
throw new IllegalReturnValueException("Method='" + method + "' returns a Redirect action with wrong number of arguments. args=" + keySet.size() + " when it should be size=" + argNames.size());
}
String path = matchInfo.getFullPath();
for (String name : argNames) {
String value = keysToValues.get(name);
if (value == null)
throw new IllegalArgumentException("Method='" + method + "' returns a Redirect that is missing argument key=" + name + " to form the url on the redirect");
path = path.replace("{" + name + "}", value);
}
PortAndIsSecure info = redirectFormation.calculateInfo(matchInfo, requestedPort, ctx.getRequest());
boolean isSecure = info.isSecure();
int port = info.getPort();
return new UrlInfo(isSecure, port, path);
}
Aggregations