/** * Return a list of all endpoints with path matching the request path. The endpoints are in order of match * preference, best match first. * * @param requestPath request path. * @param endpoints endpoints. * @param debugContext debug context. * @return a list of all endpoints with path matching the request path. The endpoints are in order of match * preference, best match first. */ public static List<Match> getAllMatches(String requestPath, Set<TyrusEndpointWrapper> endpoints, DebugContext debugContext) { List<Match> matches = new ArrayList<Match>(); for (TyrusEndpointWrapper endpoint : endpoints) { Match m = matchPath(requestPath, endpoint, debugContext); if (m != null) { matches.add(m); } } Collections.sort(matches, new MatchComparator(debugContext)); debugContext.appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "Endpoints matched to the request URI: ", matches); return matches; }
/** * Return a list of all endpoints with path matching the request path. The endpoints are in order of match * preference, best match first. * * @param requestPath request path. * @param endpoints endpoints. * @param debugContext debug context. * @return a list of all endpoints with path matching the request path. The endpoints are in order of match * preference, best match first. */ public static List<Match> getAllMatches(String requestPath, Set<TyrusEndpointWrapper> endpoints, DebugContext debugContext) { List<Match> matches = new ArrayList<Match>(); for (TyrusEndpointWrapper endpoint : endpoints) { Match m = matchPath(requestPath, endpoint, debugContext); if (m != null) { matches.add(m); } } Collections.sort(matches, new MatchComparator(debugContext)); debugContext.appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "Endpoints matched to the request URI: ", matches); return matches; }
@Override public int compare(Match m1, Match m2) { debugContext .appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, "Choosing better match from ", m1, " and ", m2); boolean m1exact = m1.isExact(); if (m2exact) { // both exact matches, no-one wins debugContext .appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, "Both ", m1, " and ", m2, " are exact matches"); return 0; } else { // m2not exact, m1 is, m1 wins debugContext.appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, m1, " is an exact match"); debugContext.appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, m2, " is an exact match"); debugContext.appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, m2, " is a better match, because ", m1, " has more variables"); debugContext.appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, m1, " is a better match, because ", m2, " has more variables"); debugContext.appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, m1, " is a better match, because it has longer exact path"); return -1; } else if (m2Index > m1Index) {
@Override public int compare(Match m1, Match m2) { debugContext .appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, "Choosing better match from ", m1, " and ", m2); boolean m1exact = m1.isExact(); if (m2exact) { // both exact matches, no-one wins debugContext .appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, "Both ", m1, " and ", m2, " are exact matches"); return 0; } else { // m2not exact, m1 is, m1 wins debugContext.appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, m1, " is an exact match"); debugContext.appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, m2, " is an exact match"); debugContext.appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, m2, " is a better match, because ", m1, " has more variables"); debugContext.appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, m1, " is a better match, because ", m2, " has more variables"); debugContext.appendTraceMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, m1, " is a better match, because it has longer exact path"); return -1; } else if (m2Index > m1Index) {
TyrusEndpointWrapper getEndpointWrapper(UpgradeRequest request, DebugContext debugContext) throws HandshakeException { if (endpointWrappers.isEmpty()) { return null; } final String requestPath = request.getRequestUri(); for (Match m : Match.getAllMatches(requestPath, endpointWrappers, debugContext)) { final TyrusEndpointWrapper endpointWrapper = m.getEndpointWrapper(); for (Map.Entry<String, String> parameter : m.getParameters().entrySet()) { request.getParameterMap().put(parameter.getKey(), Arrays.asList(parameter.getValue())); } if (endpointWrapper.upgrade(request)) { debugContext.appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "Endpoint selected as a match to the handshake URI: ", endpointWrapper.getEndpointPath()); debugContext.appendLogMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, "Target endpoint: ", endpointWrapper); return endpointWrapper; } } return null; }
TyrusEndpointWrapper getEndpointWrapper(UpgradeRequest request, DebugContext debugContext) throws HandshakeException { if (endpointWrappers.isEmpty()) { return null; } final String requestPath = request.getRequestUri(); for (Match m : Match.getAllMatches(requestPath, endpointWrappers, debugContext)) { final TyrusEndpointWrapper endpointWrapper = m.getEndpointWrapper(); for (Map.Entry<String, String> parameter : m.getParameters().entrySet()) { request.getParameterMap().put(parameter.getKey(), Arrays.asList(parameter.getValue())); } if (endpointWrapper.upgrade(request)) { debugContext.appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "Endpoint selected as a match to the handshake URI: ", endpointWrapper.getEndpointPath()); debugContext.appendLogMessage(LOGGER, Level.FINER, DebugContext.Type.MESSAGE_IN, "Target endpoint: ", endpointWrapper); return endpointWrapper; } } return null; }
private static Match matchPath(String requestPath, TyrusEndpointWrapper endpoint, DebugContext debugContext) { debugContext.appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "Matching request URI ", requestPath, " against ", endpoint.getEndpointPath()); List<PathSegment> requestPathSegments = UriComponent.decodePath(requestPath, true); .appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "URIs ", requestPath, " and ", endpoint.getEndpointPath(), " have different length"); return null; m.addParameter(getVariableName(endpointSegment), requestSegment, i); } else { debugContext.appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "Segment \"", endpointSegment, "\" does not match"); return null; // no match
private static Match matchPath(String requestPath, TyrusEndpointWrapper endpoint, DebugContext debugContext) { debugContext.appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "Matching request URI ", requestPath, " against ", endpoint.getEndpointPath()); List<PathSegment> requestPathSegments = UriComponent.decodePath(requestPath, true); .appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "URIs ", requestPath, " and ", endpoint.getEndpointPath(), " have different length"); return null; m.addParameter(getVariableName(endpointSegment), requestSegment, i); } else { debugContext.appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "Segment \"", endpointSegment, "\" does not match"); return null; // no match
if (protocolHandler == null) { handleUnsupportedVersion(request, response); debugContext.appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "Upgrade request contains unsupported version of Websocket protocol");
if (protocolHandler == null) { handleUnsupportedVersion(request, response); debugContext.appendTraceMessage(LOGGER, Level.FINE, DebugContext.Type.MESSAGE_IN, "Upgrade request contains unsupported version of Websocket protocol");